Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 审查面板合流与协同审查入口修复,生成文件卡去重 (#2048)
DavidShenXD0aad640b3ff4
diff --git a/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.ts b/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.tsindex aaaf200c3d..f903f7d7e7 100644--- a/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.ts+++ b/apps/desktop/src/main/right-sidebar-window/__tests__/controller.test.ts@@ -433,6 +433,62 @@ describe('setContext / routeCommand', () => {});});+ it('跨会话 open-turn-review 按 hostSessionId(lead 桶)裁决,worker sessionId 不拒发', async () => {+ // 协同面板审查 worker 轮次:command.sessionId 是取数目标 worker,可见桶是+ // lead(hostSessionId)。detached context 停在 lead 上,按 sessionId 裁决会+ // 误判 stale-context,worker 审查入口在 detached 形态下点了没反应。+ const h = makeHarness({ detached: true });+ h.controller.setContext(ctx);+ h.controller.open();+ h.controller.markReady();++ const command = {+ type: 'open-turn-review' as const,+ sessionId: 'worker-1',+ changeSetIds: ['c1'],+ selectedDiffId: null,+ selectedPath: null,+ requestNonce: 1,+ hostSessionId: 's1',+ };+ await expect(+ h.controller.routeCommand({ command, allowOpen: true }),+ ).resolves.toBe('routed');+ expect(h.sends.at(-1)).toEqual({ channel: 'cmd-channel', payload: command });++ // hostSessionId 与当前 context 不符时仍是 stale-context(不能放宽成任意会话)。+ await expect(+ h.controller.routeCommand({+ command: { ...command, hostSessionId: 'other-lead' },+ allowOpen: true,+ }),+ ).resolves.toBe('stale-context');+ });++ it('跨会话 open-turn-review 延迟命令按 lead 桶入队,lead ready 后派发', async () => {+ const h = makeHarness({ detached: true });+ h.controller.setContext(ctx);++ const command = {+ type: 'open-turn-review' as const,+ sessionId: 'worker-1',+ changeSetIds: ['c1'],+ selectedDiffId: null,+ selectedPath: null,+ requestNonce: 2,+ hostSessionId: 's1',+ };+ await expect(+ h.controller.routeCommand({ command, allowOpen: false }),+ ).resolves.toBe('queued');+ expect(h.windows).toHaveLength(0);++ // context 一直是 lead(s1),不会切到 worker;flush 必须按 lead 桶命中。+ h.controller.open();+ h.controller.markReady();+ expect(h.sends.at(-1)).toEqual({ channel: 'cmd-channel', payload: command });+ });+it('context mismatch / unavailable 返回 stale-context,不开窗也不派发', async () => {const h = makeHarness({ detached: true });h.controller.setContext({ ...ctx, sessionId: 's2' });diff --git a/apps/desktop/src/main/right-sidebar-window/__tests__/ipc.test.ts b/apps/desktop/src/main/right-sidebar-window/__tests__/ipc.test.tsindex 1858e462de..60501519d3 100644--- a/apps/desktop/src/main/right-sidebar-window/__tests__/ipc.test.ts+++ b/apps/desktop/src/main/right-sidebar-window/__tests__/ipc.test.ts@@ -216,6 +216,80 @@ describe('right-sidebar-window IPC', () => {).rejects.toThrow(/searchJump/);});+ it('validates and forwards the turn-review host bucket session', async () => {+ // 协同面板里 worker 流的审查入口带宿主(lead)桶。sanitizer 重建命令对象,+ // 漏透传 hostSessionId 会让 detached 窗口路径退回 worker 的不可见桶。+ const controller = makeController();+ const { handler, mainWebContents } = registerController(controller);++ await handler(+ { sender: mainWebContents },+ {+ command: {+ type: 'open-turn-review',+ sessionId: 'worker-1',+ changeSetIds: ['change-1'],+ requestNonce: 1,+ hostSessionId: 'lead-1',+ },+ allowOpen: true,+ },+ );+ await handler(+ { sender: mainWebContents },+ {+ command: {+ type: 'open-turn-review',+ sessionId: 'worker-1',+ changeSetIds: ['change-1'],+ requestNonce: 2,+ },+ allowOpen: true,+ },+ );++ expect(controller.routeCommand).toHaveBeenNthCalledWith(1, {+ command: {+ type: 'open-turn-review',+ sessionId: 'worker-1',+ changeSetIds: ['change-1'],+ selectedDiffId: null,+ selectedPath: null,+ requestNonce: 1,+ hostSessionId: 'lead-1',+ },+ allowOpen: true,+ });+ expect(controller.routeCommand).toHaveBeenNthCalledWith(2, {+ command: {+ type: 'open-turn-review',+ sessionId: 'worker-1',+ changeSetIds: ['change-1'],+ selectedDiffId: null,+ selectedPath: null,+ requestNonce: 2,+ hostSessionId: null,+ },+ allowOpen: true,+ });++ await expect(+ handler(+ { sender: mainWebContents },+ {+ command: {+ type: 'open-turn-review',+ sessionId: 'worker-1',+ changeSetIds: ['change-1'],+ requestNonce: 3,+ hostSessionId: 42,+ },+ allowOpen: true,+ },+ ),+ ).rejects.toThrow(/hostSessionId/);+ });+it('validates and forwards external-file browser commands', async () => {const controller = makeController();const { handler, mainWebContents } = registerController(controller);diff --git a/apps/desktop/src/main/right-sidebar-window/controller.ts b/apps/desktop/src/main/right-sidebar-window/controller.tsindex f2415a3eb8..92b370bb40 100644--- a/apps/desktop/src/main/right-sidebar-window/controller.ts+++ b/apps/desktop/src/main/right-sidebar-window/controller.ts@@ -61,6 +61,15 @@ export interface RsbWindowControllerDeps {const READY_TIMEOUT_MS = 8000;const MAX_DEFERRED_SESSIONS = 8;+/**+ * command 的宿主桶 session —— 裁决可见性与 deferred 排队都以它为准。+ * open-turn-review 可跨会话(协同面板审查 worker 轮次:sessionId 是取数目标+ * worker,tab 落在 lead 的桶),其余命令宿主即自身 sessionId。+ */+function commandHostSessionId(cmd: RsbWindowCommand): string {+ return cmd.type === 'open-turn-review' ? (cmd.hostSessionId ?? cmd.sessionId) : cmd.sessionId;+}+export class RsbWindowController {private winRef: BrowserWindow | null = null;/** BrowserWindow.close() 到 closed 事件之间仍未 destroyed,不能继续当活 host。 */@@ -209,7 +218,7 @@ export class RsbWindowController {return Boolean(this.lastContext?.available &&this.lastContext.sessionId &&- this.lastContext.sessionId === cmd.sessionId,+ this.lastContext.sessionId === commandHostSessionId(cmd),);}@@ -271,7 +280,10 @@ export class RsbWindowController {}private enqueueDeferredCommand(command: RsbWindowCommand): void {- const previous = this.deferredCommands.get(command.sessionId);+ // 按宿主桶排队:跨会话 open-turn-review 属于 lead 的桶,须由 lead 上下文+ // flush;按 worker sessionId 入队会在 context 保持 lead 时永远刷不出来。+ const hostSessionId = commandHostSessionId(command);+ const previous = this.deferredCommands.get(hostSessionId);if (command.type === 'ensure-orca-workers-tab' &&previous?.type === 'ensure-orca-workers-tab' &&@@ -281,13 +293,13 @@ export class RsbWindowController {return;}if (- !this.deferredCommands.has(command.sessionId) &&+ !this.deferredCommands.has(hostSessionId) &&this.deferredCommands.size >= MAX_DEFERRED_SESSIONS) {const oldest = this.deferredCommands.keys().next().value as string | undefined;if (oldest) this.deferredCommands.delete(oldest);}- this.deferredCommands.set(command.sessionId, command);+ this.deferredCommands.set(hostSessionId, command);}private flushDeferredCommandsToDetachedHost(): void {diff --git a/apps/desktop/src/main/right-sidebar-window/ipc.ts b/apps/desktop/src/main/right-sidebar-window/ipc.tsindex cb423dfc4d..ba9db24f99 100644--- a/apps/desktop/src/main/right-sidebar-window/ipc.ts+++ b/apps/desktop/src/main/right-sidebar-window/ipc.ts@@ -127,6 +127,13 @@ function parseCommand(raw: unknown): RsbWindowCommand {if (typeof r.requestNonce !== 'number' || !Number.isSafeInteger(r.requestNonce)) {throwIpcError('INVALID_PARAMS', 'command.requestNonce must be an integer');}+ if (+ r.hostSessionId !== undefined+ && r.hostSessionId !== null+ && (typeof r.hostSessionId !== 'string' || r.hostSessionId.length === 0 || r.hostSessionId.length > 256)+ ) {+ throwIpcError('INVALID_PARAMS', 'command.hostSessionId must be string | null');+ }return {type: 'open-turn-review',sessionId: r.sessionId,@@ -134,6 +141,8 @@ function parseCommand(raw: unknown): RsbWindowCommand {selectedDiffId: typeof r.selectedDiffId === 'string' ? r.selectedDiffId : null,selectedPath: typeof r.selectedPath === 'string' ? r.selectedPath : null,requestNonce: r.requestNonce,+ // 协同面板里 worker 流的入口带宿主(lead)桶;缺省 null = tab 落 sessionId 自身桶。+ hostSessionId: typeof r.hostSessionId === 'string' ? r.hostSessionId : null,};}if (r.type === 'open-file-browser') {diff --git a/apps/desktop/src/main/turn-change-set/__tests__/store.git-integration.test.ts b/apps/desktop/src/main/turn-change-set/__tests__/store.git-integration.test.tsindex 4932a1a95f..bbd9d004dc 100644--- a/apps/desktop/src/main/turn-change-set/__tests__/store.git-integration.test.ts+++ b/apps/desktop/src/main/turn-change-set/__tests__/store.git-integration.test.ts@@ -1203,6 +1203,103 @@ describe('turn change-set sidecar store', () => {});});+ it('skips known writes literally outside the workspace without marking the capture incomplete', async () => {+ const inWorkspace = path.join(workdir, 'kept.txt');+ const outside = path.join(root, 'agent-temp.md');+ await beginTurnChangeSet({+ sessionId: 'session-1',+ anchorClientId: 'user-1',+ provider: 'claude-code',+ cwd: workdir,+ });+ // Deliberate scope exclusion: temp files outside the workspace tree are not+ // tracked and must not degrade the in-workspace capture to partial.+ await captureKnownFileBefore({+ sessionId: 'session-1',+ provider: 'claude-code',+ cwd: workdir,+ targetPath: outside,+ });+ await fs.writeFile(outside, 'temp\n', 'utf8');+ await captureKnownFileBefore({+ sessionId: 'session-1',+ provider: 'claude-code',+ cwd: workdir,+ targetPath: 'kept.txt',+ });+ await fs.writeFile(inWorkspace, 'kept\n', 'utf8');+ await finalizeTurnChangeSet('session-1', null, 'complete');++ const [summary] = await listTurnChangeSets('session-1');+ expect(summary).toMatchObject({+ state: 'complete',+ incompleteReasons: [],+ fileCount: 1,+ });+ expect(summary?.files[0]?.path).toBe('kept.txt');+ });++ it('drops a turn whose only known write was outside the workspace', async () => {+ const outside = path.join(root, 'agent-temp.md');+ await beginTurnChangeSet({+ sessionId: 'session-1',+ anchorClientId: 'user-1',+ provider: 'claude-code',+ cwd: workdir,+ });+ await captureKnownFileBefore({+ sessionId: 'session-1',+ provider: 'claude-code',+ cwd: workdir,+ targetPath: outside,+ });+ await fs.writeFile(outside, 'temp\n', 'utf8');+ await finalizeTurnChangeSet('session-1', null, 'complete');++ expect(await listTurnChangeSets('session-1')).toHaveLength(0);+ });++ it('still marks the capture incomplete when an in-workspace path escapes via symlink', async () => {+ const escapeTarget = path.join(root, 'escape-target');+ await fs.mkdir(escapeTarget);+ await fs.writeFile(path.join(escapeTarget, 'secret.txt'), 'secret\n', 'utf8');+ await fs.symlink(+ escapeTarget,+ path.join(workdir, 'link'),+ process.platform === 'win32' ? 'junction' : 'dir',+ );+ await beginTurnChangeSet({+ sessionId: 'session-1',+ anchorClientId: 'user-1',+ provider: 'claude-code',+ cwd: workdir,+ });+ // Literally inside the workspace, resolves outside: the workspace tree looks+ // touched, so the incomplete reason must stay.+ await captureKnownFileBefore({+ sessionId: 'session-1',+ provider: 'claude-code',+ cwd: workdir,+ targetPath: 'link/secret.txt',+ });+ const inWorkspace = path.join(workdir, 'kept.txt');+ await captureKnownFileBefore({+ sessionId: 'session-1',+ provider: 'claude-code',+ cwd: workdir,+ targetPath: 'kept.txt',+ });+ await fs.writeFile(inWorkspace, 'kept\n', 'utf8');+ await finalizeTurnChangeSet('session-1', null, 'complete');++ const [summary] = await listTurnChangeSets('session-1');+ expect(summary).toMatchObject({+ state: 'partial',+ incompleteReasons: expect.arrayContaining(['outside-workspace']),+ fileCount: 1,+ });+ });+it.each([['absolute path', 'diff --git /outside.txt /outside.txt'],['parent traversal', 'diff --git a/../escape.txt b/../escape.txt'],diff --git a/apps/desktop/src/main/turn-change-set/store.ts b/apps/desktop/src/main/turn-change-set/store.tsindex c6211f665c..f6e287396c 100644--- a/apps/desktop/src/main/turn-change-set/store.ts+++ b/apps/desktop/src/main/turn-change-set/store.ts@@ -918,7 +918,13 @@ export async function captureKnownFileBefore(input: KnownFileWriteCapture): Promconst pending = ensurePending(input.sessionId, input.provider, input.cwd);const target = safeRelativeTarget(input.cwd, input.targetPath);if (!target) {- addIncompleteReason(pending, 'outside-workspace');+ // A known write target literally outside the workspace (agent temp files,+ // scratchpad, OS temp dirs) is a deliberate scope exclusion, not a capture+ // loss: turn change tracking only covers the workspace tree. Recording+ // 'outside-workspace' here spawned a dead-end "+0 -0" partial card for+ // turns that never touched the workspace at all. The realpath escape check+ // below still records the reason — there the workspace tree appears+ // touched, which is worth flagging.return;}if (detectSensitivePath(target.relativePath, { allowEnvTemplates: true })) {diff --git a/apps/desktop/src/renderer/__tests__/buildRenderItemsKeyStability.test.ts b/apps/desktop/src/renderer/__tests__/buildRenderItemsKeyStability.test.tsindex 4546964688..a04ad60351 100644--- a/apps/desktop/src/renderer/__tests__/buildRenderItemsKeyStability.test.ts+++ b/apps/desktop/src/renderer/__tests__/buildRenderItemsKeyStability.test.ts@@ -360,17 +360,26 @@ describe('buildRenderItems — key stability', () => {createdAt: 3,completedAt: 4,};+ // The store only records 'outside-workspace' for suspicious captures (symlink+ // escapes, fail-closed provider diff blocks) — that evidence must stay visible.+ const escaped: TurnChangeSetSummary = {+ ...base,+ id: 'cs-escape',+ incompleteReasons: ['outside-workspace'],+ createdAt: 5,+ completedAt: 6,+ };const { items } = buildRenderItems([mkUser('u1'), mkAssistant('a1'), mkUser('u2')],undefined,undefined,- { turnChangeSets: [noEvidence, truncated] },+ { turnChangeSets: [noEvidence, truncated, escaped] },);const cards = items.filter((item): item is Extract<RenderItem, { type: 'turn_changes' }> => item.type === 'turn_changes',);- expect(cards.map((card) => card.changeSet.id)).toEqual(['cs-too-large']);+ expect(cards.map((card) => card.changeSet.id)).toEqual(['cs-too-large', 'cs-escape']);});it('keeps opaque command artifacts as fallback chips without duplicating exact files', () => {diff --git a/apps/desktop/src/renderer/__tests__/generatedFiles.test.ts b/apps/desktop/src/renderer/__tests__/generatedFiles.test.tsindex d5d598e830..4f7d50c56f 100644--- a/apps/desktop/src/renderer/__tests__/generatedFiles.test.ts+++ b/apps/desktop/src/renderer/__tests__/generatedFiles.test.ts@@ -122,6 +122,40 @@ describe('collectGeneratedFiles', () => {expect(files[0].source).toBe('tool');});+ it('collapses doubled backslashes so escaped wrapper commands do not duplicate chips', () => {+ // 实测场景(pr-watch session):powershell 包一层 node -e,落库命令文本里的+ // 路径带转义残留(`C:\\Users\\...`);同轮另一条命令用正斜杠形态。fs 层它们+ // 是同一文件(Windows 归并重复分隔符),不折叠会出两个同名 chip。+ const files = collectGeneratedFiles(+ [+ toolUse('Bash', {+ command: "powershell -Command '$p = 'C:\\\\Users\\\\U\\\\pr-watch\\\\registry.json'; Get-Content $p'",+ }),+ toolUse('Bash', {+ command: "node -e \"const p='C:/Users/U/pr-watch/registry.json'; console.log(p);\"",+ }),+ ],+ 'C:\\Users\\U\\pr-watch',+ );+ const registry = files.filter((f) => f.name === 'registry.json');+ expect(registry).toHaveLength(1);+ // 画布路径本身也折叠成单反斜杠本机形态,不带转义残留。+ expect(registry[0].path).toBe('C:\\Users\\U\\pr-watch\\registry.json');+ });++ it('keeps the UNC leading double backslash while collapsing inner separator runs', () => {+ const files = collectGeneratedFiles(+ [+ toolUse('Bash', { command: "copy out '\\\\server\\share\\\\dir\\report.csv'" }),+ toolUse('Bash', { command: "open '\\\\server\\share\\dir\\report.csv'" }),+ ],+ 'C:\\work',+ );+ const reports = files.filter((f) => f.name === 'report.csv');+ expect(reports).toHaveLength(1);+ expect(reports[0].path.startsWith('\\\\server\\')).toBe(true);+ });+it('excludes command mentions of files edited by file tools this turn', () => {// 编码会话形态:Edit 改了源码文件,随后命令引用它(跑测试)。它是编辑不是// 新建,不能因 mtime 落在本轮窗口就被当成产物。diff --git a/apps/desktop/src/renderer/components/chat/TurnChangesCard.tsx b/apps/desktop/src/renderer/components/chat/TurnChangesCard.tsxindex 2beb63d1e1..1035d3f070 100644--- a/apps/desktop/src/renderer/components/chat/TurnChangesCard.tsx+++ b/apps/desktop/src/renderer/components/chat/TurnChangesCard.tsx@@ -12,6 +12,7 @@ import {import { useTranslation } from 'react-i18next';import { openTurnReview } from '@/features/right-sidebar/lib/openTurnReview';+import { useSidebarHostSessionId } from '@/features/right-sidebar/lib/sidebarHostSession';import { shouldOpenTextLightboxForOrigin } from '@/lib/filePreview';import { resolveToolFilePath } from '@/lib/localPathResolver';import { toast } from '@/lib/toast';@@ -123,9 +124,13 @@ export function TurnChangesCard({setApplying(false);}, [changeSet.id]);+ // 内嵌在 RSB(协同 worker 面板)里时把 review tab 开到宿主(lead)的可见桶;+ // 主实例 hostSessionId 为 null,openTurnReview 落到本会话桶,行为不变。+ const hostSessionId = useSidebarHostSessionId();const openReview = (selectedDiffId?: string): void => {void openTurnReview(sessionId, [changeSet.id], {selectedDiffId: selectedDiffId ?? null,+ hostSessionId,});};@@ -182,17 +187,23 @@ export function TurnChangesCard({? t('chat.turnChanges.title', { count: changeSet.fileCount }): t('chat.turnChanges.partialTitle')}</div>- <div className="mt-0.5 font-mono text-[12px] tabular-nums">- <span className="text-[var(--diff-add-fg)]">+{changeSet.additions}</span>{' '}- <span className="text-[var(--diff-del-fg)]">-{changeSet.deletions}</span>- </div>+ {files.length > 0 && (+ // 零文件卡的语义是「发生了变更但没录下内容」,+0 −0 会被误读成+ // 「没有变化」,所以增删统计只在录到文件时显示。+ <div className="mt-0.5 font-mono text-[12px] tabular-nums">+ <span className="text-[var(--diff-add-fg)]">+{changeSet.additions}</span>{' '}+ <span className="text-[var(--diff-del-fg)]">-{changeSet.deletions}</span>+ </div>+ )}{changeSet.state === 'partial' && (<div className="mt-1 flex items-center gap-1 text-[11px] text-[var(--warning-fg)]"><AlertTriangle size={12} /><span>{t(- appliesCapturedSubset- ? 'chat.turnChanges.partialReversible'- : 'chat.turnChanges.partial',+ files.length === 0+ ? 'chat.turnChanges.partialNone'+ : appliesCapturedSubset+ ? 'chat.turnChanges.partialReversible'+ : 'chat.turnChanges.partial',)}</span></div>)}@@ -233,13 +244,17 @@ export function TurnChangesCard({)}</button>)}- <button- type="button"- onClick={() => openReview()}- className="h-8 rounded-lg border border-[var(--border-default)] px-3 text-[13px] font-medium text-[var(--text-primary)] transition-colors hover:bg-[var(--surface-hover)]"- >- {t('chat.turnChanges.review')}- </button>+ {files.length > 0 && (+ // 零文件卡没有可展示的 diff,审查面板必然为空;这类卡只承担+ // 「有变更但未记录」的警示职责,不提供死路入口。+ <button+ type="button"+ onClick={() => openReview()}+ className="h-8 rounded-lg border border-[var(--border-default)] px-3 text-[13px] font-medium text-[var(--text-primary)] transition-colors hover:bg-[var(--surface-hover)]"+ >+ {t('chat.turnChanges.review')}+ </button>+ )}</div></div>diff --git a/apps/desktop/src/renderer/components/chat/__tests__/TurnChangesCard.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/TurnChangesCard.test.tsxindex 827cd1a1b1..52985c0d88 100644--- a/apps/desktop/src/renderer/components/chat/__tests__/TurnChangesCard.test.tsx+++ b/apps/desktop/src/renderer/components/chat/__tests__/TurnChangesCard.test.tsx@@ -43,6 +43,7 @@ vi.mock('../useFileChipContextMenu', () => ({useFileChipContextMenu: mocks.useFileChipContextMenu,}));+import { SidebarHostSessionProvider } from '@/features/right-sidebar/lib/sidebarHostSession';import { TurnChangesCard } from '../TurnChangesCard';import type { TurnChangeSetSummary } from '../../../../shared/turnChangeSet';@@ -155,7 +156,25 @@ describe('TurnChangesCard file actions', () => {expect(mocks.openTurnReview).toHaveBeenCalledWith('session-1',['change-1'],- { selectedDiffId: 'file-1' },+ { selectedDiffId: 'file-1', hostSessionId: null },+ );+ });++ it('routes review to the sidebar host bucket when embedded in the collab panel', () => {+ // 协同面板里 worker 流内嵌于 lead 的 RSB tab:review tab 必须开到 lead 的+ // 可见桶(hostSessionId),否则落进 worker 自己的桶,点了没有任何反应。+ render(+ <SidebarHostSessionProvider sessionId="lead-1">+ <TurnChangesCard sessionId="session-1" changeSet={CHANGE_SET} />+ </SidebarHostSessionProvider>,+ );++ fireEvent.click(screen.getByRole('button', { name: /src\/test\.ts/ }));++ expect(mocks.openTurnReview).toHaveBeenCalledWith(+ 'session-1',+ ['change-1'],+ { selectedDiffId: 'file-1', hostSessionId: 'lead-1' },);});@@ -214,6 +233,32 @@ describe('TurnChangesCard file actions', () => {));});+ it('renders a zero-file evidence card as a pure warning without +0 -0 or dead-end actions', () => {+ // 零文件但带变更证据(如 sensitive-file / diff-too-large)的卡:内容没录下,+ // +0 -0 会被误读成「没有变化」,「审查」必然打开空面板。只保留警示文案。+ render(+ <TurnChangesCard+ sessionId="session-1"+ changeSet={{+ ...CHANGE_SET,+ state: 'partial',+ isReversible: false,+ incompleteReasons: ['sensitive-file'],+ files: [],+ fileCount: 0,+ additions: 0,+ deletions: 0,+ }}+ />,+ );++ expect(screen.getByText('chat.turnChanges.partialTitle')).toBeTruthy();+ expect(screen.getByText('chat.turnChanges.partialNone')).toBeTruthy();+ expect(screen.queryByText(/\+0/)).toBeNull();+ expect(screen.queryByRole('button', { name: 'chat.turnChanges.review' })).toBeNull();+ expect(screen.queryByRole('button', { name: 'chat.turnChanges.undoAria' })).toBeNull();+ });+it('does not offer undo for a non-reversible patch', () => {render(<TurnChangesCarddiff --git a/apps/desktop/src/renderer/features/right-sidebar/lib/executeSidebarCommand.ts b/apps/desktop/src/renderer/features/right-sidebar/lib/executeSidebarCommand.tsindex 43a09f5a72..7a37d8c27d 100644--- a/apps/desktop/src/renderer/features/right-sidebar/lib/executeSidebarCommand.ts+++ b/apps/desktop/src/renderer/features/right-sidebar/lib/executeSidebarCommand.ts@@ -56,6 +56,7 @@ export async function executeSidebarCommand(command: RsbWindowCommand): Promise<selectedDiffId: command.selectedDiffId ?? null,selectedPath: command.selectedPath ?? null,requestNonce: command.requestNonce,+ hostSessionId: command.hostSessionId ?? null,});return;}diff --git a/apps/desktop/src/renderer/features/right-sidebar/lib/openTurnReview.ts b/apps/desktop/src/renderer/features/right-sidebar/lib/openTurnReview.tsindex 8dcacc1f3a..64669990b8 100644--- a/apps/desktop/src/renderer/features/right-sidebar/lib/openTurnReview.ts+++ b/apps/desktop/src/renderer/features/right-sidebar/lib/openTurnReview.ts@@ -11,9 +11,20 @@ let nextRequestNonce = 0;export async function openTurnReview(sessionId: string,changeSetIds: string[],- opts: { selectedDiffId?: string | null; selectedPath?: string | null; requestNonce?: number } = {},+ opts: {+ selectedDiffId?: string | null;+ selectedPath?: string | null;+ requestNonce?: number;+ /**+ * 承载 review tab 的 RSB 桶(缺省 = sessionId 自身)。协同面板里 worker 流+ * 的入口传 lead sessionId —— worker 自己的桶在协同视图下不可见,tab 开进去+ * 用户看不到任何反应。+ */+ hostSessionId?: string | null;+ } = {},): Promise<void> {const requestNonce = opts.requestNonce ?? ++nextRequestNonce;+ const hostSessionId = opts.hostSessionId ?? sessionId;const command = {type: 'open-turn-review' as const,sessionId,@@ -21,23 +32,26 @@ export async function openTurnReview(selectedDiffId: opts.selectedDiffId ?? null,selectedPath: opts.selectedPath ?? null,requestNonce,+ hostSessionId,};const routeResult = await routeSidebarCommand(command);if (routeResult !== 'attached') {- if (routeResult === 'routed') requestRightSidebarVisibility('open', { sessionId });+ if (routeResult === 'routed') requestRightSidebarVisibility('open', { sessionId: hostSessionId });return;}- await ensureHydrated(sessionId);- const tab = await addOrFocusSingletonTab(sessionId, 'review', null);- await patchTabState(sessionId, tab.id, (current) => ({+ await ensureHydrated(hostSessionId);+ const tab = await addOrFocusSingletonTab(hostSessionId, 'review', null);+ await patchTabState(hostSessionId, tab.id, (current) => ({...(current && typeof current === 'object' ? current as Record<string, unknown> : {}),turnTarget: {changeSetIds,selectedDiffId: opts.selectedDiffId ?? null,selectedPath: opts.selectedPath ?? null,requestNonce,+ // 目标会话与宿主桶不同(跨会话审查 worker 的轮次)时,review 插件按它取数。+ targetSessionId: sessionId,},}));- requestRightSidebarVisibility('open', { sessionId });+ requestRightSidebarVisibility('open', { sessionId: hostSessionId });}diff --git a/apps/desktop/src/renderer/features/right-sidebar/lib/sidebarHostSession.tsx b/apps/desktop/src/renderer/features/right-sidebar/lib/sidebarHostSession.tsxnew file mode 100644index 0000000000..adfaa6a08a--- /dev/null+++ b/apps/desktop/src/renderer/features/right-sidebar/lib/sidebarHostSession.tsx@@ -0,0 +1,35 @@+/**+ * sidebarHostSession — 标记「当前聊天流内嵌在哪个会话的右栏(RSB)里」。+ * ---------------------------------------------------------------------------+ * RSB 的 tab 桶按 session 划分,只有 Shell 当前注册的那个 session 的桶可见。+ * 协同(orca-workers)tab 挂在 lead 会话的桶里,里面内嵌 worker 会话的消息流;+ * worker 流里的入口(如变更卡的「审查」)若把 tab 开进 worker 自己的桶,用户+ * 永远看不到(MainLayout 对 session 不匹配的可见性请求有意只持久化不动 UI)。+ *+ * 该 context 由内嵌宿主(orca-workers tab body)提供 lead sessionId;消费方+ * (TurnChangesCard 等)据此把 tab 开到可见的宿主桶。默认 null = 消息流就是+ * 路由主实例,无需改桶。+ */++import { createContext, useContext, type ReactNode } from 'react';++const SidebarHostSessionContext = createContext<string | null>(null);++export function SidebarHostSessionProvider({+ sessionId,+ children,+}: {+ sessionId: string;+ children: ReactNode;+}) {+ return (+ <SidebarHostSessionContext.Provider value={sessionId}>+ {children}+ </SidebarHostSessionContext.Provider>+ );+}++/** 内嵌在 RSB tab 里时返回宿主(lead)sessionId;主实例返回 null。 */+export function useSidebarHostSessionId(): string | null {+ return useContext(SidebarHostSessionContext);+}diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/orca-workers/index.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/orca-workers/index.tsxindex a393514a4a..f578352c8c 100644--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/orca-workers/index.tsx+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/orca-workers/index.tsx@@ -29,6 +29,7 @@ import { isOrcaLeadSession } from '@/lib/orcaSessionIdentity';import { isSidebarWindow } from '@/lib/sidebarWindow';import * as sessionService from '@/lib/sessionService';import { createLogger } from '@/lib/logger';+import { SidebarHostSessionProvider } from '../../lib/sidebarHostSession';import { registerTabKind } from '../../registry';import { hasTabCloseInterceptor } from '../../store';import type { TabKindPlugin } from '../../types';@@ -157,6 +158,9 @@ function OrcaWorkersTabBody({);return (+ // 内嵌 worker 流里的审查等入口据此把 RSB tab 开到 lead 的可见桶,+ // 而不是 worker 自己的(协同视图下不可见的)桶。+ <SidebarHostSessionProvider sessionId={ctx.sessionId}><OrcaWorkerPanelleadSessionId={ctx.sessionId}deviceId={leadSession?.deviceLinkDeviceId}@@ -172,6 +176,7 @@ function OrcaWorkersTabBody({onSelectionIntentCleared={handleSelectionIntentCleared}onSearchJumpConsumed={handleSearchJumpConsumed}/>+ </SidebarHostSessionProvider>);}diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/review/ReviewTabBody.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/review/ReviewTabBody.tsxindex 12f649cccc..41f06ce858 100644--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/review/ReviewTabBody.tsx+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/review/ReviewTabBody.tsx@@ -106,6 +106,23 @@ interface ReviewTabBodyProps {ctx: TabKindHostContext;}+/**+ * source / selectedCommitOid 由外层 ReviewTabBody 持有并下发:轮次视图与+ * Git 视图共用同一个来源状态机,从轮次视图的来源下拉切走时目标 source+ * 要在 Git 视图挂载前就位(对齐 Codex 的单 source + turnSelection 模型)。+ */+interface GitReviewBodyProps extends ReviewTabBodyProps {+ source: ReviewSource;+ setSource: (source: ReviewSource) => void;+ selectedCommitOid: string | null;+ setSelectedCommitOid: (oid: string | null) => void;+}++interface TurnReviewBodyProps extends ReviewTabBodyProps {+ setSource: (source: ReviewSource) => void;+ setSelectedCommitOid: (oid: string | null) => void;+}+type ReviewToggleAction = Extract<ReviewStageAction, 'stage' | 'unstage'>;type RevealActionScope = 'file' | 'section';type ReviewToolbarLayout = 'wide' | 'compact' | 'minimal';@@ -368,13 +385,51 @@ export function useClearReviewOperationNoticeOnSourceChange(}export function ReviewTabBody(props: ReviewTabBodyProps) {- if (props.state.turnTarget) return <TurnChangeSetReviewBody {...props} />;- return <GitReviewTabBody {...props} />;+ const [source, setSource] = useState<ReviewSource>('unstaged');+ const [selectedCommitOid, setSelectedCommitOid] = useState<string | null>(null);+ if (props.state.turnTarget) {+ return (+ <TurnChangeSetReviewBody+ {...props}+ setSource={setSource}+ setSelectedCommitOid={setSelectedCommitOid}+ />+ );+ }+ return (+ <GitReviewTabBody+ {...props}+ source={source}+ setSource={setSource}+ selectedCommitOid={selectedCommitOid}+ setSelectedCommitOid={setSelectedCommitOid}+ />+ );}-function TurnChangeSetReviewBody({ state, ctx }: ReviewTabBodyProps) {+function TurnChangeSetReviewBody({ state, ctx, setSource, setSelectedCommitOid }: TurnReviewBodyProps) {const { t } = useTranslation();const target = state.turnTarget;+ // 变更集所属会话。协同面板里审查 worker 的轮次时,tab 桶在 lead 会话+ // (worker 自己的桶在协同视图下不可见),数据按 targetSessionId 取。+ const reviewSessionId = target?.targetSessionId ?? ctx.sessionId;+ const crossSession = Boolean(target?.targetSessionId && target.targetSessionId !== ctx.sessionId);+ // 供来源下拉的「提交」子菜单用;与 Git 视图同一 IPC,子菜单展开时刷新。+ // 跨会话时不挂来源下拉(git 视图跟随桶会话 workdir,对 worker 语义错误),+ // 传 null 跳过取数。+ const commitsState = useReviewCommits(crossSession ? null : ctx.sessionId || null, state.branchBaseRef ?? null);+ const switchToGitSource = useCallback((next: ReviewSource) => {+ // 对齐 Codex EP 语义:切到其它来源即退出轮次审查(清 turnTarget),+ // 轮次选择不保留;要再看本条消息需从聊天流卡片重新进入。+ setSelectedCommitOid(null);+ setSource(next);+ ctx.patchState({ turnTarget: null });+ }, [ctx, setSelectedCommitOid, setSource]);+ const switchToCommitSource = useCallback((oid: string) => {+ setSelectedCommitOid(oid);+ setSource('commit');+ ctx.patchState({ turnTarget: null });+ }, [ctx, setSelectedCommitOid, setSource]);const [changeSets, setChangeSets] = useState<TurnChangeSetDetail[]>([]);const [loading, setLoading] = useState(true);const [error, setError] = useState<string | null>(null);@@ -403,7 +458,7 @@ function TurnChangeSetReviewBody({ state, ctx }: ReviewTabBodyProps) {setLoading(false);return;}- void window.electronAPI.maker.getTurnChangeSets(ctx.sessionId, targetIdsKey.split('\0'))+ void window.electronAPI.maker.getTurnChangeSets(reviewSessionId, targetIdsKey.split('\0')).then((sets) => {if (cancelled) return;setChangeSets(sets);@@ -418,7 +473,7 @@ function TurnChangeSetReviewBody({ state, ctx }: ReviewTabBodyProps) {return () => {cancelled = true;};- }, [ctx.deviceLinkDeviceId, ctx.remoteHostId, ctx.sessionId, reloadToken, t, targetIdsKey]);+ }, [ctx.deviceLinkDeviceId, ctx.remoteHostId, reloadToken, reviewSessionId, t, targetIdsKey]);const selectedDiff = target?.selectedDiffId? visibleDiffs.find((diff) => diff.id === target.selectedDiffId)@@ -441,21 +496,34 @@ function TurnChangeSetReviewBody({ state, ctx }: ReviewTabBodyProps) {return (<div className="flex min-h-0 flex-1 flex-col overflow-hidden bg-[var(--panel-bg)]"><header className="flex min-h-12 shrink-0 items-center gap-2 border-b border-[var(--border-default)] px-3 py-2">- <FileDiffIcon size={15} className="shrink-0 text-[var(--text-secondary)]" />- <span className="min-w-0 flex-1 truncate text-[12px] font-medium text-[var(--text-primary)]">- {t('rightSidebar.review.turn.title')}- </span>+ {crossSession ? (+ // 跨会话(协同 worker 的轮次):不提供 git 来源切换——git 视图跟随+ // 桶会话的 workdir,对 worker 的 worktree 语义错误。静态标题,关 tab 退出。+ <>+ <FileDiffIcon size={15} className="shrink-0 text-[var(--text-secondary)]" />+ <span className="min-w-0 truncate text-[12px] font-medium text-[var(--text-primary)]">+ {t('rightSidebar.review.turn.title')}+ </span>+ </>+ ) : (+ <SourceDropdown+ source="turn"+ counts={{}}+ commits={commitsState.data?.commits ?? []}+ commitsLoading={commitsState.loading}+ commitsError={commitsState.error}+ commitsLoaded={commitsState.data !== null}+ selectedCommitOid={null}+ onChange={switchToGitSource}+ onSelectCommit={switchToCommitSource}+ onRefreshCommits={commitsState.refresh}+ />+ )}+ <span className="min-w-0 flex-1 truncate" /><span className="shrink-0 whitespace-nowrap font-mono text-[11px] tabular-nums"><span className="text-[var(--diff-add-fg)]">+{totalAdd}</span>{' '}<span className="text-[var(--diff-del-fg)]">-{totalDel}</span></span>- <button- type="button"- onClick={() => ctx.patchState({ turnTarget: null })}- className="h-7 shrink-0 rounded-full px-2 text-[11px] font-medium text-[var(--text-secondary)] hover:bg-[var(--surface-hover)] hover:text-[var(--text-primary)]"- >- {t('rightSidebar.review.turn.currentWorkspace')}- </button></header>{!loading && !error && isPartial && (<div className="flex shrink-0 items-start gap-2 border-b border-[var(--border-default)] bg-[var(--warning-bg-soft)] px-3 py-2 text-[11px] leading-relaxed text-[var(--text-secondary)]">@@ -503,7 +571,7 @@ function TurnChangeSetReviewBody({ state, ctx }: ReviewTabBodyProps) {);}-function GitReviewTabBody({ state, ctx }: ReviewTabBodyProps) {+function GitReviewTabBody({ state, ctx, source, setSource, selectedCommitOid, setSelectedCommitOid }: GitReviewBodyProps) {const { t } = useTranslation();const { confirm } = useConfirmDialog();const sessionId = ctx.sessionId || null;@@ -511,8 +579,6 @@ function GitReviewTabBody({ state, ctx }: ReviewTabBodyProps) {const branchBaseRef = state.branchBaseRef ?? null;const { data, loading, error, refresh, setData: setReviewData } = useReviewGitState(sessionId, hideWhitespace);const commitsState = useReviewCommits(sessionId, branchBaseRef);- const [source, setSource] = useState<ReviewSource>('unstaged');- const [selectedCommitOid, setSelectedCommitOid] = useState<string | null>(null);const [pendingKey, setPendingKey] = useState<string | null>(null);const [operationError, setOperationError] = useState<string | null>(null);const [operationSummary, setOperationSummary] = useState<ReviewStageOperationSummary | null>(null);@@ -909,7 +975,7 @@ function GitReviewTabBody({ state, ctx }: ReviewTabBodyProps) {if (!committed) return messageText;return decoratePushError(messageText, err);}).then((completed) => ({ committed, completed }));- }, [branchDiffState, commitsState, decoratePushError, runPushFlow, runWrite, sessionId, source, updateReviewDataFromWrite]);+ }, [branchDiffState, commitsState, decoratePushError, runPushFlow, runWrite, sessionId, setSelectedCommitOid, source, updateReviewDataFromWrite]);const pushCurrentBranch = useCallback(() => {if (!sessionId) return;@@ -927,7 +993,7 @@ function GitReviewTabBody({ state, ctx }: ReviewTabBodyProps) {setSelectedCommitOid(null);setSource('branch');}- }, [commits, commitsState.data, commitsState.loading, selectedCommitOid, source]);+ }, [commits, commitsState.data, commitsState.loading, selectedCommitOid, setSelectedCommitOid, setSource, source]);const togglePath = useCallback((id: string) => {@@ -962,7 +1028,7 @@ function GitReviewTabBody({ state, ctx }: ReviewTabBodyProps) {const selectCommitSource = useCallback((oid: string) => {setSelectedCommitOid(oid);setSource('commit');- }, []);+ }, [setSelectedCommitOid, setSource]);const requestFileJump = useCallback((diff: FileDiff) => {setJumpRequest((prev) => ({ id: diff.id, nonce: (prev?.nonce ?? 0) + 1 }));}, []);@@ -2145,8 +2211,9 @@ export function SourceDropdown({onSelectCommit,onRefreshCommits,}: {- source: ReviewSource;- counts: { unstaged: number; staged: number; branch: number; lastTurn: number };+ /** `'turn'` 表示轮次审查(turnTarget)选中态:非 git 来源,仅作为当前项展示。 */+ source: ReviewSource | 'turn';+ counts: { unstaged?: number; staged?: number; branch?: number; lastTurn?: number };commits?: ReviewCommit[];commitsLoading?: boolean;commitsError?: string | null;@@ -2158,6 +2225,11 @@ export function SourceDropdown({onRefreshCommits?: () => void;}) {const { t } = useTranslation();+ // 轮次项只在轮次审查态存在(进入它的唯一入口是聊天流的变更卡片);+ // 切走即清 turnTarget、不提供"切回轮次"的常驻项,对齐 Codex 的 EP 语义。+ const turnOption: SourceDropdownOption | null = source === 'turn'+ ? { source: 'turn', label: t('rightSidebar.review.turn.title') }+ : null;const options: SourceDropdownOption[] = [{ source: 'unstaged', label: t('rightSidebar.review.source.unstaged'), count: counts.unstaged },{ source: 'staged', label: t('rightSidebar.review.source.staged'), count: counts.staged },@@ -2166,7 +2238,7 @@ export function SourceDropdown({{ source: 'last-turn', label: t('rightSidebar.review.source.lastTurn') },];const directOptions = options.filter((option) => option.source !== 'commit');- const selected = options.find((option) => option.source === source) ?? options[0];+ const selected = turnOption ?? options.find((option) => option.source === source) ?? options[0];const commitList = commits ?? [];const commitMenuLoaded = commitsLoaded ?? false;return (@@ -2190,6 +2262,13 @@ export function SourceDropdown({sideOffset={4}className="w-[var(--radix-dropdown-menu-trigger-width)] min-w-[12rem] rounded-[8px] border border-[var(--cmd-palette-border)] bg-[var(--cmd-palette-bg)] p-1 shadow-[var(--shadow-menu)]">+ {turnOption && (+ <SourceDropdownItem+ option={turnOption}+ active+ onChange={onChange}+ />+ )}{directOptions.slice(0, 2).map((option) => (<SourceDropdownItemkey={option.source}@@ -2291,7 +2370,7 @@ export function SourceDropdown({}interface SourceDropdownOption {- source: ReviewSource;+ source: ReviewSource | 'turn';label: string;count?: number;}@@ -2316,7 +2395,10 @@ function SourceDropdownItem({}) {return (<DropdownMenuItem- onSelect={() => onChange(option.source)}+ // 轮次伪选项已是选中态,点它只关菜单,不产生来源切换。+ onSelect={() => {+ if (option.source !== 'turn') onChange(option.source);+ }}className="flex h-8 items-center gap-2 rounded-[6px] px-2 text-[12px] text-[var(--text-primary)] focus:bg-[var(--cmd-palette-item-hover)]"><span className="min-w-0 flex-1 truncate">{option.label}</span>diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/review/__tests__/ReviewTabBody.helpers.test.ts b/apps/desktop/src/renderer/features/right-sidebar/plugins/review/__tests__/ReviewTabBody.helpers.test.tsindex 0a7a818100..ea29f3b91e 100644--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/review/__tests__/ReviewTabBody.helpers.test.ts+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/review/__tests__/ReviewTabBody.helpers.test.ts@@ -231,6 +231,65 @@ describe('ReviewTabBody compact source dropdown', () => {});});+describe('ReviewTabBody turn source dropdown', () => {+ // 轮次审查(turnTarget)与 Git 审查共用同一个来源下拉:轮次态下选中项是+ // 轮次伪选项,git 来源仍全部可选——这是"从轮次视图切回 git 审查不需要+ // 关掉重开 tab"的回归钉。+ it('shows the turn pseudo-source as the selected trigger label', () => {+ render(createElement(SourceDropdown, {+ source: 'turn',+ counts: {},+ onChange: vi.fn(),+ }));++ const trigger = screen.getByRole('button', { name: 'rightSidebar.review.sourceDropdownAria' });+ expect(trigger.textContent).toBe('rightSidebar.review.turn.title');+ });++ it('lists git sources in turn mode and switches directly without close-reopen', async () => {+ const onChange = vi.fn();+ render(createElement(SourceDropdown, {+ source: 'turn',+ counts: {},+ onChange,+ }));++ const trigger = screen.getByRole('button', { name: 'rightSidebar.review.sourceDropdownAria' });+ fireEvent.keyDown(trigger, { key: 'Enter' });++ expect(await screen.findByRole('menuitem', { name: 'rightSidebar.review.turn.title' })).toBeTruthy();+ fireEvent.click(screen.getByRole('menuitem', { name: 'rightSidebar.review.source.unstaged' }));+ expect(onChange).toHaveBeenCalledWith('unstaged');+ });++ it('keeps the turn pseudo-item selection-only (no source change on click)', async () => {+ const onChange = vi.fn();+ render(createElement(SourceDropdown, {+ source: 'turn',+ counts: {},+ onChange,+ }));++ const trigger = screen.getByRole('button', { name: 'rightSidebar.review.sourceDropdownAria' });+ fireEvent.keyDown(trigger, { key: 'Enter' });+ fireEvent.click(await screen.findByRole('menuitem', { name: 'rightSidebar.review.turn.title' }));+ expect(onChange).not.toHaveBeenCalled();+ });++ it('does not offer the turn pseudo-item while a git source is active', async () => {+ render(createElement(SourceDropdown, {+ source: 'unstaged',+ counts: { unstaged: 0, staged: 0, branch: 0, lastTurn: 0 },+ onChange: vi.fn(),+ }));++ const trigger = screen.getByRole('button', { name: 'rightSidebar.review.sourceDropdownAria' });+ fireEvent.keyDown(trigger, { key: 'Enter' });+ await screen.findByRole('menuitem', { name: 'rightSidebar.review.source.unstaged' });+ expect(screen.queryByRole('menuitem', { name: 'rightSidebar.review.turn.title' })).toBeNull();+ });+});+describe('ReviewTabBody branch base dropdown', () => {it('marks stale local branch candidates with a tertiary text suffix', () => {render(createElement(BranchBaseDropdown, {diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/review/index.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/review/index.tsxindex 6486a9a2b7..a09ad0c623 100644--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/review/index.tsx+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/review/index.tsx@@ -28,6 +28,12 @@ export interface ReviewState {selectedDiffId: string | null;selectedPath: string | null;requestNonce: number;+ /**+ * 变更集所属会话。null(旧数据)= 与 tab 桶同会话;与桶会话不同(协同面板+ * 里审查 worker 的轮次)时按它取数,且不提供 git 来源切换(git 视图跟随桶+ * 会话的 workdir,对 worker 语义错误)。+ */+ targetSessionId: string | null;} | null;/** 用户收起过哪些 diff id。空数组表示所有当前 diff 默认展开。 */collapsedPaths: string[];@@ -125,6 +131,9 @@ const plugin: TabKindPlugin<ReviewState> = {requestNonce: typeof (rawTurnTarget as { requestNonce?: unknown }).requestNonce === 'number'? (rawTurnTarget as { requestNonce: number }).requestNonce: 0,+ targetSessionId: typeof (rawTurnTarget as { targetSessionId?: unknown }).targetSessionId === 'string'+ ? (rawTurnTarget as { targetSessionId: string }).targetSessionId+ : null,}: null;return { turnTarget, collapsedPaths, diffViewMode, fileTreeVisible, wordWrap, wordDiff, hideWhitespace, richMarkdownPreview, branchBaseRef };diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex e7c5470158..24e915dfeb 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -4489,7 +4489,6 @@"review": {"turn": {"title": "Changes from this message",- "currentWorkspace": "Current workspace","localOnly": "Exact message changes are not available for remote sessions yet.","partialNotice": "This message includes command or tool writes that could not be tracked exactly. Only the captured subset is shown; it is not a complete patch.","emptyTitle": "No recorded changes",@@ -6303,6 +6302,7 @@"actionUnavailable": "This message includes file changes that cannot be safely undone","actionFailed": "The changes could not be applied. Try again","partial": "Only the changes captured exactly are shown",+ "partialNone": "Files were changed, but their contents could not be recorded, so they cannot be reviewed or undone here","partialReversible": "Only exactly captured changes can be undone or reapplied; uncaptured changes are not handled","partialActionHint": "Only undo or reapply exactly captured file changes","showMore": "Show {{count}} more files",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex 5fba1330b3..5f9e15693c 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -4487,7 +4487,6 @@"review": {"turn": {"title": "このメッセージの変更",- "currentWorkspace": "現在のワークスペース","localOnly": "メッセージ単位の正確な変更は、リモートタスクではまだ利用できません。","partialNotice": "このメッセージには正確に追跡できないコマンドまたはツールの書き込みが含まれます。以下は取得できた一部のみで、完全なパッチではありません。","emptyTitle": "記録された変更はありません",@@ -6300,6 +6299,7 @@"actionUnavailable": "このメッセージには安全に元に戻せないファイル変更が含まれています","actionFailed": "変更を適用できませんでした。もう一度お試しください","partial": "正確に取得できた変更のみ表示しています",+ "partialNone": "ファイルは変更されましたが、内容を記録できなかったため、ここではレビューや元に戻す操作ができません","partialReversible": "元に戻す操作と再適用の対象は正確に取得された変更のみです。取得されていない変更は処理されません","partialActionHint": "正確に取得されたファイル変更のみを元に戻すか再適用します","showMore": "さらに {{count}} ファイルを表示",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex 2882109410..89ff555a45 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -4487,7 +4487,6 @@"review": {"turn": {"title": "이 메시지의 변경 사항",- "currentWorkspace": "현재 작업 공간","localOnly": "메시지별 정확한 변경 사항은 아직 원격 작업에서 사용할 수 없습니다.","partialNotice": "이 메시지에는 정확히 추적할 수 없는 명령 또는 도구 쓰기가 포함되어 있습니다. 아래에는 캡처된 일부만 표시되며 완전한 패치가 아닙니다.","emptyTitle": "기록된 변경 사항 없음",@@ -6300,6 +6299,7 @@"actionUnavailable": "이 메시지에는 안전하게 실행 취소할 수 없는 파일 변경 사항이 포함되어 있습니다","actionFailed": "변경 사항을 적용하지 못했습니다. 다시 시도하세요","partial": "정확히 캡처된 변경 사항만 표시됩니다",+ "partialNone": "파일이 변경되었지만 내용을 기록하지 못해 여기에서 검토하거나 실행 취소할 수 없습니다","partialReversible": "실행 취소와 다시 적용은 정확히 캡처된 변경 사항만 처리하며 캡처되지 않은 변경 사항은 처리하지 않습니다","partialActionHint": "정확히 캡처된 파일 변경 사항만 실행 취소하거나 다시 적용합니다","showMore": "파일 {{count}}개 더 보기",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 880eecfd7e..81c505df22 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -4487,7 +4487,6 @@"review": {"turn": {"title": "本条消息的变更",- "currentWorkspace": "当前工作区","localOnly": "本条消息的精确变更暂不支持远程任务。","partialNotice": "本条消息包含无法精确追踪的命令或工具写入;以下仅展示已精确捕获的部分,不能视为完整补丁。","emptyTitle": "没有已记录的变更",@@ -6300,6 +6299,7 @@"actionUnavailable": "本条消息包含无法安全撤销的文件变更","actionFailed": "未能应用本条消息的改动,请重试","partial": "仅记录了可精确捕获的部分变更",+ "partialNone": "有文件被更改,但内容未能记录,无法在此审查或撤销","partialReversible": "仅撤销或重新应用已精确记录的变更;未记录的改动不会由此操作处理","partialActionHint": "仅撤销或重新应用已精确记录的文件变更","showMore": "再显示 {{count}} 个文件",diff --git a/apps/desktop/src/renderer/lib/generatedFiles.ts b/apps/desktop/src/renderer/lib/generatedFiles.tsindex 31369d5adc..f7aebe1f9b 100644--- a/apps/desktop/src/renderer/lib/generatedFiles.ts+++ b/apps/desktop/src/renderer/lib/generatedFiles.ts@@ -51,9 +51,16 @@ interface ToolUseLike {*/function dedupeKeyForPath(abs: string): string {const isWindowsShape = /^[a-zA-Z]:[\\/]/.test(abs) || abs.includes('\\');+ if (!isWindowsShape) return abs;// 斜杠也归一:`C:/x/a.md`(命令文本常见形态)与 `C:\x\a.md`(Write 记录)是- // 同一文件,不折叠会重复出 chip。- return isWindowsShape ? abs.replace(/\//g, '\\').toLowerCase() : abs;+ // 同一文件,不折叠会重复出 chip。连续分隔符同理折叠:命令文本常是二次转义的+ // 包装串(如 powershell 包一层 node -e),提取出的 `C:\\x\\a.md` 与 `C:\x\a.md`+ // 在 fs 层等价(Windows 归并重复分隔符),不折叠会对同一文件出两个 chip。+ // UNC 头部的 `\\` 是路径语义的一部分,保留。+ return abs+ .replace(/\//g, '\\')+ .replace(/(?<!^)\\{2,}/g, '\\')+ .toLowerCase();}/**@@ -63,7 +70,11 @@ function dedupeKeyForPath(abs: string): string {* 路径原样保留。*/function canonicalizeWindowsShape(abs: string): string {- return /^[a-zA-Z]:[\\/]/.test(abs) ? abs.replace(/\//g, '\\') : abs;+ // 连续分隔符折叠进画布路径本身(不只 dedupe key):stat 虽能容忍 `C:\\x`,但+ // Explorer `/select` 与 chip 展示不该带转义残留。盘符形态不存在 UNC 头,可整段折叠。+ return /^[a-zA-Z]:[\\/]/.test(abs)+ ? abs.replace(/\//g, '\\').replace(/\\{2,}/g, '\\')+ : abs;}/** 单条 tool_use 消息 → 它新建的文件原始路径列表(可能为空)。 */diff --git a/apps/desktop/src/shared/rightSidebarWindow.ts b/apps/desktop/src/shared/rightSidebarWindow.tsindex ae341e93c6..80108789b5 100644--- a/apps/desktop/src/shared/rightSidebarWindow.ts+++ b/apps/desktop/src/shared/rightSidebarWindow.ts@@ -56,6 +56,11 @@ export type RsbWindowCommand =selectedDiffId?: string | null;selectedPath?: string | null;requestNonce: number;+ /**+ * 承载 review tab 的 RSB 桶(缺省 = sessionId 自身)。协同面板里 worker+ * 流的入口传 lead sessionId:worker 自己的桶在协同视图下不可见。+ */+ hostSessionId?: string | null;}| {type: 'open-file-browser';diff --git a/apps/desktop/src/shared/turnChangeSet.ts b/apps/desktop/src/shared/turnChangeSet.tsindex a057a591f5..71783d0433 100644--- a/apps/desktop/src/shared/turnChangeSet.ts+++ b/apps/desktop/src/shared/turnChangeSet.ts@@ -78,9 +78,11 @@ export interface PersistedTurnChangeSetV1 {/*** Reasons that only say "the capture may not have seen everything", without any* evidence that a change actually happened (opaque tools ran, the turn failed, or- * another session overlapped). Reasons outside this set (diff-too-large,- * outside-workspace, sensitive-file, …) prove real changes existed but were not- * recorded.+ * another session overlapped). Reasons outside this set prove changes existed but+ * were not recorded — including 'outside-workspace', which the store only records+ * for suspicious cases (a workspace path whose realpath escapes via symlink, or a+ * provider diff block rejected as unsafe); literal out-of-workspace targets are+ * skipped at capture time without recording any reason.*/const NO_CHANGE_EVIDENCE_REASONS: ReadonlySet<TurnChangeIncompleteReason> = new Set(['opaque-tool',diff --git a/packages/device-link/src/__tests__/client.test.ts b/packages/device-link/src/__tests__/client.test.tsindex 0337a8e926..adedf9bff4 100644--- a/packages/device-link/src/__tests__/client.test.ts+++ b/packages/device-link/src/__tests__/client.test.ts@@ -592,6 +592,17 @@ describe('DeviceLinkClient', () => {h.client.start();await tick();const ws = h.current();+ // 确定性回 pong:监听出站 ping、同步应答,彻底消除对真实计时器调度的依赖。+ // 必须在 ack()(hello-ack 启动心跳)之前装上:装晚了,建链期间的若干+ // await tick() 在慢 CI/Windows 上可能耗掉两个 8ms 心跳周期,期间 ping+ // 无人应答就已误判断网。语义不变:若慢业务 handler 真堵住帧处理,push+ // 进来的 pong 不会被消费,pongMiss 照样触发断网,断言仍能抓住回归。+ const originalSend = ws.send.bind(ws);+ ws.send = (data: string) => {+ originalSend(data);+ const env = JSON.parse(data) as Envelope;+ if (env.kind === 'ping') ws.push({ v: PROTOCOL_VERSION, kind: 'pong' });+ };ws.ack();await establishInboundReliableLink(h, 'slow-stream');@@ -611,16 +622,6 @@ describe('DeviceLinkClient', () => {data: JSON.stringify({ channel: 'maker:event', payload: { text: 'slow' } }),},});- // 确定性回 pong:监听出站 ping、同步应答,彻底消除对真实计时器调度的依赖- // (旧写法用 4ms setInterval 自由跑,慢 CI/Windows 上会落后两个 8ms 心跳- // 周期触发误断网)。语义不变:若慢业务 handler 真堵住帧处理,push 进来的- // pong 不会被消费,pongMiss 照样触发断网,断言仍能抓住回归。- const originalSend = ws.send.bind(ws);- ws.send = (data: string) => {- originalSend(data);- const env = JSON.parse(data) as Envelope;- if (env.kind === 'ping') ws.push({ v: PROTOCOL_VERSION, kind: 'pong' });- };await tick();expect(release).toBeTypeOf('function');