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(chat): keep a prompt typed during a pending tool call
reviewf847130ce5b6
diff --git a/CLAUDE.md b/CLAUDE.mdindex ff273a8b2..612af733c 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -4503,8 +4503,9 @@ command-bearing opens; this does not add a human-confirm dialog or change mobilelong prompt shows only its end. So "holds the last send" accepts that end, each burst is twoCtrl-Us per row on screen (`readClaudeDraftBox`) plus spares, and bursts repeat while what is leftends earlier in the sent text (`endsEarlierIn`). Claude still writes such a prompt to the- transcript as a branch it drops from its context, so the chat view keeps showing it (the reader- does not follow `parentUuid`; known gap). The panel also makes the terminal's interrupt guess+ transcript as a branch it drops from its context; the reader hides it once the re-sent prompt+ is in the same read (`abandonedPromptUuids`: a childless prompt with a later non-tool-result+ sibling under the same `parentUuid`). The panel also makes the terminal's interrupt guess(`inferInterruptAfterSettle`), since an early Esc writes no transcript marker.**An interrupt is drawn as Claude draws it, not as a user bubble.** Claude saves its marker(`CLAUDE_INTERRUPT_MARKERS`, now in `shared/agents/claude-interrupt.ts`, shared with the contextdiff --git a/src/core/chat-fixtures.test.ts b/src/core/chat-fixtures.test.tsindex b3820a734..3fc7c240d 100644--- a/src/core/chat-fixtures.test.ts+++ b/src/core/chat-fixtures.test.ts@@ -632,8 +632,15 @@ function abandonedPrompts(): string {// A later SIDECHAIN record with the same parent does not make a prompt abandoned./* 18 */ under(17, user('Check the lint.')),/* 19 */ { ...under(17, user('subagent prompt')), isSidechain: true },+ // Typed while a tool call is pending: the prompt and the call's (rejected) result share a+ // parent and the answer hangs off the result. The model received the prompt, so it stays.+ /* 20 */ under(18, assistant([toolUse('toolu_b1', 'Bash', { command: 'npm run lint' })])),+ /* 21 */ under(20, user('Stop, run the tests instead.')),+ /* 22 */ under(20, toolResult('toolu_b1', 'rejected')),+ /* 23 */ under(22, user([text('[Request interrupted by user for tool use]')])),+ /* 24 */ under(23, assistant([text('Running the tests.')])),// The newest prompt has no answer yet and no sibling: shown.- /* 20 */ under(18, user('One more thing.'))+ /* 25 */ under(24, user('One more thing.'))])}diff --git a/src/core/transcript-reader.abandoned.test.ts b/src/core/transcript-reader.abandoned.test.tsindex 929117893..d7b8516dd 100644--- a/src/core/transcript-reader.abandoned.test.ts+++ b/src/core/transcript-reader.abandoned.test.ts@@ -60,6 +60,30 @@ describe('abandoned prompts', () => {expect(texts(ms)).toEqual(['Explain the cache.', 'The cache keeps', 'Explain the cache briefly.'])})+ // Measured shape: a prompt typed while a tool call is pending interrupts the call. The prompt+ // and the call's result share a parent, the answer hangs off the result's interrupt marker, and+ // the model receives the prompt in that same request.+ it('keeps a prompt typed during a pending tool call (its later sibling is the tool result)', () => {+ const recs: Rec[] = [+ prompt('u1', null, 'Run the lint.'),+ {+ type: 'assistant',+ uuid: 'a1',+ parentUuid: 'u1',+ isSidechain: false,+ message: { role: 'assistant', content: [{ type: 'tool_use', id: 't1', name: 'Bash', input: { command: 'npm run lint' } }] }+ },+ prompt('u2', 'a1', 'Stop, run the tests instead.'),+ prompt('r1', 'a1', [{ type: 'tool_result', tool_use_id: 't1', content: 'rejected', is_error: true }]),+ prompt('m1', 'r1', [{ type: 'text', text: '[Request interrupted by user for tool use]' }]),+ reply('a2', 'm1', 'Running the tests.')+ ]++ const ms = parseChatMessages(recs.map((r) => JSON.stringify(r)))++ expect(texts(ms)).toContain('Stop, run the tests instead.')+ })+it('never hides a record without string uuid fields', () => {const recs = queuedThenEsc.map((r) => ({ ...r, uuid: undefined }))diff --git a/src/core/transcript-reader.ts b/src/core/transcript-reader.tsindex cc861a035..ea4230dd7 100644--- a/src/core/transcript-reader.ts+++ b/src/core/transcript-reader.ts@@ -647,6 +647,10 @@ function isPromptContent(content: unknown): boolean {return text}+function hasToolResult(content: unknown): boolean {+ return Array.isArray(content) && content.some((c) => !!c && typeof c === 'object' && (c as { type?: unknown }).type === 'tool_result')+}+/*** The uuids of prompts the model never received. A transcript is a TREE: each record names its* `parentUuid`, and the model is sent the chain from the newest record back to the root. When a@@ -657,7 +661,10 @@ function isPromptContent(content: unknown): boolean {* saw the text (5 were re-sent after an edit, one was a raw `/compact` recorded twice).** A prompt is abandoned when no record in these lines has it as its parent AND a later- * user/assistant record (not a sidechain) has the same parent. Both checks see only the lines+ * user/assistant record (not a sidechain, not a tool result) has the same parent. The tool-result+ * exclusion is measured (1 of 9 matches over 306 transcripts, 2,899 prompts): a prompt typed+ * during a pending tool call is a childless sibling of that call's result, and the request that+ * follows carries the prompt text. Both checks see only the lines* given, so on a paged read a sibling in a NEWER window is missed and the prompt is shown, as* before. A prompt the model did answer is safe: claude writes its first child right after it* (measured in the 10 prompts that have both a child and a later sibling), so any window holding@@ -670,7 +677,10 @@ function abandonedPromptUuids(records: readonly TreeFields[]): Set<string> {records.forEach((o, i) => {if (typeof o.parentUuid !== 'string') returnhasChild.add(o.parentUuid)- if ((o.type === 'user' || o.type === 'assistant') && o.isSidechain !== true) {+ // A tool-result record is never the re-send that marks its sibling abandoned: a prompt typed+ // while a tool call is pending shares that call's parent with the result (the interrupt marker+ // and the answer hang off the RESULT), and the model receives both in one request.+ if ((o.type === 'user' || o.type === 'assistant') && o.isSidechain !== true && !hasToolResult(o.message?.content)) {const list = byParent.get(o.parentUuid) ?? []list.push({ i, uuid: o.uuid })byParent.set(o.parentUuid, list)diff --git a/src/shared/chat-fixtures/README.md b/src/shared/chat-fixtures/README.mdindex 054364526..4b0ae2c09 100644--- a/src/shared/chat-fixtures/README.md+++ b/src/shared/chat-fixtures/README.md@@ -89,7 +89,7 @@ the production paging, not a second implementation of it.| `teammate-messages` | Rule **2b** of **System-injected records**: an idle notification with a report, one with no fields, a failed one (`failureReason`), a plain message whose summary is escaped (`"`) and whose body quotes the close tag, a record holding two elements (a report, then a message), an unverified sender (`verified="false"`), the same text typed by a human (by `origin` and by `promptSource` alone — both stay user messages), the frame line with no element and an element with no `teammate_id` (both stay user messages). || `pasted-content` | **Pasted content**: a span between typed lines, backtick runs inside (a five-backtick fence) and the same id twice, an array text part beside an image, a pasted `<task-notification>` (stays the user's paste), a close tag with a different id inside a span (content), an empty paste, a same-id open nested inside a span (the span ends at the FIRST close), text that is not the CLI's grammar (no id, an upper-case or three- or five-digit id, a missing newline after the open or before the close: all left as typed) and an unclosed span (left as typed). || `queued-prompts` | **Queued prompts**: a typed prompt queued mid-turn (between a tool result and the reply), one with no `origin`, an array prompt with an image (its text block only), a paste inside one (fenced, as in a typed prompt), and six attachments that stay hidden: a task notification, a peer message (`isMeta`), a coordinator message, a non-human `origin`, a blank prompt and a non-`queued_command` attachment. |-| `abandoned-prompts` | **Abandoned prompts**: a queued prompt cancelled with Esc (its parent is the interrupt marker) and a sent-then-edited array prompt are hidden; a raw `/compact` left beside its command record is hidden and the command stays; a prompt the model answered before a re-send, a prompt whose only later sibling is a sidechain record, and the newest unanswered prompt are all kept. |+| `abandoned-prompts` | **Abandoned prompts**: a queued prompt cancelled with Esc (its parent is the interrupt marker) and a sent-then-edited array prompt are hidden; a raw `/compact` left beside its command record is hidden and the command stays; a prompt the model answered before a re-send, a prompt whose only later sibling is a sidechain record, a prompt typed during a pending tool call (its later sibling is the tool-result record), and the newest unanswered prompt are all kept. |**`rich`** is a second desktop-only opt-in, beside `thinking`: the ⌘M panel reads with`page.rich: true` (`ChatParseOptions.rich`) to get the parts only it draws. The fixtures never set@@ -342,11 +342,19 @@ all of these hold:`type:"text"` and a non-empty string `text` and no element with `type:"tool_result"`;4. no record in the read has `parentUuid` equal to its `uuid` (any record type counts);5. a LATER record in the read has the same `parentUuid`, `type` `"user"` or `"assistant"`,- `isSidechain` not `true`, and a different `uuid`.+ `isSidechain` not `true`, a different `uuid`, and a `message.content` that is NOT an array+ holding an element with `type:"tool_result"`.++The last clause of rule 5 is measured: a prompt typed while a tool call is pending interrupts the+call, and Claude Code attaches the prompt and the call's tool-result record to the same parent (the+interrupt marker and the answer hang off the result). That prompt has no child and a later sibling,+yet the request that follows carries its text.Both checks see only the read's records, so on a paged read a sibling in a NEWER window is notseen and the prompt is shown, exactly as before this rule. Measured over 133 real transcripts-(5,886 prompts): 6 records match, and the model received none of them.+(5,886 prompts): 6 records match, and the model received none of them. A second set (306+transcripts, 2,899 prompts) gave 9 matches before the tool-result clause, one of them the answered+prompt above, and 8 after it.## Renderer rules that follow from these records (desktop; iOS notes)diff --git a/src/shared/chat-fixtures/expected/abandoned-prompts.pages.json b/src/shared/chat-fixtures/expected/abandoned-prompts.pages.jsonindex 4389d3533..3ef02beb3 100644--- a/src/shared/chat-fixtures/expected/abandoned-prompts.pages.json+++ b/src/shared/chat-fixtures/expected/abandoned-prompts.pages.json@@ -164,6 +164,53 @@"at": 1790362819000,"key": 7220},+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "tool",+ "name": "Bash",+ "arg": "npm run lint",+ "id": "toolu_b1",+ "result": "rejected"+ }+ ],+ "at": 1790362820000,+ "key": 7535+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "Stop, run the tests instead."+ }+ ],+ "at": 1790362821000,+ "key": 8029+ },+ {+ "role": "user",+ "parts": [+ {+ "kind": "text",+ "text": "[Request interrupted by user for tool use]"+ }+ ],+ "at": 1790362823000,+ "key": 8744+ },+ {+ "role": "assistant",+ "parts": [+ {+ "kind": "text",+ "text": "Running the tests."+ }+ ],+ "at": 1790362824000,+ "key": 9112+ },{"role": "user","parts": [@@ -172,8 +219,8 @@"text": "One more thing."}],- "at": 1790362820000,- "key": 7535+ "at": 1790362825000,+ "key": 9565}],"olderCursor": null,diff --git a/src/shared/chat-fixtures/inputs/abandoned-prompts.jsonl b/src/shared/chat-fixtures/inputs/abandoned-prompts.jsonlindex 08b9857f4..49f65f3f3 100644--- a/src/shared/chat-fixtures/inputs/abandoned-prompts.jsonl+++ b/src/shared/chat-fixtures/inputs/abandoned-prompts.jsonl@@ -18,4 +18,9 @@{"type":"user","message":{"role":"user","content":"<command-name>/compact</command-name>\n <command-message>compact</command-message>\n <command-args></command-args>"},"parentUuid":"00000000-0000-4000-8000-000000000016","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000017","timestamp":"2026-09-25T19:00:17.000Z"}{"type":"user","message":{"role":"user","content":"Check the lint."},"parentUuid":"00000000-0000-4000-8000-000000000017","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000018","timestamp":"2026-09-25T19:00:18.000Z"}{"type":"user","message":{"role":"user","content":"subagent prompt"},"parentUuid":"00000000-0000-4000-8000-000000000017","isSidechain":true,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000019","timestamp":"2026-09-25T19:00:19.000Z"}-{"type":"user","message":{"role":"user","content":"One more thing."},"parentUuid":"00000000-0000-4000-8000-000000000018","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000020","timestamp":"2026-09-25T19:00:20.000Z"}+{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"tool_use","id":"toolu_b1","name":"Bash","input":{"command":"npm run lint"}}],"stop_reason":null},"parentUuid":"00000000-0000-4000-8000-000000000018","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000020","timestamp":"2026-09-25T19:00:20.000Z"}+{"type":"user","message":{"role":"user","content":"Stop, run the tests instead."},"parentUuid":"00000000-0000-4000-8000-000000000020","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000021","timestamp":"2026-09-25T19:00:21.000Z"}+{"type":"user","message":{"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_b1","content":"rejected","is_error":false}]},"parentUuid":"00000000-0000-4000-8000-000000000020","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000022","timestamp":"2026-09-25T19:00:22.000Z"}+{"type":"user","message":{"role":"user","content":[{"type":"text","text":"[Request interrupted by user for tool use]"}]},"parentUuid":"00000000-0000-4000-8000-000000000022","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000023","timestamp":"2026-09-25T19:00:23.000Z"}+{"type":"assistant","effort":"high","message":{"id":"msg_synthetic","type":"message","role":"assistant","model":"claude-opus-5-5","content":[{"type":"text","text":"Running the tests."}],"stop_reason":null},"parentUuid":"00000000-0000-4000-8000-000000000023","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000024","timestamp":"2026-09-25T19:00:24.000Z"}+{"type":"user","message":{"role":"user","content":"One more thing."},"parentUuid":"00000000-0000-4000-8000-000000000024","isSidechain":false,"sessionId":"5f0c2a9e-3b7d-4e61-9a24-7c1d8e0f4b32","cwd":"/srv/demo","version":"2.1.290","uuid":"00000000-0000-4000-8000-000000000025","timestamp":"2026-09-25T19:00:25.000Z"}