Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix: address review — 权限审阅基线改绑 manifest 权限指纹
Chris7b5019b085d7
diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts b/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.tsindex c751d9948b..ea8e45ac13 100644--- a/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts+++ b/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts@@ -160,7 +160,7 @@ describe('updateAllController', () => {expect(installMock).not.toHaveBeenCalled();});- it('recomputes the diff when an external update moved the installed version', async () => {+ it('recomputes the diff when an external update replaced the permission baseline', async () => {stubDetail({manifest: manifest({ network: { hosts: ['api.example.com'] } }),sourceType: 'server',@@ -193,8 +193,9 @@ describe('updateAllController', () => {startUpdateAllBatch([marketItem({})]);await waitForSettledBatch();- // 外部装成第三个版本,但仍不含目标版本要新增的 network 权限。- installedGhosts = [{ manifest: manifest({ version: '1.0.5' }) }];+ // 外部装成第三个版本且权限面变了(多了 fs),但仍不含目标版本要新增的+ // network —— 基线失效触发重算,重算结果依旧是扩权。+ installedGhosts = [{ manifest: manifest({ version: '1.0.5', slots: ['fs'] }) }];reconcileUpdateAllBatch();await approveUpdateExpansion('plugin-a');@@ -205,7 +206,7 @@ describe('updateAllController', () => {expect(installMock).not.toHaveBeenCalled();});- it('recomputes on version drift even before reconcile flagged the row', async () => {+ it('recomputes on baseline drift even before reconcile flagged the row', async () => {stubDetail({manifest: manifest({ network: { hosts: ['api.example.com'] } }),sourceType: 'server',@@ -223,6 +224,55 @@ describe('updateAllController', () => {expect(installMock).toHaveBeenCalledWith('plugin-a', { expectedReleaseId: 'release-2' });});+ it('invalidates the review when a same-version manifest swap widened permissions', async () => {+ stubDetail({+ manifest: manifest({ network: { hosts: ['api.example.com'] } }),+ sourceType: 'server',+ });+ startUpdateAllBatch([marketItem({})]);+ await waitForSettledBatch();+ expect(getUpdateAllBatchState().rows?.[0]?.status).toBe('needs-confirm');++ // 「从文件更新」换入**同版本**但权限更宽的 manifest:版本号完全看不出来,+ // 沿用旧审阅会把 fs 这条从未审阅的权限一并放行。+ installedGhosts = [{ manifest: manifest({ version: '1.0.0', slots: ['fs'] }) }];+ reconcileUpdateAllBatch();+ const held = getUpdateAllBatchState().rows?.[0];+ expect(held).toMatchObject({ status: 'needs-confirm', staleReview: true });+ expect(held?.permissionDiff).toBeUndefined();++ await approveUpdateExpansion('plugin-a');+ // 相对新基线重算后仍是扩权 → 回到逐项审阅,绝不带 allowPermissionExpansion 放行。+ expect(installMock).not.toHaveBeenCalled();+ expect(getUpdateAllBatchState().rows?.[0]).toMatchObject({+ status: 'needs-confirm',+ staleReview: false,+ });+ });++ it('keeps the review valid when only the version moved but permissions are identical', async () => {+ stubDetail({+ manifest: manifest({ network: { hosts: ['api.example.com'] } }),+ sourceType: 'server',+ });+ startUpdateAllBatch([marketItem({})]);+ await waitForSettledBatch();++ // 权限面完全没变,只是版本号动了:审阅结论仍然成立,不该逼用户重审。+ installedGhosts = [{ manifest: manifest({ version: '1.0.4' }) }];+ reconcileUpdateAllBatch();+ const kept = getUpdateAllBatchState().rows?.[0];+ expect(kept).toMatchObject({ status: 'needs-confirm', fromVersion: '1.0.4' });+ expect(kept?.staleReview).toBeFalsy();+ expect(kept?.permissionDiff?.added.length).toBeGreaterThan(0);++ await approveUpdateExpansion('plugin-a');+ expect(installMock).toHaveBeenCalledWith('plugin-a', {+ expectedReleaseId: 'release-2',+ allowPermissionExpansion: true,+ });+ });+it('voids the batch when the data owner changes during the detail round-trip', async () => {let releaseDetail: (() => void) | undefined;detailMock.mockImplementation(diff --git a/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts b/apps/desktop/src/renderer/features/plugin/lib/updateAllController.tsindex 0ca45e63fc..2e96ae1873 100644--- a/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts+++ b/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts@@ -27,6 +27,7 @@ import {batchSummary,buildUpdateAllRows,isBatchFinished,+ permissionBaselineKey,updateRow,type UpdateAllRow,} from './updateAllModel';@@ -164,6 +165,8 @@ async function runQueue(): Promise<void> {status: 'needs-confirm',releaseId: detail.releaseId,permissionDiff: diff,+ // 审阅基线绑定权限指纹而非版本号:同版本换 manifest 也能识别。+ reviewedBaseline: permissionBaselineKey(installedManifest),...(detail.sourceType !== 'server' ? { expectedManifest: detail.manifest } : {}),});continue;@@ -210,14 +213,16 @@ export async function approveUpdateExpansion(pluginId: string): Promise<void> {}patchRow(pluginId, { status: 'installing' });try {- // 用户审阅的是「fromVersion → toVersion」这一段的权限差异。等待期间若被- // 「从文件更新」等外部路径装成了别的版本,那份 diff 与它换来的+ // 用户审阅的是「当前已装权限面 → 目标版本」的差异。等待期间若被+ // 「从文件更新」等外部路径换掉了已装 manifest,那份 diff 与它换来的// allowPermissionExpansion 就不再对应现实——重新取详情、以当前已装// manifest 重算,权限没扩张就按普通更新装,扩张面变了则退回待确认重审。- // 判据是 staleReview(reconcile 打的标)并联版本比较:reconcile 会把- // fromVersion 同步成当前版本供展示,那之后版本比较恒等,靠标志识别;- // reconcile 还没来得及跑的竞态窗口里,版本比较兜底。- if (row.staleReview === true || installed.version !== row.fromVersion) {+ //+ // 判据是权限指纹而非版本号:ghosts.update() 允许**同版本整体替换+ // manifest**(无版本单调性检查),同版本换入更宽的权限声明时版本比较+ // 完全看不出来,旧的 allowPermissionExpansion 会把未审阅的新权限一并+ // 放行。staleReview 并联进来覆盖 reconcile 已打标的情形。+ if (row.staleReview === true || permissionBaselineKey(installed) !== row.reviewedBaseline) {const detail = await window.electronAPI.pluginMarket.detail(pluginId);const freshDiff = diffGhostPermissionItems(installed, detail.manifest);if (freshDiff.added.length > 0) {@@ -228,6 +233,7 @@ export async function approveUpdateExpansion(pluginId: string): Promise<void> {releaseId: detail.releaseId,permissionDiff: freshDiff,staleReview: false,+ reviewedBaseline: permissionBaselineKey(installed),expectedManifest: detail.sourceType !== 'server' ? detail.manifest : undefined,});return;@@ -267,8 +273,8 @@ export function skipUpdateExpansion(pluginId: string): void {/*** 与外部事实对账:账号切换 → 整批作废;待确认行的插件被卸载 → 跳过、* 已被单项/文件更新装到目标版本 → 记为完成(不再提供重复安装入口)、- * 被装成别的版本 → 旧 permissionDiff 已不对应现实,清掉并标记待重审- * (真正的重算在 approve 时做,那里能取详情)。+ * 权限基线被换掉(含同版本替换 manifest)→ 旧 permissionDiff 已不对应+ * 现实,清掉并标记待重审(真正的重算在 approve 时做,那里能取详情)。* 页面在已装清单或身份变化时调用。*/export function reconcileUpdateAllBatch(): void {@@ -288,13 +294,18 @@ export function reconcileUpdateAllBatch(): void {} else if (installed.version === row.toVersion) {rows = updateRow(rows, row.pluginId, { status: 'done' });changed = true;- } else if (installed.version !== row.fromVersion) {+ } else if (permissionBaselineKey(installed) !== row.reviewedBaseline) {+ // 权限基线变了(换版本,或同版本换入不同权限声明):旧审阅作废。rows = updateRow(rows, row.pluginId, {fromVersion: installed.version,permissionDiff: undefined,staleReview: true,});changed = true;+ } else if (installed.version !== row.fromVersion) {+ // 权限面没变、只是版本号变了:审阅结论仍然成立,同步展示用版本即可。+ rows = updateRow(rows, row.pluginId, { fromVersion: installed.version });+ changed = true;}}if (changed) {diff --git a/apps/desktop/src/renderer/features/plugin/lib/updateAllModel.ts b/apps/desktop/src/renderer/features/plugin/lib/updateAllModel.tsindex 33d6ece445..39ffb66653 100644--- a/apps/desktop/src/renderer/features/plugin/lib/updateAllModel.ts+++ b/apps/desktop/src/renderer/features/plugin/lib/updateAllModel.ts@@ -7,7 +7,11 @@* [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md*/-import type { GhostManifest, GhostPermissionDiff } from '../../../../shared/ghost';+import {+ ghostPermissionItems,+ type GhostManifest,+ type GhostPermissionDiff,+} from '../../../../shared/ghost';import type { PluginMarketItem } from '../../../../shared/pluginMarket';/**@@ -34,10 +38,18 @@ export interface UpdateAllRow {/** 扩权详情(status 为 needs-confirm 时由运行器填充)。 */permissionDiff?: GhostPermissionDiff;/**- * 待确认期间插件被外部路径(从文件更新等)装成了别的版本:审阅过的+ * 待确认期间插件被外部路径(从文件更新等)换掉了权限基线:审阅过的* 权限差异已不对应现实,弹窗提示"需要重新审阅",按钮点下去先重算再决定。*/staleReview?: boolean;+ /**+ * 审阅所依据的**已装 manifest 权限指纹**(不是版本号)。+ * `ghosts.update()` 允许同版本整体替换 manifest,所以版本号不是可靠的+ * 审阅基线——同版本换入不同权限声明时,旧 diff 与它换来的+ * allowPermissionExpansion 会把未审阅的新权限一并放行。批准前必须拿+ * 当前已装 manifest 重算指纹比对,不一致即作废重审。+ */+ reviewedBaseline?: string;/*** 非 server 源在审阅时取得的 manifest:主进程对这类来源强制要求安装时* 传回同一份 reviewed manifest,approve 必须原样带上,否则 INVALID_PARAMS。@@ -47,6 +59,20 @@ export interface UpdateAllRow {errorText?: string;}+/**+ * 权限审阅基线指纹:同一份 manifest 推导出的权限条目集合(key + detail)。+ * 与 diffGhostPermissionItems 同口径(它也是按 key 对齐、detail 变化算差异),+ * 所以"指纹相同"等价于"权限面没变",可安全沿用先前的审阅结论。+ */+export function permissionBaselineKey(manifest: GhostManifest): string {+ // 每项 JSON 编码后再排序拼接:全可打印(不进 NUL,git diff 才不会把本文件+ // 判成二进制),且转义天然消除 "a","b" 与 "a,b","" 的拼接歧义。+ return ghostPermissionItems(manifest)+ .map((item) => JSON.stringify([item.key, item.detail ?? '']))+ .sort()+ .join('\n');+}+/** 从市场快照萃取可更新行;顺序即执行顺序(与列表快照顺序一致,稳定)。 */export function buildUpdateAllRows(marketItems: readonly PluginMarketItem[],