dsh-routines:DSH 的定時例程插件,按 cron 跑 prompt、把摘要送到你手邊

前言

用 DSH 做智能體開發,有一類需求很常見:每天凌晨跑一遍測試、定時巡檢某個項目、週期性整理任務。這些工作的共同點是週期固定、prompt 能寫清楚、跑完只需要一段結論。DSH 的理念是一切皆插件,但調度這件事本身沒有現成方案,靠系統 crontab 拼 shell 腳本,又會丟掉智能體會話的日誌和審計能力。

下面介紹 dsh-routines,它把「定時運行一個 prompt」做成了 DSH 裏的一等公民。

這是什麼

dsh-routines(npm 包名 @dsh-routines/bundle)由 Jesse-njx 維護,MIT 許可,當前版本 0.1.0,在社區目錄裏歸類爲「工作流」類插件。

一句話定位:爲 DSH 提供定時智能體(scheduled agents)——按 cron 運行一段 prompt,把摘要投遞到你已經在看的地方(file 摘要、chatnode 投遞),並保證無人值守安全。

一個 routine = 命名 prompt + schedule + 投遞渠道,存爲純 YAML 文件:人類可 diff、可 git 提交。調度器把每次到期的運行經 headless runner 以獨立 one-shot 會話啓動,完整會話日誌就是完整審計記錄,之後還能被 dsh-replay 重放。摘要的生成規則:最後一條 assistant 消息較短時直接採用,否則對會話日誌做一次性 summarizer 調用。

核心能力

例程文件與熱重載

例程放在兩個被監視的目錄裏,改動即熱重載;非法文件只報告,不會讓存儲崩潰:

目錄 作用域
<cwd>/.dsh/routines/*.yaml 項目級例程,可按名稱覆蓋全局
~/.dsh/routines/*.yaml 全局例程

主要字段與默認值:

字段 默認值 說明
name 必填 [a-z0-9][a-z0-9-]*,不超過 64 字符
schedule 必填 "0 2 * * *"@dailyevery 4h
timezone UTC 用 IANA 時區做調度計算,不用宿主機時區
prompt 必填 headless 運行執行的任務
cwd 當前目錄 運行的工作目錄,也是摘要落地處
profile headless 運行啓動的 DSH profile
overlap skip skip / queue / cancel-previous
timeoutMin 45 硬超時(分鐘)
deliver [{type: file}] 摘要投遞渠道

調度語法

cron 爲 5 字段,支持 *、步進(*/15)、範圍(9-17)、列表(0,30)、? 以及月/日名稱;當「日」和「星期」同時受限時,任一匹配即觸發(Vixie cron 語義)。也接受 @daily@hourly@weekly@monthly@yearlyevery 4hevery 30m 這類簡寫。

overlap 決定到期但上一次還沒跑完時的行爲,默認 skip(不在同一個倉庫上疊兩個智能體);timeoutMin 是硬停止,默認 45 分鐘。

摘要投遞

  • file(始終開啓):運行記錄 + 摘要 markdown 寫入 .dsh/routines/runs/<runId>.json,旁邊有可讀的 <runId>.md
  • chatnode(可選):摘要經 ctx.chatnode 服務的 send(input: { text, title? }) 發送;沒有安裝會話節點時記爲 not-installed,運行照常完成。未來暴露該服務的 @dsh-cowork/chatnode-wechat 可以自動點亮這條通道。

CLI

在承載 profile 裏使用 dsh --profile ops routines <command>

命令 作用
list 列出例程的 schedule、暫停狀態、下次運行時間
run <name> 手動立即觸發,打印摘要後退出
pause <name> / resume <name> 暫停 / 恢復調度
logs <name> [--limit n] 最近運行記錄:狀態、時長、摘要、session id

無人值守安全默認

定時運行的智能體沒人盯着,所以每個運行子進程都會被 patch:

  1. 強制審批策略 never:自動拒絕任何會彈提示的請求,被拒項記入運行記錄的 denied 並出現在摘要裏;sandbox 模式沿用 profile 繼承值(通常爲 workspace-write)。
  2. 禁止嵌套調度:run overlay 會在運行 profile 內部關掉調度器。
  3. 投遞、摘要、啓動失敗只記入運行記錄,不向外拋出。

錯過的運行(比如電腦休眠):喚醒時最多補跑一次,不做積壓重放。

組成結構

一個 bundle,三個插件加一個 run driver,均可按子路徑安裝:

