Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(routines): keep routine model on fresh lanes and gate session mode on host support

Chris869e7eb001cf
diff --git a/apps/desktop/src/main/localDb/ipc/botRemoteSettingsOps.ts b/apps/desktop/src/main/localDb/ipc/botRemoteSettingsOps.ts
index 4ecf512be9..74c981bcd4 100644
--- a/apps/desktop/src/main/localDb/ipc/botRemoteSettingsOps.ts
+++ b/apps/desktop/src/main/localDb/ipc/botRemoteSettingsOps.ts
@@ -238,6 +238,11 @@ export function createBotRemoteSettingsOps(deps: BotSettingsOpsDeps): Partial<Re
const id = call.args.id === undefined ? undefined : text(call.args.id, 'id', 128);
return deps.routines.save(botOf(call), parseRoutineInput(call.args.input), id);
}),
+ // Advertised separately: older hosts accept `saveWithModel` but drop `sessionMode`.
+ 'routines.saveWithSessionMode': call => routineCall(() => {
+ const id = call.args.id === undefined ? undefined : text(call.args.id, 'id', 128);
+ return deps.routines.save(botOf(call), parseRoutineInput(call.args.input), id);
+ }),
'routines.runNow': call => routineCall(() => deps.routines.runNow(botOf(call), text(call.args.id, 'id', 128))),
'routines.remove': call => routineCall(async () => {
await deps.routines.remove(botOf(call), text(call.args.id, 'id', 128));
diff --git a/apps/desktop/src/main/routines/__tests__/service.test.ts b/apps/desktop/src/main/routines/__tests__/service.test.ts
index 3d48fc47c0..181ab078f9 100644
--- a/apps/desktop/src/main/routines/__tests__/service.test.ts
+++ b/apps/desktop/src/main/routines/__tests__/service.test.ts
@@ -62,7 +62,7 @@ vi.mock('../store.js', () => ({
save = mock.save;
},
}));
-import { configureRoutineHost, getRoutineEngine, routineTools, stopRoutines, updateBotRoutineLifecycle } from '../service.js';
+import { configureRoutineHost, getRoutineEngine, readRoutineLaneModel, routineTools, stopRoutines, updateBotRoutineLifecycle } from '../service.js';
import { handleRoutineRequest } from '../../cindy-brain/routineSlot.js';
import type { InstalledGhost } from '../../../shared/ghost.js';
import { companionHomes } from '../../companion-cloud/homes.js';
@@ -117,6 +117,7 @@ it('creates and closes an isolated lane for each fresh routine trigger', async (
const routine = await routineTools.save('bot', {
name: 'Fresh review', prompt: 'Check only this trigger', enabled: true,
sessionMode: 'fresh', triggers: [{ id: 'tick', kind: 'interval', intervalMs: 60000 }],
+ modelOverride: { agentKind: 'codex', model: 'budget', providerId: 'subscription' },
});
await routineTools.runNow('bot', routine.id);
await vi.waitFor(async () => expect((await routineTools.history('bot', routine.id))[0].status).toBe('success'));
@@ -124,6 +125,9 @@ it('creates and closes an isolated lane for each fresh routine trigger', async (
routineId: expect.stringMatching(new RegExp(`^${routine.id}:`)),
}));
expect(mock.closeRoutineSession).toHaveBeenCalledWith(expect.stringMatching(new RegExp(`^lane-${routine.id}:`)));
+ // The per-trigger lane must still send with the routine's own model, not the companion's.
+ const laneRoutineId = mock.ensureRoutineSession.mock.calls[0][0].routineId;
+ expect(await readRoutineLaneModel('bot', `routine:${laneRoutineId}`)).toMatchObject({ agentKind: 'codex', model: 'budget' });
});
it('turns the teammate\'s weekday todo check on and off as one built-in routine', async () => {
diff --git a/apps/desktop/src/main/routines/service.ts b/apps/desktop/src/main/routines/service.ts
index ec7926085a..d142893a72 100644
--- a/apps/desktop/src/main/routines/service.ts
+++ b/apps/desktop/src/main/routines/service.ts
@@ -702,6 +702,8 @@ export async function importCompanionRoutines(botId: string, routines: Companion
for (const id of remove) if (existing.has(id) && !builtinIds.has(id)) await routineTools.remove(botId, id);
}
+const FRESH_LANE_KEY = /^(routine:.+):[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
+
/** Read without starting the scheduler: previews and manual sends may precede engine startup. */
export async function readRoutineLaneModel(botId: string, routeKey: string | null): Promise<RoutineModel | null> {
if (!routeKey?.startsWith('routine:')) return null;
@@ -710,5 +712,10 @@ export async function readRoutineLaneModel(botId: string, routeKey: string | nul
const routines = current?.scope === scope ? current.engine.list(botId)
: (await new RoutineFileStore(ownerScopedUserDataPath()).load())?.routines ?? [];
assertScope(scope);
- return routines.find((routine) => routine.botId === botId && `routine:${routine.id}` === routeKey)?.modelOverride ?? null;
+ const owned = routines.filter((routine) => routine.botId === botId);
+ // Fresh-session lanes append `:<uuid>` per trigger; they still use the routine's model.
+ const freshKey = FRESH_LANE_KEY.exec(routeKey)?.[1];
+ const match = owned.find((routine) => `routine:${routine.id}` === routeKey)
+ ?? (freshKey ? owned.find((routine) => `routine:${routine.id}` === freshKey) : undefined);
+ return match?.modelOverride ?? null;
}
diff --git a/apps/desktop/src/renderer/features/bots/BotRoutines.tsx b/apps/desktop/src/renderer/features/bots/BotRoutines.tsx
index 5d71d78afe..32091cfcb7 100644
--- a/apps/desktop/src/renderer/features/bots/BotRoutines.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotRoutines.tsx
@@ -64,6 +64,7 @@ export function BotRoutines({
const routinesApi = settingsTarget.routines;
const navigate = useNavigate();
const supportsModels = settingsTarget.kind === 'local' || settingsTarget.routineModels === true;
+ const supportsSessionModes = settingsTarget.kind === 'local' || settingsTarget.routineSessionModes === true;
const inFlight = useRef(false);
const [loading, setLoading] = useState(true);
const [reload, setReload] = useState(0);
@@ -429,7 +430,7 @@ export function BotRoutines({
fastMode: route.fastMode, agentDeviceId: route.agentDeviceId ?? null,
} : null })}
/>}
- <div className="space-y-2">
+ {supportsSessionModes && <div className="space-y-2">
<span aria-hidden className={fieldLabelClass}>{t('routines.sessionMode')}</span>
<Select
label={t('routines.sessionMode')}
@@ -444,7 +445,7 @@ export function BotRoutines({
aria-describedby="routine-session-mode-hint"
/>
<p id="routine-session-mode-hint" className="text-12 text-[var(--text-secondary)]">{t('routines.sessionModeHint')}</p>
- </div>
+ </div>}
<fieldset disabled={!!saved?.builtin} className="min-w-0 space-y-5">
<details className="space-y-3">
<summary className="min-h-8 cursor-pointer rounded-full py-2 focus-visible:outline focus-visible:outline-[var(--focus-ring)]">{t('routines.advancedSettings')}</summary>
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/remoteBotSettingsTarget.test.ts b/apps/desktop/src/renderer/features/bots/__tests__/remoteBotSettingsTarget.test.ts
index 81421a653c..df5b7d9f32 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/remoteBotSettingsTarget.test.ts
+++ b/apps/desktop/src/renderer/features/bots/__tests__/remoteBotSettingsTarget.test.ts
@@ -127,6 +127,19 @@ it('does not re-read a deleted teammate after the lifecycle action', async () =>
expect(host.invoke).toHaveBeenCalledTimes(1);
});
+it('offers routine session modes only to hosts that keep them', async () => {
+ // A host that predates session modes accepts saveWithModel but drops sessionMode.
+ const older = create([...ALL_OPS, 'routines.saveWithModel']);
+ expect(older.target.routineSessionModes).toBe(false);
+ host.invoke.mockResolvedValue(ok([]));
+ await older.target.routines.save('bot-1', { name: 'Digest' } as never, 'r1');
+ expect(sent()).toMatchObject({ input: { op: 'routines.saveWithModel' } });
+ const current = create([...ALL_OPS, 'routines.saveWithModel', 'routines.saveWithSessionMode']);
+ expect(current.target.routineSessionModes).toBe(true);
+ await current.target.routines.save('bot-1', { name: 'Digest', sessionMode: 'fresh' } as never, 'r1');
+ expect(sent(1)).toMatchObject({ input: { op: 'routines.saveWithSessionMode', args: { input: { sessionMode: 'fresh' } } } });
+});
+
it('runs routines on the teammate computer and tells the page when they change there', async () => {
const { target, changed } = create();
host.invoke.mockResolvedValue(ok([]));
diff --git a/apps/desktop/src/renderer/features/bots/botSettingsTarget.ts b/apps/desktop/src/renderer/features/bots/botSettingsTarget.ts
index 445593947d..daaa0d6d6d 100644
--- a/apps/desktop/src/renderer/features/bots/botSettingsTarget.ts
+++ b/apps/desktop/src/renderer/features/bots/botSettingsTarget.ts
@@ -84,6 +84,8 @@ export interface BotSettingsTarget {
routines: BotRoutinesApi;
/** Host accepts a persistent independent model selection for each routine. */
routineModels?: boolean;
+ /** Host keeps a routine's session mode (persistent lane or a fresh lane per trigger). */
+ routineSessionModes?: boolean;
autonomy: {
useSettings(): BotAutonomySettingsView | null;
setSchedulerBotId(botId: string | null): Promise<void>;
diff --git a/apps/desktop/src/renderer/features/bots/remoteBotSettingsTarget.ts b/apps/desktop/src/renderer/features/bots/remoteBotSettingsTarget.ts
index 67cb2468e5..e702b9ecd9 100644
--- a/apps/desktop/src/renderer/features/bots/remoteBotSettingsTarget.ts
+++ b/apps/desktop/src/renderer/features/bots/remoteBotSettingsTarget.ts
@@ -356,9 +356,13 @@ export function createRemoteBotSettingsTarget(input: RemoteBotSettingsInput) {
}),
},
routineModels: input.ops.has('routines.saveWithModel'),
+ routineSessionModes: input.ops.has('routines.saveWithSessionMode'),
routines: {
list: (id) => invokeBotSettings(deviceId, 'routines.list', id),
- save: (id, routine, routineId) => invokeBotSettings(deviceId, input.ops.has('routines.saveWithModel') ? 'routines.saveWithModel' : 'routines.save', id, { input: routine, ...(routineId ? { id: routineId } : {}) }),
+ save: (id, routine, routineId) => invokeBotSettings(deviceId,
+ input.ops.has('routines.saveWithSessionMode') ? 'routines.saveWithSessionMode'
+ : input.ops.has('routines.saveWithModel') ? 'routines.saveWithModel' : 'routines.save',
+ id, { input: routine, ...(routineId ? { id: routineId } : {}) }),
async remove(id, routineId) {
await invokeBotSettings(deviceId, 'routines.remove', id, { id: routineId });
},
diff --git a/apps/desktop/src/shared/botRemoteSettings.ts b/apps/desktop/src/shared/botRemoteSettings.ts
index 12c3970b49..88d78460ba 100644
--- a/apps/desktop/src/shared/botRemoteSettings.ts
+++ b/apps/desktop/src/shared/botRemoteSettings.ts
@@ -39,6 +39,7 @@ export const BOT_SETTINGS_OPS = [
'routines.history',
'routines.save',
'routines.saveWithModel',
+ 'routines.saveWithSessionMode',
'routines.runNow',
'routines.remove',
'voice.models',
diff --git a/docs/product-rules/agent-user-parity.md b/docs/product-rules/agent-user-parity.md
index 5985fd6d4d..b4d67a8d4a 100644
--- a/docs/product-rules/agent-user-parity.md
+++ b/docs/product-rules/agent-user-parity.md
@@ -157,6 +157,6 @@ Host 不因当前输入缺少主人标记再追加行动同意判定。只认运
实现见 `maker-ipc/taskActionAuthorization.ts`、`taskActionHost.ts` 与
`mcp-integrations/codexHttpBridge.ts`;回归见各自授权及 HTTP 桥接测试。
-伙伴例行任务(2026-10-26):桌面与 `routine_save` 共用每条规则的 `modelOverride`,可选引擎、来源、型号、执行位置、推理强度与 Fast;null 恢复跟随伙伴,省略保留选择。执行记录返回独立 `sessionId`。内置跟进/每天查待办也可选模型,指令与触发条件仍由宿主维护。跨电脑桌面设置通过 `routines.saveWithModel` 能力声明协商;手机仍按现有合同不提供例行任务管理。
+伙伴例行任务(2026-10-26):桌面与 `routine_save` 共用每条规则的 `modelOverride`,可选引擎、来源、型号、执行位置、推理强度与 Fast;null 恢复跟随伙伴,省略保留选择。执行记录返回独立 `sessionId`。内置跟进/每天查待办也可选模型,指令与触发条件仍由宿主维护。`sessionMode`(`persistent` 复用同一任务/`fresh` 每次触发新建任务)同样经桌面与 `routine_save` 设置,省略保留原值。跨电脑桌面设置通过 `routines.saveWithModel` 与 `routines.saveWithSessionMode` 能力声明协商;手机仍按现有合同不提供例行任务管理。
执行任务的模型可用 `cindy_helper` 的 cindy 类 `report_task_delivery` 报告本轮是否新交付最终结果;只限当前任务执行者,子 Agent 不可代报。三个 Harness 共用此入口;它不结束任务或授予操作权限。跟进通知门控见 `cindy-bots-runtime.md` §6.3。
diff --git a/docs/product-rules/bot-routines.md b/docs/product-rules/bot-routines.md
index ba90f9ac79..d23ecf5a34 100644
--- a/docs/product-rules/bot-routines.md
+++ b/docs/product-rules/bot-routines.md
@@ -26,11 +26,13 @@ Bot Market 原生包的例行任务只通过原导入服务保存停用定义,
每条需要 Agent 执行的例行任务对应一个持久独立 Session(`bot_session_links.role = 'routine'`,`route_key = 'routine:<routineId>'`),重复触发复用,不向伙伴主任务追加执行上下文。它与原伙伴共享 Profile、Home、记忆、技能和实际权限,权限与资料更新同样同步到专线;`list_agents`、`send_to_agent`、`check_agent_message` 沿用同一伙伴身份(含远程回执核验与排队恢复),逐轮行动授权与防循环上限不变;行动身份仍按本轮来源判定,内置跟进不会因独立任务变成主人授权。
+`sessionMode` 决定触发之间是否保留上下文(2026-10-27):`persistent`(缺省,兼容旧规则)复用上面的持久独立任务;`fresh` 每次触发由宿主新建一条同伙伴身份、同权限的独立任务(`route_key = 'routine:<routineId>:<uuid>'`),运行结束后关闭,下次触发不带旧上下文。两种方式都沿用该规则的 `modelOverride`,历史里的「查看任务」仍可打开每次运行的任务。内置规则可改会话方式,不改指令、频率与权限;夜间学习不提供此项。
+
`modelOverride` 可单独选择完整模型路由(引擎、来源、型号、执行位置、推理强度、Fast);缺失或 null 跟随伙伴模型,显式配置不套用伙伴主模型的备用链。旧客户端省略字段时保留已存选择,null 才清除。保存后下一轮通过普通模型切换与交接入口应用;独立任务内继续交流也使用这份配置。每条例行任务最多一个正在执行的运行;等待事件合成一批,各条规则通过各自任务队列派发。
独立任务保留完整执行记录,历史里的「查看任务」打开原有普通任务页面;静默只控制通知,不隐藏执行正文。它不进入自动跟进的观察列表,避免跟进自己的执行。伙伴迁走后,旧电脑上这条任务仍可回看,但普通发送、内部发送和排队派发都不能重新启动它。合成触发输入沿用原有来源说明。夜间学习已有专门宿主流程,不改为这类任务。
-远程桌面沿用同一设置页,通过 `routines.saveWithModel` 能力协商展示选模;旧主机不显示选模,新主机接受旧客户端保存时保留覆盖。手机当前仍无例行任务管理入口。模型配置随普通规则的伙伴迁移资料保留,执行任务与运行历史留在执行电脑。
+远程桌面沿用同一设置页,通过 `routines.saveWithModel` 能力协商展示选模;旧主机不显示选模,新主机接受旧客户端保存时保留覆盖。会话方式另由 `routines.saveWithSessionMode` 协商:只接受 `saveWithModel` 的旧主机会丢弃 `sessionMode`,因此不显示该选项,避免保存成功却仍共用上下文。手机当前仍无例行任务管理入口。模型配置随普通规则的伙伴迁移资料保留,执行任务与运行历史留在执行电脑。
事件、时间与立即运行触发的批次都以独立宿主作用域执行,不继承发布事件或发起调用的 Agent 轮次行动凭证;当前账号、伙伴状态、规则版本及目标任务的权限检查仍然生效。发布方轮次结束不使已接收批次失效,目标独立任务忙碌时沿用下述延期与重试规则。实现与回归见 [service.ts](../../apps/desktop/src/main/routines/service.ts)、[service.test.ts](../../apps/desktop/src/main/routines/__tests__/service.test.ts)(#7044)。