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(launch): pin UI intent through asynchronous submission
reviewf12356cf2820
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex 8389a6cf6..786ac6ccb 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -1,5 +1,5 @@import { isLaunchShell } from '@shared/agents/pane'-import { createLaunchWriter, launchCommand, registerLaunchWriter } from '../terminal/launch-command'+import { createLaunchWriter, deliverInitialLaunch, launchCommand, registerLaunchWriter } from '../terminal/launch-command'import { Suspense, lazy, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'import { NODE_MIN_SIZES } from '../lib/nodeSizing'import {@@ -3545,24 +3545,14 @@ export function TerminalNode({// forget it.if (data.initialCommand) {const command = data.initialCommand- // Publish durable intent before the asynchronous settle/echo work. The automatic- // Canvas loop leaves this manual-only record to this writer; an interrupted mount- // retains it for recovery instead of starting a second writer.- updateNodeData(id, { pendingLaunch: { after: [], command, manualOnly: true } })- whenShellSettled(() => {- void launchWriter(command, false).then((outcome) => {- if (outcome === 'submitted') {- updateNodeData(id, { initialCommand: undefined, pendingLaunch: undefined })- } else {- // Keep the exact brief and expose Run now, including an interrupted settle.- updateNodeData(id, {- initialCommand: undefined,- pendingLaunch: { after: [], command, manualOnly: true }- })- useLaunchDelivery.getState().markFailed(id, 1)- if (outcome === 'line-too-long') setCo(termKey, { launchTooLongBytes: lineBytes(command) })- }- })+ deliverInitialLaunch(command, {+ whenReady: whenShellSettled,+ write: launchWriter,+ update: (patch) => updateNodeData(id, patch),+ onFailure: (outcome) => {+ useLaunchDelivery.getState().markFailed(id, 1)+ if (outcome === 'line-too-long') setCo(termKey, { launchTooLongBytes: lineBytes(command) })+ }})} else if (coldStart && canColdRestore) {// Cold restart of an agent node: the live agent is gone, so re-launch it. Resume thediff --git a/src/renderer/terminal/launch-command.test.ts b/src/renderer/terminal/launch-command.test.tsindex 2e96c3ed3..9cd3abd0a 100644--- a/src/renderer/terminal/launch-command.test.ts+++ b/src/renderer/terminal/launch-command.test.ts@@ -1,5 +1,5 @@import { afterEach, describe, expect, it, vi } from 'vitest'-import { createLaunchWriter, launchCommand, registerLaunchWriter } from './launch-command'+import { createLaunchWriter, deliverInitialLaunch, launchCommand, registerLaunchWriter } from './launch-command'import { KILL_LINE, WINDOWS_KILL_LINE, VERIFY_TIMEOUT_MS, DELIVERY_ATTEMPTS } from './command-delivery'function fixture(fresh = true, killLine = KILL_LINE) {@@ -123,3 +123,34 @@ describe('durable launch delivery', () => {expect(await launchCommand('node', 'cmd', true)).toBe('cancelled')})})++describe('UI initial-command lifecycle', () => {+ it.each(['submitted', 'cancelled', 'line-too-long'] as const)('retains intent through settle and only discards it on submitted (%s)', async (outcome) => {+ let ready!: () => void+ let settle!: (outcome: 'submitted' | 'cancelled' | 'line-too-long') => void+ const state: { initialCommand?: string; pendingLaunch?: { command: string } } = { initialCommand: 'claude original-brief' }+ const write = vi.fn(() => new Promise<'submitted' | 'cancelled' | 'line-too-long'>((resolve) => { settle = resolve }))+ const onFailure = vi.fn()+ deliverInitialLaunch(state.initialCommand!, {+ whenReady: (run) => { ready = run }, write,+ update: (patch) => { Object.assign(state, patch) }, onFailure+ })+ // Teardown/park before ready cannot lose the brief: both live and durable intent remain.+ expect(write).not.toHaveBeenCalled()+ expect(state.initialCommand).toBe('claude original-brief')+ expect(state.pendingLaunch).toEqual({ after: [], command: 'claude original-brief', manualOnly: true })+ ready()+ expect(write).toHaveBeenCalledWith('claude original-brief', false)+ expect(state.initialCommand).toBe('claude original-brief')+ settle(outcome)+ await Promise.resolve()+ expect(state.initialCommand).toBeUndefined()+ if (outcome === 'submitted') {+ expect(state.pendingLaunch).toBeUndefined()+ expect(onFailure).not.toHaveBeenCalled()+ } else {+ expect(state.pendingLaunch?.command).toBe('claude original-brief')+ expect(onFailure).toHaveBeenCalledWith(outcome)+ }+ })+})diff --git a/src/renderer/terminal/launch-command.ts b/src/renderer/terminal/launch-command.tsindex 157f25202..62eea5482 100644--- a/src/renderer/terminal/launch-command.ts+++ b/src/renderer/terminal/launch-command.ts@@ -47,3 +47,26 @@ export function createLaunchWriter(opts: {return inFlight}}++/** Keep UI launch intent through the asynchronous shell settle and submission boundary. */+export function deliverInitialLaunch(command: string, opts: {+ whenReady(run: () => void): void+ write: Writer+ update(patch: {+ initialCommand?: undefined+ pendingLaunch?: { after: string[]; command: string; manualOnly: true }+ }): void+ onFailure(outcome: DeliveryOutcome): void+}): void {+ const pendingLaunch = { after: [], command, manualOnly: true as const }+ // Do not discard the live initialCommand before settle. The durable pending record also+ // prevents the Canvas loop from racing this writer and survives a project switch.+ opts.update({ pendingLaunch })+ opts.whenReady(() => {+ void opts.write(command, false).then((outcome) => {+ opts.update({ initialCommand: undefined,+ pendingLaunch: outcome === 'submitted' ? undefined : pendingLaunch })+ if (outcome !== 'submitted') opts.onFailure(outcome)+ })+ })+}