Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(scheduler): preserve runtime device in project automations
davidbf55a033e5fd
diff --git a/apps/desktop/src/main/scheduler-host/__tests__/project-automation-loader.test.ts b/apps/desktop/src/main/scheduler-host/__tests__/project-automation-loader.test.tsindex a845af25de..729ea57048 100644--- a/apps/desktop/src/main/scheduler-host/__tests__/project-automation-loader.test.ts+++ b/apps/desktop/src/main/scheduler-host/__tests__/project-automation-loader.test.ts@@ -3,7 +3,7 @@ import { promises as fs } from 'node:fs';import { tmpdir } from 'node:os';import * as path from 'node:path';-import type { Schedule } from '@cindy/maker-scheduler';+import type { CreateScheduleInput, Schedule } from '@cindy/maker-scheduler';import {__testing,@@ -83,6 +83,51 @@ describe('project automation WeCom group notification reconciliation', () => {});describe('project automation provider reconciliation', () => {+ // PR #6832, unit: real file upsert/reconcile plus DB mappers. Existing provider+ // coverage did not distinguish a device-only edit or removal from no change.+ it('persists, changes and clears the runtime location through project reconciliation', async () => {+ const dir = await fs.mkdtemp(path.join(tmpdir(), 'cindy-project-device-'));+ try {+ let saved: Schedule | undefined;+ const create = vi.fn(async (input: CreateScheduleInput) => {+ saved = scheduleToCamel(scheduleCreateToRow({+ ...projectSchedule({ desktop: true, feishu: false }), ...input,+ } as Schedule) as Parameters<typeof scheduleToCamel>[0]);+ return saved;+ });+ const update = vi.fn(async (_id: string, patch: Partial<Schedule>) => {+ saved = scheduleToCamel({+ ...scheduleCreateToRow(saved!), ...schedulePatchToRow(patch),+ } as Parameters<typeof scheduleToCamel>[0]);+ return saved;+ });+ const loader = new ProjectAutomationLoader({+ scheduler: { create, update } as unknown as ConstructorParameters<typeof ProjectAutomationLoader>[0]['scheduler'],+ storage: { list: async () => saved ? [saved] : [] } as ConstructorParameters<typeof ProjectAutomationLoader>[0]['storage'],+ getDb: () => ({+ select: () => ({ from: () => ({ where: () => ({ limit: async () => [] }) }) }),+ insert: () => ({ values: () => ({ onConflictDoUpdate: async () => {} }) }),+ }) as unknown as ReturnType<ConstructorParameters<typeof ProjectAutomationLoader>[0]['getDb']>,+ logger: { warn: vi.fn(), debug: vi.fn() },+ });+ const config = { ...projectConfig({ model: 'remote-model', providerId: 'remote-provider' }), agentDeviceId: 'studio' };+ expect(await loader.upsertSchedule(dir, config)).toMatchObject({ inserted: 1, updated: 0 });+ expect(saved).toMatchObject({ agentDeviceId: 'studio', model: 'remote-model', providerId: 'remote-provider' });+ expect(await loader.reconcile(dir)).toMatchObject({ inserted: 0, updated: 0 });+ expect(await loader.upsertSchedule(dir, { ...config, agentDeviceId: 'shared-device' }))+ .toMatchObject({ updated: 1 });+ expect(saved?.agentDeviceId).toBe('shared-device');+ expect(await loader.upsertSchedule(dir, { ...config, agentDeviceId: undefined }))+ .toMatchObject({ updated: 1 });+ expect(saved?.agentDeviceId).toBeUndefined();+ expect(saved?.providerId).toBe('remote-provider');+ expect(await loader.reconcile(dir)).toMatchObject({ updated: 0 });+ expect(update).toHaveBeenCalledTimes(2);+ } finally {+ await fs.rm(dir, { recursive: true, force: true });+ }+ });+it('passes an explicit provider through the loader input and detects changes', () => {const config = projectConfig({ providerId: 'openai' });const input = __testing.scheduleConfigToUpdateInput(config, workingDir);@@ -124,6 +169,10 @@ describe('project automation explicit Harness reconciliation', () => {{ override: { modelAgentKind: 'pi', model: 'test-model' }, valid: true },{ override: { modelAgentKind: 'invalid', model: 'test-model' }, valid: false },{ override: { modelAgentKind: 'pi' }, valid: false },+ { override: { agentDeviceId: 'studio', model: 'remote-model' }, valid: true },+ { override: { agentDeviceId: '../invalid', model: 'remote-model' }, valid: false },+ { override: { agentDeviceId: 42, model: 'remote-model' }, valid: false },+ { override: { agentDeviceId: 'studio' }, valid: false },])('loads version 1 project files with compatible Harness validation: %j', async ({ override, valid }) => {const dir = await fs.mkdtemp(path.join(tmpdir(), 'cindy-project-harness-'));try {diff --git a/apps/desktop/src/main/scheduler-host/project-automation-loader.ts b/apps/desktop/src/main/scheduler-host/project-automation-loader.tsindex 4a3caaabdb..3c0104603d 100644--- a/apps/desktop/src/main/scheduler-host/project-automation-loader.ts+++ b/apps/desktop/src/main/scheduler-host/project-automation-loader.ts@@ -53,6 +53,8 @@ export interface ProjectScheduleConfig {model?: string;/** 可选:显式来源(供应商)id。省略 → 走原生默认来源(与旧配置字节级一致)。详见 Schedule.providerId。 */providerId?: string;+ /** Agent 运行位置,相对项目自动化所在电脑;省略 = 本机。 */+ agentDeviceId?: string;effort?: string;/** Codex Fast 模式开关,仅 Codex 有意义。详见 Schedule.fastMode。 */fastMode?: boolean | 'ultrafast';@@ -459,6 +461,8 @@ function scheduleConfigToCreateInput(modelAgentKind: config.modelAgentKind,model: config.model,providerId: config.providerId,+ // 恒带 key:配置删掉运行位置时清除已保存的位置。+ agentDeviceId: config.agentDeviceId,effort: config.effort,fastMode: config.fastMode,workspaceKind: 'project',@@ -500,6 +504,7 @@ export function schedulesDiffer(schedule.modelAgentKind !== expected.modelAgentKind ||schedule.model !== expected.model ||(schedule.providerId ?? undefined) !== (expected.providerId ?? undefined) ||+ (schedule.agentDeviceId ?? undefined) !== (expected.agentDeviceId ?? undefined) ||schedule.effort !== expected.effort ||(schedule.fastMode ?? false) !== (expected.fastMode ?? false) ||schedule.workspaceKind !== expected.workspaceKind ||@@ -570,6 +575,10 @@ function isProjectScheduleConfig(value: unknown): value is ProjectScheduleConfig(config.modelAgentKind === undefined || (typeof config.model === 'string' && config.model.trim() !== '')) &&optionalString(config.model) &&optionalString(config.providerId) &&+ (config.agentDeviceId === undefined || (+ typeof config.agentDeviceId === 'string' && /^[A-Za-z0-9_.:-]{1,128}$/.test(config.agentDeviceId) &&+ typeof config.model === 'string' && config.model.trim() !== ''+ )) &&optionalString(config.effort) &&(optionalBoolean(config.fastMode) || config.fastMode === 'ultrafast') &&optionalBoolean(config.useWorktree) &&diff --git a/apps/desktop/src/renderer/features/scheduler/lib/__tests__/projectAutomationConfig.test.ts b/apps/desktop/src/renderer/features/scheduler/lib/__tests__/projectAutomationConfig.test.tsindex 907a1f9a02..2fc15cede7 100644--- a/apps/desktop/src/renderer/features/scheduler/lib/__tests__/projectAutomationConfig.test.ts+++ b/apps/desktop/src/renderer/features/scheduler/lib/__tests__/projectAutomationConfig.test.ts@@ -57,6 +57,20 @@ describe('formToProjectConfig fastMode', () => {});describe('project automation providerId serialization', () => {+ // PR #6832: promotion and subsequent edits must keep the provider's device.+ // Unit: both production projections cross JSON, which previously lost it.+ it('preserves the runtime location through promotion and form edits', () => {+ const route = { model: 'remote-model', providerId: 'remote-provider', agentDeviceId: 'studio' };+ const promoted = JSON.parse(JSON.stringify(scheduleToProjectConfig({+ id: 's1', name: 'n', prompt: 'p', cronExpr: '0 9 * * *', ...route,+ } as Schedule, 'daily')));+ expect(promoted).toMatchObject(route);+ const form = makeForm(route);+ expect(JSON.parse(JSON.stringify(formToProjectConfig(form, 'daily')))).toMatchObject(route);+ expect(JSON.parse(JSON.stringify(formToProjectConfig({ ...form, agentDeviceId: undefined }, 'daily'))))+ .not.toHaveProperty('agentDeviceId');+ });+it('preserves an explicit provider from the form', () => {expect(formToProjectConfig(makeForm({ providerId: 'openai' }), 'auto-provider').providerId).toBe('openai',diff --git a/apps/desktop/src/renderer/features/scheduler/lib/projectAutomationConfig.ts b/apps/desktop/src/renderer/features/scheduler/lib/projectAutomationConfig.tsindex 8a4a291be5..6237088ecb 100644--- a/apps/desktop/src/renderer/features/scheduler/lib/projectAutomationConfig.ts+++ b/apps/desktop/src/renderer/features/scheduler/lib/projectAutomationConfig.ts@@ -20,6 +20,8 @@ export interface ProjectScheduleConfig {model?: string;/** 显式来源(供应商)id;省略 = 使用该 Agent 的原生默认来源。 */providerId?: string;+ /** Agent 运行位置,相对项目自动化所在电脑;省略 = 本机。 */+ agentDeviceId?: string;effort?: string;/** Codex Fast 模式开关,仅 Codex 有意义。详见 Schedule.fastMode。 */fastMode?: boolean | 'ultrafast';@@ -63,6 +65,7 @@ export function scheduleToProjectConfig(modelAgentKind: schedule.modelAgentKind,model: schedule.model,providerId: schedule.providerId || undefined,+ agentDeviceId: schedule.agentDeviceId,effort: schedule.effort,fastMode: schedule.fastMode,useWorktree: schedule.useWorktree,@@ -93,6 +96,7 @@ export function formToProjectConfig(modelAgentKind: form.model.trim() ? form.modelAgentKind : undefined,model: form.model.trim() || undefined,providerId: form.providerId.trim() || undefined,+ agentDeviceId: form.model.trim() ? form.agentDeviceId?.trim() || undefined : undefined,effort: form.effort || undefined,// Codex / Pi 都生效(runner.ts:665);只认 codex 会丢弃 Pi 任务的 Fast(codex review)。fastMode: (form.agentKind === 'codex' || form.agentKind === 'pi') && form.fastMode ? true : undefined,diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex ad0e0cbb56..13b537651b 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -599,6 +599,12 @@ SSH 主机不自动成为设备目录成员。实现与回归见 `mcp-integratio`null` 同样表示回到本机。`cindy_scheduler` 跨电脑修改定时任务时拒绝设置 `agentDeviceId`,因为位置 id只对定时任务所在电脑有意义。+项目自动化的 `.cindy/automations/schedules.json`(version 1)与既有 upsert 参数也保留可选+`agentDeviceId`:提升用户自动化、表单编辑和文件同步均与模型/供应商一起保存,字段删除时+清除已保存的位置。新 host 校验设备 ID 格式且要求显式模型;实际运行仍按当前账号的既有+远程/分享授权校验,不因配置文件带了设备 ID 而获得授权。旧配置省略时继续使用本机;旧客户端+不支持该字段,提升或编辑时可能丢失运行位置,远端项目自动化需使用支持此字段的客户端维护。+## Agent 跨电脑管理定时任务与发消息产品规则见 [`../product-rules/agent-user-parity.md`](../product-rules/agent-user-parity.md)。