The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 05:45 UTC
fix(server): terminal history keeps text with C1 characters (#29649)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Alex Southwell committed
Nov 3, 2026 at 23:17 UTC
663cd0822d7d1cf043a2233b6025824c67609efc
2 files changed
+10
-56
apps/server/src/terminal/Manager.test.ts
+8
-14
@@ -1115,7 +1115,8 @@ it.layer(
1115
const { manager, ptyAdapter } = yield* createManager();
1116
yield* manager.open(openInput());
1117
const process = ptyAdapter.processes[0]!;
1118
- const before = "café\t界🙂\u0007\u009c\u0085";
1118
+ // Mojibake like "â€\u009d" (for ”) carries C1 code points that libghostty prints as text.
1119
+ const before = "café\t界🙂\u0007\u009c\u0085 â€\u009d Ð\u0090 \u009e\u009f\u009b6n";
1120
const after = "e\u0301\r\n";
1121
1122
process.emitData(before);
@@ -1139,8 +1140,6 @@ it.layer(
1140
process.emitData("\u001b[?2026$p\u001b[?2026;2$y\u001b[>q\u001b[?u\u001b[?31u");
1141
process.emitData("\u001bP$q m\u001b\\\u001bP1$r0m\u001b\\");
1142
process.emitData("\u001bP+q544e\u001b\\\u001bP1+r544e=1b\u001b\\");
1142
- process.emitData("\u0090$q m\u009c\u00901$r0m\u009c");
1143
- process.emitData("\u0090+q544e\u009c\u00901+r544e=1b\u009c");
1143
process.emitData('\u001b[!p\u001b["p\u001b[4 q\u001b[u');
1144
process.emitData("\u001b]0;x\u001b\u001b[?2026$p");
1145
process.emitData("done\n");
@@ -1162,11 +1161,6 @@ it.layer(
1161
{ name: "PM", sequence: "\u001b^unfinished" },
1162
{ name: "APC", sequence: "\u001b_unfinished" },
1163
{ name: "CSI", sequence: "\u001b[5" },
1165
- { name: "C1 OSC", sequence: "\u009d0;unfinished" },
1166
- { name: "C1 DCS", sequence: "\u0090unfinished" },
1167
- { name: "C1 PM", sequence: "\u009eunfinished" },
1168
- { name: "C1 APC", sequence: "\u009funfinished" },
1169
- { name: "C1 CSI", sequence: "\u009b5" },
1164
])("keeps output after a cancelled $name sequence in history", ({ sequence }) =>
1165
Effect.gen(function* () {
1166
const { manager, ptyAdapter } = yield* createManager(10);
@@ -1200,10 +1194,10 @@ it.layer(
1194
process.emitData("\u001bP$q ");
1195
process.emitData("m\u001b");
1196
process.emitData("\\after ");
1203
- process.emitData("\u009b?3");
1197
+ process.emitData("\u001b[?3");
1198
process.emitData("1uafter ");
1205
- process.emitData("\u0090+q544e");
1206
- process.emitData("\u009cafter\n");
1199
+ process.emitData("\u001bP+q544e");
1200
+ process.emitData("\u001b\\after\n");
1201
1202
yield* manager.close({ threadId: "thread-1" });
1203
@@ -1226,10 +1220,10 @@ it.layer(
1220
yield* Effect.addFinalizer(() => Effect.sync(unsubscribe));
1221
const sequences = [
1222
{ prefix: `\u001b]52;c;${"YWJj".repeat(16_384)}\u001b`, terminator: "\\" },
1229
- { prefix: `\u0090q${"?".repeat(65_536)}`, terminator: "\u009c" },
1223
+ { prefix: `\u001bPq${"?".repeat(65_536)}`, terminator: "\u001b\\" },
1224
];
1231
- const stripped = "\u001b]11;?\u0007\u0090$q m\u009c";
1232
- const preserved = "\u001b[31m\u009d52;c;YWJj\u009c";
1225
+ const stripped = "\u001b]11;?\u0007\u001bP$q m\u001b\\";
1226
+ const preserved = "\u001b[31m\u001b]52;c;YWJj\u0007";
1227
const expected =
1228
sequences.map(({ prefix, terminator }) => prefix + terminator + preserved).join("") +
1229
"done\n";
apps/server/src/terminal/Manager.ts
+2
-42
@@ -1174,7 +1174,8 @@ function findEscapeSequenceEndIndex(input: string, start: number): number | null
1174
return isEscapeFinalByte(input.charCodeAt(cursor)) ? cursor + 1 : start + 1;
1175
}
1176
1177
-const HISTORY_SEQUENCE_START = /[\u001b\u0090\u009b\u009d\u009e\u009f]/;
1177
+// libghostty prints UTF-8 C1 code points (U+0080-U+009F) as text, so only ESC starts a sequence.
1178
+const HISTORY_SEQUENCE_START = /\u001b/;
1179
const NEXT_HISTORY_SEQUENCE_START = new RegExp(HISTORY_SEQUENCE_START.source, "g");
1180
1181
function sanitizeTerminalHistoryChunk(
@@ -1259,47 +1260,6 @@ function sanitizeTerminalHistoryChunk(
1260
continue;
1261
}
1262
1262
- if (codePoint === 0x9b) {
1263
- let cursor = index + 1;
1264
- while (cursor < input.length) {
1265
- const cancelled = isControlSequenceCancel(input.charCodeAt(cursor));
1266
- if (cancelled || isCsiFinalByte(input.charCodeAt(cursor))) {
1267
- const sequence = input.slice(index, cursor + 1);
1268
- const body = input.slice(index + 1, cursor);
1269
- if (cancelled || !shouldStripCsiSequence(body, input[cursor] ?? "")) {
1270
- append(sequence);
1271
- }
1272
- index = cursor + 1;
1273
- break;
1274
- }
1275
- cursor += 1;
1276
- }
1277
- if (cursor >= input.length) {
1278
- return { visibleText, pendingControlSequence: input.slice(index) };
1279
- }
1280
- continue;
1281
- }
1282
-
1283
- if (codePoint === 0x9d || codePoint === 0x90 || codePoint === 0x9e || codePoint === 0x9f) {
1284
- const terminatorIndex = findStringTerminatorIndex(
1285
- input,
1286
- Math.max(index + 1, pendingScanStart),
1287
- );
1288
- if (terminatorIndex === null) {
1289
- return { visibleText, pendingControlSequence: input.slice(index) };
1290
- }
1291
- const sequence = input.slice(index, terminatorIndex);
1292
- const content = stripStringTerminator(input.slice(index + 1, terminatorIndex));
1293
- const strip =
1294
- (codePoint === 0x9d && shouldStripOscSequence(content)) ||
1295
- (codePoint === 0x90 && shouldStripDcsSequence(content));
1296
- if (!strip) {
1297
- append(sequence);
1298
- }
1299
- index = terminatorIndex;
1300
- continue;
1301
- }
1302
-
1263
// One slice per printable run: every chunk of coloured output reaches this loop.
1264
NEXT_HISTORY_SEQUENCE_START.lastIndex = index + 1;
1265
const nextSequenceStart = NEXT_HISTORY_SEQUENCE_START.exec(input)?.index ?? input.length;