Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): preserve workbench denial recovery guidance
ylliuuu6665e80710e71b
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botTaskResponsibilityAuthority.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botTaskResponsibilityAuthority.test.tsindex d7f62e490d..9438417ae9 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/botTaskResponsibilityAuthority.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/botTaskResponsibilityAuthority.test.ts@@ -5,6 +5,7 @@ import { and, desc, eq, inArray, isNotNull, isNull } from 'drizzle-orm';import ts from 'typescript';import { expect, it, vi } from 'vitest';import { botDelegations, botProfiles, botSessionLinks, sessions } from '../../localDb/schema.js';+import { createBotWorkbenchAccess, type WorkbenchCallerResult } from '../botWorkbenchAccess.js';// Exercise the real authority queries against SQLite, without Electron startup.// PR #6813 inserted another exported function between the queried functions, breaking@@ -89,7 +90,7 @@ function fixture(role: string) {};const api = new Function(...Object.keys(deps), js)(...Object.values(deps)) as {captureBotCreatedTaskResponsibility(id: string): Promise<null | ((id: string) => Promise<void>)>;- resolveWorkbenchCaller(id: string): Promise<{ ok: boolean; errorCode?: string }>;+ resolveWorkbenchCaller(id: string): Promise<WorkbenchCallerResult>;};return { sqlite, save, broadcast, remoteBroadcast, ...api };}@@ -107,7 +108,34 @@ it.each(['canonical', 'thread', 'channel', 'group'])(expect(f.remoteBroadcast).toHaveBeenCalledWith('hihi');// Recognizing a creator must not grant a channel/group conversation workbench access.if (role === 'channel' || role === 'group') {- expect(await f.resolveWorkbenchCaller('caller')).toMatchObject({ ok: false, errorCode: 'BOT_MAIN_TASK_REQUIRED' });+ // #6965: the real caller query must explain the recovery path, including for reads.+ // Existing coverage only checked the code. Minimum input: active group/channel link; unit.+ const denied = await f.resolveWorkbenchCaller('caller');+ expect(denied).toMatchObject({ ok: false, errorCode: 'BOT_MAIN_TASK_REQUIRED' });+ if (denied.ok) throw new Error('Expected workbench denial');+ expect(denied.message).toContain('未读取或修改');+ expect(denied.message).toContain('私聊主聊天');+ expect(denied.message).toContain('私聊话题');+ expect(denied.message).toContain('不要在当前入口重试');+ // Every operation must stop before touching business records or sending a message,+ // otherwise the shared denial's no-read/no-change statement would be false.+ const untouched = vi.fn(() => { throw new Error('Business operation reached'); });+ const access = createBotWorkbenchAccess({+ resolveCaller: f.resolveWorkbenchCaller,+ schedulerBotId: untouched, readWatched: untouched,+ readResponsibleSessionIds: untouched, saveResponsibility: untouched,+ listDelegations: untouched, readTarget: untouched, readGlance: untouched,+ readSessionTranscript: untouched, readRemoteTranscript: untouched,+ sendToSession: untouched, sendToRemoteSession: untouched, notifyChanged: untouched,+ });+ const params = { callerSessionId: 'caller', taskId: 'created' };+ expect(await access.get(params)).toEqual(denied);+ expect(await access.read(params)).toEqual(denied);+ expect(await access.setResponsibility({ ...params, responsible: true })).toEqual(denied);+ expect(await access.continueTask({ ...params, message: 'Continue' })).toEqual(denied);+ expect(untouched).not.toHaveBeenCalled();+ } else {+ expect(await f.resolveWorkbenchCaller('caller')).toEqual({ ok: true, botId: 'hihi' });}} finally { f.sqlite.close(); }},diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botTodoAccess.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botTodoAccess.test.tsindex b6be72c356..30dcd08750 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/botTodoAccess.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/botTodoAccess.test.ts@@ -10,6 +10,7 @@ const env = vi.hoisted(() => ({pending: false,notify: vi.fn(),cancel: vi.fn(async () => true),+ callerFailure: { ok: false, errorCode: 'BOT_MAIN_TASK_REQUIRED', message: 'Open the companion private chat; this call did not read or change records.' },}));vi.mock('../../appSessionState.js', () => ({activeOwnerScopeKey: () => `${env.owner}:${env.generation}`,@@ -46,6 +47,7 @@ vi.mock('../botWorkbenchTools.js', () => ({resolveWorkbenchCaller: async (id: string) =>id === 'canonical-one'? { ok: true, botId: 'bot-one' }+ : id === 'group-one' ? env.callerFailure: { ok: false, errorCode: 'NOT_A_BOT_SESSION' },}));vi.mock('../../localDb/agentInputQueueSnapshots.js', () => ({@@ -84,6 +86,16 @@ const patch = {},};describe('Todo public access', () => {+ // #6965: todoForCaller discarded the real authority hint before the MCP callback could return it.+ // Unit: denied group caller; preserve code + message and prove no Todo was registered.+ it('preserves caller recovery hints before accessing or changing todos', async () => {+ await expect(todoForCaller('group-one')).rejects.toMatchObject({+ code: env.callerFailure.errorCode,+ message: env.callerFailure.message,+ });+ expect(env.notify).not.toHaveBeenCalled();+ expect((await (await todoForCaller('canonical-one')).list()).items).toEqual([]);+ });it('enforces current active canonical teammate and owner fences', async () => {await expect(todoForCaller('ordinary-session')).rejects.toMatchObject({code: 'NOT_A_BOT_SESSION',diff --git a/apps/desktop/src/main/maker-ipc/botTodoAccess.ts b/apps/desktop/src/main/maker-ipc/botTodoAccess.tsindex dcc0c23ecf..d58020addb 100644--- a/apps/desktop/src/main/maker-ipc/botTodoAccess.ts+++ b/apps/desktop/src/main/maker-ipc/botTodoAccess.ts@@ -261,7 +261,7 @@ export async function settleBotTodoForSession(export async function todoForCaller(callerSessionId: string, ownerAuthored = () => false): Promise<BotTodoAccess> {const owner = activeOwnerScopeKey();const caller = await resolveWorkbenchCaller(callerSessionId);- if (!caller.ok) throw new TodoError(caller.errorCode);+ if (!caller.ok) throw new TodoError(caller.errorCode, caller.message);if (owner !== activeOwnerScopeKey()) throw new TodoError('OWNER_SCOPE_CHANGED');return todoAccess(caller.botId, ownerAuthored);}diff --git a/apps/desktop/src/main/maker-ipc/botWorkbenchTools.ts b/apps/desktop/src/main/maker-ipc/botWorkbenchTools.tsindex 2150df2a09..3ef2daad8e 100644--- a/apps/desktop/src/main/maker-ipc/botWorkbenchTools.ts+++ b/apps/desktop/src/main/maker-ipc/botWorkbenchTools.ts@@ -55,7 +55,13 @@ export async function resolveWorkbenchCaller(callerSessionId: string): Promise<Wreturn { ok: false, errorCode: 'BOT_SESSION_INACTIVE', message: '伙伴或它的主任务已停用' };}if (row.role !== 'canonical' && row.role !== 'thread') {- return { ok: false, errorCode: 'BOT_MAIN_TASK_REQUIRED', message: '只有伙伴的主任务可以使用工作台' };+ return {+ ok: false,+ errorCode: 'BOT_MAIN_TASK_REQUIRED',+ message: '当前入口不是伙伴的私聊主任务或私聊话题,不能使用工作台、待办或项目关联工具。'+ + '本次调用未读取或修改这些记录。请告知主人:在 Cindy 中打开这位伙伴的私聊主聊天(主任务),在那里提出本次请求;私聊话题也可用。'+ + '不要在当前入口重试。',+ };}if (row.remoteHostId) {return { ok: false, errorCode: 'REMOTE_WORKBENCH_UNAVAILABLE', message: '远端伙伴暂不支持工作台' };