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): 隐藏不可处理的旧插件恢复提示

liugaoweida43446e00c0
diff --git a/apps/desktop/src/main/__tests__/ownerNamespaceMigration.test.ts b/apps/desktop/src/main/__tests__/ownerNamespaceMigration.test.ts
index 77822c90b5..d2673bf9bf 100644
--- a/apps/desktop/src/main/__tests__/ownerNamespaceMigration.test.ts
+++ b/apps/desktop/src/main/__tests__/ownerNamespaceMigration.test.ts
@@ -537,11 +537,7 @@ describe('legacy Ghost plugin recovery', () => {
{ mode: 'cloud', dataOwnerId: ownerId, user: { id: ownerId } },
root,
),
- ).toEqual({
- state: 'partial',
- legacyPluginCount: 1,
- canRetry: false,
- });
+ ).toEqual({ state: 'none', legacyPluginCount: 0, canRetry: false });
await expect(
recoverLegacyGhostPlugins(
{ mode: 'cloud', dataOwnerId: ownerId, user: { id: ownerId } },
@@ -575,11 +571,7 @@ describe('legacy Ghost plugin recovery', () => {
{ mode: 'cloud', dataOwnerId: ownerId, user: { id: ownerId } },
root,
),
- ).toEqual({
- state: 'partial',
- legacyPluginCount: 1,
- canRetry: false,
- });
+ ).toEqual({ state: 'none', legacyPluginCount: 0, canRetry: false });
await expect(
recoverLegacyGhostPlugins(
{ mode: 'cloud', dataOwnerId: ownerId, user: { id: ownerId } },
@@ -630,11 +622,7 @@ describe('legacy Ghost plugin recovery', () => {
false,
{ reservedCommands: new Set(['draw']) },
),
- ).toEqual({
- state: 'partial',
- legacyPluginCount: 1,
- canRetry: false,
- });
+ ).toEqual({ state: 'none', legacyPluginCount: 0, canRetry: false });
});
it('ignores tombstones from a foreign shared root during recovery planning', async () => {
@@ -667,10 +655,19 @@ describe('legacy Ghost plugin recovery', () => {
realFsDeps(root),
{ rejectReservedIds: true },
),
- ).resolves.toMatchObject({ status: 'partial', moved: 0, conflicts: 1 });
+ ).resolves.toEqual({ status: 'skipped', moved: 0, conflicts: 0 });
+ expect(
+ getLegacyGhostRecoveryStatus(
+ { mode: 'cloud', dataOwnerId: ownerId, user: { id: ownerId } },
+ root,
+ false,
+ { rejectReservedIds: true },
+ ),
+ ).toEqual({ state: 'none', legacyPluginCount: 0, canRetry: false });
await expect(
fs.readFile(path.join(root, 'brain', 'cindy-untrusted', 'ghost.json'), 'utf-8'),
).resolves.toContain('"id":"cindy-untrusted"');
+ await expect(fs.access(path.join(root, __testing.CLAIM_MARKER))).rejects.toThrow();
});
it('moves builtin provisioning state with plugins before reconciliation', async () => {
@@ -736,11 +733,7 @@ describe('legacy Ghost plugin recovery', () => {
{ mode: 'cloud', dataOwnerId: ownerId, user: { id: ownerId } },
root,
),
- ).toEqual({
- state: 'partial',
- legacyPluginCount: 1,
- canRetry: false,
- });
+ ).toEqual({ state: 'none', legacyPluginCount: 0, canRetry: false });
await expect(
recoverLegacyGhostPlugins(
{ mode: 'cloud', dataOwnerId: ownerId, user: { id: ownerId } },
@@ -1033,11 +1026,7 @@ describe('legacy Ghost plugin recovery', () => {
);
expect(result).toMatchObject({ status: 'partial', moved: 0, conflicts: 1 });
- expect(status).toEqual({
- state: 'partial',
- legacyPluginCount: 1,
- canRetry: false,
- });
+ expect(status).toEqual({ state: 'none', legacyPluginCount: 0, canRetry: false });
await expect(fs.readFile(path.join(target, 'ghost.json'), 'utf-8')).resolves.toBe('scoped');
await expect(
fs.readFile(path.join(root, 'cindy-brain', 'valid-plugin', 'ghost.json'), 'utf-8'),
@@ -1162,11 +1151,7 @@ describe('legacy Ghost plugin recovery', () => {
{ mode: 'cloud', dataOwnerId: ownerId, user: { id: ownerId } },
root,
),
- ).toEqual({
- state: 'partial',
- legacyPluginCount: 1,
- canRetry: false,
- });
+ ).toEqual({ state: 'none', legacyPluginCount: 0, canRetry: false });
await expect(
recoverLegacyGhostPlugins(
@@ -1222,11 +1207,7 @@ describe('legacy Ghost plugin recovery', () => {
{},
(pid) => pid === 4242,
),
- ).toEqual({
- state: 'deferred',
- legacyPluginCount: 1,
- canRetry: false,
- });
+ ).toEqual({ state: 'none', legacyPluginCount: 0, canRetry: false });
const result = await recoverLegacyGhostPlugins(
{ mode: 'cloud', dataOwnerId: 'cloud-a', user: { id: 'cloud-a' } },
@@ -1290,7 +1271,7 @@ describe('legacy Ghost plugin recovery', () => {
expect(hasLegacyOwnerNamespaceClaim('cloud-a', root)).toBe(false);
});
- it('reports claimed-by-other-owner and never moves plugins across accounts', async () => {
+ it('ignores foreign-owned shared plugins and never moves them across accounts', async () => {
const root = await tempRoot();
await writeGhostDir(root, 'cindy-brain', 'valid-plugin');
await fs.writeFile(
@@ -1308,14 +1289,13 @@ describe('legacy Ghost plugin recovery', () => {
);
expect(result).toEqual({ status: 'claimed-by-other-owner', moved: 0, conflicts: 0 });
- expect(status).toEqual({
- state: 'claimed-by-other-owner',
- legacyPluginCount: 1,
- canRetry: false,
- });
+ expect(status).toEqual({ state: 'none', legacyPluginCount: 0, canRetry: false });
await expect(
fs.access(path.join(root, 'owners', dataOwnerStorageKey('cloud-b'), 'cindy-brain')),
).rejects.toThrow();
+ await expect(
+ fs.readFile(path.join(root, 'cindy-brain', 'valid-plugin', 'ghost.json'), 'utf-8'),
+ ).resolves.toContain('"id":"valid-plugin"');
});
it('reports retryable partial status when legacy plugins appear after a completed owner claim', async () => {
@@ -1348,11 +1328,7 @@ describe('legacy Ghost plugin recovery', () => {
{ mode: 'cloud', dataOwnerId: 'cloud-a', user: { id: 'cloud-a' } },
root,
),
- ).toEqual({
- state: 'deferred',
- legacyPluginCount: 1,
- canRetry: false,
- });
+ ).toEqual({ state: 'none', legacyPluginCount: 0, canRetry: false });
} finally {
delete process.env.XDT_PASSIVE_SHARED_USER_DATA;
}
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.ts
index c49f1e09cf..15667504eb 100644
--- a/apps/desktop/src/main/cindy-brain/index.ts
+++ b/apps/desktop/src/main/cindy-brain/index.ts
@@ -536,7 +536,10 @@ function getLegacyGhostRecoveryStatusForActiveSession(): LegacyGhostRecoveryStat
currentLegacyGhostMigrationSession(),
undefined,
isAppSessionBoundaryPending(),
- { reservedCommands: reservedBuiltinCommands },
+ {
+ reservedCommands: reservedBuiltinCommands,
+ rejectReservedIds: app.isPackaged,
+ },
);
}
diff --git a/apps/desktop/src/main/ownerNamespaceMigration.ts b/apps/desktop/src/main/ownerNamespaceMigration.ts
index 482c283990..4980414f15 100644
--- a/apps/desktop/src/main/ownerNamespaceMigration.ts
+++ b/apps/desktop/src/main/ownerNamespaceMigration.ts
@@ -286,6 +286,13 @@ interface LegacyGhostDir {
command: string | null;
}
+function filterLegacyGhostsByIdPolicy(
+ ghosts: LegacyGhostDir[],
+ rejectReservedIds: boolean,
+): LegacyGhostDir[] {
+ return rejectReservedIds ? ghosts.filter((ghost) => !isOfficialGhostId(ghost.id)) : ghosts;
+}
+
function readValidLegacyGhostDir(
dir: string,
expectedId: string,
@@ -483,7 +490,10 @@ export function getLegacyGhostRecoveryStatus(
session: MigrationSessionState,
userDataDir?: string,
boundaryPending = false,
- options: { reservedCommands?: ReadonlySet<string> } = {},
+ options: {
+ reservedCommands?: ReadonlySet<string>;
+ rejectReservedIds?: boolean;
+ } = {},
isPidAlive: (pid: number) => boolean = isPidAliveDefault,
): LegacyGhostRecoveryStatus {
if (boundaryPending || session.mode !== 'cloud' || !session.dataOwnerId || !session.user) {
@@ -493,14 +503,15 @@ export function getLegacyGhostRecoveryStatus(
const root = userDataDir ?? app.getPath('userData');
const ownerKey = dataOwnerStorageKey(session.dataOwnerId);
- const sharedLegacyGhosts = listSharedLegacyGhostDirs(root);
- const scopedLegacyGhosts = listOwnerScopedLegacyGhostDirs(root, ownerKey);
- const legacyGhosts = [...sharedLegacyGhosts, ...scopedLegacyGhosts];
- const legacyPluginCount = legacyGhosts.length;
- if (legacyPluginCount === 0) return NO_LEGACY_GHOST_RECOVERY;
- if (process.env.XDT_PASSIVE_SHARED_USER_DATA === '1') {
- return { state: 'deferred', legacyPluginCount, canRetry: false };
- }
+ const rejectReservedIds = options.rejectReservedIds === true;
+ const sharedLegacyGhosts = filterLegacyGhostsByIdPolicy(
+ listSharedLegacyGhostDirs(root),
+ rejectReservedIds,
+ );
+ const scopedLegacyGhosts = filterLegacyGhostsByIdPolicy(
+ listOwnerScopedLegacyGhostDirs(root, ownerKey),
+ rejectReservedIds,
+ );
const markerRead = readMarkerSync(root);
const sharedRecoveryBlocked =
@@ -508,19 +519,25 @@ export function getLegacyGhostRecoveryStatus(
(markerRead.invalid ||
(markerRead.marker !== null && markerRead.marker.ownerKey !== ownerKey));
if (sharedRecoveryBlocked && scopedLegacyGhosts.length === 0) {
- if (markerRead.marker && markerRead.marker.ownerKey !== ownerKey) {
- return { state: 'claimed-by-other-owner', legacyPluginCount, canRetry: false };
- }
- return { state: 'partial', legacyPluginCount, canRetry: false };
+ // 无法证明属于当前账号的共享目录不是当前账号的恢复任务:保留原文件,
+ // 但不向 Renderer 暴露数量,也不展示一个用户无法处理的永久状态。
+ return NO_LEGACY_GHOST_RECOVERY;
+ }
+ const eligibleLegacyGhosts = sharedRecoveryBlocked
+ ? scopedLegacyGhosts
+ : [...sharedLegacyGhosts, ...scopedLegacyGhosts];
+ const legacyPluginCount = eligibleLegacyGhosts.length;
+ if (legacyPluginCount === 0) return NO_LEGACY_GHOST_RECOVERY;
+ if (process.env.XDT_PASSIVE_SHARED_USER_DATA === '1') {
+ return NO_LEGACY_GHOST_RECOVERY;
}
if (hasConcurrentLiveInstanceSync(root, isPidAlive)) {
- return { state: 'deferred', legacyPluginCount, canRetry: false };
+ return NO_LEGACY_GHOST_RECOVERY;
}
- const eligibleLegacyGhosts = sharedRecoveryBlocked ? scopedLegacyGhosts : legacyGhosts;
const targetRoot = path.join(root, 'owners', ownerKey, 'cindy-brain');
if (!hasSafeRecoveryTargetChainSync(root, targetRoot)) {
- return { state: 'partial', legacyPluginCount, canRetry: false };
+ return NO_LEGACY_GHOST_RECOVERY;
}
const occupiedCommands = new Set(
listLegacyGhostDirsInRoots([targetRoot])
@@ -542,15 +559,7 @@ export function getLegacyGhostRecoveryStatus(
return command === null || !occupiedCommands.has(command);
});
if (!canRetry) {
- if (
- sharedRecoveryBlocked &&
- markerRead.marker &&
- markerRead.marker.ownerKey !== ownerKey &&
- scopedLegacyGhosts.length === 0
- ) {
- return { state: 'claimed-by-other-owner', legacyPluginCount, canRetry: false };
- }
- return { state: 'partial', legacyPluginCount, canRetry: false };
+ return NO_LEGACY_GHOST_RECOVERY;
}
const marker = markerRead.marker;
@@ -577,8 +586,15 @@ export async function recoverLegacyGhostPlugins(
const userDataDir = deps.userDataDir();
const ownerKey = dataOwnerStorageKey(ownerId);
const markerPath = path.join(userDataDir, CLAIM_MARKER);
- const sharedLegacyGhosts = listSharedLegacyGhostDirs(userDataDir);
- const scopedLegacyGhosts = listOwnerScopedLegacyGhostDirs(userDataDir, ownerKey);
+ const rejectReservedIds = options.rejectReservedIds === true;
+ const sharedLegacyGhosts = filterLegacyGhostsByIdPolicy(
+ listSharedLegacyGhostDirs(userDataDir),
+ rejectReservedIds,
+ );
+ const scopedLegacyGhosts = filterLegacyGhostsByIdPolicy(
+ listOwnerScopedLegacyGhostDirs(userDataDir, ownerKey),
+ rejectReservedIds,
+ );
let marker: ClaimMarker | null = null;
let eligibleSharedGhosts = sharedLegacyGhosts;
let sharedRecoveryBlocked = false;
@@ -616,10 +632,6 @@ export async function recoverLegacyGhostPlugins(
let movableLegacyGhosts: ReturnType<typeof listLegacyGhostDirs> = [];
let conflicts = sharedRecoveryBlocked ? sharedLegacyGhosts.length : 0;
for (const legacy of [...eligibleSharedGhosts, ...scopedLegacyGhosts]) {
- if (options.rejectReservedIds && isOfficialGhostId(legacy.id)) {
- conflicts += 1;
- continue;
- }
if ((await pathType(deps, path.join(targetRoot, legacy.id))) === 'missing') {
movableLegacyGhosts.push(legacy);
} else {