Skip to content

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

feat(transcript): render sent message images as chips with a hover card

vastsa2c33a358a500
diff --git a/apps/desktop/src/components/ImageHoverCard.tsx b/apps/desktop/src/components/ImageHoverCard.tsx
new file mode 100644
index 000000000..2bfb135a6
--- /dev/null
+++ b/apps/desktop/src/components/ImageHoverCard.tsx
@@ -0,0 +1,59 @@
+import { useEffect, useLayoutEffect, useRef, useState } from "react";
+import { portalToBody } from "../lib/portal-visibility";
+import "../styles/image-hover-card.css";
+
+/** Viewport rect of the chip that owns the card. */
+export type ImageHoverAnchor = {
+ left: number;
+ top: number;
+ bottom: number;
+ width: number;
+};
+
+/** Distance between the hovered chip and its preview card. */
+const PREVIEW_GAP = 8;
+
+/**
+ * Read-only preview card shared by every image chip (composer draft and
+ * transcript). It renders nothing without a decoded source, never takes pointer
+ * events, and asks its owner to dismiss it when the content moves underneath.
+ */
+export function ImageHoverCard({ src, anchor, onDismiss }: {
+ src: string | null;
+ anchor: ImageHoverAnchor | null;
+ onDismiss?: () => void;
+}) {
+ const cardRef = useRef<HTMLDivElement>(null);
+ const [placement, setPlacement] = useState<"above" | "below">("above");
+ useLayoutEffect(() => {
+ const card = cardRef.current;
+ // A chip on the first line has no room above it.
+ if (!anchor || !card) return;
+ setPlacement(anchor.top - card.offsetHeight - PREVIEW_GAP < 0 ? "below" : "above");
+ }, [anchor, src]);
+ useEffect(() => {
+ if (!anchor || !src || !onDismiss) return;
+ const dismiss = () => onDismiss();
+ window.addEventListener("scroll", dismiss, true);
+ window.addEventListener("resize", dismiss);
+ return () => {
+ window.removeEventListener("scroll", dismiss, true);
+ window.removeEventListener("resize", dismiss);
+ };
+ }, [anchor, src, onDismiss]);
+ if (!anchor || !src) return null;
+ return portalToBody(
+ <div
+ ref={cardRef}
+ className="image-hover-card"
+ data-placement={placement}
+ role="presentation"
+ style={{
+ left: anchor.left + anchor.width / 2,
+ top: placement === "above" ? anchor.top - PREVIEW_GAP : anchor.bottom + PREVIEW_GAP,
+ }}
+ >
+ <img src={src} alt="" draggable={false} />
+ </div>,
+ );
+}
diff --git a/apps/desktop/src/features/chat/composer/ComposerImageHoverPreview.tsx b/apps/desktop/src/features/chat/composer/ComposerImageHoverPreview.tsx
index d82fc69a1..780a77a9c 100644
--- a/apps/desktop/src/features/chat/composer/ComposerImageHoverPreview.tsx
+++ b/apps/desktop/src/features/chat/composer/ComposerImageHoverPreview.tsx
@@ -1,10 +1,7 @@
-import { useCallback, useLayoutEffect, useRef, useState, type RefObject } from "react";
-import { portalToBody } from "../../../lib/portal-visibility";
+import { useCallback, useRef, type RefObject } from "react";
+import { ImageHoverCard } from "../../../components/ImageHoverCard";
import type { ComposerImagePreviewController } from "./hooks/useComposerImagePreview";
-import { useComposerImageHover, type ComposerImageHoverTarget } from "./hooks/useComposerImageHover";
-
-/** Distance between the hovered chip and its preview card. */
-const PREVIEW_GAP = 8;
+import { useComposerImageHover } from "./hooks/useComposerImageHover";
/**
* Hover preview for inline image chips. It stays a read-only card: clicking the
@@ -26,38 +23,12 @@ export function ComposerImageHover({ controller, editorRef }: {
);
const hover = useComposerImageHover(editorRef, idForToken);
// The modal already shows the image; a card behind it would be noise.
- return <ComposerImageHoverCard controller={controller} target={controller.preview ? null : hover} />;
-}
-
-function ComposerImageHoverCard({ controller, target }: {
- controller: ComposerImagePreviewController;
- target: ComposerImageHoverTarget | null;
-}) {
- const cardRef = useRef<HTMLDivElement>(null);
- const [placement, setPlacement] = useState<"above" | "below">("above");
+ const target = controller.preview ? null : hover;
const source = target ? controller.sources?.get(target.id) : undefined;
- const src = source?.status === "ready" ? source.src : null;
- useLayoutEffect(() => {
- const card = cardRef.current;
- if (!target || !card) return;
- // A chip on the first line has no room above it.
- setPlacement(target.anchor.top - card.offsetHeight - PREVIEW_GAP < 0 ? "below" : "above");
- }, [target, src]);
- if (!target || !src) return null;
- return portalToBody(
- <div
- ref={cardRef}
- className="composer-image-hover"
- data-placement={placement}
- role="presentation"
- style={{
- left: target.anchor.left + target.anchor.width / 2,
- top: placement === "above"
- ? target.anchor.top - PREVIEW_GAP
- : target.anchor.bottom + PREVIEW_GAP,
- }}
- >
- <img src={src} alt="" draggable={false} />
- </div>,
+ return (
+ <ImageHoverCard
+ src={source?.status === "ready" ? source.src : null}
+ anchor={target?.anchor ?? null}
+ />
);
}
diff --git a/apps/desktop/src/features/chat/composer/editor.ts b/apps/desktop/src/features/chat/composer/editor.ts
index 04ce64244..1f6f9fec7 100644
--- a/apps/desktop/src/features/chat/composer/editor.ts
+++ b/apps/desktop/src/features/chat/composer/editor.ts
@@ -275,11 +275,6 @@ export function isEditableTextReference(reference: ComposerFileReference): boole
return reference.mimeType?.toLowerCase() === "text/plain" || /\.txt$/i.test(reference.name);
}
-export function isComposerAudioReference(reference: ComposerFileReference): boolean {
- const mime = reference.mimeType?.toLowerCase() ?? "";
- return mime.startsWith("audio/") || AUDIO_FILE_PATTERN.test(reference.name);
-}
-
/** Build the atomic inline chip element for one attachment reference. */
function buildChipElement(
reference: ComposerFileReference,
diff --git a/apps/desktop/src/features/chat/transcript/shared.tsx b/apps/desktop/src/features/chat/transcript/shared.tsx
index fa227cb8f..d1f879925 100644
--- a/apps/desktop/src/features/chat/transcript/shared.tsx
+++ b/apps/desktop/src/features/chat/transcript/shared.tsx
@@ -19,6 +19,7 @@ import {
import { useOpenChatFileRef, useOpenPreviewTarget } from "../../../hooks/use-preview-target";
import { useChatFileMenu } from "../../../hooks/use-chat-file-menu";
import { ContextMenu } from "../../../components/ContextMenu";
+import { ImageHoverCard, type ImageHoverAnchor } from "../../../components/ImageHoverCard";
import { useDisclosureAnchorNotifier } from "../../../lib/disclosure-anchor-context";
import { isThinkingActive, resolveThinkingDisplayMode } from "../../../lib/turn-process";
import { TranscriptSearchContext } from "../../../lib/transcript-search-context";
@@ -502,9 +503,10 @@ export function SessionRefChip({ attachment }: { attachment: MessageAttachment }
}
/**
- * User-message image attachment as a thumbnail. The host resolves the ref
- * into a bounded data URL; an unresolvable load falls back to the file chip.
- * Clicking opens the files viewer on the same contained ref.
+ * User-message image attachment as the same compact chip as any other file
+ * reference. The host resolves the ref into a bounded data URL that the hover
+ * (or focus) card shows; an unresolved load simply keeps the chip. Clicking
+ * opens the files viewer on the same contained ref.
*/
export function MessageAttachmentImage({
attachment,
@@ -513,34 +515,36 @@ export function MessageAttachmentImage({
attachment: MessageAttachment;
onOpenFile: (path: string, baseDir?: string, mimeType?: string) => void;
}) {
- const { fileMenu, openFileMenu, closeFileMenu } = useChatFileMenu();
const dataUrl = useReferencedImageDataUrl(attachment.ref, attachment.mimeType);
- if (!dataUrl) {
- return (
- <FileRefChip
- name={attachment.name}
- path={attachment.ref}
- kind="image"
- mimeType={attachment.mimeType}
- onOpen={onOpenFile}
- />
- );
- }
+ const [anchor, setAnchor] = useState<ImageHoverAnchor | null>(null);
+ const chipRef = useRef<HTMLSpanElement>(null);
+ const reveal = () => {
+ const element = chipRef.current;
+ if (!element) return;
+ const rect = element.getBoundingClientRect();
+ setAnchor({ left: rect.left, top: rect.top, bottom: rect.bottom, width: rect.width });
+ };
+ const dismiss = () => setAnchor(null);
return (
<>
- <button
- type="button"
- className="message-attachment-image"
+ <span
+ ref={chipRef}
+ className="message-attachment-image-chip"
role="listitem"
- title={`${attachment.name} — ${attachment.ref}`}
- onClick={() =>
- useAppStore.getState().openFileInWorkPanel(attachment.ref, attachment.mimeType)
- }
- onContextMenu={(event) => openFileMenu(event, { path: attachment.ref })}
+ onPointerEnter={reveal}
+ onPointerLeave={dismiss}
+ onFocus={reveal}
+ onBlur={dismiss}
>
- <img src={dataUrl} alt={attachment.name} />
- </button>
- <ContextMenu state={fileMenu} onClose={closeFileMenu} />
+ <FileRefChip
+ name={attachment.name}
+ path={attachment.ref}
+ kind="image"
+ mimeType={attachment.mimeType}
+ onOpen={onOpenFile}
+ />
+ </span>
+ <ImageHoverCard src={dataUrl} anchor={anchor} onDismiss={dismiss} />
</>
);
}
diff --git a/apps/desktop/src/styles/composer-image-preview.css b/apps/desktop/src/styles/composer-image-preview.css
index 67295ec3f..211e1539f 100644
--- a/apps/desktop/src/styles/composer-image-preview.css
+++ b/apps/desktop/src/styles/composer-image-preview.css
@@ -1,27 +1,3 @@
-/* Read-only hover card for an inline image chip in the draft. */
-.composer-image-hover {
- position: fixed;
- z-index: 55;
- box-sizing: border-box;
- padding: 3px;
- background: var(--ds-bg-elevated);
- border: 1px solid var(--ds-border-default);
- border-radius: var(--radius-md);
- box-shadow: var(--ds-shadow-dialog);
- pointer-events: none;
-}
-
-.composer-image-hover[data-placement="above"] { transform: translate(-50%, -100%); }
-.composer-image-hover[data-placement="below"] { transform: translate(-50%, 0); }
-
-.composer-image-hover img {
- display: block;
- max-width: min(240px, 40vw);
- max-height: min(240px, 40dvh);
- border-radius: var(--radius-2xs);
- object-fit: contain;
-}
-
.composer-image-preview {
box-sizing: border-box;
position: fixed;
diff --git a/apps/desktop/src/styles/image-hover-card.css b/apps/desktop/src/styles/image-hover-card.css
new file mode 100644
index 000000000..b3b928bf5
--- /dev/null
+++ b/apps/desktop/src/styles/image-hover-card.css
@@ -0,0 +1,23 @@
+/* Read-only preview card for a hovered image chip: composer draft or message. */
+.image-hover-card {
+ position: fixed;
+ z-index: 55;
+ box-sizing: border-box;
+ padding: 3px;
+ background: var(--ds-bg-elevated);
+ border: 1px solid var(--ds-border-default);
+ border-radius: var(--radius-md);
+ box-shadow: var(--ds-shadow-dialog);
+ pointer-events: none;
+}
+
+.image-hover-card[data-placement="above"] { transform: translate(-50%, -100%); }
+.image-hover-card[data-placement="below"] { transform: translate(-50%, 0); }
+
+.image-hover-card img {
+ display: block;
+ max-width: min(240px, 40vw);
+ max-height: min(240px, 40dvh);
+ border-radius: var(--radius-2xs);
+ object-fit: contain;
+}
diff --git a/apps/desktop/src/styles/messages.css b/apps/desktop/src/styles/messages.css
index e23b61edb..dbed064fe 100644
--- a/apps/desktop/src/styles/messages.css
+++ b/apps/desktop/src/styles/messages.css
@@ -1715,29 +1715,12 @@
white-space: nowrap;
}
-.message-attachment-image {
+/* A user-message image is a chip like any other attachment; its preview card
+ appears on hover or focus and is rendered outside the message row. */
+.message-attachment-image-chip {
display: inline-flex;
min-width: 0;
align-items: center;
- justify-content: center;
- border-radius: var(--radius-md);
- padding: 3px;
- background: var(--ds-tile);
- cursor: pointer;
- overflow: hidden;
-}
-
-.message-attachment-image:hover {
- background: var(--ds-raised);
- box-shadow: 0 0 0 2px color-mix(in oklab, var(--ds-accent) 18%, transparent);
-}
-
-.message-attachment-image img {
- display: block;
- max-width: 220px;
- max-height: 220px;
- object-fit: contain;
- border-radius: var(--radius-sm);
}
.message-row.assistant .message-bubble,
diff --git a/apps/desktop/test/chat-file-reveal-menu.test.mjs b/apps/desktop/test/chat-file-reveal-menu.test.mjs
index 3d9c9718c..294263a32 100644
--- a/apps/desktop/test/chat-file-reveal-menu.test.mjs
+++ b/apps/desktop/test/chat-file-reveal-menu.test.mjs
@@ -345,9 +345,11 @@ test("every transcript surface that names a file opens that item", () => {
/const \{ fileMenu, openFileMenu, closeFileMenu \} = useChatFileMenu\(\)/,
);
assert.match(shared, /onContextMenu=\{\(event\) => openFileMenu\(event, \{ path \}\)/);
+ // An image attachment is the same chip as any other attachment now, so that
+ // chip carries the file menu and the shared preview card hangs off it.
assert.match(
shared,
- /onContextMenu=\{\(event\) => openFileMenu\(event, \{ path: attachment\.ref \}\)/,
+ /<ImageHoverCard src=\{dataUrl\} anchor=\{anchor\} onDismiss=\{dismiss\} \/>/,
);
assert.match(shared, /<ContextMenu state=\{fileMenu\} onClose=\{closeFileMenu\} \/>/);
// A tool row's summary and a tool result's file and match lists name files
diff --git a/apps/desktop/test/composer-inline-image-chips.test.mjs b/apps/desktop/test/composer-inline-image-chips.test.mjs
index fbbd5064b..ee558b670 100644
--- a/apps/desktop/test/composer-inline-image-chips.test.mjs
+++ b/apps/desktop/test/composer-inline-image-chips.test.mjs
@@ -5,11 +5,13 @@ import { readComposerModule, readComposerSource } from "./helpers/composer-sourc
const read = (path) => readFile(new URL(path, import.meta.url), "utf8");
-const [composer, editor, hoverCard, hoverHook, styles, submitHook] = await Promise.all([
+const [composer, editor, hoverCard, hoverHook, card, cardStyles, styles, submitHook] = await Promise.all([
readComposerSource(),
readComposerModule("editor.ts"),
readComposerModule("ComposerImageHoverPreview.tsx"),
readComposerModule("hooks/useComposerImageHover.ts"),
+ read("../src/components/ImageHoverCard.tsx"),
+ read("../src/styles/image-hover-card.css"),
read("../src/styles/composer-image-preview.css"),
readComposerModule("hooks/useComposerSubmit.ts"),
]);
@@ -34,12 +36,15 @@ test("hovering an image chip reveals a read-only preview card", () => {
assert.match(hoverHook, /getBoundingClientRect\(\)/);
// A chip that moves under the pointer must not leave a stale card behind.
assert.match(hoverHook, /editor\.addEventListener\("input", hide\)/);
- assert.match(hoverCard, /className="composer-image-hover"/);
- assert.match(hoverCard, /data-placement=\{placement\}/);
- assert.match(styles, /\.composer-image-hover img \{[\s\S]*?max-width: min\(240px, 40vw\)/);
- assert.match(styles, /\.composer-image-hover \{[\s\S]*?pointer-events: none/);
+ // One shared card serves the draft and the transcript.
+ assert.match(hoverCard, /<ImageHoverCard/);
+ assert.match(hoverCard, /anchor=\{target\?\.anchor \?\? null\}/);
+ assert.match(card, /className="image-hover-card"/);
+ assert.match(card, /data-placement=\{placement\}/);
+ assert.match(cardStyles, /\.image-hover-card img \{[\s\S]*?max-width: min\(240px, 40vw\)/);
+ assert.match(cardStyles, /\.image-hover-card \{[\s\S]*?pointer-events: none/);
// The modal owns the open image; the card would only be noise behind it.
- assert.match(hoverCard, /target=\{controller\.preview \? null : hover\}/);
+ assert.match(hoverCard, /const target = controller\.preview \? null : hover;/);
});
test("image tokens leave the prompt text only at submission", () => {
diff --git a/apps/desktop/test/message-image-display.test.mjs b/apps/desktop/test/message-image-display.test.mjs
index 21fe3cb3c..dfd102010 100644
--- a/apps/desktop/test/message-image-display.test.mjs
+++ b/apps/desktop/test/message-image-display.test.mjs
@@ -38,14 +38,18 @@ test("renderer hook loads referenced image data URLs with a scoped bounded cache
assert.match(hook, /https\?\|data\|blob/);
});
-test("user message image attachments render as thumbnails", () => {
+test("user message image attachments render as chips with a hover card", () => {
assert.match(transcript, /function MessageAttachmentImage\(/);
assert.match(transcript, /useReferencedImageDataUrl\(attachment\.ref, attachment\.mimeType\)/);
- assert.match(transcript, /className="message-attachment-image"/);
+ assert.match(transcript, /className="message-attachment-image-chip"/);
+ assert.match(transcript, /role="listitem"/);
+ assert.match(transcript, /onOpen=\{onOpenFile\}/);
+ // One shared preview card serves the draft and the transcript.
assert.match(
transcript,
- /openFileInWorkPanel\(attachment\.ref, attachment\.mimeType\)/,
+ /import \{ ImageHoverCard, type ImageHoverAnchor \} from "\.\.\/\.\.\/\.\.\/components\/ImageHoverCard";/,
);
+ assert.match(transcript, /<ImageHoverCard src=\{dataUrl\} anchor=\{anchor\} onDismiss=\{dismiss\} \/>/);
assert.match(
transcript,
/attachment\.kind === "image" \?/,
diff --git a/apps/desktop/test/renderer-review-fixes.test.mjs b/apps/desktop/test/renderer-review-fixes.test.mjs
index 5fd7049bd..526d789a6 100644
--- a/apps/desktop/test/renderer-review-fixes.test.mjs
+++ b/apps/desktop/test/renderer-review-fixes.test.mjs
@@ -57,14 +57,14 @@ test("window controls draw through the icon wrappers", () => {
});
-test("attachment thumbnails are tone tiles, not stroked boxes (D297)", () => {
- const block = messages.slice(
- messages.indexOf(".message-attachment-image {"),
- messages.indexOf(".message-attachment-image img {"),
- );
- assert.doesNotMatch(block, /border(?:-color)?:/);
- assert.match(block, /background: var\(--ds-tile\);/);
- assert.match(block, /:hover \{[\s\S]*?background: var\(--ds-raised\);/);
+test("message image chips carry no tile or stroke of their own (D297)", () => {
+ const start = messages.indexOf(".message-attachment-image-chip {");
+ assert.notEqual(start, -1, "message image chip rule is missing");
+ const block = messages.slice(start, messages.indexOf("}", start));
+ // The shared composer chip and the preview card own the surface; the wrapper
+ // stays a bare inline layout box.
+ assert.doesNotMatch(block, /background:|border|box-shadow/);
+ assert.match(block, /display: inline-flex;/);
});
test("dead components are gone", () => {
diff --git a/apps/desktop/test/session-reference-ui.test.mjs b/apps/desktop/test/session-reference-ui.test.mjs
index d85addd63..7fcc92c2a 100644
--- a/apps/desktop/test/session-reference-ui.test.mjs
+++ b/apps/desktop/test/session-reference-ui.test.mjs
@@ -79,6 +79,7 @@ const shared = load(new URL("../src/features/chat/transcript/shared.tsx", import
useVerifiedChatText: (text) => [{ kind: "text", text: String(text ?? "") }],
},
"../../../components/ContextMenu": { ContextMenu: () => null },
+ "../../../components/ImageHoverCard": { ImageHoverCard: () => null },
"../../../components/Markdown": {
Markdown: ({ source }) => source,
useCopy: () => ({ copied: false, copy: () => {} }),
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index 8638d3c60..6efad36d7 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -1738,8 +1738,10 @@ Single message render — either user (plaintext) or assistant (markdown streami
collapse. Serialized `@path` file references render as compact leaf-name
chips matching the composer node (icon + ellipsized name; canonical path in
the tooltip and accessible name). Image attachments that are not already
- inlined as `@path` chips render as bounded thumbnails (data URL from
- `fs/readImageDataUrl`); unresolved loads keep the chip. A referenced
+ inlined as `@path` chips render as the same compact image chip; hovering or
+ focusing it reveals the bounded data URL (`fs/readImageDataUrl`) in a
+ read-only preview card above the chip (below it when the chip sits at the
+ top), and an unresolved load leaves the chip alone. A referenced
conversation (`kind: "session"`) renders as a chat-icon chip labeled with the
shared reference label and the referenced title; the tooltip and accessible
name come from the catalog, and activating it opens that conversation
@@ -1767,7 +1769,7 @@ Single message render — either user (plaintext) or assistant (markdown streami
primary folder in the side browser. A 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 resolved
- image thumbnail resolves and opens the same way. A chip whose reference
+ image chip resolves and opens the same way. A chip whose reference
matches nothing opens nothing and reports itself; an absolute path outside
every allowed root reports the access limit separately. The OS default application
is no longer what this click does.
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index a4b0785ec..4cb847eb5 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -12579,7 +12579,7 @@ are withdrawn with ADR 0165.
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. 9)
+ an attachment image chip; then right-click a reference that matches nothing. 9)
On that chip, use Copy full path and Copy relative path, then do the same on a
reference that resolves in the session scratch store.
- **Expected**:
@@ -12587,7 +12587,7 @@ are withdrawn with ADR 0165.
file's own folder (Show in folder) and both of its addresses (Copy full
path, Copy relative path). 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 items, and a reference that matches
+ attachment image chip offer the same items, and a reference that matches
nothing reports itself instead of revealing a same-named file elsewhere.
- A copy writes exactly what it names: the absolute address for the full copy
and the project-relative spelling for the relative one; a scratch or
@@ -12789,9 +12789,9 @@ are withdrawn with ADR 0165.
`docs/pixel.png`. The user has previously pasted an image so the session
JSONL stores an `attachments/<sha256>` image ref with a stored mimeType.
- **Steps**:
- 1. Reopen the session. Confirm the pasted image renders as a thumbnail, not
- only a file chip.
- 2. Click the thumbnail. Confirm the host files viewer opens on that
+ 1. Reopen the session. Confirm the pasted image renders as a chip like any
+ other attachment, and that hovering or focusing it reveals its preview card.
+ 2. Click the chip. Confirm the host files viewer opens on that
attachment ref and shows the image.
3. Send a turn whose assistant markdown includes `![](docs/pixel.png)` and
`![](/etc/passwd)`. Confirm the workspace image renders inline and the
@@ -12801,7 +12801,7 @@ are withdrawn with ADR 0165.
- **Expected**:
- Contained image refs display inline within the 5MB cap.
- Outside-root paths and mime spoofing of non-image extensions stay closed.
- - Clicking a resolved thumbnail opens the host `file:` tab, not the OS
+ - Clicking a resolved image chip opens the host `file:` tab, not the OS
handler.
- **Specs linked**: `03-runtime/01-ipc-protocol.md`,
`04-ux/08-component-spec.md` §8.3, ADR 0172, `08-meta/decisions-log.md` (D334)
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 a2bba4b34..86d56593b 100644
--- a/docs/zh-CN/spec/04-ux/08-component-spec.md
+++ b/docs/zh-CN/spec/04-ux/08-component-spec.md
@@ -1242,7 +1242,7 @@ row 而不是在转录本中添加树镶边。
聊天轮流而不是全角块。气泡按提示的 max-content 收缩,而不是撑到该上限;内联文件芯片使用确定的 240px 名称上限,因此粘贴文件加上短提示仍保持紧凑。用户正文是明文
保留硬换行符(`white-space: pre-wrap`);
仅应用 trailing/leading 输入框修剪,从不应用内部换行符
- 崩溃。序列化的 `@path` 文件引用画成与输入框一致的叶子名芯片(图标 + 省略号文件名;规范路径放在工具提示和无障碍名称里)。未内联成 `@path` 芯片的图片附件渲染为有界缩略图(`fs/readImageDataUrl` 的 data URL);无法解析时保留芯片。消息正文里的裸路径 token 识别 Unicode 字母与数字。在用户消息正文中,它们只是候选:现有的 `fs/resolveRef` 查找确认是真实文件后才显示芯片。等待、未找到或失败的查找保留原文,包括 `使用llama.cpp`。显式 `@path` 引用和结构化附件保留现有芯片,不做猜测查询。每条消息最多检查 32 个唯一候选,可见行之间最多 4 个并发查找;其余候选保持纯文本。确认结果绑定到当前消息文本、工作区路径和会话;任一变化都会丢弃旧结果并取消排队的工作。之后新建的文件在消息重新挂载或作用域变化时再考虑,不轮询。非 ASCII 文件名仍受支持。绝对路径与 `~/` 整体匹配,工作区之外(以及一切家目录路径)保持纯文本,而不是渲染一个永远打不开的芯片——包含边界不变(D322)。点击芯片先经 `pi-desktop/fs/resolveRef` 补全引用——该通道搜索整个打开的项目,按项目组文件夹顺序、主文件夹优先(ADR 0263)——再按解析结果打开:项目文件在随应用打包的 `pi.file-manager` 工作面板视图中打开(该视图不可用时退回宿主 `file:` 选项卡),会话临时目录或附件文件在宿主 `file:` 选项卡中打开,主文件夹中的 `.html`/`.htm` 仍由侧边浏览器打开。交给该视图的地址跟随应答的文件夹:主文件夹中的文件用项目内相对路径传递,同一项目的同级文件夹中的文件用绝对路径传递,与会话临时目录和附件文件一致。已解析的图片缩略图按同样规则打开。什么都没匹配到的芯片不打开任何东西,而是自己报告出来;系统默认应用不再由这次点击触发。HTTP(S) URL 仍是内联文本链接;裸 URL 保留路径、查询和片段中成对的圆括号,正文包裹网址时多出的右括号不属于链接;紧跟 URL 右括号的句末标点也不属于链接,但 `(draft).html` 这样的后缀仍保留,在侧边浏览器打开;长 URL 在板内换行并保持逻辑开始对齐,而不是继承浏览器的居中按钮文本。
+崩溃。序列化的 `@path` 文件引用画成与输入框一致的叶子名芯片(图标 + 省略号文件名;规范路径放在工具提示和无障碍名称里)。未内联成 `@path` 芯片的图片附件渲染为同样的图片芯片;悬停或聚焦该芯片会在其上方(芯片位于顶部时改在下方)浮出只读预览小卡,内容来自有界的 `fs/readImageDataUrl` data URL,无法解析时保留芯片。消息正文里的裸路径 token 识别 Unicode 字母与数字。在用户消息正文中,它们只是候选:现有的 `fs/resolveRef` 查找确认是真实文件后才显示芯片。等待、未找到或失败的查找保留原文,包括 `使用llama.cpp`。显式 `@path` 引用和结构化附件保留现有芯片,不做猜测查询。每条消息最多检查 32 个唯一候选,可见行之间最多 4 个并发查找;其余候选保持纯文本。确认结果绑定到当前消息文本、工作区路径和会话;任一变化都会丢弃旧结果并取消排队的工作。之后新建的文件在消息重新挂载或作用域变化时再考虑,不轮询。非 ASCII 文件名仍受支持。绝对路径与 `~/` 整体匹配,工作区之外(以及一切家目录路径)保持纯文本,而不是渲染一个永远打不开的芯片——包含边界不变(D322)。点击芯片先经 `pi-desktop/fs/resolveRef` 补全引用——该通道搜索整个打开的项目,按项目组文件夹顺序、主文件夹优先(ADR 0263)——再按解析结果打开:项目文件在随应用打包的 `pi.file-manager` 工作面板视图中打开(该视图不可用时退回宿主 `file:` 选项卡),会话临时目录或附件文件在宿主 `file:` 选项卡中打开,主文件夹中的 `.html`/`.htm` 仍由侧边浏览器打开。交给该视图的地址跟随应答的文件夹:主文件夹中的文件用项目内相对路径传递,同一项目的同级文件夹中的文件用绝对路径传递,与会话临时目录和附件文件一致。已解析的图片芯片按同样规则打开。什么都没匹配到的芯片不打开任何东西,而是自己报告出来;系统默认应用不再由这次点击触发。HTTP(S) URL 仍是内联文本链接;裸 URL 保留路径、查询和片段中成对的圆括号,正文包裹网址时多出的右括号不属于链接;紧跟 URL 右括号的句末标点也不属于链接,但 `(draft).html` 这样的后缀仍保留,在侧边浏览器打开;长 URL 在板内换行并保持逻辑开始对齐,而不是继承浏览器的居中按钮文本。
- 被引用的对话(`kind: "session"`)画成聊天图标芯片,标签是共享的引用标签加被引用
标题;工具提示与无障碍名称来自语言目录,激活它会打开那段对话(§20B)。
- Assistant:透明表面,左对齐,Markdown 完全渲染
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 282ca7b02..2edcd127c 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
@@ -7231,7 +7231,7 @@ eleven-tool-round desktop paths are verified by
- 点击工作区源文件芯片后,该文件在文件管理器工作面板视图中打开;芯片点击不再打开宿主的 `file:` 选项卡,也不再交给系统默认应用。
- 点击临时目录芯片时,文件在宿主的 `file:` 选项卡中按其绝对路径打开——它位于文件管理器项目根之外。
- 点击项目第二个文件夹里那个文件的芯片时,该文件在文件管理器视图中打开:补全会搜索整个项目组、主文件夹优先,同级文件夹里的文件用绝对路径寻址,因为相对路径永远指主文件夹(ADR 0263)。
- - 右键文件引用会打开渲染器自己的菜单:在文件夹中显示该文件,并复制它的完整地址与相对地址;助手 Markdown 里的行内代码引用、文件链接与本地图片、工具行自己的文件路径、工具结果的文件列表或匹配列表中的路径、图片附件缩略图都提供这几项,而什么都没匹配到的引用会自己报告出来,而不是去显示别处同名的那份文件。复制写出的就是它说的地址:完整地址即绝对路径,相对地址即项目内相对写法;临时目录或附件文件没有相对地址,会直接说明,而不是把绝对路径当成相对地址写出去。
+ - 右键文件引用会打开渲染器自己的菜单:在文件夹中显示该文件,并复制它的完整地址与相对地址;助手 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`、
@@ -7333,11 +7333,11 @@ eleven-tool-round desktop paths are verified by
- **前提条件**:工作区含 `docs/pixel.png` 的 Agent 会话。用户曾粘贴图片,会话 JSONL 存有带 mimeType 的 `attachments/<sha256>` 图片引用。
- **步骤**:
- 1. 重新打开该会话。确认粘贴图片渲染为缩略图,而不只是文件芯片。
- 2. 点击缩略图。确认宿主文件查看器打开该附件引用并显示图片。
+ 1. 重新打开该会话。确认粘贴图片与其它附件一样是芯片,悬停或聚焦时浮出预览小卡。
+ 2. 点击芯片。确认宿主文件查看器打开该附件引用并显示图片。
3. 发送一回合,助手 Markdown 含 `![](docs/pixel.png)` 和 `![](/etc/passwd)`。确认工作区图片内联显示,工作区外路径不加载文件字节。
4. 确认 `fs/readImageDataUrl` 在 `ref: "/etc/passwd"` 且 `mimeType: "image/png"` 时返回 `missing`,而不是 data URL。
-- **预期**:受限图片引用在 5MB 上限内内联显示;工作区外路径与对非图片扩展名的 mime 伪造保持关闭;点击已解析缩略图打开宿主 `file:` 选项卡,而不是系统默认应用。
+- **预期**:受限图片引用在 5MB 上限内内联显示;工作区外路径与对非图片扩展名的 mime 伪造保持关闭;点击已解析图片芯片打开宿主 `file:` 选项卡,而不是系统默认应用。
- **链接规格**:`03-runtime/01-ipc-protocol.md`、`04-ux/08-component-spec.md` §8.3、ADR 0172、`08-meta/decisions-log.md`(D334)
- **验收**:C(对话与流)、D(工作区)、安全、质量
- **里程碑**:M5
diff --git a/scripts/e2e/composer-paste.tsx b/scripts/e2e/composer-paste.tsx
index 6d8cf391f..4b76a5fca 100644
--- a/scripts/e2e/composer-paste.tsx
+++ b/scripts/e2e/composer-paste.tsx
@@ -1,4 +1,4 @@
-import { serializeInlineComposerFileReferences } from "@pi-desktop/shared";
+import { serializeInlineComposerFileReferences, type MessageAttachment } from "@pi-desktop/shared";
import { useComposerInputHistory } from "../../apps/desktop/src/features/chat/composer/hooks/useComposerInputHistory";
import type { AppState } from "../../apps/desktop/src/stores/app-state";
import { createQueueSlice } from "../../apps/desktop/src/stores/slices/queue-slice";
@@ -29,7 +29,7 @@ import {
} from "../../apps/desktop/src/features/chat/composer/editor";
import { api } from "../../apps/desktop/src/lib/api";
import { FilesTab } from "../../apps/desktop/src/components/workpanel/FilesTab";
-import { FileRefChip } from "../../apps/desktop/src/features/chat/transcript/shared";
+import { FileRefChip, MessageAttachmentImage } from "../../apps/desktop/src/features/chat/transcript/shared";
import { useOpenChatFileRef } from "../../apps/desktop/src/hooks/use-preview-target";
import {
readComposerDraft,
@@ -573,11 +573,43 @@ globalThis.composerPasteProbe = async () => {
const close = () => flushSync(() => button(i18n.t("common.close")).click());
// Hovering the chip reveals its preview card without opening the modal.
chip.dispatchEvent(new PointerEvent("pointerover", { bubbles: true }));
- await until(() => document.querySelector<HTMLImageElement>(".composer-image-hover img")?.naturalWidth === 1,
+ await until(() => document.querySelector<HTMLImageElement>(".image-hover-card img")?.naturalWidth === 1,
"hover preview card missing");
chip.dispatchEvent(new PointerEvent("pointerout", { bubbles: true }));
- await until(() => !document.querySelector(".composer-image-hover"), "hover preview card outlived the pointer");
+ await until(() => !document.querySelector(".image-hover-card"), "hover preview card outlived the pointer");
editor.focus();
+ // A sent message's image attachment is that same chip, and hovering it shows
+ // the shared preview card instead of an inline thumbnail.
+ const messageHost = document.createElement("div");
+ messageHost.style.cssText = "position: relative;";
+ document.body.append(messageHost);
+ const messageRoot = createRoot(messageHost);
+ try {
+ const messageAttachment: MessageAttachment = {
+ kind: "image",
+ ref: imageReference.path,
+ name: imageReference.name,
+ };
+ flushSync(() => messageRoot.render(
+ <I18nextProvider i18n={i18n}>
+ <div role="list">
+ <MessageAttachmentImage attachment={messageAttachment} onOpenFile={noop} />
+ </div>
+ </I18nextProvider>,
+ ));
+ await new Promise(requestAnimationFrame);
+ const messageChip = messageHost.querySelector<HTMLElement>(".message-attachment-image-chip .chat-file-chip");
+ assert(messageChip, "a message image attachment must render as a chip");
+ assert(!messageHost.querySelector("img"), "a message image attachment must not inline a thumbnail");
+ messageChip!.dispatchEvent(new PointerEvent("pointerover", { bubbles: true }));
+ await until(() => document.querySelector<HTMLImageElement>(".image-hover-card img")?.naturalWidth === 1,
+ "message hover preview card missing");
+ messageChip!.dispatchEvent(new PointerEvent("pointerout", { bubbles: true }));
+ await until(() => !document.querySelector(".image-hover-card"), "message hover card outlived the pointer");
+ } finally {
+ flushSync(() => messageRoot.unmount());
+ messageHost.remove();
+ }
setEditorCaret(editor, 7);
flushSync(() => chip.click());
assert(dialog(), "image attachment must open an overlay instead of the work panel");