Skip to content

The agent that grows with you

fix(desktop): preserve Unicode graphemes in profile initials

brooklyn!2b18ca786756
diff --git a/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx b/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx
index 7dc3722e811..8e3a5a2beb9 100644
--- a/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx
+++ b/apps/desktop/src/app/chat/sidebar/profile-switcher.tsx
@@ -51,6 +51,7 @@ import { sortConnectionsForDisplay } from '@/lib/connection-display'
import { triggerHaptic } from '@/lib/haptics'
import { Loader2 } from '@/lib/icons'
import { PROFILE_SWATCHES, profileColorSoft, resolveProfileColor } from '@/lib/profile-color'
+import { profileShortLabel } from '@/lib/profile-short-label'
import {
REORDER_DRAG_TRANSITION_CSS,
REORDER_RAIL_TRANSITION,
@@ -1115,7 +1116,7 @@ function RestSquare({
{pending ? (
<Loader2 aria-hidden="true" className="size-3 animate-spin" />
) : (
- agent.profile.replace(/[^a-z0-9]/gi, '').charAt(0) || '?'
+ profileShortLabel(agent.profile)
)}
</button>
</TooltipTrigger>
@@ -1328,7 +1329,7 @@ function ProfileSquare({
onPointerMove={notePointerMove}
onPointerUp={clearPress}
>
- {label.replace(/[^a-z0-9]/gi, '').charAt(0) || '?'}
+ {profileShortLabel(label)}
{/* The "remote" badge: a tiny globe pinned to the corner of an
overridden profile's square, so which profiles leave this
machine is visible at a glance (#91349). */}
diff --git a/apps/desktop/src/components/ui/profile-glyph.tsx b/apps/desktop/src/components/ui/profile-glyph.tsx
index 7a67c5749d2..430c2ab493e 100644
--- a/apps/desktop/src/components/ui/profile-glyph.tsx
+++ b/apps/desktop/src/components/ui/profile-glyph.tsx
@@ -1,4 +1,5 @@
import { profileColorSoft } from '@/lib/profile-color'
+import { profileShortLabel } from '@/lib/profile-short-label'
import { cn } from '@/lib/utils'
import { Codicon } from './codicon'
@@ -26,7 +27,7 @@ export function ProfileGlyph({
)
}
- const initial = name.replace(/[^a-z0-9]/gi, '').charAt(0) || '?'
+ const initial = profileShortLabel(name)
return (
<span
diff --git a/apps/desktop/src/lib/profile-short-label.ts b/apps/desktop/src/lib/profile-short-label.ts
new file mode 100644
index 00000000000..71511e2178d
--- /dev/null
+++ b/apps/desktop/src/lib/profile-short-label.ts
@@ -0,0 +1,12 @@
+const profileGraphemes = new Intl.Segmenter(undefined, { granularity: 'grapheme' })
+
+/** Keep combining marks and emoji sequences together without changing the rail's size. */
+export function profileShortLabel(label: string): string {
+ for (const { segment } of profileGraphemes.segment(label.trim())) {
+ if (/[\p{L}\p{N}\p{Extended_Pictographic}\p{Regional_Indicator}]/u.test(segment)) {
+ return segment
+ }
+ }
+
+ return '?'
+}