Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/strip-c0-thread-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"grok-bot-cli": patch
---

Strip C0/C1 controls (including CR, backspace, and BEL) from `gbot codex list-threads` text output, not only ESC sequences.
5 changes: 3 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,13 @@ function takeLeadingGlobals(args) {
return { json, gateway, files, dir };
}

/** Strip CSI/OSC so thread names/previews cannot drive the terminal. */
/** Strip CSI/OSC and other C0/C1 controls so thread fields cannot drive the terminal. */
function stripTerminalControls(text) {
return String(text)
.replace(/\u001b\[[0-9;?]*[ -/]*[@-~]/g, "")
.replace(/\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)/g, "")
.replace(/\u001b./g, "");
.replace(/\u001b./g, "")
.replace(/[\u0000-\u001F\u007F-\u009F]/g, "");
}

function parseOnOff(value, flag) {
Expand Down
12 changes: 8 additions & 4 deletions test/codex-bridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ test("codex list-threads strips terminal controls from names and previews", asyn
{
id: "t-evil",
status: { type: "idle" },
name: "Build\u001b[31mRED\u001b[0m",
preview: "hi\u001b]0;owned\u0007 there",
cwd: "/repo",
name: "Build\u001b[31mRED\u001b[0m\rOVERWRITE",
preview: "hi\u001b]0;owned\u0007 there\b\bXX",
cwd: "/repo\u0007",
source: "cli",
updatedAt: 1,
},
Expand All @@ -303,9 +303,13 @@ test("codex list-threads strips terminal controls from names and previews", asyn
try {
const { code, out } = await gbot(fake.home, "codex", "list-threads");
assert.equal(code, 0);
assert.match(out, /BuildRED/);
assert.match(out, /BuildREDOVERWRITE/);
assert.doesNotMatch(out, /\u001b/);
assert.doesNotMatch(out, /\]0;owned/);
assert.doesNotMatch(out, /\r/);
assert.doesNotMatch(out, /\u0008/);
assert.doesNotMatch(out, /\u0007/);
assert.match(out, /hi thereXX/);
} finally {
await fake.close();
}
Expand Down