Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): restore ordinary internal inputs and preview saved models
Chrisfa429f10ad26
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botModelRouteReconciler.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botModelRouteReconciler.test.tsindex dab2735416..d2759a39bf 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/botModelRouteReconciler.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/botModelRouteReconciler.test.ts@@ -23,20 +23,35 @@ describe('permanent Bot model selection', () => {// including cold startup and companions following the global default (unit tier).it.each([false, true])('preserves an automation route across repeated sends and restart (default=%s)', async (followsCindyDefault) => {const h = harness();- const state = { ...h.state, followsCindyDefault, hasScheduledModelOverride: true };+ const state = { ...h.state, followsCindyDefault, scheduledModelBaseline: { ...h.state.current } as SessionRuntimeProfile | null };const deps = { ownerEpoch: () => 'owner', read: async () => state, apply: h.apply };const reconcile = createBotModelRouteReconciler(deps);await reconcile('canonical');await reconcile('canonical');await createBotModelRouteReconciler(deps)('canonical');expect(h.apply).not.toHaveBeenCalled();- state.hasScheduledModelOverride = false;+ state.scheduledModelBaseline = null;await reconcile('canonical');expect(h.apply).toHaveBeenCalledWith('canonical', expect.objectContaining({ model: 'luna' }), state.current);});+ // Capability grants apply to the next ordinary turn, including after restart.+ // The temporary automation route must not choose a different Harness catalog.+ it('previews the saved route without restoring or consuming it', async () => {+ const h = harness();+ const baseline = { ...h.state.current, agentKind: 'claude-code' as const, model: 'saved-model' };+ const state = { ...h.state, scheduledModelBaseline: baseline };+ const reconcile = createBotModelRouteReconciler({ ownerEpoch: () => 'owner', read: async () => state, apply: h.apply });+ expect(await reconcile.preview('canonical')).toEqual(baseline);+ const draft = [{ harness: 'codex' as const, model: 'new-choice', providerId: 'xd', effort: 'medium', fastMode: false }];+ expect(await reconcile.preview('canonical', draft)).toMatchObject({ agentKind: 'codex', model: 'new-choice' });+ expect(await reconcile.preview('canonical')).toEqual(baseline);+ await reconcile('canonical');+ expect(h.apply).not.toHaveBeenCalled();+ expect(state.scheduledModelBaseline).toEqual(baseline);+ });it('lands a saved companion choice even when it equals the temporary automation route', async () => {const h = harness();- const state = { ...h.state, hasScheduledModelOverride: true };+ const state = { ...h.state, scheduledModelBaseline: { ...h.state.current } as SessionRuntimeProfile | null };const reconcile = createBotModelRouteReconciler({ ownerEpoch: () => 'owner', read: async () => state, apply: h.apply });await reconcile('canonical');state.chain = [{ harness: 'pi', model: 'glm', providerId: 'xd', effort: 'high', fastMode: false }];diff --git a/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.tsindex ca5fb023b9..7566d20e14 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/sendToSessionLazyResumePermission.test.ts@@ -1,3 +1,4 @@+import { createScheduledModelScope } from '../scheduledModelSelection.js';import { assertTaskActionCurrent, hasTaskActionAuthorization } from '../taskActionAuthorization.js';/*** #5788:插件 errand 派活走 sendToSessionInternal 的 lazy-resume 时,必须按会话落库的@@ -111,7 +112,7 @@ function botTaskDispatchSlice(): string {`${sendToSessionInternal}${dispatchBotSessionMessage}const delegationDispatch = ${delegationDispatch};-return { delegationDispatch };`,+return { delegationDispatch, dispatchBotSessionMessage };`,{ compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.None } },).outputText;}@@ -122,6 +123,7 @@ const loadBotTaskDispatch = new Function('scope',`with (scope) { return (function () { ${botTaskDispatchSlice()} })(); }`,) as (scope: object) => {+ dispatchBotSessionMessage: (input: Record<string, unknown>) => Promise<{ ok: boolean; wakeKind?: string }>;delegationDispatch: (input: Record<string, unknown>,) => Promise<{ ok: boolean; wakeKind?: string }>;@@ -130,6 +132,7 @@ const loadBotTaskDispatch = new Function(function botTaskDispatchHarness(rows: Record<string, { permissionMode: string | null; planModeEnabled: boolean }>,live: Record<string, object> = {},+ overrides: Record<string, unknown> = {},) {const bootstrapped: Array<Record<string, unknown>> = [];const sentTo: Array<{ sessionId: string; planMode: unknown }> = [];@@ -182,6 +185,7 @@ function botTaskDispatchHarness(extractPlainText: (value: unknown) => String(value ?? ''),assertReviewExternalInputAllowed: asyncNoop,reconcileBotModelRoute: asyncNoop,+ scheduledModelScope: { restore: asyncNoop },refreshBotCapabilityEpochBeforeSend: asyncNoop,assertSessionNotRestarting: noop,sendToSessionLocks: new Map(),@@ -225,6 +229,7 @@ function botTaskDispatchHarness(GroupToolAuthorizationError: class extends Error {},AcceptedCallbackDispatchCancelled: class extends Error {},};+ Object.assign(stubs, overrides);const scope = new Proxy(stubs, {// 自己声明的桩优先;JS 内建对象照常解析;其余自由标识符一读就失败。has: (target, key) => key in target || !(key in globalThis),@@ -237,6 +242,37 @@ function botTaskDispatchHarness(return { ...loadBotTaskDispatch(scope), bootstrapped, sentTo, sendOptions, readAutoReviewHistory };}+// #6895 review: the cloud-room dispatcher bypassed the ordinary send transaction.+// Execute that production closure with the real restore scope (unit behavior in+// this existing guard fixture); assert the route used to send, not call strings.+describe('companion internal delivery after automation', () => {+ it.each(['live', 'resumed'] as const)('restores before %s dispatch reads its model', async (path) => {+ const saved = { agentKind: 'pi' as const, model: 'saved-model', providerId: 'fixture-provider', effort: null, fastMode: false };+ let current = { ...saved, agentKind: 'codex' as 'codex' | 'pi', model: 'temporary-model' };+ let baseline: string | null = JSON.stringify({ ...saved, scopeId: 'automation' });+ const live: Record<string, object> = {};+ const makeLive = () => ({ id: 'child', ...current, isTurnRunning: () => false, getStatus: () => 'active' });+ if (path === 'live') live.child = makeLive();+ let dispatchedModel: string | undefined;+ const scope = createScheduledModelScope({+ createId: () => 'unused', read: async () => ({ profile: current, baseline }),+ write: async (_id, value) => { baseline = value ? JSON.stringify(value) : null; },+ isBusy: () => false,+ apply: async (_id, route) => { current = { ...current, ...route } as typeof current; if (path === 'live') live.child = makeLive(); },+ });+ const h = botTaskDispatchHarness({ child: { permissionMode: 'auto', planModeEnabled: false } }, live, {+ scheduledModelScope: scope,+ maker: { getSession: (id: string) => live[id], getSessionMeta: async () => ({ id: 'child', ...current, workDir: '/tmp/fixture/child' }) },+ bootstrapSession: async (opts: Record<string, unknown>) => ({ session: { id: 'child', model: opts.model } }),+ sendUserMessageWithAwaitedGitBaseline: async (session: { model: string }) => { dispatchedModel = session.model; return { accepted: true }; },+ });+ const result = await h.dispatchBotSessionMessage({ targetSessionId: 'child', message: 'Next owner message', clientId: 'cloud-room:next' });+ expect(result.ok).toBe(true);+ expect(dispatchedModel).toBe('saved-model');+ expect(baseline).toBeNull();+ });+});+// PR #6514: source receipts must not promote a prior owner's deployment permission.// Existing cold-start tests omitted the receipt. Execute the actual production dispatch closure// for both idle branches; guard tier because register.ts has no separately exported entry.diff --git a/apps/desktop/src/main/maker-ipc/botModelRouteReconciler.ts b/apps/desktop/src/main/maker-ipc/botModelRouteReconciler.tsindex 421f7f7703..0db5bcbd40 100644--- a/apps/desktop/src/main/maker-ipc/botModelRouteReconciler.ts+++ b/apps/desktop/src/main/maker-ipc/botModelRouteReconciler.ts@@ -15,7 +15,7 @@ interface BotRouteState {chain: BotModelRoute[];current: RuntimeRoute;hasRuntimeOverride: boolean;- hasScheduledModelOverride?: boolean;+ scheduledModelBaseline?: RuntimeRoute | null;followsCindyDefault?: boolean;next?: RuntimeRoute;}@@ -29,7 +29,7 @@ function configuredRoute(const isDraftChange = key !== JSON.stringify(state.chain);// An automation owns its temporary route until ordinary input restores it.// This also applies to companions following Cindy defaults and after restart.- if (!isDraftChange && state.hasScheduledModelOverride && (previous === undefined || previous === key)) return null;+ if (!isDraftChange && state.scheduledModelBaseline && (previous === undefined || previous === key)) return null;if (!state.followsCindyDefault && !isDraftChange && state.hasRuntimeOverride && (previous === undefined || previous === key)) return null;const primary = chain[0];if (!primary) return null;@@ -97,7 +97,7 @@ export function createBotModelRouteReconciler(deps: {return;}const current = state.current;- if (state.hasScheduledModelOverride || !sameRoute(route, current) || (state.next && !sameRoute(route, state.next))) {+ if (state.scheduledModelBaseline || !sameRoute(route, current) || (state.next && !sameRoute(route, state.next))) {try {await deps.apply(sessionId, route, state.current);} catch (error) {@@ -149,6 +149,7 @@ export function createBotModelRouteReconciler(deps: {draftChain ? normalizeBotModelChain(draftChain) : undefined,) ??state.next ??+ state.scheduledModelBaseline ??state.current);},diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex 375c4a9fb1..27e953a4d6 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -11819,6 +11819,10 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)let lockStage = 'resolve-session-meta+row';const run = waitPrev.then(async () => {await assertTaskActionCurrent();+ // Internal idle deliveries (including companion cloud-room input) bypass+ // the ordinary send transaction. Restore under this send lock before+ // reading metadata or dispatching; busy inputs defer to the queued path.+ await scheduledModelScope.restore(targetSessionId);await reconcileBotModelRoute(targetSessionId, true);const [meta, dbRow] = await Promise.all([maker.getSessionMeta(targetSessionId).catch(() => null),@@ -15984,7 +15988,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)return {chain: selection.chain,followsCindyDefault: selection.followsCindyDefault,- hasScheduledModelOverride: parseScheduledModelBaseline(row.scheduledModelBaseline) !== null,+ scheduledModelBaseline: parseScheduledModelBaseline(row.scheduledModelBaseline),current: {agentDeviceId: row.agentDeviceId,agentKind: live?.agentKind ?? dbToMakerAgentKind(row.agentKind),diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.mdindex 27a94a7f7e..cb851237dc 100644--- a/docs/product-rules/cindy-bots-runtime.md+++ b/docs/product-rules/cindy-bots-runtime.md@@ -371,7 +371,7 @@ harness + provider + model + effort + fastMode- 同一轮最多按生效候选链各尝试一次;不得循环。用户显式配置的链不得追加目录候选。- 同 harness 可在安全边界切模型;跨 harness 必须走既有 agent-switch / 交接重建事务。- 伙伴设置中的显式模型保存立即同步当前主任务的运行选择;空闲时在既有安全边界完成切换,运行中先记录最新选择,在回复、工具与审批结束后的安全边界接替,不要求用户再发一条消息才能登记。连续改选以最后一次为准,选回当前路由应取消不同的待切换路由。-- 自动化指定的临时模型在本轮发送中不被伙伴默认模型对齐覆盖,包括跟随全局默认的伙伴。主人随后保存新的伙伴模型选择时,该选择取代自动化留下的旧恢复偏好;即使新选择恰好等于临时运行模型,下一次聊天也不得恢复到旧选择。+- 自动化指定的临时模型在本轮发送中不被伙伴默认模型对齐覆盖,包括跟随全局默认的伙伴。主人随后保存新的伙伴模型选择时,该选择取代自动化留下的旧恢复偏好;即使新选择恰好等于临时运行模型,下一次聊天也不得恢复到旧选择。普通内部投递也在发送边界恢复原选择;能力设置预览使用下一轮普通聊天的选择,不因预览消费恢复记录。- 模型配置只保留统一选择器入口,备用链仍在原组件内折叠;思考深度、Fast 与 Harness 不拆成独立设置页。缩窗交接复用已经核实目标窗口的延迟选择处理,完整记录与主任务身份保留,不绕过原生副作用重放限制。- fallback 只改变当前任务的有效路由,不暗改 Profile 顺序。下一次确定性重建仍从首选开始。- 存量单模型配置归一成一项候选链,不能在升级时改变用户已有选择。