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
7 changes: 6 additions & 1 deletion apps/server/src/cli/thread.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)}…`);
});
13 changes: 9 additions & 4 deletions apps/server/src/cli/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Loading