把 59 个定时任务从 Hermes 搬到 DSH

Hermes 停用了,我在 Mac 上跑的那 59 个定时任务得挪个地方。

先说结果:28 个放 launchd,8 个放 DSH 的插件里,6 个要模型判断的留在 DSH 自带的 schedule。Hermes 那边启用的任务清零。

另外说一句,这次搬家大半是 AI 干的。查文档、改脚本、跑验证、写这篇,都是它;我在旁边做决定,这一步要不要做,这个方案行不行。

搬的过程不算顺,记几个坑。

一、launchd 跑不了 git

有个任务要 git push 到外接硬盘上的仓库。切到 launchd 以后,每天报同一个错:

1
fatal: Unable to read current working directory: Operation not permitted

在终端里敲同一条命令,正常。在 DSH 里跑,也正常。

后来才查明白是 TCC。macOS 的权限是给进程身份的,不是给命令的。launchd 起的子进程算 launchd 的身份,我给终端开的外接盘权限,它用不上。

这类有 7 个:2 个 git,5 个要开浏览器点网页。

launchd 走不通,就换了个法子:让 DSH 的宿主进程自己起子进程跑。宿主进程有我的权限。

于是写了个插件 dsh-noagent-schedule,到点直接执行命令,不叫模型。

现在能干这些:

  • 五段式 cron,也能按固定间隔
  • 每个任务单独的时区
  • 超时,上一次没跑完就跳过
  • 每次运行一份日志,外加 runs.jsonl
  • 设置页和侧边栏,能看退出码,也能手动跑
  • 三个 agent 工具:noagent_status、noagent_run、noagent_log

二、脚本跑完了,通知没了

Hermes 的脚本都是 print 到 stdout,由 Hermes 按 deliver 字段转发到 Telegram 或飞书。搬走以后脚本照跑,输出没人接了。

补了个 wrapper:

1
python3 02_deliver_wrapper.py --target telegram --title 【任务名】 -- bash /path/script.sh

stdout 是空的就不发,有东西才推。跟原来的行为一样。

三、重启一次,任务全没了

launchctl bootstrap 只是把任务注册到这次登录的 launchd 里。重启就没了。

我一开始把 plist 都放在工作区,launchctl print 看得见,跑得也正常,就没管。后来才反应过来,要看它在不在 ~/Library/LaunchAgents。

把 28 个 plist 复制进去,完事。

顺手记两条检查命令:

1
2
launchctl print gui/$(id -u) | grep -c 你的前缀
launchctl print gui/$(id -u)/你的标签 | grep -E "state|runs|last exit"

四、两处各挂一份,差点跑重

早期怕不稳,7 个任务在 launchd 和插件里各挂了一份。

后来发现不对:有个一天跑两次的任务,两边都发就变成四次。

最后 bootout 掉 launchd 那份。一个任务只留一个地方跑。

五、依赖扫漏了提示词里的脚本

搬脚本的时候按 import 递归拉依赖,以为全了。

结果 Agent 类任务的脚本不在 import 链里,写在提示词里:

先跑 x_style_check.py,再跑 jev_reply_gate.py……

7 个任务,16 个脚本,一个都没搬。不补的话,第二天早上 8 点全报 command not found。

后来从提示词里反着抽脚本名,再递归拉依赖,补齐了 26 个。

现在的样子

  • launchd:28 个
  • 插件:8 个
  • DSH schedule:6 个
  • Hermes 那边启用:0

数据也顺手搬了。脚本、venv、日志在 ~/.local/share/dsh-runtime,业务数据在 ~/.local/share/dsh-data,~/.hermes 里留了软链,脚本一行没改。~/.hermes 目录还留着,剩的是 Hermes 自己的东西。

插件是 dsh-noagent-schedule,MIT,代码在 GitHub 上。

完。

Hermes is retired, and the 59 scheduled jobs on my Mac needed a new home.

The short version: 28 went to launchd, 8 to a DSH plugin, and 6 that need model judgement stayed on DSH’s built-in schedule. Nothing is left enabled on the Hermes side.

One thing worth saying first: most of this migration was done by AI. It read the docs, rewrote the scripts, ran the checks, and wrote this post. I made the decisions: whether to take a step, whether an approach was acceptable.

The move was not smooth. Here are the potholes.

1. launchd cannot run git

One job needs to git push to a repository on an external drive. After moving it to launchd, it failed with the same error every day:

1
fatal: Unable to read current working directory: Operation not permitted

The same command worked in a terminal, and worked inside DSH.

The cause was TCC. macOS grants permissions to a process identity, not to a command. A child process started by launchd carries launchd’s identity, so the external-drive permission I gave my terminal did not apply.

Seven jobs were in this group: two git jobs, five that open a browser and click through pages.

launchd was a dead end, so I changed the approach: let the DSH host process start the child process itself. The host already has my permissions.

That became a small plugin, dsh-noagent-schedule, which runs a command on schedule without calling a model.

What it does today:

  • five-field cron, or a fixed interval
  • a separate time zone per job
  • timeout, and skipping a run when the previous one is still going
  • one log file per run plus a runs.jsonl ledger
  • a settings page and sidebar panel for exit codes and manual runs
  • three agent tools: noagent_status, noagent_run, noagent_log

2. Scripts still ran, notifications stopped

Hermes scripts printed to stdout, and Hermes forwarded that output to Telegram or Feishu according to a deliver field. After the move the scripts kept running, but nobody read the output.

I added a wrapper:

1
python3 02_deliver_wrapper.py --target telegram --title 【job name】 -- bash /path/script.sh

Empty stdout sends nothing; anything else is pushed. Same behaviour as before.

3. One reboot wiped every job

launchctl bootstrap registers a job only for the current login. After a reboot it is gone.

At first I kept the plists in a workspace folder. launchctl print showed them and they ran fine, so nothing looked wrong. What matters is whether the plist lives in ~/Library/LaunchAgents.

I copied all 28 plists there. Done.

Two checks worth keeping:

1
2
launchctl print gui/$(id -u) | grep -c your-prefix
launchctl print gui/$(id -u)/your-label | grep -E "state|runs|last exit"

4. Two owners per job nearly doubled the runs

Early on I kept seven jobs in both launchd and the plugin as a fallback.

That turned out wrong: one job runs twice a day, and with two owners it produced four runs.

I booted out the launchd copies. One owner per job.

5. The dependency scan missed scripts named in prompts

When rebuilding scripts I followed imports recursively and thought the set was complete.

Agent jobs were different: their scripts are named inside the prompt, not in an import chain.

run x_style_check.py first, then jev_reply_gate.py …

Seven jobs referenced 16 scripts, and none of them had been migrated. Without a fix, every one would fail with command not found the next morning.

I extracted the script names from the prompts, followed their dependencies, and restored 26 scripts.

Where it stands

  • launchd: 28
  • plugin: 8
  • DSH schedule: 6
  • Hermes still enabled: 0

The data moved too. Scripts, the venv, and logs live under ~/.local/share/dsh-runtime; business data under ~/.local/share/dsh-data; ~/.hermes keeps symlinks, and the scripts did not change a line. The ~/.hermes directory itself stays for now, holding what belongs to Hermes.

The plugin is dsh-noagent-schedule, MIT, on GitHub.

That’s it.