Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
show on this site's /mcp
CLI
abso show 74 --json
JSON
/christopher/abso-core/versions/74?format=json

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.

of shared·pinch··Not checked

Version 73 · Files at version 74

4 files, 137 lines added, 9 removed.

--- a/client/avcs.ts
+++ b/client/avcs.ts
@@ -26,13 +26,12 @@
2626 await serveMcp(process.stdin, (line) => process.stdout.write(`${line}\n`), process.cwd(), process.env);
2727} else {
2828 const { main } = await import("./src/main.ts");
29− const result = await main(argv, {
30− cwd: process.cwd(),
31− env: process.env,
32− write: (text) => process.stdout.write(text),
33− writeErr: (text) => process.stderr.write(text),
34− });
35− if (result.stdout) process.stdout.write(result.stdout);
36− if (result.stderr) process.stderr.write(result.stderr);
29+ // Everything printed goes through terminalText: most of it is a server's text (abso-core's terminal-text.ts).
30+ const { colorsPass, terminalText } = await import("./src/terminal-text.ts");
31+ const out = (text: string) => process.stdout.write(terminalText(text, colorsPass(process.stdout, process.env)));
32+ const err = (text: string) => process.stderr.write(terminalText(text, colorsPass(process.stderr, process.env)));
33+ const result = await main(argv, { cwd: process.cwd(), env: process.env, write: out, writeErr: err });
34+ if (result.stdout) out(result.stdout);
35+ if (result.stderr) err(result.stderr);
3736 process.exitCode = result.exit;
3837}
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -48,6 +48,7 @@
4848import { runUnqueue } from "./queue.ts";
4949import { runNote, runNotes, runReview } from "./review.ts";
5050import { installSkill, SKILL, skillPath } from "./skill.ts";
51+import { colorsPass, terminalText } from "./terminal-text.ts";
5152import { runAmend, runDrop, runFollow, runLabel, runLabels, runPluck } from "./versions.ts";
5253import { runVisibility } from "./visibility-commands.ts";
5354
@@ -180,7 +181,10 @@
180181 bool(args, "no-browser") || browserSkip(env.env, process.platform) !== null
181182 ? undefined
182183 : (url: string) => openInBrowser(url);
183− const record = await login(server, { say: (line) => process.stderr.write(`${line}\n`), open });
184+ const record = await login(server, {
185+ say: (line) => process.stderr.write(terminalText(`${line}\n`, colorsPass(process.stderr, env.env))),
186+ open,
187+ });
184188 return {
185189 text: `This box is signed in. ${boxText(record, server).split("\n").slice(1).join(" ")}`,
186190 json: { box: boxPublic(record) },
--- /dev/null
+++ b/client/src/terminal-text.ts
@@ -0,0 +1,47 @@
1+// What the client prints is mostly text a server sent: version messages, news,
2+// CI logs, file paths, agent names. So nothing in it gets to drive the terminal.
3+// Tabs, newlines and colors (SGR, ESC[...m) pass. Colors pass only to a terminal
4+// with NO_COLOR unset, and are dropped otherwise. Every other control character,
5+// and with it every other escape sequence, is shown as text (\x1b, \x07, \u009b),
6+// so nothing vanishes silently.
7+
8+/** Whether colors pass: a terminal, and NO_COLOR unset or empty (no-color.org). */
9+export function colorsPass(stream: { isTTY?: boolean }, env: Readonly<Record<string, string | undefined>>): boolean {
10+ return stream.isTTY === true && !env.NO_COLOR;
11+}
13+/** The length of the SGR sequence (ESC [ digits ; : m) starting at i, or 0 when there isn't one. */
14+function sgrAt(text: string, i: number): number {
15+ if (text.charCodeAt(i) !== 0x1b || text[i + 1] !== "[") return 0;
16+ for (let j = i + 2; j < text.length && j < i + 64; j++) {
17+ const c = text[j]!;
18+ if (c === "m") return j - i + 1;
19+ if (!/[0-9;:]/.test(c)) return 0;
20+ }
21+ return 0;
22+}
24+/** Whether a character code is one the terminal acts on: C0 but tab and newline, DEL, and C1. */
25+const control = (c: number) => (c < 0x20 && c !== 0x09 && c !== 0x0a) || (c >= 0x7f && c <= 0x9f);
27+/** `text` as it is safe to print: colors kept only when `colors`, every other control character shown as text. */
28+export function terminalText(text: string, colors: boolean): string {
29+ let i = 0;
30+ while (i < text.length && !control(text.charCodeAt(i))) i++;
31+ if (i === text.length) return text;
32+ let out = text.slice(0, i);
33+ for (; i < text.length; i++) {
34+ const c = text.charCodeAt(i);
35+ if (!control(c)) {
36+ out += text[i];
37+ continue;
38+ }
39+ const sgr = sgrAt(text, i);
40+ if (sgr > 0) {
41+ if (colors) out += text.slice(i, i + sgr);
42+ i += sgr - 1;
43+ } else if (c === 0x0d && text.charCodeAt(i + 1) === 0x0a) out += "\r";
44+ else out += c < 0x80 ? `\\x${c.toString(16).padStart(2, "0")}` : `\\u${c.toString(16).padStart(4, "0")}`;
45+ }
46+ return out;
47+}
--- /dev/null
+++ b/client/test/terminal-text.test.ts
@@ -0,0 +1,78 @@
1+// What the client prints can't drive the terminal: colors pass to a terminal
2+// with NO_COLOR unset, and every other control character shows as text.
3+
4+import assert from "node:assert/strict";
5+import { execFile } from "node:child_process";
6+import { mkdtempSync, rmSync } from "node:fs";
7+import { tmpdir } from "node:os";
8+import { join, resolve } from "node:path";
9+import { describe, it } from "node:test";
10+import { colorsPass, terminalText } from "../src/terminal-text.ts";
12+const ESC = "\x1b";
14+describe("terminalText", () => {
15+ it("leaves plain text, tabs, newlines and CRLF alone", () => {
16+ const plain = "abso 72\tpublished\nnext line: ü, 中文, 🙂\r\n";
17+ assert.equal(terminalText(plain, true), plain);
18+ assert.equal(terminalText(plain, false), plain);
19+ });
21+ it("keeps colors only when they pass, and drops them quietly otherwise", () => {
22+ const red = `${ESC}[31mfailed${ESC}[0m and ${ESC}[1;38;5;208mbold${ESC}[m`;
23+ assert.equal(terminalText(red, true), red);
24+ assert.equal(terminalText(red, false), "failed and bold");
25+ });
27+ it("shows OSC 52 (the clipboard) and OSC 8 (links) as text, with or without colors", () => {
28+ const clip = `${ESC}]52;c;ZWNobyBoaQ==\x07`;
29+ assert.equal(terminalText(clip, true), "\\x1b]52;c;ZWNobyBoaQ==\\x07");
30+ const link = `${ESC}]8;;https://evil.example${ESC}\\click${ESC}]8;;${ESC}\\`;
31+ assert.equal(terminalText(link, true), "\\x1b]8;;https://evil.example\\x1b\\click\\x1b]8;;\\x1b\\");
32+ });
34+ it("shows other CSI, DCS and the rest of C0 and C1 as text", () => {
35+ assert.equal(terminalText(`${ESC}[2J${ESC}[H`, true), "\\x1b[2J\\x1b[H");
36+ assert.equal(terminalText(`${ESC}P1$r${ESC}\\`, true), "\\x1bP1$r\\x1b\\");
37+ assert.equal(terminalText("over\rwrite\b\x00\x7f", true), "over\\x0dwrite\\x08\\x00\\x7f");
38+ assert.equal(terminalText("\u009b31m\u0090x\u009c", true), "\\u009b31m\\u0090x\\u009c");
39+ // An SGR with anything but digits, ; and : isn't one.
40+ assert.equal(terminalText(`${ESC}[31;"m`, true), '\\x1b[31;"m');
41+ });
43+ it("colors pass to a terminal only, and never with NO_COLOR set", () => {
44+ assert.equal(colorsPass({ isTTY: true }, {}), true);
45+ assert.equal(colorsPass({ isTTY: true }, { NO_COLOR: "1" }), false);
46+ assert.equal(colorsPass({ isTTY: true }, { NO_COLOR: "" }), true);
47+ assert.equal(colorsPass({ isTTY: false }, {}), false);
48+ assert.equal(colorsPass({}, {}), false);
49+ });
51+ it("the client's own output goes through it: an error naming text with escapes prints them as text", async () => {
52+ const home = mkdtempSync(join(tmpdir(), "abso-test-terminal-"));
53+ try {
54+ // An unknown command: the error names it, escape and all.
55+ const dir = mkdtempSync(join(home, "x"));
56+ const env: Record<string, string> = {
57+ PATH: process.env.PATH ?? "",
58+ HOME: home,
59+ USERPROFILE: home,
60+ AVCS_SERVERS_FILE: "no-servers.json",
61+ };
62+ if (process.env.SystemRoot) env.SystemRoot = process.env.SystemRoot;
63+ const client = resolve(import.meta.dirname, "..", "abso.ts");
64+ const run = await new Promise<{ stdout: string; stderr: string }>((done) =>
65+ execFile(
66+ process.execPath,
67+ [client, `frob${ESC}]52;c;aGk=\x07`],
68+ { cwd: dir, env },
69+ (_e, stdout, stderr) => done({ stdout, stderr }),
70+ ),
71+ );
72+ assert.doesNotMatch(run.stdout + run.stderr, /\x1b/);
73+ assert.match(run.stderr, /frob\\x1b\]52;c;aGk=\\x07/);
74+ } finally {
75+ rmSync(home, { recursive: true, force: true });
76+ }
77+ });
78+});