Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(deeplink): 统一设备身份并保持显式任务归属
Dash9f2d4a823c70
diff --git a/apps/desktop/src/main/__tests__/deviceId.test.ts b/apps/desktop/src/main/__tests__/deviceId.test.tsindex 9fe21f6ba6..693507f325 100644--- a/apps/desktop/src/main/__tests__/deviceId.test.ts+++ b/apps/desktop/src/main/__tests__/deviceId.test.ts@@ -9,11 +9,29 @@*/import { afterEach, beforeEach, describe, expect, it } from 'vitest';import path from 'node:path';+import { readFileSync } from 'node:fs';import { ensureSystemBinPathForMachineId } from '../deviceId.js';const PATCHES_PATH = process.platform === 'darwin' || process.platform === 'linux';+// Execute the production IPC registration adapter without booting Electron.+// A sandbox's auth identity can differ from the raw hardware id; renderer link+// comparisons must receive the same identity that auth uses to register it.+it('get-device-id exposes the auth device identity, including an isolated override', () => {+ const source = readFileSync(new URL('../bootstrap-electron.ts', import.meta.url), 'utf8');+ const start = source.indexOf(' // Device ID');+ const end = source.indexOf(' // CC 网络调试开关', start);+ if (start < 0 || end <= start) throw new Error('device id IPC registration not found');+ let handler!: () => string;+ new Function('ipcMain', 'authManager', 'machineIdSync', source.slice(start, end))(+ { handle: (_name: string, callback: () => string) => { handler = callback; } },+ { getDeviceId: () => 'isolated-device-override' },+ () => 'raw-hardware-id',+ );+ expect(handler()).toBe('isolated-device-override');+});+describe('ensureSystemBinPathForMachineId', () => {const originalPath = process.env.PATH;diff --git a/apps/desktop/src/main/bootstrap-electron.ts b/apps/desktop/src/main/bootstrap-electron.tsindex 8216799bb9..49fcc60c39 100644--- a/apps/desktop/src/main/bootstrap-electron.ts+++ b/apps/desktop/src/main/bootstrap-electron.ts@@ -95,7 +95,6 @@ import { textFilePreviewResult, TEXT_PREVIEW_LIMIT_MB } from './text-file-previeimport os from 'node:os';import { pipeline } from 'node:stream/promises';import { execFile, execFileSync, spawn } from 'node:child_process';-import { machineIdSync } from 'node-machine-id';import windowStateKeeper from 'electron-window-state';import { BRAND_NAME } from '@cindy/maker-shared/branding';import { assertCindyMakeEnabled } from './cindy-make/featureGate.js';@@ -5650,9 +5649,8 @@ const registerIpcHandlers = () => {},);- // Device ID (hardware-based, survives app reinstall)- const machineId = machineIdSync();- ipcMain.handle('get-device-id', () => machineId);+ // Device ID: use the identity registered by auth, including isolated dev overrides.+ ipcMain.handle('get-device-id', () => authManager.getDeviceId());// CC 网络调试开关 — renderer Settings → Experimental "CC 网络调试日志" 操作此值。// 改写 process.env.XDT_CC_DEBUG_NET, 让 buildClaudeEnv 在下次 spawn cc 时注入diff --git a/apps/desktop/src/renderer/__tests__/remoteProjectsStore.test.ts b/apps/desktop/src/renderer/__tests__/remoteProjectsStore.test.tsindex 0db56888e1..0e5eac2d2c 100644--- a/apps/desktop/src/renderer/__tests__/remoteProjectsStore.test.ts+++ b/apps/desktop/src/renderer/__tests__/remoteProjectsStore.test.ts@@ -142,6 +142,29 @@ describe('remoteProjectsStore', () => {});describe('origin 钉子(pinSessionOrigin)', () => {+ // #7115: a copied task can exist on multiple computers with the same id.+ // A link's explicit origin must survive both existing and later snapshots.+ it('keeps an explicit origin ahead of same-id snapshots from another computer', () => {+ remoteProjectsStore.setDeviceSessions('dev-B', 'B', [mk('same', { title: 'B task' })]);+ remoteProjectsStore.setDeviceSessions('dev-C', 'C', [mk('same', { title: 'C task' })]);+ remoteProjectsStore.pinSessionOrigin('dev-B', 'same');+ expect(getSessionDeviceId('same')).toBe('dev-B');+ expect(remoteProjectsStore.getSessionTitle('same')).toBe('B task');+ remoteProjectsStore.setDeviceSessions('dev-C', 'C', [mk('same', { title: 'C changed' })]);+ expect(getSessionDeviceId('same')).toBe('dev-B');+ expect(remoteProjectsStore.getSessionTitle('same')).toBe('B task');+ remoteProjectsStore.pinSessionOrigin('dev-C', 'same');+ expect(getSessionDeviceId('same')).toBe('dev-C');+ expect(remoteProjectsStore.getSessionTitle('same')).toBe('C changed');+ });++ it('does not borrow another computer\'s title while the pinned snapshot is unavailable', () => {+ remoteProjectsStore.setDeviceSessions('dev-C', 'C', [mk('same', { title: 'C task' })]);+ remoteProjectsStore.pinSessionOrigin('dev-B', 'same');+ expect(getSessionDeviceId('same')).toBe('dev-B');+ expect(remoteProjectsStore.getSessionTitle('same')).toBeNull();+ });+it('远程新建会话后 origin 立刻可判定,即使权威快照还没到', () => {remoteProjectsStore.pinSessionOrigin('dev-B', 'new-1');// 传输层据此走隧道 —— 没有钉子时它返回 undefined,首条消息就发给本机 maker。diff --git a/apps/desktop/src/renderer/components/chat/SessionLinkChip.tsx b/apps/desktop/src/renderer/components/chat/SessionLinkChip.tsxindex 858472ee5f..a82f2c3ae4 100644--- a/apps/desktop/src/renderer/components/chat/SessionLinkChip.tsx+++ b/apps/desktop/src/renderer/components/chat/SessionLinkChip.tsx@@ -116,7 +116,8 @@ export function SessionLinkChip({ href, label }: SessionLinkChipProps) {};}, [sessionId, messageClientId]);- const remoteSession = remoteSessions.find((s) => s.id === sessionId) ?? null;+ const remoteSession = remoteSessions.find((s) =>+ s.id === sessionId && (!targetDeviceId || s.deviceLinkDeviceId === targetDeviceId)) ?? null;const remoteTitle = fetchedTitle ? null : remoteSession?.title?.trim() || null;const openTarget = async (separate: boolean) => {if (!target || !sessionId) return;@@ -137,7 +138,7 @@ export function SessionLinkChip({ href, label }: SessionLinkChipProps) {await window.electronAPI.maker.openSessionInNewWindow(sessionId, deviceId, messageClientId);return null;}- return resolveSessionRoute(sessionId, remoteSession);+ return resolveSessionRoute(sessionId, remoteSession, { remote: !!deviceId });};// device-link 远程会话本地无 row,resolveSessionRoute 内部的 sessionService.get// 会 miss → 远程 Orca 会话被当普通会话路由,后续 redirect 会丢 searchJump 锚点。diff --git a/apps/desktop/src/renderer/components/chat/__tests__/embeddedSessionNavigation.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/embeddedSessionNavigation.test.tsxindex e841490b6a..2cabacf82b 100644--- a/apps/desktop/src/renderer/components/chat/__tests__/embeddedSessionNavigation.test.tsx+++ b/apps/desktop/src/renderer/components/chat/__tests__/embeddedSessionNavigation.test.tsx@@ -11,6 +11,7 @@ const mocks = vi.hoisted(() => ({writeText: vi.fn(async () => undefined),error: vi.fn(),navigate: vi.fn(),+ remoteSessions: [] as Array<{ id: string; title: string; deviceLinkDeviceId: string; orcaRole: 'lead' | 'worker' | null }>,pinSessionOrigin: vi.fn(),resolveSessionRoute: vi.fn(async (sessionId: string) => `/cc-agent/${sessionId}`),getSession: vi.fn(async (sessionId: string) => ({@@ -39,7 +40,7 @@ vi.mock('react-i18next', () => ({}),}));vi.mock('@/features/device-link/remoteProjectsStore', () => ({- useRemoteProjectSessions: () => [],+ useRemoteProjectSessions: () => mocks.remoteSessions,useRemoteSessionTitle: () => null,getSessionDeviceId: () => undefined,remoteProjectsStore: {@@ -104,6 +105,7 @@ function SidebarTargetProbe({ contentSessionId }: { contentSessionId?: string })describe('sidebar-embedded session navigation boundary', () => {beforeEach(() => {vi.clearAllMocks();+ mocks.remoteSessions = [];Object.defineProperty(window, 'electronAPI', {configurable: true, value: { maker: { openSessionInNewWindow: mocks.openSessionInNewWindow } },});@@ -138,6 +140,19 @@ describe('sidebar-embedded session navigation boundary', () => {expect(mocks.navigate).not.toHaveBeenCalled();});+ // #7115: same-id copies on two computers must use the linked computer's+ // route metadata as well as its transport origin; unit, real chip activation.+ it('selects the linked remote computer when another snapshot has the same task id', async () => {+ const wrong = { id: 'same', title: 'Wrong', deviceLinkDeviceId: 'mac-a', orcaRole: 'worker' as const };+ const right = { id: 'same', title: 'Right', deviceLinkDeviceId: 'mac-b', orcaRole: null };+ mocks.remoteSessions = [wrong, right];+ render(<SessionLinkChip href="cindy://session/same?device=mac-b" label="Task" />);+ fireEvent.click(screen.getByRole('button', { name: 'Task' }));+ await waitFor(() => expect(mocks.navigate).toHaveBeenCalled());+ expect(mocks.pinSessionOrigin).toHaveBeenCalledWith('mac-b', 'same');+ expect(mocks.resolveSessionRoute).toHaveBeenCalledWith('same', right, { remote: true });+ });+it.each([{ shiftKey: true }, { metaKey: true }, { ctrlKey: true }])('opens remote task links separately for modifier %j, keeping the message anchor', async (modifier) => {const onNavigate = vi.fn();@@ -271,7 +286,7 @@ describe('sidebar-embedded session navigation boundary', () => {);fireEvent.click(screen.getByRole('button'));- expect(mocks.resolveSessionRoute).toHaveBeenCalledWith('session-target', null);+ expect(mocks.resolveSessionRoute).toHaveBeenCalledWith('session-target', null, { remote: false });view.unmount();await act(async () => {@@ -546,7 +561,7 @@ describe('sidebar-embedded session navigation boundary', () => {render(<SessionLinkChip href="xdt-maker://session/session-d" label="Session D" />);fireEvent.click(screen.getByRole('button'));- await waitFor(() => expect(mocks.resolveSessionRoute).toHaveBeenCalledWith('session-d', null));+ await waitFor(() => expect(mocks.resolveSessionRoute).toHaveBeenCalledWith('session-d', null, { remote: false }));expect(mocks.navigate).toHaveBeenCalledWith('/cc-agent/session-d', undefined);});@@ -569,7 +584,7 @@ describe('sidebar-embedded session navigation boundary', () => {fireEvent.click(screen.getByRole('button'));await waitFor(() =>- expect(mocks.resolveSessionRoute).toHaveBeenCalledWith('session-message', null),+ expect(mocks.resolveSessionRoute).toHaveBeenCalledWith('session-message', null, { remote: false }),);expect(mocks.navigate).toHaveBeenCalledWith('/cc-agent/session-message', {state: {diff --git a/apps/desktop/src/renderer/components/layout/MainLayout.tsx b/apps/desktop/src/renderer/components/layout/MainLayout.tsxindex e94ac8064e..28623a0f00 100644--- a/apps/desktop/src/renderer/components/layout/MainLayout.tsx+++ b/apps/desktop/src/renderer/components/layout/MainLayout.tsx@@ -560,7 +560,8 @@ export function MainLayout() {// redirect 到 orca 路由时会丢 searchJump 锚点。传入远程镜像的 session 对象,// 让 Orca 路由一步到位(Codex review P2,与 SessionLinkChip 同款处理)。const remoteSession =- remoteProjectsStore.getVisibleMergedRemoteSessions().find((s) => s.id === sessionId) ?? null;+ remoteProjectsStore.getVisibleMergedRemoteSessions().find((s) =>+ s.id === sessionId && (!deviceId || s.deviceLinkDeviceId === deviceId)) ?? null;void resolveSessionRoute(sessionId, remoteSession, { remote: !!deviceId }).then((target) => {if (!isLatest()) return;const visibleSession = resolveAgentIslandVisibleSessionFromRouteTarget(target);diff --git a/apps/desktop/src/renderer/features/device-link/remoteProjectsStore.ts b/apps/desktop/src/renderer/features/device-link/remoteProjectsStore.tsindex 1f7f850084..ec00d48788 100644--- a/apps/desktop/src/renderer/features/device-link/remoteProjectsStore.ts+++ b/apps/desktop/src/renderer/features/device-link/remoteProjectsStore.ts@@ -174,8 +174,8 @@ const sessionTitleIndex = new Map<string, string>();* 那个窗口里 sessionDeviceIndex 没有这条,`getSessionDeviceId` 返回 undefined —— 传输层据此把* 一个**远程**会话的操作发给本机 maker:首条消息、setGoal、流订阅全落错边(#807 review P1)。*- * 所以创建成功后立刻把这个已确定的事实钉进来,recompute 时先铺钉子、再让分片派生值覆盖- * (分片更完整,且与钉子不可能冲突)。钉子只影响 origin 判定,不伪造会话行 —— 会话进列表仍等+ * 创建成功或打开带设备归属的链接后立刻把目标钉进来。recompute 时钉子优先于其它设备+ * 的同 id 分片(复制的任务可能保留 id)。钉子只选择 origin 与标题,不伪造会话行 —— 会话进列表仍等* 权威快照。** 不主动清理(含 clear / removeDevice):与 stickySessionOrigin 同一论证 —— 归属是单向的@@ -451,7 +451,7 @@ function recompute(): void {sessionDeviceIndex.clear();sessionTitleIndex.clear();// 先铺 origin 钉子:分片还没到的新建远程会话也必须能被判定为远程(见 pinnedOrigins)。- // 分片派生值随后覆盖同 id 的条目。+ // 其它设备的同 id 分片不能覆盖显式指定的 origin。for (const [sessionId, deviceId] of pinnedOrigins) sessionDeviceIndex.set(sessionId, deviceId);if (shards.size === 0) {mergedSnapshot = EMPTY;@@ -464,8 +464,11 @@ function recompute(): void {shard.deviceId,);flat.push(projected);- sessionDeviceIndex.set(s.id, shard.deviceId);- if (projected.title) sessionTitleIndex.set(s.id, projected.title);+ const pinnedDeviceId = pinnedOrigins.get(s.id);+ if (!pinnedDeviceId || pinnedDeviceId === shard.deviceId) {+ sessionDeviceIndex.set(s.id, shard.deviceId);+ if (projected.title) sessionTitleIndex.set(s.id, projected.title);+ }}}mergedSnapshot = flat;diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex 4d76e57b89..d68a3c9e6d 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -7,6 +7,9 @@Renderer 均保留它。导航先与本机设备 ID 比较;远端链接先登记现有会话 origin,再通过原传输层读取,不把相同 ID 的本机伙伴任务当作目标。设备判断沿用入口导航器的最新点击判据,迟到结果不覆盖后续点击。没有设备参数的旧链接保持原导航流程。+设备比较与链接生成均使用 auth 注册的本机标识,包含隔离开发实例的覆盖值。+外部入口与正文链接按设备和任务 ID 一起挑选远端镜像;显式 origin 优先于其它设备+的同 ID 分片,快照刷新不会将后续读取改到另一台电脑。不增加 IPC channel、远程授权、重试或连接恢复;离线目标仍由现有传输层报告。回滚后新增查询字段可忽略,但旧 Desktop 从外部打开远程链接仍有丢失设备参数的限制。回归入口:`deepLink.test.ts`、`deepLinkIslandEntryBridge.test.ts`、