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.

fix(chat): probe the pane's foreground process before a phone send, for every agent

Payton Schwarzc1dc7a8a8aa6
diff --git a/src/renderer/lib/chatPaneGate.test.ts b/src/renderer/lib/chatPaneGate.test.ts
index 476156613..d4eff3ed9 100644
--- a/src/renderer/lib/chatPaneGate.test.ts
+++ b/src/renderer/lib/chatPaneGate.test.ts
@@ -1,6 +1,6 @@
-// The chat send's second gate: for an agent whose hooks never announce a session end (codex,
-// opencode), the kernel must prove the agent owns the pane before text + Enter is typed — or a
-// message sent after the user `/quit` codex runs as a SHELL command.
+// The chat send's second gate: for EVERY agent, the kernel must prove the agent owns the pane before
+// text + Enter is typed — or a message sent after the agent is gone (codex `/quit`, which no hook
+// announces, or a claude that died without its SessionEnd) runs as a SHELL command.
import { afterEach, describe, expect, it, vi } from 'vitest'
import { chatPaneRefusal, chatPaneRefusalReason, chatPaneRefusalToast } from './chatPaneGate'
import { setCustomAgentBaseResolver } from '@shared/agents/config'
@@ -18,6 +18,16 @@ const CODEX_PANE: PaneOwner = {
pids: [201550, 201574]
}
const SHELL_PANE: PaneOwner = { panePid: 100, tty: '/dev/pts/31', command: 'bash', argv: ['-bash'], pids: [100] }
+// Claude's two shapes: the native binary, and `node …/claude` (tmux then reports `command: 'node'`,
+// as measured in pane-owner-predicate.ts).
+const CLAUDE_PANE: PaneOwner = { panePid: 100, tty: '/dev/pts/31', command: 'claude', argv: ['claude'], pids: [201600] }
+const CLAUDE_NODE_PANE: PaneOwner = {
+ panePid: 100,
+ tty: '/dev/pts/31',
+ command: 'node',
+ argv: ['node /usr/local/bin/claude --resume x'],
+ pids: [201601]
+}
describe('chatPaneRefusal', () => {
it('lets a send through when codex owns the pane', async () => {
@@ -33,10 +43,23 @@ describe('chatPaneRefusal', () => {
expect(await chatPaneRefusal('codex', 'n1', { paneOwner: async () => { throw new Error('ssh') } })).toBe('unverified')
})
- it('an agent whose hooks DO report a session end is not probed at all (unchanged path)', async () => {
+ // Claude announces SessionEnd, but only when it exits cleanly. Observed 2026-11-13: a Claude pane
+ // was back at its shell (likely after its project was closed; the store's state then was not
+ // captured) and a phone chat message was typed into zsh as a command. So agents whose hooks
+ // report a session end are probed too; the hook is a hint, the kernel is the proof.
+ it('probes agents that report session ends too: the shell a silent exit left behind refuses', async () => {
const paneOwner = vi.fn(async () => SHELL_PANE)
- for (const id of ['claude', 'grok']) expect(await chatPaneRefusal(id, 'n1', { paneOwner })).toBeNull()
- expect(paneOwner).not.toHaveBeenCalled()
+ for (const id of ['claude', 'grok']) expect(await chatPaneRefusal(id, 'n1', { paneOwner })).toBe('exited')
+ expect(paneOwner).toHaveBeenCalledTimes(2)
+ })
+
+ it('lets a send through when claude owns the pane, native or under node', async () => {
+ expect(await chatPaneRefusal('claude', 'n1', { paneOwner: async () => CLAUDE_PANE })).toBeNull()
+ expect(await chatPaneRefusal('claude', 'n1', { paneOwner: async () => CLAUDE_NODE_PANE })).toBeNull()
+ })
+
+ it('refuses a claude pane it cannot read (unknown is never upgraded to agent)', async () => {
+ expect(await chatPaneRefusal('claude', 'n1', { paneOwner: async () => null })).toBe('unverified')
})
it('a custom agent on the codex harness is probed for the binary its launch command runs', async () => {
diff --git a/src/renderer/lib/chatPaneGate.ts b/src/renderer/lib/chatPaneGate.ts
index 8326f04a0..e35b4fb02 100644
--- a/src/renderer/lib/chatPaneGate.ts
+++ b/src/renderer/lib/chatPaneGate.ts
@@ -1,16 +1,18 @@
// The chat send's KERNEL gate — the second half of "may the ⌘M composer / the phone type into this
// pane?", after `chatSendRefusal` (chatSendGate.ts).
//
-// `chatSendRefusal` reads the agent-status store, and for most agents that is enough: a CLI that
-// quits announces it (SessionEnd → `sessionEnded`), so a shell-owned pane is refused. Codex and
-// opencode announce NO session end (see SESSION_END_CAPABLE in shared/agents/config.ts): after a
-// deliberate `/quit` their last hook state is still `done`, and the store reads "at its prompt". A
-// chat message sent then is pasted into the SHELL with an Enter — it runs as a command. So for those
-// agents the pane's foreground process group is asked (`isAgentPane`, the same positive, three-
-// valued predicate the wake and delivery gates use) right before the send.
-//
-// Agents that DO report a session end are not probed: their path is byte-identical to before.
-import { capabilityAgentId, reportsSessionEnd } from '@shared/agents/config'
+// `chatSendRefusal` reads the agent-status store. A CLI that quits cleanly may announce it
+// (SessionEnd → `sessionEnded`), but the store cannot be the proof:
+// - Codex and opencode announce NO session end (see SESSION_END_CAPABLE in shared/agents/config.ts):
+// after a deliberate `/quit` their last hook state is still `done`, and the store reads "at its
+// prompt".
+// - Agents that DO announce one only do so on a clean exit. Observed 2026-11-13: a Claude pane
+// was back at its shell (likely after its project was closed on the desktop; the store's exact
+// state then was not captured), yet a phone chat message passed the gate and was pasted into the
+// SHELL with an Enter — it ran as a command.
+// So for EVERY agent the pane's foreground process group is asked (`isAgentPane`, the same
+// positive, three-valued predicate the wake and delivery gates use) right before the send. The hook
+// is a hint; the kernel is the proof. An unreadable pane refuses (`unverified`), never sends.
import { binariesFor, isAgentPane, type PaneOwner } from '@shared/agents/pane-owner-predicate'
import type { ChatSendReason } from '@shared/mobile-chat'
@@ -27,7 +29,6 @@ export async function chatPaneRefusal(
customAgents?: readonly { id: string; launchCmd: string; baseAgent?: string }[]
}
): Promise<ChatPaneRefusal> {
- if (reportsSessionEnd(capabilityAgentId(agentId))) return null
let owner: PaneOwner | null
try {
owner = await deps.paneOwner(nodeId)
diff --git a/src/renderer/lib/hostChatQuery.ts b/src/renderer/lib/hostChatQuery.ts
index 1784d73c7..a24047ebf 100644
--- a/src/renderer/lib/hostChatQuery.ts
+++ b/src/renderer/lib/hostChatQuery.ts
@@ -32,9 +32,10 @@ export interface HostChatSendDeps {
sendText(nodeId: string, text: string): Promise<TextDeliveryResult>
now(): number
/**
- * The KERNEL gate (`chatPaneRefusal`, chatPaneGate.ts): for an agent that announces no session end
- * (codex), is the agent really in the pane? Required, not optional — a shell that forgot it would
- * type the phone's text into whatever shell a quit codex left behind, and that must not compile.
+ * The KERNEL gate (`chatPaneRefusal`, chatPaneGate.ts): is the agent really in the pane? Asked for
+ * EVERY agent — codex announces no session end, and even a claude pane was observed back at its
+ * shell with the gate still open (2026-11-13). Required, not optional — a shell that forgot it would type the phone's
+ * text into whatever shell a quit agent left behind, and that must not compile.
*/
paneRefusal(nodeId: string, agentId: string): Promise<ChatPaneRefusal>
}
diff --git a/src/renderer/nodes/ChatPanel.codexSend.test.tsx b/src/renderer/nodes/ChatPanel.codexSend.test.tsx
index 477be18b7..66d9b0fd0 100644
--- a/src/renderer/nodes/ChatPanel.codexSend.test.tsx
+++ b/src/renderer/nodes/ChatPanel.codexSend.test.tsx
@@ -92,9 +92,19 @@ describe('ChatPanel — codex send asks the kernel', () => {
expect(toasts).toEqual(['Codex is no longer running in this terminal — the message was not sent.'])
})
- it('claude is not probed (its hooks announce a quit)', async () => {
+ // Claude's hooks announce a clean quit, but a Claude pane was observed back at its shell while a
+ // phone chat message still passed the gate (2026-11-13; likely after its project was closed).
+ // So claude is probed like every agent: a claude pane sends, a shell left behind refuses.
+ it('claude is probed too: its pane sends', async () => {
+ paneOwner.mockResolvedValue({ panePid: 1, tty: '/dev/ttys001', command: 'claude', argv: ['claude'], pids: [2] })
await send(await mount('claude'), 'hello')
- expect(paneOwner).not.toHaveBeenCalled()
+ expect(paneOwner).toHaveBeenCalled()
expect(sendChatPrompt).toHaveBeenCalled()
})
+
+ it('claude is probed too: a shell left behind refuses the send', async () => {
+ paneOwner.mockResolvedValue({ panePid: 1, tty: '/dev/ttys001', command: 'zsh', argv: ['-zsh'], pids: [1] })
+ await send(await mount('claude'), 'hello')
+ expect(sendChatPrompt).not.toHaveBeenCalled()
+ })
})
diff --git a/src/renderer/nodes/ChatPanel.composer.test.tsx b/src/renderer/nodes/ChatPanel.composer.test.tsx
index 2b3df1294..d3f793f3b 100644
--- a/src/renderer/nodes/ChatPanel.composer.test.tsx
+++ b/src/renderer/nodes/ChatPanel.composer.test.tsx
@@ -24,7 +24,7 @@ const { sendText, sendChatPrompt, session } = vi.hoisted(() => {
const session = {
api: {
chat: { readTranscript: async () => ({ messages: [], found: true }) },
- pty: { sendText, sendChatPrompt }
+ pty: { sendText, sendChatPrompt, paneOwner: async () => ({ panePid: 1, tty: '/dev/ttys001', command: 'claude', argv: ['claude'], pids: [2] }) }
}
}
return { sendText, sendChatPrompt, session }
diff --git a/src/renderer/nodes/ChatPanel.draft.test.tsx b/src/renderer/nodes/ChatPanel.draft.test.tsx
index 6eacf929f..e01f07ced 100644
--- a/src/renderer/nodes/ChatPanel.draft.test.tsx
+++ b/src/renderer/nodes/ChatPanel.draft.test.tsx
@@ -17,7 +17,7 @@ const { sendChatPrompt, session } = vi.hoisted(() => {
const session = {
api: {
chat: { readTranscript: async () => ({ messages: [], found: true }) },
- pty: { sendChatPrompt, paneOwner: async () => null }
+ pty: { sendChatPrompt, paneOwner: async () => ({ panePid: 1, tty: '/dev/ttys001', command: 'claude', argv: ['claude'], pids: [2] }) }
}
}
return { sendChatPrompt, session }
diff --git a/src/renderer/nodes/ChatPanel.escInterrupt.test.tsx b/src/renderer/nodes/ChatPanel.escInterrupt.test.tsx
index 57b1b4e72..4bb9af385 100644
--- a/src/renderer/nodes/ChatPanel.escInterrupt.test.tsx
+++ b/src/renderer/nodes/ChatPanel.escInterrupt.test.tsx
@@ -23,7 +23,7 @@ const { interruptChat, readTranscript, sendChatPrompt, session } = vi.hoisted(()
const session = {
api: {
chat: { readTranscript },
- pty: { interruptChat, sendChatPrompt, paneOwner: async () => null }
+ pty: { interruptChat, sendChatPrompt, paneOwner: async () => ({ panePid: 1, tty: '/dev/ttys001', command: 'claude', argv: ['claude'], pids: [2] }) }
}
}
return { interruptChat, readTranscript, sendChatPrompt, session }
diff --git a/src/renderer/nodes/ChatPanel.live.test.tsx b/src/renderer/nodes/ChatPanel.live.test.tsx
index 357c9a645..92d2b30c2 100644
--- a/src/renderer/nodes/ChatPanel.live.test.tsx
+++ b/src/renderer/nodes/ChatPanel.live.test.tsx
@@ -33,7 +33,7 @@ const { pending, session, sendChatPrompt } = vi.hoisted(() => {
page?: ChatTranscriptPageRequest
) => new Promise<ChatTranscriptResult>((resolve, reject) => pending.push({ page, resolve, reject }))
const sendChatPrompt = vi.fn(async (_id: string, _t: string, _agent: string) => true as const)
- const session = { api: { chat: { readTranscript }, pty: { sendChatPrompt } } }
+ const session = { api: { chat: { readTranscript }, pty: { sendChatPrompt, paneOwner: async () => ({ panePid: 1, tty: '/dev/ttys001', command: 'claude', argv: ['claude'], pids: [2] }) } } }
return { pending, session, sendChatPrompt }
})
vi.mock('../session/session', () => ({ useSession: () => session }))
diff --git a/src/renderer/nodes/ChatPanel.queuedRemount.test.tsx b/src/renderer/nodes/ChatPanel.queuedRemount.test.tsx
index 421155027..b6145b9fa 100644
--- a/src/renderer/nodes/ChatPanel.queuedRemount.test.tsx
+++ b/src/renderer/nodes/ChatPanel.queuedRemount.test.tsx
@@ -25,7 +25,12 @@ const { transcript, session } = vi.hoisted(() => {
olderCursor: null
})
},
- pty: { sendChatPrompt: vi.fn(async () => true as const) }
+ // The send gate probes the pane's foreground process for every agent, so the fake pane is
+ // a live claude; without it the gate refuses the send as `unverified`.
+ pty: {
+ sendChatPrompt: vi.fn(async () => true as const),
+ paneOwner: async () => ({ panePid: 1, tty: '/dev/ttys001', command: 'claude', argv: ['claude'], pids: [2] })
+ }
}
}
return { transcript, session }
diff --git a/src/renderer/nodes/ChatPanel.screenDialog.test.tsx b/src/renderer/nodes/ChatPanel.screenDialog.test.tsx
index 91dd52c16..e0d34ac22 100644
--- a/src/renderer/nodes/ChatPanel.screenDialog.test.tsx
+++ b/src/renderer/nodes/ChatPanel.screenDialog.test.tsx
@@ -38,7 +38,7 @@ const { screen, capture, sendChatPrompt, session } = vi.hoisted(() => {
source: 'local',
api: {
chat: { readTranscript: async () => ({ messages: [], found: true, olderCursor: null, unmatchedResults: [] }) },
- pty: { readChatScreen: capture, sendChatPrompt, sendText: vi.fn() }
+ pty: { readChatScreen: capture, sendChatPrompt, sendText: vi.fn(), paneOwner: async () => ({ panePid: 1, tty: '/dev/ttys001', command: 'claude', argv: ['claude'], pids: [2] }) }
}
}
return { screen, capture, sendChatPrompt, session }
diff --git a/src/renderer/nodes/ChatPanel.sendGate.test.tsx b/src/renderer/nodes/ChatPanel.sendGate.test.tsx
index 63261369f..cf1a2877b 100644
--- a/src/renderer/nodes/ChatPanel.sendGate.test.tsx
+++ b/src/renderer/nodes/ChatPanel.sendGate.test.tsx
@@ -22,7 +22,7 @@ const { sendChatPrompt, session } = vi.hoisted(() => {
const session = {
api: {
chat: { readTranscript: async () => ({ messages: [], found: true }) },
- pty: { sendChatPrompt }
+ pty: { sendChatPrompt, paneOwner: async () => ({ panePid: 1, tty: '/dev/ttys001', command: 'claude', argv: ['claude'], pids: [2] }) }
}
}
return { sendChatPrompt, session }
diff --git a/src/renderer/nodes/ChatPanel.thread.test.tsx b/src/renderer/nodes/ChatPanel.thread.test.tsx
index b79925545..e5661889f 100644
--- a/src/renderer/nodes/ChatPanel.thread.test.tsx
+++ b/src/renderer/nodes/ChatPanel.thread.test.tsx
@@ -24,7 +24,7 @@ const { session, reads } = vi.hoisted(() => {
return { messages: reads.messages, found: true, olderCursor: null, unmatchedResults: [] }
}
},
- pty: { sendText: vi.fn(async () => true as const), sendChatPrompt: vi.fn(async () => true as const) }
+ pty: { sendText: vi.fn(async () => true as const), sendChatPrompt: vi.fn(async () => true as const), paneOwner: async () => ({ panePid: 1, tty: '/dev/ttys001', command: 'claude', argv: ['claude'], pids: [2] }) }
}
}
return { session, reads }
diff --git a/src/renderer/nodes/ChatPanel.ux.test.tsx b/src/renderer/nodes/ChatPanel.ux.test.tsx
index 96c33d48e..e227ec7ef 100644
--- a/src/renderer/nodes/ChatPanel.ux.test.tsx
+++ b/src/renderer/nodes/ChatPanel.ux.test.tsx
@@ -28,7 +28,7 @@ const { sendChatPrompt, readTranscript, pending, session } = vi.hoisted(() => {
(sessionId: string | undefined) =>
new Promise<ChatTranscriptResult>((resolve, reject) => pending.push({ sessionId, resolve, reject }))
)
- const session = { api: { chat: { readTranscript }, pty: { sendChatPrompt } } }
+ const session = { api: { chat: { readTranscript }, pty: { sendChatPrompt, paneOwner: async () => ({ panePid: 1, tty: '/dev/ttys001', command: 'claude', argv: ['claude'], pids: [2] }) } } }
return { sendChatPrompt, readTranscript, pending, session }
})
vi.mock('../session/session', () => ({ useSession: () => session }))