Skip to content

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.

feat(windows): execute a prompt-bearing agent node's launch intent on Windows panes

review25d14fb7181c
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 7a49858f8..1133c0c43 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -71,6 +71,8 @@ import {
import { useDownloads } from '../lib/useDownloads'
import { fileLinkDialect } from '../terminal/file-link-dialect'
import { hostPlatformFor } from '../terminal/host-platform'
+import { executeHeldLaunch } from '../terminal/launch-intent'
+import { uuid } from '../lib/uuid'
import { sshFs } from '../terminal/ssh-fs'
import type { FsApi, PendingLaunch, PtyApi } from '@shared/types'
import {
@@ -4010,7 +4012,21 @@ export function TerminalNode({
cleanup: (cancel: () => void) => { cleanups.push(cancel) }
}
const launchWriter = createLaunchWriter({ ...launchWriterOptions,
- claimAttempt: (manual, command) => commitLaunch(api, id, command, manual)
+ claimAttempt: (manual, command) => commitLaunch(api, id, command, manual),
+ // A local Windows session-host pane runs pwsh/cmd, where the POSIX launch line breaks on
+ // a quote in the prompt: execute the node's held semantic launch there instead. Every
+ // other pane answers 'fallback' without an IPC (terminal/launch-intent.ts).
+ execute: (command) =>
+ executeHeldLaunch(command, {
+ held: () => (getNode(id) as CanvasNode | undefined)?.data.launchIntent,
+ sessionHost: !!sessionHost,
+ source: session.source,
+ hostPlatform: () => hostPlatformFor(api),
+ executeLaunch: api.pty.executeLaunch
+ ? (request) => api.pty.executeLaunch!(id, request)
+ : undefined,
+ newLaunchId: uuid
+ })
})
const writeWhenShellReady = (cmd: string): void => {
whenShellSettled(() => {
diff --git a/src/renderer/state/workspace.launch-intent.test.ts b/src/renderer/state/workspace.launch-intent.test.ts
new file mode 100644
index 000000000..ef30b04a9
--- /dev/null
+++ b/src/renderer/state/workspace.launch-intent.test.ts
@@ -0,0 +1,67 @@
+// The guard for `data.launchIntent`: every prompt-bearing agent node the factory builds carries
+// the semantic twin of its typed line (so a Windows pane can execute it instead of mis-parsing
+// POSIX quotes), bound to that EXACT line — and the typed line itself is byte-identical to before.
+import { describe, it, expect, afterEach } from 'vitest'
+import { createAgentNode, duplicateNode, flowToNodeStates } from './workspace'
+import { resetClaudeCliCapsForTests } from './permissionMode'
+import { UNKNOWN_CLAUDE_CLI_CAPS } from '@shared/types'
+
+afterEach(() => resetClaudeCliCapsForTests())
+
+const NASTY = `it's "x" & 50% ^y`
+
+describe('createAgentNode launchIntent', () => {
+ it('pins the POSIX line byte-for-byte and binds the intent to it', () => {
+ const n = createAgentNode('claude', 0, '/repo', undefined, NASTY)
+ expect(n.data.initialCommand).toBe(`claude 'it'\\''s "x" & 50% ^y'`)
+ expect(n.data.launchIntent).toEqual({
+ command: n.data.initialCommand,
+ intent: { kind: 'agent', action: 'start', agentId: 'claude', prompt: NASTY }
+ })
+ })
+
+ it('carries the minted id and the mode the typed line carries', () => {
+ resetClaudeCliCapsForTests({ ...UNKNOWN_CLAUDE_CLI_CAPS, version: '2.1.226', sessionIdFlag: true })
+ const n = createAgentNode('claude', 0, '/repo', undefined, 'go', undefined, undefined, 'acceptEdits')
+ expect(n.data.initialCommand).toBe(
+ `claude 'go' --permission-mode acceptEdits --session-id ${n.data.agentSessionId}`
+ )
+ expect(n.data.launchIntent?.intent).toEqual({
+ kind: 'agent',
+ action: 'start',
+ agentId: 'claude',
+ prompt: 'go',
+ permissionMode: 'acceptEdits',
+ newSessionId: n.data.agentSessionId
+ })
+ })
+
+ it('holds a prompt file by path while the POSIX line keeps its `$(cat …)` form', () => {
+ const n = createAgentNode(
+ 'claude', 0, '/repo', undefined, undefined, undefined, undefined, undefined, undefined, undefined, '/tmp/brief.md'
+ )
+ expect(n.data.initialCommand).toBe(`claude "$(cat '/tmp/brief.md')"`)
+ expect(n.data.launchIntent).toEqual({
+ command: n.data.initialCommand,
+ intent: { kind: 'agent', action: 'start', agentId: 'claude' },
+ promptFile: '/tmp/brief.md'
+ })
+ })
+
+ it('holds nothing without a prompt, on an SSH node, or with a model override', () => {
+ expect(createAgentNode('claude', 0).data.launchIntent).toBeUndefined()
+ const ssh = { server: 'h', remoteCwd: '/r' } as never
+ expect(createAgentNode('claude', 0, '/r', undefined, 'go', ssh).data.launchIntent).toBeUndefined()
+ expect(
+ createAgentNode('claude', 0, '/r', undefined, 'go', undefined, undefined, undefined, undefined, 'opus').data
+ .launchIntent
+ ).toBeUndefined()
+ })
+
+ it('is live data only: never serialized, never copied by duplicate', () => {
+ const n = createAgentNode('claude', 0, '/repo', undefined, 'go')
+ expect(n.data.launchIntent).toBeDefined()
+ expect(JSON.stringify(flowToNodeStates([n]))).not.toContain('launchIntent')
+ expect(duplicateNode(n).data.launchIntent).toBeUndefined()
+ })
+})
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.ts
index ee6de2b4c..c1eacfb17 100644
--- a/src/renderer/state/workspace.ts
+++ b/src/renderer/state/workspace.ts
@@ -3,6 +3,7 @@ import type {
CanvasMutation,
CanvasNodeState,
ClaudeAccount,
+ HeldLaunchIntent,
NodeKind,
PendingLaunch,
Project,
@@ -18,6 +19,7 @@ import {
supportsSessionIdFlag
} from '@shared/agents/config'
import { assembleLaunchCommand, assembleResumeCommand } from '@shared/agents/launch'
+import { heldLaunchIntentFor } from '@shared/agents/launch-intent'
import { agentAccountColor } from '@shared/agents/account-color'
import { boundAccountId } from '@shared/agents/account-binding'
import { agentEnvSnapshot } from '../lib/agentEnv'
@@ -140,6 +142,13 @@ export interface NodeData {
premaxRect?: { x: number; y: number; width: number; height: number }
/** One-shot command run once when the terminal first opens (not persisted). */
initialCommand?: string
+ /**
+ * The semantic twin of a prompt-bearing agent `initialCommand` (shared/agents/launch-intent.ts),
+ * bound to that exact line. A local Windows session-host pane executes THIS instead of typing the
+ * POSIX line (`pty:execute-launch`); every other surface ignores it. Not persisted — absent from
+ * flowToNodeStates, like initialCommand.
+ */
+ launchIntent?: HeldLaunchIntent
/**
* Terminal nodes armed with canvas-control's `--after`: the launch is held until every node
* in `after` reports idle. Unlike `initialCommand` this IS persisted — the wait is durable
@@ -842,6 +851,20 @@ export function createAgentNode(
`[custom-agent] ${label}: ${missingEnv.map((m) => '${env:' + m + '}').join(', ')} unset in launch command — expanded to empty.`
)
}
+ // The same launch as a semantic request, for a Windows pane whose shell is not POSIX. Only where
+ // it describes this exact line faithfully — see heldLaunchIntentFor for every exclusion.
+ const launchIntent = heldLaunchIntentFor({
+ agentId,
+ command: initialCommand,
+ launchCmdOverride,
+ model,
+ remote: !!ssh,
+ resume: resumeSessionId !== undefined,
+ initialPrompt,
+ promptFile,
+ permissionMode,
+ mintedSessionId
+ })
const size = terminalNodeSize()
return {
id: nextId('term'),
@@ -867,6 +890,7 @@ export function createAgentNode(
...(model ? { agentModel: model } : {}),
cwd: ssh ? ssh.remoteCwd : cwd,
initialCommand,
+ ...(launchIntent ? { launchIntent } : {}),
...(ssh ? { ssh: ssh.server, sshRemoteTmux: true } : {})
}
}
@@ -2341,7 +2365,7 @@ export function duplicateNode(node: CanvasNode, offset = 28): CanvasNode {
// the binding would put a phantom run on the issue card (a chip and `#N` with no run-started,
// then a run-ended when it closes). `openedBy` likewise: nobody's open verb made the copy, and
// an orchestrator told about it would be told about a station it never opened.
- data: { ...node.data, initialCommand: undefined, issueRef: undefined, openedBy: undefined }
+ data: { ...node.data, initialCommand: undefined, launchIntent: undefined, issueRef: undefined, openedBy: undefined }
}
}
diff --git a/src/renderer/terminal/launch-command.ts b/src/renderer/terminal/launch-command.ts
index 8b91f96dc..70bfb8314 100644
--- a/src/renderer/terminal/launch-command.ts
+++ b/src/renderer/terminal/launch-command.ts
@@ -34,6 +34,14 @@ export function createLaunchWriter(opts: {
shellReady(manual: boolean): Promise<boolean>
killLine: string
cleanup(cancel: () => void): void
+ /**
+ * Optional direct executor, asked AFTER the claim and the ready re-check — the same exactly-once
+ * gates the typed line passes. `'fallback'` = it delivered nothing (not its kind of pane, or it
+ * refused before touching the pane) and the typed line runs as before; any other answer is the
+ * delivery outcome itself. Today: a local Windows session-host pane's semantic launch
+ * (terminal/launch-intent.ts).
+ */
+ execute?(command: string, manual: boolean): Promise<DeliveryOutcome | 'fallback'>
}): Writer {
let attempted = false
let submitted = false
@@ -52,6 +60,11 @@ export function createLaunchWriter(opts: {
attempted = true
// Saving can take a remote round trip. Recheck after the barrier, before any input.
if (!(await opts.shellReady(manual)) || disposed) return 'cancelled' as const
+ if (opts.execute) {
+ const direct = await opts.execute(command, manual)
+ if (direct !== 'fallback') return direct
+ if (disposed) return 'cancelled' as const
+ }
return new Promise<DeliveryOutcome>((resolve) => {
try {
// A cancelled delivery may have left an unsubmitted prefix in the shell editor.
diff --git a/src/renderer/terminal/launch-intent.test.ts b/src/renderer/terminal/launch-intent.test.ts
new file mode 100644
index 000000000..8104d9619
--- /dev/null
+++ b/src/renderer/terminal/launch-intent.test.ts
@@ -0,0 +1,120 @@
+import { describe, expect, it, vi } from 'vitest'
+import { executeHeldLaunch, outcomeForLaunchResult, type HeldLaunchDeps } from './launch-intent'
+import { createLaunchWriter } from './launch-command'
+import { KILL_LINE } from '@shared/command-delivery'
+import type { HeldLaunchIntent, LaunchIntentExecutionResult } from '@shared/types'
+
+const COMMAND = `claude 'it'\\''s'`
+const HELD: HeldLaunchIntent = {
+ command: COMMAND,
+ intent: { kind: 'agent', action: 'start', agentId: 'claude', prompt: "it's" }
+}
+const OK: LaunchIntentExecutionResult = { ok: true }
+
+function deps(extra: Partial<HeldLaunchDeps> = {}) {
+ const executeLaunch = vi.fn(async () => OK)
+ const hostPlatform = vi.fn(async () => 'win32' as string | null)
+ const d: HeldLaunchDeps = {
+ held: () => HELD,
+ sessionHost: true,
+ source: 'local',
+ hostPlatform,
+ executeLaunch,
+ newLaunchId: () => 'id-1',
+ ...extra
+ }
+ return { d, executeLaunch, hostPlatform }
+}
+
+describe('executeHeldLaunch', () => {
+ it('executes the held intent for a local session-host pane on a win32 core', async () => {
+ const { d, executeLaunch } = deps()
+ expect(await executeHeldLaunch(COMMAND, d)).toBe('submitted')
+ expect(executeLaunch).toHaveBeenCalledWith({ launchId: 'id-1', intent: HELD.intent })
+ })
+
+ it('carries a prompt file to the core instead of the `$(cat …)` line', async () => {
+ const file: HeldLaunchIntent = {
+ ...HELD,
+ intent: { kind: 'agent', action: 'start', agentId: 'claude' },
+ promptFile: 'C:\\b.md'
+ }
+ const { d, executeLaunch } = deps({ held: (): HeldLaunchIntent => file })
+ await executeHeldLaunch(COMMAND, d)
+ expect(executeLaunch).toHaveBeenCalledWith({ launchId: 'id-1', intent: file.intent, promptFile: 'C:\\b.md' })
+ })
+
+ const other: HeldLaunchIntent = { ...HELD, command: 'claude other' }
+ const fallbacks: Array<[string, Partial<HeldLaunchDeps>]> = [
+ ['no held intent', { held: () => undefined }],
+ ['an intent for a different line', { held: () => other }],
+ ['a tmux pane', { sessionHost: false }],
+ ['a relay tab', { source: 'relay' }],
+ ['a surface without the channel', { executeLaunch: undefined }]
+ ]
+ it.each(fallbacks)('falls back without any IPC for %s', async (_n, extra) => {
+ const { d, executeLaunch, hostPlatform } = deps(extra)
+ expect(await executeHeldLaunch(COMMAND, d)).toBe('fallback')
+ expect(executeLaunch).not.toHaveBeenCalled()
+ expect(hostPlatform).not.toHaveBeenCalled()
+ })
+
+ it.each(['darwin', 'linux', null])('falls back on a %s core', async (platform) => {
+ const { d, executeLaunch } = deps({ hostPlatform: async () => platform })
+ expect(await executeHeldLaunch(COMMAND, d)).toBe('fallback')
+ expect(executeLaunch).not.toHaveBeenCalled()
+ })
+
+ it('never falls back after a delivery that may have reached the pane', async () => {
+ const thrown = deps({ executeLaunch: async () => { throw new Error('ipc') } })
+ expect(await executeHeldLaunch(COMMAND, thrown.d)).toBe('cancelled')
+ expect(outcomeForLaunchResult({ ok: false, reason: 'delivery-failed', message: '' })).toBe('cancelled')
+ for (const reason of ['invalid-intent', 'agent-unavailable', 'unsupported-shell', 'session-unavailable'] as const) {
+ expect(outcomeForLaunchResult({ ok: false, reason, message: '' })).toBe('fallback')
+ }
+ })
+})
+
+describe('createLaunchWriter execute hook', () => {
+ function writer(execute: (c: string, m: boolean) => Promise<'submitted' | 'cancelled' | 'fallback'>) {
+ const write = vi.fn()
+ let echo: ((t: string) => void) | undefined
+ const claimAttempt = vi.fn(async () => true as const)
+ const w = createLaunchWriter({
+ claimAttempt,
+ shellReady: async () => true,
+ killLine: KILL_LINE,
+ cleanup: () => {},
+ io: { write, onData: (cb) => { echo = cb; return () => {} } },
+ execute
+ })
+ return { w, write, claimAttempt, echo: (t: string) => echo?.(t) }
+ }
+ const tick = async () => { for (let i = 0; i < 12; i++) await Promise.resolve() }
+
+ it('runs after the exactly-once claim, types nothing, and stays submitted', async () => {
+ const execute = vi.fn(async () => 'submitted' as const)
+ const f = writer(execute)
+ expect(await f.w('claude x', false)).toBe('submitted')
+ expect(f.claimAttempt).toHaveBeenCalledTimes(1)
+ expect(execute).toHaveBeenCalledWith('claude x', false)
+ expect(f.write).not.toHaveBeenCalled()
+ expect(await f.w('claude x', true)).toBe('submitted')
+ expect(execute).toHaveBeenCalledTimes(1)
+ })
+
+ it('types the legacy line byte-for-byte on fallback', async () => {
+ const f = writer(async () => 'fallback')
+ const result = f.w('claude x', false)
+ await tick()
+ expect(f.write.mock.calls).toEqual([['claude x']])
+ f.echo('claude x')
+ expect(await result).toBe('submitted')
+ })
+
+ it('reports an uncertain direct delivery without typing a second copy', async () => {
+ const f = writer(async () => 'cancelled')
+ expect(await f.w('claude x', false)).toBe('cancelled')
+ expect(f.write).not.toHaveBeenCalled()
+ })
+})
diff --git a/src/renderer/terminal/launch-intent.ts b/src/renderer/terminal/launch-intent.ts
new file mode 100644
index 000000000..bc6ffbba9
--- /dev/null
+++ b/src/renderer/terminal/launch-intent.ts
@@ -0,0 +1,59 @@
+// The renderer half of `pty:execute-launch`: decide whether a launch line about to be typed should
+// instead be executed as its semantic intent (core/launch-intent-execute.ts), and map the answer
+// onto the launch writer's outcome vocabulary.
+//
+// Asked only for a LOCAL session-host pane on a win32 core — the one place the POSIX line is wrong.
+// On macOS, Linux, tmux, SSH and relay this answers `'fallback'` without a single IPC, so those
+// launches are byte-identical to before.
+//
+// The outcome split is the safety property: a refusal the core made before touching the pane falls
+// back to the typed line, but a delivery that may have reached the pane (`delivery-failed`, or the
+// call itself failing — the reply may be what was lost) is reported as `'cancelled'`, which leaves
+// the launch held for an explicit Run now instead of typing a second copy behind it.
+
+import type { DeliveryOutcome } from '@shared/command-delivery'
+import type {
+ HeldLaunchIntent,
+ LaunchIntentExecutionResult,
+ LaunchIntentRequest
+} from '@shared/types'
+
+export interface HeldLaunchDeps {
+ /** The node's CURRENT held intent (live node data, read at delivery time). */
+ held(): HeldLaunchIntent | undefined
+ sessionHost: boolean
+ /** `session.source` of the live terminal: only `'local'` is eligible. */
+ source: string | undefined
+ /** `process.platform` of the owning core (`hostPlatformFor`). */
+ hostPlatform(): Promise<string | null>
+ executeLaunch?: (request: LaunchIntentRequest) => Promise<LaunchIntentExecutionResult>
+ newLaunchId(): string
+}
+
+export function outcomeForLaunchResult(
+ result: LaunchIntentExecutionResult
+): DeliveryOutcome | 'fallback' {
+ if (result.ok) return 'submitted'
+ return result.reason === 'delivery-failed' ? 'cancelled' : 'fallback'
+}
+
+export async function executeHeldLaunch(
+ command: string,
+ deps: HeldLaunchDeps
+): Promise<DeliveryOutcome | 'fallback'> {
+ const held = deps.held()
+ if (!held || held.command !== command) return 'fallback'
+ if (!deps.sessionHost || deps.source !== 'local' || !deps.executeLaunch) return 'fallback'
+ if ((await deps.hostPlatform()) !== 'win32') return 'fallback'
+ let result: LaunchIntentExecutionResult
+ try {
+ result = await deps.executeLaunch({
+ launchId: deps.newLaunchId(),
+ intent: held.intent,
+ ...(held.promptFile ? { promptFile: held.promptFile } : {})
+ })
+ } catch {
+ return 'cancelled'
+ }
+ return outcomeForLaunchResult(result)
+}
diff --git a/src/shared/agents/launch-intent.test.ts b/src/shared/agents/launch-intent.test.ts
new file mode 100644
index 000000000..5d3c493d3
--- /dev/null
+++ b/src/shared/agents/launch-intent.test.ts
@@ -0,0 +1,56 @@
+import { describe, expect, it } from 'vitest'
+import { heldLaunchIntentFor, type HeldLaunchInputs } from './launch-intent'
+
+const base = (extra: Partial<HeldLaunchInputs> = {}): HeldLaunchInputs => ({
+ agentId: 'claude',
+ command: 'claude …',
+ remote: false,
+ resume: false,
+ initialPrompt: "fix it's\n bug",
+ ...extra
+})
+
+describe('heldLaunchIntentFor', () => {
+ it('describes a builtin prompt launch, collapsing the prompt exactly like the typed line', () => {
+ expect(
+ heldLaunchIntentFor(base({ permissionMode: 'auto', mintedSessionId: '123e4567-e89b-42d3-a456-426614174000' }))
+ ).toEqual({
+ command: 'claude …',
+ intent: {
+ kind: 'agent',
+ action: 'start',
+ agentId: 'claude',
+ prompt: "fix it's bug",
+ permissionMode: 'auto',
+ newSessionId: '123e4567-e89b-42d3-a456-426614174000'
+ }
+ })
+ })
+
+ it('carries a prompt file by path, with no inline prompt', () => {
+ expect(heldLaunchIntentFor(base({ promptFile: ' C:\\brief.md ' }))).toEqual({
+ command: 'claude …',
+ intent: { kind: 'agent', action: 'start', agentId: 'claude' },
+ promptFile: 'C:\\brief.md'
+ })
+ })
+
+ it('drops a mode or minted id the agent cannot express (the typed line has none either)', () => {
+ const held = heldLaunchIntentFor(
+ base({ agentId: 'opencode', permissionMode: 'plan', mintedSessionId: '123e4567-e89b-42d3-a456-426614174000' })
+ )
+ expect(held?.intent).toEqual({ kind: 'agent', action: 'start', agentId: 'opencode', prompt: "fix it's bug" })
+ })
+
+ it.each([
+ ['no prompt', { initialPrompt: undefined }],
+ ['a whitespace-only prompt', { initialPrompt: ' ' }],
+ ['a resume', { resume: true }],
+ ['a remote (SSH) node', { remote: true }],
+ ['a custom agent', { agentId: 'custom:abc' }],
+ ['a launch-command override', { launchCmdOverride: 'my-claude' }],
+ ['a per-node model', { model: 'opus' }]
+ ] as const)('builds nothing for %s — the legacy line stays the only launch', (_n, extra) => {
+ expect(heldLaunchIntentFor(base(extra as Partial<HeldLaunchInputs>))).toBeUndefined()
+ })
+})
diff --git a/src/shared/agents/launch-intent.ts b/src/shared/agents/launch-intent.ts
new file mode 100644
index 000000000..b09ddaf88
--- /dev/null
+++ b/src/shared/agents/launch-intent.ts
@@ -0,0 +1,68 @@
+// The semantic twin of a prompt-bearing first launch (`data.launchIntent`, `HeldLaunchIntent`).
+//
+// `assembleLaunchCommand` builds POSIX source, which a Windows session-host pane running pwsh,
+// Windows PowerShell or cmd.exe mis-parses the moment the prompt holds an apostrophe, a double
+// quote or a cmd metacharacter (or a `$(cat …)` prompt file). The core can encode the same launch
+// correctly for that pane's own parser (`pty:execute-launch`, core/launch-intent-execute.ts) — but
+// only from a SEMANTIC request, never by re-parsing the typed line. This builds that request.
+//
+// It is built only where it is a faithful description of the legacy line. Anything the core
+// planner does not model — a launch-command override, a per-node model, a custom agent (its own
+// args / ${env:…} expansion / baseAgent inheritance), a remote node, a resume — yields NO intent,
+// and such a node keeps its legacy line on every surface. A launch with no prompt yields none
+// either: without a prompt the legacy line holds only bare flag words and validated ids, which
+// every Windows shell already parses the same way.
+
+import type { HeldLaunchIntent } from '../types'
+import {
+ AGENT_CONFIG,
+ hasPermissionMode,
+ mintsSessionId,
+ type AgentId,
+ type AgentPermissionMode
+} from './config'
+
+export interface HeldLaunchInputs {
+ agentId: AgentId
+ /** The exact legacy line this intent stands in for. */
+ command: string
+ launchCmdOverride?: string
+ model?: string
+ /** An SSH / relay node: its shell is on another machine, never a local session host. */
+ remote: boolean
+ /** The node RESUMES an existing conversation (no prompt by construction). */
+ resume: boolean
+ initialPrompt?: string
+ promptFile?: string
+ permissionMode?: AgentPermissionMode
+ /** The id the factory minted AND put on the legacy line (`--session-id`). */
+ mintedSessionId?: string
+}
+
+export function heldLaunchIntentFor(inputs: HeldLaunchInputs): HeldLaunchIntent | undefined {
+ if (inputs.resume || inputs.remote) return undefined
+ if (!Object.hasOwn(AGENT_CONFIG, inputs.agentId)) return undefined
+ if (inputs.launchCmdOverride?.trim() || inputs.model) return undefined
+ const promptFile = inputs.promptFile?.trim()
+ // Collapsed exactly like the legacy line collapses it (`assembleLaunchCommand`).
+ const prompt = promptFile ? undefined : inputs.initialPrompt?.replace(/\s+/g, ' ').trim()
+ if (!promptFile && !prompt) return undefined
+ return {
+ command: inputs.command,
+ intent: {
+ kind: 'agent',
+ action: 'start',
+ agentId: inputs.agentId,
+ ...(prompt ? { prompt } : {}),
+ // The legacy line carries a mode flag only for an agent that has one; the core planner
+ // refuses a mode for any other, so the two agree by construction.
+ ...(inputs.permissionMode && hasPermissionMode(inputs.agentId)
+ ? { permissionMode: inputs.permissionMode }
+ : {}),
+ ...(inputs.mintedSessionId && mintsSessionId(inputs.agentId)
+ ? { newSessionId: inputs.mintedSessionId }
+ : {})
+ },
+ ...(promptFile ? { promptFile } : {})
+ }
+}