Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

feat(chat): show a recognised file in its folder from the conversation

vastsa038633ea8b60
diff --git a/apps/desktop/src/components/Markdown.tsx b/apps/desktop/src/components/Markdown.tsx
index e2f5ec04b..4a163c811 100644
--- a/apps/desktop/src/components/Markdown.tsx
+++ b/apps/desktop/src/components/Markdown.tsx
@@ -57,6 +57,10 @@ import { useAppStore } from "../stores/app-store";
import { useReferencedImageDataUrl } from "../lib/use-referenced-image-data-url";
import { absoluteImagePath, remarkLocalImagePaths } from "../lib/markdown-image-paths";
import { useOpenChatFileRef } from "../hooks/use-preview-target";
+import {
+ useChatFileMenuItems,
+ type ChatFileMenuTarget,
+} from "../hooks/use-chat-file-menu";
import {
remarkChatFileLinks,
resolvePreviewTarget,
@@ -407,6 +411,22 @@ const MarkdownBlockContext = createContext({
const MarkdownBaseDirContext = createContext("");
+/**
+ * File references inside one rendered markdown tree share a single menu.
+ *
+ * A chip, a link and a local image all name files the same way and offer the
+ * same items (`useChatFileMenuItems`), so the tree owns one surface instead of
+ * one per reference. The default is `null` for a tree rendered outside
+ * `Markdown`; a reference there keeps the platform's own menu rather than
+ * offering an action that could not run.
+ */
+const MarkdownFileMenuContext = createContext<OpenMarkdownFileMenu | null>(null);
+
+type OpenMarkdownFileMenu = (
+ event: React.MouseEvent<HTMLElement>,
+ target: ChatFileMenuTarget,
+) => void;
+
function extractCode(children: ReactNode): { code: string; lang: string } | null {
const element = Array.isArray(children)
? children.find((child) => isValidElement(child))
@@ -464,6 +484,7 @@ function InlineCode({
const root = useAppStore((s) => s.workspace?.path);
const baseDir = useContext(MarkdownBaseDirContext);
const openFileRef = useOpenChatFileRef();
+ const openFileMenu = useContext(MarkdownFileMenuContext);
const text = typeof children === "string" ? children : null;
const target =
text && !className && !text.includes("\n")
@@ -488,6 +509,12 @@ function InlineCode({
? openFileRef(text ?? target.path, baseDir)
: openHttpUrl(target.url)
}
+ onContextMenu={
+ target.kind === "file" && openFileMenu
+ ? (event) =>
+ openFileMenu(event, { path: text ?? target.path, baseDir })
+ : undefined
+ }
>
<code className={className} {...rest}>
{children}
@@ -506,6 +533,7 @@ function Anchor({
const root = useAppStore((s) => s.workspace?.path);
const baseDir = useContext(MarkdownBaseDirContext);
const openFileRef = useOpenChatFileRef();
+ const openFileMenu = useContext(MarkdownFileMenuContext);
const openUrl = useAppStore((s) => s.openUrlInWorkPanel);
const showToast = useAppStore((s) => s.showToast);
@@ -534,10 +562,22 @@ function Anchor({
destinations the app can send it to stay one press away. The surface is the
shared pointer-anchored menu, which measures before it reveals, clamps inside
the viewport, and owns dismissal and arrow-key navigation; only the items are
- link-specific.
+ link-specific. A file link has one destination of its own, and that item is
+ the one the tree's menu already carries.
*/
const onContextMenu = (event: React.MouseEvent<HTMLAnchorElement>) => {
- if (!href || !/^https?:\/\//i.test(href)) return;
+ if (!href) return;
+ if (!/^https?:\/\//i.test(href)) {
+ /*
+ A file link names the same reference a chip does, so it offers the same
+ action on the file's folder. `./` and `../` resolve against the markdown
+ file on screen, which is the base this row already holds.
+ */
+ const rel = toWorkspaceRel(safeDecodeUri(href), root, baseDir);
+ if (!rel || !openFileMenu) return;
+ openFileMenu(event, { path: rel, baseDir });
+ return;
+ }
const target = href;
openContextMenu(event, {
items: [
@@ -619,6 +659,7 @@ function MarkdownImage({
const root = useAppStore((s) => s.workspace?.path);
const baseDir = useContext(MarkdownBaseDirContext);
const openFileRef = useOpenChatFileRef();
+ const openFileMenu = useContext(MarkdownFileMenuContext);
const fileTitle = usePreviewTitle("file");
const urlTitle = usePreviewTitle("url");
const source = typeof src === "string" ? src : "";
@@ -633,6 +674,16 @@ function MarkdownImage({
// Always run the hook before any branch so hook order stays stable when a
// streaming src flips between remote and local. Remote images pass null.
const dataUrl = useReferencedImageDataUrl(isRemote ? null : localRef);
+
+ /*
+ A file the renderer can already show is still a file whose folder the user
+ may want, so a local image carries the same menu its chip fallback does.
+ */
+ const onLocalContextMenu =
+ localRef && openFileMenu
+ ? (event: React.MouseEvent<HTMLElement>) =>
+ openFileMenu(event, { path: localRef, baseDir })
+ : undefined;
if (isRemote) {
return (
<img
@@ -654,6 +705,7 @@ function MarkdownImage({
className="chat-image-local"
title={rel ? fileTitle : source}
onClick={localRef ? () => openFileRef(localRef, baseDir) : undefined}
+ onContextMenu={onLocalContextMenu}
/>
);
}
@@ -665,6 +717,7 @@ function MarkdownImage({
{...sourcePositionProps(rest)}
title={fileTitle}
onClick={() => openFileRef(localRef, baseDir)}
+ onContextMenu={onLocalContextMenu}
>
<IconImage size={14} aria-hidden />
<span>{alt || localRef.split("/").pop()}</span>
@@ -835,6 +888,23 @@ export const Markdown = memo(function Markdown({
baseDir?: string;
}) {
const workspaceRoot = useAppStore((s) => s.workspace?.path);
+
+ /*
+ One menu for every file reference in this tree. Its blocks are memoized and
+ rendered through the same component map, so the surface is asked for by the
+ reference the pointer chose and owned here, where it outlives a block that
+ streaming may replace.
+ */
+ const fileMenuItems = useChatFileMenuItems();
+ const {
+ contextMenu: fileMenu,
+ openContextMenu: openFileMenu,
+ closeContextMenu: closeFileMenu,
+ } = useContextMenu();
+ const openMarkdownFileMenu = useCallback<OpenMarkdownFileMenu>(
+ (event, target) => openFileMenu(event, { items: fileMenuItems(target) }),
+ [fileMenuItems, openFileMenu],
+ );
// Keep normalization length-preserving so source anchors and the bracket
// display plugin still address the original text. Block splitting uses the
// same math grammar as rendering, including unclosed streaming math blocks.
@@ -845,23 +915,26 @@ export const Markdown = memo(function Markdown({
const blocks = useBlocks(normalizedSource);
let sourceOffset = 0;
return (
- <MarkdownBaseDirContext.Provider value={baseDir ?? ""}>
- {blocks.map((raw, i) => {
- const start = sourceOffset;
- sourceOffset = start + raw.length;
- const originalRaw = source.slice(start, start + raw.length);
- return (
- <Block
- key={i}
- raw={raw}
- originalRaw={originalRaw}
- sourceOffset={start}
- renderDiagrams={renderDiagrams}
- workspaceRoot={workspaceRoot}
- baseDir={baseDir}
- />
- );
- })}
- </MarkdownBaseDirContext.Provider>
+ <MarkdownFileMenuContext.Provider value={openMarkdownFileMenu}>
+ <MarkdownBaseDirContext.Provider value={baseDir ?? ""}>
+ {blocks.map((raw, i) => {
+ const start = sourceOffset;
+ sourceOffset = start + raw.length;
+ const originalRaw = source.slice(start, start + raw.length);
+ return (
+ <Block
+ key={i}
+ raw={raw}
+ originalRaw={originalRaw}
+ sourceOffset={start}
+ renderDiagrams={renderDiagrams}
+ workspaceRoot={workspaceRoot}
+ baseDir={baseDir}
+ />
+ );
+ })}
+ </MarkdownBaseDirContext.Provider>
+ <ContextMenu state={fileMenu} onClose={closeFileMenu} />
+ </MarkdownFileMenuContext.Provider>
);
});
diff --git a/apps/desktop/src/components/ToolDetails.tsx b/apps/desktop/src/components/ToolDetails.tsx
index cb713c3d5..605ae9561 100644
--- a/apps/desktop/src/components/ToolDetails.tsx
+++ b/apps/desktop/src/components/ToolDetails.tsx
@@ -4,6 +4,8 @@ import { IconCheck, IconCircleAlert, IconCopy, IconInfo } from "./icons";
import { TooltipButton, cx } from "./ui";
import { toWorkspaceRel } from "../lib/chat-links";
import { useOpenPreviewTarget } from "../hooks/use-preview-target";
+import { useChatFileMenu } from "../hooks/use-chat-file-menu";
+import { ContextMenu } from "./ContextMenu";
import { useAppStore } from "../stores/app-store";
import type { ToolBlock, ToolChip } from "../lib/tool-presentation";
@@ -84,6 +86,7 @@ function FileList({ paths }: { paths: string[] }) {
const { t } = useTranslation();
const root = useAppStore((s) => s.workspace?.path);
const openTarget = useOpenPreviewTarget();
+ const { fileMenu, openFileMenu, closeFileMenu } = useChatFileMenu();
return (
<div className="tool-file-list">
{paths.map((path, index) => {
@@ -102,11 +105,13 @@ function FileList({ paths }: { paths: string[] }) {
key={`${path}-${index}`}
tooltip={t("chat.previewFile")}
onClick={() => openTarget({ kind: "file", path: rel })}
+ onContextMenu={(event) => openFileMenu(event, { path: rel })}
>
{path}
</TooltipButton>
);
})}
+ <ContextMenu state={fileMenu} onClose={closeFileMenu} />
</div>
);
}
@@ -116,6 +121,7 @@ function MatchList({ block }: { block: Extract<ToolBlock, { kind: "matches" }> }
const { t } = useTranslation();
const root = useAppStore((s) => s.workspace?.path);
const openTarget = useOpenPreviewTarget();
+ const { fileMenu, openFileMenu, closeFileMenu } = useChatFileMenu();
return (
<div className="tool-match-list">
{block.groups.map((group, index) => {
@@ -128,6 +134,9 @@ function MatchList({ block }: { block: Extract<ToolBlock, { kind: "matches" }> }
className="tool-match-path is-linked"
tooltip={t("chat.previewFile")}
onClick={() => openTarget({ kind: "file", path: rel })}
+ onContextMenu={(event) =>
+ openFileMenu(event, { path: rel })
+ }
>
{group.path}
</TooltipButton>
@@ -143,6 +152,7 @@ function MatchList({ block }: { block: Extract<ToolBlock, { kind: "matches" }> }
</div>
);
})}
+ <ContextMenu state={fileMenu} onClose={closeFileMenu} />
</div>
);
}
diff --git a/apps/desktop/src/features/chat/transcript/ToolRow.tsx b/apps/desktop/src/features/chat/transcript/ToolRow.tsx
index b234973ae..205aad94f 100644
--- a/apps/desktop/src/features/chat/transcript/ToolRow.tsx
+++ b/apps/desktop/src/features/chat/transcript/ToolRow.tsx
@@ -13,6 +13,8 @@ import {
import { useTranslation } from "react-i18next";
import type { UiMessage } from "@pi-desktop/shared";
import { useOpenPreviewTarget } from "../../../hooks/use-preview-target";
+import { useChatFileMenu } from "../../../hooks/use-chat-file-menu";
+import { ContextMenu } from "../../../components/ContextMenu";
import { useFollowScroll } from "../../../hooks/use-follow-scroll";
import { getToolPreviewTarget } from "../../../lib/chat-links";
import { disclosureKey } from "./disclosure";
@@ -154,6 +156,7 @@ export const ToolRow = memo(function ToolRow({
const detailsId = useId();
const root = useAppStore((s) => s.workspace?.path);
const openTarget = useOpenPreviewTarget();
+ const { fileMenu, openFileMenu, closeFileMenu } = useChatFileMenu();
const openSubagentTab = useAppStore((s) => s.openSubagentTab);
const activeWorkPanelTabId = useAppStore((s) => s.activeWorkPanelTabId);
const status = message.toolStatus;
@@ -484,6 +487,12 @@ export const ToolRow = memo(function ToolRow({
}
: undefined
}
+ onContextMenu={
+ previewTarget?.kind === "file"
+ ? (event) =>
+ openFileMenu(event, { path: previewTarget.path })
+ : undefined
+ }
>
{summary}
</span>
@@ -559,6 +568,7 @@ export const ToolRow = memo(function ToolRow({
onCollapse={collapseRow}
/>
) : null}
+ <ContextMenu state={fileMenu} onClose={closeFileMenu} />
</div>
);
}, toolRowPropsEqual);
diff --git a/apps/desktop/src/features/chat/transcript/shared.tsx b/apps/desktop/src/features/chat/transcript/shared.tsx
index e3aac5853..934859444 100644
--- a/apps/desktop/src/features/chat/transcript/shared.tsx
+++ b/apps/desktop/src/features/chat/transcript/shared.tsx
@@ -19,6 +19,8 @@ import {
type ThinkingLevel,
} from "@pi-desktop/shared";
import { useOpenChatFileRef, useOpenPreviewTarget } from "../../../hooks/use-preview-target";
+import { useChatFileMenu } from "../../../hooks/use-chat-file-menu";
+import { ContextMenu } from "../../../components/ContextMenu";
import { useDisclosureAnchorNotifier } from "../../../lib/disclosure-anchor-context";
import { isThinkingActive, resolveThinkingDisplayMode } from "../../../lib/turn-process";
import { TranscriptSearchContext } from "../../../lib/transcript-search-context";
@@ -427,21 +429,26 @@ export function FileRefChip({
} & SourcePositionProps) {
const { t } = useTranslation();
const Icon = fileChipIcon(name, kind);
+ const { fileMenu, openFileMenu, closeFileMenu } = useChatFileMenu();
const html = isHtmlFilePath(path) || isHtmlFilePath(name);
return (
- <button
- type="button"
- className="composer-chip chat-file-chip"
- {...position}
- title={`${html ? t("chat.previewUrl") : t("chat.openFile")} — ${path}`}
- aria-label={`${name} — ${path}`}
- onClick={() => onOpen(path)}
- >
- <span className="composer-chip-icon" aria-hidden>
- <Icon size={13} />
- </span>
- <span className="composer-chip-name">{name}</span>
- </button>
+ <>
+ <button
+ type="button"
+ className="composer-chip chat-file-chip"
+ {...position}
+ title={`${html ? t("chat.previewUrl") : t("chat.openFile")} — ${path}`}
+ aria-label={`${name} — ${path}`}
+ onClick={() => onOpen(path)}
+ onContextMenu={(event) => openFileMenu(event, { path })}
+ >
+ <span className="composer-chip-icon" aria-hidden>
+ <Icon size={13} />
+ </span>
+ <span className="composer-chip-name">{name}</span>
+ </button>
+ <ContextMenu state={fileMenu} onClose={closeFileMenu} />
+ </>
);
}
@@ -457,6 +464,7 @@ export function MessageAttachmentImage({
attachment: MessageAttachment;
onOpenFile: (path: string) => void;
}) {
+ const { fileMenu, openFileMenu, closeFileMenu } = useChatFileMenu();
const dataUrl = useReferencedImageDataUrl(attachment.ref, attachment.mimeType);
if (!dataUrl) {
return (
@@ -469,17 +477,21 @@ export function MessageAttachmentImage({
);
}
return (
- <button
- type="button"
- className="message-attachment-image"
- role="listitem"
- title={`${attachment.name} — ${attachment.ref}`}
- onClick={() =>
- useAppStore.getState().openFileInWorkPanel(attachment.ref, attachment.mimeType)
- }
- >
- <img src={dataUrl} alt={attachment.name} />
- </button>
+ <>
+ <button
+ type="button"
+ className="message-attachment-image"
+ role="listitem"
+ title={`${attachment.name} — ${attachment.ref}`}
+ onClick={() =>
+ useAppStore.getState().openFileInWorkPanel(attachment.ref, attachment.mimeType)
+ }
+ onContextMenu={(event) => openFileMenu(event, { path: attachment.ref })}
+ >
+ <img src={dataUrl} alt={attachment.name} />
+ </button>
+ <ContextMenu state={fileMenu} onClose={closeFileMenu} />
+ </>
);
}
diff --git a/apps/desktop/src/hooks/use-chat-file-menu.tsx b/apps/desktop/src/hooks/use-chat-file-menu.tsx
new file mode 100644
index 000000000..8279fab9c
--- /dev/null
+++ b/apps/desktop/src/hooks/use-chat-file-menu.tsx
@@ -0,0 +1,64 @@
+/**
+ * The right-click action every file reference in the conversation shares.
+ *
+ * A reference the transcript already recognises as a file — a chip on a turn, an
+ * inline code span, a link, a local image — is a file the user can open with one
+ * click, so its menu offers the destination a click has no room for: the file's
+ * own folder in the system file manager. The reference travels through the same
+ * completion a click uses (`useRevealChatFileRef`, ADR 0262/0263), so a
+ * reference that resolved to nothing says so instead of revealing a lookalike
+ * somewhere else.
+ *
+ * Items are data, exactly as `ContextMenu` takes them: every surface keeps the
+ * menu instance it already owns and shares only this vocabulary, so a row that
+ * already has items of its own (a markdown link) adds this one instead of
+ * opening a second surface.
+ */
+import { useCallback, type MouseEvent as ReactMouseEvent } from "react";
+import { useTranslation } from "react-i18next";
+import { useContextMenu, type ContextMenuItem } from "../components/ContextMenu";
+import { IconFolderOpen } from "../components/icons";
+import { useRevealChatFileRef } from "./use-preview-target";
+
+export type ChatFileMenuTarget = {
+ /** The reference as the surface spelled it, before completion. */
+ path: string;
+ /** Markdown file the reference was read from, for `./` and `../`. */
+ baseDir?: string;
+};
+
+export function useChatFileMenuItems() {
+ const { t } = useTranslation();
+ const revealFileRef = useRevealChatFileRef();
+ return useCallback(
+ ({ path, baseDir }: ChatFileMenuTarget): ContextMenuItem[] => [
+ {
+ id: "reveal-in-folder",
+ label: t("chat.revealFileInFolder"),
+ icon: <IconFolderOpen size={14} />,
+ onSelect: () => revealFileRef(path, baseDir),
+ },
+ ],
+ [revealFileRef, t],
+ );
+}
+
+/**
+ * The item plus the open request, for a surface that owns its own menu.
+ *
+ * A row-level menu is a different surface from this one, so a reference inside
+ * a row cannot hand its item to that menu's opener and still say which file it
+ * means. Callers therefore take the pair and render one `<ContextMenu>` where
+ * the reference lives — a tool row, a tool result list, an attachment
+ * thumbnail — while `Markdown` shares a single pair across its whole tree.
+ */
+export function useChatFileMenu() {
+ const fileMenuItems = useChatFileMenuItems();
+ const { contextMenu, openContextMenu, closeContextMenu } = useContextMenu();
+ const openFileMenu = useCallback(
+ (event: ReactMouseEvent<HTMLElement>, target: ChatFileMenuTarget) =>
+ openContextMenu(event, { items: fileMenuItems(target) }),
+ [fileMenuItems, openContextMenu],
+ );
+ return { fileMenu: contextMenu, openFileMenu, closeFileMenu: closeContextMenu };
+}
diff --git a/apps/desktop/src/hooks/use-preview-target.ts b/apps/desktop/src/hooks/use-preview-target.ts
index 313487cd6..089cfca19 100644
--- a/apps/desktop/src/hooks/use-preview-target.ts
+++ b/apps/desktop/src/hooks/use-preview-target.ts
@@ -38,7 +38,7 @@ function isDotRelative(path: string): boolean {
}
/**
- * Open a file reference the conversation mentioned.
+ * Where a chat file reference actually landed.
*
* The reference is completed in the main process first, because the token is
* routinely a shorthand: an agent that works on `/root/dir/openimage.js` names
@@ -51,19 +51,88 @@ function isDotRelative(path: string): boolean {
* named by its absolute path, and the file view switches its own folder to the
* one that contains it. Scratch and attachment files are absolute too.
*
- * 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 reference that matches
- * nothing says so instead of opening an empty panel.
+ * A reference that matches nothing is reported here, once, so every action
+ * built on a reference stays honest about a shorthand that resolved to
+ * nothing instead of acting on a differently named file.
*/
-export function useOpenChatFileRef() {
+export type ResolvedChatFileRef = {
+ /** The address the host accepts for this reference. */
+ path: string;
+ /** The primary folder's own spelling; workspace-relative surfaces take this. */
+ relativePath: string;
+ /** True for a match inside a folder the open project registers (ADR 0249). */
+ inProject: boolean;
+ /** True when that folder is the project's primary one. */
+ primary: boolean;
+};
+
+function useResolveChatFileRef() {
const { t } = useTranslation();
const workspacePath = useAppStore((s) => s.workspace?.path ?? null);
const sessionId = useAppStore((s) => s.activeSessionId);
+ const showToast = useAppStore((s) => s.showToast);
+
+ return useCallback(
+ async (
+ path: string,
+ baseDir?: string,
+ ): Promise<ResolvedChatFileRef | null> => {
+ const raw = String(path ?? "").trim();
+ if (!raw) return null;
+ // `./x` and `../x` are the one shape the caller resolves better than the
+ // main process can: the base is the markdown file on screen, which only
+ // the caller knows. Everything else is completed against the roots.
+ const anchored = isDotRelative(raw)
+ ? toWorkspaceRel(raw, workspacePath, baseDir)
+ : null;
+ let match = null;
+ try {
+ match = (await api.fsResolveRef(anchored ?? raw, sessionId)).match;
+ } catch {
+ match = null;
+ }
+ if (!match) {
+ showToast(t("chat.fileRefMissing", { name: raw }), { variant: "error" });
+ return null;
+ }
+ if (match.root !== "workspace") {
+ return {
+ path: match.absolutePath,
+ relativePath: match.absolutePath,
+ inProject: false,
+ primary: false,
+ };
+ }
+ // A project group can hold several folders, and a relative path always
+ // means the primary one, so a file from a sibling folder travels by its
+ // absolute path and the file view switches to that folder (ADR 0263).
+ const primary = match.projectRoot ? match.projectRoot.primary : true;
+ return {
+ path: primary ? match.relativePath : match.absolutePath,
+ relativePath: match.relativePath,
+ inProject: true,
+ primary,
+ };
+ },
+ [sessionId, showToast, t, workspacePath],
+ );
+}
+
+/**
+ * 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.
+ */
+export function useOpenChatFileRef() {
+ const resolveRef = useResolveChatFileRef();
const pluginViews = useAppStore((s) => s.pluginViews);
const openFile = useAppStore((s) => s.openFileInWorkPanel);
const openUrl = useAppStore((s) => s.openUrlInWorkPanel);
const openTab = useAppStore((s) => s.openWorkPanelTab);
- const showToast = useAppStore((s) => s.showToast);
const fileViewAvailable = useMemo(
() => hasPluginView(pluginViews, FILE_MANAGER_PLUGIN_TAB),
@@ -72,56 +141,53 @@ export function useOpenChatFileRef() {
return useCallback(
(path: string, baseDir?: string, mimeType?: string) => {
- const raw = String(path ?? "").trim();
- if (!raw) return;
- // `./x` and `../x` are the one shape the caller resolves better than the
- // main process can: the base is the markdown file on screen, which only
- // the caller knows. Everything else is completed against the roots.
- const anchored = isDotRelative(raw)
- ? toWorkspaceRel(raw, workspacePath, baseDir)
- : null;
void (async () => {
- let match = null;
- try {
- match = (await api.fsResolveRef(anchored ?? raw, sessionId)).match;
- } catch {
- match = null;
- }
- if (!match) {
- showToast(t("chat.fileRefMissing", { name: raw }), {
- variant: "error",
- });
+ const resolved = await resolveRef(path, baseDir);
+ if (!resolved) return;
+ if (
+ resolved.inProject &&
+ resolved.primary &&
+ isHtmlFilePath(resolved.relativePath)
+ ) {
+ openUrl(resolved.relativePath);
return;
}
- if (match.root === "workspace") {
- // A project group can hold several folders, and a relative path always
- // means the primary one, so a file from a sibling folder travels by its
- // absolute path and the file view switches to that folder (ADR 0263).
- const inPrimary = match.projectRoot ? match.projectRoot.primary : true;
- const target = inPrimary ? match.relativePath : match.absolutePath;
- if (inPrimary && isHtmlFilePath(match.relativePath)) {
- openUrl(match.relativePath);
- return;
- }
- if (fileViewAvailable) {
- openTab(fileManagerPluginTab(target));
- return;
- }
- openFile(target, mimeType);
+ if (resolved.inProject && fileViewAvailable) {
+ openTab(fileManagerPluginTab(resolved.path));
return;
}
- openFile(match.absolutePath, mimeType);
+ openFile(resolved.path, mimeType);
+ })();
+ },
+ [fileViewAvailable, openFile, openTab, openUrl, resolveRef],
+ );
+}
+
+/**
+ * Show a file reference in the system file manager.
+ *
+ * It travels through the same completion and the same address rule a click
+ * uses (`useOpenChatFileRef`), so a right-click never reveals a differently
+ * named file that happens to sit in the same folder: a reference that matched
+ * nothing says so instead.
+ */
+export function useRevealChatFileRef() {
+ const { t } = useTranslation();
+ const resolveRef = useResolveChatFileRef();
+ const showToast = useAppStore((s) => s.showToast);
+
+ return useCallback(
+ (path: string, baseDir?: string) => {
+ void (async () => {
+ const resolved = await resolveRef(path, baseDir);
+ if (!resolved) return;
+ try {
+ await api.fsReveal(resolved.path);
+ } catch {
+ showToast(t("chat.fileRevealFailed"), { variant: "error" });
+ }
})();
},
- [
- fileViewAvailable,
- openFile,
- openTab,
- openUrl,
- sessionId,
- showToast,
- t,
- workspacePath,
- ],
+ [resolveRef, showToast, t],
);
}
diff --git a/apps/desktop/test/chat-file-reveal-menu.test.mjs b/apps/desktop/test/chat-file-reveal-menu.test.mjs
new file mode 100644
index 000000000..3d5a3bc3a
--- /dev/null
+++ b/apps/desktop/test/chat-file-reveal-menu.test.mjs
@@ -0,0 +1,292 @@
+/**
+ * A file the conversation already recognised is a file the user can act on.
+ *
+ * Opening it is one click, so the only destination left for the pointer path is
+ * the file's own folder in the system file manager. Every surface that names a
+ * file offers it — a turn's chip, an inline code span, a markdown link, a local
+ * image — and all of them reveal through the same completion a click uses, so a
+ * shorthand that resolved to nothing reports that instead of revealing a
+ * lookalike file in another folder (ADR 0262/0263).
+ *
+ * The destination half is asserted behaviorally: the real hooks run against a
+ * recorded store and stubbed host replies, because the contract is the address
+ * a reveal hands the host, not the shape of the code that builds it.
+ */
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import test from "node:test";
+import * as React from "react";
+import * as jsxRuntime from "react/jsx-runtime";
+import { renderToStaticMarkup } from "react-dom/server";
+import ts from "typescript";
+import { readTranscriptSource } from "./helpers/source-contracts.mjs";
+
+const read = (relative) => readFileSync(new URL(relative, import.meta.url), "utf8");
+
+/** Compile one desktop module and evaluate it against the given mocks. */
+function loadModule(relative, imports) {
+ const file = new URL(relative, import.meta.url);
+ const { outputText } = ts.transpileModule(read(relative), {
+ compilerOptions: {
+ module: ts.ModuleKind.CommonJS,
+ jsx: ts.JsxEmit.ReactJSX,
+ target: ts.ScriptTarget.ES2022,
+ },
+ fileName: file.pathname,
+ });
+ const module = { exports: {} };
+ new Function("require", "exports", "module", outputText)(
+ (id) => {
+ assert.ok(Object.hasOwn(imports, id), `unmocked dependency: ${id}`);
+ return imports[id];
+ },
+ module.exports,
+ module,
+ );
+ return module.exports;
+}
+
+const calls = {
+ reveals: [],
+ tabs: [],
+ files: [],
+ urls: [],
+ toasts: [],
+ resolved: [],
+ menus: [],
+};
+
+const state = {
+ workspace: { path: "C:/project" },
+ activeSessionId: "session-1",
+ pluginViews: [{ pluginId: "pi.file-manager", viewId: "manager" }],
+ openFileInWorkPanel: (...args) => calls.files.push(args),
+ openUrlInWorkPanel: (...args) => calls.urls.push(args),
+ openWorkPanelTab: (tab) => calls.tabs.push(tab),
+ showToast: (...args) => calls.toasts.push(args),
+};
+
+let nextMatch = null;
+let revealFails = false;
+
+const translate = () => ({
+ t: (key, values) => `${key}:${values?.name ?? ""}`,
+});
+
+const previewTarget = loadModule("../src/hooks/use-preview-target.ts", {
+ react: React,
+ "react-i18next": { useTranslation: translate },
+ "../stores/app-store": { useAppStore: (selector) => selector(state) },
+ "../lib/api": {
+ api: {
+ fsResolveRef: async (ref) => {
+ calls.resolved.push(ref);
+ return { match: nextMatch };
+ },
+ fsReveal: async (path) => {
+ if (revealFails) throw new Error("host refused to reveal");
+ calls.reveals.push(path);
+ },
+ },
+ },
+ "../lib/chat-links": loadModule("../src/lib/chat-links.ts", {}),
+ "../lib/open-http-url": { openHttpUrl: (...args) => calls.urls.push(args) },
+ "../lib/work-panel-tabs": loadModule("../src/lib/work-panel-tabs.ts", {}),
+});
+
+const { useChatFileMenu, useChatFileMenuItems } = loadModule(
+ "../src/hooks/use-chat-file-menu.tsx",
+ {
+ react: React,
+ "react/jsx-runtime": jsxRuntime,
+ "react-i18next": { useTranslation: translate },
+ "../components/icons": { IconFolderOpen: () => null },
+ "../components/ContextMenu": {
+ useContextMenu: () => ({
+ contextMenu: null,
+ openContextMenu: (_event, request) => calls.menus.push(request),
+ closeContextMenu: () => {},
+ }),
+ },
+ "./use-preview-target": previewTarget,
+ },
+);
+
+const flush = () => new Promise((resolve) => setImmediate(resolve));
+
+function reset(match) {
+ Object.values(calls).forEach((list) => list.splice(0, list.length));
+ nextMatch = match;
+ revealFails = false;
+}
+
+/** The match the main process reports for a file of the project's main folder. */
+function projectMatch(overrides = {}) {
+ return {
+ root: "workspace",
+ relativePath: "src/dir/a.ts",
+ absolutePath: "C:/project/src/dir/a.ts",
+ matchedBy: "exact-relative",
+ projectRoot: { primary: true },
+ ...overrides,
+ };
+}
+
+/**
+ * Render both hooks for one reference, then click it and run the menu item the
+ * right-click would have offered. Both run inside a render, so no side effect
+ * fires while React is rendering.
+ */
+async function clickAndReveal(path) {
+ let open = null;
+ let items = null;
+ function Harness() {
+ open = previewTarget.useOpenChatFileRef();
+ items = useChatFileMenuItems()({ path });
+ return null;
+ }
+ renderToStaticMarkup(React.createElement(Harness));
+ assert.equal(typeof open, "function", "the hook returned a click handler");
+ const item = items.find((entry) => entry.id === "reveal-in-folder");
+ assert.ok(item, "every file reference offers its folder");
+ open(path);
+ await flush();
+ item.onSelect("");
+ await flush();
+}
+
+test("a project file is revealed at the address the click opens", async () => {
+ reset(projectMatch());
+ await clickAndReveal("src/dir/a.ts");
+ // Completion ran for both actions, so neither can act on a different file.
+ assert.deepEqual(calls.resolved, ["src/dir/a.ts", "src/dir/a.ts"]);
+ assert.equal(calls.tabs[0].location, "src/dir/a.ts");
+ assert.deepEqual(calls.reveals, ["src/dir/a.ts"]);
+ assert.deepEqual(calls.toasts, []);
+});
+
+test("a sibling folder file is revealed by absolute path, as it is opened", async () => {
+ reset(
+ projectMatch({
+ relativePath: "lib/only-here.ts",
+ absolutePath: "C:/project-second/lib/only-here.ts",
+ projectRoot: { primary: false },
+ }),
+ );
+ await clickAndReveal("lib/only-here.ts");
+ assert.equal(calls.tabs[0].location, "C:/project-second/lib/only-here.ts");
+ assert.deepEqual(calls.reveals, ["C:/project-second/lib/only-here.ts"]);
+});
+
+test("a scratch or attachment file is revealed by absolute path", async () => {
+ reset({
+ root: "scratch",
+ relativePath: "notes.md",
+ absolutePath: "C:/data/scratch/session-1/notes.md",
+ matchedBy: "exact-relative",
+ });
+ await clickAndReveal("notes.md");
+ assert.equal(calls.files[0][0], "C:/data/scratch/session-1/notes.md");
+ assert.deepEqual(calls.reveals, ["C:/data/scratch/session-1/notes.md"]);
+});
+
+test("a reference nothing answers reports itself and reveals nothing", async () => {
+ reset(null);
+ await clickAndReveal("missing-helper.js");
+ assert.deepEqual(calls.reveals, []);
+ assert.deepEqual(calls.files, []);
+ assert.deepEqual(calls.tabs, []);
+ assert.deepEqual(
+ calls.toasts.map(([message]) => message),
+ ["chat.fileRefMissing:missing-helper.js", "chat.fileRefMissing:missing-helper.js"],
+ );
+});
+
+test("a refused reveal is reported instead of failing silently", async () => {
+ reset(projectMatch());
+ revealFails = true;
+ await clickAndReveal("src/dir/a.ts");
+ assert.deepEqual(calls.reveals, []);
+ assert.deepEqual(
+ calls.toasts.map(([message]) => message),
+ ["chat.fileRevealFailed:"],
+ );
+});
+
+test("the menu a reference opens carries that one item and nothing else", () => {
+ reset(projectMatch());
+ let openFileMenu = null;
+ function Harness() {
+ openFileMenu = useChatFileMenu().openFileMenu;
+ return null;
+ }
+ renderToStaticMarkup(React.createElement(Harness));
+ openFileMenu({}, { path: "src/dir/a.ts" });
+ assert.deepEqual(
+ calls.menus.map((menu) => menu.items.map((item) => [item.id, item.label])),
+ [[["reveal-in-folder", "chat.revealFileInFolder:"]]],
+ );
+});
+
+const transcript = await readTranscriptSource();
+const markdown = read("../src/components/Markdown.tsx");
+const toolRow = read("../src/features/chat/transcript/ToolRow.tsx");
+const toolDetails = read("../src/components/ToolDetails.tsx");
+const shared = read("../src/features/chat/transcript/shared.tsx");
+
+test("every transcript surface that names a file opens that item", () => {
+ // The chip a user turn renders owns the same item its row does, next to the
+ // thumbnail that names the same attachment a second way.
+ assert.match(
+ shared,
+ /const \{ fileMenu, openFileMenu, closeFileMenu \} = useChatFileMenu\(\)/,
+ );
+ assert.match(shared, /onContextMenu=\{\(event\) => openFileMenu\(event, \{ path \}\)/);
+ assert.match(
+ shared,
+ /onContextMenu=\{\(event\) => openFileMenu\(event, \{ path: attachment\.ref \}\)/,
+ );
+ assert.match(shared, /<ContextMenu state=\{fileMenu\} onClose=\{closeFileMenu\} \/>/);
+ // A tool row's summary and a tool result's file and match lists name files
+ // the same way, so they open the same item where the reference is rendered.
+ assert.match(toolRow, /previewTarget\?\.kind === "file"/);
+ assert.match(toolRow, /openFileMenu\(event, \{ path: previewTarget\.path \}\)/);
+ assert.match(toolDetails, /openFileMenu\(event, \{ path: rel \}\)/);
+ // Markdown owns one surface for its whole tree, because its blocks are
+ // memoized and the references are spread across them.
+ assert.match(markdown, /const fileMenuItems = useChatFileMenuItems\(\)/);
+ assert.match(
+ markdown,
+ /<MarkdownFileMenuContext\.Provider value=\{openMarkdownFileMenu\}>/,
+ );
+ assert.match(markdown, /<ContextMenu state=\{fileMenu\} onClose=\{closeFileMenu\} \/>/);
+ // Inline code, a file link, and a local image each hand their own reference
+ // to that surface; `./` and `../` keep the markdown base beside the path.
+ assert.match(markdown, /openFileMenu\(event, \{ path: text \?\? target\.path, baseDir \}\)/);
+ assert.match(markdown, /openFileMenu\(event, \{ path: rel, baseDir \}\)/);
+ assert.match(markdown, /openFileMenu\(event, \{ path: localRef, baseDir \}\)/);
+ assert.match(markdown, /onContextMenu=\{onLocalContextMenu\}/);
+ // A local image that cannot be shown inline keeps a chip, and both carry the
+ // menu only when the reference actually resolved to a file.
+ assert.match(markdown, /const onLocalContextMenu =\s*localRef && openFileMenu/);
+});
+
+test("a URL never reaches the reveal", () => {
+ const menu = read("../src/hooks/use-chat-file-menu.tsx");
+ // The item is file-only by construction: it is built where the reference is a
+ // path, and an HTTP link keeps its own external/work-panel/copy menu.
+ assert.match(menu, /useRevealChatFileRef\(\)/);
+ assert.doesNotMatch(menu, /openHttpUrl|browserOpenExternal/);
+ // An HTTP link is not a file on disk, so it never grows this item; it keeps
+ // the menu it already has.
+ assert.ok(markdown.includes('if (!/^https?:\\/\\//i.test(href)) {'));
+});
+
+test("the reveal labels ship in the catalogs the menu reads", () => {
+ const en = read("../../../packages/i18n/src/locales/en/index.ts");
+ const zhCN = read("../../../packages/i18n/src/locales/zh-CN/index.ts");
+ assert.match(en, /revealFileInFolder: "Show in folder"/);
+ assert.match(en, /fileRevealFailed: "Could not show the file in its folder\."/);
+ assert.match(zhCN, /revealFileInFolder: "在文件夹中显示"/);
+ assert.match(zhCN, /fileRevealFailed: "无法在文件夹中打开该文件。"/);
+});
diff --git a/apps/desktop/test/transcript-file-chips.test.mjs b/apps/desktop/test/transcript-file-chips.test.mjs
index 66c4712d5..4bfa6a0f6 100644
--- a/apps/desktop/test/transcript-file-chips.test.mjs
+++ b/apps/desktop/test/transcript-file-chips.test.mjs
@@ -36,19 +36,20 @@ test("a file chip is routed by where the reference resolved, never optimisticall
// follows the folder that answered: relative for the primary one, absolute
// for its siblings, and the file view switches to the folder it is given.
assert.match(hook, /match\.projectRoot \? match\.projectRoot\.primary : true/);
- assert.match(hook, /inPrimary \? match\.relativePath : match\.absolutePath/);
+ assert.match(hook, /path: primary \? match\.relativePath : match\.absolutePath/);
// A workspace HTML page is a page to run, not a file to read (ADR 0163), and
// only the primary folder has a workspace-relative address for the browser.
- assert.match(hook, /inPrimary && isHtmlFilePath\(match\.relativePath\)/);
- assert.match(hook, /openUrl\(match\.relativePath\)/);
+ assert.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.
assert.match(hook, /FILE_MANAGER_PLUGIN_TAB/);
- assert.match(hook, /fileManagerPluginTab\(target\)/);
- assert.match(hook, /openFile\(target, mimeType\)/);
+ assert.match(hook, /fileManagerPluginTab\(resolved\.path\)/);
// Session scratch and attachment files live outside the plugin's project
- // roots, so they are addressed by absolute path on the host file tab.
- assert.match(hook, /openFile\(match\.absolutePath, mimeType\)/);
+ // roots, so completion hands them back as an absolute path.
+ assert.match(hook, /inProject: false/);
+ assert.match(hook, /openFile\(resolved\.path, mimeType\)/);
// 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\(/);
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index 8b14ef60f..73044e422 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -3224,10 +3224,15 @@ Anatomy:
primary-folder file is addressed to the view as a project-relative path and a
sibling-folder file as an absolute one, which is also how scratch and
attachment files are addressed. A reference that matches no file opens nothing
- and reports itself; the OS default application is no longer what this click
- does. HTTP(S)
+ and reports itself, as does right-clicking it: the file-reference menu's item
+ shows the file in the system file manager, and the same item is offered on a
+ sent `@path` chip, an inline code span, a markdown link, a local image, a tool
+ row's file path, and a path in a tool result's file or match list, through the
+ same completion and the same address.
+ The OS default application is no longer what this click does. HTTP(S)
URLs stay text links. Plain clicks follow the Link open destination setting,
- and right-clicking exposes the same external, work-panel, and copy actions.
+ and right-clicking a URL exposes the same external, work-panel, and copy
+ actions.
- States: keyboard-active row uses the shared `kb-active` treatment; empty
query lists everything (slash) / recently indexed order (file); zero
matches renders the localized empty row and the menu counts as closed for
diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.md
index 6a48c4577..e5df405cf 100644
--- a/docs/spec/04-ux/09-interaction-patterns.md
+++ b/docs/spec/04-ux/09-interaction-patterns.md
@@ -1282,9 +1282,14 @@ Project drag/drop follows these patterns:
the work panel follows the folder that answered: a file of the primary folder
travels as a project-relative path, a file of a sibling folder of the same
project as an absolute one, exactly as a scratch or attachment file does. A
- chip whose reference matches nothing opens nothing and reports itself; the OS
- default application is no longer what this click does, though that action
- stays reachable from the file view's own context menu.
+ chip whose reference matches nothing opens nothing and reports itself, and so
+ does a right-click on it: the file-reference menu's item — offered on every
+ reference the transcript renders, a sent `@path` chip, an inline code span, a
+ local link, a local image, a tool row's own file path, a path in a tool
+ result's file or match list, and an image attachment's thumbnail — shows the
+ file in the system file manager through that same completion and that same
+ address. The OS default application is no longer what this click does, though
+ that action stays reachable from the file view's own context menu.
- The same destination rule governs every other surface of the transcript that
names a file, because one opener serves them all: clicking the file path in a
tool row's summary (Read, Write, Edit, fetch) and clicking a path in a tool
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 8a52e70c2..54a8e02d9 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -11584,8 +11584,17 @@ are withdrawn with ADR 0165.
and a path heading of the `Grep` result. 6) Disable the File Manager plugin,
click a project file reference and the tool row summary again, then re-enable
it and click both once more. 7) Click a reference that resolves in the
- project's second folder, then one that resolves in its primary folder.
+ project's second folder, then one that resolves in its primary folder. 8)
+ Right-click the sent `@path` chip, the inline-code reference, the markdown
+ link, the local image, a tool row's file path, a tool result's file list, and
+ an attachment thumbnail; then right-click a reference that matches nothing.
- **Expected**:
+ - Right-clicking a file reference opens the renderer's own menu with one
+ item, Show in folder, which reveals the named file in the system file
+ manager. The inline-code reference, the file link, the local image, a tool
+ row's path, a tool result's file or match list, and an attachment thumbnail
+ offer the same item, and a reference that matches nothing reports itself
+ instead of revealing a same-named file elsewhere.
- A project file opens in the File Manager work-panel view on that file, with
its ancestor folders expanded and the file selected; no host `file:` tab is
added for it.
diff --git a/docs/zh-CN/spec/04-ux/08-component-spec.md b/docs/zh-CN/spec/04-ux/08-component-spec.md
index e2ba61a53..e8d4ea5e7 100644
--- a/docs/zh-CN/spec/04-ux/08-component-spec.md
+++ b/docs/zh-CN/spec/04-ux/08-component-spec.md
@@ -2247,7 +2247,7 @@ MainChat 底部的输入区域,用于撰写和发送提示。支持多行输
切换会话或项目、删除正在查看的附件时关闭预览;晚到的读取结果不得覆盖新图片。
- 发送的模板调用在记录中呈现为等宽命令
来自消息的 `command` 字段的芯片而不是扩展的正文。
-- 已发送的 `@path` 文件引用(带引号或不带引号)画成与草稿相同的叶子名芯片。点击芯片先经 `pi-desktop/fs/resolveRef` 补全引用——搜索整个打开的项目,按项目组文件夹顺序、主文件夹优先(ADR 0263)——再按解析结果打开:项目文件在随应用打包的 `pi.file-manager` 视图中打开(该视图不可用时退回宿主 `file:` 选项卡),会话临时目录或附件文件在宿主 `file:` 选项卡中打开,主文件夹中的 `.html`/`.htm` 在侧边浏览器打开。交给该视图的地址跟随应答的文件夹:主文件夹中的文件用项目内相对路径传递,同一项目的同级文件夹中的文件用绝对路径传递,与会话临时目录和附件文件一致。什么都没匹配到时既不打开任何东西,也会自己报告出来;系统默认应用不再由这次点击触发。HTTP(S) URL 仍是侧边浏览器的文本链接。
+- 已发送的 `@path` 文件引用(带引号或不带引号)画成与草稿相同的叶子名芯片。点击芯片先经 `pi-desktop/fs/resolveRef` 补全引用——搜索整个打开的项目,按项目组文件夹顺序、主文件夹优先(ADR 0263)——再按解析结果打开:项目文件在随应用打包的 `pi.file-manager` 视图中打开(该视图不可用时退回宿主 `file:` 选项卡),会话临时目录或附件文件在宿主 `file:` 选项卡中打开,主文件夹中的 `.html`/`.htm` 在侧边浏览器打开。交给该视图的地址跟随应答的文件夹:主文件夹中的文件用项目内相对路径传递,同一项目的同级文件夹中的文件用绝对路径传递,与会话临时目录和附件文件一致。什么都没匹配到时既不打开任何东西,也会自己报告出来,右键该芯片也一样;引用菜单里的那一条在系统文件管理器中显示该文件,发送的 `@path` 芯片、消息 Markdown 中的行内代码、本地链接与本地图片、工具行自己的文件路径、工具结果的文件列表或匹配列表中的路径、图片附件缩略图都提供同一条,并同样经这次补全与这套寻址规则。系统默认应用不再由这次点击触发。HTTP(S) URL 仍是侧边浏览器的文本链接。
- 状态:键盘活动行使用共享 `kb-active` 处理;空的
查询列出所有内容(斜杠)/最近索引的顺序(文件);零
匹配呈现本地化的空行并且菜单计为关闭
diff --git a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md b/docs/zh-CN/spec/04-ux/09-interaction-patterns.md
index fcbef20d1..d894b692d 100644
--- a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md
+++ b/docs/zh-CN/spec/04-ux/09-interaction-patterns.md
@@ -1022,7 +1022,7 @@ Mode/provider/model/permission/shell 配置和新提示仍然存在
撤消发送。该撤消操作将恢复原始芯片顺序和标签;它
从不解析序列化的 `@path` 文本。一旦回复内容开始,中止就会继续
部分抄本,不恢复草稿。
-- 发送成功后,用户气泡仅把这些序列化的 `@path` 标记解析回与输入框一致的叶子名芯片用于展示。持久化消息和模型上下文仍是规范 `@path` 文本。点击芯片先经 `pi-desktop/fs/resolveRef` 补全引用——该通道搜索整个打开的项目,按项目组自身的文件夹顺序、主文件夹优先(ADR 0263)——再按解析结果打开:项目文件在随应用打包的 `pi.file-manager` 工作面板视图中打开(该视图不可用时退回宿主 `file:` 选项卡),会话临时目录或附件文件在宿主 `file:` 选项卡中打开,项目主文件夹中的 `.html`/`.htm` 页面仍在侧边浏览器中打开,因为侧边浏览器本就以该文件夹为根。交给工作面板的地址跟随应答的文件夹:主文件夹中的文件按项目内相对路径传递,同一项目的同级文件夹中的文件按绝对路径传递,与会话临时目录或附件文件一致。什么都没匹配到的芯片不打开任何东西,而是自己报告出来;系统默认应用不再由这次点击触发,该动作仍可从文件视图自己的右键菜单使用。
+- 发送成功后,用户气泡仅把这些序列化的 `@path` 标记解析回与输入框一致的叶子名芯片用于展示。持久化消息和模型上下文仍是规范 `@path` 文本。点击芯片先经 `pi-desktop/fs/resolveRef` 补全引用——该通道搜索整个打开的项目,按项目组自身的文件夹顺序、主文件夹优先(ADR 0263)——再按解析结果打开:项目文件在随应用打包的 `pi.file-manager` 工作面板视图中打开(该视图不可用时退回宿主 `file:` 选项卡),会话临时目录或附件文件在宿主 `file:` 选项卡中打开,项目主文件夹中的 `.html`/`.htm` 页面仍在侧边浏览器中打开,因为侧边浏览器本就以该文件夹为根。交给工作面板的地址跟随应答的文件夹:主文件夹中的文件按项目内相对路径传递,同一项目的同级文件夹中的文件按绝对路径传递,与会话临时目录或附件文件一致。什么都没匹配到的芯片不打开任何东西,而是自己报告出来,右键这类芯片也一样;引用菜单里的那一条——发送的 `@path` 芯片、消息 Markdown 中的行内代码、本地链接与本地图片、工具行自己的文件路径、工具结果的文件列表或匹配列表中的路径、图片附件缩略图都提供同一条——经同一补全与同一寻址规则在系统文件管理器中显示该文件。系统默认应用不再由这次点击触发,该动作仍可从文件视图自己的右键菜单使用。
### 8a.3 打开时的键盘
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 3a9d23d30..31f497089 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
@@ -6954,7 +6954,7 @@ eleven-tool-round desktop paths are verified by
#### E2E-180:已发送的文件引用保持芯片并可点击打开
- **前提条件**:Agent 会话所在工作区含有嵌套源文件、HTML 文件,以及文件名带空格的文件;该项目组还有一个第二文件夹,里面有一个属于它自己的源文件。输入框也可以把操作系统文件粘贴到会话临时目录。内置的文件管理器插件已加载。
-- **步骤**:1)通过输入框芯片引用工作区源文件、工作区 HTML、带空格的文件名,以及粘贴的临时文件,然后发送。2)查看用户气泡。3)点击 HTML 芯片,再点击工作区源文件芯片,最后点击临时目录芯片。4)附加上项目第二个文件夹里的文件,并点击它的芯片。
+- **步骤**:1)通过输入框芯片引用工作区源文件、工作区 HTML、带空格的文件名,以及粘贴的临时文件,然后发送。2)查看用户气泡。3)点击 HTML 芯片,再点击工作区源文件芯片,最后点击临时目录芯片。4)附加上项目第二个文件夹里的文件,并点击它的芯片。5)右键那条已发送的 `@path` 芯片、助手 Markdown 里的行内代码引用、文件链接、本地图片、工具行自己的文件路径、工具结果的文件列表,以及附件缩略图,再右键一个什么都没匹配到的引用。
- **预期**:
- 每条已发送引用画成紧凑的叶子名芯片(图标 + 名称),而不是完整 `@path`。工具提示和无障碍名称保留规范路径。带引号路径和临时绝对路径也包括在内。
- 芯片加上短提示时,用户气泡按内容收缩,而不是撑到 `min(82%, 600px)` 上限。
@@ -6962,6 +6962,7 @@ eleven-tool-round desktop paths are verified by
- 点击工作区源文件芯片后,该文件在文件管理器工作面板视图中打开;芯片点击不再打开宿主的 `file:` 选项卡,也不再交给系统默认应用。
- 点击临时目录芯片时,文件在宿主的 `file:` 选项卡中按其绝对路径打开——它位于文件管理器项目根之外。
- 点击项目第二个文件夹里那个文件的芯片时,该文件在文件管理器视图中打开:补全会搜索整个项目组、主文件夹优先,同级文件夹里的文件用绝对路径寻址,因为相对路径永远指主文件夹(ADR 0263)。
+ - 右键文件引用会打开渲染器自己的菜单,里面只有一条「在文件夹中显示」,它在系统文件管理器中显示该文件;助手 Markdown 里的行内代码引用、文件链接与本地图片、工具行自己的文件路径、工具结果的文件列表或匹配列表中的路径、图片附件缩略图都提供同一条,而什么都没匹配到的引用会自己报告出来,而不是去显示别处同名的那份文件。
- 持久化用户消息仍包含给模型用的规范 `@path` 文本。
- **链接规格**:`04-ux/08-component-spec.md` §8.3 / §11.8、
`04-ux/09-interaction-patterns.md` §8a.2、`03-runtime/01-ipc-protocol.md`、
diff --git a/packages/i18n/src/locales/de/index.ts b/packages/i18n/src/locales/de/index.ts
index f9624d024..875fce59b 100644
--- a/packages/i18n/src/locales/de/index.ts
+++ b/packages/i18n/src/locales/de/index.ts
@@ -320,6 +320,8 @@ export const de = {
"errorModel": "Modell",
"previewFile": "Vorschau im Seitenbereich",
"fileRefMissing": "Keine Datei entspricht {{name}}",
+ "revealFileInFolder": "Im Ordner anzeigen",
+ "fileRevealFailed": "Die Datei konnte nicht im Ordner angezeigt werden.",
"previewUrl": "Im Seitenbrowser öffnen",
"openFile": "Mit Standardanwendung öffnen",
"retry": "Neu generieren",
diff --git a/packages/i18n/src/locales/en/index.ts b/packages/i18n/src/locales/en/index.ts
index 1078c8ddf..0e3c49e2d 100644
--- a/packages/i18n/src/locales/en/index.ts
+++ b/packages/i18n/src/locales/en/index.ts
@@ -327,6 +327,8 @@ export const en = {
errorModel: "Model",
previewFile: "Preview in the side panel",
fileRefMissing: "No file matches {{name}}",
+ revealFileInFolder: "Show in folder",
+ fileRevealFailed: "Could not show the file in its folder.",
previewUrl: "Open in the side browser",
openFile: "Open with default application",
retry: "Regenerate",
diff --git a/packages/i18n/src/locales/es/index.ts b/packages/i18n/src/locales/es/index.ts
index ad756c061..b8d4d5008 100644
--- a/packages/i18n/src/locales/es/index.ts
+++ b/packages/i18n/src/locales/es/index.ts
@@ -320,6 +320,8 @@ export const es = {
"errorModel": "Modelo",
"previewFile": "Vista previa en el panel lateral",
"fileRefMissing": "Ningún archivo coincide con {{name}}",
+ "revealFileInFolder": "Mostrar en carpeta",
+ "fileRevealFailed": "No se pudo mostrar el archivo en su carpeta.",
"previewUrl": "Abrir en el navegador lateral",
"openFile": "Abrir con aplicación predeterminada",
"retry": "Regenerar",
diff --git a/packages/i18n/src/locales/fr/index.ts b/packages/i18n/src/locales/fr/index.ts
index 86f328fa6..d07ebfb39 100644
--- a/packages/i18n/src/locales/fr/index.ts
+++ b/packages/i18n/src/locales/fr/index.ts
@@ -320,6 +320,8 @@ export const fr = {
"errorModel": "Modèle",
"previewFile": "Aperçu dans le panneau latéral",
"fileRefMissing": "Aucun fichier ne correspond à {{name}}",
+ "revealFileInFolder": "Afficher dans le dossier",
+ "fileRevealFailed": "Impossible d'afficher le fichier dans son dossier.",
"previewUrl": "Ouvrir dans le navigateur latéral",
"openFile": "Ouvrir avec l'application par défaut",
"retry": "Régénérer la branche",
diff --git a/packages/i18n/src/locales/ko/index.ts b/packages/i18n/src/locales/ko/index.ts
index 9d09241eb..f6cdd4cb5 100644
--- a/packages/i18n/src/locales/ko/index.ts
+++ b/packages/i18n/src/locales/ko/index.ts
@@ -329,6 +329,8 @@ export const ko = {
errorModel: "모델",
previewFile: "사이드 패널에서 미리 보기",
fileRefMissing: "{{name}}과(와) 일치하는 파일이 없습니다",
+ revealFileInFolder: "폴더에서 보기",
+ fileRevealFailed: "폴더에서 파일을 표시할 수 없습니다.",
previewUrl: "사이드 브라우저에서 열기",
openFile: "기본 애플리케이션으로 열기",
retry: "다시 생성",
diff --git a/packages/i18n/src/locales/pt-BR/index.ts b/packages/i18n/src/locales/pt-BR/index.ts
index 7225cf6e2..c93b3c5fd 100644
--- a/packages/i18n/src/locales/pt-BR/index.ts
+++ b/packages/i18n/src/locales/pt-BR/index.ts
@@ -318,6 +318,8 @@ export const ptBR = {
errorModel: "Modelo",
previewFile: "Pré-visualizar no painel lateral",
fileRefMissing: "Nenhum arquivo corresponde a {{name}}",
+ revealFileInFolder: "Mostrar na pasta",
+ fileRevealFailed: "Não foi possível mostrar o arquivo na pasta.",
previewUrl: "Abrir no navegador lateral",
openFile: "Abrir no aplicativo padrão",
retry: "Regenerar",
diff --git a/packages/i18n/src/locales/tr/index.ts b/packages/i18n/src/locales/tr/index.ts
index dd3656b7c..b39f4ed9a 100644
--- a/packages/i18n/src/locales/tr/index.ts
+++ b/packages/i18n/src/locales/tr/index.ts
@@ -329,6 +329,8 @@ export const tr = {
errorModel: "Model",
previewFile: "Yan panelde önizle",
fileRefMissing: "{{name}} ile eşleşen dosya yok",
+ revealFileInFolder: "Klasörde göster",
+ fileRevealFailed: "Dosya klasörde gösterilemedi.",
previewUrl: "Yan tarayıcıda aç",
openFile: "Varsayılan uygulamayla aç",
retry: "Yeniden oluştur",
diff --git a/packages/i18n/src/locales/zh-CN/index.ts b/packages/i18n/src/locales/zh-CN/index.ts
index 34a2cdcc0..e5d817d16 100644
--- a/packages/i18n/src/locales/zh-CN/index.ts
+++ b/packages/i18n/src/locales/zh-CN/index.ts
@@ -321,6 +321,8 @@ export const zhCN = {
errorModel: "模型",
previewFile: "在侧边面板预览",
fileRefMissing: "没有匹配 {{name}} 的文件",
+ revealFileInFolder: "在文件夹中显示",
+ fileRevealFailed: "无法在文件夹中打开该文件。",
previewUrl: "在侧边浏览器中打开",
openFile: "用系统默认应用打开",
retry: "重新生成",
diff --git a/packages/i18n/src/locales/zh-TW/index.ts b/packages/i18n/src/locales/zh-TW/index.ts
index d0a63fd81..669228b1b 100644
--- a/packages/i18n/src/locales/zh-TW/index.ts
+++ b/packages/i18n/src/locales/zh-TW/index.ts
@@ -321,6 +321,8 @@ export const zhTW = {
errorModel: "模型",
previewFile: "在側邊面板預覽",
fileRefMissing: "沒有匹配 {{name}} 的檔案",
+ revealFileInFolder: "在資料夾中顯示",
+ fileRevealFailed: "無法在資料夾中開啟該檔案。",
previewUrl: "在側邊瀏覽器中開啟",
openFile: "用系統預設應用開啟",
retry: "重新生成",