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(windows): submit agent messages in a second write once they render
Fabricio Casali9f09c2f78136
diff --git a/CLAUDE.md b/CLAUDE.mdindex 462d167ef..1f4a281a9 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -98,6 +98,11 @@ Do not route the persistent session-host backend through this direct-PTY adapterversioned `messageOwnerV1` / `messagePasteReadyV1` / `messageEnvelopeV1` extension runs in the host:the OS probe is bound to `HostSession.generation`, the session registry is rechecked after everyawait, and the emulator's paste mode is checked again immediately before the synchronous write.+**The Enter is a SECOND write, sent only once the pane shows the envelope** — every backend+(Server Edition tmux, session host, direct PTY) runs the one `core/settled-submit.ts`. Measured on+the installed build (2026-09-14): with the `\r` in the same write as the paste, Codex rendered the+whole envelope in its composer and never submitted it, so the delivery reported `stalled`; a+separate Enter moments later sent it. A pane that never shows the envelope gets no Enter at all.An older live host refuses these unknown commands while keeping the v1/v2 terminal contract intact;never replace it automatically or fall back to name-only input to enable messaging. Windows OpenCodecontext exports use the npm shim through PowerShell with a validated session identifier, notdiff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 2a13c85a6..c62e87a5d 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -63,6 +63,8 @@ Do not replace that read with a stored `agentId` or the restart heuristic's deepAn interpreter such as `node` is named by its script's package `bin` entry, never as `node`, sonpm-installed CLIs such as Codex are recognized. A session released by park expiry or offscreenrelease is still messageable: existence and routing ask the backend, not the attached client.+Never put the submitting Enter in the same write as a message paste: `core/settled-submit.ts`+pastes, waits for the envelope to render, then submits separately, on every backend.The persistent session-host transport has its own versioned messaging extension: the host checksits session generation, OS process identity and emulator before writing. An older live host keepsits terminals and refuses the extension; never restart it automatically or fall back to sendKeys.diff --git a/docs/windows-session-host.md b/docs/windows-session-host.mdindex 7dc261e6c..3e1da4b96 100644--- a/docs/windows-session-host.md+++ b/docs/windows-session-host.md@@ -501,8 +501,11 @@ The persistent host has a separate, additive messaging extension (`messageOwnerV`messagePasteReadyV1`, `messageEnvelopeV1`). `session-host/message-pane.ts` observes the OS consoleunder the **host's** session generation and reads the host's existing emulator after its outputbarrier. Before sending, it repeats the identity probe, checks paste mode again, and confirms-that the same session object is still registered after every await. The resulting write is one-sanitized multiline bracketed paste plus Enter. Main still owns the project/consent/hook/binary+that the same session object is still registered after every await. It then writes one sanitized+multiline bracketed paste, watches its own emulator until the envelope footer renders, and sends+Enter as a second write, only while the same generation is still registered+(`core/settled-submit.ts`, shared with the Server Edition). With the Enter inside the paste write,+Codex 0.154 left the envelope unsent in its composer and the delivery reported `stalled`. Main still owns the project/consent/hook/binaryand receipt gates. The direct adapter is never used for host-backed sessions.A host-backed session stays addressable after the desktop releases its client (park expiry,diff --git a/src/core/native-windows-pane.test.ts b/src/core/native-windows-pane.test.tsindex eb639710a..3f0077c35 100644--- a/src/core/native-windows-pane.test.ts+++ b/src/core/native-windows-pane.test.ts@@ -4,23 +4,39 @@ import type { PaneOwner } from '../shared/agents/pane-owner-predicate'const expected: PaneOwner = { panePid: 10, paneId: 'win32:generation-a:birth-root', tty: 'win32-console:10', command: 'opencode', argv: ['opencode'], pids: [20], processBirths: ['birth-agent'] }const panes: NativeWindowsPane[] = []-function fixture() {- const write = vi.fn()+/** `render` makes the fake app draw what it is pasted, as a real composer does; off, the pane+ * never shows the envelope. Settle polls do not wait: the test controls the screen directly. */+function fixture(render = true) {+ let pane!: NativeWindowsPane+ const write = vi.fn((data: string) => {+ const paste = /^\x1b\[200~([\s\S]*)\x1b\[201~$/.exec(data)+ if (render && paste) pane.recordOutput(paste[1].replace(/\n/g, '\r\n'))+ })const probe = vi.fn(async (): Promise<PaneOwner | null> => expected)- const pane = new NativeWindowsPane({ pid: 10, write }, { cols: 80, rows: 24, scrollback: 100 }, probe)+ pane = new NativeWindowsPane({ pid: 10, write }, { cols: 80, rows: 24, scrollback: 100 }, probe, {+ wait: async () => {}+ })panes.push(pane)return { pane, write, probe }}afterEach(() => { for (const p of panes.splice(0)) p.dispose() })describe('native Windows envelope delivery', () => {- it('waits for split terminal-mode output and pastes one sanitized block before Enter', async () => {+ it('waits for split terminal-mode output, pastes one sanitized block, then Enter once it renders', async () => {const { pane, write } = fixture()pane.recordOutput('\x1b[?20')pane.recordOutput('04h')expect(await pane.sendEnvelope('line 1\nline 2\x1b[201~', expected)).toBe(true)expect(write.mock.calls).toEqual([['\x1b[200~line 1\nline 2[201~\x1b[201~'], ['\r']])})+ it('reports the paste but sends no Enter while the pane never shows the envelope', async () => {+ // An Enter before the composer installs the block is the swallowed or doubled submit; the+ // receipt watcher reports `stalled` instead.+ const { pane, write } = fixture(false)+ pane.recordOutput('\x1b[?2004h')+ expect(await pane.sendEnvelope('line 1\nEND FOOTER', expected)).toBe(true)+ expect(write.mock.calls).toEqual([['\x1b[200~line 1\nEND FOOTER\x1b[201~']])+ })it('refuses before paste mode is observed, after it is disabled, and without a checked owner', async () => {const { pane, write } = fixture()expect(await pane.sendEnvelope('hello', expected)).toBe(false)diff --git a/src/core/native-windows-pane.ts b/src/core/native-windows-pane.tsindex 97ffe6b27..6f2194570 100644--- a/src/core/native-windows-pane.ts+++ b/src/core/native-windows-pane.ts@@ -3,6 +3,7 @@ import { TerminalEmulator } from '../session-host/terminal-emulator'import { readWindowsConsoleOwner, sameNativeProcess } from '../session-host/windows-pane-owner'import type { PaneOwner } from '../shared/agents/pane-owner-predicate'import { sanitizePasteText } from './paste-injection'+import { pasteThenSubmitWhenSettled, type SettleOptions } from './settled-submit'export { sameNativeProcess } from '../session-host/windows-pane-owner'@@ -18,7 +19,8 @@ export class NativeWindowsPane {constructor(private readonly proc: { pid: number; write(data: string): void },size: { cols: number; rows: number; scrollback: number },- private readonly probe = readWindowsConsoleOwner+ private readonly probe = readWindowsConsoleOwner,+ private readonly settle: SettleOptions = {}) {this.screen = new TerminalEmulator(size)}@@ -53,13 +55,24 @@ export class NativeWindowsPane {// Re-check the exact process immediately before typing. A replacement with the same// PID but a different OS birth time, or a shell returned to the console, refuses.if (!sameNativeProcess(expected, await this.owner()) || !(await this.pasteAware())) return false- try {- const text = sanitizePasteText(envelope)- if (!text) return false- this.proc.write(`\x1b[200~${text}\x1b[201~`)- this.proc.write('\r')- return true- } catch { return false }+ const text = sanitizePasteText(envelope)+ if (!text) return false+ // Paste, let the composer install the block, then submit in a second write+ // (core/settled-submit.ts). Two synchronous writes arrive as one read on the other side.+ return pasteThenSubmitWhenSettled(text, {+ capture: async () => (this.alive ? this.capture(false) : null),+ paste: async () => {+ if (!this.alive || !(await this.pasteAware())) return false+ try {+ this.proc.write(`\x1b[200~${text}\x1b[201~`)+ return true+ } catch { return false }+ },+ submit: async () => {+ if (!this.alive) return+ try { this.proc.write('\r') } catch { /* paste landed; receipt reports stalled */ }+ }+ }, this.settle)}/**diff --git a/src/core/settled-submit.test.ts b/src/core/settled-submit.test.tsnew file mode 100644index 000000000..7b92e812f--- /dev/null+++ b/src/core/settled-submit.test.ts@@ -0,0 +1,64 @@+import { describe, expect, it } from 'vitest'+import { pasteThenSubmitWhenSettled, type SettleSurface } from './settled-submit'++const ENVELOPE = '--- NODETERM MESSAGE abc ---\nbody\n--- END NODETERM MESSAGE abc ---'+const noWait = { wait: async () => {} }++function surface(frames: Array<string | null>, pasteOk = true) {+ const log: string[] = []+ let i = 0+ const s: SettleSurface = {+ capture: async () => frames[Math.min(i++, frames.length - 1)],+ paste: async () => {+ log.push('paste')+ return pasteOk+ },+ submit: async () => {+ log.push('submit')+ }+ }+ return { s, log }+}++describe('pasteThenSubmitWhenSettled', () => {+ it('submits in a second step once the footer is on screen', async () => {+ const { s, log } = surface(['prompt>', 'prompt>', `prompt> ${ENVELOPE}`])+ expect(await pasteThenSubmitWhenSettled(ENVELOPE, s, noWait)).toBe(true)+ expect(log).toEqual(['paste', 'submit'])+ })++ it('still finds the footer through the Braille animation Codex paints over its composer', async () => {+ // Measured 2026-09-14: dots from Codex's idle animation land inside rendered envelope lines.+ const noisy = ' --- END NODE⠈TERM MESS⠁AGE abc --- ⠠⠄'+ const { s, log } = surface(['prompt>', noisy], true)+ expect(await pasteThenSubmitWhenSettled(ENVELOPE, s, { ...noWait, polls: 1 })).toBe(true)+ expect(log).toEqual(['paste', 'submit'])+ })++ it('reports the paste but never submits a pane that did not settle', async () => {+ let n = 0+ const s: SettleSurface = {+ capture: async () => `frame ${n++}`, // always changing, never the footer+ paste: async () => true,+ submit: async () => {+ throw new Error('must not submit')+ }+ }+ expect(await pasteThenSubmitWhenSettled(ENVELOPE, s, noWait)).toBe(true)+ })++ it('submits after two identical changed frames when the footer is not rendered verbatim', async () => {+ const { s, log } = surface(['prompt>', 'changed', 'changed'])+ expect(await pasteThenSubmitWhenSettled(ENVELOPE, s, noWait)).toBe(true)+ expect(log).toEqual(['paste', 'submit'])+ })++ it('answers false and submits nothing when the paste itself failed, or there is no envelope', async () => {+ const failed = surface(['prompt>'], false)+ expect(await pasteThenSubmitWhenSettled(ENVELOPE, failed.s, noWait)).toBe(false)+ expect(failed.log).toEqual(['paste'])+ const empty = surface(['prompt>'])+ expect(await pasteThenSubmitWhenSettled('', empty.s, noWait)).toBe(false)+ expect(empty.log).toEqual([])+ })+})diff --git a/src/core/settled-submit.ts b/src/core/settled-submit.tsnew file mode 100644index 000000000..062f9a0d6--- /dev/null+++ b/src/core/settled-submit.ts@@ -0,0 +1,98 @@+/**+ * Paste an agent-message envelope, then submit it in a SECOND write once the pane has visibly+ * settled. One algorithm for every backend that delivers one: the Server Edition's tmux path, the+ * Windows session host and the direct Windows PTY.+ *+ * Why the Enter cannot ride the paste. A composer can accept a bracketed paste asynchronously: the+ * close marker has been written, but an Enter queued right behind it is consumed before the TUI has+ * installed the pasted block, so the next key submits both messages together (measured on a fresh+ * Claude pane, Server Edition). On Windows the same shape leaves the message unsubmitted: Codex+ * 0.154 under the session host rendered the whole envelope in its composer and treated the trailing+ * `\r` of the same write as part of the paste, so the delivery reported `stalled` with the text+ * sitting unsent; a bare Enter sent moments later submitted it and the agent answered (measured+ * 2026-09-14). Both are the same fix: paste, observe the envelope footer (or a stable change), then+ * submit separately.+ *+ * The boolean means "the envelope reached the pane", not "Enter was observed". Once the paste+ * succeeds, a capture or submit failure still returns true so the receipt watcher can report+ * `stalled`; false would misreport a partially delivered message as `targetGone`.+ */++export const ENVELOPE_SETTLE_POLL_MS = 40+export const ENVELOPE_SETTLE_POLLS = 15++export interface SettleSurface {+ /** The pane's visible text now, or null when it cannot be read. Never throws. */+ capture(): Promise<string | null>+ /** Write the envelope WITHOUT submitting. False means nothing reached the pane. Never throws. */+ paste(): Promise<boolean>+ /** Submit, in its own write. Called only after the pane settled. Never throws. */+ submit(): Promise<void>+}++export interface SettleOptions {+ wait?: (ms: number) => Promise<void>+ polls?: number+}++function delay(ms: number): Promise<void> {+ return new Promise((resolve) => setTimeout(resolve, ms))+}++function visibleSnapshot(value: string): string {+ return value.replace(/\r/g, '').replace(/[ \t]+$/gm, '').trimEnd()+}++/**+ * Whitespace goes, and so do Braille pattern cells (U+2800–U+28FF): Codex paints an idle+ * animation of Braille dots over the composer area, and a dot landing between two characters of+ * the footer would otherwise hide it (observed on the same 2026-09-14 pane). The footer itself is+ * ASCII, so dropping those cells cannot create a match that is not there.+ */+function compact(value: string): string {+ return value.replace(/[\s⠀-⣿]+/g, '')+}++export async function pasteThenSubmitWhenSettled(+ envelope: string,+ surface: SettleSurface,+ options: SettleOptions = {}+): Promise<boolean> {+ if (!envelope) return false+ const snapshot = async (): Promise<string | null> => {+ const text = await surface.capture()+ return text === null ? null : visibleSnapshot(text)+ }+ const before = await snapshot()+ if (!(await surface.paste())) return false++ const footer = compact(envelope.split('\n').at(-1) ?? '')+ const wait = options.wait ?? delay+ const polls = Math.max(1, options.polls ?? ENVELOPE_SETTLE_POLLS)+ let priorChanged: string | null = null+ let settled = false++ for (let i = 0; i < polls; i++) {+ if (i > 0) await wait(ENVELOPE_SETTLE_POLL_MS)+ const current = await snapshot()+ if (current === null) continue+ if (footer && compact(current).includes(footer)) {+ settled = true+ break+ }+ if (current && current !== before) {+ if (current === priorChanged) {+ settled = true+ break+ }+ priorChanged = current+ } else {+ priorChanged = null+ }+ }++ // Unsettled: no Enter. A premature one is exactly the double-submit this exists to prevent; the+ // receipt watcher reports the non-retryable `stalled` instead.+ if (settled) await surface.submit()+ return true+}diff --git a/src/server/settled-envelope.ts b/src/server/settled-envelope.tsindex 69a3dd2c3..42074e2c4 100644--- a/src/server/settled-envelope.ts+++ b/src/server/settled-envelope.ts@@ -1,49 +1,18 @@/**- * Server-only agent-message delivery sequencing.- *- * A fresh Claude composer can accept a bracketed paste asynchronously: tmux has written the close- * marker, but an Enter queued in the same command list is consumed before the TUI has installed the- * pasted block. The next key then submits both messages together. Paste first, observe the pane- * render the unique envelope footer (or become stably different from its baseline), then submit in- * a second write.- *- * The boolean deliberately means "the envelope reached the pane", not "Enter was observed". Once- * the paste succeeds, a capture or submit failure returns true so the unchanged receipt watcher can- * report `stalled`; returning false would misreport a partially delivered message as `targetGone`.+ * Server-only adapter: the tmux-backed pane is reached through PtyManager's capture + sendText.+ * The sequencing itself (paste, observe the envelope settle, submit in a second write) lives in+ * `core/settled-submit.ts`, shared with the Windows session host and the direct Windows PTY.*/+import { pasteThenSubmitWhenSettled, type SettleOptions } from '../core/settled-submit'-export const ENVELOPE_SETTLE_POLL_MS = 40-export const ENVELOPE_SETTLE_POLLS = 15+export { ENVELOPE_SETTLE_POLL_MS, ENVELOPE_SETTLE_POLLS } from '../core/settled-submit'export interface SettledEnvelopePty {captureSession(nodeId: string): Promise<string>sendText(nodeId: string, text: string, opts?: { enter?: boolean }): Promise<boolean>}-export interface SettledEnvelopeOptions {- wait?: (ms: number) => Promise<void>- polls?: number-}--function delay(ms: number): Promise<void> {- return new Promise((resolve) => setTimeout(resolve, ms))-}--function visibleSnapshot(value: string): string {- return value.replace(/\r/g, '').replace(/[ \t]+$/gm, '').trimEnd()-}--function compact(value: string): string {- return value.replace(/\s+/g, '')-}--async function capture(pty: SettledEnvelopePty, nodeId: string): Promise<string | null> {- try {- return visibleSnapshot(await pty.captureSession(nodeId))- } catch {- return null- }-}+export type SettledEnvelopeOptions = SettleOptions/** Paste one complete envelope and submit only after the target pane has visibly settled. */export async function sendSettledEnvelope(@@ -52,48 +21,33 @@ export async function sendSettledEnvelope(envelope: string,options: SettledEnvelopeOptions = {}): Promise<boolean> {- if (!envelope) return false- const before = await capture(pty, nodeId)- let pasted = false- try {- pasted = await pty.sendText(nodeId, envelope, { enter: false })- } catch {- return false- }- if (!pasted) return false-- const footer = compact(envelope.split('\n').at(-1) ?? '')- const wait = options.wait ?? delay- const polls = Math.max(1, options.polls ?? ENVELOPE_SETTLE_POLLS)- let priorChanged: string | null = null- let settled = false-- for (let i = 0; i < polls; i++) {- if (i > 0) await wait(ENVELOPE_SETTLE_POLL_MS)- const current = await capture(pty, nodeId)- if (current === null) continue- if (footer && compact(current).includes(footer)) {- settled = true- break- }- if (current && current !== before) {- if (current === priorChanged) {- settled = true- break+ return pasteThenSubmitWhenSettled(+ envelope,+ {+ capture: async () => {+ try {+ return await pty.captureSession(nodeId)+ } catch {+ return null+ }+ },+ paste: async () => {+ try {+ return await pty.sendText(nodeId, envelope, { enter: false })+ } catch {+ return false+ }+ },+ submit: async () => {+ try {+ // False is still a successful paste: no receipt follows, and the shared messaging path+ // reports the non-retryable `stalled` after its deadline.+ await pty.sendText(nodeId, '', { enter: true })+ } catch {+ // Same partial-delivery contract as a false return.+ }}- priorChanged = current- } else {- priorChanged = null- }- }-- if (!settled) return true- try {- // False here is intentionally still a successful paste. No receipt follows, so shared- // agent-messaging reports the existing non-retryable `stalled` outcome after its deadline.- await pty.sendText(nodeId, '', { enter: true })- } catch {- // Same partial-delivery contract as a false return from the bare Enter.- }- return true+ },+ options+ )}diff --git a/src/session-host/message-pane.test.ts b/src/session-host/message-pane.test.tsindex 8595557a7..cfebde3b4 100644--- a/src/session-host/message-pane.test.ts+++ b/src/session-host/message-pane.test.ts@@ -3,10 +3,19 @@ import { hostMessagePane, type MessagePaneSession } from './message-pane'import { windowsConsoleOwner } from './windows-pane-owner'function fixture() {+ // The fake app draws what it is pasted, so the settle step can see the envelope land.+ let screen = 'prompt>'const session: MessagePaneSession = {generation: 'generation-a', exited: false,- proc: { pid: 10, write: vi.fn() },- messagePasteReady: vi.fn(async () => true)+ proc: {+ pid: 10,+ write: vi.fn((data: string) => {+ const paste = /^\x1b\[200~([\s\S]*)\x1b\[201~$/.exec(data)+ if (paste) screen += '\n' + paste[1]+ })+ },+ messagePasteReady: vi.fn(async () => true),+ serialize: vi.fn(async () => screen)}const snapshot = {console: [10, 11],@@ -17,7 +26,7 @@ function fixture() {}let live: MessagePaneSession | undefined = sessionconst probe = vi.fn(async (pid: number, generation: string) => windowsConsoleOwner(pid, generation, snapshot))- return { session, snapshot, probe, pane: hostMessagePane(() => live, probe), replace: () => {+ return { session, snapshot, probe, pane: hostMessagePane(() => live, probe, { wait: async () => {} }), replace: () => {live = { ...session, generation: 'generation-b' }} }}@@ -29,7 +38,11 @@ describe('session-host messaging extension', () => {expect(owner?.paneId).toContain('generation-a')expect(await pane.send('line one\nline two\x1b[201~', owner!)).toBe(true)expect(probe).toHaveBeenCalledTimes(2)- expect(session.proc.write).toHaveBeenCalledExactlyOnceWith('\x1b[200~line one\nline two[201~\x1b[201~\r')+ // Two writes, in order: the paste, then Enter only once the envelope is on screen.+ expect(vi.mocked(session.proc.write).mock.calls).toEqual([+ ['\x1b[200~line one\nline two[201~\x1b[201~'],+ ['\r']+ ])})it('refuses an expected owner from an older same-name generation', async () => {@@ -81,6 +94,19 @@ describe('session-host messaging extension', () => {expect(f.session.proc.write).not.toHaveBeenCalled()})+ it('sends no Enter when the generation is replaced between the paste and the submit', async () => {+ // A bare Enter into whatever took the session's place would submit a stranger's input.+ const f = fixture()+ const owner = await f.pane.owner()+ const render = vi.mocked(f.session.serialize).getMockImplementation()!+ vi.mocked(f.session.serialize).mockImplementationOnce(render).mockImplementation(async () => {+ f.replace()+ return render()+ })+ expect(await f.pane.send('message', owner!)).toBe(true)+ expect(vi.mocked(f.session.proc.write).mock.calls).toEqual([['[200~message[201~']])+ })+it('never submits an empty envelope or an unobserved identity', async () => {const f = fixture()expect(await f.pane.send('', (await f.pane.owner())!)).toBe(false)diff --git a/src/session-host/message-pane.ts b/src/session-host/message-pane.tsindex 89a03b7f9..b0ddacb95 100644--- a/src/session-host/message-pane.ts+++ b/src/session-host/message-pane.ts@@ -1,5 +1,6 @@import type { PaneOwner } from '../shared/agents/pane-owner-predicate'import { sanitizePasteText } from '../core/paste-injection'+import { pasteThenSubmitWhenSettled, type SettleOptions } from '../core/settled-submit'import { readWindowsConsoleOwner, sameNativeProcess } from './windows-pane-owner'export interface MessagePaneSession {@@ -7,14 +8,20 @@ export interface MessagePaneSession {exited: booleanproc: { pid: number; write(data: string): void }messagePasteReady(): Promise<boolean>+ /** The host emulator's screen (`HostSession.serialize`), read to see the envelope land. */+ serialize(scrollback?: number): Promise<string>}+/** Recent lines are enough to find the envelope footer; the whole scrollback is not needed. */+const SETTLE_CAPTURE_LINES = 200+/** The persistent host owns both the emulator and the generation. Never route this through the* main process's direct-PTY adapter: that object cannot observe a replacement inside this host.* Project grants, verified hooks, agent binary checks and receipts still belong to core. */export function hostMessagePane(lookup: () => MessagePaneSession | undefined,- probe = readWindowsConsoleOwner+ probe = readWindowsConsoleOwner,+ settle: SettleOptions = {}) {const current = (s: MessagePaneSession): boolean => !s.exited && lookup() === sreturn {@@ -35,13 +42,31 @@ export function hostMessagePane(if (!text || !(await s.messagePasteReady()) || !current(s)) return falseconst owner = await probe(s.proc.pid, s.generation)if (!current(s) || !sameNativeProcess(expected, owner)) return false- // Cross the emulator barrier again after the OS probe: paste mode may have changed while- // it was running. Check the registry again after EVERY await, then write synchronously.- if (!(await s.messagePasteReady()) || !current(s)) return false- try {- s.proc.write(`\x1b[200~${text}\x1b[201~\r`)- return true- } catch { return false }+ // Paste, let the composer install the block, then submit in a second write+ // (core/settled-submit.ts): an Enter in the same write was swallowed by the paste.+ return pasteThenSubmitWhenSettled(text, {+ capture: async () => {+ if (!current(s)) return null+ try {+ const screen = await s.serialize(SETTLE_CAPTURE_LINES)+ return current(s) ? screen : null+ } catch { return null }+ },+ paste: async () => {+ // Cross the emulator barrier again after the OS probe and the baseline capture: paste+ // mode may have changed meanwhile. No await between this check and the write.+ if (!(await s.messagePasteReady()) || !current(s)) return false+ try {+ s.proc.write(`\x1b[200~${text}\x1b[201~`)+ return true+ } catch { return false }+ },+ submit: async () => {+ // A replaced or exited generation gets nothing: a bare Enter into a stranger's pane.+ if (!current(s)) return+ try { s.proc.write('\r') } catch { /* the paste already landed; receipt reports stalled */ }+ }+ }, settle)}}}