Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
fix(preview): restore local attachment image actions
CloudTianTian1cf5efb78ab8
diff --git a/src/renderer/modules/chat-lightbox.js b/src/renderer/modules/chat-lightbox.jsindex 783479e2..9fdeaceb 100644--- a/src/renderer/modules/chat-lightbox.js+++ b/src/renderer/modules/chat-lightbox.js@@ -68,6 +68,33 @@ function _absPathFromChatMediaLocalUrl(src) {return p.startsWith('/') ? p : `/${p}`;}+function _lightboxSetCurrentFile(fileOpts) {+ _lightboxCurrentFile = fileOpts && fileOpts.absPath ? {+ absPath: fileOpts.absPath,+ cid: fileOpts.cid || null,+ projectId: fileOpts.projectId || null,+ } : null;+ if (_lightboxAddLibraryBtn) _lightboxAddLibraryBtn.hidden = !_lightboxCanAddToLibrary(_lightboxCurrentFile);+ if (_lightboxRevealBtn) _lightboxRevealBtn.hidden = !_lightboxCurrentFile;+}++async function _lightboxResolveAttachment(src, sequence) {+ try {+ const url = new URL(src);+ if (url.protocol !== 'chat-media:' || url.host !== 'cid') return;+ const parts = decodeURIComponent(url.pathname).replace(/^\/+/, '').split('/');+ if (parts.length !== 2 || parts.some(part => !part || part.includes('\\'))) return;+ const [cid, name] = parts;+ // Use the same resolver as the media protocol; never infer storage layout+ // or attach an image to whichever conversation happens to be selected.+ const result = await window.orkas.invoke('attachments.absPath', { cid, name });+ if (sequence !== _lightboxLoadSeq || !_isOpen()) return;+ if (result?.ok && typeof result.path === 'string' && result.path) {+ _lightboxSetCurrentFile({ absPath: result.path, cid });+ }+ } catch (_) { /* Keep the preview usable; reopening retries unavailable file actions. */ }+}+function _isOpen() {return !!(_lightboxEl && _lightboxEl.classList.contains('is-open'));}@@ -533,15 +560,10 @@ function openChatImageLightbox(src, alt, opts) {const fileOpts = (opts && opts.absPath)? opts: (inferredAbsPath ? { absPath: inferredAbsPath, cid: opts?.cid || fallbackCid } : null);- _lightboxCurrentFile = fileOpts && fileOpts.absPath ? {- absPath: fileOpts.absPath,- cid: fileOpts.cid || null,- projectId: fileOpts.projectId || null,- } : null;- if (_lightboxAddLibraryBtn) _lightboxAddLibraryBtn.hidden = !_lightboxCanAddToLibrary(_lightboxCurrentFile);- if (_lightboxRevealBtn) _lightboxRevealBtn.hidden = !_lightboxCurrentFile;+ _lightboxSetCurrentFile(fileOpts);el.classList.add('is-open');el.setAttribute('aria-hidden', 'false');+ if (!_lightboxCurrentFile) void _lightboxResolveAttachment(src, loadSeq);if (!wasOpen) el.querySelector('.chat-lightbox-close').focus({ preventScroll: true });_updateLightboxNavigation();if (!_lightboxKeyHandler) {diff --git a/src/renderer/preview.css b/src/renderer/preview.cssindex 7da5baa7..e57b42f1 100644--- a/src/renderer/preview.css+++ b/src/renderer/preview.css@@ -36,6 +36,7 @@.preview-window .chat-file-viewer-actions:focus-within,.preview-window .chat-lightbox-actions:hover,.preview-window .chat-lightbox-actions:focus-within { opacity: 1; }+.preview-window .chat-lightbox-actions:not(:has(> button:not([hidden]):not(.chat-lightbox-close))) { display: none; }.preview-window .chat-lightbox-actions > button {width: 28px; height: 28px; background: transparent; box-shadow: none;}diff --git a/test/e2e/preview_windows_e2e_lifecycle.spec.ts b/test/e2e/preview_windows_e2e_lifecycle.spec.tsindex 62f88634..4a05bf97 100644--- a/test/e2e/preview_windows_e2e_lifecycle.spec.ts+++ b/test/e2e/preview_windows_e2e_lifecycle.spec.ts@@ -1,7 +1,74 @@-import { appendFileSync } from 'node:fs';+import { appendFileSync, readFileSync } from 'node:fs';import path from 'node:path';+import sharp from 'sharp';import { expect, test } from './fixtures/orkas';+for (const locale of ['zh', 'en']) {+ test(`attachment markdown images retain local file actions without empty chrome (${locale})`, async ({ modelOrkas: orkas }, info) => {+ orkas.setLibraryImageDescriptionReplies(['A violet rectangle.', 'A yellow rectangle.']);+ await orkas.page!.evaluate(lang => (window as any).setLang(lang), locale);+ const created: any = await orkas.invoke('conversations.create', { title: 'Attachment preview actions' });+ const cid = created.conversation.conversation_id;+ const png = await sharp({ create: { width: 640, height: 360, channels: 3, background: '#5b57d6' } }).png().toBuffer();+ const images = new Map([+ ['cover art.png', png],+ ['second.png', await sharp(png).negate().png().toBuffer()],+ ]);+ for (const [name, bytes] of images) {+ // Distinct bytes prevent the attachment store's content deduplication.+ const uploaded: any = await orkas.invoke('conversations.attachments.upload', { cid, name, data: bytes.toString('base64') });+ expect(uploaded.ok).toBe(true);+ }+ const source = (name: string) => `chat-media://cid/${encodeURIComponent(cid)}/${encodeURIComponent(name)}`;+ const rows = [...images.keys()].map((name, index) => ({ id: `actions-${index}`, from: 'commander', to: ['user'],+ ts: new Date(Date.now() - (2 - index) * 1000).toISOString(), text: `})` }));+ appendFileSync(path.join(orkas.workspaceRoot, 'account-e2e', 'cloud', 'chats', `${cid}.jsonl`), rows.map(r => JSON.stringify(r)).join('\n') + '\n');+ await orkas.page!.evaluate(async id => { await (window as any).loadConversations(); await (window as any).setView('conversation', id); }, cid);+ // Keep the real reveal IPC/validation; control only the OS shell side effect.+ await orkas.electronApp!.evaluate(({ shell }) => {+ (process as any).revealedPaths = [];+ (process as any).originalReveal = shell.showItemInFolder;+ shell.showItemInFolder = file => { (process as any).revealedPaths.push(file); };+ });+ const preview = await orkas.openPreview(() => orkas.page!.locator('#chat-history img.chat-md-img').first().click());+ const image = preview.locator('.chat-lightbox-img');+ await expect.poll(() => image.evaluate((img: HTMLImageElement) => img.naturalWidth)).toBe(640);+ await expect(preview.locator('.chat-lightbox-share')).toHaveCount(0);+ for (const name of images.keys()) {+ if (name === 'second.png') await preview.locator('.chat-lightbox-next').click();+ await expect(image).toHaveAttribute('src', source(name));+ for (const action of ['add-library', 'reveal']) await expect(preview.locator(`.chat-lightbox-${action}`)).toBeVisible();+ const resolved: any = await orkas.invoke('attachments.absPath', { cid, name });+ expect(resolved.ok).toBe(true);+ await preview.locator('.chat-lightbox-reveal').click();+ await expect.poll(() => orkas.electronApp!.evaluate(() => (process as any).revealedPaths.at(-1))).toBe(resolved.path);+ await expect(preview.locator('.ui-dialog-overlay:visible')).toHaveCount(0);+ await preview.locator('.chat-lightbox-add-library').click();+ const imported = path.join(orkas.workspaceRoot, 'account-e2e', 'cloud', 'contexts', name);+ await expect.poll(() => { try { return readFileSync(imported).equals(images.get(name)!); } catch { return false; } }).toBe(true);+ await expect.poll(async () => {+ const status: any = await orkas.invoke('kb.status');+ return status.files.find((file: any) => file.path === name)?.status;+ }, { timeout: 40_000 }).toBe('ready');+ }+ const win = await orkas.electronApp!.browserWindow(preview);+ for (const [width, height] of [[1040, 760], [480, 320]]) {+ await win.evaluate((win, size) => win.setContentSize(size[0], size[1]), [width, height]);+ const box = (await preview.locator('.chat-lightbox-actions').boundingBox())!;+ expect(box.x).toBeGreaterThanOrEqual(0);+ expect(box.x + box.width).toBeLessThanOrEqual(width);+ expect(box.y + box.height).toBeLessThanOrEqual(height);+ await preview.screenshot({ path: info.outputPath(`attachment-actions-${locale}-${width}.png`) });+ }+ await orkas.page!.evaluate(src => (window as any).openChatImageLightbox(src, 'Display only'), `data:image/png;base64,${png.toString('base64')}`);+ await expect(preview).toHaveTitle('Display only');+ await expect(image).toBeVisible();+ await expect(preview.locator('.chat-lightbox-actions')).toBeHidden();+ await preview.screenshot({ path: info.outputPath(`image-without-actions-${locale}.png`) });+ await orkas.electronApp!.evaluate(({ shell }) => { shell.showItemInFolder = (process as any).originalReveal; });+ });+}+test('task previews share one native window while different applications remain open together', async ({ orkas }, info) => {const page = orkas.page!;const expectBackgroundWindows = async () => {diff --git a/test/renderer/chat-lightbox.test.ts b/test/renderer/chat-lightbox.test.tsindex 33394a1f..d2169aa5 100644--- a/test/renderer/chat-lightbox.test.ts+++ b/test/renderer/chat-lightbox.test.ts@@ -24,6 +24,88 @@ function loadLightbox() {return context;}+function mountedLightbox() {+ const context = loadLightbox();+ context.t = (key: string) => key;+ context.document.removeEventListener = vi.fn();+ const elements = new Map<string, any>();+ const element = (key: string) => {+ if (!elements.has(key)) {+ const classes = new Set<string>();+ elements.set(key, { style: {}, hidden: false,+ classList: { contains: (name: string) => classes.has(name),+ add: (name: string) => classes.add(name), remove: (name: string) => classes.delete(name), toggle: vi.fn() },+ setAttribute: vi.fn(), removeAttribute: vi.fn(), addEventListener: vi.fn(), removeEventListener: vi.fn(), focus: vi.fn() });+ }+ return elements.get(key);+ };+ context.element = element;+ vm.runInContext(`+ _lightboxEl = element('root'); _lightboxEl.querySelector = element;+ _lightboxImg = element('image');+ _lightboxAddLibraryBtn = element('library'); _lightboxRevealBtn = element('reveal');+ `, context);+ const visibility = () => ['library', 'reveal'].map(key => !element(key).hidden);+ return { context, element, visibility };+}++describe('attachment image action recovery', () => {+ it('resolves the image owner on first open and reveals the resolved file', async () => {+ const { context, visibility } = mountedLightbox();+ const invoke = vi.fn(async () => ({ ok: true, path: '/fixtures/cover art.png' }));+ context.window.orkas = { invoke };+ context.openChatImageLightbox('chat-media://cid/source-chat/cover%20art.png', 'generated image', { cid: 'current-chat' });+ await vi.waitFor(() => expect(visibility()).toEqual([true, true]));+ expect(invoke).toHaveBeenCalledExactlyOnceWith('attachments.absPath', { cid: 'source-chat', name: 'cover art.png' });+ await context._onLightboxReveal({ stopPropagation: vi.fn() });+ expect(invoke).toHaveBeenLastCalledWith('workspace.revealPath', { path: '/fixtures/cover art.png', cid: 'source-chat' });+ });++ it.each(['replace', 'close'])('ignores resolution after %s and never transfers file ownership', async (action) => {+ const { context, visibility } = mountedLightbox();+ let finish!: (value: any) => void;+ context.window.orkas = { invoke: vi.fn(() => new Promise(resolve => { finish = resolve; })) };+ context.openChatImageLightbox('chat-media://cid/old/old.png', 'old');+ expect(context.window.orkas.invoke).toHaveBeenCalledOnce();+ if (action === 'close') context.closeChatImageLightbox();+ else context.openChatImageLightbox('https://example.com/new.png', 'new');+ finish({ ok: true, path: '/fixtures/old.png' });+ await new Promise(resolve => setTimeout(resolve, 0));+ expect(visibility()).toEqual([false, false]);+ await context._onLightboxReveal({ stopPropagation: vi.fn() });+ expect(context.window.orkas.invoke).toHaveBeenCalledTimes(1);+ });++ it('keeps the image open on lookup failure and retries when reopened', async () => {+ const { context, visibility, element } = mountedLightbox();+ context.window.orkas = { invoke: vi.fn().mockRejectedValueOnce(new Error('unavailable'))+ .mockResolvedValueOnce({ ok: false }).mockResolvedValueOnce({ ok: true, path: '/fixtures/retry.png' }) };+ for (let attempt = 0; attempt < 3; attempt++) {+ context.openChatImageLightbox('chat-media://cid/task/retry.png', 'retry');+ await new Promise(resolve => setTimeout(resolve, 0));+ expect(visibility()).toEqual(Array(2).fill(attempt === 2));+ expect(element('image').src).toBe('chat-media://cid/task/retry.png');+ expect(context._isOpen()).toBe(true);+ }+ expect(context.window.orkas.invoke).toHaveBeenCalledTimes(3);+ });++ it('does not resolve remote, malformed, or already-owned image sources', () => {+ const { context, visibility } = mountedLightbox();+ context.window.orkas = { invoke: vi.fn() };+ for (const src of ['https://example.com/cover.png', 'chat-media://cid/task/%E0%A4%A.png',+ 'chat-media://cid/task/folder%2Fcover.png', 'chat-media://cid/task/']) {+ context.openChatImageLightbox(src, 'image');+ expect(visibility()).toEqual([false, false]);+ }+ context.openChatImageLightbox('chat-media://cid/task/cover.png', 'image', { absPath: '/fixtures/cover.png', cid: 'task' });+ expect(visibility()).toEqual([true, true]);+ context.openChatImageLightbox('chat-media://local/fixtures/cover.png', 'image', { cid: 'task' });+ expect(visibility()).toEqual([true, true]);+ expect(context.window.orkas.invoke).not.toHaveBeenCalled();+ });+});+describe('chat image lightbox file ownership', () => {it('forwards an outside image path when the user clicks reveal and re-enables the button', async () => {const context = loadLightbox();