Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
test(server): agent-status e2e (hook POST → ws); docs(server): Phase 3b scope
enes11392828977e
diff --git a/docs/SERVER.md b/docs/SERVER.mdindex fa29ff1b5..d15c41aa0 100644--- a/docs/SERVER.md+++ b/docs/SERVER.md@@ -182,6 +182,44 @@ closed: a flooding PTY is automatically paused based on the WebSocket**Still deferred to Phase 3b:** the SDK **chat node** and the **agent-statusbadges/hooks** are not yet wired into the server bridge.+## Phase 3b: agent status, subagents & the context meter++Phase 3b brings the agent-observability surface — the same code path the desktop app+uses — to the browser. The server boots the loopback **hook server**+(`hookServer.start()`, on its own `127.0.0.1` port) and installs the managed hook+scripts, so every agent CLI the server spawns POSTs its lifecycle hooks back to the+host. `wireAgentStatus` installs the hook server's normalized + raw listeners and+routes each event over `platform.broadcast`, so the existing renderer badge / subagent+/ context code now works unchanged in the browser:++- **Agent-status badges** — an agent's own hooks (not output parsing) drive the shared+ 4-state model; the normalized event is broadcast over `agent:status` and the header+ shows the pulsing **RUNNING** (working) / **NEEDS YOU** (waiting/blocked) badge, plus+ the unread dot and completion notification (as a Web Notification — see Phase 2).+- **Subagent visualization** — subagent start/end drive ephemeral **SubagentNode** cards+ over `agent:subagent-activity`; the main-process subagent tail streams each card's live+ transcript to the browser.+- **Context-window meter** — the per-node context tail streams `context:update` so the+ meter fills as the session's transcript grows (this channel was already real in 3a; 3b+ feeds it from the hook pipeline).++Because the hook POST carries a `transcript_path`, a forged POST is defended by jailing+that path to the system-default `~/.claude/projects` or a managed account dir+(`isSafeLocalTranscriptPath`) before any tail reads it.++**Deliberate scope skips (Phase 3b):**++- The SDK **chat node** is still **deferred** — it is not wired into the server bridge.+- **Canvas-control** (`agent:control`, the Claude-only `nodeterm` CLI verbs) is **not+ wired** over the server.+- The **`ptyDestroy` tail-teardown is skipped**: the platform's single-listener registry+ forbids a second `ptyDestroy` listener, so tails self-clear on `SessionEnd`. A node+ closed *without* a SessionEnd leaves a **bounded, lingering file-tail** until the+ process exits — no leak of unbounded resources.+- **SSH-remote agent tails are N/A** — the server has no SSH-project manager, so the+ SSH branch of the desktop hook-wiring block is dropped (the raw listener falls straight+ through to the local logic).+## Manual browser smoke checklistRun against a real browser (this is the human-verified path; the automated harness@@ -209,3 +247,11 @@ only exercises the HTTP/auth surface). With `npm run server:dev` running:10. **Source Control (Phase 3a)** — open the Source Control panel; your edit shows as achange. Click it to see the **diff**, **stage** it (+), type a message, and**commit**; the file leaves the change list and the commit appears in recent commits.+11. **Agent status (Phase 3b)** — open a **Claude** terminal node, run a prompt; the header+ should show the pulsing **RUNNING** badge while it works and clear (with an unread dot+ if the tab is unfocused) when it's done.+12. **Subagent card (Phase 3b)** — from a Claude node, run a prompt that dispatches a+ subagent (e.g. a `/task`); an ephemeral **subagent card** appears connected to the+ parent node; click it to watch its live transcript stream.+13. **Context meter (Phase 3b)** — as a Claude session accumulates transcript, the node's+ **context-window meter** should fill.diff --git a/test/server/agent-status-e2e.test.ts b/test/server/agent-status-e2e.test.tsnew file mode 100644index 000000000..a89db06ea--- /dev/null+++ b/test/server/agent-status-e2e.test.ts@@ -0,0 +1,117 @@+import { describe, it, expect, beforeAll, afterAll } from 'vitest'+import fs from 'fs'+import os from 'os'+import path from 'path'+import WebSocket from 'ws'+import { startServer } from '../../src/server/index'+import { SESSION_COOKIE } from '../../src/server/http'+import { hookServer } from '../../src/core/agents/hook-server'+import { IPC } from '../../src/shared/ipc'++// End-to-end proof of the Phase-3b agent-status chain, exercised over real sockets:+//+// hook script POST → loopback hook server → normalizeClaude → platform.broadcast+// → WS `agent:status`+//+// `startServer` boots the loopback hook server (`hookServer.start()`) and wires its normalized+// listener onto the platform (`wireAgentStatus`). We reproduce the EXACT POST the managed hook+// script sends — path `POST /hook/<agentId>`, an `x-www-form-urlencoded` body carrying `nodeId`+// plus a JSON `payload`, authenticated by the per-session bearer token in the+// `x-nodeterm-hook-token` header (see src/core/agents/hook-server.ts) — using the live+// port/token exposed by `hookServer.getPort()` / `hookServer.getToken()` after boot.+//+// The synthetic payload is a Claude `Stop` hook event, which `normalizeClaude` maps to+// `{ kind:'state', state:'done' }` (truthy → the platform listener fires → broadcast). A WS+// client (registered as a broadcast sink on connect) must then receive the `agent:status`+// event carrying that normalized state.+describe('agent-status e2e: hook POST → agent:status over ws', () => {+ let dataDir: string, close: () => Promise<void>, port: number, cookie: string++ beforeAll(async () => {+ dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'nt-e2e-agst-'))+ const srv = await startServer({+ port: 0,+ host: '127.0.0.1',+ dataDir,+ rendererDir: path.join(dataDir, 'no-renderer'),+ insecureHttp: false,+ passwordSeed: 'agst-e2e-pw'+ })+ port = srv.port+ close = srv.close+ const res = await fetch(`http://127.0.0.1:${port}/auth/login`, {+ method: 'POST',+ headers: { 'content-type': 'application/x-www-form-urlencoded' },+ body: 'password=agst-e2e-pw',+ redirect: 'manual'+ })+ expect(res.status).toBe(303)+ cookie = res.headers.get('set-cookie')!.split(';')[0]+ expect(cookie).toContain(SESSION_COOKIE)+ }, 30_000)++ afterAll(async () => {+ await close?.()+ fs.rmSync(dataDir, { recursive: true, force: true })+ })++ it('a posted hook event is broadcast to the ws client as agent:status', async () => {+ // The boot step must have actually started the loopback hook server.+ const hookPort = hookServer.getPort()+ const hookToken = hookServer.getToken()+ expect(hookPort).toBeGreaterThan(0)+ expect(hookToken).not.toBe('')++ const ws = new WebSocket(`ws://127.0.0.1:${port}/ws`, { headers: { cookie } })+ await new Promise<void>((res, rej) => {+ ws.on('open', () => res())+ ws.on('error', rej)+ })++ const got = new Promise<Record<string, unknown>>((resolve) => {+ ws.on('message', (d, isBinary) => {+ if (isBinary) return+ const m = JSON.parse(d.toString()) as Record<string, unknown>+ if (m.t === 'ev' && m.channel === IPC.agentStatus) resolve(m)+ })+ })++ // Reproduce the managed hook script's POST exactly. A Claude `Stop` event normalizes to a+ // state change (done) → the platform listener fires → `agent:status` broadcast.+ const nodeId = 'e2e-node-1'+ const payload = JSON.stringify({+ hook_event_name: 'Stop',+ session_id: 'e2e-session-abc',+ is_interrupt: false,+ last_assistant_message: 'e2e done'+ })+ const body = `nodeId=${encodeURIComponent(nodeId)}&payload=${encodeURIComponent(payload)}`+ const hookRes = await fetch(`http://127.0.0.1:${hookPort}/hook/claude`, {+ method: 'POST',+ headers: {+ 'content-type': 'application/x-www-form-urlencoded',+ 'x-nodeterm-hook-token': hookToken+ },+ body+ })+ // The hook server always fails open with 204 (a broken hook must never block the agent).+ expect(hookRes.status).toBe(204)++ const ev = (await Promise.race([+ got,+ new Promise((_r, rej) => setTimeout(() => rej(new Error('no agent:status broadcast')), 10_000))+ ])) as Record<string, unknown>++ expect(ev.channel).toBe(IPC.agentStatus)+ // `platform.broadcast(channel, e)` serializes as `{ t:'ev', channel, args:[e] }`; the first+ // arg is the NormalizedAgentEvent produced by normalizeClaude for our Stop payload.+ const normalized = (ev.args as Array<Record<string, unknown>>)[0]+ expect(normalized.nodeId).toBe(nodeId)+ expect(normalized.agentId).toBe('claude')+ expect(normalized.kind).toBe('state')+ expect(normalized.state).toBe('done')+ expect(normalized.sessionId).toBe('e2e-session-abc')++ ws.close()+ }, 30_000)+})