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 — 批量与单项互斥、按 owner 重排、前置条件可恢复、同步 MCP 描述
Chris37010848dd9e
diff --git a/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx b/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsxindex ba449d6d3f..e4bf8d5a23 100644--- a/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx+++ b/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx@@ -172,6 +172,8 @@ export function GhostPluginPage() {const [query, setQuery] = useState('');const [marketSnapshot, setMarketSnapshot] = useState<PluginMarketSnapshot | null>(null);const [openPanelId, setOpenPanelId] = useState<string | null>(null);+ // 数据归属键:面板宿主与排序快照都按它失效(定义要早于两处消费点)。+ const panelOwnerKey = ghostPanelOwnerKey(mode, dataOwnerId);const ignoredRoundKey = ignoredRoundStorageKey(mode, dataOwnerId);const [ignoredRound, setIgnoredRound] = useState(() => readIgnoredRound(ignoredRoundKey));// 账号 / 本地云模式切换:换桶重读,不把上一个身份的「忽略本轮」带进来。@@ -474,6 +476,15 @@ export function GhostPluginPage() {// ── 排序快照:进页(市场快照首次就绪)时排一次,页内交互不重排 ──// 可更新的排最前,其余按最近使用;停留期间清未读/装更新都不许让卡片跳位。const [orderSnapshot, setOrderSnapshot] = useState<string[] | null>(null);+ // 换账号/模式要丢弃旧顺序:两个 owner 的已装集合、可更新集合与最近使用+ // 都不同,沿用账号 A 的 id 顺序会把 B 的非更新项排到更新项前面,违背+ // 「可更新优先」。清空后由下面的 effect 基于**新 owner 的首个市场快照**重排。+ const orderOwnerKeyRef = useRef(panelOwnerKey);+ useEffect(() => {+ if (orderOwnerKeyRef.current === panelOwnerKey) return;+ orderOwnerKeyRef.current = panelOwnerKey;+ setOrderSnapshot(null);+ }, [panelOwnerKey]);useEffect(() => {if (orderSnapshot !== null) return;if (marketSnapshot === null) return;@@ -584,7 +595,6 @@ export function GhostPluginPage() {* 账号 B 面前。这里按 owner 键显式清空;首帧不清,免得把 ?panel= 深链刚设上的* 目标一并抹掉(那条 effect 排在本条之前)。*/- const panelOwnerKey = ghostPanelOwnerKey(mode, dataOwnerId);const panelOwnerKeyRef = useRef(panelOwnerKey);useEffect(() => {const previous = panelOwnerKeyRef.current;@@ -729,6 +739,9 @@ export function GhostPluginPage() {setUpdateDialogOpen(true);return;}+ // 单项更新持有 market lease 期间不许开新批次:此刻的市场快照还把那个+ // 插件标成 update-available,批次会把它一并收进去重复装一遍。+ if (marketBusyLockRef.current !== null) return;startUpdateAllBatch(updatableInstalledItems.flatMap((item) => (item.marketUpdate ? [item.marketUpdate] : [])),);@@ -1284,10 +1297,12 @@ export function GhostPluginPage() {>{t('settings.ghosts.page.ignoreRound')}</button>+ {/* 单项更新在飞时禁用:与 handleUpdateAll 的守卫同因,按钮如实变灰。 */}<buttontype="button"onClick={handleUpdateAll}- className="inline-flex h-9 shrink-0 items-center rounded-full bg-[var(--accent-cta-bg)] px-4 text-12 font-medium text-[var(--accent-pure-cta-fg)] transition-transform duration-150 hover:bg-[var(--accent-hover)] active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]"+ disabled={marketBusyId !== null}+ className="inline-flex h-9 shrink-0 items-center rounded-full bg-[var(--accent-cta-bg)] px-4 text-12 font-medium text-[var(--accent-pure-cta-fg)] transition-transform duration-150 hover:bg-[var(--accent-hover)] active:scale-[0.98] disabled:cursor-not-allowed disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]">{t('settings.ghosts.page.updateAll')}</button>diff --git a/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts b/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.tsindex f3d80e5567..23ef3aa5e7 100644--- a/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts+++ b/apps/desktop/src/renderer/features/plugin/__tests__/updateAllController.test.ts@@ -509,6 +509,51 @@ describe('updateAllController', () => {expect(vi.mocked(toast.success)).toHaveBeenCalledTimes(1);});+ it('skips a row whose target release was already installed by the single-item flow', async () => {+ // 用户在批次启动前用卡片的单项更新装了同一个 release;本批次拿的是那之前的+ // 市场快照,仍标 update-available。runner 取详情后必须发现已落账并跳过。+ detailMock.mockResolvedValue({+ ...marketItem({ installState: 'installed' }),+ manifest: manifest({ version: '1.1.0' }),+ readme: null,+ } as unknown as PluginMarketDetail);++ startUpdateAllBatch([marketItem({})]);+ await waitForSettledBatch();++ expect(getUpdateAllBatchState().rows?.[0]?.status).toBe('done');+ expect(installMock).not.toHaveBeenCalled();+ });++ it('holds a runner row for re-review instead of failing it on PRECONDITION_FAILED', async () => {+ stubDetail({ manifest: manifest({}), sourceType: 'git-market' });+ installMock.mockRejectedValueOnce(+ Object.assign(new Error('precondition'), {+ message: 'Error invoking remote method: Error: [PRECONDITION_FAILED] release changed',+ }),+ );++ startUpdateAllBatch([marketItem({ sourceType: 'git-market' })]);+ await waitForSettledBatch();++ const row = getUpdateAllBatchState().rows?.[0];+ // 自动安装路径遇到前置条件变化 → 可恢复的待重审,不是终态失败。+ expect(row).toMatchObject({ status: 'needs-confirm', staleReview: true });+ expect(row?.errorText).toBeUndefined();+ expect(row?.permissionDiff).toBeUndefined();+ });++ it('still fails the row on non-precondition install errors', async () => {+ stubDetail({ manifest: manifest({}), sourceType: 'server' });+ installMock.mockRejectedValueOnce(new Error('network down'));++ startUpdateAllBatch([marketItem({})]);+ await waitForSettledBatch();++ // 真失败仍然是失败:不能把所有错误都变成"再审一次"。+ expect(getUpdateAllBatchState().rows?.[0]?.status).toBe('failed');+ });+it('re-reviews instead of failing when a custom source swaps the manifest under the plain update path', async () => {// 自定义市场源:审阅基线含 network,目标包在此之上多出 fs。installedGhosts = [diff --git a/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts b/apps/desktop/src/renderer/features/plugin/lib/updateAllController.tsindex 60bb2c6a3a..387e347b03 100644--- a/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts+++ b/apps/desktop/src/renderer/features/plugin/lib/updateAllController.ts@@ -122,6 +122,26 @@ function batchOwnerCurrent(): boolean {return batchOwner !== null && isDataOwnerGenerationCurrent(batchOwner);}+/**+ * 把一行退回「待重新审阅」——前置条件变化的统一收敛(runner 与批准共用)。+ *+ * 清掉旧的 permissionDiff 并打 staleReview:弹窗据此显示「权限差异已过期 /+ * 重新审阅」,用户点一下就走 approve 按当前事实重取详情、重算差异,+ * 无扩权直接装、仍扩权则逐项审。可恢复,不必关弹窗重启整批。+ */+function holdRowForReReview(+ generation: number,+ pluginId: string,+ patch: Partial<UpdateAllRow> = {},+): void {+ patchRow(generation, pluginId, {+ status: 'needs-confirm',+ staleReview: true,+ permissionDiff: undefined,+ ...patch,+ });+}+/** 账号/模式切换后作废整个批次(旧代际的 runner 在下一个检查点自行退出)。 */function voidStaleBatch(): void {batchOwner = null;@@ -219,6 +239,13 @@ async function runQueue(generation: number): Promise<void> {voidStaleBatch();return;}+ if (detail.installState === 'installed') {+ // 目标 release 已经落账——典型是用户在批次启动前后用卡片上的单项更新+ // 装了同一个 release,而本批次拿的是那之前的市场快照。直接收束,+ // 不重复下载安装同一份包。+ patchRow(generation, next.pluginId, { status: 'done' });+ continue;+ }const installedManifest = installedManifestOf(next.ghostId);if (!installedManifest) {// 批量期间插件已被卸载:绝不拿市场 manifest 兜底继续安装@@ -245,12 +272,20 @@ async function runQueue(generation: number): Promise<void> {});patchRow(generation, next.pluginId, { status: 'done' });} catch (error) {+ if (batchGeneration !== generation) return;+ if (extractIpcError(error)?.code === 'PRECONDITION_FAILED') {+ // 前置条件变化(基线复核否决 / release 变了 / 自定义源换了 manifest)+ // 不是「更新失败」而是「事实已变,请重新审阅」。落成终态 failed 会让+ // 这一项彻底没有入口,用户只能关掉弹窗重启整批。改为可恢复的待重审:+ // 弹窗显示「权限差异已过期 / 重新审阅」,点一下就按当前事实重算。+ holdRowForReReview(generation, next.pluginId);+ continue;+ }// 失败也只写回自己的批次:代际失效时这条错误属于已作废的批次。patchRow(generation, next.pluginId, {status: 'failed',errorText: i18n.t(pluginMarketErrorKey(error)),});- if (batchGeneration !== generation) return;}}} finally {diff --git a/packages/cindy-tools/src/ghost/mcpServer.ts b/packages/cindy-tools/src/ghost/mcpServer.tsindex ed42b921c2..96de3b3465 100644--- a/packages/cindy-tools/src/ghost/mcpServer.ts+++ b/packages/cindy-tools/src/ghost/mcpServer.ts@@ -71,8 +71,8 @@ const D_GHOST_FORGE_GUIDE = ["管子 API(cindy.send)、面板与主题、沙箱红线、打包与测试流程。整本超出单次工具",'结果上限,分章取用:不传参数返回目录,传 section(章号如 "4.7" 或章标题关键词如','"network")返回单章正文。用户说"帮我做一个 XX 插件 / 改一下某插件"时,先取目录、',- "先按第 0 章「设计对齐」用带选项的提问卡片和用户确认界面形态(停靠面板/右侧栏页签/",- "纯工具)等关键决策,再按需读相关章;新插件可用 ghost_forge_scaffold 生成骨架,",+ "先按第 0 章「设计对齐」用带选项的提问卡片和用户确认界面形态(停靠面板/插件页内",+ "面板/纯工具)等关键决策,再按需读相关章;新插件可用 ghost_forge_scaffold 生成骨架,","修改完成后再用 ghost_forge_pack 打包装入。",].join("\n");