Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(claude-code): 保留远程会话本地图片警告
DavidShene0eda0fc6bfa
diff --git a/apps/desktop/src/main/__tests__/normalizeAttachmentsOss.test.ts b/apps/desktop/src/main/__tests__/normalizeAttachmentsOss.test.tsindex 434d3f0e72..653413bb60 100644--- a/apps/desktop/src/main/__tests__/normalizeAttachmentsOss.test.ts+++ b/apps/desktop/src/main/__tests__/normalizeAttachmentsOss.test.ts@@ -148,10 +148,13 @@ describe('normalizeUserMessage — device-link 出方向 OSS 引用物化', () =const [ossKeyArg, destArg] = downloadToFile.mock.calls[0] as unknown as [string, string];expect(ossKeyArg).toBe('cindy/device-link/u/x.png');expect(destArg).toMatch(/cindy-attachments[\\/]v2-[^\\/]+[\\/]sess-1[\\/].+\.png$/);- const block = (out as { content: Array<{ type: string; path?: string; mimeType?: string }> })+ const block = (out as {+ content: Array<{ type: string; path?: string; mimeType?: string; pathOrigin?: string }>;+ }).content[1];expect(block.path).toBe(destArg); // path 指向下载目标expect(block.mimeType).toBe('image/png');+ expect(block.pathOrigin).toBe('desktop-host');expect(removeRemote).toHaveBeenCalledWith('cindy/device-link/u/x.png');});diff --git a/apps/desktop/src/main/maker-ipc/__tests__/normalizeAttachmentsTemp.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/normalizeAttachmentsTemp.test.tsindex d3975df770..e018dbdef5 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/normalizeAttachmentsTemp.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/normalizeAttachmentsTemp.test.ts@@ -66,7 +66,10 @@ describe('inline attachment temporary files', () => {}const imageBlock = normalized.content.find((block) => block.type === 'image');const imagePath = imageBlock?.path;- if (typeof imagePath !== 'string') throw new Error('expected materialized image path');+ if (!imageBlock || typeof imagePath !== 'string') {+ throw new Error('expected materialized image path');+ }+ expect(imageBlock.pathOrigin).toBe('desktop-host');const sessionTempDir = path.dirname(imagePath);const ownerRoot = path.dirname(sessionTempDir);const ownerRecord = JSON.parse(diff --git a/apps/desktop/src/main/maker-ipc/normalizeAttachments.ts b/apps/desktop/src/main/maker-ipc/normalizeAttachments.tsindex 39ede26e34..b7f4b4999d 100644--- a/apps/desktop/src/main/maker-ipc/normalizeAttachments.ts+++ b/apps/desktop/src/main/maker-ipc/normalizeAttachments.ts@@ -272,6 +272,7 @@ type AttachmentBlock = {path?: string;base64?: string;mimeType?: string;+ pathOrigin?: 'desktop-host';};type UserMessageShape = string | { type: 'user'; content: string | RawBlock[] };@@ -299,6 +300,16 @@ export async function normalizeUserMessage(}const block = { ...raw } as AttachmentBlock & { type: 'image' | 'file' };+ const isDesktopHostImage = block.type === 'image' && (+ block.pathOrigin === 'desktop-host'+ || Boolean(block.base64)+ || (typeof block.path === 'string' && (+ block.path.startsWith('xdt-image://')+ || block.path.startsWith('cindy-media://')+ || isAttachmentOssRef(block.path)+ ))+ );+ if (isDesktopHostImage) block.pathOrigin = 'desktop-host';// 0) device-link 出方向 OSS 引用(控制端发来的附件)→ presign-get 下载物化到临时文件,// 用后删 OSS。新引用下载/校验失败 → 整条不发;旧引用保留历史的单附件降级语义。diff --git a/apps/desktop/src/renderer/__tests__/messageAttachmentPayload.test.ts b/apps/desktop/src/renderer/__tests__/messageAttachmentPayload.test.tsindex 66f0125efc..df580710d6 100644--- a/apps/desktop/src/renderer/__tests__/messageAttachmentPayload.test.ts+++ b/apps/desktop/src/renderer/__tests__/messageAttachmentPayload.test.ts@@ -65,6 +65,7 @@ describe('messageAttachmentPayload', () => {type: 'image',path: 'xdt-image://session/shot.png',mimeType: 'image/png',+ pathOrigin: 'desktop-host',originalName: 'original.png',},]);@@ -95,11 +96,33 @@ describe('messageAttachmentPayload', () => {type: 'image',base64: 'inline-image',mimeType: 'image/png',+ pathOrigin: 'desktop-host',originalName: 'fallback.png',},]);});+ it('marks a desktop image path so remote sessions can keep the local-file warning', () => {+ const imagePath = join('desktop', 'photo.jpg');+ const image = attachment({+ name: 'photo.jpg',+ path: imagePath,+ ext: '.jpg',+ category: 'image',+ mimeType: 'image/jpeg',+ });++ expect(buildMakerUserContentBlocks('', undefined, [image])).toEqual([+ {+ type: 'image',+ path: imagePath,+ mimeType: 'image/jpeg',+ pathOrigin: 'desktop-host',+ originalName: 'photo.jpg',+ },+ ]);+ });+it('passes non-image files by path for render, persist, and SDK send', () => {const pdfPath = join('repo', 'doc.pdf');const pdf = attachment({diff --git a/apps/desktop/src/renderer/lib/messageAttachmentPayload.ts b/apps/desktop/src/renderer/lib/messageAttachmentPayload.tsindex 77ab2c5c4b..f1ba8785c6 100644--- a/apps/desktop/src/renderer/lib/messageAttachmentPayload.ts+++ b/apps/desktop/src/renderer/lib/messageAttachmentPayload.ts@@ -30,6 +30,7 @@ export type SdkAttachmentBlock = {path?: string;base64?: string;mimeType?: string;+ pathOrigin?: 'desktop-host';originalName?: string;/*** 显式文件附件的原始磁盘路径(path 为 xdt-image:// 缓存 URL 时携带):@@ -143,6 +144,7 @@ export function buildUserMessageAttachmentPayload(function buildAttachmentBlock(file: SerializedAttachedFile): SdkAttachmentBlock | null {const type = getAgentInputAttachmentBlockType(file.category, file.ext);+ const pathOrigin = type === 'image' ? { pathOrigin: 'desktop-host' as const } : {};if (file.url) {// 显式文件(选择器/拖拽)拷入缓存后 url 与原始磁盘 path 并存:把原始路径一并// 带上,message 形态的远程发送才能识别「字节精确」语义不压缩(队列形态的@@ -154,6 +156,7 @@ function buildAttachmentBlock(file: SerializedAttachedFile): SdkAttachmentBlocktype,path: file.url,mimeType: file.mimeType,+ ...pathOrigin,originalName: file.originalName ?? file.name,...(originalPath ? { originalPath } : {}),};@@ -163,6 +166,7 @@ function buildAttachmentBlock(file: SerializedAttachedFile): SdkAttachmentBlocktype,path: file.path,mimeType: file.mimeType,+ ...pathOrigin,originalName: file.originalName ?? file.name,};}@@ -173,6 +177,7 @@ function buildAttachmentBlock(file: SerializedAttachedFile): SdkAttachmentBlocktype,base64: legacyBase64,mimeType: file.mimeType,+ ...pathOrigin,originalName: file.originalName ?? file.name,};}diff --git a/packages/maker-core/src/agents/claude-code/__tests__/plan-mode.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/plan-mode.test.tsindex 887d7dfb61..fce16f76bb 100644--- a/packages/maker-core/src/agents/claude-code/__tests__/plan-mode.test.ts+++ b/packages/maker-core/src/agents/claude-code/__tests__/plan-mode.test.ts@@ -550,6 +550,59 @@ describe('ClaudeCodeAgent plan mode', () => {await handle.close();});+ it('warns when an SSH session receives a desktop-local image', async () => {+ const configDir = await makeTempDir();+ process.env.CLAUDE_CONFIG_DIR = configDir;+ const workingDir = await makeTempDir();+ const imagePath = path.join(workingDir, 'desktop.png');+ const remoteSend = vi.fn(async () => {});+ const fakeQuery = { ...createFakeQuery(), send: remoteSend };+ const remoteCcQueryFactory: NonNullable<AgentDeps['remoteCcQueryFactory']> = async () =>+ fakeQuery as never;+ const logger = createNoopLogger();+ const warn = vi.spyOn(logger, 'warn');+ const agent = new ClaudeCodeAgent(createDeps({ logger, remoteCcQueryFactory }));+ const handle = await agent.startSession({+ sessionId: 'session-remote-desktop-image',+ model: 'claude-opus-4-6',+ workingDir,+ remoteHostId: 'remote-1',+ permissionMode: 'auto',+ });+ const iterator = handle.events()[Symbol.asyncIterator]();++ await handle.send({+ type: 'user',+ content: [+ {+ type: 'image',+ path: imagePath,+ mimeType: 'image/png',+ pathOrigin: 'desktop-host',+ },+ { type: 'text', text: 'Inspect this' },+ ],+ });+ await vi.waitFor(() => expect(remoteSend).toHaveBeenCalledTimes(1));++ expect(warn).toHaveBeenCalledWith(+ 'cc remote: local attachment not accessible on remote session',+ expect.objectContaining({+ sessionId: 'session-remote-desktop-image',+ hostId: 'remote-1',+ }),+ );+ const events = [await nextEvent(iterator), await nextEvent(iterator)];+ expect(events).toContainEqual(expect.objectContaining({+ type: 'error',+ data: expect.objectContaining({+ message: expect.stringContaining('[REMOTE_LOCAL_ATTACHMENT_UNSUPPORTED]'),+ isTerminal: false,+ }),+ }));+ await handle.close();+ });+it('overrides remote cc-manager env with a host-materialized Claude route', async () => {const configDir = await makeTempDir();process.env.CLAUDE_CONFIG_DIR = configDir;diff --git a/packages/maker-core/src/agents/claude-code/index.ts b/packages/maker-core/src/agents/claude-code/index.tsindex f064910624..df9886b765 100644--- a/packages/maker-core/src/agents/claude-code/index.ts+++ b/packages/maker-core/src/agents/claude-code/index.ts@@ -5160,10 +5160,12 @@ export class ClaudeCodeAgent extends BaseAgent {// 这里 MVP 检测到附件就 emit warn event 让用户知道,实际请求里把附件 ref 留着// (daemon 端 SDK 读不到就跳过, 不会 crash)。if (opts.remoteHostId && Array.isArray(message.content)) {- const hasFileAttachment = message.content.some(- (b) => b.type === 'file' || b.type === 'mention',+ const hasDesktopLocalAttachment = message.content.some(+ (b) => b.type === 'file'+ || b.type === 'mention'+ || (b.type === 'image' && b.pathOrigin === 'desktop-host'),);- if (hasFileAttachment) {+ if (hasDesktopLocalAttachment) {log.warn('cc remote: local attachment not accessible on remote session', {sessionId: opts.sessionId,hostId: opts.remoteHostId,diff --git a/packages/maker-core/src/types/common.ts b/packages/maker-core/src/types/common.tsindex c08fb40ebc..361615095f 100644--- a/packages/maker-core/src/types/common.ts+++ b/packages/maker-core/src/types/common.ts@@ -45,7 +45,7 @@ export type ReasoningDisplay = 'off' | 'summarized' | 'full';*/export type UserContentBlock =| { type: 'text'; text: string }- | { type: 'image'; path: string; mimeType?: string }+ | { type: 'image'; path: string; mimeType?: string; pathOrigin?: 'desktop-host' }| { type: 'file'; path: string; mimeType?: string }| { type: 'mention'; name: string; path: string; kind?: 'file' | 'dir' | 'agent' };