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(agent): block native history transfer through shared task routes

Dashd7f3cfe16fdd
diff --git a/apps/desktop/src/main/remote-agent/__tests__/relocateNativeHistory.test.ts b/apps/desktop/src/main/remote-agent/__tests__/relocateNativeHistory.test.ts
index 76d3f9d6ea..4150d8e167 100644
--- a/apps/desktop/src/main/remote-agent/__tests__/relocateNativeHistory.test.ts
+++ b/apps/desktop/src/main/remote-agent/__tests__/relocateNativeHistory.test.ts
@@ -1,4 +1,5 @@
import { beforeEach, expect, it, vi } from 'vitest';
+import { providerShareHostPeer } from '@cindy/device-link';
import { createNativeHistoryRelocator } from '../controller/relocateNativeHistory';
const h = vi.hoisted(() => ({ generation: 1, caps: vi.fn(), remote: vi.fn(), transfer: vi.fn(), local: vi.fn() }));
@@ -13,6 +14,21 @@ beforeEach(() => { vi.resetAllMocks(); h.generation = 1; });
const input = { sessionId: 'task', kind: 'codex' as const, nativeId: 'native', workingDir: '/project',
fromDevice: null, toDevice: 'mini', assertCurrent: () => {} };
+it.each([
+ ['task source', 'share:untrusted', 'mini'],
+ ['task destination', null, 'share:untrusted'],
+ ['resolved source', providerShareHostPeer('untrusted', 'host'), 'mini'],
+ ['resolved destination', null, providerShareHostPeer('untrusted', 'host')],
+])('rejects a sharing %s before consulting its advertised capability', async (_label, fromDevice, toDevice) => {
+ h.caps.mockResolvedValue({ nativeHistoryTransfer: true });
+ h.transfer.mockResolvedValue('restored');
+ expect(await createNativeHistoryRelocator('/test-user-data', vi.fn())({ ...input, fromDevice, toDevice })).toBeNull();
+ expect(h.caps).not.toHaveBeenCalled();
+ expect(h.transfer).not.toHaveBeenCalled();
+ expect(h.remote).not.toHaveBeenCalled();
+ expect(h.local).not.toHaveBeenCalled();
+});
+
it('leaves old peers on the existing handoff path without starting a snapshot', async () => {
h.caps.mockResolvedValue({});
expect(await createNativeHistoryRelocator('/test-user-data', vi.fn())(input)).toBeNull();
diff --git a/apps/desktop/src/main/remote-agent/controller/relocateNativeHistory.ts b/apps/desktop/src/main/remote-agent/controller/relocateNativeHistory.ts
index 63ed38793f..1bf88480e1 100644
--- a/apps/desktop/src/main/remote-agent/controller/relocateNativeHistory.ts
+++ b/apps/desktop/src/main/remote-agent/controller/relocateNativeHistory.ts
@@ -1,5 +1,6 @@
import path from 'node:path';
import { isProviderSharePeer } from '@cindy/device-link';
+import { isProviderShareAgentDeviceId } from '../../../shared/providerShare.js';
import { getActiveAppSession } from '../../appSessionState';
import { createNativeHistoryTransfer, transferNativeHistory, type NativeHistoryEndpoint } from '../nativeHistoryTransfer';
import { nativeHistoryStorage } from '../nativeHistoryStorage';
@@ -13,7 +14,8 @@ export function createNativeHistoryRelocator(userDataDir: string, invoke: Device
fromDevice: string | null; toDevice: string | null; assertCurrent(): void;
}): Promise<string | null> => {
// Sharing relays have different ownership and storage. They retain the existing handoff fallback.
- if ([input.fromDevice, input.toDevice].some(device => device && isProviderSharePeer(device))) return null;
+ if ([input.fromDevice, input.toDevice].some(device =>
+ isProviderShareAgentDeviceId(device) || isProviderSharePeer(device))) return null;
const owner = getActiveAppSession();
const assertCurrent = () => {
input.assertCurrent();
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 224660c102..80d4a3306e 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -3,6 +3,7 @@
## 同 Harness 换电脑接续原生记录
`remote-agent` caps 增加可选 `nativeHistoryTransfer: true`,仅同账号 owner 可用;缺省、旧端或分享中转继续使用 handoff。
+发送端在查询能力前同时拒绝来源与目标的 `share:<id>` 任务位置及已解析的分享 peer;不以跨账号对端自报能力作为原生历史传输授权。
同通道新增 `native-history` 操作,携带任务 ID 与 export/import/read/write/restore/release 命令。
接收端自行决定原生目录,不接收目标路径;Pi 源路径必须在本机 Pi home 内。临时句柄绑定账号代次、控制端与任务,
每段至多 512 KiB,顺序与 SHA-256 完整性校验通过才导入;原生 ID 重新生成,源记录不修改。
@@ -14,7 +15,7 @@ Pi 只改写副本首行的 session ID 与 cwd,使其指向接收端工作目
这些命令不加入只读/断链自动重放名单。恢复失败回落已有的原子 resume fallback,不把切账号或清空历史当普通失败。
边界消息增加可选 `nativeHistory: restored | fallback`,桌面与手机在 fallback 时显示「已用摘要接续」;旧客户端忽略新增字段,
仍能读取原有 handoff/resumed。无服务端、数据库 schema、环境变量或 Mobile 原生配置变化。
-回归:`nativeHistoryTransfer.test.ts`、`nativeHistoryStorage.test.ts`、`sessionAgentSwitchHandler.test.ts`、device-link `remoteAgent.test.ts`。
+回归:`relocateNativeHistory.test.ts`、`nativeHistoryTransfer.test.ts`、`nativeHistoryStorage.test.ts`、`sessionAgentSwitchHandler.test.ts`、device-link `remoteAgent.test.ts`。
配额均衡的同账号提议复用既有 `kind: auto`,桌面与手机不弹常规换电脑确认。实际需要摘要时,宿主通过既有 permission
确认卡(`hostOwnedConfirmation: native_history_fallback`)询问,支持同账号远控回答;取消、超时保留原电脑与原生记录。
旧客户端已支持 auto 和通用 permission 卡;共享来源仍沿用原来的 ask/记住偏好,不自动扩大授权。