an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions
HTML agent-harnessagent-orchestrationagentsai-agentsautonomous-agentsclaude-codecodexcoding-agentsdesktop-appdeveloper-toolselectrongemini-cliharnessharness-engineeringlocal-firstmemorymulti-agentopencodeorchestrationtypescript
fix(floor): stop ANSI cursor sequences garbling the thought bubbles (#141)
Gastón Péchieua3b75f62c423
diff --git a/package.json b/package.jsonindex 8dc851de..a86c72ec 100644--- a/package.json+++ b/package.json@@ -19,7 +19,7 @@"typecheck:node": "tsc --noEmit -p tsconfig.node.json","typecheck:web": "tsc --noEmit -p tsconfig.web.json","typecheck": "npm run typecheck:node && npm run typecheck:web",- "test:focused": "node --test test/codex-remote.test.cjs test/control.test.cjs test/provider-automation.test.cjs test/provider-config.test.cjs test/queue-delivery.test.cjs test/terminal-automation.test.cjs test/terminal-recovery.test.cjs test/roster.test.cjs test/proc-kill.test.cjs test/expand-tilde.test.cjs test/hive-cwd.test.cjs test/hive-hook-node.test.cjs test/hive-roster-injection.test.cjs test/hive-runtime-path.test.cjs test/cli-install-ladder.test.cjs test/node-install.test.cjs test/office-gl-recovery.test.cjs test/update-state.test.cjs test/transcript-project-dir.test.cjs test/commit-graph.test.cjs",+ "test:focused": "node --test test/codex-remote.test.cjs test/control.test.cjs test/provider-automation.test.cjs test/provider-config.test.cjs test/queue-delivery.test.cjs test/terminal-automation.test.cjs test/terminal-recovery.test.cjs test/roster.test.cjs test/proc-kill.test.cjs test/expand-tilde.test.cjs test/hive-cwd.test.cjs test/hive-hook-node.test.cjs test/hive-roster-injection.test.cjs test/hive-runtime-path.test.cjs test/cli-install-ladder.test.cjs test/node-install.test.cjs test/office-gl-recovery.test.cjs test/update-state.test.cjs test/transcript-project-dir.test.cjs test/commit-graph.test.cjs test/ansi-text.test.cjs","check:links": "node tools/check-release-links.cjs","dist": "npm run build && electron-builder","dist:mac": "npm run build && electron-builder --mac",diff --git a/src/renderer/src/components/ansiText.ts b/src/renderer/src/components/ansiText.tsnew file mode 100644index 00000000..88e9d93c--- /dev/null+++ b/src/renderer/src/components/ansiText.ts@@ -0,0 +1,29 @@+/**+ * Strip ANSI escape sequences from scraped terminal output.+ *+ * The pty parser used to remove ONLY SGR color codes (`ESC[…m`), so every other+ * escape flavor leaked into the text the thought bubbles and desk cards show+ * (issue #141): the CLI repaints its live status line with cursor-forward moves+ * (`ESC[1C`) standing in for runs of spaces it knows are already on screen,+ * plus cursor addressing (`ESC[14;6H`) and erases — scraped, that rendered as+ * "all␛[1Cthree␛[1Cland…".+ *+ * Cursor-forward is TRANSLATED into the spaces it stands for (dropping it would+ * fuse adjacent words); everything else is control, not content, and is+ * removed: OSC strings (window title, hyperlinks), any remaining CSI (SGR,+ * cursor, erase, modes), charset selects, and whatever two-byte escape is left.+ */+const CUF_RE = /\x1b\[(\d*)C/g; // cursor-forward: the TUI's stand-in for spaces+const OSC_RE = /\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)?/g; // OSC … BEL/ST (titles, links)+const CSI_RE = /\x1b\[[0-9;:?]*[ -/]*[@-~]/g; // any CSI: SGR, cursor, erase, modes+const CHARSET_RE = /\x1b[()][0-9A-B]/g; // charset selects (ESC ( B …)+const ESC2_RE = /\x1b./g; // stray two-byte escapes (ESC 7, ESC = …)++export function stripAnsi(chunk: string): string {+ return chunk+ .replace(CUF_RE, (_, n: string) => ' '.repeat(Math.min(parseInt(n || '1', 10) || 1, 80)))+ .replace(OSC_RE, '')+ .replace(CSI_RE, '')+ .replace(CHARSET_RE, '')+ .replace(ESC2_RE, '');+}diff --git a/src/renderer/src/hooks/usePtyParser.ts b/src/renderer/src/hooks/usePtyParser.tsindex 9c2dd45e..257c72e8 100644--- a/src/renderer/src/hooks/usePtyParser.ts+++ b/src/renderer/src/hooks/usePtyParser.ts@@ -1,8 +1,6 @@import { useCallback, useEffect, useRef } from 'react';import { useStore, type ToolKind, type StationKind } from '@/store/store';--// ANSI escape sequence stripper — Claude colors its tool tags with these.-const ANSI_RE = /\x1b\[[0-9;]*m/g;+import { stripAnsi } from '@/components/ansiText';// Tool call lines look like: `● Read SPEC.md`, `● Bash npm test`, `● Edit src/foo.ts`const TOOL_RE = /●\s+([A-Za-z][A-Za-z_]*)(?:\s+(.+))?/g;@@ -86,7 +84,7 @@ export function usePtyParser(agentId: string) {}, []);return useCallback((chunk: string) => {- const text = chunk.replace(ANSI_RE, '');+ const text = stripAnsi(chunk);if (!text.trim()) return;// Passive context-limit sniffing from /context output (the gauge poll@@ -118,7 +116,10 @@ export function usePtyParser(agentId: string) {if (lastTool) {const station = TOOL_TO_STATION[lastTool] ?? 'desk';const carrying = TOOLKIND_BY_NAME[lastTool] ?? undefined;- const summary = lastArg ? `${lastTool.toLowerCase()} ${lastArg}` : lastTool.toLowerCase();+ // Collapse space runs: translated cursor-forwards (see stripAnsi) can+ // stand for several columns, and the bubble shouldn't show the gaps.+ const summary = (lastArg ? `${lastTool.toLowerCase()} ${lastArg}` : lastTool.toLowerCase())+ .replace(/\s+/g, ' ');// NOTE: `progress` deliberately untouched — it's the context gauge now// (filled by the useHive context poll), not a per-task meter.updateAgent(agentId, {diff --git a/test/ansi-text.test.cjs b/test/ansi-text.test.cjsnew file mode 100644index 00000000..617b101d--- /dev/null+++ b/test/ansi-text.test.cjs@@ -0,0 +1,57 @@+'use strict';++/**+ * #141 — "garbled text" in the thought bubbles. The pty scrape stripped ONLY+ * SGR color codes, so the CLI's cursor-movement repaints leaked into bubble+ * text as "all␛[1Cthree␛[1Cland…". Cursor-forward must become the spaces it+ * stands for; every other escape flavor is control, not content.+ */++const test = require('node:test');+const assert = require('node:assert/strict');+const loadTs = require('./load-ts.cjs');++const { stripAnsi } = loadTs('src/renderer/src/components/ansiText.ts');++test('translates cursor-forward into spaces (the issue #141 capture)', () => {+ // Reconstructed from the screenshot attached to the issue: the CLI repaints+ // its interim-message line using ESC[1C to skip over columns.+ const raw =+ 'all three land\x1b[1Cd.\x1b[1CSynth\x1b[1Csizing now,\x1b[1Cthen\x1b[1Cwriting' ++ '\x1b[1Cthe\x1b[1CSlack-ready\x1b[1Cresult\x1b[1Cand\x1b[1Creplying\x1b[1Cto' ++ '\x1b[1Cthe\x1b[1Chuman.\x1b[14;6H';+ assert.equal(+ stripAnsi(raw),+ 'all three land d. Synth sizing now, then writing the Slack-ready result and replying to the human.'+ );+});++test('a multi-column forward becomes that many spaces (never fuses words)', () => {+ assert.equal(stripAnsi('col\x1b[3Cnext'), 'col next');+ assert.equal(stripAnsi('a\x1b[Cb'), 'a b', 'a bare ESC[C means forward one');+});++test('SGR color codes are still stripped', () => {+ assert.equal(stripAnsi('\x1b[36m● Read\x1b[0m foo.ts'), '● Read foo.ts');+ assert.equal(stripAnsi('\x1b[1;38;5;208mbold orange\x1b[m'), 'bold orange');+});++test('cursor addressing, erases, and private modes are control, not content', () => {+ assert.equal(stripAnsi('\x1b[2J\x1b[?25lhi\x1b[K\x1b[10;4H there\x1b[?25h'), 'hi there');+ assert.equal(stripAnsi('up\x1b[2A\x1b[5Ddown'), 'updown');+});++test('OSC strings (window title, hyperlinks) vanish entirely', () => {+ assert.equal(stripAnsi('\x1b]0;my title\x07text'), 'text');+ assert.equal(stripAnsi('\x1b]8;;https://x.dev\x1b\\link\x1b]8;;\x1b\\'), 'link');+});++test('stray two-byte escapes and charset selects go too', () => {+ assert.equal(stripAnsi('\x1b7saved\x1b8'), 'saved');+ assert.equal(stripAnsi('\x1b(Bascii'), 'ascii');+});++test('plain text — unicode included — passes through untouched', () => {+ const s = '● Bash npm test — 131/131 ✔ (déjà vu)';+ assert.equal(stripAnsi(s), s);+});