Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(tray): cap session titles by display columns
vastsa9a5ed767efdb
diff --git a/docs/adr/tray-session-shortcuts.md b/docs/adr/tray-session-shortcuts.mdindex 28c0d1b51..e3df874f9 100644--- a/docs/adr/tray-session-shortcuts.md+++ b/docs/adr/tray-session-shortcuts.md@@ -44,8 +44,9 @@ or closed, so a renderer-only menu snapshot would become stale.read. Single-click opens the attached menu; double-click and Open retainwindow restore behavior. Each overflowing group has View more, whichrestores the main window and expands the existing session sidebar. Titles are one- line and capped at 48 Unicode code points including an ellipsis; labels- use the active shipped locale. Quit retains confirmation and shutdown.+ line and capped at 32 display columns including an ellipsis, counting an East+ Asian wide or emoji code point as two; labels use the active shipped locale.+ Quit retains confirmation and shutdown.## Consequencesdiff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.mdindex 8c86d108c..5a8426821 100644--- a/docs/spec/04-ux/09-interaction-patterns.md+++ b/docs/spec/04-ux/09-interaction-patterns.md@@ -189,10 +189,12 @@ recency only breaks ties between equally relevant matches.- Empty groups are hidden. Archived sessions/projects and deleted sessionsare excluded. Running/Pinned follow sidebar sorting; Unread follows thelatest unread result per session, newest first, including failed results.-- Long titles use one line and an ellipsis after at most 48 Unicode code- points. An overflowing group offers View more to restore the window and- expand session navigation. A session row restores/focuses its exact conversation,- activating its project through the existing selection flow.+- Long titles use one line capped at 32 display columns including the+ ellipsis; an East Asian wide or emoji code point counts as two, so a CJK+ row stays as wide as a Latin one. An overflowing group offers View more to+ restore the window and expand session navigation. A session row+ restores/focuses its exact conversation, activating its project through the+ existing selection flow.- macOS single-click opens the menu without restoring/focusing a conversationor marking it read. Entering a conversation uses normal acknowledgement.Open and double-click restore the window; Quit keeps its confirmation anddiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 259e811e4..d91d8346d 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -13081,7 +13081,8 @@ plugin-form fixtures in an isolated temporary directory at runtime.Running overflow cannotappear as Unread/Pinned. Empty groups and stale shortcuts disappear. Unreaduses the latest terminal result per session, newest first. Titles remain- one line within the cap, including literal ampersands. Opening the macOS+ one line within the 32-column cap, half as many characters for CJK/emoji,+ including literal ampersands. Opening the macOSmenu leaves the window hidden and records unread. A row opens exactly thatsession/project, acknowledges it normally, and wins over startup navigation.View more returns from Settings, closes search, and expands session navigation. Hidden/closed windows receive fresh groups;diff --git a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md b/docs/zh-CN/spec/04-ux/09-interaction-patterns.mdindex 0c61af0cd..7e76a0a8f 100644--- a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md+++ b/docs/zh-CN/spec/04-ux/09-interaction-patterns.md@@ -152,10 +152,12 @@- Empty groups are hidden. Archived sessions/projects and deleted sessionsare excluded. Running/Pinned follow sidebar sorting; Unread follows thelatest unread result per session, newest first, including failed results.-- Long titles use one line and an ellipsis after at most 48 Unicode code- points. An overflowing group offers View more to restore the window and- expand session navigation. A session row restores/focuses its exact conversation,- activating its project through the existing selection flow.+- Long titles use one line capped at 32 display columns including the+ ellipsis; an East Asian wide or emoji code point counts as two, so a CJK+ row stays as wide as a Latin one. An overflowing group offers View more to+ restore the window and expand session navigation. A session row+ restores/focuses its exact conversation, activating its project through the+ existing selection flow.- macOS single-click opens the menu without restoring/focusing a conversationor marking it read. Entering a conversation uses normal acknowledgement.Open and double-click restore the window; Quit keeps its confirmation anddiff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex 398f8596c..0e8930d25 100644--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@ -7885,7 +7885,8 @@ runner 会在运行时的隔离临时目录中生成六个插件形态 fixtureRunning overflow cannotappear as Unread/Pinned. Empty groups and stale shortcuts disappear. Unreaduses the latest terminal result per session, newest first. Titles remain- one line within the cap, including literal ampersands. Opening the macOS+ one line within the 32-column cap, half as many characters for CJK/emoji,+ including literal ampersands. Opening the macOSmenu leaves the window hidden and records unread. A row opens exactly thatsession/project, acknowledges it normally, and wins over startup navigation.View more returns from Settings, closes search, and expands session navigation. Hidden/closed windows receive fresh groups;diff --git a/packages/shared/src/tray-sessions.test.ts b/packages/shared/src/tray-sessions.test.tsindex 7840d163f..91de187cf 100644--- a/packages/shared/src/tray-sessions.test.ts+++ b/packages/shared/src/tray-sessions.test.ts@@ -187,11 +187,39 @@ describe("parseTraySessionPreferences", () => {});describe("traySessionTitle", () => {- it("keeps one line and truncates to 48 code points including the ellipsis", () => {+ it("keeps one line and leaves a title inside the column budget alone", () => {expect(traySessionTitle(["line", "one"].join("\n"), "fallback")).toBe("line one");- const title = "😀".repeat(49);- const truncated = traySessionTitle(title, "fallback");- expect(Array.from(truncated)).toHaveLength(48);- expect(truncated.endsWith("…")).toBe(true);+ expect(traySessionTitle(" ", "fallback")).toBe("fallback");+ expect(traySessionTitle("a".repeat(32), "fallback")).toBe("a".repeat(32));+ expect(traySessionTitle("中".repeat(16), "fallback")).toBe("中".repeat(16));+ });++ it("cuts a Latin title to 31 columns plus an ellipsis", () => {+ expect(traySessionTitle("a".repeat(40), "fallback")).toBe(`${"a".repeat(31)}…`);+ // A cut that lands on a space never leaves it in front of the ellipsis.+ expect(traySessionTitle(`${"a".repeat(30)} ${"b".repeat(5)}`, "fallback")).toBe(+ `${"a".repeat(30)}…`,+ );+ });++ it("counts a CJK character as two columns, so half as many fit", () => {+ expect(traySessionTitle("中".repeat(20), "fallback")).toBe(`${"中".repeat(15)}…`);+ expect(traySessionTitle(`a${"中".repeat(20)}`, "fallback")).toBe(`a${"中".repeat(15)}…`);+ });++ it("counts an emoji as two columns, with or without the variation selector", () => {+ expect(traySessionTitle("😀".repeat(20), "fallback")).toBe(`${"😀".repeat(15)}…`);+ expect(traySessionTitle("✅".repeat(20), "fallback")).toBe(`${"✅".repeat(15)}…`);+ const sun = "\u2600\ufe0f";+ expect(traySessionTitle(sun.repeat(21), "fallback")).toBe(`${sun.repeat(15)}…`);+ });++ it("counts a combining mark as nothing and drops a joiner left by the cut", () => {+ expect(traySessionTitle("e\u0301".repeat(40), "fallback")).toBe(+ `${"e\u0301".repeat(31)}…`,+ );+ expect(traySessionTitle(`${"a".repeat(29)}\u{1f468}\u200d${"b".repeat(3)}`, "fallback")).toBe(+ `${"a".repeat(29)}\u{1f468}…`,+ );});});diff --git a/packages/shared/src/tray-sessions.ts b/packages/shared/src/tray-sessions.tsindex 0d68ab222..065104460 100644--- a/packages/shared/src/tray-sessions.ts+++ b/packages/shared/src/tray-sessions.ts@@ -12,7 +12,8 @@ import type { AppNotification } from "./types/workspace.js";export const TRAY_SESSION_GROUP_SHARE = 3;/** Rows the menu may show across all groups once unused shares are reclaimed. */export const TRAY_SESSION_TOTAL_LIMIT = 9;-export const TRAY_SESSION_TITLE_LIMIT = 48;+/** Display columns one tray row may use, ellipsis included. */+export const TRAY_SESSION_TITLE_COLUMNS = 32;export const TRAY_SESSION_GROUPS = ["running", "unread", "pinned"] as const;export type TraySessionGroupKind = (typeof TRAY_SESSION_GROUPS)[number];@@ -54,15 +55,60 @@ export function parseTraySessionPreferences(input: unknown): TraySessionPreferen};}+/**+ * East Asian wide and fullwidth code points, plus everything Unicode gives+ * emoji presentation by default, draw at two display columns. Counting them as+ * two keeps a CJK menu row as wide as a Latin one instead of letting one+ * Chinese title fill the whole tray menu.+ */+const WIDE_CODE_POINT =+ /[\u1100-\u115f\u2329-\u232a\u2e80-\u303e\u3041-\u33ff\u3400-\u4dbf\u4e00-\u9fff\ua000-\ua4cf\ua960-\ua97f\uac00-\ud7a3\uf900-\ufaff\ufe10-\ufe19\ufe30-\ufe6f\uff00-\uff60\uffe0-\uffe6\u{1b000}\u{1b001}\u{1f000}-\u{1faff}\u{20000}-\u{3fffd}]|\p{Emoji_Presentation}/u;+/** Joiners, zero-width space, variation selectors, and combining marks draw nothing of their own. */+const ZERO_WIDTH_CODE_POINT = /[\u200b-\u200d\u2060\ufe00-\ufe0f]|\p{Mn}/u;+/** A text-presentation base becomes a two-column emoji once this selector follows it. */+const EMOJI_VARIATION_SELECTOR = "\ufe0f";+/** Joiners and zero-width code points that the cut left with nothing to join. */+const DANGLING_TAIL = /[\u200b-\u200d\u2060]+$/u;++/** Display columns one code point of `characters` occupies in a native menu row. */+function characterColumns(characters: readonly string[], index: number): number {+ const character = characters[index];+ if (ZERO_WIDTH_CODE_POINT.test(character)) return 0;+ if (characters[index + 1] === EMOJI_VARIATION_SELECTOR) return 2;+ return WIDE_CODE_POINT.test(character) ? 2 : 1;+}++function titleColumns(characters: readonly string[]): number {+ let columns = 0;+ for (let index = 0; index < characters.length; index += 1) {+ columns += characterColumns(characters, index);+ }+ return columns;+}++/**+ * One line that never outgrows `TRAY_SESSION_TITLE_COLUMNS`: a longer title is+ * cut to `TRAY_SESSION_TITLE_COLUMNS - 1` columns plus an ellipsis, so Latin,+ * CJK, and emoji rows land at the same menu width.+ */export function traySessionTitle(title: string, fallback: string): string {const singleLine = title.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, " ").replace(/\s+/g, " ").trim();- const characters = Array.from(singleLine || fallback);- return characters.length > TRAY_SESSION_TITLE_LIMIT- ? `${characters.slice(0, TRAY_SESSION_TITLE_LIMIT - 1).join("")}…`- : characters.join("");+ const line = singleLine || fallback;+ const characters = Array.from(line);+ if (titleColumns(characters) <= TRAY_SESSION_TITLE_COLUMNS) return line;+ const budget = TRAY_SESSION_TITLE_COLUMNS - 1;+ let clipped = "";+ let columns = 0;+ for (let index = 0; index < characters.length; index += 1) {+ const next = columns + characterColumns(characters, index);+ if (next > budget) break;+ clipped += characters[index];+ columns = next;+ }+ return `${clipped.replace(DANGLING_TAIL, "").trimEnd()}\u2026`;}/**