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(transcript): finish disclosure follow-up
vastsa655626c98ec2
diff --git a/apps/desktop/src/components/workpanel/WorkPanel.tsx b/apps/desktop/src/components/workpanel/WorkPanel.tsxindex 882cfc1f4..7f328c6e7 100644--- a/apps/desktop/src/components/workpanel/WorkPanel.tsx+++ b/apps/desktop/src/components/workpanel/WorkPanel.tsx@@ -275,6 +275,17 @@ export function WorkPanel({},[closeTab, tabs],);+ const closeSubagentPanelAndFocus = useCallback(() => {+ const delegationId = subagentPanel?.delegationId;+ onCloseSubagentPanel?.();+ if (!delegationId) return;+ requestAnimationFrame(() => {+ const trigger = [...document.querySelectorAll<HTMLElement>("[data-subagent-trigger]")].find(+ (candidate) => candidate.dataset.subagentTrigger === delegationId,+ );+ trigger?.focus({ preventScroll: true });+ });+ }, [onCloseSubagentPanel, subagentPanel?.delegationId]);const onTabKeyDown = useCallback((event: ReactKeyboardEvent<HTMLButtonElement>, tabId: string) => {@@ -564,7 +575,7 @@ export function WorkPanel({className="work-panel-subagent-back"tooltip={t("panel.subagentClose")}ariaLabel={t("panel.subagentClose")}- onClick={onCloseSubagentPanel}+ onClick={closeSubagentPanelAndFocus}><IconChevronLeft size={15} /></TooltipButton>diff --git a/apps/desktop/src/features/chat/transcript/ToolRow.tsx b/apps/desktop/src/features/chat/transcript/ToolRow.tsxindex 91b595023..3d621a6e9 100644--- a/apps/desktop/src/features/chat/transcript/ToolRow.tsx+++ b/apps/desktop/src/features/chat/transcript/ToolRow.tsx@@ -344,8 +344,9 @@ export const ToolRow = memo(function ToolRow({{variant === "topology" ? (<buttonclassName="subagent-topology-node-header"+ data-subagent-trigger={panelSelectionId}aria-expanded={panelOpen}- aria-controls={hasDetails ? "subagent-panel" : undefined}+ aria-controls={panelOpen ? "subagent-panel" : undefined}disabled={!hasDetails}title={[agentName || rawName, modelLabel, summary].filter(Boolean).join(" · ")}onClick={() => {diff --git a/apps/desktop/src/lib/subagent-topology.ts b/apps/desktop/src/lib/subagent-topology.tsindex 0cd653c34..046c38868 100644--- a/apps/desktop/src/lib/subagent-topology.ts+++ b/apps/desktop/src/lib/subagent-topology.ts@@ -47,6 +47,7 @@ const DELEGATION_STATUSES = new Set<SubagentOutcome>(["aborted","failed","stopped",+ "denied",]);function asDelegationStatus(value: unknown): SubagentOutcome | null {diff --git a/apps/desktop/test/interaction-performance.test.mjs b/apps/desktop/test/interaction-performance.test.mjsindex a726b785c..11f8090d5 100644--- a/apps/desktop/test/interaction-performance.test.mjs+++ b/apps/desktop/test/interaction-performance.test.mjs@@ -100,10 +100,8 @@ test("expanded live tool output stays local to the changed row", () => {assert.match(transcript, /function toolRowPropsEqual\(/);assert.match(transcript, /if \(previous.variant !== "topology"\) return true;/);assert.match(transcript, /const autoOpenLatest =\s*!compact && isLast && itemIndex === items.length - 1/);- assert.match(- transcript,- /const blocks =\s*variant !== "topology" && open && hasDetails\s*\?\s*buildToolPresentation\(/,- );+ assert.match(transcript, /if \(variant !== "topology" && open && hasDetails && disclosure\.parentVisible/);+ assert.match(transcript, /const blocks = variant !== "topology" && open && hasDetails \? presentation\.current\?\.blocks : null/);});test("stream event bursts are coalesced until a paint or terminal event", () => {@@ -120,8 +118,8 @@ test("tool errors stay local to their rows instead of failing the activity groupassert.doesNotMatch(toolRow, /tool-activity-group[\s\S]*?failed/);// Failures remain visible in the row header; automatic open is last-tool// ownership, not error ownership.- assert.match(toolRow, /const disclosure = useAutomaticDisclosure\(\s*autoOpen && !failed && status !== "denied",\s*\)/);- assert.match(`${toolRow}\n${transcriptShared}`, /if \(userInteractedRef.current\) return/);+ assert.match(toolRow, /const disclosure = useAutomaticDisclosure\(\s*autoOpen && !failed && status !== "denied",\s*revealRequest,\s*disclosureKey\("tool"/);+ assert.match(transcript, /bodyEvents: \{ onPointerDownCapture: claim, onFocusCapture: claim \}/);assert.match(toolRow, /status === "error"\s*\? t\("chat.toolFailed"\)/);});diff --git a/apps/desktop/test/session-message-presentation.test.mjs b/apps/desktop/test/session-message-presentation.test.mjsindex a16da2936..935a4311c 100644--- a/apps/desktop/test/session-message-presentation.test.mjs+++ b/apps/desktop/test/session-message-presentation.test.mjs@@ -43,6 +43,9 @@ function loadComponent(name, extras = {}) {"../../../components/icons": new Proxy({}, { get: () => Icon }),"../../../components/ui": { TooltipButton },"./shared": shared,+ "../../../lib/transcript-search-context": {+ transcriptItemKey: (messageId, kind, roundId = "") => JSON.stringify([messageId, kind, roundId]),+ },"./menu-items": { userMessageMenuItems: () => [] },"./TranscriptMenu": {useTranscriptMenu: () => () => {},diff --git a/apps/desktop/test/subagent-panel.test.mjs b/apps/desktop/test/subagent-panel.test.mjsindex dd8878aa5..59c885943 100644--- a/apps/desktop/test/subagent-panel.test.mjs+++ b/apps/desktop/test/subagent-panel.test.mjs@@ -36,7 +36,7 @@ test("a topology node toggles a session-scoped side-panel selection", () => {assert.match(transcriptSource, /const toggleSubagentPanel = useAppStore\(\(s\) => s\.toggleSubagentPanel\)/);assert.match(transcriptSource, /const panelSelectionId =/);assert.match(transcriptSource, /toggleSubagentPanel\(panelSelectionId\)/);- assert.match(transcriptSource, /aria-controls=\{hasDetails \? "subagent-panel" : undefined\}/);+ assert.match(transcriptSource, /aria-controls=\{panelOpen \? "subagent-panel" : undefined\}/);assert.match(transcriptSource, /variant !== "topology" && open/);assert.match(transcriptSource, /variant !== "topology" && open && hasDetails/);assert.match(storeSource, /subagentPanel: SubagentPanelSelection \| null/);diff --git a/apps/desktop/test/subagent-topology.test.mjs b/apps/desktop/test/subagent-topology.test.mjsindex 1bb4fa825..869954adb 100644--- a/apps/desktop/test/subagent-topology.test.mjs+++ b/apps/desktop/test/subagent-topology.test.mjs@@ -202,6 +202,27 @@ test("reads settled delegation status from a persisted TaskWait result", () => {"completed",);});+test("preserves denied lifecycle outcomes", () => {+ const statuses = collectDelegationStatuses([+ lifecycle("TaskWait", {+ delegations: [+ { delegationId: "denied", agent: "reviewer", status: "denied" },+ ],+ }),+ ]);+ assert.equal(statuses.get("denied"), "denied");+ assert.equal(+ delegationRosterOutcome(delegationRoster({+ toolName: "TaskWait",+ toolResult: {+ details: {+ delegations: [{ delegationId: "denied", agent: "reviewer", status: "denied" }],+ },+ },+ })),+ "denied",+ );+});test("reads stopped status from TaskStop, including a running snapshot", () => {const statuses = collectDelegationStatuses([diff --git a/apps/desktop/test/subagent-transcript.test.mjs b/apps/desktop/test/subagent-transcript.test.mjsindex 30cba2510..fdb08a085 100644--- a/apps/desktop/test/subagent-transcript.test.mjs+++ b/apps/desktop/test/subagent-transcript.test.mjs@@ -258,8 +258,9 @@ test("every Task row renders as one accessible delegation topology", () => {assert.match(transcriptSource, /role="list"/);assert.match(transcriptSource, /variant="topology"/);assert.match(transcriptSource, /className="subagent-topology-node-header"/);+ assert.match(transcriptSource, /data-subagent-trigger=\{panelSelectionId\}/);+ assert.match(transcriptSource, /aria-controls=\{panelOpen \? "subagent-panel" : undefined\}/);assert.match(transcriptSource, /aria-expanded=\{panelOpen\}/);- assert.match(transcriptSource, /aria-controls=\{hasDetails \? "subagent-panel" : undefined\}/);const topologyNode = transcriptSource.slice(transcriptSource.indexOf('className="subagent-topology-node-header"'),transcriptSource.indexOf(diff --git a/apps/desktop/test/thinking-ui.test.mjs b/apps/desktop/test/thinking-ui.test.mjsindex 90b918234..fb819853a 100644--- a/apps/desktop/test/thinking-ui.test.mjs+++ b/apps/desktop/test/thinking-ui.test.mjs@@ -18,6 +18,7 @@ const composerModelPickerSource = await readComposerModule("ComposerModelPicker.const transcriptSource = await readTranscriptSource();const transcriptSharedSource = await readTranscriptModule("shared.tsx");const transcriptToolRowSource = await readTranscriptModule("ToolRow.tsx");+const transcriptDisclosureSource = await readTranscriptModule("disclosure.tsx");const transcriptActivityGroupSource = await readTranscriptModule("ActivityGroup.tsx");const appSource = await readFile(new URL("../src/components/ChatSurface.tsx", import.meta.url),@@ -232,12 +233,11 @@ test("expanded assistant activity rails collapse their disclosures", () => {});test("detailed mode opens the last tool while compact keeps payloads collapsed", () => {- assert.match(transcriptSource, /function useAutomaticDisclosure\(automaticOpen: boolean, revealRequest\?: number\)/);- assert.match(transcriptSource, /const userInteractedRef = useRef\(false\)/);- assert.match(transcriptSource, /useLayoutEffect\(\(\) => \{/);- assert.match(transcriptSource, /if \(userInteractedRef.current\) return/);- assert.match(transcriptSource, /const \{ open, toggle: toggleDisclosure, collapse: collapseDisclosure \}/);- assert.match(transcriptSource, /useAutomaticDisclosure\(live, revealRequest\)/);+ assert.match(transcriptDisclosureSource, /export function useAutomaticDisclosure\(/);+ assert.match(transcriptDisclosureSource, /revealRequest\?: number/);+ assert.match(transcriptDisclosureSource, /const currentOpen = useRef\(open\)/);+ assert.match(transcriptDisclosureSource, /const setManualOpen = useCallback/);+ assert.match(transcriptSource, /useAutomaticDisclosure\(\s*hasSubagentTopology \? live : visibleItems\.length <= 1/);assert.match(transcriptSource,/<ThinkingRow[\s\S]*?autoOpen=\{live && itemIndex === items.length - 1\}/,@@ -247,7 +247,7 @@ test("detailed mode opens the last tool while compact keeps payloads collapsed",/const autoOpenLatest =\s*!compact && isLast && itemIndex === items.length - 1/,);assert.match(transcriptSource, /<ToolRow[\s\S]*?autoOpen=\{autoOpenLatest\}/);- assert.match(transcriptToolRowSource, /const disclosure = useAutomaticDisclosure\(\s*autoOpen && !failed && status !== "denied",\s*\)/);+ assert.match(transcriptToolRowSource, /const disclosure = useAutomaticDisclosure\(\s*autoOpen && !failed && status !== "denied",\s*revealRequest/);assert.match(transcriptSource, /onClick=\{toggleDisclosure\}/);assert.match(transcriptSource, /onCollapse=\{collapseDisclosure\}/);assert.match(transcriptSource, /onUserInteraction=\{claimDisclosure\}/);diff --git a/apps/desktop/test/transcript-disclosure-reading.test.mjs b/apps/desktop/test/transcript-disclosure-reading.test.mjsindex fdeeec38a..a969a1958 100644--- a/apps/desktop/test/transcript-disclosure-reading.test.mjs+++ b/apps/desktop/test/transcript-disclosure-reading.test.mjs@@ -5,8 +5,9 @@ import { readTranscriptSource } from "./helpers/source-contracts.mjs";const read = (path) => readFile(new URL(path, import.meta.url), "utf8");-const [transcript, followScroll, anchorControl, scrollInput] = await Promise.all([+const [transcript, disclosure, followScroll, anchorControl, scrollInput] = await Promise.all([readTranscriptSource(),+ read("../src/features/chat/transcript/disclosure.tsx"),read("../src/hooks/use-follow-scroll.ts"),read("../src/hooks/use-disclosure-anchor.ts"),read("../src/lib/scroll-input.ts"),@@ -14,31 +15,24 @@ const [transcript, followScroll, anchorControl, scrollInput] = await Promise.alltest("a manual disclosure hands over its title before the state changes", () => {// The scroller has to measure the title while the layout still matches what- // the reader clicked, so the notification comes before `setOpen` (#324).- assert.match(- transcript,- /const notifyAnchor = useDisclosureAnchorNotifier\(\);\s*const titleRef = useRef<HTMLButtonElement \| null>\(null\);/,- );- assert.match(- transcript,- /const toggle = useCallback\(\(\) => \{\s*claim\(\);\s*notifyAnchor\?\.\(titleRef\.current\);\s*setOpen\(\(value\) => !value\);/,- );- assert.match(- transcript,- /const collapse = useCallback\(\(\) => \{\s*claim\(\);\s*notifyAnchor\?\.\(titleRef\.current\);\s*setOpen\(false\);/,- );- assert.match(transcript, /return \{ open, toggle, collapse, claim, titleRef \};/);+ // the reader clicked, so the notification comes before the choice changes (#324).+ assert.match(disclosure, /const notifyAnchor = useDisclosureAnchorNotifier\(\);/);+ assert.match(disclosure, /const setManualOpen = useCallback\(\(next: boolean\) => \{/);+ assert.match(disclosure, /notifyAnchor\?\.\(titleRef\.current\);/);+ assert.match(disclosure, /choices\.set\(key, \{ \.\.\.choices\.get\(key\), open: next \}\)/);+ assert.match(disclosure, /const toggle = useCallback\(\(\) => setManualOpen\(!currentOpen\.current\)/);+ assert.match(disclosure, /const collapse = useCallback\(\(\) => setManualOpen\(false\)/);});-test("the automatic open/close never claims a reading position", () => {- // Only a user click holds the viewport. The running/settled transition keeps- // going through `setOpen` directly, so the automatic rules are unchanged.- const automatic = transcript.match(- /useLayoutEffect\(\(\) => \{\s*if \(userInteractedRef\.current\) return;([\s\S]*?)\n \}, \[automaticOpen\]\);/,- )?.[1];- assert.ok(automatic, "the automatic disclosure effect is missing");- assert.doesNotMatch(automatic, /notifyAnchor/);- assert.match(automatic, /setOpen\(automaticOpen\);/);+test("automatic disclosure does not claim a reading position", () => {+ // Automatic reveal/collapse may claim the parent hierarchy, but never calls+ // the scroll anchor notifier reserved for direct user interaction.+ assert.match(disclosure, /if \(previousOpen\.current && !open && !choice && ownsReadingPosition/);+ const revealEffect = disclosure.match(+ /useLayoutEffect\(\(\) => \{\s*if \(revealRequest === undefined[\s\S]*?\n \}, \[choices, key, parent\.claim, revealRequest\]\);/,+ )?.[0];+ assert.ok(revealEffect, "the automatic reveal effect is missing");+ assert.doesNotMatch(revealEffect, /notifyAnchor/);});test("every manual title hands over the element the reader clicked", () => {diff --git a/apps/desktop/test/transcript-style.test.mjs b/apps/desktop/test/transcript-style.test.mjsindex 373adec31..4d1c9b91e 100644--- a/apps/desktop/test/transcript-style.test.mjs+++ b/apps/desktop/test/transcript-style.test.mjs@@ -56,8 +56,9 @@ test("tool rows render structured blocks instead of dumping JSON", async () => {assert.doesNotMatch(transcriptSource, /getToolSections|hasToolSections/);assert.doesNotMatch(permissionSource, /JSON\.stringify|formatToolValue/);assert.match(transcriptSource, /buildToolPresentation\(message, \{\n\s+hideSummaryArg: true,/);- // Blocks stay behind the open guard so streaming ticks stay cheap.- assert.match(transcriptSource, /open && hasDetails\s*\?\s*buildToolPresentation/);+ // Formatting remains lazy and the cached blocks are read only while visible.+ assert.match(transcriptSource, /if \(variant !== "topology" && open && hasDetails && disclosure\.parentVisible/);+ assert.match(transcriptSource, /const blocks = variant !== "topology" && open && hasDetails \? presentation\.current\?\.blocks : null/);assert.match(transcriptSource, /<ToolChips chips=\{chips\} \/>/);assert.match(transcriptSource, /<ToolDetailBlocks blocks=\{blocks\} plain=\{runHead\} \/>/);assert.match(permissionSource, /<ToolDetailBlocks blocks=\{argBlocks\} \/>/);diff --git a/apps/desktop/test/turn-process.test.mjs b/apps/desktop/test/turn-process.test.mjsindex a99676cb4..8108cc752 100644--- a/apps/desktop/test/turn-process.test.mjs+++ b/apps/desktop/test/turn-process.test.mjs@@ -99,12 +99,12 @@ test("missing and unknown display settings retain detailed mode", () => {assert.equal(resolveThinkingDisplayMode("compact"), "compact");});-test("only compact groups a turn into a process; compact auto-opens active failures", () => {- assert.equal(shouldGroupTurnProcess("detailed"), false);+test("both display modes group a turn and only compact auto-opens active failures", () => {+ assert.equal(shouldGroupTurnProcess("detailed"), true);assert.equal(shouldGroupTurnProcess("compact"), true);- assert.equal(shouldAutoOpenTurnProcess("detailed", false, false), false);- assert.equal(shouldAutoOpenTurnProcess("detailed", true, false), false);- assert.equal(shouldAutoOpenTurnProcess("detailed", true, true), false);+ assert.equal(shouldAutoOpenTurnProcess("detailed", false, false), true);+ assert.equal(shouldAutoOpenTurnProcess("detailed", true, false), true);+ assert.equal(shouldAutoOpenTurnProcess("detailed", true, true), true);assert.equal(shouldAutoOpenTurnProcess("compact", false, false), false);assert.equal(shouldAutoOpenTurnProcess("compact", true, false), false);assert.equal(shouldAutoOpenTurnProcess("compact", true, true), true);diff --git a/apps/desktop/test/work-panel.test.mjs b/apps/desktop/test/work-panel.test.mjsindex d240795b8..d814524a9 100644--- a/apps/desktop/test/work-panel.test.mjs+++ b/apps/desktop/test/work-panel.test.mjs@@ -28,6 +28,13 @@ const panelSource = await readFile(const transcriptSource = await readTranscriptSource();const storeSource = await readStoreSource();const globalStyles = await loadStyles();+test("closing a subagent panel restores focus to its transcript trigger", () => {+ assert.match(panelSource, /const closeSubagentPanelAndFocus = useCallback/);+ assert.match(panelSource, /data-subagent-trigger/);+ assert.match(panelSource, /candidate\.dataset\.subagentTrigger === delegationId/);+ assert.match(panelSource, /trigger\?\.focus\(\{ preventScroll: true \}\)/);+ assert.match(panelSource, /onClick=\{closeSubagentPanelAndFocus\}/);+});test("work panel replaces the context panel overlay", async () => {await assert.rejects(