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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ const codex = ProviderDriverKind.make("codex");
const acpRegistry = ProviderDriverKind.make("acpRegistry");

describe("providerInstanceInitials", () => {
it("treats punctuation as a word break but keeps apostrophes between letters", () => {
expect(providerInstanceInitials("Codex (hub)")).toBe("CH");
expect(providerInstanceInitials("work_codex")).toBe("WC");
expect(providerInstanceInitials("Theo's Codex")).toBe("TC");
expect(providerInstanceInitials("Codex 'hub'")).toBe("CH");
expect(providerInstanceInitials("‘hub’")).toBe("HU");
expect(providerInstanceInitials("(hub)")).toBe("HU");
});

it("keeps an emoji whole instead of splitting its surrogate pair", () => {
expect(providerInstanceInitials("😀 Work")).toBe("😀W");
expect(providerInstanceInitials("😀")).toBe("😀");
Expand Down
9 changes: 8 additions & 1 deletion packages/client-runtime/src/state/providerInstanceDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ export function resolveProviderInstanceDisplayName(
}

export function providerInstanceInitials(label: string): string {
const words = label.replace(/[_-]+/g, " ").split(/\s+/u).filter(Boolean);
// Punctuation separates words so "Codex (hub)" reads CH, not C(. An apostrophe
// inside a word stays ("Theo's Codex" is TC); a quoting one does not
// ("Codex 'hub'" is CH).
const words = label
.replace(/[^\P{P}'’]+/gu, " ")
.split(/\s+/u)
.map((word) => word.replace(/^['’]+|['’]+$/gu, ""))
.filter(Boolean);
if (words.length === 0) return "";
if (words.length === 1) return Array.from(words[0]!).slice(0, 2).join("").toUpperCase();
return words
Expand Down
Loading