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
fix(control): spill long prompts on the --project and cold-open paths too
review63884e4fcc83
diff --git a/CLAUDE.md b/CLAUDE.mdindex ce1dd494c..681ef4254 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -3287,6 +3287,16 @@ command-bearing opens; this does not add a human-confirm dialog or change mobilerefused caller, and its refusal said whether that project had a GitHub board). Main's`gateProjectTarget` runs before the renderer as ever; the Server Edition already resolved afterits identity, source and target gates, now pinned by a test.+ **The open PROMPT is decided in the same place, once, for every open path** (`openPrompt`, via+ `launchPromptFor` in `lib/promptSpill.ts`): the issue reference line composed through+ `issueLaunchPrompt`, then spilled to a file when it is over the typed-line budget (#706), judged+ "local" by the project the node opens in (an SSH project's pane cannot read a file written here),+ which comes from the SAME authorization belt (`issueFlagScope`, exported for this): a caller the+ paths refuse gets no project and no spill. The live open was the only path that spilled; the `--project` and cold opens typed the prompt+ inline, so the docs' "a long `--prompt` is safe on a local project" was false exactly where the+ ~490-byte issue line made it likeliest to bite, and the `--project` path silently DROPPED+ `--prompt-file` (the session started with no brief) and `--model`. A new open path types+ `openPrompt`, never its own prompt — `control-prompt-spill.source.test.ts` pins each path.`--prompt` replaces the default task after the reference line; `--prompt-file` stays the whole brief. Bothgenerated agent bodies render the contract from `issueBindingDocLines` (the example first promptis rendered from `issueLaunchPrompt` itself): move your OWN card with `assign` (In Progress ondiff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 6ac096b9c..2d1698d7d 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -461,11 +461,7 @@ import {} from '@shared/agents/config'import { withPermissionMode } from '@shared/agents/approval-mode'import { promptFilePathError } from '@shared/agents/launch'-import {- encodeUtf8Base64,- shouldSpillPrompt,- spillPromptToFile-} from '../lib/promptSpill'+import { encodeUtf8Base64, launchPromptFor } from '../lib/promptSpill'import { parseTeamSpec } from '../lib/teamSpec'import { relativeTime } from '../lib/relativeTime'import { AgentIcon } from '../lib/agentIcons'@@ -480,7 +476,7 @@ import {type IssueRef} from '@shared/github-issue-ref'import { runEndedEntry, runStartedEntry } from '../lib/issueRuns'-import { resolveIssueFlagForCall, type IssueFlagResult } from '../lib/issueFlag'+import { issueFlagScope, resolveIssueFlagForCall, type IssueFlagResult } from '../lib/issueFlag'import type { GitHubIssueCardView } from '@shared/github-issues'import { branchClaudeSession } from '../lib/claudeBranch'import {@@ -10506,6 +10502,47 @@ export function Canvas() {return}const issueRefPre = issuePre.ref+ // The prompt every agent open types, decided ONCE, HERE, for the same reason as `issuePre`+ // (#706, `launchPromptFor`): an over-budget `--prompt` becomes a file the pane's own shell+ // reads, on EVERY open path — live, cold and `--project`. Two of the three typed it inline,+ // so the docs' "a long --prompt is safe on a local project" held only on screen; deciding it+ // inside a path would also put an await after that path had read the projects store.+ // "Local" is judged by the project the node OPENS in (the one `#N` was resolved against): an+ // SSH project's pane runs on the host, where a file written here does not exist. A dry run+ // writes nothing, and a call passing both flags is refused by its path before this is read.+ // Which project that is comes from the SAME authorization belt `#N` runs behind+ // (`issueFlagScope`): a caller the paths will refuse gets no project here, so nothing is+ // spilled for it — its path refuses it with the same sentence.+ const openScopePre = issueOpen+ ? issueFlagScope({+ targetId: args.project,+ sourceNodeId,+ liveNodes: nodesRef.current,+ projects: useProjects.getState().projects,+ activeProjectId: useProjects.getState().activeProjectId+ })+ : undefined+ const openProjectPre = openScopePre?.ok+ ? useProjects.getState().getProject(openScopePre.projectId)+ : undefined+ const openPromptFileArg = (args['prompt-file'] ?? '').trim() || undefined+ const spillIo = {+ saveUpload: (name: string, data: string) => api.files.saveUpload(name, data),+ encodeBase64: encodeUtf8Base64+ }+ const openPrompt: { prompt?: string; promptFile?: string } =+ issueOpen && openScopePre?.ok && !dryRun && !(args.prompt && openPromptFileArg)+ ? await launchPromptFor(+ {+ // An issue-bound session's prompt is the REFERENCE line, with the caller's own+ // `--prompt` after it. `--prompt-file` is the whole brief and passes through.+ prompt: issueRefPre ? issueLaunchPrompt(issueRefPre, args.prompt) : args.prompt,+ promptFile: openPromptFileArg,+ localFs: !openProjectPre?.ssh+ },+ spillIo+ )+ : {}// ── Agent messaging (`send`/`reply`) — handled BEFORE the source-routing machinery ──────// These are STORE_ANSWERED_VERBS (lib/controlRouting): routing by source must never travel@@ -10847,9 +10884,29 @@ export function Canvas() {const target = tgResolved.projectconst tgAgentId = (verb === 'open-agent' ? args.agent : 'claude') as AgentIdconst tgIsTerminal = verb === 'open-terminal'- // `#N` was resolved against the TARGET project above (`issuePre`) — the node opens there.+ // `#N` was resolved against the TARGET project above (`issuePre`) — the node opens there,+ // and so was `openPrompt` (the target is local here: SSH and relay targets are refused).const tgIssueRef = tgIsTerminal ? undefined : issueRefPre- const tgPrompt = tgIssueRef ? issueLaunchPrompt(tgIssueRef, args.prompt) : args.prompt+ // `--prompt-file` used to be DROPPED on this path without a word, so the session started+ // with no brief at all. Validated exactly as the live and cold paths do; the file is read+ // from this machine's filesystem, which is the target's (resolveProjectTarget refused an+ // SSH or relay one above).+ if (!tgIsTerminal && openPromptFileArg) {+ if (args.prompt) {+ reply({ ok: false, error: `${verb}: pass either --prompt or --prompt-file, not both` })+ return+ }+ const pfErr = promptFilePathError(openPromptFileArg)+ if (pfErr) {+ reply({ ok: false, error: `${verb}: --prompt-file ${pfErr}` })+ return+ }+ const pfExists = await api.fs.exists(openPromptFileArg).catch(() => true)+ if (!pfExists) {+ reply({ ok: false, error: `${verb}: --prompt-file not found: ${openPromptFileArg}` })+ return+ }+ }const tgCount = Math.max(1,Math.min(tgIsTerminal ? 8 : 5, parseInt(args.count || '1', 10) || 1)@@ -10863,14 +10920,17 @@ export function Canvas() {? undefined: resolveNewNodeAccount(undefined, target, useSettings.getState().settings.claudeAccounts)const tgMode = tgIsTerminal ? undefined : projectPermissionMode(target, tgAgentId)- const tgActive = target.id === tgStore.activeProjectId+ // Read AFTER the `--prompt-file` await above: a tab switch in that window decides whether+ // the node belongs on the live canvas or in the store (the #443 class).+ const tgActive = target.id === useProjects.getState().activeProjectId// Placement: below the lowest existing node in the TARGET (placeBelow(src) is// meaningless in a project that does not contain the source). The live canvas is the// truthful node set for the active project, the serialized store for any other.- const tgPlacedNodes = tgActive ? nodesRef.current : target.nodes+ const tgStoredNodes = useProjects.getState().getProject(target.id)?.nodes ?? target.nodes+ const tgPlacedNodes = tgActive ? nodesRef.current : tgStoredNodesconst tgMade: CanvasNode[] = []let tgBase = { x: 0, y: 0 }- const tgIndexBase = tgActive ? nodesRef.current.length : target.nodes.length+ const tgIndexBase = tgActive ? nodesRef.current.length : tgStoredNodes.lengthfor (let i = 0; i < tgCount; i++) {const node = tgIsTerminal? createTerminalNode(tgIndexBase + i, tgCwd, { x: 0, y: 0 }, args.cmd)@@ -10880,13 +10940,17 @@ export function Canvas() {tgIndexBase + i,tgCwd,{ x: 0, y: 0 },- tgPrompt,+ openPrompt.prompt,undefined,tgAccount,tgMode,// The TARGET project: its `.nodeterm/settings.json` launch override applies to// what runs in it, not the caller's.- target.id+ target.id,+ // `--model` was dropped here too, like `--prompt-file`: honoured as on every+ // other open path (`withAgentModel` re-validates it at the interpolation site).+ args.model,+ openPrompt.promptFile),tgIssueRef)@@ -11191,9 +11255,9 @@ export function Canvas() {return}}- // `#N` was resolved against the OWNING project above (`issuePre`): the node is saved there.+ // `#N` was resolved against the OWNING project above (`issuePre`): the node is saved+ // there — and so was `openPrompt`, spilled or not by that project's own locality.const coldIssueRef = coldTerminal ? undefined : issueRefPre- const coldPrompt = coldIssueRef ? issueLaunchPrompt(coldIssueRef, args.prompt) : args.promptif (dryRun) {if (!coldTerminal) {const dryKnownAgent =@@ -11259,13 +11323,13 @@ export function Canvas() {coldNodes.length + i,coldCwd,undefined,- coldPrompt,+ openPrompt.prompt,coldSsh,coldAccount,coldMode,owner.id,args.model,- coldPromptFile+ openPrompt.promptFile),coldIssueRef)@@ -11524,12 +11588,7 @@ export function Canvas() {const spillLongPrompt = async (prompt: string | undefined): Promise<{ prompt?: string; promptFile?: string }> => {- if (!shouldSpillPrompt(prompt, !ctlSsh)) return { prompt }- const path = await spillPromptToFile(prompt as string, {- saveUpload: (n, d) => api.files.saveUpload(n, d),- encodeBase64: encodeUtf8Base64- })- return path ? { promptFile: path } : { prompt }+ return launchPromptFor({ prompt, localFs: !ctlSsh }, spillIo)}// Place opened nodes BELOW the source and rope them to it (source flow-out → target// flow-in), mirroring how subagent/loop nodes attach — so they read as "hanging off" the@@ -11944,15 +12003,10 @@ export function Canvas() {// See the same list in open-terminal: which of these nodes end up ARMED is// `armAfter`'s per-node decision, recorded as it builds them.const openBatch = createControlOpenBatch()- // A `--prompt` over the typed-line budget is spilled to a file and delivered through- // the same `"$(cat …)"` substitution `--prompt-file` uses (#706). An explicit- // `--prompt-file` already took that route and is passed through untouched.- // An issue-bound session's prompt is the REFERENCE line (`issueLaunchPrompt`), with the- // caller's own `--prompt` after it. `--prompt-file` is left untouched: the file is the- // whole brief (the skill tells the caller to name the issue in it).- const promptLaunch = await spillLongPrompt(- promptFile ? undefined : issueRef ? issueLaunchPrompt(issueRef, args.prompt) : args.prompt- )+ // The prompt was decided above (`openPrompt`, #706): an over-budget `--prompt` rides a+ // spilled file through the same `"$(cat …)"` substitution `--prompt-file` uses, an+ // issue-bound session's prompt leads with the REFERENCE line, and an explicit+ // `--prompt-file` (the whole brief) is passed through untouched.const issueNodes: CanvasNode[] = []const make = (i: number): CanvasNode => {const node = armAfter(@@ -11961,7 +12015,7 @@ export function Canvas() {nodesRef.current.length + i,agentCwd,placeBelow(i),- promptLaunch.prompt,+ openPrompt.prompt,sshFor(agentCwd),account,activePermissionMode(agentId),@@ -11972,7 +12026,7 @@ export function Canvas() {// interpolation site and emits nothing for an agent outside MODEL_SWITCH_CAPABLE,// so an unsupported agent's command line stays byte-identical.args.model,- promptFile ?? promptLaunch.promptFile+ openPrompt.promptFile),after ?? [],intoGroupIddiff --git a/src/renderer/canvas/control-prompt-spill.source.test.ts b/src/renderer/canvas/control-prompt-spill.source.test.tsnew file mode 100644index 000000000..b993a46d7--- /dev/null+++ b/src/renderer/canvas/control-prompt-spill.source.test.ts@@ -0,0 +1,128 @@+import { describe, it, expect } from 'vitest'+import { readFileSync } from 'node:fs'++/**+ * STRUCTURAL pins: EVERY canvas-control open path types the same prompt the same way (#706).+ *+ * A `--prompt` becomes a quoted argument on a launch line TYPED into the pane, and a canonical-mode+ * tty drops everything past 1024 bytes on macOS. `spillPromptToFile` moves an over-budget prompt+ * into a file the pane's shell reads, and the agent-facing docs promise that a long `--prompt` is+ * therefore safe on a local project. That promise held on ONE of three paths: the live open. The+ * `--project` path and the cold open (the caller's own project, not on screen) typed the prompt+ * inline, and the issue reference line (#1000, ~490 bytes on its own) made that likelier. The+ * `--project` path also dropped `--prompt-file` without a word, so the session started with no+ * brief at all.+ *+ * The decision itself is `launchPromptFor` (lib/promptSpill.ts), proven against real inputs in its+ * own test. What only the SOURCE can show is that each path asks it, once, before any path snapshots+ * the projects store — an await inside a path is the #443 class (a tab switch in that window writes+ * the node into the project that just became active).+ */+const src = readFileSync(new URL('./Canvas.tsx', import.meta.url), 'utf8').replace(/\r\n/g, '\n')++const PROJECT_GUARD = "(verb === 'open-terminal' || verb === 'open-claude' || verb === 'open-agent') &&\n args.project !== undefined"+const RUN_PROJECT = "if (verb === 'run' && args.project !== undefined) {"++function slice(fromMarker: string, toMarker: string, from = 0): string {+ const start = src.indexOf(fromMarker, from)+ expect(start, `marker: ${fromMarker}`).toBeGreaterThan(-1)+ const end = src.indexOf(toMarker, start + fromMarker.length)+ expect(end, `marker: ${toMarker}`).toBeGreaterThan(start)+ return src.slice(start, end)+}++const projectBlock = (): string => slice(PROJECT_GUARD, RUN_PROJECT)+const coldBlock = (): string =>+ slice('if (canColdOpen(verb)) {', 'if (answersOffCanvas(verb) || answersFromStoredNodes(verb)) {')+const liveAgentCase = (): string => slice("case 'open-claude':", "case 'show-image':")++/** Every `createAgentNode(…)` call in a block, argument list included (balanced parentheses). */+function agentNodeCalls(block: string): string[] {+ const calls: string[] = []+ let at = block.indexOf('createAgentNode(')+ while (at !== -1) {+ let depth = 0+ let end = at + 'createAgentNode'.length+ for (; end < block.length; end++) {+ if (block[end] === '(') depth+++ else if (block[end] === ')' && --depth === 0) break+ }+ calls.push(block.slice(at, end + 1))+ at = block.indexOf('createAgentNode(', end)+ }+ return calls+}++describe('the open prompt is resolved ONCE, before any path reads the store', () => {+ it('is decided by launchPromptFor next to issuePre, ahead of the --project block and routing', () => {+ const decided = src.indexOf('const openPrompt:')+ expect(decided, 'the one openPrompt resolution').toBeGreaterThan(-1)+ expect(src.indexOf('const openPrompt:', decided + 1), 'resolved exactly once').toBe(-1)+ expect(src.slice(decided, decided + 1500)).toContain('launchPromptFor(')+ expect(decided).toBeGreaterThan(src.indexOf('const issuePre: IssueFlagResult'))+ expect(decided).toBeLessThan(src.indexOf(PROJECT_GUARD))+ expect(decided).toBeLessThan(src.indexOf('routeControlSource(projects, activeId, sourceNodeId)'))+ })++ it('never spills for a dry run — a dry run writes no file', () => {+ const decided = src.indexOf('const openPrompt:')+ expect(src.slice(decided, decided + 1500)).toMatch(/!dryRun/)+ })++ it('asks the SAME authorization belt as `#N` which project that is — a refused caller spills nothing', () => {+ const decided = src.indexOf('const openPrompt:')+ const before = src.slice(src.indexOf('const issuePre: IssueFlagResult'), decided)+ expect(before).toMatch(/const openScopePre = issueOpen\s*\?\s*issueFlagScope\(/)+ expect(src.slice(decided, decided + 400)).toContain('openScopePre?.ok')+ })++ it('judges "local" by the project the node OPENS in, never the one on screen', () => {+ // An SSH project's pane runs on the host, so a spilled file would land on the wrong machine.+ const decided = src.indexOf('const openPrompt:')+ const body = src.slice(decided, decided + 1500)+ expect(body).toMatch(/localFs: !openProjectPre\?\.ssh/)+ expect(src).toContain('const openProjectPre')+ })+})++describe('each open path types openPrompt, never its own inline prompt', () => {+ const cases: [string, () => string, RegExp][] = [+ ['--project', projectBlock, /\btgPrompt\b/],+ ['cold open', coldBlock, /\bcoldPrompt\b/],+ ['live open', liveAgentCase, /promptLaunch/]+ ]+ for (const [name, block, legacy] of cases) {+ it(`${name}: every agent node takes openPrompt.prompt and openPrompt.promptFile`, () => {+ const calls = agentNodeCalls(block())+ expect(calls.length, `${name} builds agent nodes`).toBeGreaterThan(0)+ for (const call of calls) {+ expect(call).toContain('openPrompt.prompt,')+ expect(call).toMatch(/openPrompt\.promptFile\s*\)/)+ }+ // The per-path prompt that used to be typed inline is gone, not merely unused.+ expect(block()).not.toMatch(legacy)+ })+ }++ it('--project passes --model through instead of dropping it', () => {+ for (const call of agentNodeCalls(projectBlock())) expect(call).toMatch(/args\.model,\s*openPrompt\.promptFile/)+ })++ it('--project validates --prompt-file instead of dropping it', () => {+ const body = projectBlock()+ expect(body).toContain('promptFilePathError(')+ expect(body).toContain('pass either --prompt or --prompt-file, not both')+ expect(body).toMatch(/\.exists\(/)+ })++ it('--project re-reads the store after its await, so a tab switch cannot misroute the node', () => {+ // `tgActive` decides between setNodes (live canvas) and a store write; a value read before an+ // await describes a canvas that may no longer be on screen.+ const body = projectBlock()+ const awaited = body.indexOf('.exists(')+ const active = body.indexOf('const tgActive')+ expect(awaited).toBeGreaterThan(-1)+ expect(active).toBeGreaterThan(awaited)+ expect(body.slice(active, active + 200)).toContain('useProjects.getState().activeProjectId')+ })+})diff --git a/src/renderer/canvas/issue-binding.source.test.ts b/src/renderer/canvas/issue-binding.source.test.tsindex 0fdb234ce..973e5140b 100644--- a/src/renderer/canvas/issue-binding.source.test.ts+++ b/src/renderer/canvas/issue-binding.source.test.ts@@ -57,8 +57,9 @@ describe('--issue in the desktop control dispatch', () => {expect(body).not.toContain('resolveIssueFlagForCall(')expect(body).toContain('const issueRef = issueRefPre')expect(body).toContain('bound to GitHub issue ${formatIssueRef(issueRef)}')- // The launch prompt is composed by the one function allowed to turn a reference into text.- expect(body).toMatch(/issueRef \? issueLaunchPrompt\(issueRef, args\.prompt\) : args\.prompt/)+ // The launch prompt is the one composed (and spilled if long) above, through issueLaunchPrompt.+ expect(body).toContain('openPrompt.prompt,')+ expect(body).not.toContain('issueLaunchPrompt(')expect(body).toContain('bindIssue(node, issueRef)')expect(body).toContain('logRunsStarted(ctlProject?.id, issueNodes, issueRef)')})@@ -68,7 +69,8 @@ describe('--issue in the desktop control dispatch', () => {expect(body).not.toContain('resolveIssueFlagForCall(')expect(body).toContain('const coldIssueRef = coldTerminal ? undefined : issueRefPre')expect(body).toContain('bound to GitHub issue ${formatIssueRef(coldIssueRef)}')- expect(body).toMatch(/coldIssueRef \? issueLaunchPrompt\(coldIssueRef, args\.prompt\) : args\.prompt/)+ expect(body).toContain('openPrompt.prompt,')+ expect(body).not.toContain('issueLaunchPrompt(')expect(body).toContain('logRunsStarted(owner.id, coldMade, coldIssueRef)')})@@ -76,13 +78,21 @@ describe('--issue in the desktop control dispatch', () => {const body = code(between("args.project !== undefined\n ) {", '// ── end of the early-handled'))expect(body).not.toContain('resolveIssueFlagForCall(')expect(body).toContain('const tgIssueRef = tgIsTerminal ? undefined : issueRefPre')- expect(body).toMatch(/tgIssueRef \? issueLaunchPrompt\(tgIssueRef, args\.prompt\) : args\.prompt/)+ expect(body).toContain('openPrompt.prompt,')+ expect(body).not.toContain('issueLaunchPrompt(')expect(body).toContain('logRunsStarted(target.id, tgMade, tgIssueRef)')// The pre-resolution is handed the `--project` target, which it judges before asking anyone// (`resolveIssueFlagForCall` runs the renderer's authorization belt first — lib/issueFlag.test).expect(code(src)).toMatch(/await resolveIssueFlagForCall\(\s*\{[^}]*targetId: args\.project,/)})+ it('every agent open types the prompt composed ONCE through issueLaunchPrompt', () => {+ // The one function allowed to turn a reference into text, used at the one place the open+ // prompt is decided (`openPrompt`, which also spills it when long — #706).+ const body = code(between('const openPrompt:', 'if (verb === \'send\''))+ expect(body).toMatch(/prompt: issueRefPre \? issueLaunchPrompt\(issueRefPre, args\.prompt\) : args\.prompt/)+ })+it('no path splices the raw --issue value into a prompt or a launch line', () => {expect(code(src)).not.toMatch(/args\.issue[^\n]*(prompt|initialCommand|createAgentNode)/)// The only reader of the raw flag is the resolver.diff --git a/src/renderer/lib/issueFlag.ts b/src/renderer/lib/issueFlag.tsindex 86d1c6be8..ebc10f0f0 100644--- a/src/renderer/lib/issueFlag.ts+++ b/src/renderer/lib/issueFlag.ts@@ -86,8 +86,10 @@ export async function resolveIssueFlagForCall(}/** Which project `#N` is resolved against — the one the node opens in — or the refusal the open- * paths would give this call. */-function issueFlagScope<P extends ProjectTargetProject & ControlProject>(input: {+ * paths would give this call. Exported because it is the one answer for every per-open question the+ * dispatch decides before its paths (Canvas also sizes the open prompt's spill by it): two copies+ * of "which project, and may this caller ask" are how one of them drifts. */+export function issueFlagScope<P extends ProjectTargetProject & ControlProject>(input: {targetId: string | undefinedsourceNodeId: stringliveNodes: readonly { id: string; data: { agentId?: unknown } }[]diff --git a/src/renderer/lib/promptSpill.test.ts b/src/renderer/lib/promptSpill.test.tsindex 71d311766..73a4edef0 100644--- a/src/renderer/lib/promptSpill.test.ts+++ b/src/renderer/lib/promptSpill.test.ts@@ -3,6 +3,7 @@ import {LAUNCH_PROMPT_BUDGET_BYTES,encodeUtf8Base64,flattenPrompt,+ launchPromptFor,promptExceedsLineBudget,shouldSpillPrompt,spillPromptToFile@@ -10,6 +11,7 @@ import {import { MAX_LAUNCH_LINE_BYTES, fitsLaunchLine, lineBytes } from '@shared/canonical-line'import { DEFAULT_LENSES, verifyLensPrompt, verifySynthesisPrompt } from './verifyPanel'import { assembleLaunchCommand } from '@shared/agents/launch'+import { issueLaunchPrompt } from '@shared/github-issue-ref'const io = (saveUpload: (n: string, d: string) => Promise<string | null>) => ({saveUpload,@@ -90,6 +92,57 @@ describe('spillPromptToFile', () => {})})+describe('launchPromptFor — the one decision every open path makes', () => {+ const long = 'x'.repeat(LAUNCH_PROMPT_BUDGET_BYTES + 1)++ it('a short prompt stays inline and writes nothing', async () => {+ const save = vi.fn(async () => '/tmp/p.txt' as string | null)+ expect(await launchPromptFor({ prompt: 'hello', localFs: true }, io(save))).toEqual({ prompt: 'hello' })+ expect(save).not.toHaveBeenCalled()+ })++ it('an over-budget prompt on a local project becomes a prompt FILE', async () => {+ const save = vi.fn(async () => '/tmp/spill.txt' as string | null)+ expect(await launchPromptFor({ prompt: long, localFs: true }, io(save))).toEqual({+ promptFile: '/tmp/spill.txt'+ })+ expect(save).toHaveBeenCalledTimes(1)+ })++ it('an over-budget prompt on an SSH project stays inline — the delivery refusal is its backstop', async () => {+ const save = vi.fn(async () => '/tmp/spill.txt' as string | null)+ expect(await launchPromptFor({ prompt: long, localFs: false }, io(save))).toEqual({ prompt: long })+ expect(save).not.toHaveBeenCalled()+ })++ it("an explicit --prompt-file passes through untouched, whatever the project", async () => {+ const save = vi.fn(async () => '/tmp/spill.txt' as string | null)+ expect(+ await launchPromptFor({ promptFile: '/home/u/brief.md', localFs: true }, io(save))+ ).toEqual({ promptFile: '/home/u/brief.md' })+ expect(save).not.toHaveBeenCalled()+ })++ it('fails OPEN: a spill that cannot be written keeps the prompt inline', async () => {+ expect(await launchPromptFor({ prompt: long, localFs: true }, io(async () => null))).toEqual({+ prompt: long+ })+ })++ it('no prompt at all is no prompt at all', async () => {+ const save = vi.fn(async () => '/tmp/spill.txt' as string | null)+ expect(await launchPromptFor({ localFs: true }, io(save))).toEqual({ prompt: undefined })+ expect(save).not.toHaveBeenCalled()+ })++ it('an issue-bound prompt plus a modest brief is over the budget — the case #1000 made common', () => {+ // The issue reference lines are ~490 bytes around a caller's brief; a 400-character brief crosses the+ // typed-line budget. Before the fix, the `--project` and cold-open paths typed that inline.+ const prompt = issueLaunchPrompt({ owner: 'eneskirca', repo: 'nodeterm', number: 1000 }, 'y'.repeat(400))+ expect(shouldSpillPrompt(prompt, true)).toBe(true)+ })+})+describe("verify's own prompts (the case that fires with no user input)", () => {const shimPath = '/Users/x/Library/Application Support/node-terminal/context-link/context.sh'const targetId = 'n'.repeat(22)diff --git a/src/renderer/lib/promptSpill.ts b/src/renderer/lib/promptSpill.tsindex a5a2b364f..d35a2bd23 100644--- a/src/renderer/lib/promptSpill.ts+++ b/src/renderer/lib/promptSpill.ts@@ -117,3 +117,25 @@ export async function spillPromptToFile(return null}}++/**+ * The prompt an open types, decided ONCE for every canvas-control open path — live, cold (the+ * caller's own project, not on screen) and `--project`. Two of the three used to type the prompt+ * inline whatever its length, so the docs' promise that a long `--prompt` is safe on a local+ * project held only on the live one.+ *+ * - An explicit `--prompt-file` passes through untouched: the file is already the whole brief.+ * - A prompt within budget, or any prompt for a pane that cannot read this machine's files+ * (`localFs` false: an SSH project), stays inline. The delivery layer's `line-too-long` refusal is+ * the backstop there.+ * - Otherwise it is spilled; a spill that cannot be written keeps the prompt inline (fail open).+ */+export async function launchPromptFor(+ input: { prompt?: string; promptFile?: string; localFs: boolean },+ io: PromptSpillIo+): Promise<{ prompt?: string; promptFile?: string }> {+ if (input.promptFile) return { promptFile: input.promptFile }+ if (!shouldSpillPrompt(input.prompt, input.localFs)) return { prompt: input.prompt }+ const path = await spillPromptToFile(input.prompt as string, io)+ return path ? { promptFile: path } : { prompt: input.prompt }+}