Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(companions): 任务操作复用普通权限流程,避免重复授权
Dash475c52ddb533
diff --git a/apps/desktop/src/main/maker-host/mcp-tool-approval-policy.ts b/apps/desktop/src/main/maker-host/mcp-tool-approval-policy.tsindex 81300c973a..2d615cf5d5 100644--- a/apps/desktop/src/main/maker-host/mcp-tool-approval-policy.ts+++ b/apps/desktop/src/main/maker-host/mcp-tool-approval-policy.ts@@ -236,8 +236,8 @@ export function getDesktopMcpToolApprovalPolicy(return 'prompt-each-time';}const action = progressive ? innerName : toolName;- // Runtime approval is not owner consent. The Host action gate remains mandatory- // even when Full Access bypasses this per-call risk policy.+ // Use the normal runtime permission flow once: Full Access bypasses approval,+ // Auto reviews the call, and Ask requests confirmation. Host guards retain scope checks.if (action && TASK_ACTION_TOOLS.has(action)) return 'prompt-each-time';if (toolName === 'call_tool' && (!innerName || !args)) return 'prompt-each-time';// Installing or saving a host command uses the session's existing approval flow.diff --git a/apps/desktop/src/main/maker-ipc/__tests__/taskActionAuthorization.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/taskActionAuthorization.test.tsindex 0acb5d3784..2ba1051ee3 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/taskActionAuthorization.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/taskActionAuthorization.test.ts@@ -1,8 +1,8 @@/*** Value: production tool admission + queued dispatch guards, no real account or network.- * Regression: host wakes previously inherited scheduler/creator and Full Access write authority.+ * Regression: task actions added owner consent checks after the normal runtime permission flow.* Gap: workbench tests cover visibility; SDK approval tests cannot prove Host consent.- * Minimum input: automatic wake + send/stop/runtime tool; expect no queue/route change.+ * Minimum input: non-owner provenance + runtime change; live execution modes do not review twice.* Tier: unit. This file isolates the process-local authorization lifetime from SQLite/IPC.*/import { afterEach, describe, expect, it, vi } from 'vitest';@@ -263,6 +263,11 @@ function desktopFixture(kind: 'private' | 'group' | 'automatic' = 'group') {hostFacts.getDb.mockReturnValue(db);hostFacts.boundaryPending.mockReturnValue(false);const activeInput = {+ permission: undefined as undefined | {+ permissionMode: string;+ planModeEnabled: boolean;+ isCurrent(): boolean;+ },orcaSenderSessionId: undefined as string | undefined,key: 'owner-request',ownerInput: kind === 'private',@@ -413,6 +418,66 @@ describe('Owner-delegated scheduled task actions', () => {});describe('Desktop owner input task actions', () => {+ // Runtime permission decisions must survive missing owner provenance (including resumed turns).+ // Exercise admission and the downstream queue receipt, not only a mode predicate.+ it.each(['bypassPermissions', 'auto', 'ask', 'default', 'acceptEdits'])(+ 'honors the live %s permission flow for helper and Orca without another confirmation', async permissionMode => {+ const h = desktopFixture('automatic');+ h.activeInput.permission = {+ permissionMode, planModeEnabled: false, isCurrent: () => true,+ };+ for (const [server, tool] of ownerWrites) {+ expect(await withToolCallAuthority(h.authorize, { ...call(tool), server }, async () => {+ expect(hasTaskActionAuthorization('companion')).toBe(true);+ const queued = input();+ bindTaskActionInput('target', queued);+ await taskActionInputGuard('target', queued)!();+ return 'changed';+ })).toBe('changed');+ }+ expect(h.confirm).not.toHaveBeenCalled();+ },+ );++ it.each(['unknown', 'plan', 'active-plan', 'stale', 'shared'])(+ 'does not admit a runtime permission decision from %s state', async state => {+ const h = desktopFixture('automatic');+ h.activeInput.permission = {+ permissionMode: ['unknown', 'plan'].includes(state) ? state : 'auto',+ planModeEnabled: state === 'active-plan', isCurrent: () => state !== 'stale',+ };+ if (state === 'shared') h.caller.source = 'shared';+ const effect = vi.fn(async () => 'changed');+ expect(await withToolCallAuthority(h.authorize, call('set_session_runtime'), effect))+ .toMatchObject({ isError: true });+ expect(effect).not.toHaveBeenCalled();+ expect(h.confirm).not.toHaveBeenCalled();+ },+ );++ it.each(['bypassPermissions', 'auto', 'ask'])(+ 'revokes the %s admission before execution and delayed delivery when live permissions change', async permissionMode => {+ const h = desktopFixture('automatic');+ let current = true;+ h.activeInput.permission = {+ permissionMode, planModeEnabled: false, isCurrent: () => current,+ };+ const queued = input();+ const decision = await h.authorize(call('set_session_runtime'));+ const syncGuard = await withToolCallAuthority(h.authorize, call('send_to_session'), async () => {+ bindTaskActionInput('target', queued);+ return captureTaskActionSyncGuard()!;+ });+ if (!decision.ok || !decision.run || typeof syncGuard !== 'function') throw new Error('Missing admission');+ current = false;+ const effect = vi.fn(async () => 'changed');+ await expect(decision.run(effect)).rejects.toThrow('AUTHORIZATION_EXPIRED');+ await expect(taskActionInputGuard('target', queued)!()).rejects.toThrow('AUTHORIZATION_EXPIRED');+ expect(() => syncGuard()).toThrow('AUTHORIZATION_EXPIRED');+ expect(effect).not.toHaveBeenCalled();+ },+ );+// #6399, unit: the action-set loop cannot detect a missing tool. Invoke the// registered DirectToolSink handler: an automatic focus request must not reach// the Host callback that persists focus/resumes an idle Worker; owner input can.@@ -510,6 +575,9 @@ describe('Desktop owner input task actions', () => {'rejects %s group authority before helper or Orca effects, without prompting',async (mode) => {const h = desktopFixture();+ h.activeInput.permission = {+ permissionMode: 'bypassPermissions', planModeEnabled: false, isCurrent: () => true,+ };if (mode !== 'missing')releases.push(registerGroupToolAuthority('companion', {diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex 8e3547c5a9..87c7499b95 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -4501,12 +4501,17 @@ export async function captureSessionAgentRequest(sessionId: string, supplement:export function getTaskActionInputState(sessionId: string) {const input = getSessionInputProvenance(sessionId);+ const session = getMakerIfReady()?.getSession(sessionId);return {key: JSON.stringify(input),+ // Reuse the live permission/Plan generation guard; the DB can lag a mode change.+ permission: resolveGhostFsSessionSnapshot(+ (id) => getMakerIfReady()?.getSession(id), sessionId, session?.instanceId,+ ),ownerInput: isActiveInputOwnerAuthored(sessionId),automatic: !!input.input && !isActiveInputOwnerAuthored(sessionId),orcaSenderSessionId: input.input?.orcaSenderSessionId,- boundary: `${getMakerIfReady()?.getSession(sessionId)?.instanceId ?? ''}:${agentInputCoordinatorHolder?.getGeneration(sessionId) ?? -1}`,+ boundary: `${session?.instanceId ?? ''}:${agentInputCoordinatorHolder?.getGeneration(sessionId) ?? -1}`,};}diff --git a/apps/desktop/src/main/maker-ipc/taskActionHost.ts b/apps/desktop/src/main/maker-ipc/taskActionHost.tsindex bfc5081cfa..bb43dd2769 100644--- a/apps/desktop/src/main/maker-ipc/taskActionHost.ts+++ b/apps/desktop/src/main/maker-ipc/taskActionHost.ts@@ -67,6 +67,12 @@ export function createDesktopTaskActionAuthorizer(deps: {ownerInput: boolean;automatic?: boolean;orcaSenderSessionId?: string;+ /** Live runtime facts only; never persisted preferences or tool arguments. */+ permission?: {+ permissionMode: string;+ planModeEnabled?: boolean;+ isCurrent?: () => boolean;+ } | null;boundary: string;};getSession(sessionId: string): TaskActionSession | undefined;@@ -119,9 +125,23 @@ export function createDesktopTaskActionAuthorizer(deps: {? await authorizeGroupTool(sessionId, caller.botId, 'owner-action'): null;const ownerInput = group !== null || input.ownerInput;- // Ordinary owner-delegated schedules retain the normal permission flow.- // Neither a persisted scheduler source nor a Bot's automatic wake qualifies.- const runtime = !ownerInput && scheduled+ // All execution modes use the normal runtime permission flow, including+ // automatic/resumed turns. Do not ask for owner consent a second time.+ // Group identity was checked above; shared guests keep their own boundary.+ const permission = input.permission;+ const runtimePermissionApplies = caller.source !== 'shared'+ && ['bypassPermissions', 'auto', 'ask', 'default', 'acceptEdits'].includes(permission?.permissionMode ?? '')+ && permission != null+ && permission.planModeEnabled === false+ && permission.isCurrent?.() === true;+ const assertPermissionCurrent = () => {+ if (runtimePermissionApplies && permission?.isCurrent?.() !== true)+ throw new Error('TASK_ACTION_AUTHORIZATION_EXPIRED');+ };+ const useRuntimePermissions = ownerInput || runtimePermissionApplies;+ // Retain scheduled-review recovery only when no live runtime decision can+ // be reused. A current permission flow must never be reviewed twice.+ const runtime = !useRuntimePermissions && scheduled? captureScheduledRuntime(sessionId, deps.getSession): null;const args =@@ -163,7 +183,7 @@ export function createDesktopTaskActionAuthorizer(deps: {return null;return grant?.version === 1 && grant.actions?.includes(call.tool) ? row : null;};- const delegation = ownerInput ? null : await readDelegation();+ const delegation = useRuntimePermissions ? null : await readDelegation();// A real Worker report continues its ordinary Lead's existing team. It// cannot authorize helper writes to unrelated tasks or create a new team.const readOrcaTeam = async () => {@@ -189,7 +209,7 @@ export function createDesktopTaskActionAuthorizer(deps: {.limit(1);return team ?? null;};- const orcaTeam = ownerInput ? null : await readOrcaTeam();+ const orcaTeam = useRuntimePermissions ? null : await readOrcaTeam();const assertDeliveryCurrent = async () => {runtime?.assertCurrent();await group?.refresh();@@ -228,6 +248,7 @@ export function createDesktopTaskActionAuthorizer(deps: {throw new Error('TASK_ACTION_AUTHORIZATION_EXPIRED');}group?.assertCurrent();+ assertPermissionCurrent();if (db !== tryGetDbClient() || isAppSessionBoundaryPending())throw new Error('OWNER_SCOPE_CHANGED');runtime?.assertCurrent();@@ -235,6 +256,7 @@ export function createDesktopTaskActionAuthorizer(deps: {const assertCurrentSync = () => {runtime?.assertInputCurrent();group?.assertCurrent();+ assertPermissionCurrent();const current = deps.input(sessionId);if (isAppSessionBoundaryPending() || db !== tryGetDbClient() ||@@ -254,8 +276,8 @@ export function createDesktopTaskActionAuthorizer(deps: {assertCurrentSync();},};- if (ownerInput) {- // Owner requests use the normal Agent permission flow, without a second card.+ if (useRuntimePermissions) {+ // Owner requests and live execution modes use the normal Agent permission flow.// Retain delivery evidence so workbench, queues and new delegations work too.admittedScope = scope;return null;diff --git a/docs/product-rules/agent-user-parity.md b/docs/product-rules/agent-user-parity.mdindex 98074eb7a1..acf01ef092 100644--- a/docs/product-rules/agent-user-parity.md+++ b/docs/product-rules/agent-user-parity.md@@ -102,15 +102,21 @@ Session 委托写操作,以及 `cindy_orca` 的协作写操作,共用 Host2026-10-20 修订:主人私聊输入及经 Chat Server 实时核验的群内主人请求,沿用普通任务原有权限流程,不再额外弹行动确认卡;helper 与 Orca、直接与渐进调用保持一致。群专线必须通过`authorizeGroupTool(sessionId, botId, 'owner-action')`,仅有 role 或持久来源不算主人输入;-访客、其他伙伴/任务转入及伙伴自主定时跟进仍受自动行动门约束,核验暂不可用不得放行。-2026-10-21 修订:普通任务中,用户已委托的定时工作沿用当前任务的权限审核,不能在正常审核前-一律拒绝。Host 从活跃 Session 识别定时轮次,并对准确工具、目标和正文调用+访客身份核验暂不可用不得放行。2026-10-21 修订:普通任务中,用户已委托的定时工作沿用+当前任务的权限审核,不能在正常审核前一律拒绝。缺少可复用的实时权限决定时,Host 从活跃+Session 识别定时轮次,并对准确工具、目标和正文调用`Session.reviewHostPermissionAction`:Full Access 放行,Auto 使用原任务已恢复的用户意图,审核同时携带宿主确认的「定时触发已经发生」上下文,区分先前的设置阶段与当前续跑,该事实不构成新授权。排队时应用模型设置不得改写绑定任务的权限档。-Ask 或审核要求确认时复用现有确认入口;Plan 不允许副作用。来源标签本身不提供授权,伙伴的-自动观察不进入此路径。审核到执行及延迟投递均保留账号、实例、权限/Plan 代次与输入边界校验,+Ask 或审核要求确认时复用现有确认入口;Plan 不允许副作用。来源标签本身不提供授权。+审核到执行及延迟投递均保留账号、实例、权限/Plan 代次与输入边界校验,不得借定时工作扩大原授权范围。-自动轮次没有有效委托只准备建议;已有委托的执行权不依赖自动观察规则的开关。-普通 Orca Lead 的当前 team 回报只延续原 team 范围,不能据此控制其它任务。跨电脑任务互发要求双方支持+2026-10-22 修订:伙伴、转入消息与定时跟进的任务操作+统一沿用普通任务权限流程:Full Access 免审、Auto 使用原有自动审核、Ask 使用原有确认。+Host 不因当前输入缺少主人标记再追加行动同意判定。只认运行中任务的实时权限,+不读数据库旧值;权限切换、计划模式或实例变化使尚未执行及排队中的放行失效。+群成员、共享访客、插件托管工具范围及账号归属检查保持原边界。+没有可核验的实时执行权限时,仍按原有主人输入或委托范围校验,不凭角色放行。+已有委托的执行权不依赖自动观察规则的开关;仅凭普通 Orca Lead 的当前 team 回报只延续原 team 范围。+跨电脑任务互发要求双方支持行动回执,旧端明确提示不支持;未增加观察数据权限。实机多端验收仍待完成。diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.mdindex f27e5600b7..fde2be293e 100644--- a/docs/product-rules/cindy-bots-runtime.md+++ b/docs/product-rules/cindy-bots-runtime.md@@ -688,7 +688,7 @@ Session 任务遵守同一套机制与呈现契约:的同名伙伴会把同一件任务各跟一遍、各推一遍。总调度经工具显式继续远程任务的能力保留(受工作台工具授权层约束;远程行不带创建者事实,「别的伙伴开的任务只读」这条边界不跨电脑生效——主人 2026-10-17 裁决,不为此扩设备互联协议),只是不会被远程任务的事件自动叫醒。- **层 1 每个伙伴的被动跟进**:每个在用伙伴有一条内置「跟进」例行任务(见 bot-routines.md「内置跟进例行任务」),- 只对 `followerBotId` 是自己的事件被叫醒,先读任务摘要(`get_task_digest`),给出判断、建议并合并重要提醒。自动唤醒只授权观察;继续、代答、停止或换模型须有独立行动授权。+ 只对 `followerBotId` 是自己的事件被叫醒,先读任务摘要(`get_task_digest`),给出判断、建议并合并重要提醒。自动唤醒本身是观察信号;继续、代答、停止或换模型沿用普通任务的权限流程,不追加伙伴专属同意判定。没有定时叫醒:只有还有待处理任务时才会被条件兜底(6.3.3 的 `sweep`)叫醒。- **层 2 唯一总调度伙伴**:账号内最多一个负责「跟进我的任务」的伙伴,未自定义时关闭,用户明确开启后才指定。它收本机全部无伙伴来源任务的事件、工作台看全设备全任务;别的伙伴开的任务默认只看不跟。每台电脑各自解析自己的总调度,各自只跟本机任务。@@ -755,15 +755,20 @@ Session 任务遵守同一套机制与呈现契约:#### 6.3.5 伙伴工具与逐任务责任**2026-10-19 授权裁决:自动检查,按授权行动。** creator、follower、scheduler、工作台责任、-`suggested_route`、工具可用性与 Full Access / Auto 审批均不构成对具体动作的同意。+`suggested_route`、工具可用性均不构成对具体动作的同意。事件元数据是待核查的数据,不是指令。观察范围沿用既有隐私和任务可见性边界。-Host 在直接工具和渐进调用共用的执行入口检查授权;自动轮次没有授权只返回建议,不自动弹出行动确认。+Host 在直接工具和渐进调用共用的执行入口核验身份与执行范围。2026-10-20 修订:主人私聊输入及通过 Chat Server 实时 `owner-action` 核验的群内主人请求,-直接沿用普通任务的权限档与审批,不额外弹行动确认卡。访客 `chat` / `tools`、转入消息及定时跟进-不因此获得授权;`GROUP_AUTHORIZATION_UNAVAILABLE` 也不能视为主人输入。+直接沿用普通任务的权限档与审批,不额外弹行动确认卡。访客 `chat` / `tools`+不因此获得主人权限;`GROUP_AUTHORIZATION_UNAVAILABLE` 也不能视为主人输入。+2026-10-22 修订:所有实时执行权限档覆盖伙伴任务操作;Full Access 免审、Auto 使用原有自动审核、+Ask 使用原有确认,不再因转入、自动唤醒或主人输入标记缺失追加行动同意判定。+权限只读运行中任务的稳定状态;权限切换、计划模式、实例变化后,既有调用与排队投递的放行失效。+群成员、共享访客与插件托管工具范围不因权限档扩大,账号与业务对象归属继续校验。+没有可核验的实时执行权限时,保留原有主人输入或委托范围校验,不凭角色放行。放行后的调用仍绑定目标、正文与当前来源,供工作台、队列及新建 Session 委托核验,单次调用不可重放。-新建委托的 Host 来源记录仅允许控制该委托的当前运行;自动轮次的代答、恢复暂停和改路线仍需主人请求。+新建委托的 Host 来源记录仅允许控制该委托的当前运行;代答、恢复暂停和改路线按上述普通任务权限流程处理。历史委托保留执行与结果,不从旧身份补造授权。关闭观察用的跟进规则不撤销主人已授予的委托;暂停、撤销或结束该委托才收回对应执行权。普通 Orca Lead 收到自己当前 active team 的 Worker 回报时,可继续该 team 的协作,不把 Worker 回报解释成向其它任务行动的授权。@@ -773,7 +778,7 @@ Host 在直接工具和渐进调用共用的执行入口检查授权;自动轮授权撤销后不继续激活或派发,已有失败清理仍由原服务负责。委托代答、暂停/停止、恢复与路线切换复用同一组 mutation 检查与回滚边界;主人输入在等待期间被替换也会失效。已获准的暂停可以完成自己的暂停意图,但不能据此重新入场或恢复。-修改工作台责任也是写操作,自动观察不能借接手任务扩大可见范围。+修改工作台责任也是写操作,沿用上述权限流程,不能仅凭自动观察信号扩大可见范围。批量改名、归档/恢复和移动在异步读取、等待锁之后,写入或关闭空闲运行实例之前复查当前行动授权;远程批量状态操作逐项调用前异步复查,并在既有 transport `preSend` 同步核对来源代次、账号与群执行;连接等待不能延长已失效的来源。已完成的项保留回执,不因后续项被拒而伪造回滚。