Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
merge: 同步父任务运行时的撤权历史边界修复
Dashf30fa8ca5354
diff --cc apps/desktop/src/main/cindy-brain/forge.tsindex c5393a0cce,06f56e447f..2251333d67--- a/apps/desktop/src/main/cindy-brain/forge.ts+++ b/apps/desktop/src/main/cindy-brain/forge.ts@@@ -3911,13 -3911,8 +3911,13 @@@ const r = await cindy.agent.requestSche先调用 \`capabilities()\` 获取实际支持操作。当前仅支持本插件创建的本机普通任务:\`create\`、\`get\`、\`list\`、\`send\`、\`getRun\`、\`listRuns\`、\`readMessages\`、\`cancel\`。可对自有任务调用 \`startTeam({taskId})\` 启用 Orca 主任务,并用 \`getTeam({taskId})\` 读取实际协同状态。协调主任务需经用户授权 Auto,Worker 自动沿用 Auto。- 这些任务及其 Worker 不提供 \`cindy_helper\` 的账号级历史或跨任务控制能力,\`cindy_memory.session_search\` 也拒绝历史检索;协调使用独立 Orca 工具,结果由插件通过 \`readMessages/getTeam\` 读取。旧 errand/workspace 不因来源标记受到限制;明确卸载撤销归属后,保留的用户任务恢复普通 helper 与历史检索能力。这不构成通用执行沙箱。+ 这些任务及其 Worker 不提供 \`cindy_helper\` 的账号级历史或跨任务控制能力,\`cindy_memory.session_search\` 也拒绝历史检索;协调使用独立 Orca 工具,结果由插件通过 \`readMessages/getTeam\` 读取。旧 errand/workspace 不因来源标记受到限制;明确卸载撤销归属后,调用方已无正在执行的输入或已接受新真人输入时,保留的用户任务恢复普通 helper 与历史检索能力;仍执行旧插件输入时继续受限,自动回报和插件输入重试不构成真人接管。这不恢复插件控制权,也不保证停止已接受执行,不构成通用执行沙箱。-在首次派发前调用 \`setTeamPlan({taskId,plan:{concurrency,items}})\`,每项包含\`label, workingDir, route\`。计划冻结后不可改写。+在首次派发前调用 \`setTeamPlan({taskId,plan:{concurrency,task,items}})\`,每项包含+\`label, workingDir, route, task\`。可选 \`task\` 是插件提供的工作范围(每段最多 8000 字符),+不是用户原话。Host 核对已批准启用的插件、自有主任务、真实 Worker 归属、模型和目录后,+将范围单独交给 Auto 审阅;仍逐动作审批,用户限制、撤权和只读设置始终优先。+计划须在首次派发或创建 Worker 前登记,之后不可改写(包括补填 task);需要不同范围时创建新任务。+缺少该字段的存量计划继续可读,但不允许插件任务自动授权或普通 MCP 快捷放行,不会从 Agent 消息推导额外授权;Ask/acceptEdits 仍可沿原流程逐次确认。计划不授予目录权限。Worker 仅可使用宿主任务目录及解析后仍在其中的子目录、插件 AI 配置目录或用户亲选的确切目录;Library 绑定不自动变成 Agent 工作根。宿主在登记和创建时均复核。这描述准入检查,不是持续的 OS 目录隔离保证。首版用于可信本地工作区;同权限进程在检查后恶意置换目录对象仍可能改变实际 cwd,不提供此类对抗性沙箱。diff --cc apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.tsindex c34e5b08ff,3f40a1b59e..e962a8ddff--- 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@@@ -1,8 -1,6 +1,9 @@@import { AUTO_REVIEW_SOURCE_CONTENT, AUTO_REVIEW_USER_INTENT, appendAutoReviewUserIntent } from '@cindy/maker-core';+import { AUTO_REVIEW_DELEGATED_CONTINUATION, restoreAutoReviewUserIntent, type AutoReviewHistoryMessage } from '../autoReviewUserIntent.js';+import { createPluginTaskReviewResolver, type PluginReviewSnapshot } from '../pluginTaskReviewContext.js';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { AgentInputCoordinator } from '../agent-input-coordinator.js';++import { hasAcceptedUserTaskInput } from '../pluginTaskInput.js';import { runSchedulerQueuedPreparation } from '../schedulerQueuedPreparation.js';import {createPiTranslateContext, disposePiTranslateContext, translatePiEvent,@@@ -1493,18 -1489,16 +1494,31 @@@ describe('AgentInputCoordinator send trexpect(h.coordinator.getAcceptedInputProvenance(sid)?.clientId).toBe('plugin-task:run');});+ it.each([+ { source: {kind: 'delegated-continuation'} as const, authoredText: undefined },+ { source: 'My next task', authoredText: 'My next task' },+ ])('exposes only human text as input takeover evidence: $source', async ({source, authoredText}) => {+ const h = createHarness(), sid = 'typed-input-provenance';+ h.sendToAgent.mockImplementationOnce(async () => { h.setRunning(true); return sendSuccess(); });+ h.coordinator.enqueue(sid, {...makeItem('input', 'Continue'), autoReviewUserText: source});+ await flush();+ expect(h.coordinator.getAcceptedInputProvenance(sid)).toMatchObject({clientId: 'input', authoredText});++ const db = { get drizzle(): never { throw new Error('Current Host source must not borrow older transcript'); } };++ await expect(hasAcceptedUserTaskInput(db, sid, h.coordinator.getAcceptedInputProvenance(sid)))++ .resolves.toBe(typeof source === 'string');+ expect(h.sendToAgent.mock.calls[0]?.[3][AUTO_REVIEW_DELEGATED_CONTINUATION]).toBe(typeof source === 'object' ? true : undefined);+ });++ it('keeps a Worker Lead directive distinct from accepted human input', async () => {+ const h = createHarness(), sid = 'worker-input-origin';+ h.sendToAgent.mockImplementationOnce(async () => { h.setRunning(true); return sendSuccess(); });+ h.coordinator.enqueue(sid, { ...makeItem('directive', 'Evaluate'), origin: { kind: 'orca', senderLabel: 'Lead' } });+ await flush();+ expect(h.coordinator.getAcceptedInputProvenance(sid)).toMatchObject({ clientId: 'directive', originKind: 'orca' });+ await h.coordinator.steer(sid, { ...makeItem('human', 'New direction'), autoReviewUserText: 'New direction' });+ expect(h.coordinator.getAcceptedInputProvenance(sid)).toMatchObject({ clientId: 'human', authoredText: 'New direction', originKind: undefined });+ });+it('keeps accepted plugin authority through pending and rejected human steering', async () => {const h = createHarness(), sid = 'accepted-plugin-authority';h.sendToAgent.mockImplementationOnce(async () => { h.setRunning(true); return sendSuccess(); });diff --cc apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.tsindex 5b805ff6c4,aad7b722a0..bfdf987de1--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts@@@ -2880,88 -2881,6 +2881,88 @@@ describe('production plugin Auto admissconst helper = source.slice(source.indexOf(' const assertPluginWorkerAutoAuthorized ='), source.indexOf(' const orcaWorkerCreationService ='));const callback = source.slice(source.indexOf(' validateCreationPlan: async (params, resolvedWorkingDir, resolvedRoute) => {'), source.indexOf(' getLeadSessionRow: async (leadSessionId) => {'));const js = ts.transpileModule(`${helper}\nreturn ({${callback}}).validateCreationPlan;`, { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText;+ const override = source.slice(source.indexOf(' getWorkerPermissionModeOverride: async (leadSessionId) => {'), source.indexOf(' setWorkerPermissionMode: applyWorkerPermissionModePreference,'));+ const overrideJs = ts.transpileModule(`${helper}\nreturn ({${override}}).getWorkerPermissionModeOverride;`, { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText;++ it.each([false, true].flatMap(planned => ['bootstrap', 'renewal'].flatMap(stage =>+ ['disabled', 'uninstalled', 'reinstalled', 'account', 'owner', 'missing', 'downgraded', 'plan', 'archived', 'storage', 'healthy'].map(change => ({ planned, stage, change })),+ )))('rechecks $change after $stage with planned=$planned before persistence and dispatch', async ({ planned, stage, change }) => {+ let epoch = { client: {} };+ let enabled = true, missing = false, storageFailed = false;+ const task = { revision: 1, status: 'active', permissionMode: 'auto', planModeEnabled: false, workingDir: path.resolve('repo') };+ const receipt = { pluginId: 'plugin', operation: 'create', payload: JSON.stringify(planned ? {+ teamPlan: { concurrency: 2, items: [{ label: 'sample', workingDir: task.workingDir,+ route: { agentKind: 'codex', model: 'gpt-5.5', providerId: 'xd', effort: 'medium', fastMode: false } }] },+ } : {}) };+ const callbackDeps = {+ maker: {getSession:()=>null}, inputCoordinator: { getAcceptedInputProvenance: () => null },+ readPluginTaskPlanReceipt: JSON.parse, getCurrentDbClientSnapshot: () => epoch,+ createPluginTaskStore: () => ({ get: async () => {+ if (storageFailed) throw new Error('storage unavailable');+ return missing ? null : structuredClone(receipt);+ } }),+ pluginTaskServiceForCurrentOwner: () => ({ get: async () => {+ if (JSON.parse(receipt.payload).ownershipRevoked) throw new PluginTaskError('TASK_NOT_FOUND', 'Not owned');+ return { ...task };+ } }),+ readGhostErrandConfig: () => ({ permissionMode: 'auto', workingDir: task.workingDir }),+ isPluginTaskAuthorized: () => enabled,+ resolvePluginWorkerDirectory: async () => task.workingDir,+ isGhostPickedDir: () => false, PluginTaskError,+ };+ const validateCreationPlan = new Function(...Object.keys(callbackDeps), js)(...Object.values(callbackDeps));+ const { deps, service } = createDeps({ validateCreationPlan });+ const mutate = () => {+ if (change === 'disabled') enabled = false;+ if (['uninstalled', 'reinstalled'].includes(change)) {+ receipt.payload = JSON.stringify({ ...JSON.parse(receipt.payload), ownershipRevoked: true });+ enabled = change === 'reinstalled';+ }+ if (change === 'account') epoch = { client: {} };+ if (change === 'owner') receipt.pluginId = 'other-plugin';+ if (change === 'missing') missing = true;+ if (change === 'downgraded') task.permissionMode = 'default';+ if (change === 'plan') task.planModeEnabled = true;+ if (change === 'archived') task.status = 'archived';+ if (change === 'storage') storageFailed = true;+ };+ const bootstrap = deps.bootstrapSession;+ deps.bootstrapSession = vi.fn(async opts => { const result = await bootstrap(opts); if (stage === 'bootstrap') mutate(); return result; });+ deps.renewWorkerCreationReservation = vi.fn(async () => { if (stage === 'renewal') mutate(); return true; });+ const markTeamEnded = vi.fn(async () => undefined);- const getWorkerPermissionModeOverride = new Function(...Object.keys(callbackDeps), overrideJs)(...Object.values(callbackDeps));++ const getWorkerPermissionModeOverride = new Function('hasAcceptedUserTaskInput', ...Object.keys(callbackDeps), overrideJs)(hasAcceptedUserTaskInput, ...Object.values(callbackDeps));+ const lifecycle = createOrcaLifecycleService({+ getWorkerPermissionModeOverride,+ getActiveTeamByLead: async () => planned ? null : { id: 'team-1', leadSessionId: 'lead-1' },+ createActiveTeam: async () => ({ id: 'team-1', leadSessionId: 'lead-1' }),+ isOrphanedTeamInit: async () => false, getWorkerPermissionMode: () => 'auto',+ setWorkerPermissionMode: vi.fn(), createWorkerInTeam: service.createWorkerInTeam,+ dispatchWorkerTask: deps.dispatchWorkerTask, markTeamEnded, setSessionOrcaRole: vi.fn(async () => undefined),+ clearKnownNonOrcaSession: vi.fn(), setLeadVendorOptions: vi.fn(async () => undefined), clearLeadVendorOptions: vi.fn(async () => undefined),+ sendWorkerReadyPlaceholder: vi.fn(async () => undefined), rollbackCreatedWorker: vi.fn(async () => undefined),+ broadcastSessionCreated: deps.broadcastSessionCreated, broadcastOrcaWorkerChanged: deps.broadcastOrcaWorkerChanged,+ });+ const result = planned+ ? await lifecycle.enableTeam({ leadSessionId: 'lead-1', workerAgent: 'codex', role: 'eval', label: 'sample', delegateTask: 'Evaluate sample' })+ : await lifecycle.createWorker({ leadSessionId: 'lead-1', agent: 'codex', role: 'eval', label: 'sample', initialTask: 'Evaluate sample' });+ expect(deps.bootstrapSession).toHaveBeenCalledOnce();+ expect(deps.releaseWorkerCreationReservation).toHaveBeenCalledOnce();+ if (change === 'healthy') {+ expect(result.ok).toBe(true);+ expect(deps.addOrUpdateWorker).toHaveBeenCalledOnce();+ expect(deps.dispatchWorkerTask).toHaveBeenCalledOnce();+ expect(deps.closeWorkerSession).not.toHaveBeenCalled();+ } else {+ expect(result).toMatchObject({ ok: false, errorCode: 'INTERNAL' });+ expect(deps.addOrUpdateWorker).not.toHaveBeenCalled();+ expect(deps.markOrcaRoleIfNeeded).not.toHaveBeenCalled();+ expect(deps.dispatchWorkerTask).not.toHaveBeenCalled();+ for (const cleanup of [deps.closeWorkerSession, deps.forgetWorkerSession, deps.archiveWorkerSession]) {+ expect(cleanup).toHaveBeenCalledExactlyOnceWith(WORKER_SESSION_ID);+ }+ if (planned) expect(markTeamEnded).toHaveBeenCalledExactlyOnceWith('team-1', 'failed');+ }+ });it.each(['uninstalled', 'reinstalled', 'malformed'])('keeps ordinary Worker creation separate from %s plugin receipts', async state => {const epoch = { client: {} }, get = vi.fn(async () => { throw new PluginTaskError('TASK_NOT_FOUND', 'Not owned'); });diff --cc apps/desktop/src/main/maker-ipc/agent-input-coordinator.tsindex 2ddc1e563c,4bdbc3dbd2..58b9ed0dad--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts@@@ -1115,8 -1109,8 +1115,9 @@@ export class AgentInputCoordinatorconst item = active?.item;// Native tools may arrive before sendToAgent returns its dispatch acknowledgement.if (!item) return null;- return { clientId: item.clientId, autoResume: item.autoResume, authoredText: item.autoReviewUserText,+ return { clientId: item.clientId, autoResume: item.autoResume,+ authoredText: typeof item.autoReviewUserText === 'string' ? item.autoReviewUserText : undefined,+ originKind: item.origin?.kind,retrySourceClientId: item.retrySourceClientId ?? item.supersedesUserClientId };}diff --cc apps/desktop/src/main/maker-ipc/register.tsindex 5d533fd8fd,5f52e42657..106a6e4972--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@@ -4,8 -3,9 +4,9 @@@ import { resolvePluginWorkerDirectoryimport { PluginWriteAccessGate } from './pluginWriteAccessGate.js';import { pluginWorkerCompletedAt } from './pluginWorkerCompletion.js';import { createPluginTaskStore } from './pluginTaskStore.js';+ import { hasAcceptedUserTaskInput } from './pluginTaskInput.js';import { controlOwnedSessionExecution, isSameSessionExecution, withdrawOwnedSessionInputs } from './sessionExecutionOwnership.js';-import { setPluginTaskHandler, setPluginTaskUninstaller, isPluginTaskAuthorized, getPluginTaskInstallRevision } from '../cindy-brain/index.js';+import { setPluginTaskHandler, setPluginTaskUninstaller, isPluginTaskAuthorized, getPluginTaskInstallRevision, pluginTaskAuthorizationRevision } from '../cindy-brain/index.js';import type { PluginTaskRoute, PluginTaskRequest } from '../../shared/pluginTasks.js';import { createHash as pluginTaskConfigHash } from 'node:crypto';import { finishCompanionEnvironmentRemoval } from '../bot-import/runtime.js';