Skip to content
TypeScript

fix(cli): t3 thread start titles no longer end in a broken character (#29563)

Alex Southwella565d8953ed9
diff --git a/apps/server/src/cli/thread.test.ts b/apps/server/src/cli/thread.test.ts
index e09f3be0031..1fab7881bcb 100644
--- a/apps/server/src/cli/thread.test.ts
+++ b/apps/server/src/cli/thread.test.ts
@@ -2,7 +2,7 @@ import { assert, it } from "@effect/vitest";
import { RunId, ThreadId } from "@t3tools/contracts";
import * as Effect from "effect/Effect";
-import { readLatestMessages, type ThreadTools, waitForRun } from "./thread.ts";
+import { readLatestMessages, type ThreadTools, titleFromMessage, waitForRun } from "./thread.ts";
const threadId = ThreadId.make("thread-1");
const runId = RunId.make("run-1");
@@ -160,3 +160,8 @@ it.effect("show returns a --messages count larger than one call can spread", ()
);
}),
);
+
+it("titles from a long first line without splitting an emoji", () => {
+ const title = titleFromMessage(`${"a".repeat(78)}😀 and the rest of a long first line`);
+ assert.strictEqual(title, `${"a".repeat(78)}…`);
+});
diff --git a/apps/server/src/cli/thread.ts b/apps/server/src/cli/thread.ts
index 5d944e2723e..7bfddda4723 100644
--- a/apps/server/src/cli/thread.ts
+++ b/apps/server/src/cli/thread.ts
@@ -508,11 +508,16 @@ const finishRun = Effect.fn("cli.thread.finishRun")(function* (
}
});
-const titleFromMessage = (message: string) => {
+export const titleFromMessage = (message: string) => {
const firstLine = message.trim().split("\n")[0]?.trim() ?? "";
- return firstLine.length > TITLE_MAX_CHARS
- ? `${firstLine.slice(0, TITLE_MAX_CHARS - 1).trimEnd()}…`
- : firstLine;
+ if (firstLine.length <= TITLE_MAX_CHARS) return firstLine;
+ let end = TITLE_MAX_CHARS - 1;
+ const previous = firstLine.charCodeAt(end - 1);
+ const next = firstLine.charCodeAt(end);
+ if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
+ end -= 1;
+ }
+ return `${firstLine.slice(0, end).trimEnd()}…`;
};
const launchWorkspaceStrategy = (input: {