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
blame on this site's /mcp
CLI
abso blame client/src/terminal-text.ts --json
JSON
/christopher/abso-core/blame/client/src/terminal-text.ts?format=json
70 linespinch 100%Last change pinch in version 82,

70 lines from 3 changes in 3 versions.

pinch74Server 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.Compare1// 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). */
9export function colorsPass(stream: { isTTY?: boolean }, env: Readonly<Record<string, string | undefined>>): boolean {
10 return stream.isTTY === true && !env.NO_COLOR;
13/** The length of the SGR sequence (ESC [ digits ; : m) starting at i, or 0 when there isn't one. */
14function 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;
pinch79abso help --json: every command help shows, with its usage, about and flags, as data, so a command reference can be built from the client itself. And the terminal filter drops SGR 8 (conceal), which could hide text, keeping 8 where it's a color (38;5;8).Compare24/**
pinch82Terminal text: conceal (SGR 8) is found by value, as a terminal reads it. 08, 008 and 8:1 are 8 too and are dropped. 038;05;8 is still a color and is kept.Compare25 * An SGR sequence without parameter 8 (conceal), which would hide the text after it from the reader. Parameters
26 * are read by value, as a terminal reads them: 08 and 8:1 are 8 too. The 8 in an extended color (38;5;8,
27 * 48;2;8;8;8, 038;05;8) is a color, so those are copied whole. Nothing is left when 8 was all it said.
pinch79abso help --json: every command help shows, with its usage, about and flags, as data, so a command reference can be built from the client itself. And the terminal filter drops SGR 8 (conceal), which could hide text, keeping 8 where it's a color (38;5;8).Compare28 */
29function withoutConceal(sgr: string): string {
30 const parts = sgr.slice(2, -1).split(";");
pinch82Terminal text: conceal (SGR 8) is found by value, as a terminal reads it. 08, 008 and 8:1 are 8 too and are dropped. 038;05;8 is still a color and is kept.Compare31 const value = (p: string | undefined) => (p === undefined ? Number.NaN : Number(p.split(":")[0]));
pinch79abso help --json: every command help shows, with its usage, about and flags, as data, so a command reference can be built from the client itself. And the terminal filter drops SGR 8 (conceal), which could hide text, keeping 8 where it's a color (38;5;8).Compare32 const kept: string[] = [];
33 for (let i = 0; i < parts.length; i++) {
34 const p = parts[i]!;
pinch82Terminal text: conceal (SGR 8) is found by value, as a terminal reads it. 08, 008 and 8:1 are 8 too and are dropped. 038;05;8 is still a color and is kept.Compare35 const v = value(p);
36 const mode = value(parts[i + 1]);
37 if ((v === 38 || v === 48 || v === 58) && !p.includes(":") && (mode === 5 || mode === 2)) {
38 const n = mode === 5 ? 3 : 5;
pinch79abso help --json: every command help shows, with its usage, about and flags, as data, so a command reference can be built from the client itself. And the terminal filter drops SGR 8 (conceal), which could hide text, keeping 8 where it's a color (38;5;8).Compare39 kept.push(...parts.slice(i, i + n));
40 i += n - 1;
pinch82Terminal text: conceal (SGR 8) is found by value, as a terminal reads it. 08, 008 and 8:1 are 8 too and are dropped. 038;05;8 is still a color and is kept.Compare41 } else if (v !== 8) kept.push(p);
pinch79abso help --json: every command help shows, with its usage, about and flags, as data, so a command reference can be built from the client itself. And the terminal filter drops SGR 8 (conceal), which could hide text, keeping 8 where it's a color (38;5;8).Compare42 }
43 if (kept.length === parts.length) return sgr;
44 return kept.length === 0 ? "" : `\x1b[${kept.join(";")}m`;
pinch74Server 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.Compare47/** Whether a character code is one the terminal acts on: C0 but tab and newline, DEL, and C1. */
48const control = (c: number) => (c < 0x20 && c !== 0x09 && c !== 0x0a) || (c >= 0x7f && c <= 0x9f);
50/** `text` as it is safe to print: colors kept only when `colors`, every other control character shown as text. */
51export function terminalText(text: string, colors: boolean): string {
52 let i = 0;
53 while (i < text.length && !control(text.charCodeAt(i))) i++;
54 if (i === text.length) return text;
55 let out = text.slice(0, i);
56 for (; i < text.length; i++) {
57 const c = text.charCodeAt(i);
58 if (!control(c)) {
59 out += text[i];
60 continue;
61 }
62 const sgr = sgrAt(text, i);
63 if (sgr > 0) {
pinch79abso help --json: every command help shows, with its usage, about and flags, as data, so a command reference can be built from the client itself. And the terminal filter drops SGR 8 (conceal), which could hide text, keeping 8 where it's a color (38;5;8).Compare64 if (colors) out += withoutConceal(text.slice(i, i + sgr));
pinch74Server 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.Compare65 i += sgr - 1;
66 } else if (c === 0x0d && text.charCodeAt(i + 1) === 0x0a) out += "\r";
67 else out += c < 0x80 ? `\\x${c.toString(16).padStart(2, "0")}` : `\\u${c.toString(16).padStart(4, "0")}`;
68 }
69 return out;