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): freeze delegated scopes and retain input authorship

Dash90e763998958
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
index a1aeddfee7..d82753f3d0 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
@@ -11237,6 +11237,24 @@ describe('AgentInputCoordinator replaceQueuedMessage(Orca lead 排队消息修
},
);
+ it('preserves empty plugin authorship receipts through queue snapshots and dispatch', async () => {
+ const h = createHarness();
+ const sid = 'plugin-empty-authorship';
+ await h.coordinator.ensureQueueRestored(sid);
+ h.setRunning(true);
+ h.coordinator.enqueue(sid, { ...makeItem('plugin-input', 'Plugin task'), autoReviewUserText: '' });
+ await flush();
+ const snapshot = JSON.parse(JSON.stringify(h.persistQueueSnapshot.mock.calls.at(-1)?.[1] ?? []));
+ expect(snapshot[0]).toMatchObject({ autoReviewUserText: '' });
+ const restarted = createHarness();
+ restarted.setLoadQueueSnapshot(async () => snapshot);
+ await restarted.coordinator.ensureQueueRestored(sid);
+ expect(restarted.coordinator.getQueueControlSnapshot(sid).pendingQueue[0]).toMatchObject({ autoReviewUserText: '' });
+ restarted.coordinator.enqueue(sid, makeItem('resume-input', 'Continue'), { resumeRestorePausedQueue: true });
+ await flush();
+ expect(restarted.sendToAgent.mock.calls[0]?.[3][AUTO_REVIEW_SOURCE_CONTENT]).toBe('');
+ });
+
it('编辑保留主机接收时间,清空边界后的条目崩溃恢复时不会被误删', async () => {
const h = createHarness();
const sid = 'replace-after-clear';
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
index 4b1946beb9..9ac0d98896 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
@@ -2585,6 +2585,18 @@ describe('session-agent-switch handoff injection', () => {
});
});
+ it('persists empty plugin authorship rather than promoting plugin instructions', async () => {
+ const { deps } = createDeps();
+ await createMakerSendTransaction(deps).sendToAgentAccepted('session-1', 'Plugin instructions', undefined, {
+ [AUTO_REVIEW_SOURCE_CONTENT]: '',
+ persistUserMessage: { clientId: 'plugin-input', content: 'Plugin instructions', delivery: 'turn' },
+ });
+ expect(deps.createDbMessage).toHaveBeenCalledWith('session-1', expect.objectContaining({
+ clientId: 'plugin-input',
+ agentMeta: expect.objectContaining({ autoReviewUserText: '', delivery: 'turn' }),
+ }), undefined);
+ });
+
it.each(['Earlier authorization; do not deploy.', ''])('preserves restored intent for wire-only recovery: %s', async (intent) => {
const { deps, session } = createDeps();
await createMakerSendTransaction(deps).sendToAgentAccepted('session-1', 'Internal continuation', undefined, {
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskAuthorshipWiring.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskAuthorshipWiring.test.ts
new file mode 100644
index 0000000000..5861cb8b7a
--- /dev/null
+++ b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskAuthorshipWiring.test.ts
@@ -0,0 +1,46 @@
+import { readFileSync } from 'node:fs';
+import { resolve } from 'node:path';
+import ts from 'typescript';
+import { expect, it, vi } from 'vitest';
+
+const source = readFileSync(resolve(__dirname, '..', 'register.ts'), 'utf8');
+const compile = (code: string) => ts.transpileModule(code, {
+ compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.None },
+}).outputText;
+
+it('marks plugin dispatch and every queue fallback with the host-only receipt', () => {
+ const start = source.indexOf('async function sendToSessionInternal(params: {');
+ const end = source.indexOf('const startOrcaTeamForCaller', start);
+ const dispatch = source.slice(start, end);
+ expect(dispatch).toContain("message: text, autoReviewUserText: '', forceQueue: true");
+ const queues = [...dispatch.matchAll(/await enqueueSendToSessionMessage\(\{([\s\S]*?)\}\);/g)];
+ expect(queues).toHaveLength(4);
+ for (const call of queues) expect(call[1]).toContain('autoReviewUserText: params.autoReviewUserText');
+ // Both newly created and resumed direct tasks persist the same authored metadata.
+ expect(dispatch.match(/agentMeta: inputAgentMeta/g)).toHaveLength(2);
+});
+
+it('keeps empty receipts distinct from missing authorship on direct persistence', () => {
+ const start = source.indexOf('const inputAgentMeta: AgentMeta');
+ const end = source.indexOf(' if (!message)', start);
+ expect(start).toBeGreaterThan(0);
+ const build = new Function('params', 'queuedOrigin', compile(source.slice(start, end) + '\nreturn inputAgentMeta;'));
+ expect(build({ autoReviewUserText: '' }, undefined)).toEqual({ autoReviewUserText: '', delivery: 'turn' });
+ expect(build({}, undefined)).toBeUndefined();
+ expect(build({ autoReviewUserText: '' }, { kind: 'orca' })).toMatchObject({ origin: { kind: 'orca' }, autoReviewUserText: '' });
+});
+
+it('builds a durable queued plugin input without promoting plugin text to user intent', async () => {
+ const start = source.indexOf(' async function buildSessionControlInputItem(params: {');
+ const end = source.indexOf(' const orcaInterAgentDispatcher:', start);
+ expect(start).toBeGreaterThan(0);
+ const createOpts = { model: 'm', effort: 'high', permissionMode: 'auto', workingDir: '/answer' };
+ const build = new Function('buildCreateOptsForQueuedSession', 'permissionModeOrAsk',
+ compile(source.slice(start, end) + '\nreturn buildSessionControlInputItem;'))(
+ vi.fn(async () => createOpts), (mode: string) => mode,
+ );
+ const base = { targetSessionId: 'lead', clientId: 'plugin-input', message: 'Plugin instructions', persistedContent: 'Plugin instructions', meta: {} };
+ const queued = JSON.parse(JSON.stringify(await build({ ...base, autoReviewUserText: '' })));
+ expect(queued).toMatchObject({ text: base.message, persistedContent: base.persistedContent, autoReviewUserText: '', permissionMode: 'auto' });
+ expect(await build(base)).not.toHaveProperty('autoReviewUserText');
+});
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskService.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskService.test.ts
index 61cd131c70..82d9f53551 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskService.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskService.test.ts
@@ -496,16 +496,23 @@ describe('current plugin dispatch authority', () => {
});
});
-it('adds missing delegation scopes once without mutating an older plan identity', async () => {
+it('keeps taskless plans immutable instead of retroactively granting scope', async () => {
const f=fixture(),task=await f.create();
const old={concurrency:2,items:[{label:'sample',workingDir:'/answer',route:f.route}]};
await f.service.setTeamPlan('p',task.taskId,old);
const scoped={...old,task:'Coordinate',items:[{...old.items[0]!,task:'Run tests'}]};
- await f.service.setTeamPlan('p',task.taskId,scoped);
- await f.service.setTeamPlan('p',task.taskId,scoped);
- expect(JSON.parse(f.rows.get(task.taskId)!.payload).teamPlan).toEqual(scoped);
- await expect(f.service.setTeamPlan('p',task.taskId,{...scoped,task:'Publish'})).rejects.toThrow('immutable');
- await expect(f.service.setTeamPlan('p',task.taskId,{...scoped,items:[{...scoped.items[0]!,task:'Publish'}]})).rejects.toThrow('immutable');
- await expect(f.service.setTeamPlan('p',task.taskId,old)).rejects.toThrow('immutable');
+ await expect(f.service.setTeamPlan('p',task.taskId,scoped)).rejects.toThrow('immutable');
+ await f.send();
+ await expect(f.service.setTeamPlan('p',task.taskId,scoped)).rejects.toThrow('immutable');
+ await f.service.setTeamPlan('p',task.taskId,old);
+ expect(JSON.parse(f.rows.get(task.taskId)!.payload).teamPlan).toEqual(old);
+});
+it('registers a complete scope once and permits only identical replays', async () => {
+ const f=fixture(),task=await f.create();
+ const plan={concurrency:2,task:'Coordinate',items:[{label:'sample',workingDir:'/answer',route:f.route,task:'Run tests'}]};
+ await f.service.setTeamPlan('p',task.taskId,plan);
+ await f.service.setTeamPlan('p',task.taskId,plan);
+ await expect(f.service.setTeamPlan('p',task.taskId,{...plan,task:'Publish'})).rejects.toThrow('immutable');
+ await expect(f.service.setTeamPlan('p',task.taskId,{...plan,items:[{...plan.items[0]!,task:'Publish'}]})).rejects.toThrow('immutable');
});
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 065374af07..c5f9095ba3 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -8891,6 +8891,8 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
onAcceptedRollback?: () => void | Promise<void>;
onAcceptedCommit?: () => void | Promise<void>;
origin?: AgentInputQueuedMessage['origin'];
+ /** Host-only receipt: plugin-authored input is not user-authored permission. */
+ autoReviewUserText?: '';
authorizationGuard?: BotAuthorizationInputGuard;
createDefaults?: SendToSessionCreateDefaults;
/** 安全调用方可要求新会话不比来源会话拥有更高的权限。 */
@@ -8921,6 +8923,14 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
message,
explicitOrigin: origin,
});
+ const inputAgentMeta: AgentMeta | undefined = queuedOrigin || params.autoReviewUserText !== undefined
+ ? {
+ ...(queuedOrigin ? { origin: queuedOrigin } : {}),
+ ...(params.autoReviewUserText !== undefined
+ ? { autoReviewUserText: params.autoReviewUserText, delivery: 'turn' as const }
+ : {}),
+ } as AgentMeta
+ : undefined;
if (!message) {
return { ok: false, errorCode: 'INVALID_ARGS', message: 'message required' };
}
@@ -9137,7 +9147,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
clientId,
role: 'user',
content: persistedContent ?? message,
- ...(queuedOrigin ? { agentMeta: { origin: queuedOrigin } as AgentMeta } : {}),
+ ...(inputAgentMeta ? { agentMeta: inputAgentMeta } : {}),
});
// F4: send_to_session 的 create 分支也建了一条用户可见新会话(有 title + 落了 user
// 消息),同属"新建会话需同步所有窗侧栏"的 purpose。广播跟 user row 持久化
@@ -9267,6 +9277,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
onAcceptedRollback,
onAcceptedCommit,
origin: queuedOrigin,
+ autoReviewUserText: params.autoReviewUserText,
authorizationGuard: params.authorizationGuard,
});
return {
@@ -9301,7 +9312,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
clientId,
role: 'user',
content: persistedContent ?? message,
- ...(queuedOrigin ? { agentMeta: { origin: queuedOrigin } as AgentMeta } : {}),
+ ...(inputAgentMeta ? { agentMeta: inputAgentMeta } : {}),
});
await runAcceptedCallback(onAccepted, targetSessionId, clientId);
};
@@ -9330,6 +9341,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
onAcceptedRollback,
onAcceptedCommit,
origin: queuedOrigin,
+ autoReviewUserText: params.autoReviewUserText,
});
return {
ok: true as const,
@@ -9453,6 +9465,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
onAcceptedRollback,
onAcceptedCommit,
origin: queuedOrigin,
+ autoReviewUserText: params.autoReviewUserText,
});
return {
ok: true as const,
@@ -9562,6 +9575,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
onAcceptedRollback,
onAcceptedCommit,
origin: queuedOrigin,
+ autoReviewUserText: params.autoReviewUserText,
});
return {
ok: true as const,
@@ -10219,7 +10233,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
},
dispatch: async (pluginId, taskId, clientId, text) => {
assertPlugin(pluginId);
- const outcome = await sendToSessionInternal({ targetSessionId: taskId, clientId, message: text, forceQueue: true, onAccepted: async () => { assertPlugin(pluginId); await pluginTaskServiceForCurrentOwner!().assertDispatch(pluginId, taskId); assertPlugin(pluginId); } });
+ const outcome = await sendToSessionInternal({ targetSessionId: taskId, clientId, message: text, autoReviewUserText: '', forceQueue: true, onAccepted: async () => { assertPlugin(pluginId); await pluginTaskServiceForCurrentOwner!().assertDispatch(pluginId, taskId); assertPlugin(pluginId); } });
await awaitAgentInputQueueSnapshotPersistence(taskId);
assertCurrent();
return outcome;
@@ -10761,6 +10775,8 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
onAcceptedRollback?: SchedulerQueuedPromptRequest['onAcceptedRollback'];
onAcceptedCommit?: () => void | Promise<void>;
origin?: AgentInputQueuedMessage['origin'];
+ /** Host-only receipt: plugin-authored input is not user-authored permission. */
+ autoReviewUserText?: '';
authorizationGuard?: BotAuthorizationInputGuard;
}): Promise<void> {
const queued = await buildSessionControlInputItem(params);
@@ -10800,6 +10816,8 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
meta: NonNullable<Awaited<ReturnType<typeof maker.getSessionMeta>>>;
files?: AgentInputQueuedMessage['files'];
origin?: AgentInputQueuedMessage['origin'];
+ /** Host-only receipt: plugin-authored input is not user-authored permission. */
+ autoReviewUserText?: '';
toolsDisabled?: boolean;
}): Promise<AgentInputQueuedMessage> {
const createOpts = await buildCreateOptsForQueuedSession(params.targetSessionId, params.meta, params.inheritTargetPlanMode);
@@ -10834,6 +10852,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
return {
clientId: params.clientId,
text: params.message,
+ ...(params.autoReviewUserText !== undefined ? { autoReviewUserText: params.autoReviewUserText } : {}),
...(params.toolsDisabled === true ? { toolsDisabled: true } : {}),
persistedContent,
model: createOpts.model,
diff --git a/docs/dev-rules/plugin-task-api-implementation.md b/docs/dev-rules/plugin-task-api-implementation.md
index d6a554edba..49fb726d2b 100644
--- a/docs/dev-rules/plugin-task-api-implementation.md
+++ b/docs/dev-rules/plugin-task-api-implementation.md
@@ -71,8 +71,9 @@ getTeam 的 completedAt 可由宿主落盘的 turnCompleted 终态恢复:仅
### 委派范围与 Auto 审阅
计划的顶层 `task` 及每项 `task` 是可选的插件原始任务说明,最多 8000 字符。
-Host 只接受经绑定插件身份写入的自有创建收据;允许旧计划一次补齐缺失范围,不允许重写
-已有范围或改变执行身份。没有新增权限档位、没有提升到 Full access。
+Host 只接受经绑定插件身份写入的自有创建收据;已登记计划整体不可变,包括原本缺失的范围。
+旧计划缺少范围时沿用原审批行为,不事后补造授权;新范围须在新任务中登记完整计划。
+没有新增权限档位、没有提升到 Full access。
审批在查询缓存前重新核对插件批准版本、启用状态、Auto 设置、账号 epoch、任务状态、
团队归属和计划匹配;异步结果返回前再次核对。真实用户限制来自 Host 保存的作者凭据,