Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(teammates): confirm independent full-access agent schedules
Chris9273b93c1ed1
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/taskActionAuthorization.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/taskActionAuthorization.test.tsindex 5e9d005770..a9d0b04e96 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/taskActionAuthorization.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/taskActionAuthorization.test.ts@@ -910,7 +910,7 @@ describe('teammate turn principal', () => {const h = desktopFixture('automatic');live(h);const request = { sessionId: 'companion', server: 'cindy_scheduler' as const, tool,- args: { id: 'routine-owner-weekly', scheduleId: 'routine-owner-weekly', prompt: 'Merge everything' } };+ args: { id: 'routine-owner-weekly', scheduleId: 'routine-owner-weekly', prompt: 'Merge everything', bindToCurrentSession: true } };expect(await withToolCallAuthority(h.authorize, request, async () => 'changed')).toBe('changed');expect(h.confirm).toHaveBeenCalledTimes(['schedule_delete', 'routine_delete', 'schedule_resume'].includes(tool) ? 1 : 0);h.activeInput.ownerInput = true;@@ -955,7 +955,7 @@ describe('teammate turn principal', () => {'waits for an exact decision before autonomous %s can execute shell commands', async tool => {const h = desktopFixture('automatic');live(h);- const definition = { id: 'script', name: 'Command check', executionMode: 'script' as const,+ const definition = { id: 'script', name: 'Command check', prompt: '', executionMode: 'script' as const,workingDir: '/tmp/check', scriptConfig: { command: 'printf reviewed', capabilities: [] } };h.schedules.set('script', definition);const args = tool === 'schedule_run_now' ? { id: 'script' } : definition;@@ -978,13 +978,59 @@ describe('teammate turn principal', () => {},);- it('expires a command decision when the saved schedule changes', async () => {+ // r4409452538: standalone Agent schedules default to Full Access in the runner.+ // Existing shell-command cases miss an agent prompt creating a more privileged session.+ // Unit: production admission + effects, default agent mode is the minimum failing input.+ it.each(['create', 'detach', 'run-now', 'persistent'] as const)(+ 'requires the exact command-capable decision for autonomous Agent schedule %s', async variant => {+ const h = desktopFixture('automatic');+ live(h);+ const definition = { id: 'agent', name: 'Agent work', prompt: 'Run the saved work',+ workingDir: '/work', executionMode: 'agent' as const,+ ...(variant === 'detach' ? { targetSessionId: 'companion' } : {}) };+ h.schedules.set('agent', definition);+ const tool = variant === 'run-now' ? 'schedule_run_now' : variant === 'detach' ? 'schedule_update' : 'schedule_create';+ const args = variant === 'run-now' ? { id: 'agent', bindToCurrentSession: true } : variant === 'detach'+ ? { id: 'agent', targetSessionId: null } : { prompt: definition.prompt, workingDir: '/work',+ ...(variant === 'persistent' ? { bindToCurrentSession: true, persistentSession: true } : {}) };+ const request = { sessionId: 'companion', server: 'cindy_scheduler' as const, tool, args };+ const effect = vi.fn(async () => 'started');+ h.confirm.mockResolvedValue(false);+ expect(JSON.stringify(await withToolCallAuthority(h.authorize, request, effect))).toContain('USER_CANCELLED');+ expect(effect).not.toHaveBeenCalled();+ expect(h.confirm).toHaveBeenCalledWith('companion', tool, args,+ expect.objectContaining({ risk: 'command', details: expect.objectContaining({+ execution: { mode: 'agent', newTaskPermissionMode: 'bypassPermissions' },+ }) }));+ h.confirm.mockResolvedValue(true);+ expect(await withToolCallAuthority(h.authorize, request, effect)).toBe('started');+ expect(effect).toHaveBeenCalledTimes(1);+ h.confirm.mockClear();+ h.activeInput.ownerInput = true;+ expect(await withToolCallAuthority(h.authorize, request, effect)).toBe('started');+ expect(h.confirm).not.toHaveBeenCalled();+ },+ );++ it('keeps an approved independent Agent schedule metadata edit ordinary', async () => {+ const h = desktopFixture('automatic');+ live(h);+ h.schedules.set('agent', { id: 'agent', name: 'Agent work', prompt: 'Saved owner instruction',+ executionMode: 'agent', workingDir: '/work' });+ const request = { sessionId: 'companion', server: 'cindy_scheduler' as const, tool: 'schedule_update',+ args: { id: 'agent', name: 'Renamed', cronExpr: '0 9 * * *' } };+ expect(await withToolCallAuthority(h.authorize, request, async () => 'saved')).toBe('saved');+ expect(h.confirm).not.toHaveBeenCalled();+ });++ it.each(['script', 'agent'] as const)('expires a %s command decision when the saved schedule changes', async mode => {const h = desktopFixture('automatic');live(h);- h.schedules.set('script', { id: 'script', name: 'Command check', executionMode: 'script',- scriptConfig: { command: 'printf reviewed', capabilities: [] } });+ h.schedules.set('script', { id: 'script', name: 'Command check', prompt: '', executionMode: mode,+ ...(mode === 'script' ? { scriptConfig: { command: 'printf reviewed', capabilities: [] } } : { prompt: 'Reviewed prompt' }) });h.confirm.mockImplementation(async () => {- h.schedules.get('script')!.scriptConfig!.command = 'printf replacement';+ if (mode === 'script') h.schedules.get('script')!.scriptConfig!.command = 'printf replacement';+ else h.schedules.get('script')!.prompt = 'Replacement prompt';return true;});const effect = vi.fn(async () => 'executed');@@ -1003,8 +1049,8 @@ describe('teammate turn principal', () => {await call('schedule_set_pre_run_hook', { script: 'process.exit(2)' });expect(h.confirm).toHaveBeenCalledTimes(2);h.confirm.mockClear();- await call('schedule_create', { prompt: 'Remind me tomorrow' });- h.schedules.set('prompt', { id: 'prompt', name: 'Reminder', executionMode: 'agent' });+ await call('schedule_create', { prompt: 'Remind me tomorrow', bindToCurrentSession: true });+ h.schedules.set('prompt', { id: 'prompt', name: 'Reminder', prompt: 'Remind me tomorrow', executionMode: 'agent', targetSessionId: 'companion' });await call('schedule_update', { id: 'prompt', name: 'Updated reminder' });await call('schedule_run_now', { id: 'prompt' });expect(h.confirm).not.toHaveBeenCalled();@@ -1036,7 +1082,7 @@ describe('teammate turn principal', () => {it('binds the scheduler hook installer decision to its actual schedule target', async () => {const h = desktopFixture('automatic');live(h);- const target = { id: 'bound', name: 'Bound check', executionMode: 'agent' as const,+ const target = { id: 'bound', name: 'Bound check', prompt: 'Bound owner instruction', executionMode: 'agent' as const,targetSessionId: 'child', workingDir: '/schedule', preRunHook: { command: 'node old.mjs' },hookInstallation: { workingDir: '/session', fallbackDir: '/fallback' } };h.schedules.set('bound', target);diff --git a/apps/desktop/src/main/maker-ipc/taskActionAuthorization.ts b/apps/desktop/src/main/maker-ipc/taskActionAuthorization.tsindex d808986d7a..7f057d9e13 100644--- a/apps/desktop/src/main/maker-ipc/taskActionAuthorization.ts+++ b/apps/desktop/src/main/maker-ipc/taskActionAuthorization.ts@@ -116,7 +116,7 @@ export const SCHEDULER_TASK_ACTION_TOOLS: ReadonlySet<string> = new Set([export type TaskActionRisk = 'remove' | 'permission' | 'resume' | 'command' | 'authority';export type TaskActionScheduleDefinition = Pick<Schedule,- 'id' | 'name' | 'executionMode' | 'scriptConfig' | 'preRunHook' | 'workingDir' | 'targetSessionId'> & {+ 'id' | 'name' | 'prompt' | 'persistentSession' | 'executionMode' | 'scriptConfig' | 'preRunHook' | 'workingDir' | 'targetSessionId'> & {hookInstallation?: { workingDir?: string; fallbackDir: string };};export interface TaskActionConfirmation {@@ -140,6 +140,23 @@ export interface TaskActionRoutineSnapshot {assertCurrent(): void;}+/** Independent Agent runs use the runner's existing Full Access default; bound+ * continuations inherit their target permissions. Persistent runs may create a replacement. */+export function taskActionStartsIndependentAgent(call: Pick<Call, 'server' | 'tool' | 'args'>,+ schedule?: TaskActionScheduleDefinition | null): boolean {+ if (call.server !== 'cindy_scheduler' || !['schedule_create', 'schedule_update', 'schedule_run_now'].includes(call.tool))+ return false;+ const args = call.args && typeof call.args === 'object' && !Array.isArray(call.args)+ ? call.args as Record<string, unknown> : {};+ if (call.tool !== 'schedule_create' && args.device && args.device !== 'local') return false;+ const definition = call.tool === 'schedule_run_now' ? schedule : { ...schedule, ...args };+ const bindsCurrent = call.tool !== 'schedule_run_now' && args.bindToCurrentSession === true;+ return (definition?.executionMode ?? 'agent') === 'agent' &&+ typeof definition?.prompt === 'string' && !!definition.prompt.trim() &&+ (definition.persistentSession === true ||+ (!(typeof definition.targetSessionId === 'string' && definition.targetSessionId.trim()) && !bindsCurrent));+}+/** A small, explicit risk list. Everything else follows the task's normal permissions. */export function taskActionRisk(call: Pick<Call, 'server' | 'tool' | 'args'>,facts?: { routineEnabled?: boolean; routinePrompt?: string; routineBuiltin?: boolean; routinePreRunCommand?: string; schedule?: TaskActionScheduleDefinition | null }): TaskActionRisk | undefined {@@ -161,6 +178,10 @@ export function taskActionRisk(call: Pick<Call, 'server' | 'tool' | 'args'>,return 'command';}}+ if (taskActionStartsIndependentAgent(call, facts?.schedule) &&+ (call.tool !== 'schedule_update' ||+ (['prompt', 'workingDir', 'executionMode', 'targetSessionId', 'persistentSession'] as const)+ .some(key => key in args && args[key] !== facts?.schedule?.[key]))) return 'command';if (call.tool === 'routine_run_now' && facts?.routinePreRunCommand?.trim()) return 'command';const routineHook = args.preRunHook;if (call.tool === 'routine_save' && routineHook && typeof routineHook === 'object' &&diff --git a/apps/desktop/src/main/maker-ipc/taskActionHost.ts b/apps/desktop/src/main/maker-ipc/taskActionHost.tsindex 803dd335c7..ff84baaf12 100644--- a/apps/desktop/src/main/maker-ipc/taskActionHost.ts+++ b/apps/desktop/src/main/maker-ipc/taskActionHost.ts@@ -20,6 +20,7 @@ import {createTaskActionAuthorizer,DELEGATED_TASK_ACTIONS,taskActionRisk,+ taskActionStartsIndependentAgent,type TaskActionConfirmation,type TaskActionTarget,type TaskActionRoutineSnapshot,@@ -386,6 +387,8 @@ export function createDesktopTaskActionAuthorizer(deps: {const confirmed = await deps.confirm(sessionId, call.tool, structuredClone(call.args),{ server: call.server, risk, ...(permissionTarget ? { details: permissionTarget.details }: helperInstallation ? { details: { installation: { workingDir: helperInstallDir ?? null } } }+ : risk === 'command' && taskActionStartsIndependentAgent(call, schedule)+ ? { details: { ...(schedule ? { schedule } : {}), execution: { mode: 'agent', newTaskPermissionMode: 'bypassPermissions' } } }: risk === 'command' && schedule ? { details: { schedule } }: call.tool === 'routine_run_now' && routine?.details ? { details: routine.details } : {}) });if (!confirmed) {diff --git a/apps/desktop/src/main/mcp-integrations/mcp-providers.ts b/apps/desktop/src/main/mcp-integrations/mcp-providers.tsindex e04551273c..99db82f70a 100644--- a/apps/desktop/src/main/mcp-integrations/mcp-providers.ts+++ b/apps/desktop/src/main/mcp-integrations/mcp-providers.ts@@ -330,8 +330,8 @@ export function createDesktopMcpProviders(deps: DesktopMcpProvidersDeps): LiziMcgetScheduleDefinition: async (id, hookInstallation) => {const schedule = await getScheduler().get(id);if (!schedule) return null;- const { name, executionMode, scriptConfig, preRunHook, workingDir, targetSessionId } = schedule;- const definition = { id, name, executionMode, scriptConfig, preRunHook, workingDir, targetSessionId };+ const { name, prompt, persistentSession, executionMode, scriptConfig, preRunHook, workingDir, targetSessionId } = schedule;+ const definition = { id, name, prompt, persistentSession, executionMode, scriptConfig, preRunHook, workingDir, targetSessionId };if (!hookInstallation) return definition;let installWorkingDir = hookInstallation.workingDir;if (!installWorkingDir && executionMode !== 'script' && targetSessionId)diff --git a/docs/product-rules/teammate-authority.md b/docs/product-rules/teammate-authority.mdindex bc66b7a5b9..be36c1d61a 100644--- a/docs/product-rules/teammate-authority.md+++ b/docs/product-rules/teammate-authority.md@@ -20,6 +20,7 @@| 风险 | 实际入口 || --- | --- || 本机调度命令 | `schedule_create` / `schedule_update` 保存脚本执行或命令前置检查、`schedule_run_now` 执行含此类命令的已存定义、`cindy_helper` 和 `cindy_scheduler` 两个入口的 `schedule_set_pre_run_hook` 安装并自测脚本,以及 `routine_save` 保存新命令前置检查(沿用同一命令不追加确认)、`routine_run_now` 手动执行含前置命令的已存规则 |+| 新建完全访问 Agent | 本机 `schedule_create` 创建未绑定任务的 Agent 调度、`schedule_update` 改写其指令/目录或解除绑定/改成可重建的持续模式、`schedule_run_now` 手动执行;包含持续模式丢失目标后新建任务的分支 || 授予常驻指令 | `routine_save` 新建启用的自定义规则或改写启用规则的指令;禁用草稿和不改指令的编辑沿原权限 || 删除自动化 | `routine_delete`、`schedule_delete` || 代用户回答权限请求 | `message_session_task` 携带 `decision` |@@ -28,7 +29,8 @@其余操作不命中风险表就继续现有权限流程。新增普通工具不需要另开“自主解锁”例外。主人输入、已核实的主人转达和受托指令沿正常权限审核,不再加第二张行动确认卡。风险表不是平台权限、账号访问或消息来源认证的替代品。-本机调度的脚本及前置检查由宿主直接执行,不经过 Agent 的 Bash 审批;自主调用须展示命令、工作目录及准确动作,由主人决定。普通提示词自动化、提醒与只读工具不追加此类确认。+本机调度的脚本及前置检查由宿主直接执行,不经过 Agent 的 Bash 审批;自主调用须展示命令、工作目录及准确动作,由主人决定。绑定已有任务并继承其权限的无命令跟进、提醒与只读工具不追加此类确认。+独立 Agent 调度沿用调度器既有的新任务完全访问默认值,不得由自主轮静默创建更高权限的执行。卡片展示完整指令、目录与新任务权限默认值;已有独立调度只改名称/时间等元数据不追加确认。此处不修改调度器、普通任务权限档或全局自动审核器。按 ID 执行或修改时,卡片展示已存命令定义;脚本安装按 `scheduleId` 展示目标、旧命令及绑定任务解析出的目录与后备落盘目录,并绑定同一快照;helper 安装器保持不接受 `scheduleId` 或外部目录,只展示并绑定调用伙伴自身的任务目录。确认期间定义或解析目录变化使旧许可失效,安装前再次复核。跨电脑调度仍沿已有逐次任务权限流程。禁用草稿、重命名、改时间等不改常驻指令和命令的保存不追加授权;主人输入和受托指令仍沿原权限。自主创建启用的自定义指令或改写启用规则指令,必须经一次性本人确认才可作为后续 entrusted 执行的常驻授权,不能靠保存制造主人授权。