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(desktop): pass full-review flag and frozen digest in detail install and recovery retry

Yuewei-LL2f64c0cb13fe
diff --git a/apps/desktop/src/main/cindy-brain/GhostManager.ts b/apps/desktop/src/main/cindy-brain/GhostManager.ts
index 21b8cfee4b..6781c04dbb 100644
--- a/apps/desktop/src/main/cindy-brain/GhostManager.ts
+++ b/apps/desktop/src/main/cindy-brain/GhostManager.ts
@@ -1244,6 +1244,8 @@ export class GhostManager {
const resumeLedger = this.receiptStore.readMigrationLedger();
const resumePending =
resumeLedger?.state === 'in-progress' ? new Set(resumeLedger.pendingIds ?? []) : null;
+ const resumeApprovalProjectionDigest =
+ resumeLedger?.recoveryApprovalProjectionSha256ById ?? undefined;
const root = this.contentRootDir();
let entries: fs.Dirent[] = [];
@@ -1357,7 +1359,10 @@ export class GhostManager {
for (const id of candidates) {
try {
- const migrated = await this.backfillLegacyApproval(path.join(root, id), id);
+ const migrated = await this.backfillLegacyApproval(path.join(root, id), id, {
+ expectedApprovalProjectionSha256:
+ resumeApprovalProjectionDigest?.[id],
+ });
(migrated ? result.migrated : result.skipped).push(id);
pendingForRetry.delete(id);
} catch (err) {
@@ -1460,6 +1465,8 @@ export class GhostManager {
// Persist the complete recovery work queue before the first backfill. If the
// first receipt write or subsequent processing crashes, receiptStore.write()
// cannot auto-close the migration door and the remaining ids are still durable.
+ // Frozen digests are persisted alongside pending ids so that the generic
+ // retry path in migrateLegacyApprovalsOnce can verify content hasn't changed.
const queuedIds = [...new Set([...pendingForRetry, ...workIds])].sort();
const hadQueuedWork = queuedIds.length > 0;
if (queuedIds.length > 0) {
@@ -1470,6 +1477,11 @@ export class GhostManager {
...(prev?.failedIds?.length ? { failedIds: prev.failedIds } : {}),
state: 'in-progress',
pendingIds: queuedIds,
+ recoveryApprovalProjectionSha256ById: Object.fromEntries(
+ queuedIds
+ .filter((id) => options.expectedApprovalProjectionSha256ById[id] !== undefined)
+ .map((id) => [id, options.expectedApprovalProjectionSha256ById[id]]),
+ ),
});
for (const id of queuedIds) pendingForRetry.add(id);
}
@@ -1551,9 +1563,19 @@ export class GhostManager {
migratedIds: [...new Set([...(prev?.migratedIds ?? []), ...out.migrated])].sort(),
...(failedIds.length > 0 ? { failedIds } : {}),
// 旁路 backfill 的瞬时失败也必须进入持久化 work queue;目录已经搬入安装根,
- // 下一轮不会再次出现在“刚恢复”清单里,不能只靠内存日志重试。
+ // 下一轮不会再次出现在”刚恢复”清单里,不能只靠内存日志重试。
+ // 同时钉死恢复冻结的批准投影摘要,确保重试时内容未变。
state: pendingForRetry.size > 0 ? 'in-progress' : 'completed',
- ...(pendingForRetry.size > 0 ? { pendingIds: [...pendingForRetry].sort() } : {}),
+ ...(pendingForRetry.size > 0
+ ? {
+ pendingIds: [...pendingForRetry].sort(),
+ recoveryApprovalProjectionSha256ById: Object.fromEntries(
+ [...pendingForRetry]
+ .filter((id) => options.expectedApprovalProjectionSha256ById[id] !== undefined)
+ .map((id) => [id, options.expectedApprovalProjectionSha256ById[id]]),
+ ),
+ }
+ : {}),
});
}
if (out.migrated.length > 0) this.options.onChanged?.(this.list());
diff --git a/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts b/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
index 8af78bbdaa..0fbacc40ce 100644
--- a/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
+++ b/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
@@ -120,6 +120,12 @@ export interface GhostLegacyMigrationLedger {
state?: 'in-progress' | 'completed';
/** 仅 `in-progress`:本轮待迁 id 全集(动笔前钉死)。 */
pendingIds?: string[];
+ /**
+ * Owner recovery 在搬目录前冻结的批准投影摘要,按 id 索引。
+ * 仅对恢复路径进入 pending 的 id 有效;主迁移候选不含此字段。
+ * retry 路径用它在重试前验证内容未被篡改。
+ */
+ recoveryApprovalProjectionSha256ById?: Record<string, string>;
}
/**
@@ -456,6 +462,17 @@ export class GhostInstallReceiptStore {
return null;
}
if (raw.state !== 'in-progress' && raw.pendingIds !== undefined) return null;
+ if (
+ raw.recoveryApprovalProjectionSha256ById !== undefined &&
+ (typeof raw.recoveryApprovalProjectionSha256ById !== 'object' ||
+ raw.recoveryApprovalProjectionSha256ById === null ||
+ Array.isArray(raw.recoveryApprovalProjectionSha256ById) ||
+ Object.keys(raw.recoveryApprovalProjectionSha256ById).some(
+ (k) => !isValidGhostId(k) || !/^[a-f0-9]{64}$/.test(raw.recoveryApprovalProjectionSha256ById![k]),
+ ))
+ ) {
+ return null;
+ }
return raw;
} catch {
return null;
diff --git a/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx b/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx
index ad57d835b6..bfdc3f47e2 100644
--- a/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx
+++ b/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx
@@ -1277,7 +1277,9 @@ export function GhostPluginPage() {
...(isUpdate && installedGhost
? { expectedInstalledApproval: ghostInstallApprovalToken(installedGhost.approval) }
: {}),
- ...(isUpdate && diff!.added.length > 0
+ ...(isUpdate &&
+ (diff!.added.length > 0 ||
+ installedGhost?.approval.state !== 'approved')
? {
allowPermissionExpansion: true,
...(installedGhost