The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
feat: automatically inject local client details into relayed terminal_open frames
0xken154f96670eb046
diff --git a/cli/src/cli.ts b/cli/src/cli.tsindex 8e1b11cc7..228bad0ed 100644--- a/cli/src/cli.ts+++ b/cli/src/cli.ts@@ -3783,6 +3783,10 @@ async function runForeground(session: AuthSession): Promise<void> {backend,relayPool,autonomousEnv: readAuthSession()?.autonomousEnv ?? session.autonomousEnv,+ // A window from before it introduced itself still gets named on the far side's "took control"+ // banner: the relay knows it is this machine's desktop. Same source as `describeClient` above.+ // Cut to the wire's limit here rather than let the far daemon drop the whole claim over a long name.+ localClient: () => ({ kind: 'desktop', name: terminalHintMachineName().slice(0, 64), machineId: backend.machineId }),})// Install both CLI hooks with the port the local server actually bound.if (!env.DISABLE_HOOK_INSTALL) {diff --git a/cli/src/localWsServer.spec.ts b/cli/src/localWsServer.spec.tsindex b6fd89d35..d57c0d3a3 100644--- a/cli/src/localWsServer.spec.ts+++ b/cli/src/localWsServer.spec.ts@@ -105,6 +105,44 @@ describe('local CLI WebSocket', () => {ws.close()})+ // A window from before it introduced itself on `terminal_open` still gets named on the far+ // machine's "took control" banner: this daemon knows the window is its own desktop.+ it('introduces a silent window on a relayed terminal_open, and believes one that speaks', async () => {+ const backend = new FakeBackend()+ const relayed: Frame[] = []+ const relayPool = {+ acquire: async (_machineId: string, _env: string, _select: Frame, sink: LocalClientSink) => {+ sink.sendFrame({ type: 'connected', payload: { machineId: 'other-machine', e2ee: false } })+ return { send: async (frame: Frame) => { relayed.push(frame) }, sendBinary: async () => {}, detach: () => {} }+ },+ acquireIsolated: async () => { throw new Error('unused') },+ invalidate: () => {},+ }+ server = http.createServer((_req, res) => { res.statusCode = 404; res.end() })+ local = attachLocalWsServer(server, {+ machineId, backend, autonomousEnv: 'test',+ relayPool: relayPool as unknown as NonNullable<Parameters<typeof attachLocalWsServer>[1]['relayPool']>,+ localClient: () => ({ kind: 'desktop', name: 'This Mac', machineId }),+ })+ await new Promise<void>((resolve) => server!.listen(0, '127.0.0.1', resolve))+ const ws = new WebSocket(`ws://127.0.0.1:${(server.address() as AddressInfo).port}/api/local-ws`)+ await onceOpen(ws)+ const connected = onceMessage(ws)+ ws.send(JSON.stringify({ type: 'machine_select', payload: { machineId: 'other-machine', localProtocolVersion: 1 } }))+ await expect(connected).resolves.toMatchObject({ type: 'connected' })++ ws.send(JSON.stringify({ type: 'terminal_open', payload: { requestId: 'o1', agentId: 'a', cols: 80, rows: 24, protocolVersion: 3 } }))+ ws.send(JSON.stringify({ type: 'terminal_open', payload: { requestId: 'o2', agentId: 'a', cols: 80, rows: 24, protocolVersion: 3, client: { kind: 'desktop', name: 'Named by the window' } } }))+ ws.send(JSON.stringify({ type: 'agents_list', payload: { requestId: 'r1' } }))+ await new Promise((resolve) => setTimeout(resolve, 30))+ expect(relayed).toEqual([+ { type: 'terminal_open', payload: { requestId: 'o1', agentId: 'a', cols: 80, rows: 24, protocolVersion: 3, client: { kind: 'desktop', name: 'This Mac', machineId } } },+ { type: 'terminal_open', payload: { requestId: 'o2', agentId: 'a', cols: 80, rows: 24, protocolVersion: 3, client: { kind: 'desktop', name: 'Named by the window' } } },+ { type: 'agents_list', payload: { requestId: 'r1' } },+ ])+ ws.close()+ })+it('takes the window\'s tile roster, keeps it off the wire, and forgets it on close', async () => {const backend = new FakeBackend()const rosters: string[][] = []diff --git a/cli/src/localWsServer.ts b/cli/src/localWsServer.tsindex 1437c8e1b..e02decc9d 100644--- a/cli/src/localWsServer.ts+++ b/cli/src/localWsServer.ts@@ -42,6 +42,13 @@ export interface LocalWsServerOptions {relayPool?: RemoteRelayPoolshareRelay?: HarnessShareRelayautonomousEnv?: string+ /**+ * Who a window on this computer is, for a `terminal_open` it relays to another machine without+ * introducing itself (a desktop build from before `client`). This daemon knows what the window+ * cannot be made to say: the client is a desktop on THIS machine, by id and name. Filled in only+ * when the frame carries no `client` of its own — a window that does introduce itself is believed.+ */+ localClient?: () => { kind: string; name: string; machineId?: string } | null/** The desktop app opened an agent's terminal — which agent, and on which machine. Lets the dial follow* the window, so the two screens stay one desk. *//** Explicit app focus, including clear/disconnect, for voice routing independent of the dial. */@@ -198,6 +205,15 @@ function binaryBytes(raw: RawData): Uint8Array {return new Uint8Array()}+/** `terminal_open` with this computer's own introduction, when the window gave none — see `localClient`. */+function withLocalClient(frame: Frame, localClient: LocalWsServerOptions['localClient']): Frame {+ if (frame.type !== 'terminal_open' || !localClient) return frame+ const payload = frame.payload && typeof frame.payload === 'object' ? frame.payload as Record<string, unknown> : {}+ if (payload.client !== undefined) return frame+ const client = localClient()+ return client ? { ...frame, payload: { ...payload, client } } : frame+}+/*** Add an internal loopback WebSocket endpoint to the CLI's existing HTTP server. It intentionally has* no credential: loopback-only, no Origin header, and the desktop computer-id validation identify the@@ -453,7 +469,7 @@ export function attachLocalWsServer(server: http.Server, options: LocalWsServerOreturn}if (!parsed) { close(4400, 'invalid json frame'); return }- await relay.send(parsed)+ await relay.send(withLocalClient(parsed, options.localClient))return}