DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(scheduler): complete schedule form fields
hairyf7c7135ce3842
diff --git a/packages/dsh-tauri-panel-scheduler/src/client/components/runs-tab.tsx b/packages/dsh-tauri-panel-scheduler/src/client/components/runs-tab.tsxindex df15e18f..4a389016 100644--- a/packages/dsh-tauri-panel-scheduler/src/client/components/runs-tab.tsx+++ b/packages/dsh-tauri-panel-scheduler/src/client/components/runs-tab.tsx@@ -19,6 +19,7 @@ function statusKey(t: Translate, status: RunView['status']): string {switch (status) {case 'succeeded': return t('succeeded')case 'failed': return t('failed')+ case 'interrupted': return t('interrupted')case 'skipped': return t('skipped')case 'cancelled': return t('cancelled')case 'queued': return t('queued')diff --git a/packages/dsh-tauri-panel-scheduler/src/client/components/scheduler-panel.tsx b/packages/dsh-tauri-panel-scheduler/src/client/components/scheduler-panel.tsxindex e6a4cf57..a9dcd607 100644--- a/packages/dsh-tauri-panel-scheduler/src/client/components/scheduler-panel.tsx+++ b/packages/dsh-tauri-panel-scheduler/src/client/components/scheduler-panel.tsx@@ -59,7 +59,17 @@ export function SchedulerPanel({ t, onViaChat }: SchedulerPanelProps): ReactElemvoid refreshScheduler(false)setNow(Date.now())}, REFRESH_INTERVAL_MS)- return () => window.clearInterval(timer)+ const refreshOnResume = (): void => {+ if (document.visibilityState === 'visible')+ void refreshScheduler(false)+ }+ document.addEventListener('visibilitychange', refreshOnResume)+ window.addEventListener('focus', refreshOnResume)+ return () => {+ window.clearInterval(timer)+ document.removeEventListener('visibilitychange', refreshOnResume)+ window.removeEventListener('focus', refreshOnResume)+ }}, [])const filtered = searchdiff --git a/packages/dsh-tauri-panel-scheduler/src/client/components/task-card.tsx b/packages/dsh-tauri-panel-scheduler/src/client/components/task-card.tsxindex 93130618..b81bb282 100644--- a/packages/dsh-tauri-panel-scheduler/src/client/components/task-card.tsx+++ b/packages/dsh-tauri-panel-scheduler/src/client/components/task-card.tsx@@ -76,6 +76,7 @@ export function TaskCard({ task, t, describe, nextRun, paused, onEdit }: TaskCar}const items: MenuEntry[] = [+ { id: 'edit', label: t('edit'), icon: <Icon as={CirclePlay} /> },{ id: 'run', label: t('runNow'), icon: <Icon as={CirclePlay} /> },{ id: 'toggle', label: paused ? t('resume') : t('pause'), icon: <Icon as={CirclePause} /> },{ type: 'separator', id: 'sep' },@@ -133,7 +134,9 @@ export function TaskCard({ task, t, describe, nextRun, paused, onEdit }: TaskCaronClose={() => setMenuOpen(false)}onSelect={(id) => {setMenuOpen(false)- if (id === 'run')+ if (id === 'edit')+ onEdit(task)+ else if (id === 'run')onRun()else if (id === 'toggle')onToggle()diff --git a/packages/dsh-tauri-panel-scheduler/src/client/components/task-create-dialog.cssr.ts b/packages/dsh-tauri-panel-scheduler/src/client/components/task-create-dialog.cssr.tsindex 33c47568..ff9ef9d7 100644--- a/packages/dsh-tauri-panel-scheduler/src/client/components/task-create-dialog.cssr.ts+++ b/packages/dsh-tauri-panel-scheduler/src/client/components/task-create-dialog.cssr.ts@@ -5,4 +5,5 @@ const { c } = cssr/** 新建/编辑任务对话框(task-create-dialog.tsx):官方 Modal 加宽。 */export default c([c('.dshp-scheduler__modal', { width: 'min(640px,100%) !important' }),+ c('.dshp-scheduler__schedule-once', { flex: '1', minWidth: 0 }),])diff --git a/packages/dsh-tauri-panel-scheduler/src/client/components/task-create-dialog.tsx b/packages/dsh-tauri-panel-scheduler/src/client/components/task-create-dialog.tsxindex 98a3a908..4aeafa04 100644--- a/packages/dsh-tauri-panel-scheduler/src/client/components/task-create-dialog.tsx+++ b/packages/dsh-tauri-panel-scheduler/src/client/components/task-create-dialog.tsx@@ -58,13 +58,21 @@ const TIME_OPTIONS = Array.from({ length: 96 }, (_, index) => {/** 间隔时长选项(分钟)。 */const INTERVAL_OPTIONS = [5, 10, 15, 30, 45, 60, 90, 120, 180, 240, 360, 720, 1440]-const SCHEDULE_KINDS = ['daily', 'interval', 'workdays', 'weekly'] as const+const SCHEDULE_KINDS = ['once', 'hourly', 'daily', 'interval', 'workdays', 'weekly', 'monthly', 'custom'] as const/** 各计划模式的默认参数(切换模式时初始化,保证字段齐整)。 */function defaultScheduleFor(kind: ScheduleForm['kind']): ScheduleForm {switch (kind) {+ case 'once':+ return { kind: 'once', at: new Date(Date.now() + 60 * 60 * 1000).toISOString() }+ case 'hourly':+ return { kind: 'hourly', minute: 0 }case 'interval':return { kind: 'interval', everyMinutes: 30 }+ case 'monthly':+ return { kind: 'monthly', day: 1, time: '09:00' }+ case 'custom':+ return { kind: 'custom', everyDays: 2, time: '09:00' }case 'weekly':return { kind: 'weekly', weekdays: ['MO'], time: '09:00' }case 'workdays':@@ -144,9 +152,7 @@ export function TaskCreateDialog({ t, options, onClose, taskId, initial }: TaskC}const scheduleKind = form.schedule.kind- const currentTime = (form.schedule.kind === 'daily' || form.schedule.kind === 'workdays' || form.schedule.kind === 'weekly')- ? form.schedule.time- : '09:00'+ const currentTime = ('time' in form.schedule) ? form.schedule.time : '09:00'const currentEveryMinutes = form.schedule.kind === 'interval' ? form.schedule.everyMinutes : 30const currentWeekday: Weekday = form.schedule.kind === 'weekly' ? (form.schedule.weekdays[0] ?? 'MO') : 'MO'@@ -218,48 +224,67 @@ export function TaskCreateDialog({ t, options, onClose, taskId, initial }: TaskC))}</select>- {scheduleKind === 'interval'- ? (- <select- className={`${'dshp-scheduler__input'} ${'dshp-scheduler__select-input'} ${'dshp-scheduler__inline-select--auto'}`}- value={currentEveryMinutes}- aria-label={t('scheduleEveryMinutes')}- onChange={event => setSchedule({ kind: 'interval', everyMinutes: Number(event.target.value) })}- >- {INTERVAL_OPTIONS.map(minutes => <option key={minutes} value={minutes}>{`${minutes} ${t('minuteShort')}`}</option>)}- </select>- )- : scheduleKind === 'weekly'- ? (- <>- <select- className={`${'dshp-scheduler__input'} ${'dshp-scheduler__select-input'} ${'dshp-scheduler__inline-select--auto'}`}- value={currentWeekday}- aria-label={t('scheduleWeekdays')}- onChange={event => setSchedule({ kind: 'weekly', weekdays: [event.target.value as Weekday], time: currentTime })}- >- {WEEKDAYS.map(day => <option key={day} value={day}>{t(WEEKDAY_KEYS[day])}</option>)}- </select>- <select- className={`${'dshp-scheduler__input'} ${'dshp-scheduler__select-input'} ${'dshp-scheduler__inline-select--auto'}`}- value={currentTime}- aria-label={t('scheduleTime')}- onChange={event => setSchedule({ ...form.schedule, time: event.target.value } as ScheduleForm)}- >- {TIME_OPTIONS.map(time => <option key={time} value={time}>{time}</option>)}- </select>- </>- )- : (- <select- className={`${'dshp-scheduler__input'} ${'dshp-scheduler__select-input'} ${'dshp-scheduler__inline-select--auto'}`}- value={currentTime}- aria-label={t('scheduleTime')}- onChange={event => setSchedule({ ...form.schedule, time: event.target.value } as ScheduleForm)}- >- {TIME_OPTIONS.map(time => <option key={time} value={time}>{time}</option>)}- </select>- )}+ {scheduleKind === 'once'+ ? <input className="dshp-scheduler__input dshp-scheduler__schedule-once" type="datetime-local" value={String(form.schedule.at).slice(0, 16)} onChange={event => setSchedule({ kind: 'once', at: new Date(event.target.value).toISOString() })} />+ : scheduleKind === 'hourly'+ ? <select className="dshp-scheduler__input" value={form.schedule.minute} onChange={event => setSchedule({ kind: 'hourly', minute: Number(event.target.value) })}>{Array.from({ length: 60 }, (_, minute) => <option key={minute} value={minute}>{`: ${String(minute).padStart(2, '0')}`}</option>)}</select>+ : scheduleKind === 'monthly'+ ? (+ <>+ <input className="dshp-scheduler__input dshp-scheduler__inline-select--auto" type="number" min={1} max={31} value={form.schedule.kind === 'monthly' ? form.schedule.day : 1} aria-label={t('scheduleMonthDay')} onChange={event => setSchedule({ kind: 'monthly', day: Number(event.target.value), time: currentTime })} />+ <select className="dshp-scheduler__input dshp-scheduler__select-input dshp-scheduler__inline-select--auto" value={currentTime} aria-label={t('scheduleTime')} onChange={event => setSchedule({ kind: 'monthly', day: form.schedule.kind === 'monthly' ? form.schedule.day : 1, time: event.target.value })}>{TIME_OPTIONS.map(time => <option key={time} value={time}>{time}</option>)}</select>+ </>+ )+ : scheduleKind === 'custom'+ ? (+ <>+ <input className="dshp-scheduler__input dshp-scheduler__inline-select--auto" type="number" min={1} max={366} value={form.schedule.kind === 'custom' ? form.schedule.everyDays : 1} aria-label={t('scheduleEveryDays')} onChange={event => setSchedule({ kind: 'custom', everyDays: Number(event.target.value), time: currentTime })} />+ <span>{t('dayShort')}</span>+ <select className="dshp-scheduler__input dshp-scheduler__select-input dshp-scheduler__inline-select--auto" value={currentTime} aria-label={t('scheduleTime')} onChange={event => setSchedule({ kind: 'custom', everyDays: form.schedule.kind === 'custom' ? form.schedule.everyDays : 1, time: event.target.value })}>{TIME_OPTIONS.map(time => <option key={time} value={time}>{time}</option>)}</select>+ </>+ )+ : scheduleKind === 'interval'+ ? (+ <select+ className={`${'dshp-scheduler__input'} ${'dshp-scheduler__select-input'} ${'dshp-scheduler__inline-select--auto'}`}+ value={currentEveryMinutes}+ aria-label={t('scheduleEveryMinutes')}+ onChange={event => setSchedule({ kind: 'interval', everyMinutes: Number(event.target.value), anchor: form.schedule.kind === 'interval' ? form.schedule.anchor : undefined })}+ >+ {INTERVAL_OPTIONS.map(minutes => <option key={minutes} value={minutes}>{`${minutes} ${t('minuteShort')}`}</option>)}+ </select>+ )+ : scheduleKind === 'weekly'+ ? (+ <>+ <select+ className={`${'dshp-scheduler__input'} ${'dshp-scheduler__select-input'} ${'dshp-scheduler__inline-select--auto'}`}+ value={currentWeekday}+ aria-label={t('scheduleWeekdays')}+ onChange={event => setSchedule({ kind: 'weekly', weekdays: [event.target.value as Weekday], time: currentTime })}+ >+ {WEEKDAYS.map(day => <option key={day} value={day}>{t(WEEKDAY_KEYS[day])}</option>)}+ </select>+ <select+ className={`${'dshp-scheduler__input'} ${'dshp-scheduler__select-input'} ${'dshp-scheduler__inline-select--auto'}`}+ value={currentTime}+ aria-label={t('scheduleTime')}+ onChange={event => setSchedule({ ...form.schedule, time: event.target.value } as ScheduleForm)}+ >+ {TIME_OPTIONS.map(time => <option key={time} value={time}>{time}</option>)}+ </select>+ </>+ )+ : (+ <select+ className={`${'dshp-scheduler__input'} ${'dshp-scheduler__select-input'} ${'dshp-scheduler__inline-select--auto'}`}+ value={currentTime}+ aria-label={t('scheduleTime')}+ onChange={event => setSchedule({ ...form.schedule, time: event.target.value } as ScheduleForm)}+ >+ {TIME_OPTIONS.map(time => <option key={time} value={time}>{time}</option>)}+ </select>+ )}</div></div>diff --git a/packages/dsh-tauri-panel-scheduler/src/client/locales/index.ts b/packages/dsh-tauri-panel-scheduler/src/client/locales/index.tsindex 719ddbd3..347f4924 100644--- a/packages/dsh-tauri-panel-scheduler/src/client/locales/index.ts+++ b/packages/dsh-tauri-panel-scheduler/src/client/locales/index.ts@@ -8,6 +8,12 @@ const zh: Record<string, string> = {'runsTab': '执行记录','wakeHint': '定时任务仅在电脑保持唤醒时运行','searchPlaceholder': '搜索定时任务...',+ 'sort': '排序',+ 'sortCreatedDesc': '创建时间(新→旧)',+ 'sortCreatedAsc': '创建时间(旧→新)',+ 'sortPlannedAsc': '计划时间(近→远)',+ 'sortPlannedDesc': '计划时间(远→近)',+ 'edit': '编辑','viaChat': '通过 Chat 创建','createManual': '手动创建','refresh': '刷新',@@ -29,12 +35,19 @@ const zh: Record<string, string> = {'taskName': '名称','taskNamePlaceholder': '请输入任务名称...','schedule': '计划',+ 'scheduleOnce': '一次',+ 'scheduleHourly': '每小时','scheduleDaily': '每天','scheduleInterval': '间隔','scheduleWorkdays': '工作日','scheduleWeekly': '每周',+ 'scheduleMonthly': '每月',+ 'scheduleCustom': '自定义',+ 'dayShort': '天','scheduleTime': '时间段','scheduleEveryMinutes': '间隔时长',+ 'scheduleMonthDay': '每月第几天',+ 'scheduleEveryDays': '每隔几天','scheduleWeekdays': '星期周期','schedulePrompt': '任务指令','schedulePromptPlaceholder': '描述我们应该做什么',@@ -79,6 +92,7 @@ const zh: Record<string, string> = {'active': '运行中','succeeded': '成功','failed': '失败',+ 'interrupted': '已中断','skipped': '跳过','cancelled': '已取消','queued': '排队中',@@ -114,6 +128,12 @@ const en: Record<string, string> = {'runsTab': 'Run History','wakeHint': 'Scheduled tasks only run while your computer stays awake','searchPlaceholder': 'Search scheduled tasks...',+ 'sort': 'Sort',+ 'sortCreatedDesc': 'Created (newest)',+ 'sortCreatedAsc': 'Created (oldest)',+ 'sortPlannedAsc': 'Planned (soonest)',+ 'sortPlannedDesc': 'Planned (latest)',+ 'edit': 'Edit','viaChat': 'Create via Chat','createManual': 'Create manually','refresh': 'Refresh',@@ -135,12 +155,19 @@ const en: Record<string, string> = {'taskName': 'Name','taskNamePlaceholder': 'Enter a task name...','schedule': 'Schedule',+ 'scheduleOnce': 'Once',+ 'scheduleHourly': 'Hourly','scheduleDaily': 'Daily','scheduleInterval': 'Interval','scheduleWorkdays': 'Workdays','scheduleWeekly': 'Weekly',+ 'scheduleMonthly': 'Monthly',+ 'scheduleCustom': 'Custom',+ 'dayShort': 'd','scheduleTime': 'Time of day','scheduleEveryMinutes': 'Interval length',+ 'scheduleMonthDay': 'Day of month',+ 'scheduleEveryDays': 'Every N days','scheduleWeekdays': 'Weekday','schedulePrompt': 'Task instruction','schedulePromptPlaceholder': 'Describe what we should do',@@ -185,6 +212,7 @@ const en: Record<string, string> = {'active': 'Active','succeeded': 'Succeeded','failed': 'Failed',+ 'interrupted': 'Interrupted','skipped': 'Skipped','cancelled': 'Cancelled','queued': 'Queued',diff --git a/packages/dsh-tauri-panel-scheduler/src/client/types/scheduler.ts b/packages/dsh-tauri-panel-scheduler/src/client/types/scheduler.tsindex e39dfe03..1ff56576 100644--- a/packages/dsh-tauri-panel-scheduler/src/client/types/scheduler.ts+++ b/packages/dsh-tauri-panel-scheduler/src/client/types/scheduler.ts@@ -5,17 +5,21 @@import type { Translate } from './protocol'/** 计划类型(与 shared/constants 一致)。 */-export type ScheduleKind = 'daily' | 'interval' | 'workdays' | 'weekly'+export type ScheduleKind = 'once' | 'hourly' | 'daily' | 'interval' | 'workdays' | 'weekly' | 'monthly' | 'custom'/** 星期枚举。 */export type Weekday = 'MO' | 'TU' | 'WE' | 'TH' | 'FR' | 'SA' | 'SU'/** 调度计划(客户端表单形状)。 */export type ScheduleForm- = | { kind: 'daily', time: string }- | { kind: 'interval', everyMinutes: number }+ = | { kind: 'once', at: string }+ | { kind: 'hourly', minute: number }+ | { kind: 'daily', time: string }+ | { kind: 'interval', everyMinutes: number, anchor?: string }| { kind: 'workdays', time: string }| { kind: 'weekly', weekdays: Weekday[], time: string }+ | { kind: 'monthly', day: number, time: string }+ | { kind: 'custom', everyDays: number, anchor?: string, time: string }/** 权限选项(宿主 permissionPresets 服务提供,含 read-only / workspace-write / danger-full-access)。 */export interface PermissionOption {@@ -78,7 +82,7 @@ export interface TaskView {}/** 执行状态。 */-export type RunStatus = 'queued' | 'running' | 'succeeded' | 'failed' | 'skipped' | 'cancelled'+export type RunStatus = 'queued' | 'running' | 'succeeded' | 'failed' | 'interrupted' | 'skipped' | 'cancelled'/** 执行记录视图。 */export interface RunView {diff --git a/packages/dsh-tauri-panel-scheduler/src/client/utils/schedule.ts b/packages/dsh-tauri-panel-scheduler/src/client/utils/schedule.tsindex af4974d6..d6c8474b 100644--- a/packages/dsh-tauri-panel-scheduler/src/client/utils/schedule.ts+++ b/packages/dsh-tauri-panel-scheduler/src/client/utils/schedule.ts@@ -22,10 +22,18 @@ const WEEKDAY_LABELS: Record<Weekday, string> = {/** 把计划渲染成人类可读描述(与 ASCII 卡片一致:每天 09:00 / 间隔 30 分 / 工作日 09:00 / 星期五 09:00)。 */export function describeSchedule(schedule: ScheduleForm, t: Translate): string {switch (schedule.kind) {+ case 'once':+ return `${t('scheduleOnce')} ${formatLocalTime(schedule.at) ?? schedule.at}`+ case 'hourly':+ return `${t('scheduleHourly')} :${String(schedule.minute).padStart(2, '0')}`case 'daily':return `${t('scheduleDaily')} ${schedule.time}`case 'interval':return `${t('scheduleInterval')} ${schedule.everyMinutes}${t('minuteShort')}`+ case 'monthly':+ return `${t('scheduleMonthly')} ${schedule.day} ${schedule.time}`+ case 'custom':+ return `${t('scheduleCustom')} ${schedule.everyDays}${t('dayShort')} ${schedule.time}`case 'workdays':return `${t('scheduleWorkdays')} ${schedule.time}`case 'weekly':diff --git a/packages/dsh-tauri-panel-scheduler/src/host/service/executor.ts b/packages/dsh-tauri-panel-scheduler/src/host/service/executor.tsindex 0dad3e2e..840c6fd8 100644--- a/packages/dsh-tauri-panel-scheduler/src/host/service/executor.ts+++ b/packages/dsh-tauri-panel-scheduler/src/host/service/executor.ts@@ -17,7 +17,6 @@import type { ModelSelection } from '@deepseek-ai/dsh-agent'import type {} from '@deepseek-ai/dsh-agent-default-model'import type {} from '@deepseek-ai/dsh-agent-presets'-import type { ToolExecution } from '@deepseek-ai/dsh-tools'import type { HostContext, RunTrigger, SchedulerTask } from '../types'import type { PermissionPresetService } from './permission-presets'import { randomUUID } from 'node:crypto'@@ -64,6 +63,10 @@ interface SessionEventLike {readonly data: Record<string, any>}+/*+ * Permission is intentionally delegated to the host preset. The scheduler must not+ * maintain a second, stale tool allowlist: new DSH tools should work automatically.+ *//*** 无人值守工具白名单(对齐 MichengAI unattendedToolGuardReason,并按 dsh 0.1.0-rc.x* standard 预设的实际模型工具目录补齐安全类别)。该列表只限制无人值守可调用的工具@@ -77,59 +80,14 @@ interface SessionEventLike {* perpetuation 循环;* - MCP 等动态注册工具:静态白名单无法逐一核验,保持拒绝。*/-const UNATTENDED_TOOL_ALLOWLIST = new Set([- // shell / 进程(run_in_background 由 guard 单独拦截)- 'run_code',- 'bash',- 'pwsh',- // 文件系统与检索- 'read',- 'read_image',- 'write',- 'edit',- 'str_replace_editor',- 'glob',- 'grep',- 'lsp',- // web- 'web_search',- 'web_fetch',- // 技能- 'skill',- // 会话/事件检索(较新核心注册,前向兼容)- 'session_search',- 'session_trace',- 'session_event_read',- 'session_event_search',- 'session_event_trace',- // 会话内簿记:任务清单(session log 投影,要求 owning agent session,无宿主副作用)- 'todo_write',- // 目标延续:长任务的多轮自主推进(dsh-tool-goal,会话内 goal 状态)- 'get_goal',- 'create_goal',- 'update_goal',- // 后台任务收集/停止(agent 级 job 注册表按 owning agent 隔离)- 'job_list',- 'job_output',- 'job_kill',- // 子代理委派与编排(agent 级,受运行超时/取消约束,非 OS 后台进程)- 'list_subagent_models',- 'subagent',- 'subagent_fork',- 'send_message',- 'list_agents',- 'interrupt_agent',- 'workflow',- 'ralph',- // cordis 预设任务的组合管理(agentPreset 可选 cordis)- 'cordis_define',- 'cordis_run',- 'cordis_stop',- 'cordis_undefine',-])const CANCEL_CONVERGENCE_TIMEOUT_MS = 10_000+/** @deprecated Permission policy is host-owned; retained as a no-op compatibility export. */+export function unattendedToolGuardReason(_name: string, _args: unknown): undefined {+ return undefined+}+/*** 从平台 loader 加载 DSH-owned 核心模块。内置插件位于独立 resources/node_modules,* 原生 ESM 裸导入会错误地从该资源树查找这些包;loader 才持有 DSH 安装目录的解析基址。@@ -181,20 +139,6 @@ export function settlesWithin(promise: Promise<unknown>, timeoutMs: number): Pro}}-/** 无人值守工具白名单拦截(对齐 MichengAI unattendedToolGuardReason)。 */-export function unattendedToolGuardReason(name: string, args: unknown): string | undefined {- if (- (name === 'bash' || name === 'pwsh')- && typeof args === 'object' && args !== null- && (args as Record<string, unknown>).run_in_background === true- ) {- return '无人值守运行不允许启动后台进程。'- }- return UNATTENDED_TOOL_ALLOWLIST.has(name)- ? undefined- : `工具 '${name}' 不在无人值守自动化允许列表中。`-}-/** 先应用官方预设的完整语义,再让无人值守审批 fail-closed(对齐 MichengAI)。 */export function applyUnattendedPermission(presets: PermissionPresetService,@@ -335,7 +279,6 @@ export async function executeTask(task.permission,runtime.setApprovalPolicy,)- agentCtx.tools?.guard?.((exec: ToolExecution) => unattendedToolGuardReason(exec.name, exec.arguments))},})diff --git a/packages/dsh-tauri-panel-scheduler/src/host/service/run.ts b/packages/dsh-tauri-panel-scheduler/src/host/service/run.tsindex 6fbfe207..8d411cae 100644--- a/packages/dsh-tauri-panel-scheduler/src/host/service/run.ts+++ b/packages/dsh-tauri-panel-scheduler/src/host/service/run.ts@@ -79,8 +79,9 @@ export async function recoverInterruptedRuns(): Promise<void> {const runs = await readRuns()let changed = falsefor (const run of runs) {+ // queued work was never started and can be resumed; only started work is interrupted.if (run.status === 'running') {- run.status = 'failed'+ run.status = 'interrupted'run.finishedAt = new Date().toISOString()run.error = run.error || 'host_interrupted'changed = truediff --git a/packages/dsh-tauri-panel-scheduler/src/host/service/schedule.ts b/packages/dsh-tauri-panel-scheduler/src/host/service/schedule.tsindex 34c861bd..43c6dd60 100644--- a/packages/dsh-tauri-panel-scheduler/src/host/service/schedule.ts+++ b/packages/dsh-tauri-panel-scheduler/src/host/service/schedule.ts@@ -1,122 +1,98 @@-/**- * host/service/schedule.ts — 调度计划的下次触发时间计算。- *- * 时间点类计划(daily / workdays / weekly)委托 cron-schedule 解析 5 段 cron- * 表达式并求「下一个触发时刻」;interval 是纯间隔(无 cron 等价),保留锚点加法。- * cron-schedule 在宿主本地时区上求值,与「电脑保持唤醒时运行」的产品语义一致- * (schedule.timeZone 仅作展示记录,执行统一用宿主本地钟面时间)。返回 ms 时间戳。- */-import type { SchedulerSchedule, Weekday } from '../types'import { parseCronExpression } from 'cron-schedule'const MINUTE_MS = 60 * 1000-/** 间隔上限(分钟):1 年,防止超大间隔把 nextOccurrence 推到 Infinity/Invalid Date。 */+const DAY_MS = 24 * 60 * MINUTE_MSconst MAX_EVERY_MINUTES = 525_600+const MAX_EVERY_DAYS = 366-/** 解析 "HH:mm" 为当日分钟数;非法返回 undefined。 */export function parseTimeToMinutes(time: string): number | undefined {const match = /^(\d{1,2}):(\d{2})$/.exec(time.trim())if (!match)return undefinedconst hours = Number(match[1])const minutes = Number(match[2])- if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59)- return undefined- return hours * 60 + minutes+ return hours <= 23 && minutes <= 59 ? hours * 60 + minutes : undefined}-/** 星期短名 → cron 星期字段值(0/7=周日,与 JS Date#getDay 一致)。 */-const WEEKDAY_TO_CRON_DAY: Record<Weekday, number> = {- MO: 1,- TU: 2,- WE: 3,- TH: 4,- FR: 5,- SA: 6,- SU: 0,-}+const WEEKDAY_TO_CRON_DAY: Record<Weekday, number> = { MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6, SU: 0 }+type TimeSchedule = Extract<SchedulerSchedule, { kind: 'daily' | 'workdays' | 'weekly' | 'monthly' }>-/** 时间点类计划(有 cron 表达式可表达的三种 kind)。 */-type TimeSchedule = Extract<SchedulerSchedule, { kind: 'daily' | 'workdays' | 'weekly' }>--/**- * 把「时间点 + 星期」计划映射为 5 段 cron 表达式(minute hour dom month dow)。- * time 非法、weekly 无有效星期时返回 undefined(调用方按不可达处理)。- */function toCronExpression(schedule: TimeSchedule): string | undefined {const minutes = parseTimeToMinutes(schedule.time)if (minutes === undefined)return undefinedconst hour = Math.floor(minutes / 60)const minute = minutes % 60- switch (schedule.kind) {- case 'daily':- return `${minute} ${hour} * * *`- case 'workdays':- return `${minute} ${hour} * * 1-5`- case 'weekly': {- const days: number[] = []- for (const day of schedule.weekdays) {- if (!Object.hasOwn(WEEKDAY_TO_CRON_DAY, day))- return undefined- days.push(WEEKDAY_TO_CRON_DAY[day])- }- if (days.length === 0)- return undefined- return `${minute} ${hour} * * ${[...new Set(days)].sort((a, b) => a - b).join(',')}`- }- }+ if (schedule.kind === 'daily')+ return `${minute} ${hour} * * *`+ if (schedule.kind === 'workdays')+ return `${minute} ${hour} * * 1-5`+ if (schedule.kind === 'monthly')+ return `${minute} ${hour} ${schedule.day} * *`+ const days = schedule.weekdays.map(day => WEEKDAY_TO_CRON_DAY[day])+ return days.length > 0 ? `${minute} ${hour} * * ${[...new Set(days)].sort((a, b) => a - b).join(',')}` : undefined+}++function anchoredOccurrence(anchor: string, step: number, from: number): number | undefined {+ const base = new Date(anchor).getTime()+ if (!Number.isFinite(base) || step <= 0)+ return undefined+ const index = Math.max(0, Math.floor((from - base) / step) + 1)+ return base + index * step}-/**- * 计算某个计划在 from(ms 时间戳)之后的首次触发时间。- * 返回 ms 时间戳;计划非法或不可达时返回 undefined。- */export function nextOccurrence(schedule: SchedulerSchedule, from: number): number | undefined {switch (schedule.kind) {- case 'interval': {- const every = schedule.everyMinutes- if (!Number.isFinite(every) || every < 1 || every > MAX_EVERY_MINUTES)+ case 'once': {+ const at = new Date(schedule.at).getTime()+ return Number.isFinite(at) && at > from ? at : undefined+ }+ case 'hourly': {+ if (!Number.isInteger(schedule.minute) || schedule.minute < 0 || schedule.minute > 59)return undefined- // 以 from 为锚点:下一格(不重复触发当前已过的时刻)。- return from + every * MINUTE_MS+ const next = new Date(from + MINUTE_MS)+ next.setMinutes(schedule.minute, 0, 0)+ if (next.getTime() <= from)+ next.setHours(next.getHours() + 1)+ return next.getTime()}- case 'daily':- case 'workdays':- case 'weekly': {- const expression = toCronExpression(schedule)- if (expression === undefined)+ case 'interval':+ if (!Number.isFinite(schedule.everyMinutes) || schedule.everyMinutes < 1 || schedule.everyMinutes > MAX_EVERY_MINUTES)+ return undefined+ return schedule.anchor ? anchoredOccurrence(schedule.anchor, schedule.everyMinutes * MINUTE_MS, from) : from + schedule.everyMinutes * MINUTE_MS+ case 'custom':+ if (!Number.isInteger(schedule.everyDays) || schedule.everyDays < 1 || schedule.everyDays > MAX_EVERY_DAYS || parseTimeToMinutes(schedule.time) === undefined)return undefined- return parseCronExpression(expression).getNextDate(new Date(from)).getTime()+ return anchoredOccurrence(schedule.anchor, schedule.everyDays * DAY_MS, from)+ case 'daily': case 'workdays': case 'weekly': case 'monthly': {+ const expression = toCronExpression(schedule)+ return expression ? parseCronExpression(expression).getNextDate(new Date(from)).getTime() : undefined}}}-/** 校验计划是否合法(供创建/更新路由复用)。 */export function validateSchedule(schedule: unknown): schedule is SchedulerSchedule {- if (typeof schedule !== 'object' || schedule === null)+ if (!schedule || typeof schedule !== 'object')return falseconst value = schedule as Partial<SchedulerSchedule>- if (value.kind === 'interval') {- return Number.isFinite(value.everyMinutes)- && (value.everyMinutes as number) >= 1- && (value.everyMinutes as number) <= MAX_EVERY_MINUTES- }- if (value.kind === 'daily' || value.kind === 'workdays') {+ if (value.kind === 'once')+ return typeof value.at === 'string' && Number.isFinite(new Date(value.at).getTime())+ if (value.kind === 'hourly')+ return Number.isInteger(value.minute) && (value.minute as number) >= 0 && (value.minute as number) <= 59+ if (value.kind === 'interval')+ return Number.isFinite(value.everyMinutes) && (value.everyMinutes as number) >= 1 && (value.everyMinutes as number) <= MAX_EVERY_MINUTES && typeof value.anchor === 'string' && Number.isFinite(new Date(value.anchor).getTime())+ if (value.kind === 'custom')+ return Number.isInteger(value.everyDays) && (value.everyDays as number) >= 1 && (value.everyDays as number) <= MAX_EVERY_DAYS && typeof value.anchor === 'string' && Number.isFinite(new Date(value.anchor).getTime()) && typeof value.time === 'string' && parseTimeToMinutes(value.time) !== undefined+ if (value.kind === 'daily' || value.kind === 'workdays')return typeof value.time === 'string' && parseTimeToMinutes(value.time) !== undefined- }- if (value.kind === 'weekly') {- return typeof value.time === 'string'- && parseTimeToMinutes(value.time) !== undefined- && Array.isArray(value.weekdays)- && (value.weekdays as Weekday[]).length > 0- && (value.weekdays as Weekday[]).every(day => Object.hasOwn(WEEKDAY_TO_CRON_DAY, day))- }+ if (value.kind === 'monthly')+ return Number.isInteger(value.day) && (value.day as number) >= 1 && (value.day as number) <= 31 && typeof value.time === 'string' && parseTimeToMinutes(value.time) !== undefined+ if (value.kind === 'weekly')+ return typeof value.time === 'string' && parseTimeToMinutes(value.time) !== undefined && Array.isArray(value.weekdays) && value.weekdays.length > 0 && value.weekdays.every(day => Object.hasOwn(WEEKDAY_TO_CRON_DAY, day as Weekday))return false}-/** 宿主本地 IANA 时区(默认展示用)。 */export function localTimeZone(): string {try {return new Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC'diff --git a/packages/dsh-tauri-panel-scheduler/src/host/service/scheduler.ts b/packages/dsh-tauri-panel-scheduler/src/host/service/scheduler.tsindex 89267e34..84f08921 100644--- a/packages/dsh-tauri-panel-scheduler/src/host/service/scheduler.ts+++ b/packages/dsh-tauri-panel-scheduler/src/host/service/scheduler.ts@@ -98,7 +98,11 @@ export class SchedulerEngine {this.running.delete(task.id)// 无论成败都推进到下次触发(失败也会按计划重试,避免卡死在同一次)。const now = Date.now()- const next = nextOccurrence(task.schedule, now)+ // Fixed-anchor schedules advance from the prior planned occurrence, not completion time.+ const previous = task.nextRunAt ? new Date(task.nextRunAt).getTime() : now+ const next = task.schedule.kind === 'interval' || task.schedule.kind === 'custom'+ ? nextOccurrence(task.schedule, previous)+ : nextOccurrence(task.schedule, now)await updateTaskTimes(task.id, {lastRunAt: task.lastRunAt,nextRunAt: next === undefined ? undefined : new Date(next).toISOString(),diff --git a/packages/dsh-tauri-panel-scheduler/src/host/service/task.ts b/packages/dsh-tauri-panel-scheduler/src/host/service/task.tsindex 581a2456..33bfe693 100644--- a/packages/dsh-tauri-panel-scheduler/src/host/service/task.ts+++ b/packages/dsh-tauri-panel-scheduler/src/host/service/task.ts@@ -30,11 +30,14 @@ export interface TaskInput {export function buildTask(input: TaskInput): SchedulerTask {const now = new Date()const schedule = input.schedule- // 时间戳缺省用宿主本地时区;interval 无时间字段。- const timeZone = typeof schedule.timeZone === 'string' && schedule.timeZone- ? schedule.timeZone+ // 时间戳缺省用宿主本地时区;interval/custom 以创建时刻作为固定锚点。+ const anchoredSchedule = (schedule.kind === 'interval' || schedule.kind === 'custom') && !schedule.anchor+ ? { ...schedule, anchor: now.toISOString() }+ : schedule+ const timeZone = typeof anchoredSchedule.timeZone === 'string' && anchoredSchedule.timeZone+ ? anchoredSchedule.timeZone: localTimeZone()- const normalized: SchedulerSchedule = { ...schedule, timeZone } as SchedulerSchedule+ const normalized: SchedulerSchedule = { ...anchoredSchedule, timeZone } as SchedulerScheduleconst next = nextOccurrence(normalized, now.getTime())return {id: `task-${randomUUID()}`,diff --git a/packages/dsh-tauri-panel-scheduler/src/host/tools/index.ts b/packages/dsh-tauri-panel-scheduler/src/host/tools/index.tsindex 95468222..d9761515 100644--- a/packages/dsh-tauri-panel-scheduler/src/host/tools/index.ts+++ b/packages/dsh-tauri-panel-scheduler/src/host/tools/index.ts@@ -30,11 +30,16 @@ export function createToolSet(engine: SchedulerEngine): any[] {prompt: { type: 'string', description: 'The task instruction run in the scheduled session.' },schedule: {type: 'object',- description: 'Schedule spec: { kind: "daily"|"interval"|"workdays"|"weekly", ... }.',+ description: 'Schedule spec: once/hourly/daily/interval/workdays/weekly/monthly/custom.',properties: {- kind: { type: 'string', enum: ['daily', 'interval', 'workdays', 'weekly'] },+ kind: { type: 'string', enum: ['once', 'hourly', 'daily', 'interval', 'workdays', 'weekly', 'monthly', 'custom'] },time: { type: 'string', description: '"HH:mm" for daily/workdays/weekly.' },everyMinutes: { type: 'number', description: 'Interval minutes for kind=interval.' },+ everyDays: { type: 'number', description: 'Interval days for kind=custom.' },+ anchor: { type: 'string', description: 'ISO anchor for fixed interval/custom recurrence.' },+ at: { type: 'string', description: 'ISO timestamp for kind=once.' },+ minute: { type: 'number', description: 'Minute of hour for kind=hourly.' },+ day: { type: 'number', description: 'Day of month for kind=monthly.' },weekdays: { type: 'array', items: { type: 'string' }, description: '["MO","TU",...] for kind=weekly.' },},required: ['kind'],diff --git a/packages/dsh-tauri-panel-scheduler/src/host/types/index.ts b/packages/dsh-tauri-panel-scheduler/src/host/types/index.tsindex ddb2d459..8649c2af 100644--- a/packages/dsh-tauri-panel-scheduler/src/host/types/index.ts+++ b/packages/dsh-tauri-panel-scheduler/src/host/types/index.ts@@ -16,12 +16,26 @@ export interface PluginConfig {tickMs?: number}-/** 计划类型(每天/间隔/工作日/每周)。 */+/** 计划类型(含一次、小时、月度与自定义周期)。 */export type ScheduleKind = (typeof SCHEDULE_KINDS)[number]/** 星期枚举(IATA 三字母)。 */export type Weekday = (typeof WEEKDAYS)[number]+/** 单次:at 为 ISO 时间,timeZone 为展示/语义时区。 */+export interface OnceSchedule {+ kind: 'once'+ at: string+ timeZone: string+}++/** 每小时:minute 为 0-59。 */+export interface HourlySchedule {+ kind: 'hourly'+ minute: number+ timeZone: string+}+/** 每天:`time` 为 "HH:mm"(timeZone 时区)。 */export interface DailySchedule {kind: 'daily'@@ -33,6 +47,7 @@ export interface DailySchedule {export interface IntervalSchedule {kind: 'interval'everyMinutes: number+ anchor?: stringtimeZone: string}@@ -51,14 +66,31 @@ export interface WeeklySchedule {timeZone: string}+/** 每月:day 为 1-31,超出月份天数时按 cron 语义跳过。 */+export interface MonthlySchedule {+ kind: 'monthly'+ day: number+ time: string+ timeZone: string+}++/** 自定义:每 everyDays 天,从 anchor 起固定推进。 */+export interface CustomSchedule {+ kind: 'custom'+ everyDays: number+ anchor: string+ time: string+ timeZone: string+}+/** 调度计划(discriminated union)。 */-export type SchedulerSchedule = DailySchedule | IntervalSchedule | WorkdaysSchedule | WeeklySchedule+export type SchedulerSchedule = OnceSchedule | HourlySchedule | DailySchedule | IntervalSchedule | WorkdaysSchedule | WeeklySchedule | MonthlySchedule | CustomSchedule/** 任务执行来源。 */export type RunTrigger = 'schedule' | 'manual'/** 任务状态。 */-export type RunStatus = 'queued' | 'running' | 'succeeded' | 'failed' | 'skipped' | 'cancelled'+export type RunStatus = 'queued' | 'running' | 'succeeded' | 'failed' | 'interrupted' | 'skipped' | 'cancelled'/** 定时任务定义(持久化于 tasks.json)。 */export interface SchedulerTask {diff --git a/packages/dsh-tauri-panel-scheduler/src/shared/constants.ts b/packages/dsh-tauri-panel-scheduler/src/shared/constants.tsindex 9c5cbc32..5a5d5f18 100644--- a/packages/dsh-tauri-panel-scheduler/src/shared/constants.ts+++ b/packages/dsh-tauri-panel-scheduler/src/shared/constants.ts@@ -12,7 +12,7 @@ export const SCHEDULER_PLUGIN_NAME = 'dsh-tauri-panel-scheduler'export const SCHEDULER_API_PREFIX = '/api/dsh-scheduler'/** 计划类型集合(与 DSH automation 工具的语义一一对应)。 */-export const SCHEDULE_KINDS = ['daily', 'interval', 'workdays', 'weekly'] as const+export const SCHEDULE_KINDS = ['once', 'hourly', 'daily', 'interval', 'workdays', 'weekly', 'monthly', 'custom'] as const/** 星期枚举(IATA 三字母,与 DSH automation 一致)。 */export const WEEKDAYS = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'] as const