Skip to content

Commit dd48efc

Browse files
saphidclaude
andcommitted
fix(provider-core): long subagent titles no longer end in a broken character
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 61c3794 commit dd48efc

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { subagentThreadTitle } from "./subagentProjection.ts";
4+
5+
describe("subagentThreadTitle", () => {
6+
it("clips a long prompt without splitting a surrogate pair", () => {
7+
const title = (prompt: string) =>
8+
subagentThreadTitle({ parentTitle: "Parent", prompt, ordinal: 1 });
9+
10+
expect(title(`${"a".repeat(68)}😀 and more work.`)).toBe(`${"a".repeat(68)}...`);
11+
expect(title(`${"a".repeat(67)}😀 and more work.`)).toBe(`${"a".repeat(67)}😀...`);
12+
});
13+
});

‎packages/provider-core/src/server/subagentProjection.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ export function subagentThreadTitle(input: {
3939
if (detail === undefined) {
4040
return `${input.parentTitle} subagent ${input.ordinal}`;
4141
}
42-
const clipped = detail.length > 72 ? `${detail.slice(0, 69)}...` : detail;
43-
return clipped;
42+
if (detail.length <= 72) return detail;
43+
let end = 69;
44+
const previous = detail.charCodeAt(end - 1);
45+
const next = detail.charCodeAt(end);
46+
if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
47+
end -= 1;
48+
}
49+
return `${detail.slice(0, end)}...`;
4450
}
4551

4652
export function makeSubagentChildThread(input: {

0 commit comments

Comments
 (0)