Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(transcript): keep a message's image chip in the body text flow
vastsaa840a14db8d3
diff --git a/apps/desktop/src/features/chat/transcript/MessageRow.tsx b/apps/desktop/src/features/chat/transcript/MessageRow.tsxindex 3bba2f174..cd0e3e012 100644--- a/apps/desktop/src/features/chat/transcript/MessageRow.tsx+++ b/apps/desktop/src/features/chat/transcript/MessageRow.tsx@@ -123,6 +123,35 @@ export const MessageRow = memo(function MessageRow({attachment.kind !== "session" && !inline.has(attachment.ref),);}, [message.attachments, message.content, workspaceRoot]);+ // An attachment the body does not already name inline continues the body+ // text instead of taking a line of its own above it.+ const attachmentChips = extraAttachments.length ? (+ <span+ className="message-attachments"+ role="list"+ aria-label={t("chat.messageAttachments")}+ >+ {extraAttachments.map((attachment) =>+ attachment.kind === "image" ? (+ <MessageAttachmentImage+ key={`${attachment.ref}:${attachment.name}`}+ attachment={attachment}+ onOpenFile={openFileRef}+ />+ ) : (+ <span key={`${attachment.ref}:${attachment.name}`} role="listitem">+ <FileRefChip+ name={attachment.name}+ path={attachment.ref}+ kind={attachment.kind}+ mimeType={attachment.mimeType}+ onOpen={openFileRef}+ />+ </span>+ ),+ )}+ </span>+ ) : null;const beginEdit = async () => {if (!editableUserMessage || isRunning || loadingEdit) return;const request = new AbortController();@@ -256,36 +285,6 @@ export const MessageRow = memo(function MessageRow({</form>) : isUser ? (<>- {extraAttachments.length ? (- <div- className="message-attachments"- role="list"- aria-label={t("chat.messageAttachments")}- >- {extraAttachments.map((attachment) =>- attachment.kind === "image" ? (- <MessageAttachmentImage- key={`${attachment.ref}:${attachment.name}`}- attachment={attachment}- onOpenFile={openFileRef}- />- ) : (- <span- key={`${attachment.ref}:${attachment.name}`}- role="listitem"- >- <FileRefChip- name={attachment.name}- path={attachment.ref}- kind={attachment.kind}- mimeType={attachment.mimeType}- onOpen={openFileRef}- />- </span>- ),- )}- </div>- ) : null}{message.content ? (<div className="message-user-text selectable">{editableUserMessage && message.command ? (@@ -305,8 +304,9 @@ export const MessageRow = memo(function MessageRow({) : (<LinkifiedText text={String(message.content || "")} attachments={message.attachments} />)}+ {attachmentChips}</div>- ) : null}+ ) : attachmentChips}</>) : (<div className="prose-chat">diff --git a/apps/desktop/src/styles/messages.css b/apps/desktop/src/styles/messages.cssindex c785789bc..5f9203a0e 100644--- a/apps/desktop/src/styles/messages.css+++ b/apps/desktop/src/styles/messages.css@@ -1697,11 +1697,13 @@}.message-attachments {- display: flex;+ display: inline-flex;max-width: 100%;flex-wrap: wrap;gap: 5px;- margin-bottom: 7px;+ /* The chips continue the body line instead of heading it. */+ margin-left: 4px;+ vertical-align: middle;}.message-row.user .message-attachments {diff --git a/apps/desktop/test/session-reference-ui.test.mjs b/apps/desktop/test/session-reference-ui.test.mjsindex 4a17dae02..ce042e543 100644--- a/apps/desktop/test/session-reference-ui.test.mjs+++ b/apps/desktop/test/session-reference-ui.test.mjs@@ -222,6 +222,32 @@ test("a user message shows the reference as its body chip, not a second block",assert.doesNotMatch(html, /pi-desktop:\/\/session\/session-a/, "the raw link is replaced by the chip");});+test("an extra attachment chip continues the body text instead of heading it", () => {+ locale = "en";+ const withImage = {+ ...userMessage,+ content: "look at this",+ attachments: [{ kind: "image", name: "shot.png", ref: "attachments/abc" }],+ };+ const html = renderRow(withImage);+ const bodyAt = html.indexOf("message-user-text");+ assert.notEqual(bodyAt, -1, "the body text container is missing");+ assert.doesNotMatch(+ html.slice(0, bodyAt),+ /message-attachments/,+ "no attachment block above the body",+ );+ assert.match(+ html.slice(bodyAt),+ /class="message-attachments"/,+ "the chip lives inside the body text container",+ );+ assert.ok(+ html.indexOf("look at this") < html.indexOf("message-attachments"),+ "the body text comes before its attachment chip",+ );+});+test("a referenced conversation is not rendered as a file chip", () => {locale = "en";const withFile = {diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.mdindex ac9907d86..068ac5243 100644--- a/docs/spec/04-ux/08-component-spec.md+++ b/docs/spec/04-ux/08-component-spec.md@@ -1738,10 +1738,12 @@ Single message render — either user (plaintext) or assistant (markdown streamicollapse. Serialized `@path` file references render as compact leaf-namechips matching the composer node (icon + ellipsized name; canonical path inthe tooltip and accessible name). Image attachments that are not already- 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+ inlined as `@path` chips render as the same compact image chip inside the+ body's own text flow, continuing the message text instead of heading it on a+ line of its own. Hovering or focusing the chip reveals the bounded data URL+ (`fs/readImageDataUrl`) in a read-only preview card above it (below it when+ the chip sits at the top), and an unresolved load leaves the chip alone. A+ referencedconversation (`kind: "session"`) renders as a chat-icon chip labeled with theshared reference label and the referenced title; the tooltip and accessiblename come from the catalog, and activating it opens that conversationdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 7b3b2ed55..2d6e59c8d 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -12801,7 +12801,8 @@ are withdrawn with ADR 0165.JSONL stores an `attachments/<sha256>` image ref with a stored mimeType.- **Steps**: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.+ other attachment, continuing the body text instead of heading it, and that+ hovering or focusing it reveals its preview card.2. Click the chip. Confirm the host files viewer opens on thatattachment ref and shows the image.3. Send a turn whose assistant markdown includes `` anddiff --git a/docs/zh-CN/spec/04-ux/08-component-spec.md b/docs/zh-CN/spec/04-ux/08-component-spec.mdindex b201bfdca..d2972c5f8 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.mdindex 0a3e3eef4..fad21938f 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@@ -7339,7 +7339,7 @@ eleven-tool-round desktop paths are verified by- **前提条件**:工作区含 `docs/pixel.png` 的 Agent 会话。用户曾粘贴图片,会话 JSONL 存有带 mimeType 的 `attachments/<sha256>` 图片引用。- **步骤**:- 1. 重新打开该会话。确认粘贴图片与其它附件一样是芯片,悬停或聚焦时浮出预览小卡。+ 1. 重新打开该会话。确认粘贴图片与其它附件一样是芯片、接在正文之后而不是排在正文上方,悬停或聚焦时浮出预览小卡。2. 点击芯片。确认宿主文件查看器打开该附件引用并显示图片。3. 发送一回合,助手 Markdown 含 `` 和 ``。确认工作区图片内联显示,工作区外路径不加载文件字节。4. 确认 `fs/readImageDataUrl` 在 `ref: "/etc/passwd"` 且 `mimeType: "image/png"` 时返回 `missing`,而不是 data URL。