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
Merge origin/main (#1029-#1033) into feat/after-outcome
review3b0324bc4305
diff --cc src/core/canvas-control-core.tsindex 6434b8546,dc1d5d28f..904eed352--- a/src/core/canvas-control-core.ts+++ b/src/core/canvas-control-core.ts@@@ -31,14 -31,10 +31,16 @@@ import} from '../shared/station-notice'import { STATION_NOTICE_FROM } from '../shared/agents/agent-messaging'import { PR_DEADLINE_DEFAULT_MS, PR_DEADLINE_MAX_MS, PR_WAIT_MAX, afterPrFlagRefusal } from '../shared/pr-wait'+import {+ OUTCOME_NOTE_MAX,+ REPORT_OUTCOME_VERB,+ SUCCESS_WAIT_MAX,+ afterSuccessFlagRefusal+} from '../shared/station-outcome'import { ISSUE_BRANCH_SLUG_MAX, issueWorktreeBranch } from '../shared/issue-worktree'+ import { CONTROL_REQUEST_TIMEOUT_MS } from '../shared/control-confirm'import {+ REQUEST_ID_HINT_LEAD,REQUEST_ID_MAX_LENGTH,REQUEST_ID_OUTCOME_GLOSS,REQUEST_ID_REPLAYED_LEAD,diff --cc src/main/index.tsindex 770cedcf2,1f3a4d20b..df1638118--- a/src/main/index.ts+++ b/src/main/index.ts@@@ -3892,32 -3909,41 +3940,45 @@@ app.whenReady().then(async () =>// it keeps the renderer's view consistent from the moment ownership exists.pushBrowserLeases()}- }- // Record a project grant the moment an open-project succeeds — the open-browser ledger- // pattern above, same conditions: ONLY when the caller's identity verdict for THIS request- // was `verified` (main's own verdict, never anything off the wire) AND the renderer's reply- // carries a non-empty projectId. Inert until PR 2: today the renderer's `default:` case- // answers `unknown verb: open-project` with ok: false, so nothing is ever recorded — but the- // record path ships fail-closed and finished, not stubbed.- if (verb === 'open-project') {- // The whole decision (verified && ok && string projectId → grant; cap race detection) is- // the PURE recordOpenProjectGrant — proven branch by branch in project-grants.test.ts.- // 'cap' = the pre-forward atCap() check passed but a concurrent open-project from the same- // caller filled the last slot while this one was in flight (PR #362 review, M1): the- // caller must NOT hear ok while holding no targeting right, so the named refusal replaces- // the success reply. Nothing is lost — open-project is idempotent (B1), so a re-run once- // grants have cleared returns the same project id and records the grant.- if (recordOpenProjectGrant(nodeId, result, verified) === 'cap') {- console.warn(- `[project-grants] grant cap raced for caller ${nodeId}: open-project succeeded but ` +- 'the grant was not recorded; replying open-project-grant-cap'- )- return { ok: false, error: OPEN_PROJECT_GRANT_CAP, message: OPEN_PROJECT_GRANT_CAP }+ // Record a project grant the moment an open-project succeeds — the open-browser ledger+ // pattern above, same conditions: ONLY when the caller's identity verdict for THIS request+ // was `verified` (main's own verdict, never anything off the wire) AND the renderer's reply+ // carries a non-empty projectId. (open-project never claims a request-ledger row, so it never+ // gets a late answer; it is here so no finishing step can be left off one path.)+ if (verb === 'open-project') {+ // The whole decision (verified && ok && string projectId → grant; cap race detection) is+ // the PURE recordOpenProjectGrant — proven branch by branch in project-grants.test.ts.+ // 'cap' = the pre-forward atCap() check passed but a concurrent open-project from the same+ // caller filled the last slot while this one was in flight (PR #362 review, M1): the+ // caller must NOT hear ok while holding no targeting right, so the named refusal replaces+ // the success reply. Nothing is lost — open-project is idempotent (B1), so a re-run once+ // grants have cleared returns the same project id and records the grant.+ if (recordOpenProjectGrant(nodeId, answer, verified) === 'cap') {+ console.warn(+ `[project-grants] grant cap raced for caller ${nodeId}: open-project succeeded but ` ++ 'the grant was not recorded; replying open-project-grant-cap'+ )+ return { ok: false, error: OPEN_PROJECT_GRANT_CAP, message: OPEN_PROJECT_GRANT_CAP }+ }}++ // New work handed to a station through canvas control withdraws its outcome report — the++ // "new task" rule in src/core/station-outcome-store.ts. On the answer (prompt or late), and++ // only on success.++ clearOutcomesAfterControl(stationOutcomes, verb, args, answer, nodeId)+ return answer}- // New work handed to a station through canvas control withdraws its outcome report — the- // "new task" rule in src/core/station-outcome-store.ts. After the answer, and only on success.- clearOutcomesAfterControl(stationOutcomes, verb, args, result, nodeId)+ // The timeout is NAMED, and what it says depends on the verb and on whether the request ledger+ // holds a row for this call (`controlTimeoutError`): a DENIAL is a different answer (`denied by+ // user`, final), and only a confirm-gated verb, whose dialog dismisses itself at the same+ // deadline (ConfirmState.expiresAt), may be called safe to retry. An open is not cancelled by+ // main giving up, so its timeout is indeterminate and its late answer goes back to the request+ // ledger through `onLateAnswer` — finished first.+ const result = await controlForwarder.forward(+ verb,+ (requestId) =>+ target.webContents.send(IPC.agentControl, { requestId, sourceNodeId: nodeId, verb, args }),+ { onLate: onLateAnswer, finish: finishAnswer }+ )return result})initMediaProtocol()diff --cc src/main/station-outcome-wiring.test.tsindex f0caf9f9c,000000000..dd839adecmode 100644,000000..100644--- a/src/main/station-outcome-wiring.test.ts+++ b/src/main/station-outcome-wiring.test.ts@@@ -1,118 -1,0 +1,122 @@@+import { describe, it, expect } from 'vitest'+import { readFileSync } from 'node:fs'++/**+ * SOURCE-LEVEL pins for `report-outcome` / `--after-success` wiring — the same remedy+ * `hook-verified-parity.test.ts` uses for the same class of hole: every piece below is well-typed+ * whether or not it is wired (an optional dep left out, a store never registered, a handler that+ * forgets to clear), so a feature can be plumbed end to end, pass `npm run typecheck` and every+ * unit test, and ship INERT on one shell. The behaviour itself is proven against real code in+ * `shared/station-outcome.test.ts`, `core/station-outcome-store.test.ts`,+ * `renderer/lib/pendingLaunch.test.ts` and `server/headless-node-factory.test.ts`.+ */+const read = (rel: string): string =>+ readFileSync(new URL(rel, import.meta.url), 'utf8').replace(/\r\n/g, '\n')+const main = read('./index.ts')+const serverControl = read('../server/canvas-control.ts')+const serverIndex = read('../server/index.ts')+const canvas = read('../renderer/canvas/Canvas.tsx')++describe('desktop main', () => {+ const handler = main.slice(main.indexOf('hookServer.setControlHandler('))++ it('runs the --after-success shape gate before anything is forwarded', () => {+ const gate = handler.indexOf('afterSuccessFlagRefusal(verb, args)')+ expect(gate).toBeGreaterThan(-1)+ expect(gate).toBeLessThan(handler.indexOf("'window unavailable'"))+ })++ it('answers report-outcome in MAIN, never forwarding it to the renderer', () => {+ const at = handler.indexOf("if (verb === 'report-outcome') {")+ expect(at).toBeGreaterThan(-1)+ expect(at).toBeLessThan(handler.indexOf('controlForwarder.forward('))+ const block = handler.slice(at, at + 600)+ expect(block).toContain('handleReportOutcome(')+ expect(block).toContain('store: stationOutcomes')+ expect(block).toContain('{ nodeId, args, verified }')+ })+- it('withdraws a station\'s report after new work lands, on the answered result', () => {- const clear = handler.indexOf('clearOutcomesAfterControl(stationOutcomes, verb, args, result, nodeId)')- expect(clear).toBeGreaterThan(handler.indexOf('controlForwarder.forward('))++ it('withdraws a station\'s report after new work lands — in the finishing step both answers take', () => {++ // `finishAnswer` runs on the prompt answer AND on a late one (#1033), so a send whose answer++ // arrives after main's timeout still withdraws the report.++ const finish = handler.slice(handler.indexOf('const finishAnswer = ('))++ const body = finish.slice(0, finish.indexOf('\n }\n'))++ expect(body).toContain('clearOutcomesAfterControl(stationOutcomes, verb, args, answer, nodeId)')++ expect(handler).toMatch(/finish: finishAnswer/)+ })++ it('registers the read channel and pushes every change to the window', () => {+ expect(main).toContain('registerStationOutcomeIpc(corePlatform, () => stationOutcomes)')+ expect(main).toMatch(/new StationOutcomeStore\(\(records\) =>\s*sendToMain\(IPC\.stationOutcomeChanged, records\)/)+ })+})++describe('Server Edition', () => {+ it('routes report-outcome through the SAME core handler and re-evaluates its arms', () => {+ const at = serverControl.indexOf('reportOutcome: (sourceNodeId, args, verified) =>')+ expect(at).toBeGreaterThan(-1)+ const block = serverControl.slice(at, at + 900)+ expect(block).toContain('handleReportOutcome(')+ expect(block).toContain('onRecorded: () => void factory.refreshArmed()')+ })++ it('hands the factory the outcome store, so --after-success is honoured headlessly', () => {+ expect(serverControl).toContain('outcomeOf: (nodeId) => stationOutcomes.get(nodeId)')+ })++ it('wraps its control handler with the same "new work withdraws a report" rule', () => {+ expect(serverControl).toContain(+ 'clearOutcomesAfterControl(stationOutcomes, req.verb, req.args, reply, req.nodeId)'+ )+ })++ it('registers the read channel whether or not canvas control comes up', () => {+ expect(serverIndex).toContain(+ 'registerStationOutcomeIpc(platform, () => canvasControl?.stationOutcomes ?? null)'+ )+ })+})++describe('the desktop renderer', () => {+ it('mirrors core\'s store', () => {+ expect(canvas).toContain('useEffect(() => installStationOutcomeWiring(window.nodeTerminal), [])')+ })++ it('folds --after-success into --after once, before any open path resolves --after', () => {+ const fold = canvas.indexOf('args = { ...args, after: [...new Set([...plainAfter, ...successIdsPre])].join(\',\') }')+ expect(fold).toBeGreaterThan(-1)+ // Before every consumer of `args.after`: the live resolver, the cold resolver, the run-now belt.+ expect(fold).toBeLessThan(canvas.indexOf('const resolveAfter = (): string[] | null | undefined => {'))+ expect(fold).toBeLessThan(canvas.indexOf('const coldAfter = coldResolveAfter('))+ expect(fold).toBeLessThan(canvas.indexOf('reply({ ok: false, error: RUN_NOW_AFTER_REFUSAL })'))+ expect(fold).toBeLessThan(canvas.indexOf('routeControlSource(projects, activeId, sourceNodeId)'))+ })++ it('checks that a success station can REPORT, on the live and the cold path', () => {+ expect(canvas).toMatch(/successIdsPre\.includes\(depId\) && !sourceIsControlCapable\(depAgent\)/)+ expect(canvas).toMatch(/const coldCannotReport = successIdsPre\.find\(/)+ })++ it('attaches the hold on the live path (armAfter) and the cold path', () => {+ const armAfter = canvas.slice(canvas.indexOf('const armAfter = ('), canvas.indexOf('const addGrouped = ('))+ expect(armAfter).toContain('withSuccessHold(')+ expect(armAfter).toContain('successHoldPre')+ const cold = canvas.slice(+ canvas.indexOf('if (canColdOpen(verb)) {'),+ canvas.indexOf('if (answersOffCanvas(verb) || answersFromStoredNodes(verb)) {')+ )+ expect(cold).toMatch(/withSuccessHold\(/)+ })++ it('judges the gate with the outcome store, and re-runs off a PRIMITIVE signature', () => {+ const effect = canvas.slice(canvas.indexOf('const ready = launchesToFire('), canvas.indexOf('}, [nodes, armedDepSig'))+ expect(effect).toContain('{ outcomes: useStationOutcomes.getState().byId, now: Date.now() }')+ const sig = canvas.slice(canvas.indexOf('const armedSuccessSig = useStationOutcomes((s) => {'))+ expect(sig.slice(0, 900)).toContain('sig +=')+ })++ it('list reads the outcomes on both the live and the stored path', () => {+ const hits = canvas.split('useStationOutcomes.getState().byId)').length - 1+ expect(hits).toBeGreaterThanOrEqual(2)+ })+})