Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

refactor(scheduler): 工具面收敛为 4 个,对齐官方集合 (#765)

Mao Mr30754545f63a
diff --git a/packages/dsh-tauri-scheduler/THIRD_PARTY_NOTICES.md b/packages/dsh-tauri-scheduler/THIRD_PARTY_NOTICES.md
index 52103596..25b064e1 100644
--- a/packages/dsh-tauri-scheduler/THIRD_PARTY_NOTICES.md
+++ b/packages/dsh-tauri-scheduler/THIRD_PARTY_NOTICES.md
@@ -63,7 +63,7 @@ Official packages used:
Official counterpart (official `@deepseek-ai/dsh-schedule` + `@deepseek-ai/dsh-client-ui-schedule` → this package):
-- Tools: official `schedule_create` / `schedule_list` / `schedule_delete` / `schedule_update` → `scheduler_create` / `scheduler_list` / `scheduler_toggle` / `scheduler_delete` / `scheduler_run_now` (`src/host/tools/`), five instead of four.
+- Tools: official `schedule_create` / `schedule_list` / `schedule_update` / `schedule_delete` → `scheduler_create` / `scheduler_list` / `scheduler_update` / `scheduler_delete` (`src/host/tools/`), four to four. `scheduler_update` additionally absorbs pausing/resuming (`enabled`, the official set has no toggle) and offers a `run_now` switch that also triggers an immediate manual run.
- Delivery: official durable Host-wide reminders in the **original** Session → unattended runs, each starting a **fresh** Session (`workspaceId`, `permission`, `provider`, `model`, `reasoningEffort`).
- Recurrence: official one-shot / fixed-rate / daily / weekly / cron (`createCronScheduleRecord`, `resolveCronOccurrence`, `canonicalizeCronExpression`) → `once` / `hourly` / `daily` / `interval` / `workdays` / `weekly` / `monthly` / `custom` (`SCHEDULE_KINDS` in `src/shared/constants.ts`), evaluated with the `cron-schedule` package or anchored arithmetic; no cron kind.
- Missed occurrences: official keeps only the latest missed occurrence and restores a cold Session → anchored interval/custom arithmetic plus `runs/recover` reconciliation for interrupted runs.
diff --git a/packages/dsh-tauri-scheduler/docs/sync-log.md b/packages/dsh-tauri-scheduler/docs/sync-log.md
index 891a4f45..a2b24db1 100644
--- a/packages/dsh-tauri-scheduler/docs/sync-log.md
+++ b/packages/dsh-tauri-scheduler/docs/sync-log.md
@@ -281,6 +281,33 @@ git diff --check # 无输出
`summarizeCollectedRun`(2 例:增量带收尾原因时不再扫快照;增量缺收尾原因含「只剩正文」时回退快照且失败不被吞成成功)、
`isPluginUnloadError`(1 例)、`executor.run` 插件卸载记 `cancelled`(1 例)。
+### 工具面精简(2026-09-29)
+
+本地注入给 agent 的工具由 5 个收敛为 4 个,与官方 `@deepseek-ai/dsh-schedule` 的
+`schedule_create` / `schedule_list` / `schedule_update` / `schedule_delete` 一一对应(官方集合无 update 之外的差异项)。
+
+- 新增 `src/host/tools/update-task.ts`(`scheduler_update`):吸收原 `scheduler_toggle` 的启停语义
+ (`enabled` 本就是 `TaskInput` 的普通字段,走 `task.update` 同一条路径),并补齐原本缺失的
+ 改名 / 改指令 / 改计划 / 改 workspace / permission / provider / model / reasoningEffort。
+ 显式传入的字段才并入 patch,缺省字段由 `defaults({}, patch, current)` 保持原值。
+- `run_now` 开关保留原 `scheduler_run_now` 的立即运行能力;更新已落盘而运行失败时不回滚,
+ 如实返回 `更新已保存,但立即运行失败:<原因>`。
+- 计划片段 schema 上移到 `src/host/utils/tool.ts` 的 `scheduleParameters`,create / update 共用。
+- 删除 `src/host/tools/toggle-task.ts`、`src/host/tools/run-task.ts`。
+- 宿主 HTTP 路由 `/tasks/toggle`、`/tasks/run` 与面板调用**有意保留**:本轮只收敛注入给 agent 的工具面。
+
+验证记录(2026-09-29):
+
+```text
+pnpm --filter dsh-tauri-scheduler typecheck # tsc 通过(0 error)
+pnpm exec eslint src/host/apply.ts src/host/utils/tool.ts src/host/tools
+ # 0 error / 0 warning
+npx vitest run --project unit packages/dsh-tauri-scheduler # 9 test files, 74 tests passed
+```
+
+新增单测 `src/host/tools/update-task.test.ts`(8 例):工具名、`task_id` 唯一必填与字段集、
+只并入显式字段、`enabled` 启停语义、`run_now` 触发时机、更新失败不触发、更新成功后触发失败如实回报。
+
## 待同步项
无。`f1bc91a..ecfe1e6` 的全部提交已评估并由用户逐条裁决(见上),本地行为要求「等待中」已实施。
diff --git a/packages/dsh-tauri-scheduler/src/client/styles/index.cssr.ts b/packages/dsh-tauri-scheduler/src/client/styles/index.cssr.ts
index 89aa951b..05f4d029 100644
--- a/packages/dsh-tauri-scheduler/src/client/styles/index.cssr.ts
+++ b/packages/dsh-tauri-scheduler/src/client/styles/index.cssr.ts
@@ -12,5 +12,6 @@ const { secondary } = sharedStyles
export default c([
c(`[${SESSION_ICON_ATTRIBUTE}]`, { width: '16px', height: '20px', flex: 'none', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', marginLeft: '2px', marginRight: '5px', color: secondary }),
c('[role="treeitem"]', { position: 'relative' }),
+ c(`[role="treeitem"]:hover [${SESSION_ICON_ATTRIBUTE}]`, { visibility: 'hidden' }),
c('button:has(.dshp-scheduler__nav-dot)', { position: 'relative' }),
])
diff --git a/packages/dsh-tauri-scheduler/src/host/apply.ts b/packages/dsh-tauri-scheduler/src/host/apply.ts
index 3cecfcf7..d2e4c18c 100644
--- a/packages/dsh-tauri-scheduler/src/host/apply.ts
+++ b/packages/dsh-tauri-scheduler/src/host/apply.ts
@@ -7,8 +7,7 @@ import { scheduler } from './service/scheduler'
import { createTaskTool } from './tools/create-task'
import { deleteTaskTool } from './tools/delete-task'
import { listTasksTool } from './tools/list-tasks'
-import { runTaskTool } from './tools/run-task'
-import { toggleTaskTool } from './tools/toggle-task'
+import { updateTaskTool } from './tools/update-task'
const SCHEDULER_TICK_MS = 1_000
@@ -29,9 +28,8 @@ export function apply(ctx: HostContext, config: Config = {}): void {
ctx.tools.register(createTaskTool())
ctx.tools.register(listTasksTool())
- ctx.tools.register(toggleTaskTool())
+ ctx.tools.register(updateTaskTool())
ctx.tools.register(deleteTaskTool())
- ctx.tools.register(runTaskTool())
const tickMs = Number.isFinite(config?.tickMs) && (config.tickMs as number) > 0
? (config.tickMs as number)
diff --git a/packages/dsh-tauri-scheduler/src/host/service/task.ts b/packages/dsh-tauri-scheduler/src/host/service/task.ts
index 106f1493..a787df41 100644
--- a/packages/dsh-tauri-scheduler/src/host/service/task.ts
+++ b/packages/dsh-tauri-scheduler/src/host/service/task.ts
@@ -1,7 +1,7 @@
import type { OperationResult, SchedulerSchedule, SchedulerTask, TaskInput } from '../types'
import { randomUUID } from 'node:crypto'
import { defineService } from 'dsh-tauri'
-import { conformsTo, defaults, filter, find, findIndex, isArray, isBoolean, isEmpty, isNil, isObject, isString, omitBy, pick, reject } from 'lodash-es'
+import { conformsTo, defaults, filter, find, findIndex, isArray, isBoolean, isEmpty, isEqual, isNil, isObject, isString, omitBy, pick, reject } from 'lodash-es'
import { withWriteQueue } from '../config/runtime'
import { storage } from '../storage'
import { localTimeZone, nextOccurrence, validateSchedule } from '../utils/schedule'
@@ -40,7 +40,17 @@ export const task = defineService({
const invalid = validateInput(merged)
if (invalid !== null)
return { ok: false, error: invalid }
- const updated = { ...build(merged), id: current.id }
+ const rebuilt = build(merged)
+ const updated: SchedulerTask = {
+ ...rebuilt,
+ id: current.id,
+ createdAt: current.createdAt,
+ updatedAt: new Date().toISOString(),
+ lastRunAt: current.lastRunAt,
+ nextRunAt: !isEqual(rebuilt.schedule, current.schedule) || (rebuilt.enabled && isNil(current.nextRunAt))
+ ? rebuilt.nextRunAt
+ : current.nextRunAt,
+ }
await saveTask(updated)
return { ok: true, task: updated }
},
diff --git a/packages/dsh-tauri-scheduler/src/host/tools/create-task.ts b/packages/dsh-tauri-scheduler/src/host/tools/create-task.ts
index 0156b31d..378e0ff4 100644
--- a/packages/dsh-tauri-scheduler/src/host/tools/create-task.ts
+++ b/packages/dsh-tauri-scheduler/src/host/tools/create-task.ts
@@ -1,6 +1,5 @@
-import { SCHEDULE_KINDS } from '../../shared/constants'
import { task } from '../service/task'
-import { textBlock } from '../utils/tool'
+import { nullableText, scheduleParameters, textBlock } from '../utils/tool'
const outputSchema = {
type: 'object',
@@ -8,7 +7,7 @@ const outputSchema = {
properties: {
ok: { type: 'boolean' },
taskId: { type: 'string' },
- nextRunAt: { type: 'string' },
+ nextRunAt: nullableText,
error: { type: 'string' },
},
required: ['ok'],
@@ -26,22 +25,7 @@ export function createTaskTool(): any {
properties: {
name: { type: 'string', description: 'Task name, e.g. "Daily report".' },
prompt: { type: 'string', description: 'The task instruction run in the scheduled session.' },
- schedule: {
- type: 'object',
- description: 'Schedule spec: once/hourly/daily/interval/workdays/weekly/monthly/custom.',
- properties: {
- kind: { type: 'string', enum: [...SCHEDULE_KINDS] },
- 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'],
- },
+ schedule: scheduleParameters,
workspaceId: { type: 'string', description: 'Optional target workspace id (cwd).' },
permission: { type: 'string', enum: ['read-only', 'workspace-write', 'danger-full-access'], description: 'Permission boundary (read-only / workspace-write / danger-full-access). Default read-only.' },
provider: { type: 'string', description: 'Optional pinned model provider id (pair with model).' },
diff --git a/packages/dsh-tauri-scheduler/src/host/tools/run-task.ts b/packages/dsh-tauri-scheduler/src/host/tools/run-task.ts
deleted file mode 100644
index 5398f7e3..00000000
--- a/packages/dsh-tauri-scheduler/src/host/tools/run-task.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { scheduler } from '../service/scheduler'
-import { textBlock } from '../utils/tool'
-
-export function runTaskTool(): any {
- return {
- name: 'scheduler_run_now',
- description: 'Immediately run a scheduled task by id (manual trigger).',
- parameters: {
- type: 'object',
- properties: { task_id: { type: 'string', description: 'Task id.' } },
- required: ['task_id'],
- },
- output: {
- schema: { type: 'object', additionalProperties: true, properties: { ok: { type: 'boolean' }, error: { type: 'string' } }, required: ['ok'] },
- render: (_args: unknown, value: any) => value.ok ? textBlock('✅ 已触发立即运行。') : textBlock(`❌ 触发失败:${value.error}`),
- },
- async execute(args: any) {
- const result = await scheduler.trigger(String(args.task_id ?? ''))
- if (!result.ok)
- return { ok: false, error: result.error }
- return { ok: true }
- },
- }
-}
diff --git a/packages/dsh-tauri-scheduler/src/host/tools/toggle-task.ts b/packages/dsh-tauri-scheduler/src/host/tools/toggle-task.ts
deleted file mode 100644
index 16fbeed2..00000000
--- a/packages/dsh-tauri-scheduler/src/host/tools/toggle-task.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import { task } from '../service/task'
-import { textBlock } from '../utils/tool'
-
-export function toggleTaskTool(): any {
- return {
- name: 'scheduler_toggle',
- description: 'Pause or resume a scheduled task by id.',
- parameters: {
- type: 'object',
- properties: {
- task_id: { type: 'string', description: 'Task id.' },
- enabled: { type: 'boolean', description: 'true to resume, false to pause.' },
- },
- required: ['task_id', 'enabled'],
- },
- output: {
- schema: { type: 'object', additionalProperties: true, properties: { ok: { type: 'boolean' }, error: { type: 'string' } }, required: ['ok'] },
- render: (_args: unknown, value: any) => value.ok
- ? textBlock(`✅ 已${value.enabled ? '恢复' : '暂停'}定时任务。`)
- : textBlock(`❌ 操作失败:${value.error}`),
- },
- async execute(args: any) {
- const result = await task.toggle(String(args.task_id ?? ''), args.enabled === true)
- if (!result.ok)
- return { ok: false, error: result.error }
- return { ok: true, enabled: result.task.enabled }
- },
- }
-}
diff --git a/packages/dsh-tauri-scheduler/src/host/tools/update-task.test.ts b/packages/dsh-tauri-scheduler/src/host/tools/update-task.test.ts
new file mode 100644
index 00000000..f0e4ad83
--- /dev/null
+++ b/packages/dsh-tauri-scheduler/src/host/tools/update-task.test.ts
@@ -0,0 +1,102 @@
+import type { SchedulerTask } from '../types'
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+import { scheduler } from '../service/scheduler'
+import { task } from '../service/task'
+import { updateTaskTool } from './update-task'
+
+vi.mock('../service/task', () => ({ task: { update: vi.fn() } }))
+
+vi.mock('../service/scheduler', () => ({ scheduler: { trigger: vi.fn() } }))
+
+const taskFixture: SchedulerTask = {
+ id: 'task-1',
+ name: 'nightly',
+ schedule: { kind: 'interval', everyMinutes: 30, timeZone: 'UTC' },
+ prompt: 'run the nightly job',
+ enabled: true,
+ createdAt: '2025-12-31T00:00:00.000Z',
+ updatedAt: '2025-12-31T00:00:00.000Z',
+ nextRunAt: '2026-01-01T00:30:00.000Z',
+}
+
+const tool = updateTaskTool()
+
+beforeEach(() => {
+ vi.clearAllMocks()
+})
+
+describe('scheduler_update', () => {
+ it('对外只暴露四个 agent 工具之一:名称为 scheduler_update', () => {
+ expect(tool.name).toBe('scheduler_update')
+ })
+
+ it('task_id 是唯一必填参数,其余字段均可选', () => {
+ expect(tool.parameters.required).toEqual(['task_id'])
+ expect(Object.keys(tool.parameters.properties).sort()).toEqual([
+ 'enabled',
+ 'model',
+ 'name',
+ 'permission',
+ 'prompt',
+ 'provider',
+ 'reasoningEffort',
+ 'run_now',
+ 'schedule',
+ 'task_id',
+ 'workspaceId',
+ ])
+ })
+
+ it('只把显式传入的字段并入 patch,缺省字段保持不变', async () => {
+ vi.mocked(task.update).mockResolvedValue({ ok: true, task: { ...taskFixture, name: 'weekly' } })
+
+ await tool.execute({ task_id: 'task-1', name: 'weekly' })
+
+ expect(task.update).toHaveBeenCalledWith('task-1', { name: 'weekly' })
+ })
+
+ it('吸收 toggle 语义:enabled 作为普通可更新字段写入', async () => {
+ vi.mocked(task.update).mockResolvedValue({ ok: true, task: { ...taskFixture, enabled: false } })
+
+ await tool.execute({ task_id: 'task-1', enabled: false })
+
+ expect(task.update).toHaveBeenCalledWith('task-1', { enabled: false })
+ })
+
+ it('run_now 为真时在更新之后触发一次手动运行', async () => {
+ vi.mocked(task.update).mockResolvedValue({ ok: true, task: taskFixture })
+ vi.mocked(scheduler.trigger).mockResolvedValue({ ok: true })
+
+ await expect(tool.execute({ task_id: 'task-1', name: 'nightly', run_now: true }))
+ .resolves
+ .toEqual({ ok: true, taskId: 'task-1', nextRunAt: '2026-01-01T00:30:00.000Z', ran: true })
+ expect(scheduler.trigger).toHaveBeenCalledWith('task-1')
+ })
+
+ it('未传 run_now 时不触发运行', async () => {
+ vi.mocked(task.update).mockResolvedValue({ ok: true, task: taskFixture })
+
+ await expect(tool.execute({ task_id: 'task-1', prompt: 'again' }))
+ .resolves
+ .toEqual({ ok: true, taskId: 'task-1', nextRunAt: '2026-01-01T00:30:00.000Z' })
+ expect(scheduler.trigger).not.toHaveBeenCalled()
+ })
+
+ it('更新失败时直接返回领域错误,不触发运行', async () => {
+ vi.mocked(task.update).mockResolvedValue({ ok: false, error: '任务不存在' })
+
+ await expect(tool.execute({ task_id: 'missing', run_now: true }))
+ .resolves
+ .toEqual({ ok: false, error: '任务不存在' })
+ expect(scheduler.trigger).not.toHaveBeenCalled()
+ })
+
+ it('更新已保存但立即运行失败时如实回报,不掩盖已写入的更新', async () => {
+ vi.mocked(task.update).mockResolvedValue({ ok: true, task: taskFixture })
+ vi.mocked(scheduler.trigger).mockResolvedValue({ ok: false, error: '任务正在执行中' })
+
+ await expect(tool.execute({ task_id: 'task-1', run_now: true }))
+ .resolves
+ .toEqual({ ok: false, error: '更新已保存,但立即运行失败:任务正在执行中' })
+ })
+})
diff --git a/packages/dsh-tauri-scheduler/src/host/tools/update-task.ts b/packages/dsh-tauri-scheduler/src/host/tools/update-task.ts
new file mode 100644
index 00000000..e2dd3a82
--- /dev/null
+++ b/packages/dsh-tauri-scheduler/src/host/tools/update-task.ts
@@ -0,0 +1,80 @@
+import type { TaskInput } from '../types'
+import { scheduler } from '../service/scheduler'
+import { task } from '../service/task'
+import { nullableText, scheduleParameters, textBlock } from '../utils/tool'
+
+const TEXT_FIELDS = ['name', 'prompt', 'workspaceId', 'permission', 'provider', 'model', 'reasoningEffort'] as const
+
+const outputSchema = {
+ type: 'object',
+ additionalProperties: true,
+ properties: {
+ ok: { type: 'boolean' },
+ taskId: { type: 'string' },
+ nextRunAt: nullableText,
+ ran: { type: 'boolean' },
+ error: { type: 'string' },
+ },
+ required: ['ok'],
+}
+
+export function updateTaskTool(): any {
+ return {
+ name: 'scheduler_update',
+ description:
+ 'Update a scheduled task by id: rename it, rewrite its instruction, replace its schedule, '
+ + 'pause or resume it (enabled), or change the workspace/permission/model used by its runs. '
+ + 'Omitted fields keep their current value. Set run_now to also trigger an immediate manual run.',
+ parameters: {
+ type: 'object',
+ properties: {
+ task_id: { type: 'string', description: 'Task id.' },
+ name: { type: 'string', description: 'New task name.' },
+ prompt: { type: 'string', description: 'New task instruction.' },
+ schedule: scheduleParameters,
+ enabled: { type: 'boolean', description: 'true to resume, false to pause.' },
+ workspaceId: { type: 'string', description: 'New target workspace id (cwd).' },
+ permission: { type: 'string', enum: ['read-only', 'workspace-write', 'danger-full-access'], description: 'New permission boundary.' },
+ provider: { type: 'string', description: 'New pinned model provider id (pair with model).' },
+ model: { type: 'string', description: 'New pinned model id (pair with provider).' },
+ reasoningEffort: { type: 'string', description: 'New pinned reasoning effort id.' },
+ run_now: { type: 'boolean', description: 'Also trigger an immediate manual run after the update.' },
+ },
+ required: ['task_id'],
+ },
+ output: {
+ schema: outputSchema,
+ render: (_args: unknown, value: any) => value.ok
+ ? textBlock(`✅ 定时任务已更新:${value.taskId}(下次运行 ${value.nextRunAt ?? '待计算'})${value.ran === true ? ',已触发立即运行' : ''}`)
+ : textBlock(`❌ ${value.error}`),
+ },
+ async execute(args: any) {
+ const id = String(args.task_id ?? '')
+ const result = await task.update(id, patchOf(args))
+ if (!result.ok)
+ return { ok: false, error: result.error }
+ const updated = { ok: true, taskId: result.task.id, nextRunAt: result.task.nextRunAt ?? null }
+ if (args.run_now !== true)
+ return updated
+ const run = await scheduler.trigger(id)
+ if (!run.ok)
+ return { ok: false, error: `更新已保存,但立即运行失败:${run.error}` }
+ return { ...updated, ran: true }
+ },
+ }
+}
+
+// --- internal ---
+
+function patchOf(args: any): Partial<TaskInput> {
+ const patch: Record<string, unknown> = {}
+ for (const field of TEXT_FIELDS) {
+ if (args[field] !== undefined)
+ patch[field] = String(args[field])
+ }
+ if (args.schedule !== undefined)
+ patch.schedule = args.schedule
+ if (args.enabled !== undefined)
+ patch.enabled = args.enabled === true
+ return patch as Partial<TaskInput>
+}
diff --git a/packages/dsh-tauri-scheduler/src/host/utils/tool.ts b/packages/dsh-tauri-scheduler/src/host/utils/tool.ts
index a8a18edb..af118e12 100644
--- a/packages/dsh-tauri-scheduler/src/host/utils/tool.ts
+++ b/packages/dsh-tauri-scheduler/src/host/utils/tool.ts
@@ -1,3 +1,25 @@
+import { SCHEDULE_KINDS } from '../../shared/constants'
+
+export const scheduleParameters = {
+ type: 'object',
+ description: 'Schedule spec: once/hourly/daily/interval/workdays/weekly/monthly/custom.',
+ properties: {
+ kind: { type: 'string', enum: [...SCHEDULE_KINDS] },
+ time: { type: 'string', description: '"HH:mm" for daily/workdays/weekly/monthly/custom.' },
+ 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'],
+}
+
+// 核心校验器只认 `oneOf`;`type: ['string','null']` 与 `anyOf` 都会抛错。
+export const nullableText = { oneOf: [{ type: 'string' }, { type: 'null' }] }
+
export function textBlock(text: string): Array<{ type: 'text', text: string }> {
return [{ type: 'text', text }]
}