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, 04:30 UTC
fix(web): big terminal selections no longer break sending (#29804)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Alex Southwell committed
Nov 3, 2026 at 23:31 UTC
77b948e3e78d53e2c0ff52b2c36ab02edc59fd4c
2 files changed
+26
-3
apps/web/src/lib/composerContextRecords.test.ts
+16
-1
@@ -255,7 +255,7 @@ describe("composerContextRecords", () => {
255
expect(removeInlineContextReference(prompt, reference.contextId).prompt).toBe("prose tail");
256
});
257
258
- it("clamps an oversized review selection so the record still encodes", () => {
258
+ it("clamps oversized review and terminal selections so the records still encode", () => {
259
const build = (diffLength: number) =>
260
reviewCommentContextRecord({
261
id: "rc-big",
@@ -276,6 +276,21 @@ describe("composerContextRecords", () => {
276
expect(overLimit.diff.endsWith("… truncated …")).toBe(true);
277
expect(() => decodeMessageContext({ version: 1, records: [atLimit] })).not.toThrow();
278
expect(() => decodeMessageContext({ version: 1, records: [overLimit] })).not.toThrow();
279
+
280
+ const terminal = terminalContextRecord({
281
+ id: "term-big",
282
+ threadId: ThreadId.make("t"),
283
+ createdAt: "2026-01-01T00:00:00.000Z",
284
+ terminalId: "default",
285
+ terminalLabel: "Terminal 1",
286
+ lineStart: 1,
287
+ lineEnd: 2_000,
288
+ text: `${"t".repeat(63_985)}${"😀".repeat(8)}`,
289
+ });
290
+ expect(terminal.text).toBe(`${"t".repeat(63_985)}\n… truncated …`);
291
+ expect(decodeMessageContext({ version: 1, records: [terminal] }).records).toMatchObject([
292
+ { kind: "terminal", text: terminal.text },
293
+ ]);
294
});
295
296
it("finds the destination collision for different legacy terminal messages", () => {
apps/web/src/lib/composerContextRecords.ts
+10
-2
@@ -5,6 +5,7 @@ import {
5
import {
6
COMPOSER_CONTEXT_REVIEW_DIFF_MAX_CHARS,
7
COMPOSER_CONTEXT_REVIEW_TEXT_MAX_CHARS,
8
+ COMPOSER_CONTEXT_TERMINAL_TEXT_MAX_CHARS,
9
} from "@t3tools/contracts";
10
import type {
11
ComposerContextId,
@@ -52,7 +53,11 @@ const TRUNCATION_MARKER = "\n… truncated …";
53
54
function clampContextText(value: string, max: number): string {
55
if (value.length <= max) return value;
55
- return `${value.slice(0, Math.max(0, max - TRUNCATION_MARKER.length))}${TRUNCATION_MARKER}`;
56
+ let end = Math.max(0, max - TRUNCATION_MARKER.length);
57
+ // Never end on a lone high surrogate.
58
+ const last = value.charCodeAt(end - 1);
59
+ if (last >= 0xd800 && last <= 0xdbff) end -= 1;
60
+ return `${value.slice(0, end)}${TRUNCATION_MARKER}`;
61
}
62
63
type ReviewCommentPresentation = ReviewCommentContext | ReviewCommentContextRecord;
@@ -187,7 +192,10 @@ export function terminalContextRecord(context: TerminalContextDraft): TerminalCo
192
terminalLabel: context.terminalLabel,
193
lineStart: context.lineStart,
194
lineEnd: context.lineEnd,
190
- text: normalizeTerminalContextText(context.text),
195
+ text: clampContextText(
196
+ normalizeTerminalContextText(context.text),
197
+ COMPOSER_CONTEXT_TERMINAL_TEXT_MAX_CHARS,
198
+ ),
199
};
200
}
201