Skip to content

Commit c58d1cc

Browse files
saphidclaude
andcommitted
fix(cli): t3 thread start titles no longer end in a broken character
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent cc59f99 commit c58d1cc

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎apps/server/src/cli/thread.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { assert, it } from "@effect/vitest";
22
import { RunId, ThreadId } from "@t3tools/contracts";
33
import * as Effect from "effect/Effect";
44

5-
import { readLatestMessages, type ThreadTools, waitForRun } from "./thread.ts";
5+
import { readLatestMessages, type ThreadTools, titleFromMessage, waitForRun } from "./thread.ts";
66

77
const threadId = ThreadId.make("thread-1");
88
const runId = RunId.make("run-1");
@@ -160,3 +160,8 @@ it.effect("show returns a --messages count larger than one call can spread", ()
160160
);
161161
}),
162162
);
163+
164+
it("titles from a long first line without splitting an emoji", () => {
165+
const title = titleFromMessage(`${"a".repeat(78)}😀 and the rest of a long first line`);
166+
assert.strictEqual(title, `${"a".repeat(78)}…`);
167+
});

‎apps/server/src/cli/thread.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,16 @@ const finishRun = Effect.fn("cli.thread.finishRun")(function* (
508508
}
509509
});
510510

511-
const titleFromMessage = (message: string) => {
511+
export const titleFromMessage = (message: string) => {
512512
const firstLine = message.trim().split("\n")[0]?.trim() ?? "";
513-
return firstLine.length > TITLE_MAX_CHARS
514-
? `${firstLine.slice(0, TITLE_MAX_CHARS - 1).trimEnd()}…`
515-
: firstLine;
513+
if (firstLine.length <= TITLE_MAX_CHARS) return firstLine;
514+
let end = TITLE_MAX_CHARS - 1;
515+
const previous = firstLine.charCodeAt(end - 1);
516+
const next = firstLine.charCodeAt(end);
517+
if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
518+
end -= 1;
519+
}
520+
return `${firstLine.slice(0, end).trimEnd()}…`;
516521
};
517522

518523
const launchWorkspaceStrategy = (input: {

0 commit comments

Comments
 (0)