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(chat): honor line refs in host file view
vastsad8ac99d0b855
diff --git a/apps/desktop/src/components/workpanel/FilesTab.tsx b/apps/desktop/src/components/workpanel/FilesTab.tsxindex f10f71b73..200adfcbc 100644--- a/apps/desktop/src/components/workpanel/FilesTab.tsx+++ b/apps/desktop/src/components/workpanel/FilesTab.tsx@@ -126,7 +126,7 @@ function HighlightedText({ path, content }: { path: string; content: string }) {<pre className="file-viewer-code">{tokens? tokens.tokens.map((row, i) => (- <div className="file-viewer-line" key={i}>+ <div className="file-viewer-line" data-line={i + 1} key={i}>{row.length === 0? "\n": row.map((token, j) => (@@ -137,7 +137,7 @@ function HighlightedText({ path, content }: { path: string; content: string }) {</div>)): visible.split("\n").map((line, i) => (- <div className="file-viewer-line" key={i}>+ <div className="file-viewer-line" data-line={i + 1} key={i}>{line || "\n"}</div>))}@@ -163,8 +163,10 @@ export function FilesTab() {const [expanded, setExpanded] = useState<Set<string>>(new Set());const [selected, setSelected] = useState<string | null>(null);const [selectedMimeType, setSelectedMimeType] = useState<string | undefined>();+ const [selectedLine, setSelectedLine] = useState<number | undefined>();const [file, setFile] = useState<FsReadResult | null>(null);const [fileError, setFileError] = useState(false);+ const viewerBodyRef = useRef<HTMLDivElement>(null);// Workspace switches reset all browsing state. Guarded so it only fires on// an actual root change: an unconditional [root] effect also runs on the@@ -178,6 +180,7 @@ export function FilesTab() {setExpanded(new Set());setSelected(null);setSelectedMimeType(undefined);+ setSelectedLine(undefined);setFile(null);setFileError(false);}, [root]);@@ -219,14 +222,15 @@ export function FilesTab() {async (rel: string, mimeType?: string, position?: { line?: number; column?: number }) => {setSelected(rel);setSelectedMimeType(mimeType);+ setSelectedLine(position?.line);setFile(null);setFileError(false);try {setFile(await api.fsRead(rel, mimeType));if (position?.line != null) {requestAnimationFrame(() => {- const lineNode = document.querySelector(- `.work-files-preview [data-line="${position.line}"]`,+ const lineNode = viewerBodyRef.current?.querySelector(+ `[data-line="${position.line}"]`,);lineNode?.scrollIntoView({ block: "center" });});@@ -351,6 +355,7 @@ export function FilesTab() {onClick={() => {setSelected(null);setSelectedMimeType(undefined);+ setSelectedLine(undefined);setFile(null);}}>@@ -370,12 +375,15 @@ export function FilesTab() {<IconExternal size={14} /></TooltipButton></div>- <div className="file-viewer-body">+ <div className="file-viewer-body" ref={viewerBodyRef}>{fileError ? (<WorkTabEmpty icon={IconFileText} title={t("panel.files.error")} />) : !file ? (<div className="file-tree-note">{t("panel.files.loading")}</div>- ) : file.kind === "text" && isMarkdownPath(selected) ? (+ ) :+ file.kind === "text" &&+ isMarkdownPath(selected) &&+ selectedLine === undefined ? (<div className="file-viewer-markdown prose-chat"><Markdown source={file.content ?? ""} baseDir={fileDirOf(selected)} /></div>diff --git a/apps/desktop/src/hooks/use-preview-target.ts b/apps/desktop/src/hooks/use-preview-target.tsindex 81a8c4338..47285f514 100644--- a/apps/desktop/src/hooks/use-preview-target.ts+++ b/apps/desktop/src/hooks/use-preview-target.ts@@ -136,10 +136,10 @@ function useResolveChatFileRef() {* Open a file reference the conversation mentioned.** A workspace `.html` page in the primary folder stays with the side browser- * (ADR 0163): it is a page to run, not a file to read. A project file opens in- * the bundled file view when that view is installed and on the host file tab- * otherwise; scratch and attachment files live outside the project and always- * take the host file tab.+ * (ADR 0163): it is a page to run, not a file to read. A plain project file+ * opens in the bundled file view when available; a positioned `path:line`+ * reference uses the host file tab, which can scroll to the requested line.+ * Scratch and attachment files also use the host file tab.*/export function useOpenChatFileRef() {const resolveRef = useResolveChatFileRef();@@ -165,7 +165,9 @@ export function useOpenChatFileRef() {void (async () => {const resolved = await resolveRef(path, baseDir);if (!resolved) return;+ const hasPosition = line !== undefined || column !== undefined;if (+ !hasPosition &&resolved.inProject &&resolved.primary &&resolved.relativePath &&@@ -174,10 +176,12 @@ export function useOpenChatFileRef() {openUrl(resolved.relativePath);return;}- if (resolved.inProject && fileViewAvailable) {- // Thread path:line into the plugin tab so the bundled file view can- // scroll to the line (#681 / #1149 review). Host fallback uses openFile.- openTab(fileManagerPluginTab(resolved.path, { line, column }));+ if (+ resolved.inProject &&+ fileViewAvailable &&+ !hasPosition+ ) {+ openTab(fileManagerPluginTab(resolved.path));return;}openFile(resolved.path, mimeType, { line, column });diff --git a/apps/desktop/src/lib/chat-links.ts b/apps/desktop/src/lib/chat-links.tsindex e3dbf0c1d..5a81f485d 100644--- a/apps/desktop/src/lib/chat-links.ts+++ b/apps/desktop/src/lib/chat-links.ts@@ -225,9 +225,8 @@ export function resolvePreviewTarget(}const file = parseFileRef(trimmed);if (!file) return null;- if (isAbsoluteFilePath(file)) return { kind: "file", path: file };+ if (isAbsoluteFilePath(file)) return { kind: "file", path: file, ...(position ?? {}) };const rel = toWorkspaceRel(file, root, baseDir);- const position = parseFileRefPosition(trimmed);return rel ? { kind: "file", path: rel, ...(position ?? {}) } : null;}diff --git a/apps/desktop/src/lib/work-panel-tabs.ts b/apps/desktop/src/lib/work-panel-tabs.tsindex 3fc3e240a..37b6200f0 100644--- a/apps/desktop/src/lib/work-panel-tabs.ts+++ b/apps/desktop/src/lib/work-panel-tabs.ts@@ -154,19 +154,14 @@ export const FILE_MANAGER_PLUGIN_TAB = {viewId: "manager",} as const;-/** The file view, asked to show one file (optional chat `path:line` position). */-export function fileManagerPluginTab(- location: string,- position?: { line?: number; column?: number },-): WorkPanelTab {+/** The file view, asked to show one file. */+export function fileManagerPluginTab(location: string): WorkPanelTab {return {...pluginWorkPanelTab(FILE_MANAGER_PLUGIN_TAB.pluginId,FILE_MANAGER_PLUGIN_TAB.viewId,),location,- ...(position?.line != null ? { line: position.line } : {}),- ...(position?.column != null ? { column: position.column } : {}),};}diff --git a/apps/desktop/test/chat-links.test.mjs b/apps/desktop/test/chat-links.test.mjsindex ad6ece572..1db6959bd 100644--- a/apps/desktop/test/chat-links.test.mjs+++ b/apps/desktop/test/chat-links.test.mjs@@ -751,4 +751,10 @@ test("resolvePreviewTarget carries line/col on file chips (#681)", () => {line: 42,column: 7,});+ assert.deepEqual(resolvePreviewTarget(`${ROOT}/src/a.ts:42:7`, ROOT), {+ kind: "file",+ path: `${ROOT}/src/a.ts`,+ line: 42,+ column: 7,+ });});diff --git a/apps/desktop/test/transcript-file-chips.test.mjs b/apps/desktop/test/transcript-file-chips.test.mjsindex 75d27bd5f..df44d82f2 100644--- a/apps/desktop/test/transcript-file-chips.test.mjs+++ b/apps/desktop/test/transcript-file-chips.test.mjs@@ -8,13 +8,14 @@ import test from "node:test";const read = (path) => readFile(new URL(path, import.meta.url), "utf8");-const [transcript, styles, hook, api, toolDetails, toolRow] = await Promise.all([+const [transcript, styles, hook, api, toolDetails, toolRow, filesTab] = await Promise.all([readTranscriptSource(),read("../src/styles/chat-links.css"),read("../src/hooks/use-preview-target.ts"),read("../src/lib/api.ts"),read("../src/components/ToolDetails.tsx"),readTranscriptModule("ToolRow.tsx"),+ read("../src/components/workpanel/FilesTab.tsx"),]);test("sent user-message file refs render as composer-like chips", () => {@@ -44,14 +45,21 @@ test("a file chip is routed by where the reference resolved, never optimisticallassert.match(hook, /resolved\.primary &&/);assert.match(hook, /isHtmlFilePath\(resolved\.relativePath\)/);assert.match(hook, /openUrl\(resolved\.relativePath\)/);- // A project file prefers the bundled file view; without that plugin the- // host file tab is the same surface this hook used before.+ // Plain project files prefer the bundled file view. A path:line reference+ // uses the host file tab because the bundled view has no line-navigation API.assert.match(hook, /FILE_MANAGER_PLUGIN_TAB/);- assert.match(hook, /fileManagerPluginTab\(resolved\.path, \{ line, column \}\)/);+ assert.match(hook, /const hasPosition = line !== undefined \|\| column !== undefined/);+ assert.match(hook, /!hasPosition[\s\S]*?isHtmlFilePath/);+ assert.match(hook, /!hasPosition[\s\S]*?fileViewAvailable/);+ assert.match(hook, /fileManagerPluginTab\(resolved\.path\)/);+ assert.match(filesTab, /data-line=\{i \+ 1\}/);+ assert.match(filesTab, /viewerBodyRef\.current\?\.querySelector/);+ assert.match(filesTab, /data-line="\$\{position\.line\}"/);+ assert.match(filesTab, /selectedLine === undefined/);// Session scratch and attachment files live outside the plugin's project- // roots, so completion hands them back as an absolute path.+ // roots, and positioned references need the host viewer's line navigation.assert.match(hook, /inProject: false/);- assert.match(hook, /openFile\(resolved\.path, mimeType\)/);+ assert.match(hook, /openFile\(resolved\.path, mimeType, \{ line, column \}\)/);// The OS handoff is no longer what a chat click does; the channel itself// stays part of the public IPC surface.assert.doesNotMatch(hook, /api\.fsOpen\(/);@@ -65,10 +73,8 @@ test("a tool row and a tool result row open a file where the message body does",// row land in the bundled file view too (ADR 0262). The call this replaces is// the one that let those surfaces pick the destination themselves.assert.match(hook, /const openFileRef = useOpenChatFileRef\(\);/);- assert.match(- hook,- /target\.kind === "file" \? openFileRef\(target\.path\) : openHttpUrl\(target\.url\)/,- );+ assert.match(hook, /target\.kind === "file"[\s\S]*?openFileRef\(target\.path, undefined, undefined, \{/);+ assert.match(hook, /line: target\.line,[\s\S]*?column: target\.column/);assert.doesNotMatch(hook, /openFile\(target\.path\)/);// Both surfaces still call that opener, and neither reaches the host viewer's// store action directly: the tool row summary carries the call's own path,diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.mdindex 20ba98958..e2e59552e 100644--- a/docs/spec/04-ux/08-component-spec.md+++ b/docs/spec/04-ux/08-component-spec.md@@ -1537,6 +1537,10 @@ storage but compose into one assistant turn until the next user message.content's left rule is itself a pointer and keyboard-focusable collapsecontrol.- Hover code block: copy button appears+- Click a transcript file reference with `:line[:column]`: resolve the file+ first, then open it in the host `file:` tab and scroll the requested line into+ view. Plain project-file references still prefer the bundled file view, whose+ open contract does not carry a line position.- Hover or focus a minimap marker: show the localized sender and a boundedplaintext preview; multiple assistant fragments produced within one userturn are combined into one AI-response marker and preview; nearby markersdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 62e544ba0..b6f1d80b4 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -8768,16 +8768,20 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.6. Click a project file path in the conversation. Confirm it opens in thisview on that file — a chat click now prefers the file view over the host`file:` tab.- 7. Disable the File Manager plugin. Confirm the view disappears from the menu+ 7. Click a conversation reference to `src/example.ts:42`. Confirm the host+ `file:` tab opens at line 42 even though the File Manager plugin is enabled.+ 8. Disable the File Manager plugin. Confirm the view disappears from the menuand the panel, and that a clicked conversation file path falls back to thehost `file:<path>` tab under Open resources.- 8. Re-enable it, then restart the app. Confirm the enabled state and the tree+ 9. Re-enable it, then restart the app. Confirm the enabled state and the treereturn, and that the registry did not gain a duplicate row.- **Expected**: A panel surface runs entirely on the public plugin contributionchannel, is user-disableable, cannot be uninstalled, and survives restart. Itshost-mediated actions obey the declared `fs.read` scope, and its own reads andwrites stay inside the jail of the one project folder it is browsing- (ADR 0241, ADR 0263).+ (ADR 0241, ADR 0263). Plain project-file links open in the bundled view; a+ positioned `path:line` reference opens the host file tab and scrolls the+ requested line even while the plugin view is available.- **Specs linked**: `07-plugins/03-plugin-api.md` §3,`07-plugins/13-plugin-permissions-matrix.md` §2,`04-ux/08-component-spec.md` §5, ADR 0104, ADR 0109, ADR 0111,