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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(amp): strip the ESC with the SGR parameters in the approval reader (#1767)
0xdiego25dfce14373d5e
diff --git a/cli/src/engines/amp/askQuestion.spec.ts b/cli/src/engines/amp/askQuestion.spec.tsindex a72d8ec8f..0b626d216 100644--- a/cli/src/engines/amp/askQuestion.spec.ts+++ b/cli/src/engines/amp/askQuestion.spec.ts@@ -74,4 +74,43 @@ describe('amp approval dialog', () => {const view = parseAmpQuestionPane(twice) as QuestionViewexpect(view.question).toBe('Approve shell_command: echo second')})++ /**+ * The same pane as `capture-pane -e` hands it over: SGR attributes kept, which is how every OTHER+ * engine's dialog arrives — 23 of the 33 captures in `lib/__fixtures__` carry them, up to 505 sequences+ * in one. `PANE` itself is trimmed to plain text, so nothing above can see this.+ *+ * Without the ESC in the strip pattern the attributes go and a BARE ESC is left where each colour was,+ * so the anchored row pattern cannot see past it: the highlighted row is dropped from the list and the+ * `tool:` line no longer reads, leaving the generic `Approval required`. A device user is then offered+ * three answers to a four-way approval, none of them the highlighted one.+ */+ const STYLED = PANE+ .replace(/^(\s*)│/gm, '$1\u001b[38;5;244m│')+ .replace(/╭─+╮/g, '\u001b[1m╭─+╮\u001b[0m')+ .replace(/╰[^╯]*╯/g, (line) => `\u001b[38;5;244m${line}\u001b[0m`)+ .replace(/‣ /g, '\u001b[7m‣ \u001b[0m')+ .replace(/█/g, '\u001b[38;5;240m█\u001b[0m')+ .replace(/Allow Once/g, '\u001b[38;2;255;255;255mAllow Once\u001b[39m')++ it('reads every option off a pane that still carries its SGR attributes', () => {+ const view = parseAmpQuestionPane(STYLED) as QuestionView+ expect(view?.kind).toBe('question')+ expect(view.rows.map((r) => r.label)).toEqual([+ 'Allow Once', 'Reject with feedback', 'Allow All for This Session', 'Allow All for Every Session',+ ])+ })++ it('names what is being approved on a styled pane too, not just the generic prompt', () => {+ // The `‣ Allow Once` row is styled separately from its border, which is what dropped it before.+ const view = parseAmpQuestionPane(STYLED) as QuestionView+ expect(view.question).toBe('Approve shell_command: echo probe123')+ })++ it('does not eat bracketed text that is not an escape sequence', () => {+ // A path or a glob in the approved command is content, not styling: `[0m` must survive it.+ const bracketed = PANE.replace('echo probe123', 'cat log[0m].txt')+ const view = parseAmpQuestionPane(bracketed) as QuestionView+ expect(view.question).toBe('Approve shell_command: cat log[0m].txt')+ })})diff --git a/cli/src/engines/amp/askQuestion.ts b/cli/src/engines/amp/askQuestion.tsindex 5c6852b99..1e68fae74 100644--- a/cli/src/engines/amp/askQuestion.ts+++ b/cli/src/engines/amp/askQuestion.ts@@ -47,9 +47,19 @@ const ROW_RE = /^\s*[‣>›]?\s{0,3}([A-Z][\w ]{2,60}?)\s*$//** `"command": "echo hi"` — one complete pair on one line. A wrapped value simply does not match. */const ARG_RE = /"(?:command|path|file_path|name|query|url)"\s*:\s*"([^"]{1,120})"/+/**+ * The pane is read from `capture-pane -e`, which keeps the SGR attributes tmux already rendered, so every+ * styled run arrives as `ESC [ … m`. The ESC must be PART OF THE MATCH, as it is in the six other copies+ * (`kit/pane`, `kit/runtime`, `kit/questionPane`, devin, grok, cursor): without it the parameters are+ * dropped and a BARE ESC is left standing where the colour was, which no `^\s*`-anchored row pattern can+ * see past. Measured against the captured dialogs in `lib/__fixtures__` — 23 of the 23 that carry SGR+ * disagree with that consensus, by up to 505 stray ESC characters each.+ *+ * The same commit that introduced this regex added the same note in `lib/askQuestion.ts` `unframe`, where+ * a missing strip left hermes reading as "no dialog open" with its dialog plainly on screen.+ */function stripAnsi(text: string): string {- // eslint-disable-next-line no-control-regex- return text.replace(/\[[0-9;?]*[A-Za-z]/g, '')+ return text.replace(/\u001b\[[0-9;:]*[A-Za-z]/g, '')}/**