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 the live tool run open while the agent waits on a prompt
reviewdade2efdb7a4
diff --git a/src/renderer/lib/chatToolGroups.test.ts b/src/renderer/lib/chatToolGroups.test.tsindex b5f392e8c..1081c1cf2 100644--- a/src/renderer/lib/chatToolGroups.test.ts+++ b/src/renderer/lib/chatToolGroups.test.ts@@ -108,9 +108,19 @@ describe('groupToolCalls', () => {const layout = groupToolCalls(messages, { foldTail: false })expect(runs(messages)).toEqual([['1:0', '2:0'], ['4:0', '5:0']]) // default folds bothexpect([...layout.groupAt.keys()]).toEqual(['1:0']) // tail run left alone+ expect(layout.absorbed.has('2:0')).toBe(true) // the earlier run still foldsexpect(layout.absorbed.has('5:0')).toBe(false)})+ it('foldTail:false still folds every run when the thread ends in something else', () => {+ const messages = [user('go'), call('Bash'), call('Read'), say('mid'), call('Bash'), call('Edit'), say('done')]++ const layout = groupToolCalls(messages, { foldTail: false })++ expect([...layout.groupAt.keys()]).toEqual(['1:0', '4:0'])+ expect([...layout.absorbed]).toEqual(['2:0', '5:0'])+ })+it('memberKey uses the transcript line key, so a prepended page does not re-key a member', () => {expect(memberKey([call('Bash', 120)], { message: 0, part: 0 })).toBe('k120:0')expect(memberKey([call('Bash')], { message: 0, part: 0 })).toBe('i0:0')diff --git a/src/renderer/nodes/ChatPanel.thread.test.tsx b/src/renderer/nodes/ChatPanel.thread.test.tsxindex 508606b23..89d2589e6 100644--- a/src/renderer/nodes/ChatPanel.thread.test.tsx+++ b/src/renderer/nodes/ChatPanel.thread.test.tsx@@ -157,4 +157,17 @@ describe('⌘M thread look', () => {expect(host.querySelector('.term-chat__tool-group')).toBeNull()expect(host.querySelectorAll('.term-chat__tool')).toHaveLength(2)})++ it('while the agent waits on a prompt mid-turn, the trailing run of tool calls is not folded', async () => {+ // `waiting` (a PermissionRequest) refuses with `dialog`: the turn is still live, so its calls stay+ // chips rather than folding closed on every prompt. The afterEach restores `done`.+ useAgentStatus.setState((s) => ({ byId: { ...s.byId, [NODE]: { state: 'waiting' } as (typeof s.byId)[string] } }))+ await mount([+ { role: 'user', parts: [{ kind: 'text', text: 'q' }], key: 0 },+ { role: 'assistant', parts: [{ kind: 'tool', name: 'Bash', arg: 'a' }], key: 10 },+ { role: 'assistant', parts: [{ kind: 'tool', name: 'Read', arg: 'b' }], key: 20 }+ ])+ expect(host.querySelector('.term-chat__tool-group')).toBeNull()+ expect(host.querySelectorAll('.term-chat__tool')).toHaveLength(2)+ })})diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsxindex e81bed9ae..79f716a9c 100644--- a/src/renderer/nodes/ChatPanel.tsx+++ b/src/renderer/nodes/ChatPanel.tsx@@ -969,10 +969,11 @@ export function ChatPanel({// (a per-row timer would be a timer per turn for a label that changes once a minute).const turnEnds = useMemo(() => assistantTurnEnds(messages), [messages])// Runs of consecutive tool calls, folded into one closed block each (lib/chatToolGroups.ts) —- // except, while the agent works, the run at the end of the thread: that is the live turn, and its- // calls stay open chips until something else ends the run.- const foldTail = refusal !== 'working'- const toolGroups = useMemo(() => groupToolCalls(messages, { foldTail }), [messages, foldTail])+ // except, while the turn is live, the run at the end of the thread: its calls stay open chips until+ // something else ends the run. Live = working, or waiting on a prompt (`dialog`: a permission+ // request or question lands MID-turn, and folding on it would close the run on every prompt).+ const liveTurn = refusal === 'working' || refusal === 'dialog'+ const toolGroups = useMemo(() => groupToolCalls(messages, { foldTail: !liveTurn }), [messages, liveTurn])// The last key IS the latest turn end: `assistantTurnEnds` inserts in thread order.const latestTurnEnd = useMemo(() => {let last = -1diff --git a/src/renderer/styles.chat-view.test.ts b/src/renderer/styles.chat-view.test.tsindex 1f4f44114..6cd12f571 100644--- a/src/renderer/styles.chat-view.test.ts+++ b/src/renderer/styles.chat-view.test.ts@@ -78,7 +78,9 @@ describe('⌘M thread: claude.ai look', () => {})it('a folded message collapses to its action row', () => {- expect(ruleBody('.term-chat__msg--folded')).toMatch(/padding:\s*0;/)+ const folded = ruleBody('.term-chat__msg--folded')+ expect(folded).toMatch(/padding:\s*0;/)+ expect(folded).toMatch(/min-height:\s*0;/)})})diff --git a/src/shared/chat-fixtures/README.md b/src/shared/chat-fixtures/README.mdindex 7c1a89508..e81281a89 100644--- a/src/shared/chat-fixtures/README.md+++ b/src/shared/chat-fixtures/README.md@@ -72,7 +72,7 @@ the production paging, not a second implementation of it.| fixture | pins ||---|---|| `plain-turns` | User/assistant text, markdown (headings, lists, a blockquote, code fences), string and array user content, two text blocks in one message, and non-ASCII text. Metadata-only records (`file-history-snapshot`, `system`) yield no message. |-| `tools-cross-page` | A `tool_use` that lands in the second (older) page while its `tool_result` lands in the tail. The tail carries it in `unmatchedResults`, and the older page carries the tool part with its `id` so the port can attach it. One tool call is matched inside the tail. It also shows the `summarizeResult` rules: three lines joined, capped at 500. The desktop renderer folds a run of two or more consecutive agent tool calls into one block, and the parser output is unchanged, so a port that renders a thread should fold the same runs. |+| `tools-cross-page` | A `tool_use` that lands in the second (older) page while its `tool_result` lands in the tail. The tail carries it in `unmatchedResults`, and the older page carries the tool part with its `id` so the port can attach it. One tool call is matched inside the tail. It also shows the `summarizeResult` rules: three lines joined, capped at 500. The desktop renderer folds a run of two or more consecutive agent tool calls into one block, except the run at the END of the thread while the agent is working or waiting on a prompt (the live turn), and the parser output is unchanged, so a port that renders a thread should fold the same runs. || `plan-mode` | An `ExitPlanMode` tool call with `input:{plan}`. The tool part carries the full plan as `body` and the approval text as `result`. || `ask-question` | `AskUserQuestion` with a single-select and a multi-select question: the rendered `body`, the parsed `questions` (the same reader the answer controls match on) and each result. || `utf8-edge` | Multi-byte characters on the window boundaries. The tail window (EOF − 262144) opens **inside** a 4-byte emoji of one line, which must be dropped as the partial line and never decoded torn. The second page (524288) starts **exactly** on the first byte of a multi-byte line, which is kept only because of the lookbehind `\n`. The straddled line reappears whole in that page. The test asserts both placements. |