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
A signed-in core takes its services by their token: they no longer have to name the account's machine id (#839)
Dee3489ea22fb55
diff --git a/cli/e2e/signedIn.e2e.ts b/cli/e2e/signedIn.e2e.tsnew file mode 100644index 000000000..f97d8503d--- /dev/null+++ b/cli/e2e/signedIn.e2e.ts@@ -0,0 +1,79 @@+/**+ * A signed-in daemon, with every service in its own process (the default), for Claude Code and Codex.+ * Signed in, the core serves under its account's machine id while its services name this computer's,+ * and the core took a service only when the two matched: every service of every signed-in daemon was+ * refused and answered SERVICE_UNAVAILABLE for good. Every other end-to-end test runs signed out, and the+ * release rehearsal found it only when it was asked to sign in (`REHEARSE_SIGNED_IN=1`).+ */+import { mkdirSync, writeFileSync } from 'node:fs'+import { join } from 'node:path'+import { afterEach, describe, expect, it, onTestFailed } from 'vitest'+import { LocalClient, type Frame } from './harness/client.js'+import { IsolatedDaemon, until } from './harness/daemon.js'+import { FakeBackend, type FakeMachine } from './harness/fakeBackend.js'++type Engine = 'claude' | 'codex'+const MACHINE: FakeMachine = { machineId: 'c3'.repeat(16), computerId: 'e2e-computer-0000-0000-00000000000c', name: 'signed-in', token: 'e2e-token-signed-in' }+const SERVICES = ['search', 'viewers', 'workspaces', 'teams'] as const++const row = async (client: LocalClient, agentId: string) =>+ ((await client.request<{ agents: Array<Record<string, any>> }>('agents_list', { includeStopped: true }, 30_000)).agents)+ .find((agent) => agent.id === agentId)+async function create(daemon: IsolatedDaemon, client: LocalClient, engine: Engine, folder: string): Promise<Record<string, any>> {+ const cwd = join(daemon.projectsDir, folder)+ mkdirSync(cwd, { recursive: true })+ const created = await client.request('agent_create', { engine, cwd, bypassPermission: true }, 90_000)+ expect(created.error, `${folder}: ${JSON.stringify(created)}`).toBeUndefined()+ return until(`${folder} to bind its conversation`, async () => {+ const agent = await row(client, created.agent.id)+ return agent?.sessionId && agent.status === 'active' ? agent : null+ }, 60_000, 500)+}+const isTurn = (type: string, agentId: string) => (frame: Frame) => frame.type === type && frame.agentId === agentId+async function turn(client: LocalClient, agentId: string, content: string): Promise<void> {+ const ended = client.next(isTurn('turn_ended', agentId), 45_000, `turn_ended (${content})`)+ client.send('message', { agentId, content })+ await ended+}++describe('a signed-in daemon', () => {+ let daemon: IsolatedDaemon | undefined+ let backend: FakeBackend | undefined+ afterEach(async () => {+ await daemon?.close(); daemon = undefined+ await backend?.close(); backend = undefined+ })++ it('runs every service in its own process, each taken by the core, and search answers for both engines', async () => {+ backend = await FakeBackend.start()+ backend.addMachine(MACHINE)+ const d = await IsolatedDaemon.create({ env: {+ BACKEND_WS_URL: backend.wsUrl, WEB_URL: backend.httpUrl, ADAPTER_COMPUTER_ID: MACHINE.computerId,+ } })+ daemon = d+ onTestFailed(() => { console.log(`---- daemon log\n${d.log().split('\n').slice(-150).join('\n')}`) })+ // Signed in, as `harness login` leaves a computer: a session for its machine on this account.+ writeFileSync(join(d.root, 'auth', 'session.json'), JSON.stringify({+ version: 1, accessToken: MACHINE.token, autonomousEnv: 'prod', computerId: MACHINE.computerId,+ machineId: MACHINE.machineId, expiresAt: Date.now() + 30 * 24 * 3600_000, updatedAt: Date.now(), signInEpoch: 'e2e',+ }), { mode: 0o600 })+ await d.start()+ await until('the daemon to connect as the machine\'s node', () => backend!.nodeUp(MACHINE.machineId) || null, 60_000, 250)+ for (const service of SERVICES) {+ await until(`${service} to be taken by the core`, () => d.log().includes(`[service ${service}] connected to the core`) || null, 30_000, 250)+ }+ expect(d.log()).not.toContain('service refused')+ const client = await LocalClient.connect(d, { machineId: MACHINE.machineId })+ for (const engine of ['claude', 'codex'] as const) {+ const agent = await create(d, client, engine, `signed-in-${engine}`)+ await turn(client, agent.id, `a ${engine} turn about the pangolin`)+ await until(`search to find ${engine}'s conversation`, async () => {+ const answer = await client.request('session_search', { query: 'pangolin' }, 30_000)+ expect(answer.error, JSON.stringify(answer)).toBeUndefined()+ return JSON.stringify(answer).includes(agent.sessionId) || null+ }, 60_000, 1_000)+ }+ expect(d.coresStarted()).toBe(1)+ client.close()+ }, 240_000)+})diff --git a/cli/src/localWsServer.spec.ts b/cli/src/localWsServer.spec.tsindex 3850e93b5..b2887f3af 100644--- a/cli/src/localWsServer.spec.ts+++ b/cli/src/localWsServer.spec.ts@@ -1041,6 +1041,42 @@ describe('local CLI WebSocket', () => {ws.close()})+ it('takes the core\'s own services by their token, whatever machine id they name', async () => {+ // A signed-in core serves under its account's machine id; its services name this computer's.+ const accepted: string[] = []+ const services = {+ accept: (service: string, token: string) => {+ if (token !== 'boot-token') return null+ accepted.push(service)+ return { receive: vi.fn(), closed: vi.fn() }+ },+ }+ const url = await start(new FakeBackend(), { services })+ const ws = new WebSocket(url)+ await onceOpen(ws)+ const connected = onceMessage(ws)+ ws.send(JSON.stringify({+ type: 'machine_select',+ payload: { machineId: 'this-computer-id', localProtocolVersion: 1, role: 'service', service: 'search', token: 'boot-token' },+ }))+ await expect(connected).resolves.toMatchObject({ type: 'connected', payload: { machineId, service: 'search' } })+ expect(accepted).toEqual(['search'])+ ws.close()++ // The token is the check: a wrong one is refused, whichever machine id it names.+ for (const named of [machineId, 'this-computer-id']) {+ const wrong = new WebSocket(url)+ await onceOpen(wrong)+ const closed = new Promise<number>((resolve) => wrong.once('close', resolve))+ wrong.send(JSON.stringify({+ type: 'machine_select',+ payload: { machineId: named, localProtocolVersion: 1, role: 'service', service: 'search', token: 'guessed' },+ }))+ await expect(closed).resolves.toBe(4401)+ }+ expect(accepted).toEqual(['search'])+ })+it('rejects browser origins and machine-id mismatches', async () => {const url = await start(new FakeBackend())const browser = new WebSocket(url, { origin: 'https://example.com' })diff --git a/cli/src/localWsServer.ts b/cli/src/localWsServer.tsindex f1dbf187e..b6417fd1a 100644--- a/cli/src/localWsServer.ts+++ b/cli/src/localWsServer.ts@@ -386,8 +386,11 @@ export function attachLocalWsServer(server: http.Server, options: LocalWsServerOreturn}// One of the core's own services, started by harnessd's master: its frames go to its link, and it- // never joins the windows' event stream.- if (requestedMachineId === options.machineId && payload.role === 'service') {+ // never joins the windows' event stream. Known by its token, the secret the master gave only it and+ // the core for this boot, never by the machine id it names: a signed-in core serves under its+ // account's machine id while a service names this computer's, and matching them refused every+ // service of every signed-in daemon (found by the release rehearsal, signed in).+ if (payload.role === 'service') {const link = options.services?.accept(String(payload.service ?? ''), String(payload.token ?? ''), sink, close) ?? nullif (!link) { close(4401, 'service refused'); return }serviceLink = link