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): 按有效目录核验委派计划身份

Dash70f139dfaa71
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskReviewContext.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskReviewContext.test.ts
index 9b60d86e61..96b6e9b89c 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskReviewContext.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskReviewContext.test.ts
@@ -1,3 +1,6 @@
+import { mkdtemp, mkdir, realpath, rm, symlink } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
import { describe, it, expect } from 'vitest';
import type { AutoReviewRequest } from '@cindy/maker-core';
import {
@@ -209,3 +212,29 @@ it.each([false, true])('marks tied user grant/revocation as incomplete regardles
expect(result.userIntent).toMatchObject({historyOmitted: true});
expect(JSON.stringify(result.userIntent)).toContain('Do not write');
});
+
+it('accepts a plan alias only while it resolves to the stored Worker directory', async () => {
+ const root = await mkdtemp(join(tmpdir(), 'plugin-review-path-'));
+ try {
+ const target = join(root, 'target'), other = join(root, 'other'), alias = join(root, 'alias');
+ await mkdir(target); await mkdir(other);
+ await symlink(target, alias, 'junction');
+ const s = fixture();
+ s.plan!.items[0]!.workingDir = alias;
+ s.session.workingDir = await realpath(target);
+ const r = {...request, workspaceRoots: [s.session.workingDir]};
+ const resolve = createPluginTaskReviewResolver(async () => s);
+ expect((await resolve(r)).delegatedTask?.workingDir).toBe(s.session.workingDir);
+ await rm(alias);
+ await symlink(other, alias, 'junction');
+ expect((await resolve(r)).authorizationError).toBeTruthy();
+ await rm(alias);
+ expect((await resolve(r)).authorizationError).toBeTruthy();
+ s.plan!.items[0]!.workingDir = join(target, '..', 'target');
+ expect((await resolve(r)).authorizationError).toBeUndefined();
+ s.authorized = false;
+ expect((await resolve(r)).authorizationError).toBeTruthy();
+ } finally {
+ await rm(root, {recursive: true, force: true});
+ }
+});
diff --git a/apps/desktop/src/main/maker-ipc/pluginTaskReviewContext.ts b/apps/desktop/src/main/maker-ipc/pluginTaskReviewContext.ts
index 18d5824a10..c71c2da478 100644
--- a/apps/desktop/src/main/maker-ipc/pluginTaskReviewContext.ts
+++ b/apps/desktop/src/main/maker-ipc/pluginTaskReviewContext.ts
@@ -1,4 +1,5 @@
import { createHash } from 'node:crypto';
+import { realpath } from 'node:fs/promises';
import {
appendAutoReviewUserIntent,
type AutoReviewRequest,
@@ -110,6 +111,16 @@ export function createPluginTaskReviewResolver(
? plan?.items.find((x) => x.label === snapshot.worker!.label)
: undefined;
const task = snapshot.worker ? item?.task : plan?.task;
+ // Worker creation stores a canonical local directory. Compare aliases to
+ // that same identity, never broaden the plan to a parent or a new root.
+ let directoryMatches = item?.workingDir === snapshot.session.workingDir;
+ if (snapshot.worker && item && !directoryMatches) {
+ try {
+ directoryMatches = await realpath(item.workingDir) === snapshot.session.workingDir;
+ } catch {
+ directoryMatches = false;
+ }
+ }
if (!snapshot.worker && task && (!snapshot.registeredRoute ||
(['agentKind', 'providerId', 'model', 'effort', 'fastMode'] as const).some(
k => snapshot.registeredRoute![k] !== snapshot.session.route[k],
@@ -119,7 +130,7 @@ export function createPluginTaskReviewResolver(
(!snapshot.worker.activeTeam ||
!item ||
snapshot.settledLabels?.includes(snapshot.worker.label) ||
- item.workingDir !== snapshot.session.workingDir ||
+ !directoryMatches ||
(Object.keys(item.route) as Array<keyof PluginTaskRoute>).some(
(k) => item.route[k] !== snapshot.session.route[k],
))