Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(sharing): align attachments with relay storage prefix
DavidShena37de9224bac
diff --git a/apps/desktop/src/main/device-link/__tests__/outboundMedia.test.ts b/apps/desktop/src/main/device-link/__tests__/outboundMedia.test.tsindex ffea54a288..ef5a259743 100644--- a/apps/desktop/src/main/device-link/__tests__/outboundMedia.test.ts+++ b/apps/desktop/src/main/device-link/__tests__/outboundMedia.test.ts@@ -45,21 +45,21 @@ describe('rewriteOutboundMedia — channel gating', () => {const attachment = buildUserMessageAttachmentPayload([{ id: 'image', name: 'a.png', path: '/controller/a.png', url: 'xdt-image://task/a.png', size: 10, ext: '.png', category: 'image', mimeType: 'image/png' }]);expect(attachment.serializedFiles?.[0].pathOrigin).toBe('desktop-host');resolveSafe.mockReturnValue({ absPath: '/cache/a.png', mimeType: 'image/png' });- uploadLocalFile.mockResolvedValue({ key: 'cindy/shared-task/sharedTask/u/a.png', contentType: 'image/png', size: 10, sha256: SHA256 });+ uploadLocalFile.mockResolvedValue({ key: 'cindy/device-link/shared-task/sharedTask/u/a.png', contentType: 'image/png', size: 10, sha256: SHA256 });const item = { files: attachment.serializedFiles, persistedContent: JSON.stringify({ images: attachment.persistImageRefs }), chatMessage: { images: attachment.imageAttachments } };const result = await withSharedTaskMedia('sharedTask', () => rewriteOutboundMedia('maker:input:enqueue', ['task', item]));expect(uploadLocalFile).toHaveBeenCalledWith('/cache/a.png', { contentType: 'image/png' });expect(() => assertSharedTaskReferences(result[1], 'task', 0, 'sharedTask')).not.toThrow();});it('rewrites newly added shared queue-edit attachments and preserves host-owned existing files', async () => {- uploadLocalFile.mockResolvedValue({ key: 'cindy/shared-task/sharedTask/u/new.png', contentType: 'image/png', size: 10, sha256: SHA256 });+ uploadLocalFile.mockResolvedValue({ key: 'cindy/device-link/shared-task/sharedTask/u/new.png', contentType: 'image/png', size: 10, sha256: SHA256 });const item = { files: [{ path: '/host/cache/old.png', pathOrigin: 'desktop-host' }, { path: '/controller/new.png' }], persistedContent: JSON.stringify({ files: [{ path: '/host/cache/old.png' }, { path: '/controller/new.png' }] }) };const result = await withSharedTaskMedia('sharedTask', () => rewriteOutboundMedia('maker:input:update-content', ['task', 'client', item], new Set(['/host/cache/old.png'])));expect(uploadLocalFile).toHaveBeenCalledTimes(1);expect(uploadLocalFile).toHaveBeenCalledWith('/controller/new.png', {});const rewritten = result[2] as typeof item;expect(rewritten.files[0].path).toBe('/host/cache/old.png');- expect(parseAttachmentOssRef(rewritten.files[1].path)?.ossKey).toBe('cindy/shared-task/sharedTask/u/new.png');+ expect(parseAttachmentOssRef(rewritten.files[1].path)?.ossKey).toBe('cindy/device-link/shared-task/sharedTask/u/new.png');expect(rewritten.persistedContent).not.toContain('/controller/new.png');});it('非媒体 channel → 原样,不上传', async () => {@@ -87,7 +87,7 @@ describe('rewriteOutboundMedia — channel gating', () => {describe('rewriteQueued — persistedContent 同批改写 + 去重单上传', () => {it('sends a shared Desktop attachment without leaking local optimistic/retry paths', async () => {- uploadLocalFile.mockResolvedValue({ key: 'cindy/shared-task/shared/u/file.pdf', size: 10, contentType: 'application/pdf', sha256: SHA256 });+ uploadLocalFile.mockResolvedValue({ key: 'cindy/device-link/shared-task/shared/u/file.pdf', size: 10, contentType: 'application/pdf', sha256: SHA256 });const file = { name: 'file.pdf', path: '/local/file.pdf', mimeType: 'application/pdf', category: 'file' };const input = { text: 'Read this', files: [file], persistedContent: JSON.stringify({ text: 'Read this', files: [{ name: file.name, path: file.path }] }),chatMessage: { role: 'user', content: 'Read this', files: [file], images: [{ url: '/local/preview.png' }], retryFiles: [file], retryMentions: [{ path: '/local/file.pdf' }] } };diff --git a/apps/mobile/src/__tests__/mobileAttachmentUpload.test.ts b/apps/mobile/src/__tests__/mobileAttachmentUpload.test.tsindex 74565ea0fe..897b56b6cd 100644--- a/apps/mobile/src/__tests__/mobileAttachmentUpload.test.ts+++ b/apps/mobile/src/__tests__/mobileAttachmentUpload.test.ts@@ -23,7 +23,7 @@ const readFileChunk = vi.fn(async (_uri: string, _position: number, length: numbdescribe('mobileAttachmentUpload', () => {it('presigns against the captured shared task rather than the private account namespace', async () => {- const apiFetch = vi.fn(async () => ({ putUrl: 'https://oss.example/upload', key: 'cindy/shared-task/task/u/file.png', expiresAt: '2026-09-16T12:00:00Z' }));+ const apiFetch = vi.fn(async () => ({ putUrl: 'https://oss.example/upload', key: 'cindy/device-link/shared-task/task/u/file.png', expiresAt: '2026-09-16T12:00:00Z' }));await presignMobileAttachmentUpload({ name: 'file.png', size: 10, mimeType: 'image/png' }, {token: 'token', sharedTaskId: 'task', deps: { apiFetch: apiFetch as unknown as typeof apiFetchRaw },});diff --git a/docs/product-rules/shared-task-mode.md b/docs/product-rules/shared-task-mode.mdindex 5780be5cd0..f7726f1367 100644--- a/docs/product-rules/shared-task-mode.md+++ b/docs/product-rules/shared-task-mode.md@@ -47,6 +47,7 @@- 复用 packages/device-link;新增跨账号的单任务授权,禁止降级为旧版全设备远控。- 同时校验 invoke、push、历史、附件、嵌套引用、离线补发与结果缓存的任务及成员归属。+- 共享附件使用 `cindy/device-link/shared-task/<sharedTaskId>/<uploaderAccountId>/<uuid.ext>`,复用既有中转前缀的 OSS 授权与生命周期;共享路径仍按任务和当前成员校验,不回退为同账号对象权限。客户端与服务端同步升级,不保留未发布开发版顶层 `cindy/shared-task/` 路径别名;普通远控附件路径不变。- Desktop 与 Mobile 复用现有任务页面;房主在手机上通过既有同账号远控管理共享。网页端和匿名访客不在范围内。- 新协议以能力协商开放;缺少能力提示升级。两区域独立,不默认跨区域加入。- 关闭记录必须落入原 profile 的 journal 后才能释放数据库;本地同步撤权,服务端失败下次恢复重试。diff --git a/packages/device-link/src/__tests__/sharedTask.test.ts b/packages/device-link/src/__tests__/sharedTask.test.tsindex 1de20ff20d..5e47e6589d 100644--- a/packages/device-link/src/__tests__/sharedTask.test.ts+++ b/packages/device-link/src/__tests__/sharedTask.test.ts@@ -24,8 +24,16 @@ describe('sharedTask authorization', () => {});it('only permits attachment references in this sharing namespace', () => {const ref = (ossKey: string) => buildAttachmentOssRef({ ossKey, originalName: 'image.png', mimeType: 'image/png', size: 1, sha256: 'a'.repeat(64) });- expect(isSharedTaskAttachment(ref('cindy/shared-task/shared/u/file.png'), 'shared')).toBe(true);- for (const key of ['cindy/shared-task/other/u/file.png', 'cindy/device-link/u/file.png', 'cindy/shared-task/shared/u/../file.png']) {+ expect(isSharedTaskAttachment(ref('cindy/device-link/shared-task/shared/u/file.png'), 'shared')).toBe(true);+ for (const key of [+ 'cindy/device-link/shared-task/other/u/file.png',+ 'cindy/device-link/u/file.png',+ 'cindy/device-link/shared-task/file.png',+ 'cindy/device-link/shared-task/shared/u/../file.png',+ 'cindy/device-link/shared-task/shared/u/%2e%2e',+ 'cindy/device-link/shared-task/shared/u',+ 'cindy/shared-task/shared/u/file.png',+ ]) {expect(isSharedTaskAttachment(ref(key), 'shared')).toBe(false);}expect(isSharedTaskAttachment('file:///private/file.png', 'shared')).toBe(false);diff --git a/packages/device-link/src/sharedTask.ts b/packages/device-link/src/sharedTask.tsindex f4f029e62a..24f5be7dec 100644--- a/packages/device-link/src/sharedTask.ts+++ b/packages/device-link/src/sharedTask.ts@@ -10,8 +10,9 @@ import { parseAttachmentOssRef } from './attachmentOssRef.js';export function isSharedTaskAttachment(value: string, sharedTaskId: string): boolean {const ref = parseAttachmentOssRef(value);const parts = ref?.ossKey.split('/');- return !!parts && parts.length === 5 && parts[0] === 'cindy' && parts[1] === 'shared-task' &&- parts[2] === sharedTaskId && parts.slice(2).every((part) => /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(part));+ return !!parts && parts.length === 6 && parts[0] === 'cindy' && parts[1] === 'device-link' &&+ parts[2] === 'shared-task' && parts[3] === sharedTaskId &&+ parts.slice(3).every((part) => /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(part));}export const SHARED_TASK_CAPABILITY = 'shared-task-v1';