dsh-im-cron:为 DeepSeek Harness 添加定时任务

前言

DeepSeek Harness(DSH)的理念是「一切皆插件」,但原生 schedule_* 运行在会话内部,且默认关闭 deliverModelAnswers,导致定时提醒是静默的。dsh-im 负责连接 IM 平台、会话绑定、主动发送与目标管理,本插件负责调度、执行、结果收集与记账。它为 @xmanrui/dsh-im 添加定时任务,在聊天中创建任务,按时间运行,结果返回同一聊天。

插件定位

  • 名称:dsh-im-cron
  • 维护者:mashago
  • 分类:工作流
  • GitHub:https://github.com/mashago/dsh-im-cron
  • 目录页:https://www.skillhub.cn/plugins/mashago/dsh-im-cron
  • 星标:0

它是一个 DSH 插件,为 dsh-im 增加定时通知/脚本/智能体任务,与 dsh-im 协同完成 IM 中的调度与交付。

核心功能

三类 payload

Payload 作用 模型调用
notify 定时发送固定文本 不调用模型
command 定时执行脚本,推送 stdout 不调用模型
agent 定时运行一轮智能体,推送回答 调用 1 轮模型

notify / command 不触碰模型;agent 仅执行时使用模型,交付本身不依赖模型。

工具(全局 im-cron-tools 行)

工具 用途
imcron_remind 定时发送固定文本
imcron_run 定时执行脚本
imcron_ask 定时运行一轮智能体
imcron_list 列出当前聊天任务、下次运行与最近结果
imcron_update 更新任务(id + schedule/text/notify/maxRuns 等)
imcron_remove 删除任务(不删除交付目标)

路由与渠道

路由由表驱动,遵循 dsh-im 的 normalizeRoute。默认 allowChannels 为全部五个渠道:

渠道 直聊 群组 路由键 状态
qq ✅ ✅ userOpenId / groupOpenId 真机测试
feishu ✅ — openId 结构性
weixin ✅ — toUserId 结构性
dingtalk ✅ ✅ userId / openConversationId 结构性
wecom ✅ ✅ chatId 结构性

Feishu 群/线程、微信群、以及 dsh-im 的其他渠道(slack、telegram 等)被显式拒绝。只有 QQ 有真机测试,其他是结构检查与单元测试覆盖。

依赖与约束

  • Node.js:>= 24.9.0(与 DSH 一致)
  • DeepSeek Harness:>= 0.2.2-rc.0 < 0.3.0(由 engines.dsh 强制)
  • pnpm:任意近期版本(dsh plugin 将参数转发给 pnpm)
  • @xmanrui/dsh-im:>= 5.10.0(契约验证基于此版本)
  • 平台:macOS 测试;Linux 预期可工作;Windows 静态检查仅支持 .exe/.com(无 shell,不支持 .sh/.cmd/.bat)

执行与交付

  • agent payload 在专用任务会话中运行,不绑定聊天会话。
  • 交付对象为 botId + targetId,与会话解耦,用户 /new 不影响交付。
  • 无 dsh-im 时,声明的 jobs(含显式目标)仍会运行并记录到 runs.jsonl,但交付状态为 pending,由重试与退避机制处理。
  • 改变主行(im-cron:timezone、scriptDir、activeHours、jobs、caps 等)需要重启 DSH;群聊开关与智能体任务会话设置在 Plugins 页面保存后下次智能体运行生效。

安装与启用

以下命令来自 README 原文,不要凭名称拼接。

# ① 安装 pnpm(若已可用可跳过)
npm install -g pnpm

# ② 安装并配置 dsh-im(至少一个机器人 + 接收目标),并确认可收发
dsh plugin --profile web add @xmanrui/dsh-im

# ③ 安装本插件
dsh plugin --profile web add dsh-im-cron
# 或从仓库安装
dsh plugin --profile web add github:mashago/dsh-im-cron
# 或本地目录/tarball
dsh plugin --profile web add /path/to/dsh-im-cron

# ④ 重启 dsh web,使插件加载

确认行已插入:

dsh --profile web --dump-config | grep im-cron

启动日志应包含:

[im-cron] delivery=dshIm agent=on jobs=N stateDir=~/.dsh/im-cron

delivery=pending 表示启动时未检测到 dsh-im,每次使用时会再次探测;notify / command 仍会运行,交付保持 pending。

典型用法

以下示例来自 README 快速开始。

你说 创建的 payload
“remind me about the meeting in 1 minute” notify + at
“remind me to write the daily report every morning at 9” notify + cron
“run stock-report.sh in 1 minute and tell me when it’s done” command + at
“run the closing script at 15:30 every day, no notification” command + cron + notify:never
“summarize the financial news at 9 every day” agent + cron
“check the processes every 2 minutes, stop after 3 runs” agent + every{minute,2} + maxRuns:3

脚本类 payload 需先将脚本放入 script 目录。

适用场景与注意

适合已有 dsh-im 配置、需要在 IM 聊天中定期执行脚本或智能体、希望定时提醒或批量执行的用户。插件以当前 DSH 进程权限运行,安装前应检查源码与许可证(MIT)。确保在同一 DSH 实例与同一 profile 下使用,插件通过 ctx.get('dshIm') 查找 dsh-im。

小结

dsh-im-cron 将调度与交付解耦,为 dsh-im 提供定时通知、脚本执行与智能体任务能力。配合 dsh-im 的 IM 连接与会话管理,可在聊天中创建、管理并接收定时任务结果。更多细节见目录页与 GitHub 仓库。

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

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

小夜