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(plugins): bind picked task roots and reject duplicate consent prompts

Dash4ae5efabbb62
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/ghostInstallConsentWindowBridge.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/ghostInstallConsentWindowBridge.test.ts
index 8316e57bee..3c01e1ce1c 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/ghostInstallConsentWindowBridge.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/ghostInstallConsentWindowBridge.test.ts
@@ -29,6 +29,24 @@ function target(id: number, delivered = true) {
}
describe('GhostInstallConsentWindowBridge', () => {
+ it.each(['allow', 'deny', 'close', 'account'] as const)('does not queue duplicate task capability prompts across %s', async outcome => {
+ const bridge = new GhostInstallConsentWindowBridge();
+ const window = target(7);
+ const request = {...REQUEST, purpose: 'task-capability' as const};
+ const first = bridge.request(window.target, request);
+ const duplicates = await Promise.all(Array.from({length: 20}, () => bridge.request(window.target, request)));
+ expect(duplicates).toEqual(Array(20).fill(false));
+ expect(window.sent).toHaveLength(1);
+ if (outcome === 'close') bridge.cancelRequester(7);
+ else if (outcome === 'account') bridge.cancelAll();
+ else bridge.resolve(7, window.sent[0]!.requestId, outcome === 'allow');
+ expect(await first).toBe(outcome === 'allow');
+ expect(bridge.pendingCount).toBe(0);
+ const next = bridge.request(window.target, request);
+ expect(window.sent).toHaveLength(2);
+ bridge.resolve(7, window.sent[1]!.requestId, false);
+ expect(await next).toBe(false);
+ });
it('only accepts the answer from the window that started the install', async () => {
const bridge = new GhostInstallConsentWindowBridge();
const window = target(7);
diff --git a/apps/desktop/src/main/cindy-brain/ghostInstallConsentWindowBridge.ts b/apps/desktop/src/main/cindy-brain/ghostInstallConsentWindowBridge.ts
index 177168f3c4..030400415a 100644
--- a/apps/desktop/src/main/cindy-brain/ghostInstallConsentWindowBridge.ts
+++ b/apps/desktop/src/main/cindy-brain/ghostInstallConsentWindowBridge.ts
@@ -23,6 +23,7 @@ export interface GhostInstallConsentWindowTarget {
interface PendingConsent {
target: GhostInstallConsentWindowTarget;
+ taskCapabilityPluginId?: string;
resolve: (confirmed: boolean) => void;
timeoutId: ReturnType<typeof setTimeout>;
}
@@ -36,13 +37,19 @@ export class GhostInstallConsentWindowBridge {
target: GhostInstallConsentWindowTarget,
request: Omit<GhostInstallConsentRequest, 'requestId'>,
): Promise<boolean> {
+ const taskCapabilityPluginId = request.purpose === 'task-capability' ? request.facts.ghostId : undefined;
+ // Reuse the existing pending-dialog owner. Concurrent capability attempts
+ // fail closed instead of queuing more prompts or sharing another call's grant.
+ if (taskCapabilityPluginId && [...this.pending.values()].some(
+ pending => pending.taskCapabilityPluginId === taskCapabilityPluginId,
+ )) return Promise.resolve(false);
const requestId = randomUUID();
return new Promise<boolean>((resolve, reject) => {
const timeoutId = setTimeout(
() => this.settle(requestId, false),
this.deps.timeoutMs ?? HOST_CONFIRM_TIMEOUT_MS,
);
- this.pending.set(requestId, { target, resolve, timeoutId });
+ this.pending.set(requestId, { target, resolve, timeoutId, taskCapabilityPluginId });
let delivered = false;
try {
delivered = target.send({ ...request, requestId });
diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.ts
index eafe647ac4..8708279b01 100644
--- a/apps/desktop/src/main/cindy-brain/index.ts
+++ b/apps/desktop/src/main/cindy-brain/index.ts
@@ -3215,7 +3215,8 @@ export function getGhostPickSlot(): GhostPickSlot {
properties: ['openDirectory', 'createDirectory'],
});
if (result.canceled || result.filePaths.length === 0) return null;
- return result.filePaths[0];
+ // Record and return the selected target, never a retargetable alias.
+ return fs.promises.realpath(result.filePaths[0]);
},
// userGranted=true 的授权事实 = 用户刚在系统对话框里亲手选中了这个目录
// (与确认卡点允许同强度;dirDeposit 注释的授权语义包含本通道)。
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/pluginWorkerDirectory.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/pluginWorkerDirectory.test.ts
index 07ee4ad07f..3fd662ddb1 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/pluginWorkerDirectory.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/pluginWorkerDirectory.test.ts
@@ -7,6 +7,19 @@ import { resolvePluginWorkerDirectory } from '../pluginWorkerDirectory.js';
describe('plugin Worker directory authorization', () => {
const roots: string[] = [];
afterEach(async () => { await Promise.all(roots.splice(0).map(root => rm(root,{recursive:true,force:true}))); });
+ it('binds picked grants to the selected real target, not a replaceable alias', async () => {
+ const root = await realpath(await mkdtemp(path.join(os.tmpdir(), 'plugin-picked-'))); roots.push(root);
+ const selected = path.join(root, 'selected'), other = path.join(root, 'other'), alias = path.join(root, 'alias');
+ await mkdir(selected); await mkdir(other); await mkdir(path.join(selected, 'child'));
+ await symlink(selected, alias, 'junction');
+ const input = {requested: alias, isPickedDirectory: (dir: string) => dir === selected, assertCurrent: () => {}};
+ expect(await resolvePluginWorkerDirectory(input)).toBe(selected);
+ await expect(resolvePluginWorkerDirectory({...input, requested: path.join(selected, 'child')})).rejects.toMatchObject({code: 'PERMISSION_DENIED'});
+ await rm(alias); await symlink(other, alias, 'junction');
+ await expect(resolvePluginWorkerDirectory(input)).rejects.toMatchObject({code: 'PERMISSION_DENIED'});
+ // Legacy alias-only records cannot prove the originally selected target.
+ await expect(resolvePluginWorkerDirectory({...input, isPickedDirectory: dir => dir === alias})).rejects.toMatchObject({code: 'PERMISSION_DENIED'});
+ });
it('allows the task and its real children, configured or picked roots, without granting Library', async () => {
const root = await realpath(await mkdtemp(path.join(os.tmpdir(),'plugin-dirs-'))); roots.push(root);
const dirs = ['task','task/child','task-other','configured','picked','library'];
diff --git a/apps/desktop/src/main/maker-ipc/pluginWorkerDirectory.ts b/apps/desktop/src/main/maker-ipc/pluginWorkerDirectory.ts
index dd61c84625..fcc21488e5 100644
--- a/apps/desktop/src/main/maker-ipc/pluginWorkerDirectory.ts
+++ b/apps/desktop/src/main/maker-ipc/pluginWorkerDirectory.ts
@@ -23,7 +23,7 @@ export async function resolvePluginWorkerDirectory(input: {
allowed = isPathInsideDir(configured, resolved) && isPathInsideDir(resolved, configured);
}
// Pick grants are exact-directory grants, not permission for an arbitrary Library root.
- if (!allowed) allowed = input.isPickedDirectory(resolved) || input.isPickedDirectory(input.requested);
+ if (!allowed) allowed = input.isPickedDirectory(resolved);
input.assertCurrent();
if (!allowed) throw deny();
return resolved;