Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
feat(chat): rebuild the radial context menu around readable sectors
vastsac33ef2ed66ee
diff --git a/apps/desktop/src/components/RadialMenu.tsx b/apps/desktop/src/components/RadialMenu.tsxindex 34cb09739..2d69b964c 100644--- a/apps/desktop/src/components/RadialMenu.tsx+++ b/apps/desktop/src/components/RadialMenu.tsx@@ -1,13 +1,18 @@/*** The radial menu a right-click opens on the empty transcript background.*- * Four directions, one action each, keyed by the pointer's direction from the- * click point. It is not a replacement for `ContextMenu`: the list stays the- * menu for rows, links, and file references, where the item count varies per- * target. This surface only renders when the user opts in through- * `AppSettings.radialMenu`, and it keeps the same floating-layer contract —- * viewport-fixed portal, measured before reveal, clamped inside the window,- * Escape and outside-press dismissal, and keyboard reachability.+ * Four wedges, one action each, keyed by the pointer's direction from the+ * click point. Every wedge carries its icon and label at rest, so the ring is+ * readable without hovering; the wedge under the pointer or keyboard focus+ * fills, and the hub stays a recessed center the click point sits in. It is+ * not a replacement for `ContextMenu`: the list stays the menu for rows,+ * links, and file references, where the item count varies per target. This+ * surface only renders when the user opts in through `AppSettings.radialMenu`,+ * and it keeps the same floating-layer contract — viewport-fixed portal,+ * measured before reveal, clamped inside the window, Escape and outside-press+ * dismissal, and keyboard reachability. The standard marking gesture works+ * too: a right-press started while the ring is open runs the wedge it is+ * released on, and releasing in the hub dismisses without running.*/import {useCallback,@@ -30,14 +35,16 @@ export type RadialMenuItem = {export type RadialMenuSlot = RadialMenuItem & { disabled?: boolean };/** Ring geometry, in CSS px. The four item slots sit on the ring's mid-line. */-const OUTER_RADIUS = 160;-const INNER_RADIUS = 56;-const ITEM_RADIUS = 108;-const ITEM_SIZE = 80;+const OUTER_RADIUS = 124;+const INNER_RADIUS = 40;+/** Distance from the center to the middle of an item's icon-and-label stack. */+const CONTENT_RADIUS = 85;+const ITEM_WIDTH = 100;+const ITEM_HEIGHT = 56;/** Clockwise from the top; matches `RADIAL_MENU_DIRECTIONS`. */const ITEM_ANGLES = [-90, 0, 90, 180] as const;-const SECTOR_ANGLES = [+const WEDGE_ANGLES = [[-135, -45],[-45, 45],[45, 135],@@ -46,7 +53,7 @@ const SECTOR_ANGLES = [const rad = (degrees: number) => (degrees * Math.PI) / 180;-function sectorPath(startAngle: number, endAngle: number): string {+function wedgePath(startAngle: number, endAngle: number): string {const center = OUTER_RADIUS;const at = (radius: number, angle: number) => [center + radius * Math.cos(rad(angle)),@@ -91,6 +98,13 @@ export function RadialMenu({const itemRefs = useRef<Array<HTMLButtonElement | null>>([]);const [activeIndex, setActiveIndex] = useState<number | null>(null);const [open, setOpen] = useState(false);+ /*+ The marking gesture only counts a right-button release that follows a+ right-button press seen while the ring is open. The press that opened the+ ring precedes the mount, so its trailing release (macOS fires+ `contextmenu` on press-down) never runs an action by itself.+ */+ const rightPressedRef = useRef(false);const firstEnabledIndex = items.findIndex((item) => !item.disabled);@@ -139,8 +153,28 @@ export function RadialMenu({event.stopPropagation();onClose();};+ const resolveAtPoint = (event: PointerEvent): number | null => {+ const rect = root?.getBoundingClientRect();+ if (!rect) return null;+ return slotAt(+ event.clientX - rect.left - OUTER_RADIUS,+ event.clientY - rect.top - OUTER_RADIUS,+ );+ };+ const onPointerDown = (event: PointerEvent) => {+ if (event.button === 2) rightPressedRef.current = true;+ };+ const onPointerUp = (event: PointerEvent) => {+ if (event.button !== 2 || !rightPressedRef.current) return;+ rightPressedRef.current = false;+ // A release on a wedge runs it; a release in the hub or the margin+ // dismisses without running anything.+ select(resolveAtPoint(event));+ };window.addEventListener("pointerdown", onOutside, true);window.addEventListener("contextmenu", onOutside, true);+ window.addEventListener("pointerdown", onPointerDown, true);+ window.addEventListener("pointerup", onPointerUp, true);window.addEventListener("scroll", onClose, true);window.addEventListener("resize", onClose);window.addEventListener("blur", onClose);@@ -148,12 +182,14 @@ export function RadialMenu({return () => {window.removeEventListener("pointerdown", onOutside, true);window.removeEventListener("contextmenu", onOutside, true);+ window.removeEventListener("pointerdown", onPointerDown, true);+ window.removeEventListener("pointerup", onPointerUp, true);window.removeEventListener("scroll", onClose, true);window.removeEventListener("resize", onClose);window.removeEventListener("blur", onClose);window.removeEventListener("keydown", onKeyDown, true);};- }, [onClose]);+ }, [onClose, select]);// Focus the first actionable item; when every slot is empty, focus the menu// itself so keyboard dismissal remains available.@@ -257,15 +293,15 @@ export function RadialMenu({}}><svg- className="radial-menu-ring"+ className="radial-menu-plate"viewBox={`0 0 ${width} ${width}`}aria-hidden="true">- {SECTOR_ANGLES.map(([start, end], index) => (+ {WEDGE_ANGLES.map(([start, end], index) => (<pathkey={start}- className={`radial-menu-sector${activeIndex === index ? " is-active" : ""}`}- d={sectorPath(start, end)}+ className={`radial-menu-wedge${activeIndex === index ? " is-active" : ""}`}+ d={wedgePath(start, end)}/>))}<circle@@ -278,21 +314,13 @@ export function RadialMenu({className="radial-menu-dot"cx={OUTER_RADIUS}cy={OUTER_RADIUS}- r={4}+ r={2.5}/></svg>- {/*- The sectors carry icons only: the four labels together are wider than- a sector, and truncated menu labels are worse than none. The active- action's full label sits in the hub under the pointer.- */}- <div className="radial-menu-hub-label" aria-hidden="true">- {activeIndex === null ? "" : items[activeIndex]?.label}- </div>{items.map((item, index) => {const angle = rad(ITEM_ANGLES[index] ?? -90);- const x = OUTER_RADIUS + Math.cos(angle) * ITEM_RADIUS;- const y = OUTER_RADIUS + Math.sin(angle) * ITEM_RADIUS;+ const x = OUTER_RADIUS + Math.cos(angle) * CONTENT_RADIUS;+ const y = OUTER_RADIUS + Math.sin(angle) * CONTENT_RADIUS;return (<buttonkey={item.id}@@ -308,8 +336,8 @@ export function RadialMenu({style={{left: `${x}px`,top: `${y}px`,- width: `${ITEM_SIZE}px`,- minHeight: `${ITEM_SIZE}px`,+ width: `${ITEM_WIDTH}px`,+ height: `${ITEM_HEIGHT}px`,}}onClick={(event) => {event.stopPropagation();@@ -321,6 +349,7 @@ export function RadialMenu({<span className="radial-menu-icon" aria-hidden>{item.icon}</span>+ <span className="radial-menu-label">{item.label}</span></button>);})}diff --git a/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx b/apps/desktop/src/features/chat/transcript/ChatTranscript.tsxindex c901a5290..73b1ac57b 100644--- a/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx+++ b/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx@@ -310,7 +310,7 @@ function TranscriptBody({return {id,label,- icon: <IconCopy size={18} />,+ icon: <IconCopy size={16} />,disabled: !copyable,onSelect: () => void copyConversation(),};@@ -318,7 +318,7 @@ function TranscriptBody({return {id,label,- icon: <IconTextSelect size={18} />,+ icon: <IconTextSelect size={16} />,onSelect: () => selectText(contentRef.current),};case "copy-last-answer": {@@ -326,7 +326,7 @@ function TranscriptBody({return {id,label,- icon: <IconChat size={18} />,+ icon: <IconChat size={16} />,disabled: !lastAnswer,onSelect: () => void copyText(lastAnswer),};@@ -335,14 +335,14 @@ function TranscriptBody({return {id,label,- icon: <IconArrowUp size={18} />,+ icon: <IconArrowUp size={16} />,onSelect: () => scrollRef.current?.scrollTo({ top: 0 }),};case "scroll-bottom":return {id,label,- icon: <IconArrowDown size={18} />,+ icon: <IconArrowDown size={16} />,onSelect: () => {onReturnToLatest?.();jumpToLatest();@@ -352,7 +352,7 @@ function TranscriptBody({return {id,label,- icon: <IconBrowser size={18} />,+ icon: <IconBrowser size={16} />,disabled: !sessionId || isRemoteSession(sessionSummary),onSelect: () => openWorkPanelTab(browserPluginTab()),};@@ -364,7 +364,7 @@ function TranscriptBody({label: workPanelOpen? t("chat.radialMenuCloseWorkPanel"): label,- icon: <IconPanel size={18} />,+ icon: <IconPanel size={16} />,disabled: !sessionId || isRemoteSession(sessionSummary),onSelect: () => (workPanelOpen ? collapseWorkPanel() : openWorkPanel()),};@@ -373,7 +373,7 @@ function TranscriptBody({return {id,label,- icon: <IconFolder size={18} />,+ icon: <IconFolder size={16} />,disabled: !path || isRemoteSession(sessionSummary),onSelect: () => {if (!path) return;@@ -387,7 +387,7 @@ function TranscriptBody({};}default:- return { id, label, icon: <IconChat size={18} />, disabled: true, onSelect: () => {} };+ return { id, label, icon: <IconChat size={16} />, disabled: true, onSelect: () => {} };}});};diff --git a/apps/desktop/src/styles/ui-kit.css b/apps/desktop/src/styles/ui-kit.cssindex 09820802b..4468a5978 100644--- a/apps/desktop/src/styles/ui-kit.css+++ b/apps/desktop/src/styles/ui-kit.css@@ -355,20 +355,28 @@}/* Radial context menu on the empty transcript background (opt-in through- Settings → AI → Defaults). It joins the same floating-layer family as+ Settings → General). It joins the same floating-layer family as`.context-menu`: viewport-fixed, measured before reveal, clamped inside the- window. The four sectors are one SVG plate; the buttons on top carry the- icons, labels, focus, and hit targets. */+ window, disc surface with a hairline edge and the composer shadow. The SVG+ plate draws the four wedges, their hairline separators, the recessed hub,+ and the active fill; the buttons on top carry icon, label, focus, and hit+ target, so the ring reads without hovering and one highlight covers both+ layers. */.radial-menu {position: fixed;z-index: 60; /* body-level menu layer, above pane stacking */+ border: 1px solid var(--ds-border-subtle);+ border-radius: var(--radius-round);+ background: var(--ds-bg-elevated-opaque, var(--ds-bg-primary));+ box-shadow: var(--ds-shadow-composer);+ color: var(--ds-text-primary);opacity: 0;pointer-events: none;visibility: hidden;- transform: scale(0.94);+ transform: scale(0.9);transition:opacity var(--motion-duration-fast) var(--motion-ease-out),- transform var(--motion-duration-fast) var(--motion-ease-out);+ transform var(--motion-duration-normal) var(--motion-ease-out);}.radial-menu.is-open {@@ -385,7 +393,7 @@}}-.radial-menu-ring {+.radial-menu-plate {position: absolute;inset: 0;width: 100%;@@ -393,19 +401,19 @@overflow: visible;}-.radial-menu-sector {- fill: var(--ds-bg-elevated-opaque);+.radial-menu-wedge {+ fill: transparent;stroke: var(--ds-border-subtle);stroke-width: 1;transition: fill var(--motion-duration-fast) var(--motion-ease-out);}-.radial-menu-sector.is-active {- fill: var(--ds-bg-hover);+.radial-menu-wedge.is-active {+ fill: var(--ds-bg-active);}.radial-menu-hub {- fill: var(--ds-bg-elevated-opaque);+ fill: var(--ds-bg-inset);stroke: var(--ds-border-subtle);stroke-width: 1;}@@ -420,16 +428,21 @@flex-direction: column;align-items: center;justify-content: center;- gap: 2px;+ gap: 4px;transform: translate(-50%, -50%);- border-radius: var(--radius-lg);padding: 4px;- color: var(--ds-text-primary);+ color: var(--ds-text-secondary);text-align: center;+ cursor: pointer;+ user-select: none;+ transition:+ color var(--motion-duration-fast) var(--motion-ease-out),+ transform var(--motion-duration-fast) var(--motion-ease-out);}.radial-menu-item[data-active="true"] {- background: var(--ds-bg-hover);+ color: var(--ds-text-primary);+ transform: translate(-50%, -50%) scale(1.04);}/* An action the conversation cannot fill keeps its direction visible instead of@@ -443,27 +456,31 @@color: var(--ds-text-faint);}+/* Keyboard focus keeps the wedge fill as its indicator; the default ring would+ draw a rectangle over the wedge. */.radial-menu-item:focus-visible {- outline: 2px solid var(--ds-focus);- outline-offset: 2px;+ outline: none;}.radial-menu-icon {display: inline-flex;color: var(--ds-text-secondary);+ transition: color var(--motion-duration-fast) var(--motion-ease-out);}-.radial-menu-hub-label {- position: absolute;- top: 50%;- left: 50%;- width: 92px;- transform: translate(-50%, -50%);- color: var(--ds-text-secondary);- font-size: var(--text-2xs);+.radial-menu-item[data-active="true"] .radial-menu-icon {+ color: var(--ds-text-primary);+}++.radial-menu-label {+ display: -webkit-box;+ width: 100%;+ -webkit-box-orient: vertical;+ -webkit-line-clamp: 2;+ overflow: hidden;+ overflow-wrap: anywhere;+ font-size: var(--text-xs);line-height: var(--leading-tight);- text-align: center;- pointer-events: none;}/* Shared labeled selections keep native input semantics, not platform paint. */diff --git a/scripts/e2e/radial-menu.tsx b/scripts/e2e/radial-menu.tsxindex 3bae48f7e..d6c8b3326 100644--- a/scripts/e2e/radial-menu.tsx+++ b/scripts/e2e/radial-menu.tsx@@ -12,10 +12,6 @@ const settle = () => {return promise;};-const RING = 320;-const CENTER = 160;-const ITEM_RADIUS = 108;-type ProbeState = {calls: string[];closes: number;@@ -65,11 +61,24 @@ const mount = (disabledLeft = false, disabledUp = false) => {return menu as HTMLElement;};-const pointFor = (menu: HTMLElement, degrees: number) => {+/** Ring center and the mid-line radius where the item stacks sit. */+const geometry = (menu: HTMLElement) => {const rect = menu.getBoundingClientRect();- const x = rect.left + CENTER + Math.cos((degrees * Math.PI) / 180) * ITEM_RADIUS;- const y = rect.top + CENTER + Math.sin((degrees * Math.PI) / 180) * ITEM_RADIUS;- return { x, y };+ return {+ rect,+ centerX: rect.left + rect.width / 2,+ centerY: rect.top + rect.height / 2,+ itemRadius: rect.width * 0.34,+ };+};++const pointFor = (menu: HTMLElement, degrees: number | "hub") => {+ const { centerX, centerY, itemRadius } = geometry(menu);+ if (degrees === "hub") return { x: centerX, y: centerY };+ return {+ x: centerX + Math.cos((degrees * Math.PI) / 180) * itemRadius,+ y: centerY + Math.sin((degrees * Math.PI) / 180) * itemRadius,+ };};const pointerMove = async (menu: HTMLElement, degrees: number) => {@@ -83,11 +92,7 @@ const pointerMove = async (menu: HTMLElement, degrees: number) => {};const clickAt = async (menu: HTMLElement, degrees: number | "hub") => {- const rect = menu.getBoundingClientRect();- const { x, y } =- degrees === "hub"- ? { x: rect.left + CENTER, y: rect.top + CENTER }- : pointFor(menu, degrees);+ const { x, y } = pointFor(menu, degrees);flushSync(() =>menu.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, clientX: x, clientY: y }),@@ -96,24 +101,44 @@ const clickAt = async (menu: HTMLElement, degrees: number | "hub") => {await settle();};+const pressAt = (menu: HTMLElement, degrees: number | "hub") => {+ const { x, y } = pointFor(menu, degrees);+ flushSync(() =>+ menu.dispatchEvent(+ new PointerEvent("pointerdown", { bubbles: true, button: 2, clientX: x, clientY: y }),+ ),+ );+};++const releaseAt = async (menu: HTMLElement, degrees: number | "hub") => {+ const { x, y } = pointFor(menu, degrees);+ flushSync(() =>+ menu.dispatchEvent(+ new PointerEvent("pointerup", { bubbles: true, button: 2, clientX: x, clientY: y }),+ ),+ );+ await settle();+};+Object.assign(globalThis, {radialMenuProbe: async () => {- // 1. Four sectors render with their labels.+ // 1. The four wedges render with their visible labels.let menu = mount();+ check(menu.querySelectorAll(".radial-menu-wedge").length === 4, "expected four wedge paths");const labels = [...menu.querySelectorAll(".radial-menu-item")].map((node) => node.getAttribute("aria-label"));check(labels.join("|") === "Copy conversation|Select text|Jump to latest|Leave empty", `labels: ${labels.join("|")}`);- check(menu.querySelectorAll(".radial-menu-item").length === 4, "expected four item buttons");+ const shown = [...menu.querySelectorAll(".radial-menu-label")].map((node) => node.textContent);+ check(shown.join("|") === "Copy conversation|Select text|Jump to latest|Leave empty", `visible labels: ${shown.join("|")}`);+ check(menu.querySelector(".radial-menu-hub-label") === null, "the retired hub label is still rendered");- // 2. The sector under the pointer highlights.+ // 2. The wedge under the pointer highlights.await pointerMove(menu, 0);- check(menu.querySelector(".radial-menu-sector.is-active") !== null, "no sector highlighted at 0°");- check(menu.querySelectorAll(".radial-menu-sector.is-active").length === 1, "more than one sector highlighted");- check(- menu.querySelector(".radial-menu-hub-label")?.textContent === "Select text",- `hub label read ${JSON.stringify(menu.querySelector(".radial-menu-hub-label")?.textContent)}`,- );+ check(menu.querySelector(".radial-menu-wedge.is-active") !== null, "no wedge highlighted at 0°");+ check(menu.querySelectorAll(".radial-menu-wedge.is-active").length === 1, "more than one wedge highlighted");+ const active = menu.querySelector(".radial-menu-item[data-active='true']");+ check(active?.getAttribute("aria-label") === "Select text", `active item read ${active?.getAttribute("aria-label")}`);- // 3. Clicking the sector runs it and closes the ring.+ // 3. Clicking the wedge runs it and closes the ring.await clickAt(menu, 0);check(state.calls.join("|") === "right", `click ran ${state.calls.join("|")}`);check(document.getElementById("ring-closed") !== null, "ring stayed mounted after running an item");@@ -129,9 +154,9 @@ Object.assign(globalThis, {const closesBefore = state.closes;menu = mount(true);await clickAt(menu, 180);- check(state.disabledCalls.length === 0, "disabled sector ran its action");- check(state.closes === closesBefore, "disabled sector closed the ring");- check(document.querySelector(".radial-menu") !== null, "disabled sector removed the ring");+ check(state.disabledCalls.length === 0, "disabled wedge ran its action");+ check(state.closes === closesBefore, "disabled wedge closed the ring");+ check(document.querySelector(".radial-menu") !== null, "disabled wedge removed the ring");// 6. Arrow keys move the highlight and Enter activates the focused slot.const buttons = [...menu.querySelectorAll<HTMLButtonElement>(".radial-menu-item")];@@ -162,15 +187,36 @@ Object.assign(globalThis, {await settle();check(state.calls.at(-1) === "down", `keyboard action ran ${state.calls.at(-1)}`);- // 8. Escape closes the ring.+ // 8. Marking gesture: a right press seen while open runs its release wedge.+ menu = mount();+ pressAt(menu, 0);+ await releaseAt(menu, 0);+ check(state.calls.at(-1) === "right", `marking release ran ${state.calls.at(-1)}`);+ check(document.getElementById("ring-closed") !== null, "marking release did not close the ring");++ // 9. Releasing in the hub dismisses without running anything.+ const markingBefore = state.calls.length;menu = mount();+ pressAt(menu, "hub");+ await releaseAt(menu, "hub");+ check(state.calls.length === markingBefore, "hub release ran an action");+ check(document.getElementById("ring-closed") !== null, "hub release did not close the ring");++ // 10. The opening right-click's trailing release is inert: it has no+ // matching press seen while the ring was open.+ menu = mount();+ await releaseAt(menu, 0);+ check(state.calls.length === markingBefore, "unpaired release ran an action");+ check(document.querySelector(".radial-menu") !== null, "unpaired release closed the ring");++ // 11. Escape closes the ring.flushSync(() =>window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true })),);await settle();check(document.querySelector(".radial-menu") === null, "Escape did not close the ring");- // 8. The ring is clamped inside a small viewport.+ // 12. The ring is clamped inside a small viewport.document.body.replaceChildren();const host = document.createElement("div");document.body.append(host);@@ -188,8 +234,9 @@ Object.assign(globalThis, {const edge = document.querySelector<HTMLElement>(".radial-menu");check(!!edge, "edge ring did not mount");const rect = (edge as HTMLElement).getBoundingClientRect();+ const declaredWidth = Number.parseFloat((edge as HTMLElement).style.width);check(- rect.right <= window.innerWidth && rect.bottom <= window.innerHeight && rect.width === RING,+ rect.right <= window.innerWidth && rect.bottom <= window.innerHeight && rect.width === declaredWidth,`edge ring escaped the viewport: ${JSON.stringify({ right: rect.right, bottom: rect.bottom, width: rect.width })}`,);