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): a draft carry never escapes as an unhandled rejection
Paul Robertsonc5e0033533ca
diff --git a/src/renderer/components/kanban/CardModal.test.tsx b/src/renderer/components/kanban/CardModal.test.tsxindex 7abe0d4ab..6644b1892 100644--- a/src/renderer/components/kanban/CardModal.test.tsx+++ b/src/renderer/components/kanban/CardModal.test.tsx@@ -15,7 +15,11 @@ vi.mock('../../session/session', async () => {return {useSession: () => ({api: {- pty: { generateName: vi.fn(async () => ({ ok: true, message: 'AI Name' })) },+ pty: {+ generateName: vi.fn(async () => ({ ok: true, message: 'AI Name' })),+ putChatDraft: vi.fn(async () => ({ put: false, reason: 'empty' })),+ takeChatDraft: vi.fn(async () => ({ taken: false, reason: 'empty' }))+ },shell: { openExternal: vi.fn(async () => {}) }}}),diff --git a/src/renderer/lib/chatDraftCarry.test.ts b/src/renderer/lib/chatDraftCarry.test.tsindex 62b963be1..213923811 100644--- a/src/renderer/lib/chatDraftCarry.test.ts+++ b/src/renderer/lib/chatDraftCarry.test.ts@@ -148,3 +148,28 @@ describe('carryDraftToChat', () => {expect(note()).toBeNull()})})++describe('a pty method that throws instead of rejecting', () => {+ const throwing = () => {+ throw new Error('not a function')+ }++ it('leaves the chat draft in place on the way to the terminal', async () => {+ useChatDraft.getState().setDraft(NODE, 'half a thought')+ const p = pty({ put: true })+ p.putChatDraft.mockImplementation(throwing)++ await expect(carryDraftToTerminal(p, NODE, 'claude')).resolves.toBeUndefined()++ expect(draft()).toBe('half a thought')+ })++ it('leaves the composer empty on the way to chat', async () => {+ const p = pty({ put: true })+ p.takeChatDraft.mockImplementation(throwing)++ await expect(carryDraftToChat(p, NODE, 'claude')).resolves.toBeUndefined()++ expect(draft()).toBe('')+ })+})diff --git a/src/renderer/lib/chatDraftCarry.ts b/src/renderer/lib/chatDraftCarry.tsindex 59b2c423b..057548f17 100644--- a/src/renderer/lib/chatDraftCarry.ts+++ b/src/renderer/lib/chatDraftCarry.ts@@ -68,7 +68,11 @@ export async function carryDraftToTerminal(pty: DraftCarryPty, nodeId: string, aif (!carriesDraft(agentId)) returnconst draft = useChatDraft.getState().drafts[nodeId] ?? ''if (draft.trim() === '') return- const put = pty.putChatDraft(nodeId, agentId, draft).catch((): ChatDraftPutResult => ({ put: false, reason: 'failed' }))+ // Called inside an async function so a synchronous throw is caught like a rejection: both callers+ // `void` the carry, and an escaped throw would be an unhandled rejection.+ const put = (async () => pty.putChatDraft(nodeId, agentId, draft))().catch(+ (): ChatDraftPutResult => ({ put: false, reason: 'failed' })+ )const settled = put.then((r) => {if (r.put) {// Only the draft that was typed: a draft changed meanwhile is the user's newer text.@@ -86,7 +90,9 @@ export async function carryDraftToChat(pty: DraftCarryPty, nodeId: string, agentif (!carriesDraft(agentId)) return// Two drafts are never merged: a chat draft already waiting wins, and the terminal keeps its own.if ((useChatDraft.getState().drafts[nodeId] ?? '') !== '') return- const r = await pty.takeChatDraft(nodeId, agentId).catch((): ChatDraftTakeResult => ({ taken: false, reason: 'failed' }))+ const r = await (async () => pty.takeChatDraft(nodeId, agentId))().catch(+ (): ChatDraftTakeResult => ({ taken: false, reason: 'failed' })+ )const store = useChatDraft.getState()if (r.taken) {// Typed into the composer while the take ran: the taken text goes first, as it was older.