{"version":74,"agent":"pinch","message":"Server text can't drive the terminal: everything the client prints goes through one filter. Tabs, newlines and colors (SGR) pass, colors only to a terminal with NO_COLOR unset. Every other control character, and so every other escape sequence (OSC clipboard writes and links, cursor moves, DCS), prints as visible text such as \\x1b, so nothing vanishes silently. It covers news, version messages, CI logs, file paths and agent names, from any server.","time":1791610945827,"timeIso":"2026-10-10T05:42:25.827Z","changes":4,"change":889,"files":["client/avcs.ts","client/src/main.ts","client/src/terminal-text.ts","client/test/terminal-text.test.ts"],"draft":null,"diff":[{"path":"client/avcs.ts","added":7,"removed":8,"diff":"--- a/client/avcs.ts\n+++ b/client/avcs.ts\n@@ -26,13 +26,12 @@\n \tawait serveMcp(process.stdin, (line) => process.stdout.write(`${line}\\n`), process.cwd(), process.env);\n } else {\n \tconst { main } = await import(\"./src/main.ts\");\n-\tconst result = await main(argv, {\n-\t\tcwd: process.cwd(),\n-\t\tenv: process.env,\n-\t\twrite: (text) => process.stdout.write(text),\n-\t\twriteErr: (text) => process.stderr.write(text),\n-\t});\n-\tif (result.stdout) process.stdout.write(result.stdout);\n-\tif (result.stderr) process.stderr.write(result.stderr);\n+\t// Everything printed goes through terminalText: most of it is a server's text (abso-core's terminal-text.ts).\n+\tconst { colorsPass, terminalText } = await import(\"./src/terminal-text.ts\");\n+\tconst out = (text: string) => process.stdout.write(terminalText(text, colorsPass(process.stdout, process.env)));\n+\tconst err = (text: string) => process.stderr.write(terminalText(text, colorsPass(process.stderr, process.env)));\n+\tconst result = await main(argv, { cwd: process.cwd(), env: process.env, write: out, writeErr: err });\n+\tif (result.stdout) out(result.stdout);\n+\tif (result.stderr) err(result.stderr);\n \tprocess.exitCode = result.exit;\n }"},{"path":"client/src/main.ts","added":5,"removed":1,"diff":"--- a/client/src/main.ts\n+++ b/client/src/main.ts\n@@ -48,6 +48,7 @@\n import { runUnqueue } from \"./queue.ts\";\n import { runNote, runNotes, runReview } from \"./review.ts\";\n import { installSkill, SKILL, skillPath } from \"./skill.ts\";\n+import { colorsPass, terminalText } from \"./terminal-text.ts\";\n import { runAmend, runDrop, runFollow, runLabel, runLabels, runPluck } from \"./versions.ts\";\n import { runVisibility } from \"./visibility-commands.ts\";\n \n@@ -180,7 +181,10 @@\n \t\t\t\tbool(args, \"no-browser\") || browserSkip(env.env, process.platform) !== null\n \t\t\t\t\t? undefined\n \t\t\t\t\t: (url: string) => openInBrowser(url);\n-\t\t\tconst record = await login(server, { say: (line) => process.stderr.write(`${line}\\n`), open });\n+\t\t\tconst record = await login(server, {\n+\t\t\t\tsay: (line) => process.stderr.write(terminalText(`${line}\\n`, colorsPass(process.stderr, env.env))),\n+\t\t\t\topen,\n+\t\t\t});\n \t\t\treturn {\n \t\t\t\ttext: `This box is signed in. ${boxText(record, server).split(\"\\n\").slice(1).join(\" \")}`,\n \t\t\t\tjson: { box: boxPublic(record) },"},{"path":"client/src/terminal-text.ts","added":47,"removed":0,"diff":"--- /dev/null\n+++ b/client/src/terminal-text.ts\n@@ -0,0 +1,47 @@\n+// What the client prints is mostly text a server sent: version messages, news,\n+// CI logs, file paths, agent names. So nothing in it gets to drive the terminal.\n+// Tabs, newlines and colors (SGR, ESC[...m) pass. Colors pass only to a terminal\n+// with NO_COLOR unset, and are dropped otherwise. Every other control character,\n+// and with it every other escape sequence, is shown as text (\\x1b, \\x07, \\u009b),\n+// so nothing vanishes silently.\n+\n+/** Whether colors pass: a terminal, and NO_COLOR unset or empty (no-color.org). */\n+export function colorsPass(stream: { isTTY?: boolean }, env: Readonly<Record<string, string | undefined>>): boolean {\n+\treturn stream.isTTY === true && !env.NO_COLOR;\n+}\n+\n+/** The length of the SGR sequence (ESC [ digits ; : m) starting at i, or 0 when there isn't one. */\n+function sgrAt(text: string, i: number): number {\n+\tif (text.charCodeAt(i) !== 0x1b || text[i + 1] !== \"[\") return 0;\n+\tfor (let j = i + 2; j < text.length && j < i + 64; j++) {\n+\t\tconst c = text[j]!;\n+\t\tif (c === \"m\") return j - i + 1;\n+\t\tif (!/[0-9;:]/.test(c)) return 0;\n+\t}\n+\treturn 0;\n+}\n+\n+/** Whether a character code is one the terminal acts on: C0 but tab and newline, DEL, and C1. */\n+const control = (c: number) => (c < 0x20 && c !== 0x09 && c !== 0x0a) || (c >= 0x7f && c <= 0x9f);\n+\n+/** `text` as it is safe to print: colors kept only when `colors`, every other control character shown as text. */\n+export function terminalText(text: string, colors: boolean): string {\n+\tlet i = 0;\n+\twhile (i < text.length && !control(text.charCodeAt(i))) i++;\n+\tif (i === text.length) return text;\n+\tlet out = text.slice(0, i);\n+\tfor (; i < text.length; i++) {\n+\t\tconst c = text.charCodeAt(i);\n+\t\tif (!control(c)) {\n+\t\t\tout += text[i];\n+\t\t\tcontinue;\n+\t\t}\n+\t\tconst sgr = sgrAt(text, i);\n+\t\tif (sgr > 0) {\n+\t\t\tif (colors) out += text.slice(i, i + sgr);\n+\t\t\ti += sgr - 1;\n+\t\t} else if (c === 0x0d && text.charCodeAt(i + 1) === 0x0a) out += \"\\r\";\n+\t\telse out += c < 0x80 ? `\\\\x${c.toString(16).padStart(2, \"0\")}` : `\\\\u${c.toString(16).padStart(4, \"0\")}`;\n+\t}\n+\treturn out;\n+}"},{"path":"client/test/terminal-text.test.ts","added":78,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/terminal-text.test.ts\n@@ -0,0 +1,78 @@\n+// What the client prints can't drive the terminal: colors pass to a terminal\n+// with NO_COLOR unset, and every other control character shows as text.\n+\n+import assert from \"node:assert/strict\";\n+import { execFile } from \"node:child_process\";\n+import { mkdtempSync, rmSync } from \"node:fs\";\n+import { tmpdir } from \"node:os\";\n+import { join, resolve } from \"node:path\";\n+import { describe, it } from \"node:test\";\n+import { colorsPass, terminalText } from \"../src/terminal-text.ts\";\n+\n+const ESC = \"\\x1b\";\n+\n+describe(\"terminalText\", () => {\n+\tit(\"leaves plain text, tabs, newlines and CRLF alone\", () => {\n+\t\tconst plain = \"abso 72\\tpublished\\nnext line: ü, 中文, 🙂\\r\\n\";\n+\t\tassert.equal(terminalText(plain, true), plain);\n+\t\tassert.equal(terminalText(plain, false), plain);\n+\t});\n+\n+\tit(\"keeps colors only when they pass, and drops them quietly otherwise\", () => {\n+\t\tconst red = `${ESC}[31mfailed${ESC}[0m and ${ESC}[1;38;5;208mbold${ESC}[m`;\n+\t\tassert.equal(terminalText(red, true), red);\n+\t\tassert.equal(terminalText(red, false), \"failed and bold\");\n+\t});\n+\n+\tit(\"shows OSC 52 (the clipboard) and OSC 8 (links) as text, with or without colors\", () => {\n+\t\tconst clip = `${ESC}]52;c;ZWNobyBoaQ==\\x07`;\n+\t\tassert.equal(terminalText(clip, true), \"\\\\x1b]52;c;ZWNobyBoaQ==\\\\x07\");\n+\t\tconst link = `${ESC}]8;;https://evil.example${ESC}\\\\click${ESC}]8;;${ESC}\\\\`;\n+\t\tassert.equal(terminalText(link, true), \"\\\\x1b]8;;https://evil.example\\\\x1b\\\\click\\\\x1b]8;;\\\\x1b\\\\\");\n+\t});\n+\n+\tit(\"shows other CSI, DCS and the rest of C0 and C1 as text\", () => {\n+\t\tassert.equal(terminalText(`${ESC}[2J${ESC}[H`, true), \"\\\\x1b[2J\\\\x1b[H\");\n+\t\tassert.equal(terminalText(`${ESC}P1$r${ESC}\\\\`, true), \"\\\\x1bP1$r\\\\x1b\\\\\");\n+\t\tassert.equal(terminalText(\"over\\rwrite\\b\\x00\\x7f\", true), \"over\\\\x0dwrite\\\\x08\\\\x00\\\\x7f\");\n+\t\tassert.equal(terminalText(\"\\u009b31m\\u0090x\\u009c\", true), \"\\\\u009b31m\\\\u0090x\\\\u009c\");\n+\t\t// An SGR with anything but digits, ; and : isn't one.\n+\t\tassert.equal(terminalText(`${ESC}[31;\"m`, true), '\\\\x1b[31;\"m');\n+\t});\n+\n+\tit(\"colors pass to a terminal only, and never with NO_COLOR set\", () => {\n+\t\tassert.equal(colorsPass({ isTTY: true }, {}), true);\n+\t\tassert.equal(colorsPass({ isTTY: true }, { NO_COLOR: \"1\" }), false);\n+\t\tassert.equal(colorsPass({ isTTY: true }, { NO_COLOR: \"\" }), true);\n+\t\tassert.equal(colorsPass({ isTTY: false }, {}), false);\n+\t\tassert.equal(colorsPass({}, {}), false);\n+\t});\n+\n+\tit(\"the client's own output goes through it: an error naming text with escapes prints them as text\", async () => {\n+\t\tconst home = mkdtempSync(join(tmpdir(), \"abso-test-terminal-\"));\n+\t\ttry {\n+\t\t\t// An unknown command: the error names it, escape and all.\n+\t\t\tconst dir = mkdtempSync(join(home, \"x\"));\n+\t\t\tconst env: Record<string, string> = {\n+\t\t\t\tPATH: process.env.PATH ?? \"\",\n+\t\t\t\tHOME: home,\n+\t\t\t\tUSERPROFILE: home,\n+\t\t\t\tAVCS_SERVERS_FILE: \"no-servers.json\",\n+\t\t\t};\n+\t\t\tif (process.env.SystemRoot) env.SystemRoot = process.env.SystemRoot;\n+\t\t\tconst client = resolve(import.meta.dirname, \"..\", \"abso.ts\");\n+\t\t\tconst run = await new Promise<{ stdout: string; stderr: string }>((done) =>\n+\t\t\t\texecFile(\n+\t\t\t\t\tprocess.execPath,\n+\t\t\t\t\t[client, `frob${ESC}]52;c;aGk=\\x07`],\n+\t\t\t\t\t{ cwd: dir, env },\n+\t\t\t\t\t(_e, stdout, stderr) => done({ stdout, stderr }),\n+\t\t\t\t),\n+\t\t\t);\n+\t\t\tassert.doesNotMatch(run.stdout + run.stderr, /\\x1b/);\n+\t\t\tassert.match(run.stderr, /frob\\\\x1b\\]52;c;aGk=\\\\x07/);\n+\t\t} finally {\n+\t\t\trmSync(home, { recursive: true, force: true });\n+\t\t}\n+\t});\n+});"}],"ci":null}