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.

Keep swarm prompt origin across ⇧⏎ and ⌥⏎ line breaks

reinSPQR3b008732666f
diff --git a/cli/src/teams/promptScope.spec.ts b/cli/src/teams/promptScope.spec.ts
index d8ddc274a..9cbbc0910 100644
--- a/cli/src/teams/promptScope.spec.ts
+++ b/cli/src/teams/promptScope.spec.ts
@@ -34,6 +34,34 @@ describe('prompt swarm origin', () => {
expect(scopes.current(agent)).toBe(b)
})
+ it('keeps the origin of prompts broken with the app’s ⇧⏎ and ⌥⏎ line keys', () => {
+ const scopes = new SwarmPromptScopes()
+ 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.
+ 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)
+ scopes.raw(agent, bytes('c\x1b\rd\r'), 'swarm-a')
+ scopes.started(agent, 'c\nd', 'hook', 'codex')
+ expect(scopes.current(agent)).toBe(a)
+ // Under LNM the app sends Return as \r\n, so ⌥⏎ arrives as \x1b\r\n: still one line break.
+ scopes.raw(agent, bytes('e\x1b\r\nf\r\n'), 'swarm-b')
+ scopes.started(agent, 'e\nf', 'hook', 'codex')
+ expect(scopes.current(agent)).toBe(b)
+ })
+
+ it('still fails closed on ⌥⌫ and on other CSI keys that share the ⇧⏎ prefix', () => {
+ const scopes = new SwarmPromptScopes()
+ scopes.raw(agent, bytes('one two\x1b\x7f\r'), 'swarm-a')
+ scopes.started(agent, 'one ', 'hook', 'claude')
+ expect(scopes.current(agent)).toBeNull()
+ scopes.raw(agent, bytes('word\x1b[1;5D\r'), 'swarm-a')
+ scopes.started(agent, 'word', 'hook', 'claude')
+ expect(scopes.current(agent)).toBeNull()
+ })
+
it('matches native accepted text instead of treating permission keys as prompts', () => {
const scopes = new SwarmPromptScopes()
scopes.raw(agent, bytes('1\r'), 'swarm-b')
diff --git a/cli/src/teams/promptScope.ts b/cli/src/teams/promptScope.ts
index 5fe3267fb..db18d710f 100644
--- a/cli/src/teams/promptScope.ts
+++ b/cli/src/teams/promptScope.ts
@@ -114,12 +114,18 @@ 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
for (const char of state.decoder.write(Buffer.from(bytes))) {
+ if (metaReturn) { metaReturn = false; if (char === '\n') continue }
if (state.escape) {
state.escape += char
if (state.escape === '\x1b[200~') { state.paste = true; state.escape = ''; continue }
if (state.escape === '\x1b[201~') { state.paste = false; state.escape = ''; continue }
- if (['\x1b', '\x1b[', '\x1b[2', '\x1b[20', '\x1b[200', '\x1b[201', '\x1b[3', '\x1bO'].includes(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 }
+ 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 = ''
if (sequence === '\x1b[D') state.cursor = Math.max(0, state.cursor - 1)
@@ -127,6 +133,8 @@ 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.
else { state.known = false; state.draft = [] }
continue
}