Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(plugin): 插件派活唤醒会话时沿用落库权限档,不再按 bypass 恢复 (#5791)
FicoWang62d108a5e654
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.tsnew file mode 100644index 0000000000..22815318fb--- /dev/null+++ b/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.ts@@ -0,0 +1,60 @@+/**+ * #5788:插件 errand 派活走 sendToSessionInternal 的 lazy-resume 时,必须按会话落库的+ * 权限档恢复,不能落到 main 侧通路的缺省 bypass。否则插件任务被提权,errand 复用判定也会+ * 因活跃会话的档位(bypass)≠ 任务设置的档位而每轮失败、另开新会话。+ *+ * 这项决定由宿主显式传入的策略参数承载;`sourcePlugin` 只是来源标签,不能当权限判据+ * (docs/product-rules/message-source.md)。+ */+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';++import { describe, expect, it } from 'vitest';++const registerSource = readFileSync(resolve(__dirname, '..', 'register.ts'), 'utf8').replace(+ /\r\n?/g,+ '\n',+);++function lazyResumeCreateOpts(): string {+ const start = registerSource.indexOf('async function sendToSessionInternal(params: {');+ const resume = registerSource.indexOf("lockStage = 'lazy-resume-bootstrap';", start);+ const end = registerSource.indexOf('await synthesizeOrcaVendorOptionsFromDb(targetSessionId, createOpts);', resume);+ expect(start).toBeGreaterThanOrEqual(0);+ expect(resume).toBeGreaterThan(start);+ expect(end).toBeGreaterThan(resume);+ return registerSource.slice(resume, end);+}++describe('sendToSessionInternal lazy-resume permission mode', () => {+ it('restores the stored permission mode when the host asks for it', () => {+ expect(lazyResumeCreateOpts()).toContain(+ `permissionMode: params.resumeWithStoredPermissionMode+ ? permissionModeOrAsk(dbRow.permissionMode)+ : 'bypassPermissions',`,+ );+ });++ it('does not derive the permission decision from the source label', () => {+ const opts = lazyResumeCreateOpts();+ expect(opts).not.toMatch(/^\s*permissionMode: 'bypassPermissions',$/m);+ expect(opts).not.toMatch(/permissionMode:[^\n]*sourcePlugin/);+ });++ it('has the Ghost errand dispatch request the stored permission mode', () => {+ const runner = registerSource.indexOf('createGhostErrandRunner({');+ const dispatch = registerSource.indexOf('dispatch: async ({ targetSessionId, message, ghostId }) => {', runner);+ const call = registerSource.indexOf('const r = await sendToSessionInternal({', dispatch);+ const close = registerSource.indexOf('});', call);+ expect(runner).toBeGreaterThanOrEqual(0);+ expect(dispatch).toBeGreaterThan(runner);+ expect(call).toBeGreaterThan(dispatch);+ expect(registerSource.slice(call, close)).toContain('resumeWithStoredPermissionMode: true,');+ });++ it('reads the persisted permission mode in the row snapshot used by lazy resume', () => {+ const sessionsSource = readFileSync(resolve(__dirname, '..', '..', 'localDb', 'ipc', 'sessions.ts'), 'utf8');+ const select = sessionsSource.slice(sessionsSource.indexOf('async function selectSessionRowSnapshot('));+ expect(select.slice(0, select.indexOf('.from(sessions)'))).toContain('permissionMode: sessions.permissionMode,');+ });+});diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex 8913edac66..15fe88666a 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -10217,6 +10217,12 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)forceQueue?: boolean;/** 插件任务派发的来源(只用于标签与 `[消息来源]`,不是权限判据,也不是 origin)。 */sourcePlugin?: AgentInputQueuedMessage['sourcePlugin'];+ /**+ * Host 持有的恢复策略:目标会话不在运行、需要 lazy-resume 时,按会话落库的权限档+ * 启动,而不是 main 侧通路的缺省 bypass。插件任务的档位来自用户的任务设置,只能由+ * 宿主的插件派发入口显式要求,不从来源字段推断(#5788)。+ */+ resumeWithStoredPermissionMode?: boolean;}): Promise<SendToSessionInternalResult> {const {targetSessionId,@@ -10863,7 +10869,13 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)workingDir: meta.workDir,model: meta.model,resumeSessionId: meta.sdkSessionId,- permissionMode: 'bypassPermissions',+ // 插件任务的档位由用户在任务设置里给定(errand 还会再收窄),不能借 lazy-resume+ // 的缺省 bypass 提权;档位不一致还会让 errand 复用判定每轮都失败、另开新会话+ // (#5788)。由宿主的插件派发入口显式要求,其它 main 侧通路(Orca 派活、伙伴+ // 委派等)保持既有缺省。+ permissionMode: params.resumeWithStoredPermissionMode+ ? permissionModeOrAsk(dbRow.permissionMode)+ : 'bypassPermissions',// 发起方回合结束后进程常被释放。漏掉 providerId = 回落到隐式默认路由,// 订阅 / 自定义来源的伙伴会以 AGENT_NOT_READY 起不来,委派结果停在外发// 队列里,表现就是「对方做完了,发起方没被叫醒」。@@ -12395,6 +12407,8 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)targetSessionId,message,sourcePlugin: { pluginId: ghostId, ...(errandPluginName ? { name: errandPluginName } : {}) },+ // errand 会话按任务设置的权限档落库;冷启动必须沿用,不能退回 bypass(#5788)。+ resumeWithStoredPermissionMode: true,});if (!r.ok) return { ok: false, errorCode: r.errorCode, message: r.message };return { ok: true, wakeKind: r.wakeKind };