Files
dsh-enhancements/plugins/dsh-scheduler/README.md
T
江晨 c0d0177a53 feat: 新增 dsh-scheduler 定时任务插件 + 用户截图留档
- plugins/dsh-scheduler: cron5字段/every:N 调度、持久化到 storages、
  sched_add/list/remove/run_now/toggle 五工具(host-only)
- assets/user-screenshot.png: 用户提供的 Codex 参考截图
2026-08-17 11:58:03 +08:00

42 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# dsh-scheduler — 定时任务插件
Host 侧定时任务调度器。给 DeepSeek Harness 补上缺失的**定时任务**能力。
## 能力
- **调度表达式**
- cron 5 字段:`分 时 日 月 周`,支持 `*``*/n``a-b``a,b,c`(如 `*/10 * * * *` 每 10 分钟)
- 间隔简写:`every:30s` / `every:5m` / `every:1h`
- **动作**:任意 cmd 命令行(可指定工作目录、超时)
- **持久化**:任务存于 `%DSH_HOME%\storages\dsh-scheduler.json`,重启不丢
- **工具**(注册给 agent 调用):
| 工具 | 作用 |
|---|---|
| `sched_add` | 添加任务(名称/调度/命令/cwd/enabled |
| `sched_list` | 列出任务与运行状态 |
| `sched_remove` | 按 id 删除 |
| `sched_run_now` | 立即执行一次 |
| `sched_toggle` | 启用/停用 |
## 实现要点
- 宿主插件环境**没有** `fs`/`process` 全局 → 文件读写走 `shell` 服务 + node 子进程
`btoa` 内置做 base64 传参,避免引号转义问题)
- 每秒 tick`ctx.timer.interval`),`ticking` 标志防重入
- 任务执行用 `cmd /c <command>`,默认 cwd `D:\project`,默认超时 60s
- cron 的 `nextRun` 预计算:从当前时间起逐分钟扫描(最多 7 天)
## 文件
- `host.js` — 完整宿主插件源码
- 部署方式:动态 Cordis 插件(`cordis_define` + `cordis_run`),或归档到 presets/
## 示例
```
sched_add name="每30秒打点" schedule="every:30s" command="echo tick >> C:\Users\a1703\.dsh\logs\sched-demo.log"
sched_add name="每整点提醒" schedule="0 * * * *" command="msg * 整点提醒"
sched_list
```