Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(sharing): verify MCP output candidate timestamps

david89c9ca61cc69
diff --git a/apps/desktop/src/main/device-link/__tests__/sharedTaskMediaAccess.test.ts b/apps/desktop/src/main/device-link/__tests__/sharedTaskMediaAccess.test.ts
index 4ec660ea7a..a2fd9080e9 100644
--- a/apps/desktop/src/main/device-link/__tests__/sharedTaskMediaAccess.test.ts
+++ b/apps/desktop/src/main/device-link/__tests__/sharedTaskMediaAccess.test.ts
@@ -155,23 +155,27 @@ describe('shared task media access', () => {
else await expect(assertSharedTaskMedia(url, capture)).rejects.toThrow('PERMISSION_DENIED');
}
});
- // A successful no-clobber command can leave a pre-existing target untouched.
- // Lexical output paths need file/time evidence before granting outside access.
- it.each(['written', 'unchanged', 'later-write', 'directory', 'stat-error', 'missing-time', 'revoked'])('checks command output file evidence: %s', async (kind) => {
- // The extractor intentionally excludes temp directories; do not depend on
- // whether this checkout itself happens to live under a temp directory.
- const file = path.join(path.parse(process.cwd()).root, 'deliveries', 'private.pdf');
- const row = { rowid: 1, role: 'tool_use', toolUseId: 'copy-1', createdAt: 100,
- content: JSON.stringify({ toolName: 'Bash', input: { command: `cp -n /work/source.txt "${markdownPath(file)}"` } }) };
- deps.query.mockResolvedValueOnce([row]).mockResolvedValueOnce([{ content: JSON.stringify(''), createdAt: kind === 'missing-time' ? null : 200 }]);
- deps.stat.mockImplementation(async () => {
- if (kind === 'stat-error') throw new Error('ENOENT');
- if (kind === 'revoked') current = false;
- return { isFile: () => kind !== 'directory', mtimeMs: kind === 'unchanged' ? 99 : kind === 'later-write' ? 201 : 150 };
+ // Successful shell/MCP calls can leave a pre-existing target untouched.
+ // Input output paths need file/time evidence before granting outside access.
+ describe.each(['command', 'mcp'])('%s output candidates', (source) => {
+ it.each(['written', 'unchanged', 'later-write', 'directory', 'stat-error', 'missing-time', 'revoked'])('checks output file evidence: %s', async (kind) => {
+ // The extractor intentionally excludes temp directories; do not depend on
+ // whether this checkout itself happens to live under a temp directory.
+ const file = path.join(path.parse(process.cwd()).root, 'deliveries', 'private.pdf');
+ const row = { rowid: 1, role: 'tool_use', toolUseId: 'copy-1', createdAt: 100,
+ content: JSON.stringify(source === 'command'
+ ? { toolName: 'Bash', input: { command: `cp -n /work/source.txt "${markdownPath(file)}"` } }
+ : { toolName: 'mcp:reports:generate', input: { outPath: file } }) };
+ deps.query.mockResolvedValueOnce([row]).mockResolvedValueOnce([{ content: JSON.stringify(''), createdAt: kind === 'missing-time' ? null : 200 }]);
+ deps.stat.mockImplementation(async () => {
+ if (kind === 'stat-error') throw new Error('ENOENT');
+ if (kind === 'revoked') current = false;
+ return { isFile: () => kind !== 'directory', mtimeMs: kind === 'unchanged' ? 99 : kind === 'later-write' ? 201 : 150 };
+ });
+ const access = assertSharedTaskMedia('xdt-file://local?path=' + encodeURIComponent(file), capture);
+ if (kind === 'written') await expect(access).resolves.toEqual({ file });
+ else await expect(access).rejects.toThrow('PERMISSION_DENIED');
});
- const access = assertSharedTaskMedia('xdt-file://local?path=' + encodeURIComponent(file), capture);
- if (kind === 'written') await expect(access).resolves.toEqual({ file });
- else await expect(access).rejects.toThrow('PERMISSION_DENIED');
});
// Direct result links must pass the same completed/non-failed provenance gate
// as tool-use outputs; an error message mentioning a URL is not a delivery.
@@ -187,6 +191,7 @@ describe('shared task media access', () => {
});
if (kind === 'ok') await expect(assertSharedTaskMedia(url, capture)).resolves.toEqual({ file });
else await expect(assertSharedTaskMedia(url, capture)).rejects.toThrow('PERMISSION_DENIED');
+ expect(deps.stat).not.toHaveBeenCalled();
if (kind !== 'missing-id') {
expect(deps.query.mock.calls[1][0]).toContain('rewind_at IS NULL AND tool_use_id = ? AND rowid < ?');
expect(deps.query.mock.calls[1][1]).toEqual(['task', 'run-1', 2]);
@@ -197,10 +202,11 @@ describe('shared task media access', () => {
const file = path.resolve('deliveries/report.pdf');
const url = 'xdt-file://local?path=' + encodeURIComponent(file);
const tool = { toolName: 'mcp:reports:generate', input: role === 'tool_use' ? { outPath: file } : {} };
+ deps.stat.mockResolvedValue({ isFile: () => true, mtimeMs: 150 });
for (const success of [false, true]) {
const result = { ok: true, result: { ok: success, xdt_media_produced: [url] } };
- deps.query.mockResolvedValueOnce([{ rowid: role === 'tool_use' ? 1 : 2, role, toolUseId: 'generate-1', content: JSON.stringify(role === 'tool_use' ? tool : result) }])
- .mockResolvedValueOnce([{ content: JSON.stringify(role === 'tool_use' ? result : tool) }]);
+ deps.query.mockResolvedValueOnce([{ rowid: role === 'tool_use' ? 1 : 2, role, toolUseId: 'generate-1', createdAt: 100, content: JSON.stringify(role === 'tool_use' ? tool : result) }])
+ .mockResolvedValueOnce([{ content: JSON.stringify(role === 'tool_use' ? result : tool), createdAt: 200 }]);
const access = assertSharedTaskMedia(url, capture);
if (success) await expect(access).resolves.toEqual({ file });
else await expect(access).rejects.toThrow('PERMISSION_DENIED');
diff --git a/apps/desktop/src/main/device-link/sharedTaskFileReferences.ts b/apps/desktop/src/main/device-link/sharedTaskFileReferences.ts
index 55fe8304ab..e3f0e40b36 100644
--- a/apps/desktop/src/main/device-link/sharedTaskFileReferences.ts
+++ b/apps/desktop/src/main/device-link/sharedTaskFileReferences.ts
@@ -181,9 +181,9 @@ export async function sharedTaskReferencesFile(
const result = decode(results[0].content);
const descriptor = describeToolUse(tool.toolName, tool.input);
if (toolResultFailed(descriptor, result)) continue;
- if (descriptor.kind === 'command') {
- // Output-path extraction is lexical. A successful no-clobber command
- // must not expose an untouched, pre-existing file at its destination.
+ if (descriptor.kind === 'command' || descriptor.kind === 'mcp') {
+ // Shell destinations and MCP output arguments are only candidates.
+ // Success must not expose an untouched, pre-existing destination file.
const start = row.createdAt;
const end = results[0].createdAt;
if (!Number.isFinite(start) || !Number.isFinite(end) || end < start) continue;
diff --git a/docs/product-rules/shared-task-mode.md b/docs/product-rules/shared-task-mode.md
index 26af3153e2..b415b36ee0 100644
--- a/docs/product-rules/shared-task-mode.md
+++ b/docs/product-rules/shared-task-mode.md
@@ -43,7 +43,7 @@
- 任务关联的本机文件即使位于工作目录外,访客也可经原有取件通道只读访问(2026-10-19 修复):归属由房主端当前未回退且未被 `/clear` 隐藏的消息记录确认,包括主机已校验并接收的结构化附件(含访客上传)、房主/Agent 明确交付的文件链接及已完成且未报错的工具产出。文件引用及配对的工具调用、结果均须晚于任务的清空边界;清空前的记录即使仍在数据库中,也不再提供授权。访客自行粘贴的路径、代码示例、其他任务记录或仅前缀相同的路径不构成授权;仅放行关联的具体文件,不开放其父目录浏览或写入。取件继续检查成员资格、敏感路径和解析后的文件身份,不缓存历史授权结论。Desktop 与 Mobile 共用房主校验,无新增 wire 字段;SSH 的工作目录限界保持原规则,不以本机路径例外绕过。实现与回归见 `sharedTaskFileReferences.ts`、`sharedTaskMediaAccess.ts` 及 `sharedTaskMediaAccess.test.ts`、`mediaFetch.test.ts`。
- 工具结果中的普通文本链接不构成外部文件交付,包括读取、搜索、网页或 shell 返回的内容。原生工具产出沿用调用中明确声明的输出路径;MCP/动态工具的结果只认既有结构化交付字段 `xdt_media_produced`、`_xdt_model_files`,并继续核对调用配对、成功状态及当前历史边界。原生读取和 shell 输出即使形似这些字段,也不按交付解释。房主/Agent 在消息中明确交付的链接仍按上述规则处理。
- 工具结果外层 `ok: true` 仅代表调用包装成功,内层 `result` 的失败状态同样阻止文件授权,调用产出路径与结果交付字段使用相同判定。房主/Agent 消息中可解析为文件链接的正文路径和完整行内代码路径沿用界面已有的链接/文件卡片语义;代码块中的示例、普通代码表达式、链接标签中的路径不提供额外授权。正文路径分词由 Renderer 与房主共用 `shared/bareFilePathTokens.ts`,仍须完整匹配请求文件。
-- shell 命令中的输出路径只是词法候选,不能仅凭调用成功就授权工作目录外的旧文件。取件时还须确认目标为普通文件,修改时间落在该调用到配对结果的执行时段内;无法读取元数据、缺少有效时间、未修改的旧目标或执行时段外的修改均不能使用该命令作为授权依据。显式消息链接及结构化交付仍按各自规则处理。
+- shell 命令中的输出路径及 MCP 输入中的输出路径(如 `outPath`)只是候选,不能仅凭调用成功就授权工作目录外的旧文件。取件时还须确认目标为普通文件,修改时间落在该调用到配对结果的执行时段内;无法读取元数据、缺少有效时间、未修改的旧目标或执行时段外的修改均不能使用该调用的输入路径作为授权依据。显式消息链接及结构化交付仍按各自规则处理。
- 消息按主机现有输入队列顺序处理,保留 clientId 幂等。访客仅编辑/撤回自己未处理消息,房主可处理全部未处理消息;直接更新内容,不显示“已编辑”。
- 发言者身份来自经过验证的账号和成员关系,不能信任消息正文或客户端自报的身份。