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): confirm a typed ⌘M prompt from the composer, so short answers submit
Paul Robertson845ba5bc268a
diff --git a/CLAUDE.md b/CLAUDE.mdindex 79491cf96..e09bd3d29 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -4426,7 +4426,14 @@ command-bearing opens; this does not add a human-confirm dialog or change mobilethe dialog check `sendChatPrompt` makes is seconds old by then, and an Enter into a dialog thatopened meanwhile would ANSWER it — the text stays in the composer and the caller hears`pasted-not-submitted`. The panel ignores a second Enter while a send is in flight (the draft is- cleared only once it lands).+ cleared only once it lands). **"The text arrived" is read from the COMPOSER, never counted+ across the screen** (`TypedSurface.draftOf` → `readClaudeDraft`, on a styled capture so the dim+ placeholder is not draft text): the draft must end with the message's tail and differ from the+ draft before typing. Typing also clears the placeholder and shortens the status line ("· ← for+ agents" goes away), so a one-letter answer like `a` appeared once more in the box and once less+ elsewhere; the screen-wide count never rose and every such send ended `pasted-not-submitted` with+ the answer sitting in the box. The screen-wide count stays only as the fallback for a poll with+ no readable input box (a draft too tall for the box reader).**The agent's OWN dialogs are read off the screen** (`shared/agents/claude-screen.ts`, claudeonly — `SCREEN_DIALOG_READABLE`). The folder-trust prompt, `/model` and one-time setup questionsfire NO hook, so the state gate above reads `done` while one owns the keyboard, and a paste intodiff --git a/src/core/pty-manager.ts b/src/core/pty-manager.tsindex e98ead056..2f1293b5c 100644--- a/src/core/pty-manager.ts+++ b/src/core/pty-manager.ts@@ -1,5 +1,5 @@import type { ChatPromptBlocked, ChatPromptResult, EmptyPromptResult, TextDeliveryResult } from '../shared/text-delivery'-import { claudeScreenBlocksInput, readClaudeComposer, readClaudeScreen } from '../shared/agents/claude-screen'+import { claudeScreenBlocksInput, readClaudeComposer, readClaudeDraft, readClaudeScreen } from '../shared/agents/claude-screen'import os from 'os'import fs from 'fs'import path from 'path'@@ -6690,12 +6690,18 @@ export class PtyManager {return false}}+ // For an agent whose composer we can read, the settle check reads the draft in its input box+ // (`readClaudeDraft`), which needs the styled capture: the placeholder is told apart by being dim.+ const readsDraft = readsScreenDialogs(agentId)try {return await typeThenSubmitWhenSettled(text, {capture: async () => {- const screen = await this.captureSession(persistKey)+ const screen = readsDraft+ ? await this.captureStyledScreen(persistKey)+ : await this.captureSession(persistKey)return screen === '' ? null : screen},+ draftOf: readsDraft ? readClaudeDraft : undefined,type: (stdin) => ok(() => type(stdin)),// An empty capture is not evidence of a dialog (the `sendChatPrompt` rule).canSubmit: async () => {diff --git a/src/core/typed-input.test.ts b/src/core/typed-input.test.tsindex 269cbbe74..73d06bcdb 100644--- a/src/core/typed-input.test.ts+++ b/src/core/typed-input.test.ts@@ -9,6 +9,8 @@ import {typedStdin,type TypedSurface} from './typed-input'+import { readClaudeDraft } from '../shared/agents/claude-screen'+import composer from '../shared/agents/__fixtures__/claude/composer-capture.json'describe('typedLines', () => {it('splits on every line-ending style and keeps blank lines', () => {@@ -143,6 +145,50 @@ describe('typeThenSubmitWhenSettled', () => {expect(surface.submit).toHaveBeenCalledTimes(1)})+ it('submits a one-letter answer whose letter typing also removes elsewhere on screen', async () => {+ // Real Claude Code captures: typing clears the placeholder and shortens the status line, which+ // loses the `a` in "← for agents". Counting `a` across the screen never rose, so the Enter was+ // withheld with the answer sitting in the box.+ const before = composer.screens.empty+ const after = composer.screens.draft.replace('heb ik getest', 'a')+ let captures = 0+ const submit = vi.fn(async () => true)++ const result = await typeThenSubmitWhenSettled('a', {+ capture: async () => (captures++ === 0 ? before : after),+ type: async () => true,+ submit,+ draftOf: readClaudeDraft+ }, noWait)++ expect(result).toBe(true)+ expect(submit).toHaveBeenCalledTimes(1)+ })++ it('does not take a draft that already ended with the answer as the answer arriving', async () => {+ const leftover = composer.screens.draft.replace('heb ik getest', 'a')+ const submit = vi.fn(async () => true)++ const result = await typeThenSubmitWhenSettled('a', {+ capture: async () => leftover,+ type: async () => true,+ submit,+ draftOf: readClaudeDraft+ }, noWait)++ expect(result).toBe('pasted-not-submitted')+ expect(submit).not.toHaveBeenCalled()+ })++ it('falls back to counting on screen when the composer cannot be read', async () => {+ const surface = { ...fakeSurface({ lag: 1 }), draftOf: () => null }++ const result = await typeThenSubmitWhenSettled('hello there', surface, noWait)++ expect(result).toBe(true)+ expect(surface.submit).toHaveBeenCalledTimes(1)+ })+it('types nothing for a message with no visible characters', async () => {const surface = fakeSurface({})diff --git a/src/core/typed-input.ts b/src/core/typed-input.tsindex 3889d0b99..06106d3d4 100644--- a/src/core/typed-input.ts+++ b/src/core/typed-input.ts@@ -114,6 +114,12 @@ export interface TypedSurface {* meanwhile), and the Enter — which would ANSWER it — is not sent. Absent = always submit.*/canSubmit?(): Promise<boolean>+ /**+ * What the agent's composer holds in a `capture()` result, whitespace removed, or null when this+ * screen does not show it. When it answers, it decides whether the text has arrived (see+ * `typeThenSubmitWhenSettled`). Absent = an agent whose composer we cannot read.+ */+ draftOf?(screen: string): string | null}// eslint-disable-next-line no-control-regex@@ -134,9 +140,15 @@ export const TYPED_NEEDLE_CHARS = 24** "Shows it" is NOT "the screen stopped changing" (the envelope path's rule): while an agent works,* its spinner and token counter repaint constantly, so a stable screen never comes and a QUEUED- * prompt would never be submitted. It is: the message's tail is on screen MORE times than before- * the typing, on two polls in a row — more, so an identical earlier message already visible does- * not count; twice, so the composer has finished taking the burst in.+ * prompt would never be submitted. It is, on two polls in a row (twice, so the composer has finished+ * taking the burst in):+ * - when the surface can read the composer (`draftOf`): the draft ends with the message's tail and+ * differs from the draft before the typing. Only the composer counts, because typing changes the+ * rest of the screen too (Claude Code clears its placeholder and shortens its status line), and+ * for a short answer that change can take away exactly the characters the text adds;+ * - otherwise: the message's tail is on screen MORE times than before the typing — more, so an+ * identical earlier message already visible does not count. This is also the rule for a poll+ * whose screen shows no readable composer.** `pasted-not-submitted` whenever the text may be in the composer unsent — a failed or partial* type, an unconfirmed settle, a failed Enter. Callers surface it and never resend.@@ -154,6 +166,12 @@ export async function typeThenSubmitWhenSettled(if (!(await surface.type(typedStdin(lines)))) return 'pasted-not-submitted'if (before === null) return 'pasted-not-submitted'const baseline = occurrences(visible(before), needle)+ const draftBefore = surface.draftOf?.(before) ?? null+ const arrived = (screen: string): boolean => {+ const draft = surface.draftOf?.(screen) ?? null+ if (draft !== null) return draft.endsWith(needle) && draft !== draftBefore+ return occurrences(visible(screen), needle) > baseline+ }const wait = options.wait ?? ((ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)))const polls = Math.max(1, options.polls ?? ENVELOPE_SETTLE_POLLS)@@ -161,7 +179,7 @@ export async function typeThenSubmitWhenSettled(for (let i = 0; i < polls; i++) {await wait(ENVELOPE_SETTLE_POLL_MS)const now = await surface.capture()- const shown = now !== null && occurrences(visible(now), needle) > baseline+ const shown = now !== null && arrived(now)if (shown && seenOnce) {if (surface.canSubmit && !(await surface.canSubmit())) return 'pasted-not-submitted'return (await surface.submit()) ? true : 'pasted-not-submitted'diff --git a/src/shared/agents/claude-composer.test.ts b/src/shared/agents/claude-composer.test.tsindex 111c2cb2d..94cb221fa 100644--- a/src/shared/agents/claude-composer.test.ts+++ b/src/shared/agents/claude-composer.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest'-import { readClaudeComposer } from './claude-screen'+import { readClaudeComposer, readClaudeDraft } from './claude-screen'import capture from './__fixtures__/claude/composer-capture.json'// Real captures (Claude Code 2.1.301, `capture-pane -p -e`) — see the fixture's `_note`. Issue #1144.@@ -57,3 +57,33 @@ describe('readClaudeComposer (#1144)', () => {expect(readClaudeComposer('\n\n')).toBe('unknown')})})++describe('readClaudeDraft', () => {+ it('reads an empty composer as an empty draft: the dim placeholder is not the user’s text', () => {+ expect(readClaudeDraft(S.empty)).toBe('')+ })++ it('reads a typed draft without the prompt character or whitespace', () => {+ expect(readClaudeDraft(S.draft)).toBe('hebikgetest')+ })++ it('reads every line of a multi-line draft', () => {+ expect(readClaudeDraft(S.multiline)).toBe('hebikgetestlinetwo')+ })++ it('keeps shell mode’s typed `!` and drops the dim placeholder after it', () => {+ expect(readClaudeDraft(S.shellmode)).toBe('!')+ })++ it('reads a one-letter answer', () => {+ expect(readClaudeDraft(S.draft.replace('heb ik getest', 'a'))).toBe('a')+ })++ it('is null when there is no live input box, and for an empty capture', () => {+ const noBox = S.empty.split('\n').filter((l) => !l.includes('─')).join('\n')+ expect(readClaudeDraft(noBox)).toBeNull()+ const dialog = S.empty.replace(/\n[^\n]*manual mode on[^\n]*/, '\n Enter to confirm · Esc to cancel')+ expect(readClaudeDraft(dialog)).toBeNull()+ expect(readClaudeDraft('')).toBeNull()+ })+})diff --git a/src/shared/agents/claude-screen.ts b/src/shared/agents/claude-screen.tsindex 8b37b998c..555a69f66 100644--- a/src/shared/agents/claude-screen.ts+++ b/src/shared/agents/claude-screen.ts@@ -132,10 +132,17 @@ export function claudeScreenBlocksInput(s: ClaudeScreen): boolean {export type ClaudeComposer = 'empty' | 'draft' | 'no-prompt' | 'unknown'/** Does any visible, non-blank character of this styled line (from `from`, a plain-text column)- * sit outside SGR dim? Walks the SGR state; non-SGR escapes are skipped. */+ * sit outside SGR dim? */function hasUndimmedText(styled: string, from: number): boolean {+ return undimmedText(styled, from).trim() !== ''+}++/** The characters of this styled line (from `from`, a plain-text column) drawn outside SGR dim, in+ * order. Walks the SGR state; non-SGR escapes are skipped. */+function undimmedText(styled: string, from: number): string {let dim = falselet col = 0+ let out = ''let i = 0while (i < styled.length) {if (styled[i] === '\x1b') {@@ -151,11 +158,11 @@ function hasUndimmedText(styled: string, from: number): boolean {continue}const ch = String.fromCodePoint(styled.codePointAt(i)!)- if (col >= from && ch.trim() !== '' && !dim) return true+ if (col >= from && !dim) out += chcol += ch.lengthi += ch.length}- return false+ return out}/** The dim flag after one SGR sequence's parameters. Extended colours (`38;5;n`, `38;2;r;g;b`, and@@ -186,3 +193,34 @@ export function readClaudeComposer(styledScreen: string): ClaudeComposer {for (let i = promptAt + 1; i < box[1]; i++) if (lines[i].trim() !== '') return 'draft'return hasUndimmedText(styled[promptAt], 1) ? 'draft' : 'empty'}++/**+ * What the user's draft in Claude Code's composer says, read from a STYLED capture, with all+ * whitespace removed: the undimmed text of every line in the live input box, minus the `❯` prompt+ * character. Shell mode's `!` is kept, since it was typed. The dim placeholder is not part of it, so+ * an empty composer reads `''`. null when there is no live input box to read (a dialog, no box, a+ * draft too tall for the box reader, an empty capture).+ *+ * Exists so the typed chat send can see that ITS text reached the composer. Counting the text across+ * the whole screen fails for a short answer: typing also clears the placeholder and shortens the+ * status line ("· ? for shortcuts · ← for agents" goes away), so the letter `a` typed in answer to a+ * multiple-choice question appeared once more in the box and once less elsewhere. The count never+ * rose, and the Enter was withheld with the text sitting in the box.+ *+ * Without SGR (a capture that lost it), the placeholder reads as draft text. Callers compare against+ * the draft read before typing, so that only costs a match when the placeholder ends the same way.+ */+export function readClaudeDraft(styledScreen: string): string | null {+ const styled = styledScreen.split(/\r?\n/)+ const lines = styled.map((l) => l.replace(ANSI, '').trimEnd())+ if (lines.every((l) => l === '')) return null+ if (readClaudeScreen(styledScreen).kind !== 'prompt') return null+ const box = inputBox(lines)+ if (!box) return null+ let draft = ''+ for (let i = box[0] + 1; i < box[1]; i++) {+ const from = i === box[0] + 1 && lines[i].startsWith('❯') ? 1 : 0+ draft += undimmedText(styled[i], from)+ }+ return draft.replace(/\s/g, '')+}