Overview
Concrete tool for managing the mesh hosts configuration file — adding, looking up, and identifying the self host, provided by AI Maestro's `lib/hosts-config.ts`.
Description
The hosts-config module manages the file-based mesh host configuration. addHost adds a new host with duplicate detection by ID and URL/IP (prevents the same machine under different hostnames). addHostAsync wraps `addHost` with a file lock for concurrent-safe writes. getHosts returns all configured hosts. getHostById looks up a single host. getSelfHost returns this machine's `Host` object, falling back to a default. getSelfHostId returns the canonical lowercase hostname. isSelf is the only place self-detection happens — checks hostname, IPs, and legacy 'local' value.
Usage
- Call `addHost`/`addHostAsync` to register a peer host.
- Call `getHosts`/`getHostById` to look up peers.
- Call `getSelfHost`/`getSelfHostId` to identify this machine.
- Call `isSelf` to check whether a host ID is this machine.
Code Reference
Source Location
- Repository: ai-maestro
- File: lib/hosts-config.ts (L139-141 getSelfHostId, L228 isSelf, L504-510 getHosts, L511 getHostById, L595-599 getSelfHost, L769-810 addHost, L813-850 addHostAsync)
Signature
export function getSelfHostId(): string
export function isSelf(hostId: string): boolean
export function getHosts(): Host[]
export function getHostById(hostId: string): Host | undefined
export function getSelfHost(): Host
export function addHost(host: Host): {
success: boolean
host?: Host
error?: string
existingHost?: Host
}
export async function addHostAsync(host: Host): Promise<{
success: boolean
host?: Host
error?: string
}>
interface Host {
id: string
name: string
url: string
enabled: boolean
}
Import
import { getSelfHostId, isSelf, getHosts, getHostById, getSelfHost, addHost, addHostAsync } from '@/lib/hosts-config'
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| host |
Host |
Yes (addHost) |
New host configuration
|
| hostId |
string |
Yes (isSelf/getHostById) |
Host ID
|
Outputs
| Name |
Type |
Description
|
| getSelfHostId() returns |
string |
Lowercase hostname without .local
|
| isSelf() returns |
boolean |
true if host is this machine
|
| getHosts() returns |
Host[] |
All configured hosts
|
| getHostById() returns |
undefined |
Host or undefined
|
| getSelfHost() returns |
Host |
This machine's host (default if not configured)
|
| addHost() returns |
{ success, host?, error? } |
Success with host, or error on duplicate
|
Usage Examples
import { addHost, getSelfHostId, isSelf } from '@/lib/hosts-config'
// Register a new peer host
const result = addHost({
id: 'mac-mini',
name: 'Mac Mini',
url: 'http://192.168.1.50:23000',
enabled: true,
})
if (!result.success) {
console.error(`Failed: ${result.error}`)
if (result.existingHost) {
console.log(`Same machine as existing host: ${result.existingHost.id}`)
}
}
// Check if a host is this machine
if (isSelf('macbook-pro')) {
console.log('This is me')
}
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.