模塊 職責
@dsh-routines/bundle/store 監視 .dsh/routines/*.yaml(項目 + 全局),校驗、熱重載、持有持久狀態
@dsh-routines/bundle/scheduler 把到期例程註冊到 ctx.jobs(kind routine),負責 overlap、錯過運行與超時語義
@dsh-routines/bundle/cli dsh routines ... 命令行
@dsh-routines/bundle/run 子進程側驅動,經生成的 --patch overlay 注入每個 one-shot 運行,負責寫運行記錄和摘要

安裝與啓用

npm 包 @dsh-routines/bundle 在 README 中標註爲 when published(發佈後可用),當前可直接從 GitHub 安裝:

# 1. 創建承載調度器與 CLI  profile,並裝入本 bundle
dsh plugin --profile ops add github:Jesse-njx/dsh-routines
# npm 發佈後也可:dsh plugin --profile ops add @dsh-routines/bundle

# 2. 保持進程存活,調度纔會觸發(守護模式,Ctrl-C 停止)
dsh --profile ops

dsh --profile ops 不帶內層參數就是預期的守護形態:CLI 保持靜默,調度器接管進程生命週期。調度器在 bundle 安裝進的 profile 內運行,所以也可以裝入主 web profile,web 應用運行期間例程照常觸發:

dsh plugin --profile web add @dsh-routines/bundle

環境要求 node >= 20;peerDependencies 依賴 @deepseek-ai/cordis@deepseek-ai/cordis-plugin-timerdsh-agentdsh-cmdlinedsh-jobsdsh-llm 等 DSH 相關包。例程運行默認啓動 DSH 自帶的 headless profile,無需額外設置;需要別的 profile 時在例程裏設 profile: <name>,該 profile 須支持 one-shot(包含 headless bundle,或同樣安裝本 bundle——無論哪種,運行 overlay 都會禁用嵌套調度)。

調度簿記(暫停集合、上次運行錨點)存放在 <cwd>/.dsh/routines/state.json

典型用法:夜間測試分診

README 給出的示例例程:凌晨 2 點跑測試套件,若有失敗則診斷首要失敗並在分支上起草修復,最後留一份不超過 10 行的總結。

# ~/work/projectx/.dsh/routines/nightly-tests.yaml
name: nightly-tests
schedule: "0 2 * * *"        # 5 字段 cron;也接受 "@daily"、"every 4h"
timezone: Asia/Shanghai       # 顯式聲明,不靜默使用宿主機時區
prompt: |
  Run the test suite. If anything fails, diagnose the top failure
  and draft a fix on a branch. Summarize in <10 lines.
cwd: ~/work/projectx
profile: headless              # 運行使用的 profile
overlap: skip                  # skip | queue | cancel-previous
timeoutMin: 45
deliver:
  - type: file                 # 始終開啓:摘要寫入 .dsh/routines/runs/
  - type: chatnode             # 可選:已安裝的會話節點

把這個 YAML 放進被監視目錄即可,改動會熱重載。先確認例程已被識別:

$ dsh --profile ops routines list
nightly-tests          active   0 2 * * *           tz=Asia/Shanghai next=2026-08-15T02:00:00.000Z

第二天早上查看最近運行記錄:

$ dsh --profile ops routines logs nightly-tests --limit 3
[completed] 2026-08-14T18:00:01.000Z 41213 ms session=session-2f7d…
  tests: 3 failed of 412; top failure: flaky wait in auth.spec.ts — drafted fix on branch fix/auth-wait

在信任一條 schedule 之前,先用 dsh --profile ops routines run nightly-tests 手動觸發一次驗證。

適用場景與注意

適合的場景:週期固定、一段 prompt 能說清楚、結果只要一份摘要的任務——夜間測試、定時巡檢、週期性整理。前提是承載進程在觸發時刻存活,錯過運行只補跑一次,不做積壓重放。

幾點注意:

  1. 插件以當前 dsh 進程的權限運行,安裝前應檢查源碼與許可證。本項目 MIT 許可,源碼公開在 GitHub。
  2. 無人值守運行強制 approval: never,任何需要確認的操作都會被自動拒絕並記入 denied、出現在摘要中。寫 prompt 時要把這一點考慮進去。
  3. chatnode 是軟依賴:需要安裝暴露 send(input: { text, title? }) 服務的會話節點;沒有安裝也不影響 file 投遞。
  4. npm 渠道是否已發佈無法確認,當前以 GitHub 安裝方式爲準。

小結

dsh-routines 把「定時跑 prompt、拿到摘要」收進一個 DSH bundle:例程是可 git 提交的 YAML,運行是獨立 one-shot 會話、日誌可審計,投遞落在文件或已安裝的會話節點上。如果你在 DSH 裏有周期性任務的需求,可以從這個 bundle 入手。

  • GitHub 倉庫:https://github.com/Jesse-njx/dsh-routines
  • 社區目錄頁:https://www.skillhub.cn/plugins/Jesse-njx/dsh-routines

目錄爲社區獨立維護的站點,與 DeepSeek / 幻方無官方從屬關係。

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

小夜