Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Fail closed on line-key bytes inside pastes and split lone Esc

reinSPQR424b709fa598
diff --git a/cli/src/teams/promptScope.spec.ts b/cli/src/teams/promptScope.spec.ts
index 9cbbc0910..9a00f0806 100644
--- a/cli/src/teams/promptScope.spec.ts
+++ b/cli/src/teams/promptScope.spec.ts
@@ -39,7 +39,7 @@ describe('prompt swarm origin', () => {
scopes.raw(agent, bytes('a\x1b[13;2ub\r'), 'swarm-a')
scopes.started(agent, 'a\nb', 'hook', 'claude')
expect(scopes.current(agent)).toBe(a)
- // The reported pattern: a paste, two ⇧⏎, then text, each key its own write.
+ // A paste, two ⇧⏎, then text, each key arriving as its own write.
for (const chunk of ['\x1b[200~pasted code\x1b[201~', '\x1b[13;2u', '\x1b', '[13;2u', 'explain it', '\r']) scopes.raw(agent, bytes(chunk), 'swarm-b')
scopes.started(agent, 'pasted code\n\nexplain it', 'hook', 'claude')
expect(scopes.current(agent)).toBe(b)
@@ -60,6 +60,16 @@ describe('prompt swarm origin', () => {
scopes.raw(agent, bytes('word\x1b[1;5D\r'), 'swarm-a')
scopes.started(agent, 'word', 'hook', 'claude')
expect(scopes.current(agent)).toBeNull()
+ // Pasted escapes reach the engine literally; they are not line keys.
+ scopes.raw(agent, bytes('\x1b[200~x\x1b[13;2uy\x1b\rz\x1b[201~\r'), 'swarm-a')
+ scopes.started(agent, 'x\ny\nz', 'hook', 'claude')
+ expect(scopes.current(agent)).toBeNull()
+ // A lone Esc followed later by Return is not ⌥⏎: the draft must not become 'hello\n…'.
+ scopes.raw(agent, bytes('hello\x1b'), 'swarm-a')
+ scopes.raw(agent, bytes('\r'), 'swarm-a')
+ scopes.raw(agent, bytes('next\r'), 'swarm-a')
+ scopes.started(agent, 'hello\nnext', 'hook', 'claude')
+ expect(scopes.current(agent)).toBeNull()
})
it('matches native accepted text instead of treating permission keys as prompts', () => {
diff --git a/cli/src/teams/promptScope.ts b/cli/src/teams/promptScope.ts
index db18d710f..44e1fa1b4 100644
--- a/cli/src/teams/promptScope.ts
+++ b/cli/src/teams/promptScope.ts
@@ -114,8 +114,9 @@ export class SwarmPromptScopes {
if (bytes.length > MAX_TEXT) { state.known = false; state.draft = []; return }
insert(Buffer.from(bytes).toString('utf8')); return
}
- // ⌥⏎ under LNM is \x1b\r\n; its \n belongs to the same keystroke, so only this write can hold it.
- let metaReturn = false
+ // The app writes each line key as one string, so ⌥⏎ (and its \n under LNM) is only
+ // recognised within this call; a lone Esc followed later by Return fails closed.
+ let escaped = false, metaReturn = false
for (const char of state.decoder.write(Buffer.from(bytes))) {
if (metaReturn) { metaReturn = false; if (char === '\n') continue }
if (state.escape) {
@@ -123,8 +124,9 @@ export class SwarmPromptScopes {
if (state.escape === '\x1b[200~') { state.paste = true; state.escape = ''; continue }
if (state.escape === '\x1b[201~') { state.paste = false; state.escape = ''; continue }
// The app sends ⇧⏎ as CSI-u and ⌥⏎ as Meta+Return; engines read both as a line break.
- if (state.escape === '\x1b[13;2u') { state.escape = ''; insert('\n'); continue }
- if (state.escape === '\x1b\r') { state.escape = ''; insert('\n'); metaReturn = true; continue }
+ // Inside a paste the engine receives those bytes literally, so they fail closed there.
+ if (state.escape === '\x1b[13;2u' && !state.paste) { state.escape = ''; insert('\n'); continue }
+ if (state.escape === '\x1b\r' && escaped && !state.paste) { state.escape = ''; insert('\n'); metaReturn = true; continue }
if (['\x1b', '\x1b[', '\x1b[1', '\x1b[13', '\x1b[13;', '\x1b[13;2', '\x1b[2', '\x1b[20', '\x1b[200', '\x1b[201', '\x1b[3', '\x1bO'].includes(state.escape)) continue
const sequence = state.escape
state.escape = ''
@@ -133,12 +135,11 @@ export class SwarmPromptScopes {
else if (sequence === '\x1b[H' || sequence === '\x1bOH') state.cursor = 0
else if (sequence === '\x1b[F' || sequence === '\x1bOF') state.cursor = state.draft.length
else if (sequence === '\x1b[3~') state.draft.splice(state.cursor, 1)
- // Everything else fails closed, ⌥⌫ (\x1b\x7f) included: Claude and Codex may not agree
- // on word boundaries, and a guessed kill could match a different prompt.
+ // ⌥⌫ (\x1b\x7f) fails closed too: engines may disagree on word boundaries.
else { state.known = false; state.draft = [] }
continue
}
- if (char === '\x1b') { state.escape = char; continue }
+ if (char === '\x1b') { state.escape = char; escaped = true; continue }
if (state.paste) { insert(char); continue }
if (char === '\r') {
if (state.known && state.draft.length) this.prepare(agentId, state.draft.join(''), tabId)