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(desktop): open conversation MP4 attachments with the system player
yuxinobb0984b4dc3b
diff --git a/apps/desktop/electron/main/ipc/workspace-ipc.ts b/apps/desktop/electron/main/ipc/workspace-ipc.tsindex 9a990b0df..94015c57c 100644--- a/apps/desktop/electron/main/ipc/workspace-ipc.ts+++ b/apps/desktop/electron/main/ipc/workspace-ipc.ts@@ -2,7 +2,7 @@ import { BrowserWindow, dialog, shell, type OpenDialogOptions } from "electron";import { dirname } from "node:path";import { homedir } from "node:os";import { existsSync, statSync } from "node:fs";-import { realpath } from "node:fs/promises";+import { realpath, stat } from "node:fs/promises";import { isAbsolute, join, resolve } from "node:path";import {ErrorCodes,@@ -32,9 +32,9 @@ import {listDir,readOpenableFile,readOpenableImage,- resolveOpenablePath,resolveRealOpenablePath,} from "@pi-desktop/host-runtime";+import { openableMp4Path } from "../open-attachment-video";import { resolveChatFileRef } from "../chat-ref-resolve";import { getWorkspaceFileIndex } from "../fs-index";import {@@ -870,10 +870,11 @@ export function registerWorkspaceIpc({return { ok: true };});- handle(IPC.invoke.fsOpen, async (input: { path?: string } = {}) => {+ handle(IPC.invoke.fsOpen, async (input: { path?: string; mimeType?: string } = {}) => {const workspaceRoot = await optionalWorkspaceRoot();- const target = resolveOpenablePath(- String(input.path ?? ""),+ const requested = String(input.path ?? "").trim();+ const target = await resolveRealOpenablePath(+ requested,workspaceRoot,await fsExtraRoots(workspaceRoot),);@@ -882,7 +883,13 @@ export function registerWorkspaceIpc({errorCode: ErrorCodes.INVALID_ARGUMENT,});}- const openError = await shell.openPath(stripWinLongPrefix(target));+ if (!(await stat(target)).isFile()) {+ throw Object.assign(new Error("not a file"), {+ errorCode: ErrorCodes.INVALID_ARGUMENT,+ });+ }+ const openPath = await openableMp4Path(dataDir, target, input.mimeType);+ const openError = await shell.openPath(stripWinLongPrefix(openPath));if (openError) throw new Error(openError);return { ok: true };});diff --git a/apps/desktop/electron/main/open-attachment-video.ts b/apps/desktop/electron/main/open-attachment-video.tsnew file mode 100644index 000000000..3c3edddef--- /dev/null+++ b/apps/desktop/electron/main/open-attachment-video.ts@@ -0,0 +1,39 @@+import { lstat, mkdir, realpath, symlink } from "node:fs/promises";+import { basename, dirname, join } from "node:path";++const ATTACHMENT_HASH = /^[0-9a-f]{64}$/i;++/** Give an extensionless attachment its media association without copying it. */+export async function openableMp4Path(+ dataDir: string,+ target: string,+ mimeType?: string,+): Promise<string> {+ const hash = basename(target);+ if (!ATTACHMENT_HASH.test(hash) || mimeType?.toLowerCase() !== "video/mp4") {+ return target;+ }+ let attachmentRoot: string;+ try {+ attachmentRoot = await realpath(join(dataDir, "attachments"));+ } catch {+ return target;+ }+ if (dirname(target) !== attachmentRoot) return target;++ const directory = join(dataDir, "openable-attachments");+ await mkdir(directory, { recursive: true, mode: 0o700 });+ if ((await lstat(directory)).isSymbolicLink()) {+ throw new Error("attachment open directory is a symbolic link");+ }+ const alias = join(directory, `${hash.toLowerCase()}.mp4`);+ try {+ await symlink(target, alias, "file");+ } catch (error) {+ if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;+ if (!(await lstat(alias)).isSymbolicLink() || (await realpath(alias)) !== target) {+ throw new Error("attachment open path is already occupied");+ }+ }+ return alias;+}diff --git a/apps/desktop/src/components/workpanel/FilesTab.tsx b/apps/desktop/src/components/workpanel/FilesTab.tsxindex ad0c17493..b73418a9e 100644--- a/apps/desktop/src/components/workpanel/FilesTab.tsx+++ b/apps/desktop/src/components/workpanel/FilesTab.tsx@@ -12,7 +12,7 @@ import { useAppStore } from "../../stores/app-store";import { api } from "../../lib/api";import { Markdown } from "../Markdown";import { fileDirOf } from "../../lib/chat-links";-import { cx } from "../ui";+import { Button, cx } from "../ui";import { TooltipButton } from "../ui";import {ensureLang,@@ -74,6 +74,13 @@ function isMarkdownPath(path: string): boolean {return /\.(?:md|markdown)$/i.test(path);}+function isMp4(path: string, mimeType?: string): boolean {+ return /\.mp4$/i.test(path) || (+ /(?:^|[\\/])attachments[\\/][0-9a-f]{64}$/i.test(path) &&+ mimeType?.toLowerCase() === "video/mp4"+ );+}+function formatSize(size: number): string {if (size < 1024) return `${size} B`;if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)} KB`;@@ -149,11 +156,13 @@ export function FilesTab() {const { t } = useTranslation();const workspace = useAppStore((s) => s.workspace);const fileRequest = useAppStore((s) => s.workPanelFileRequest);+ const showToast = useAppStore((s) => s.showToast);const root = workspace?.path ?? null;const [dirs, setDirs] = useState<Record<string, DirState>>({});const [expanded, setExpanded] = useState<Set<string>>(new Set());const [selected, setSelected] = useState<string | null>(null);+ const [selectedMimeType, setSelectedMimeType] = useState<string | undefined>();const [file, setFile] = useState<FsReadResult | null>(null);const [fileError, setFileError] = useState(false);@@ -168,6 +177,7 @@ export function FilesTab() {setDirs({});setExpanded(new Set());setSelected(null);+ setSelectedMimeType(undefined);setFile(null);setFileError(false);}, [root]);@@ -207,6 +217,7 @@ export function FilesTab() {const openFile = useCallback(async (rel: string, mimeType?: string) => {setSelected(rel);+ setSelectedMimeType(mimeType);setFile(null);setFileError(false);try {@@ -216,6 +227,15 @@ export function FilesTab() {}}, []);+ const openMp4 = useCallback(async () => {+ if (!selected) return;+ try {+ await api.fsOpen(selected, selectedMimeType);+ } catch {+ showToast(t("panel.files.openFailed"), { variant: "error" });+ }+ }, [selected, selectedMimeType, showToast, t]);+// Chat-initiated previews: open the file and expand its ancestor folders// so "back" lands on a tree that reveals it. Attachment blobs and absolute// scratch paths live outside the workspace tree.@@ -316,6 +336,7 @@ export function FilesTab() {ariaLabel={t("panel.files.back")}onClick={() => {setSelected(null);+ setSelectedMimeType(undefined);setFile(null);}}>@@ -358,7 +379,13 @@ export function FilesTab() {? t("panel.files.tooLarge"): t("panel.files.binary")}- />+ >+ {isMp4(selected, selectedMimeType) && (+ <Button type="button" onClick={() => void openMp4()}>+ {t("chat.openFile")}+ </Button>+ )}+ </WorkTabEmpty>)}</div></div>diff --git a/apps/desktop/src/features/chat/transcript/MessageRow.tsx b/apps/desktop/src/features/chat/transcript/MessageRow.tsxindex c9078af31..7b69b7445 100644--- a/apps/desktop/src/features/chat/transcript/MessageRow.tsx+++ b/apps/desktop/src/features/chat/transcript/MessageRow.tsx@@ -269,6 +269,7 @@ export const MessageRow = memo(function MessageRow({name={attachment.name}path={attachment.ref}kind={attachment.kind}+ mimeType={attachment.mimeType}onOpen={openFileRef}/></span>diff --git a/apps/desktop/src/features/chat/transcript/shared.tsx b/apps/desktop/src/features/chat/transcript/shared.tsxindex 0d3effde7..91d82f7c8 100644--- a/apps/desktop/src/features/chat/transcript/shared.tsx+++ b/apps/desktop/src/features/chat/transcript/shared.tsx@@ -416,13 +416,15 @@ export function FileRefChip({name,path,kind,+ mimeType,onOpen,...position}: {name: string;path: string;kind?: "image" | "file";- onOpen: (path: string) => void;+ mimeType?: string;+ onOpen: (path: string, baseDir?: string, mimeType?: string) => void;} & SourcePositionProps) {const { t } = useTranslation();const Icon = fileChipIcon(name, kind);@@ -436,7 +438,7 @@ export function FileRefChip({{...position}title={`${html ? t("chat.previewUrl") : t("chat.openFile")} — ${path}`}aria-label={`${name} — ${path}`}- onClick={() => onOpen(path)}+ onClick={() => onOpen(path, undefined, mimeType)}onContextMenu={(event) => openFileMenu(event, { path })}><span className="composer-chip-icon" aria-hidden>@@ -459,7 +461,7 @@ export function MessageAttachmentImage({onOpenFile,}: {attachment: MessageAttachment;- onOpenFile: (path: string) => void;+ onOpenFile: (path: string, baseDir?: string, mimeType?: string) => void;}) {const { fileMenu, openFileMenu, closeFileMenu } = useChatFileMenu();const dataUrl = useReferencedImageDataUrl(attachment.ref, attachment.mimeType);@@ -469,6 +471,7 @@ export function MessageAttachmentImage({name={attachment.name}path={attachment.ref}kind="image"+ mimeType={attachment.mimeType}onOpen={onOpenFile}/>);diff --git a/apps/desktop/src/lib/api.ts b/apps/desktop/src/lib/api.tsindex f4c60c636..2c30bb6a9 100644--- a/apps/desktop/src/lib/api.ts+++ b/apps/desktop/src/lib/api.ts@@ -1360,7 +1360,8 @@ export const api = {...(mimeType ? { mimeType } : {}),}),fsReveal: (path: string) => invoke(IPC.invoke.fsReveal, { path }),- fsOpen: (path: string) => invoke(IPC.invoke.fsOpen, { path }),+ fsOpen: (path: string, mimeType?: string) =>+ invoke(IPC.invoke.fsOpen, { path, mimeType }),fsIndex: () => invoke<FsIndexResult>(IPC.invoke.fsIndex),/*** Complete a file reference from chat text to a real file (D320 follow-up).diff --git a/apps/desktop/test/open-attachment-video.test.mjs b/apps/desktop/test/open-attachment-video.test.mjsnew file mode 100644index 000000000..d80927508--- /dev/null+++ b/apps/desktop/test/open-attachment-video.test.mjs@@ -0,0 +1,56 @@+import assert from "node:assert/strict";+import { mkdtemp, mkdir, readlink, realpath, rm, stat, writeFile } from "node:fs/promises";+import { tmpdir } from "node:os";+import { join } from "node:path";+import test from "node:test";+import { openableMp4Path } from "../electron/main/open-attachment-video.ts";++test("an extensionless stored MP4 gets an OS-openable name without copying bytes", async (t) => {+ const dataDir = await mkdtemp(join(tmpdir(), "pi-mp4-open-"));+ t.after(() => rm(dataDir, { recursive: true, force: true }));+ const attachments = join(dataDir, "attachments");+ await mkdir(attachments);+ const hash = "a".repeat(64);+ const stored = join(attachments, hash);+ await writeFile(stored, Buffer.alloc(512 * 1024 + 1));+ const storedReal = await realpath(stored);++ const alias = await openableMp4Path(dataDir, storedReal, "video/mp4");+ assert.equal(alias, join(dataDir, "openable-attachments", `${hash}.mp4`));+ assert.equal(await realpath(alias), storedReal);+ assert.equal(await readlink(alias), storedReal);+ assert.equal((await stat(alias)).size, 512 * 1024 + 1);+ assert.equal(await openableMp4Path(dataDir, storedReal, "video/mp4"), alias);+});++test("only a typed content-addressed MP4 is given an alias", async (t) => {+ const dataDir = await mkdtemp(join(tmpdir(), "pi-mp4-open-"));+ t.after(() => rm(dataDir, { recursive: true, force: true }));+ const file = join(dataDir, "clip.mp4");+ await writeFile(file, "video");+ const workspace = join(dataDir, "workspace");+ await mkdir(workspace);+ const hashNamedProjectFile = join(workspace, "b".repeat(64));+ await writeFile(hashNamedProjectFile, "project file");++ assert.equal(await openableMp4Path(dataDir, file, "video/mp4"), file);+ assert.equal(await openableMp4Path(dataDir, file, "text/plain"), file);+ assert.equal(await openableMp4Path(dataDir, hashNamedProjectFile, "video/mp4"), hashNamedProjectFile);+});++test("an occupied alias cannot redirect the OS handoff", async (t) => {+ const dataDir = await mkdtemp(join(tmpdir(), "pi-mp4-open-"));+ t.after(() => rm(dataDir, { recursive: true, force: true }));+ const attachments = join(dataDir, "attachments");+ const aliases = join(dataDir, "openable-attachments");+ await Promise.all([mkdir(attachments), mkdir(aliases)]);+ const hash = "c".repeat(64);+ const stored = join(attachments, hash);+ await writeFile(stored, "video");+ await writeFile(join(aliases, `${hash}.mp4`), "different file");++ await assert.rejects(+ openableMp4Path(dataDir, await realpath(stored), "video/mp4"),+ /already occupied/,+ );+});diff --git a/apps/desktop/test/transcript-file-chips.test.mjs b/apps/desktop/test/transcript-file-chips.test.mjsindex 4bfa6a0f6..cd37a0945 100644--- a/apps/desktop/test/transcript-file-chips.test.mjs+++ b/apps/desktop/test/transcript-file-chips.test.mjs@@ -24,6 +24,8 @@ test("sent user-message file refs render as composer-like chips", () => {assert.match(transcript, /useOpenChatFileRef/);assert.match(transcript, /composer-chip-name/);assert.match(styles, /\.chat-file-chip[\s\S]*?appearance: none/);+ assert.match(transcript, /mimeType=\{attachment\.mimeType\}/);+ assert.match(transcript, /onOpen\(path, undefined, mimeType\)/);});test("a file chip is routed by where the reference resolved, never optimistically", () => {@@ -53,7 +55,7 @@ test("a file chip is routed by where the reference resolved, never optimisticall// 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\(/);- assert.match(api, /fsOpen: \(path: string\) => invoke\(IPC\.invoke\.fsOpen, \{ path \}\)/);+ assert.match(api, /fsOpen: \(path: string, mimeType\?: string\) =>\s*invoke\(IPC\.invoke\.fsOpen, \{ path, mimeType \}\)/);});test("a tool row and a tool result row open a file where the message body does", () => {diff --git a/docs/spec/03-runtime/01-ipc-protocol.md b/docs/spec/03-runtime/01-ipc-protocol.mdindex a93949c33..b3800c75e 100644--- a/docs/spec/03-runtime/01-ipc-protocol.md+++ b/docs/spec/03-runtime/01-ipc-protocol.md@@ -1774,8 +1774,12 @@ Renderer IPC kept for the Plan-safe preview facade and URL fallback:containment as `fs/read`. Never returns non-image bytes. Renderer-only;not a plugin host API.- `fs/reveal({path})` → reveal in Finder. Same containment as `fs/read`.-- `fs/open({path})` → open with the OS default application. Same lexical- containment as `fs/read` (without the extra realpath step used by reads).+- `fs/open({path, mimeType?})` → open an existing regular file with the OS+ default application. It uses the same realpath containment as `fs/read`,+ including rejection of symlink escapes. For a content-addressed+ `attachments/<sha256>` blob declared as `video/mp4`, the host creates a+ `.mp4` symlink inside its private app-data directory before the OS handoff,+ so the extensionless blob has a media association without copying its bytes.- `fs/resolveRef({ref, sessionId?})` → `FsChatRefResolveResult`(`{ match: FsChatRefMatch | null }`, the match naming the answering `root`(`workspace` / `scratch` / `attachments`), the `relativePath` relative to thatdiff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.mdindex 6d29ffbcf..1b187693c 100644--- a/docs/spec/04-ux/09-interaction-patterns.md+++ b/docs/spec/04-ux/09-interaction-patterns.md@@ -1298,6 +1298,11 @@ Project drag/drop follows these patterns:outside the project has no relative path to copy and says so. The OS defaultapplication is no longer what this click does, though that action staysreachable from the file view's own context menu.+- In the host `file:` tab, a conversation MP4 that cannot be previewed because+ it is binary or exceeds the text preview limit offers **Open with default+ application**. This applies to named `.mp4` files and extensionless+ attachment blobs carrying `video/mp4` metadata. A failed OS handoff shows an+ error; the user can still reveal the contained file in the file manager.- The same destination rule governs every other surface of the transcript thatnames a file, because one opener serves them all: clicking the file path in atool row's summary (Read, Write, Edit, fetch) and clicking a path in a tooldiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 2cbcbec72..31b8b95d9 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -8583,6 +8583,7 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.| Quality (Independent session communication) | E2E-SESSION-independent-top-level-communication, E2E-SESSION-hover-card-model-and-links || C — Conversation & stream (Hover card model and links) | E2E-SESSION-hover-card-model-and-links || C — Conversation & stream (Chat file references) | E2E-CHAT-shorthand-file-ref-opens-the-matching-file, E2E-CHAT-file-ref-opens-the-surface-that-owns-it |+| C / Quality / Security (Conversation MP4 attachments) | E2E-CHAT-mp4-attachment-opens-in-system-player || G — Plugins (Chat file references) | E2E-CHAT-file-ref-opens-the-surface-that-owns-it, E2E-PLUGIN-file-view-collapse-persists || Quality (Chat file references) | E2E-CHAT-shorthand-file-ref-opens-the-matching-file, E2E-CHAT-file-ref-opens-the-surface-that-owns-it, E2E-PLUGIN-file-view-collapse-persists || G — Plugins (project folder roots) | E2E-PLUGIN-file-view-switches-folder-per-project |@@ -8617,6 +8618,7 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.| M6+ (Windows updater cache) | E2E-260 || M6+ (Independent session communication) | E2E-SESSION-independent-top-level-communication, E2E-SESSION-hover-card-model-and-links || M5 (Chat file references) | E2E-CHAT-shorthand-file-ref-opens-the-matching-file, E2E-CHAT-file-ref-opens-the-surface-that-owns-it |+| M5 (Conversation MP4 attachments) | E2E-CHAT-mp4-attachment-opens-in-system-player || M6+ (Chat file references) | E2E-PLUGIN-file-view-collapse-persists || M6+ (project folder roots) | E2E-PLUGIN-file-view-switches-folder-per-project || Post-MVP | E2E-022A, E2E-022B, E2E-022C, E2E-024I, E2E-024J, E2E-024K, E2E-024L, E2E-024M (plugin roadmap R2/R3/R6) |@@ -11699,6 +11701,26 @@ are withdrawn with ADR 0165.shape of resolution produces); full UI journey Draft (run only in a capableenvironment when this surface changes)+#### E2E-CHAT-mp4-attachment-opens-in-system-player++- **Preconditions**: A conversation has one pasted MP4 in session scratch and+ two stored MP4 attachments whose content-addressed refs have no extension:+ one larger than 512 KiB and one smaller binary file. All retain `video/mp4`+ metadata.+- **Steps**: Click each attachment in the transcript, then choose **Open with+ default application** in the host file tab. Repeat with a workspace `.mp4`.+- **Expected**: The large attachment reports that inline preview is unavailable+ because of size and the small attachment reports binary content; both offer+ the OS-open action. The host validates realpath containment and hands the OS+ an `.mp4` alias of the same stored bytes. A file outside allowed roots or a+ symlink escape is refused. Failed OS handoff is visible to the user.+- **Specs linked**: `03-runtime/01-ipc-protocol.md` § fs,+ `04-ux/09-interaction-patterns.md` §8a.2.+- **Acceptance**: C (conversation & stream), Quality, Security+- **Milestone**: M5+- **Status**: Electron fixture covered for pasted scratch MP4 and both blob sizes+ (`test:e2e:composer-paste`); full installed-app/player journey Draft.+#### E2E-181: An imported skill is listed in the next session catalog- **Preconditions**: Settings > Agent > Skills is open. A conventionaldiff --git a/packages/i18n/src/locales/de/index.ts b/packages/i18n/src/locales/de/index.tsindex 710ff14a3..1904836e1 100644--- a/packages/i18n/src/locales/de/index.ts+++ b/packages/i18n/src/locales/de/index.ts@@ -1830,7 +1830,8 @@ sklm: {"back": "Zurück zu Dateien","reveal": "Im Finder anzeigen","binary": "Binärdatei – Vorschau nicht verfügbar",- "tooLarge": "Datei ist zu groß für die Vorschau"+ "tooLarge": "Datei ist zu groß für die Vorschau",+ "openFailed": "Die Datei konnte nicht mit der Standardanwendung geöffnet werden."}},"palette": {diff --git a/packages/i18n/src/locales/en/index.ts b/packages/i18n/src/locales/en/index.tsindex 8e1b7dc4b..dfefe1616 100644--- a/packages/i18n/src/locales/en/index.ts+++ b/packages/i18n/src/locales/en/index.ts@@ -1849,6 +1849,7 @@ sklm: {reveal: "Reveal in Finder",binary: "Binary file — preview unavailable",tooLarge: "File is too large to preview",+ openFailed: "Could not open the file with its default application.",},},palette: {diff --git a/packages/i18n/src/locales/es/index.ts b/packages/i18n/src/locales/es/index.tsindex b1666c157..63cb48ed5 100644--- a/packages/i18n/src/locales/es/index.ts+++ b/packages/i18n/src/locales/es/index.ts@@ -1830,7 +1830,8 @@ sklm: {"back": "Volver a los archivos","reveal": "Mostrar en el Finder","binary": "Archivo binario: vista previa no disponible",- "tooLarge": "El archivo es demasiado grande para obtener una vista previa"+ "tooLarge": "El archivo es demasiado grande para obtener una vista previa",+ "openFailed": "No se pudo abrir el archivo con la aplicación predeterminada."}},"palette": {diff --git a/packages/i18n/src/locales/fr/index.ts b/packages/i18n/src/locales/fr/index.tsindex 1bf9e2fd2..75e40f991 100644--- a/packages/i18n/src/locales/fr/index.ts+++ b/packages/i18n/src/locales/fr/index.ts@@ -1830,7 +1830,8 @@ sklm: {"back": "Retour aux fichiers","reveal": "Révéler dans le Finder","binary": "Fichier binaire — aperçu indisponible",- "tooLarge": "Le fichier est trop volumineux pour être prévisualisé"+ "tooLarge": "Le fichier est trop volumineux pour être prévisualisé",+ "openFailed": "Impossible d’ouvrir le fichier avec l’application par défaut."}},"palette": {diff --git a/packages/i18n/src/locales/ko/index.ts b/packages/i18n/src/locales/ko/index.tsindex 66081e682..55067dc56 100644--- a/packages/i18n/src/locales/ko/index.ts+++ b/packages/i18n/src/locales/ko/index.ts@@ -1846,6 +1846,7 @@ sklm: {reveal: "Finder에서 보기",binary: "바이너리 파일 — 미리 볼 수 없음",tooLarge: "파일이 너무 커서 미리 볼 수 없음",+ openFailed: "기본 앱으로 파일을 열 수 없습니다.",},},palette: {diff --git a/packages/i18n/src/locales/pt-BR/index.ts b/packages/i18n/src/locales/pt-BR/index.tsindex a57c86b0e..d713aa54b 100644--- a/packages/i18n/src/locales/pt-BR/index.ts+++ b/packages/i18n/src/locales/pt-BR/index.ts@@ -1781,7 +1781,8 @@ export const ptBR = {back: "Voltar aos arquivos",reveal: "Revelar no Finder",binary: "Arquivo binário — pré-visualização indisponível",- tooLarge: "O arquivo é grande demais para pré-visualização"+ tooLarge: "O arquivo é grande demais para pré-visualização",+ openFailed: "Não foi possível abrir o arquivo com o aplicativo padrão."}},palette: {diff --git a/packages/i18n/src/locales/tr/index.ts b/packages/i18n/src/locales/tr/index.tsindex 6b73ca076..f422935fe 100644--- a/packages/i18n/src/locales/tr/index.ts+++ b/packages/i18n/src/locales/tr/index.ts@@ -1836,6 +1836,7 @@ sklm: {reveal: "Finder’da göster",binary: "İkili dosya — önizleme yok",tooLarge: "Dosya önizlemek için çok büyük",+ openFailed: "Dosya varsayılan uygulamayla açılamadı.",},},palette: {diff --git a/packages/i18n/src/locales/zh-CN/index.ts b/packages/i18n/src/locales/zh-CN/index.tsindex 3dd81f3c6..f20603b53 100644--- a/packages/i18n/src/locales/zh-CN/index.ts+++ b/packages/i18n/src/locales/zh-CN/index.ts@@ -1817,6 +1817,7 @@ sklm: {reveal: "在 Finder 中显示",binary: "二进制文件,无法预览",tooLarge: "文件过大,无法预览",+ openFailed: "无法使用系统默认应用打开文件。",},},palette: {diff --git a/packages/i18n/src/locales/zh-TW/index.ts b/packages/i18n/src/locales/zh-TW/index.tsindex 67bae8389..097e46c2a 100644--- a/packages/i18n/src/locales/zh-TW/index.ts+++ b/packages/i18n/src/locales/zh-TW/index.ts@@ -1817,6 +1817,7 @@ sklm: {reveal: "在 Finder 中顯示",binary: "二進位制檔案,無法預覽",tooLarge: "檔案過大,無法預覽",+ openFailed: "無法使用系統預設應用程式開啟檔案。",},},palette: {diff --git a/scripts/e2e-composer-paste.mjs b/scripts/e2e-composer-paste.mjsindex 70e44a736..0ddd0e337 100644--- a/scripts/e2e-composer-paste.mjs+++ b/scripts/e2e-composer-paste.mjs@@ -37,6 +37,7 @@ try {entryPoints: {writer: join(root, "apps/desktop/electron/main/composer-paste.ts"),reader: join(root, "packages/host-runtime/src/workspace-files.ts"),+ video: join(root, "apps/desktop/electron/main/open-attachment-video.ts"),},outdir: temp,outExtension: { ".js": ".cjs" },@@ -69,10 +70,14 @@ const path = require("node:path");const fs = require("node:fs/promises");const assert = require("node:assert/strict");const { saveComposerPasteFiles } = require("./writer.cjs");-const { readOpenableFile, readOpenableImage } = require("./reader.cjs");+const { readOpenableFile, readOpenableImage, resolveRealOpenablePath } = require("./reader.cjs");+const { openableMp4Path } = require("./video.cjs");app.setPath("userData", path.join(__dirname, "profile"));const saved = [];const history = [];+const opened = [];+let completeOpens;+const opensDone = new Promise(resolve => { completeOpens = resolve; });ipcMain.handle("pi-desktop/composer/pasteFiles", async (_event, input) => {const files = await saveComposerPasteFiles(__dirname, input.sessionId, input.files);for (let i = 0; i < files.length; i++) {@@ -96,13 +101,41 @@ ipcMain.handle("pi-desktop/fs/readImageDataUrl", async (_event, input) => ({}));ipcMain.handle("pi-desktop/fs/read", async (_event, input) => ({ok: true,- data: await readOpenableFile(input.path, null, [path.join(__dirname, "scratch")], input.mimeType),+ data: input.path === "untrusted.sh"+ ? { kind: "tooLarge", size: 512 * 1024 + 1 }+ : await readOpenableFile(input.path, null, [path.join(__dirname, "scratch"), path.join(__dirname, "attachments")], input.mimeType),}));+ipcMain.handle("pi-desktop/fs/resolveRef", async (_event, input) => {+ const scratchRoot = path.join(__dirname, "scratch") + path.sep;+ if (input.ref.startsWith(scratchRoot)) {+ return { ok: true, data: { match: {+ root: "scratch", relativePath: path.relative(scratchRoot, input.ref),+ absolutePath: input.ref, matchedBy: "exact-absolute",+ } } };+ }+ const hash = input.ref.startsWith("attachments/") ? input.ref.slice("attachments/".length) : "";+ assert(/^[ab]{64}$/.test(hash), "unexpected MP4 attachment reference");+ return { ok: true, data: { match: {+ root: "attachments", relativePath: hash,+ absolutePath: path.join(__dirname, "attachments", hash), matchedBy: "exact-relative",+ } } };+});+ipcMain.handle("pi-desktop/fs/open", async (_event, input) => {+ const target = await resolveRealOpenablePath(input.path, null, [path.join(__dirname, "scratch"), path.join(__dirname, "attachments")]);+ assert(target, "host rejected the MP4 attachment path");+ const openPath = await openableMp4Path(__dirname, target, input.mimeType);+ opened.push(openPath);+ if (opened.length === 3) completeOpens();+ return { ok: true, data: { ok: true } };+});ipcMain.handle("pi-desktop/clipboard/recordPaste", (_event, input) => {history.push(input.text);return { ok: true, data: null };});app.whenReady().then(async () => {+ await fs.mkdir(path.join(__dirname, "attachments"));+ await fs.writeFile(path.join(__dirname, "attachments", "a".repeat(64)), Buffer.alloc(512 * 1024 + 1));+ await fs.writeFile(path.join(__dirname, "attachments", "b".repeat(64)), Buffer.from([0, 1, 2, 0]));const window = new BrowserWindow({ show: false, webPreferences: {preload: ${JSON.stringify(join(root, "apps/desktop/out/preload/index.cjs"))},sandbox: true, contextIsolation: true, nodeIntegration: false, backgroundThrottling: false,@@ -141,11 +174,16 @@ app.whenReady().then(async () => {});await window.webContents.executeJavaScript('globalThis.composerPreviewPointer = input => new Promise(resolve => { globalThis.composerPreviewPointerDone = resolve; console.log("PI_PREVIEW_POINTER:" + JSON.stringify(input)); }); void 0');const result = await window.webContents.executeJavaScript("globalThis.composerPasteProbe()");+ await opensDone;+ assert.deepEqual(opened.map(path.extname), [".mp4", ".mp4", ".mp4"]);+ assert.equal(await fs.realpath(opened[0]), await fs.realpath(path.join(__dirname, "attachments", "a".repeat(64))));+ assert.equal(await fs.realpath(opened[1]), await fs.realpath(path.join(__dirname, "attachments", "b".repeat(64))));+ assert.equal(opened[2], saved.find(entry => entry.mimeTypes.includes("video/mp4"))?.files[0].path);const mimeSets = saved.map((entry) => entry.mimeTypes.join("+"));assert.equal(saved.length,- 5,- "unexpected scratch writes (large text, image-only, native image, empty image-only, native files): " + JSON.stringify(mimeSets),+ 6,+ "unexpected scratch writes (large text, MP4, image-only, native image, empty image-only, native files): " + JSON.stringify(mimeSets),);assert.deepEqual(mimeSets.filter((mimes) => mimes === "text/plain"),@@ -157,6 +195,7 @@ app.whenReady().then(async () => {4,"image-only and native-file pastes must keep writing image bytes: " + JSON.stringify(mimeSets),);+ assert.equal(mimeSets.filter((mimes) => mimes === "video/mp4").length, 1);assert(history.some(text => text.includes("Word paragraph")), "short text missing from clipboard history");console.log("COMPOSER_PASTE_PROBE " + JSON.stringify({ ...result, scratchBytesVerified: true }));app.quit();diff --git a/scripts/e2e/composer-paste.tsx b/scripts/e2e/composer-paste.tsxindex 1bcbc3bc6..240a9b1fa 100644--- a/scripts/e2e/composer-paste.tsx+++ b/scripts/e2e/composer-paste.tsx@@ -26,6 +26,8 @@ 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 { useOpenChatFileRef } from "../../apps/desktop/src/hooks/use-preview-target";import {readComposerDraft,resetComposerDraftCache,@@ -108,6 +110,27 @@ function Fixture({ sessionId, t, workspacePath }: { sessionId: string; t: TFunct);}+function Mp4AttachmentChips({ scratchPath }: { scratchPath: string }) {+ const openFile = useOpenChatFileRef();+ return (+ <div className="mp4-attachment-chips">+ {[+ { name: "a.mp4", path: `attachments/${"a".repeat(64)}` },+ { name: "b.mp4", path: `attachments/${"b".repeat(64)}` },+ { name: "scratch.mp4", path: scratchPath },+ ].map((video) => (+ <FileRefChip+ key={video.name}+ name={video.name}+ path={video.path}+ mimeType="video/mp4"+ onOpen={openFile}+ />+ ))}+ </div>+ );+}+globalThis.composerPasteProbe = async () => {const i18n = createInstance();await i18n.init({@@ -240,7 +263,11 @@ globalThis.composerPasteProbe = async () => {await pendingPaste;assert(controller.value === "", "pending paste changed the destination draft");render("paste-a");- await new Promise(requestAnimationFrame);+ const restoreDeadline = performance.now() + 3000;+ while (!controller.fileReferences.some((reference) => reference.name === "new.txt") &&+ performance.now() < restoreDeadline) {+ await new Promise(requestAnimationFrame);+ }const names = controller.fileReferences.map((r) => r.name);assert(names.includes("original.txt") && names.includes("new.txt"),"PENDING_PASTE_SESSION_SWITCH lost original attachment: " + JSON.stringify({ names, text: readEditorValue(controller.ref.current!), visible: controller.ref.current!.textContent }));@@ -389,20 +416,36 @@ globalThis.composerPasteProbe = async () => {`prefix ${controller.fileReferences[0].token} suffix`,"large text chip lost the selection boundary",);+ const longTextPath = controller.fileReferences[0].path;+ await paste("", [new File([new Uint8Array(512 * 1024 + 1)], "clip.mp4", {+ type: "video/mp4",+ })]);+ assert(controller.fileReferences.length === 1 &&+ controller.fileReferences[0].mimeType === "video/mp4" &&+ controller.fileReferences[0].path.endsWith(".mp4"),+ "a pasted MP4 did not retain its playable scratch filename");+ const scratchVideoPath = controller.fileReferences[0].path;// Preview the persisted long-text attachment through the public work-panel// entry point, with no project open (the temporary-task user path).const previewHost = document.createElement("div");document.body.append(previewHost);const previewRoot = createRoot(previewHost);+ const originalFsOpen = api.fsOpen;+ const openRequests: Array<ReturnType<typeof api.fsOpen>> = [];+ api.fsOpen = (path: string, mimeType?: string) => {+ const request = originalFsOpen(path, mimeType);+ openRequests.push(request);+ return request;+ };try {flushSync(() => previewRoot.render(- <I18nextProvider i18n={i18n}><FilesTab /></I18nextProvider>,+ <I18nextProvider i18n={i18n}><FilesTab /><Mp4AttachmentChips scratchPath={scratchVideoPath} /></I18nextProvider>,));assert(previewHost.textContent?.includes(i18n.t("panel.files.noWorkspace")),"file browsing without a project should show the empty state");flushSync(() => useAppStore.getState().openFileInWorkPanel(- controller.fileReferences[0].path, "text/plain",+ longTextPath, "text/plain",));const deadline = performance.now() + 3000;while (!previewHost.querySelector(".file-viewer-code") && performance.now() < deadline) {@@ -410,6 +453,39 @@ globalThis.composerPasteProbe = async () => {}assert(previewHost.querySelector(".file-viewer-code")?.textContent === longText,"temporary-task attachment did not display its saved text in the file preview");+ for (const [index, [hash, expected]] of [+ ["a", i18n.t("panel.files.tooLarge")],+ ["b", i18n.t("panel.files.binary")],+ ["scratch", i18n.t("panel.files.tooLarge")],+ ].entries()) {+ const chip = previewHost.querySelector<HTMLButtonElement>(+ `.mp4-attachment-chips [aria-label^="${hash}.mp4"]`,+ );+ assert(chip, `MP4 attachment chip is missing: ${hash}`);+ flushSync(() => chip!.click());+ const deadline = performance.now() + 3000;+ while (!previewHost.textContent?.includes(expected) && performance.now() < deadline) {+ await new Promise(requestAnimationFrame);+ }+ assert(previewHost.textContent?.includes(expected),+ `MP4 attachment did not reach its expected preview state: ${hash}`);+ const open = Array.from(previewHost.querySelectorAll<HTMLButtonElement>("button"))+ .find((button) => button.textContent === i18n.t("chat.openFile"));+ assert(open, `MP4 attachment has no system-player action: ${hash}`);+ flushSync(() => open!.click());+ assert(openRequests.length === index + 1, `MP4 open did not reach IPC: ${hash}`);+ await openRequests[index];+ }+ flushSync(() => useAppStore.getState().openFileInWorkPanel("untrusted.sh", "video/mp4"));+ const unsafeDeadline = performance.now() + 3000;+ while ((previewHost.querySelector(".file-viewer-path")?.textContent !== "untrusted.sh" ||+ !previewHost.textContent?.includes(i18n.t("panel.files.tooLarge"))) &&+ performance.now() < unsafeDeadline) {+ await new Promise(requestAnimationFrame);+ }+ assert(!Array.from(previewHost.querySelectorAll<HTMLButtonElement>("button"))+ .some((button) => button.textContent === i18n.t("chat.openFile")),+ "a spoofed video MIME must not offer an OS-open action for a script");const back = previewHost.querySelector<HTMLButtonElement>(`[aria-label="${i18n.t("panel.files.back")}"]`,);@@ -418,6 +494,7 @@ globalThis.composerPasteProbe = async () => {assert(previewHost.textContent?.includes(i18n.t("panel.files.noWorkspace")),"back from a temporary attachment should restore the no-project empty state");} finally {+ api.fsOpen = originalFsOpen;flushSync(() => previewRoot.unmount());previewHost.remove();}@@ -480,7 +557,7 @@ globalThis.composerPasteProbe = async () => {assert(dialog()!.contains(document.activeElement), "modal allowed background input focus");button(i18n.t("chat.imagePreview.fit")).focus();await globalThis.composerPreviewPressKey("Tab");- assert(dialog()!.contains(document.activeElement), "Tab escaped the preview");+ await until(() => dialog()?.contains(document.activeElement), "Tab escaped the preview");assert(preview.naturalWidth === 1 && preview.getBoundingClientRect().width === 1,"small image must not be stretched to fill the window");assert(!useAppStore.getState().workPanelOpen, "preview opened the work panel");@@ -808,6 +885,7 @@ globalThis.composerPasteProbe = async () => {crossBreakAndChipSelection: true,mixedLongText: true,temporaryTaskTextPreview: true,+ mp4AttachmentOpen: true,imageOnly: true,nativeImageFile: true,imagePreviewAndKeyboard: true,