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
harness watch <name>: a harness's state changes as events, one line (--json: one object) a change, for programs that follow it (#1874) (#1876)
daniel-autof26884e3d872
diff --git a/cli/src/agentClient/commands.spec.ts b/cli/src/agentClient/commands.spec.tsindex 0c5db1120..65bf250e4 100644--- a/cli/src/agentClient/commands.spec.ts+++ b/cli/src/agentClient/commands.spec.ts@@ -2,7 +2,7 @@ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'import { join } from 'node:path'import { afterEach, beforeEach, describe, expect, it } from 'vitest'-import { addressOf, agentOrigin, AGENTS_START_AGENTS_OFF, closeCommand, DEPTH_REFUSAL, EXIT, parseDuration, psCommand, refusalNext, replyCommand, showCommand, spawnCheck, spawnCount, spawnRefusal, SPAWN_LIMITS, step, tellCommand, waitCommand, whoamiCommand, type ClientDeps } from './commands.js'+import { addressOf, agentOrigin, AGENTS_START_AGENTS_OFF, closeCommand, DEPTH_REFUSAL, EXIT, parseDuration, psCommand, refusalNext, replyCommand, showCommand, spawnCheck, spawnCount, spawnRefusal, SPAWN_LIMITS, step, tellCommand, waitCommand, watchCommand, whoamiCommand, type ClientDeps } from './commands.js'import { RefusedError, type Rpc } from '../messages/rpc.js'import { AgentClientError, type Daemon, type Where } from './daemon.js'import { Ledger, ledgerPath } from './ledger.js'@@ -1957,3 +1957,166 @@ describe('harness tell', () => {expect(mcp.out.join('\n')).toContain('Next: harness_tell (name: "kid", text: "<work>")')})})++describe('harness watch', () => {+ const cloud = (id: string, state: string, over: Partial<Frame> = {}) => frame(id, {+ engine: 'devin-cloud', location: 'cloud', tmuxPane: null, project: null, sessionId: id,+ activity: { state: state === 'working' || state === 'starting' ? 'working' : 'idle' },+ cloud: { state, links: [{ label: 'Session', url: 'https://app.devin.ai/sessions/1' }] }, ...over,+ })+ /** Each round's frame and transcript, one per look; the last stays. */+ const script = (d: FakeDaemon, rounds: Array<{ frame: Frame; said?: Array<{ from: string; text: string }> }>) => {+ let at = 0+ const now = () => rounds[Math.min(at, rounds.length - 1)]+ d.extra.agents_list = (payload) => {+ const f = now().frame+ return { agents: payload.includeStopped || f.status !== 'stopped' ? [f] : [] }+ }+ d.extra.cloud_transcript = () => ({ messages: (now().said ?? []).map((m, i) => ({ id: String(i), at: '', ...m })) })+ return () => { at++ }+ }+ const lines = (out: string[]) => out.map((l) => JSON.parse(l) as Record<string, unknown>)++ it('follows a cloud harness: one line a change, its question and its answer, until it stops (exit 4)', async () => {+ const d = new FakeDaemon()+ const asked = [{ from: 'person', text: 'add a slugify helper' }]+ const question = [...asked, { from: 'agent', text: 'Question: kebab or snake case?' }]+ const answer = [...question, { from: 'person', text: 'kebab' }, { from: 'agent', text: 'Summary: added slugify with tests.' }]+ const next = script(d, [+ { frame: cloud('devin', 'starting', { updatedAt: '1' }) },+ { frame: cloud('devin', 'working', { updatedAt: '2' }), said: asked },+ { frame: cloud('devin', 'working', { updatedAt: '2' }), said: asked },+ { frame: cloud('devin', 'needs_input', { updatedAt: '3' }), said: question },+ { frame: cloud('devin', 'needs_input', { updatedAt: '3' }), said: question },+ { frame: cloud('devin', 'working', { updatedAt: '4' }), said: [...question, { from: 'person', text: 'kebab' }] },+ { frame: cloud('devin', 'idle', { updatedAt: '5' }), said: answer },+ { frame: cloud('devin', 'idle', { updatedAt: '5' }), said: answer },+ { frame: cloud('devin', 'stopped', { updatedAt: '6', status: 'stopped' }), said: answer },+ ])+ const h = harness(d, { sleep: async () => { h.advance(1_000); next() } })+ expect(await watchCommand(['devin', '--json'], h.deps)).toBe(EXIT.stopped)+ const said = lines(h.out)+ expect(said.map((l) => l.event)).toEqual(['started', 'working', 'needs_person', 'working', 'done', 'stopped'])+ expect(said[2]).toMatchObject({ name: 'devin', agent: 'devin-cloud', state: 'needs-input', question: 'Question: kebab or snake case?', truncated: false,+ cloud: { state: 'needs_input' }, links: [{ label: 'Session', url: 'https://app.devin.ai/sessions/1' }] })+ expect(said[3]).toMatchObject({ event: 'working', ask: 'kebab' })+ expect(said[4]).toMatchObject({ event: 'done', state: 'idle', summary: 'Summary: added slugify with tests.' })+ expect(said[0].at).toBe(new Date(NOW).toISOString())+ // Read no screen, and the transcript only when the frame moved (the stopped line reads its last answer).+ expect(d.requests.some((r) => r.type === 'agent_close' || r.type === 'session_get')).toBe(false)+ expect(d.requests.filter((r) => r.type === 'cloud_transcript').length).toBe(5)+ expect(said[5]).toMatchObject({ event: 'stopped', summary: 'Summary: added slugify with tests.' })+ })++ it('says a second question as a new line, in the same state', async () => {+ const d = new FakeDaemon()+ const first = [{ from: 'person', text: 'go' }, { from: 'agent', text: 'Which repo?' }]+ const second = [...first, { from: 'person', text: 'lamp' }, { from: 'agent', text: 'Which branch?' }]+ const next = script(d, [+ { frame: cloud('devin', 'needs_input', { updatedAt: '1' }), said: first },+ { frame: cloud('devin', 'needs_input', { updatedAt: '2' }), said: second },+ ])+ const h = harness(d, { sleep: async (ms) => { h.advance(ms); next() } })+ expect(await watchCommand(['devin', '--json', '--timeout', '5s'], h.deps)).toBe(EXIT.timeout)+ expect(lines(h.out).map((l) => l.question)).toEqual(['Which repo?', 'Which branch?'])+ })++ it('follows a harness here by wait\'s looks: working, a question on its screen, then done on two idle looks', async () => {+ const d = new FakeDaemon()+ d.frames = [frame('kid', { activity: { state: 'working' } })]+ d.pages.set('s-kid', [{ events: [ev('user_message', { content: 'fix the test' }), ev('tool_start'), ev('tool_end'), ev('text_delta', { content: 'Fixed: 12 passed.' })], hasMore: false }])+ let round = 0+ const h = harness(d, { sleep: async (ms) => {+ h.advance(ms)+ round+++ // Its screen: a question, then a draft (about to work again), then idle.+ if (round === 2) { d.frames = [frame('kid')]; d.screens.set('kid', ['needs_input', 'draft', 'idle']) }+ } })+ expect(await watchCommand(['kid', '--json', '--timeout', '8s'], h.deps)).toBe(EXIT.timeout)+ const said = lines(h.out)+ expect(said.map((l) => l.event)).toEqual(['working', 'needs_person', 'working', 'done'])+ expect(said[0]).toMatchObject({ state: 'working', ask: 'fix the test' })+ expect(said[1]).toMatchObject({ state: 'needs-input', question: 'Fixed: 12 passed.' })+ expect(said[3]).toMatchObject({ state: 'idle', summary: 'Fixed: 12 passed.', tools: 1 })+ })++ it('says idle, not done, for a harness with nothing asked of it, once it is past its start', async () => {+ const d = new FakeDaemon()+ d.frames = [frame('new', { createdAt: '2026-10-11T11:00:00Z' })]+ const h = harness(d)+ expect(await watchCommand(['new', '--json', '--timeout', '10s'], h.deps)).toBe(EXIT.timeout)+ expect(lines(h.out).map((l) => l.event)).toEqual(['idle'])+ })++ it('prints a line a change for a person, and ends at --timeout while it still works', async () => {+ const d = new FakeDaemon()+ d.frames = [frame('kid', { activity: { state: 'working' } })]+ d.pages.set('s-kid', [{ events: [ev('user_message', { content: 'build it' })], hasMore: false }])+ const h = harness(d)+ expect(await watchCommand(['kid', '--timeout', '10s'], h.deps)).toBe(EXIT.timeout)+ expect(h.out).toEqual(['12:00:00Z kid: working: asked: build it'])+ })++ it('says stopped and exits 4 for a harness gone while it was watched', async () => {+ const d = new FakeDaemon()+ d.frames = [frame('kid', { activity: { state: 'working' } })]+ const h = harness(d, { sleep: async (ms) => { h.advance(ms); d.frames = [] } })+ expect(await watchCommand(['kid', '--json'], h.deps)).toBe(EXIT.stopped)+ expect(lines(h.out).map((l) => l.event)).toEqual(['working', 'stopped'])+ })++ it('looks again after a round that timed out', async () => {+ const d = new FakeDaemon()+ d.frames = [frame('kid', { activity: { state: 'working' } })]+ let first = true+ const real = d.request.bind(d)+ d.request = async (type, payload) => {+ if (type === 'agents_list' && first && d.requests.some((r) => r.type === 'agents_list')) { first = false; throw new AgentClientError('TIMEOUT', 'slow') }+ return real(type, payload)+ }+ const h = harness(d)+ expect(await watchCommand(['kid', '--json', '--timeout', '3s'], h.deps)).toBe(EXIT.timeout)+ expect(lines(h.out).map((l) => l.event)).toEqual(['working'])+ })++ it('keeps a cloud maker\'s state: a Devin that has only finished is needs_person, with its words and providerStatus (#1449)', async () => {+ const d = new FakeDaemon()+ const asked = [{ from: 'person', text: 'add a word counter' }]+ const finished = [...asked, { from: 'agent', text: 'Summary: added it; all 3 tests pass.' }]+ const next = script(d, [+ { frame: cloud('devin', 'working', { updatedAt: '1', cloud: { state: 'working', providerStatus: { status: 'running', detail: 'working' } } }), said: asked },+ { frame: cloud('devin', 'needs_input', { updatedAt: '2', cloud: { state: 'needs_input', providerStatus: { status: 'running', detail: 'waiting_for_user' } } }), said: finished },+ { frame: cloud('devin', 'stopped', { updatedAt: '3', status: 'stopped', cloud: { state: 'stopped', providerStatus: { status: 'suspended', detail: 'inactivity' } } }), said: finished },+ ])+ const h = harness(d, { sleep: async (ms) => { h.advance(ms); next() } })+ expect(await watchCommand(['devin', '--json'], h.deps)).toBe(EXIT.stopped)+ const said = lines(h.out)+ expect(said.map((l) => l.event)).toEqual(['working', 'needs_person', 'stopped'])+ expect(said[1]).toMatchObject({ question: 'Summary: added it; all 3 tests pass.', cloud: { providerStatus: { status: 'running', detail: 'waiting_for_user' } } })+ // Put to sleep after it finished: the stopped line still carries the answer.+ expect(said[2]).toMatchObject({ state: 'stopped', summary: 'Summary: added it; all 3 tests pass.', cloud: { providerStatus: { status: 'suspended', detail: 'inactivity' } } })+ })++ it('says what the harness was asked without the line harness new puts before it', async () => {+ const d = new FakeDaemon()+ d.frames = [frame('kid', { activity: { state: 'working' } })]+ d.pages.set('s-kid', [{ events: [ev('user_message', { content: '[from Claude Code outside Harness · studio, the agent that started you. It reads your answer itself.]\n\nbuild it' })], hasMore: false }])+ const h = harness(d)+ expect(await watchCommand(['kid', '--json', '--timeout', '1s'], h.deps)).toBe(EXIT.timeout)+ expect(lines(h.out)[0]).toMatchObject({ event: 'working', ask: 'build it' })+ })++ it('takes one name, a whole --chars and a duration', async () => {+ const d = new FakeDaemon()+ d.frames = [frame('a'), frame('b')]+ for (const [argv, said] of [+ [[], 'Name the harness to watch.'],+ [['a', 'b'], 'Watch one harness.'],+ [['a', '--chars', '0'], '--chars takes a whole number.'],+ ] as const) {+ const h = harness(d)+ expect(await watchCommand(argv, h.deps)).toBe(EXIT.usage)+ expect(h.err[0]).toBe(said)+ }+ })+})diff --git a/cli/src/agentClient/commands.ts b/cli/src/agentClient/commands.tsindex ab730318d..732944002 100644--- a/cli/src/agentClient/commands.ts+++ b/cli/src/agentClient/commands.ts@@ -81,6 +81,16 @@ Exit status: 0 idle or closed by you, 3 one needs the person (a question or a pe124 timed out.--timeout takes 90s, 30m, 2h; 0 waits as long as it takes.${ON_MACHINE}`+export const WATCH_USAGE = `Usage: harness watch [--machine <name>] <name> [--chars N] [--timeout 30m] [--json]++Follows one harness and prints a line each time it changes: started, working, needs_person (its last words),+done (its answer), idle (nothing asked of it), failed, stopped (with its last answer). With --json each line is one+JSON object, for a program to read. The first line is how it stands now; the same state with new words is a new line.+It looks every 3 s, as wait does. A cloud harness's state is its maker's: Devin Cloud says needs_person both when it+asks and when it has only finished, so read the words and cloud.providerStatus.+Exit status: 4 once it stops or is gone, 124 when --timeout passes. --timeout takes 90s, 30m, 2h; 0, the default,+follows it as long as it lives.+${ON_MACHINE}`export const CLOSE_USAGE = `Usage: harness close [--machine <name>] <name> [--now] [--json]Saves the harness's screen and stops it. Its conversation is kept: the person can resume it.@@ -1033,6 +1043,130 @@ export function waitCommand(argv: readonly string[], deps: ClientDeps = {}): Pro})}+// ── watch ──────────────────────────────────────────────────────────────────────────────────────────++/** What `harness watch` says changed. `idle`: idle with nothing asked of it, so nothing done to report. */+export type WatchEvent = 'started' | 'working' | 'needs_person' | 'done' | 'idle' | 'failed' | 'stopped'++/** A cloud harness's maker state as an event; none while it is unknown. */+const CLOUD_EVENTS: Partial<Record<State, WatchEvent>> = {+ starting: 'started', installing: 'started', working: 'working', 'needs-input': 'needs_person', idle: 'done', failed: 'failed', stopped: 'stopped',+}++/** The state a harness here is in at each event: its frame says only working or idle, the screen the rest. */+const EVENT_STATES: Record<WatchEvent, State> = {+ started: 'starting', working: 'working', needs_person: 'needs-input', done: 'idle', idle: 'idle', failed: 'failed', stopped: 'stopped',+}++/**+ * Follows one harness by `wait`'s looks (the maker's state for a cloud harness; the daemon's activity, then the screen,+ * then two idle looks on one turn for one here) and prints each change once: what a program driving something from a+ * harness (lampOS's lamp, which moves and speaks as Devin works) polled `show` for and worked out itself. Read-only:+ * the same requests over the same local socket, so an older harnessd answers it as it answers `wait`.+ */+export function watchCommand(argv: readonly string[], deps: ClientDeps = {}): Promise<number> {+ return run(WATCH_USAGE, deps, wantsJson, argv, async (s) => {+ const { names, flags, machine } = words(argv, { '--chars': 'value', '--timeout': 'value', '--json': 'flag' })+ if (names.length !== 1) throw new UsageError(names.length ? 'Watch one harness.' : 'Name the harness to watch.')+ const chars = flags.has('--chars') ? Number(flags.get('--chars')) : DEFAULT_CHARS+ if (!Number.isInteger(chars) || chars < 1) throw new UsageError('--chars takes a whole number.')+ const timeoutMs = flags.has('--timeout') ? parseDuration(String(flags.get('--timeout'))) : 0+ const json = flags.has('--json')+ const away = await machineOf(s, s.where(), machine)+ const o = await opened(s)+ let t: Target | null = null+ try {+ t = await target(s, o, names[0], away)+ const h = t+ const deadline = timeoutMs > 0 ? s.now() + timeoutMs : Infinity+ /** The last line printed, as its event and the turn it spoke of: a line is printed only when this changes. */+ let printed: string | null = null+ let sawWorking = false+ let idle: { turn: string; looks: number } | null = null+ /** The turn read for the frame last seen changed (its `updatedAt`): read again only when that moves. */+ let turnFor: { updatedAt: string; turn: Awaited<ReturnType<typeof readLastTurn>> } | null = null+ const turnNow = async () => {+ const updatedAt = h.frame.updatedAt ?? ''+ if (!turnFor || turnFor.updatedAt !== updatedAt || !updatedAt) turnFor = { updatedAt, turn: await readLastTurn(h, 1) }+ return turnFor.turn+ }+ const keyOf = (turn: Awaited<ReturnType<typeof readLastTurn>>): string => (turn ? `${turn.ask}\u0000${turn.tools}\u0000${turn.answer.length}` : '')+ /** This round's event: null while it can't be told yet (an idle look not yet confirmed, a state unknown). */+ const look = async (): Promise<WatchEvent | null> => {+ const frame = (await list(h.daemon, false)).find((f) => f.id === h.frame.id)+ if (!frame) {+ const stopped = (await list(h.daemon, true)).find((f) => f.id === h.frame.id)+ if (stopped) h.frame = stopped+ return 'stopped'+ }+ h.frame = frame+ if (frame.status === 'stopped') return 'stopped'+ if (frame.location === 'cloud') return CLOUD_EVENTS[stateOf(frame)] ?? null+ const screen = frame.activity?.state === 'working' ? 'working' : await inspect(h)+ if (screen === 'working' || screen === 'draft') { sawWorking = true; idle = null; return 'working' }+ if (screen === 'needs-input') { idle = null; return 'needs_person' }+ if (screen === null && stateOf(frame) !== 'idle') { idle = null; return null }+ // Idle on two looks in a row with the same last turn, as `wait` decides it (#1180).+ const turn = await turnNow()+ if (toldPending(o, h, turn, s.now())) { idle = null; return 'working' }+ const key = keyOf(turn)+ const looks = idle && idle.turn === key ? idle.looks + 1 : 1+ idle = { turn: key, looks }+ if (looks < 2) return null+ if (sawWorking || turn?.answered) return 'done'+ const age = frame.createdAt ? s.now() - Date.parse(frame.createdAt) : Infinity+ return age > STARTING_MS && looks >= QUIET_LOOKS ? 'idle' : null+ }+ for (;;) {+ const event = await look().catch((error) => {+ // A round that timed out (its machine slow for a moment) is looked at again next round, as `wait` does.+ if (error instanceof AgentClientError && error.code === 'TIMEOUT') return null+ throw error+ })+ if (event) {+ const said = event !== 'started' && event !== 'idle'+ const turn = said ? await turnNow() : null+ const key = `${event}\u0000${event === 'working' ? turn?.ask ?? '' : keyOf(turn)}`+ if (key !== printed) {+ printed = key+ printWatch(s, json, chars, h, event, turn)+ }+ if (event === 'stopped') return EXIT.stopped+ }+ if (s.now() >= deadline) return EXIT.timeout+ await s.sleep(Math.min(s.intervalMs, Math.max(0, deadline - s.now())))+ }+ } finally { if (t?.remote) t.daemon.close(); o.daemon.close() }+ })+}++/** The line `harness new` puts before an agent's task, saying who started it (`startHeader`): not the person's words. */+const START_HEADER = /^\[from [^\]\n]*, the (?:agent|harness) that started you\. It reads your answer itself\.\]\n\n/+const withoutStartHeader = (ask: string): string => ask.replace(START_HEADER, '')++/** One `watch` line: a JSON object with `--json`, else the time, the harness, the event and its words. */+function printWatch(s: Setup, json: boolean, chars: number, t: Target, event: WatchEvent,+ turn: { ask: string | null; answer: string; tools: number } | null): void {+ const text = turn?.answer ?? ''+ const words: Record<string, unknown> = event === 'working' ? { ask: turn?.ask ? withoutStartHeader(turn.ask) : null }+ : event === 'needs_person' ? { question: clip(text, chars), truncated: text.length > chars }+ : event === 'done' || event === 'failed' ? { summary: clip(text, chars), truncated: text.length > chars, tools: turn?.tools ?? 0 }+ // Stopped after a turn (Devin put to sleep once it finished, #1449): its answer is still the one to read.+ : event === 'stopped' && text ? { summary: clip(text, chars), truncated: text.length > chars }+ : {}+ const cloud = cloudMeta(t.frame)+ const at = new Date(s.now()).toISOString()+ const line = {+ event, at, name: t.frame.name ?? t.frame.id.slice(0, 8), id: t.frame.id, agent: engineName(t.frame.engine ?? ''),+ state: t.frame.location === 'cloud' && event !== 'stopped' ? stateOf(t.frame) : EVENT_STATES[event], ...words,+ ...(cloud ? { cloud } : {}), ...(t.frame.cloud?.links?.length ? { links: t.frame.cloud.links } : {}),+ }+ if (json) { s.out(JSON.stringify(line)); return }+ const said = typeof words.question === 'string' ? words.question : typeof words.summary === 'string' ? words.summary+ : typeof words.ask === 'string' ? `asked: ${clip(words.ask, 200)}` : ''+ s.out(`${at.slice(11, 19)}Z ${line.name}: ${event.replace('_', ' ')}${said ? `: ${said}` : ''}`)+}+// ── close ──────────────────────────────────────────────────────────────────────────────────────────export function closeCommand(argv: readonly string[], deps: ClientDeps = {}): Promise<number> {diff --git a/cli/src/agentClient/help.ts b/cli/src/agentClient/help.tsindex 27417ac21..811c2e3ac 100644--- a/cli/src/agentClient/help.ts+++ b/cli/src/agentClient/help.ts@@ -2,7 +2,7 @@* `harness help agents`: all an agent needs on one screen (docs/design/2026-10-15-agent-experience.md, part 4). Each* verb's line is its own usage's first line, so this cannot name an option the verb does not take.*/-import { CLOSE_USAGE, EXIT, PS_USAGE, SHOW_USAGE, SPAWN_LIMITS, TELL_USAGE, WAIT_USAGE, WHOAMI_USAGE } from './commands.js'+import { CLOSE_USAGE, EXIT, PS_USAGE, SHOW_USAGE, SPAWN_LIMITS, TELL_USAGE, WAIT_USAGE, WATCH_USAGE, WHOAMI_USAGE } from './commands.js'import { NEW_USAGE } from '../lib/newCommand.js'import { SEND_USAGE } from '../messages/command.js'import { outsideCaller } from './model.js'@@ -23,6 +23,7 @@ export function agentsHelp(): string {` ${synopsis(NEW_USAGE)}`,` ${synopsis(WAIT_USAGE)}`,` ${synopsis(SHOW_USAGE)}`,+ ` ${synopsis(WATCH_USAGE)} a line each time it changes, for a program that follows it`,` ${synopsis(CLOSE_USAGE)}`,` ${synopsis(TELL_USAGE)} more work for one you started, while the person allows it`,` ${sendLine()}`,diff --git a/cli/src/cli.ts b/cli/src/cli.tsindex a6d155f79..e1a9a181b 100644--- a/cli/src/cli.ts+++ b/cli/src/cli.ts@@ -170,10 +170,11 @@ Machine:harness ps [--all] the harnesses here: state, who started each, what each is aboutharness show <name> a harness's state and last turn: what it was asked and what it answeredharness wait <name>[,<name>] wait until they stop working (--any, --timeout 30m); exit 3 = needs the person+ harness watch <name> follow a harness: a line (--json: an object) each time it changes, until it stopsharness close <name> [--now] save a harness's screen and stop it; an agent closes only what it startedharness tell <name> -- <w> from an agent's pane: more work for a harness it started (agents-tell-agents)harness reply <name> -- <w> say words to a cloud harness (Devin Cloud, Cursor Cloud, Fo): its answer or what next- new, ps, show, wait, tell, reply and close take --machine <name> for another of your+ new, ps, show, wait, watch, tell, reply and close take --machine <name> for another of yourmachines: \`harness show --machine office x\`harness mcp the agent verbs as an MCP server on stdin/stdout, for agents that use MCPharness help agents the agent commands, states, exit codes and rules on one screen@@ -2672,7 +2673,7 @@ async function logsExportCommand(json: boolean): Promise<void> {import { orchestratorCommand } from './orchestrator/command.js'import { paneOwner, sendCommand } from './messages/command.js'-import { agentOrigin, closeCommand, psCommand, replyCommand, showCommand, tellCommand, waitCommand, whoamiCommand } from './agentClient/commands.js'+import { agentOrigin, closeCommand, psCommand, replyCommand, showCommand, tellCommand, waitCommand, watchCommand, whoamiCommand } from './agentClient/commands.js'import { agentsHelp, helpFor } from './agentClient/help.js'import { openUrlCommand } from './agentClient/openUrl.js'import { harnessRunner, mcpCommand } from './agentClient/mcp.js'@@ -2752,6 +2753,9 @@ switch (cmd) {case 'wait':waitCommand(rest, { machines: usableMachines }).then(code => { process.exitCode = code }).catch(onError)break+ case 'watch':+ watchCommand(rest, { machines: usableMachines }).then(code => { process.exitCode = code }).catch(onError)+ breakcase 'close':closeCommand(rest, { machines: usableMachines }).then(code => { process.exitCode = code }).catch(onError)breakdiff --git a/docs/cli.md b/docs/cli.mdindex 64d505c0b..d2e6cd85b 100644--- a/docs/cli.md+++ b/docs/cli.md@@ -110,7 +110,7 @@ of a word in it); `@mini`, the old way, is refused with what to type instead. `-auto|ask|plan|full`, `--name`, `--new [name]` and `--json` are the rest. There is still no`harness split`: panes are arranged in the app.-`harness ps`, `show`, `wait` and `close` take `--machine <name>` too, to read, wait for or close a+`harness ps`, `show`, `wait`, `watch` and `close` take `--machine <name>` too, to read, wait for or close aharness on another of your machines: `harness new claude --machine office --name check -- …`, then`harness wait --machine office check` and `harness show --machine office check`.@@ -120,6 +120,33 @@ A cloud agent starts the same way: `harness new devin-cloud --machine office --rstate, what it said after the last thing it was told, and its links (`links` in JSON). `harness reply <name> --<words>` says the person's answer, or what to do next, to a cloud harness; an agent does not.+`harness watch <name>` follows one harness for a program that acts on it: a line each time it changes, one JSON+object a line with `--json`, until it stops or is gone (exit 4) or `--timeout` passes (exit 124; `0`, the default,+follows it as long as it lives). It decides as `wait` does: the maker's state for a cloud harness; the daemon's+activity, then the screen, then two idle looks on one turn for one here. The first line is how it stands now.++| event | when | with |+|---|---|---|+| `started` | installing or starting | |+| `working` | it works (a draft in its box counts) | `ask`: the last thing it was told |+| `needs_person` | a question or a permission; for a cloud harness, its maker's own state | `question`: its last words, to `--chars` (4000) |+| `done` | idle after a turn | `summary`: its last answer, to `--chars`; `truncated`; `tools` |+| `idle` | idle with nothing asked of it, past its start | |+| `failed` | the cloud says it failed | `summary`, `links` |+| `stopped` | stopped or gone | `summary`: its last answer, when it has one |++Every line has `at`, `name`, `id`, `agent` and `state` (as `show` says it), and `cloud` and `links` for a cloud+harness. The same state with new words (a second question, a new answer) is a new line carrying the whole words again;+the same words are never said twice. **A cloud harness's state is its maker's, not a guess:** Devin Cloud says+`waiting_for_user` both when it asks and when it has only finished (#1449), so `needs_person` comes either way: read+`question` and `cloud.providerStatus` to tell. A Devin put to sleep once it finished is `stopped`+(`providerStatus` `suspended`/`inactivity`), with its answer as `summary`. The words are the harness's own, as they+are, Devin's `ATTACHMENT:` lines included; `ask` leaves out the line `harness new` puts before a task. It looks every+3 s, as `wait` does, so a watch of another machine's harness is one `agents_list` over the machine link every 3 s. It reads with the requests+`wait` makes, over the same socket: one `agents_list` a round, the screen for a harness here that the daemon does not+already say is working, and the last transcript page only when the harness changed. Nothing reports failing tests+during a turn yet, so there is no event for them.+`harness whoami` says, for an agent, where it is and what it may do before it acts (`--json` gives the same as`context`); the top of an agent's `harness ps` begins with it, and `harness mcp` puts it in its instructions: