work-rhythm 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/notes/AGENTS.md +1 -0
- package/.agents/notes/decisions/2026-11-30-bot-inbound-uses-websocket-and-a-responder-command.md +1 -0
- package/.agents/notes/decisions/2026-11-30-scheduling-moves-to-a-local-service.md +1 -0
- package/.agents/notes/decisions/2026-12-01-scheduling-is-cli-only-and-needs-a-bound-agent.md +31 -0
- package/.agents/skills/work-rhythm/SKILL.md +11 -9
- package/README.md +1 -0
- package/collectors/local.env.example +4 -2
- package/docs/agents.md +49 -0
- package/docs/channels.md +1 -1
- package/docs/scheduled-tasks.md +2 -12
- package/package.json +1 -1
- package/scripts/cli.js +1 -0
- package/scripts/cmd/agent.js +110 -0
- package/scripts/cmd/check.js +16 -2
- package/scripts/lib/agent.js +156 -17
- package/scripts/lib/bot.js +1 -1
- package/scripts/test/agent.test.js +199 -0
- package/scripts/test/check.test.js +31 -9
- package/scripts/test/config.test.js +0 -2
- package/scripts/test/harness.js +4 -1
- package/scripts/test/listen.test.js +2 -2
- package/scripts/test/rhythm.test.js +2 -2
- package/scripts/test/stubs.js +19 -1
- package/templates/00-config/profile.example.yaml +0 -1
- package/templates/AGENTS.md +1 -1
- package/templates/README.md +1 -1
package/.agents/notes/AGENTS.md
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
| 改录耗费任务的指令或填法 | [录耗费直接写入,只填空格子](decisions/2026-11-30-cost-entry-writes-into-empty-cells-directly.md) |
|
|
24
24
|
| 改推送(`scripts/lib/notify.js`、`scripts/lib/robot.js`)、`docs/channels.md`、`preferences.notify` 的取值,或想知道提醒为什么不直接用 yzj-cli 给自己发 | [推送走个人机器人](decisions/2026-11-30-push-via-personal-robot-webhook.md)、[消息渠道预置进 skill](decisions/2026-11-30-message-channels-are-preset-in-the-skill.md) |
|
|
25
25
|
| 验证一条推送有没有送到,或想把机器人会话加进订阅 | [刚发的消息搜不到](pitfalls/2026-11-30-message-search-lags-after-sending.md) |
|
|
26
|
+
| 改引导第 6 步、`work-rhythm agent`、预置的 agent(`scripts/lib/agent.js`),或想知道为什么不往运行时的调度器建任务 | "+NEW+" |
|
|
26
27
|
| 改值守(`scripts/lib/bot.js`、`scripts/lib/agent.js`),想换一个回复的 agent,或要改值守的权限默认值 | [值守用长连接收消息](decisions/2026-11-30-bot-inbound-uses-websocket-and-a-responder-command.md) |
|
|
27
28
|
| 改本地服务(`scripts/lib/rhythm.js`)、`tasks/*.md`、`profile` 的 `rhythm:` 一节,或想知道定时任务为什么不绑在运行时的调度器上 | [运转的中心挪到本机服务](decisions/2026-11-30-scheduling-moves-to-a-local-service.md) |
|
|
28
29
|
| 写或改自测(`scripts/test/`),或自测在真实使用过的目录里变红 | [自测不能带上本机的个人配置](pitfalls/2026-11-30-selftest-must-not-inherit-local-config.md)、[在用例里再起 node --test 会一个用例都不跑](pitfalls/2026-12-01-spawning-node-test-inside-a-test-runs-nothing.md)、[钩子里登记不了收尾](pitfalls/2026-12-01-node-test-hooks-cannot-register-after-callbacks.md) |
|
package/.agents/notes/decisions/2026-11-30-bot-inbound-uses-websocket-and-a-responder-command.md
CHANGED
|
@@ -46,3 +46,4 @@ Decided: 2026-11-30
|
|
|
46
46
|
- 还没有数据:`edit` 模式下 Bash 要不要确认;客户端对新消息弹不弹提醒。长连接本身已实测(2026-11-30):认证、心跳、系统通知,以及我发给机器人的话——包在 `{"cmd":"directPush","type":"robotMessage","msg":{…}}` 里,`operatorOpenid` 和 `whoami` 的 openId 一致。
|
|
47
47
|
- 重新考虑的情况:云之家的长连接协议变了;ZCode 的命令行有了更轻的无界面入口;要在群里用。
|
|
48
48
|
- 2026-12-01 后续:bash 入口没有了,值守整个是 node,命令是 `work-rhythm listen`;agent 自定义命令不再经过 bash 展开。见[全改成 JS、收成一个 work-rhythm 命令](2026-12-01-everything-is-js-behind-work-rhythm.md)。
|
|
49
|
+
- 2026-12-01 后续:值守的 agent 改由 `work-rhythm agent bind` 绑(预置加了 qoder、claude),没绑就不跑。见[定时任务只建在 CLI 上,先绑一个 agent](2026-12-01-scheduling-is-cli-only-and-needs-a-bound-agent.md)。
|
|
@@ -35,3 +35,4 @@ Decided: 2026-11-30
|
|
|
35
35
|
- 还没有数据:服务连续跑几天的稳定性;端口被占时的表现;别的系统上怎么常驻。
|
|
36
36
|
- 重新考虑的情况:运行时的调度器能不占会话、能跨目录建任务了;或者本机不让跑常驻进程。
|
|
37
37
|
- 2026-12-01 后续:bash 入口没有了,服务是 `work-rhythm rhythm`;判断工作日直接调 today 的函数,采集直接在同一个进程里跑 sync,不再起 bash 子进程。见[全改成 JS、收成一个 work-rhythm 命令](2026-12-01-everything-is-js-behind-work-rhythm.md)。
|
|
38
|
+
- 2026-12-01 后续:「备选:绑到运行时的调度器」去掉了,定时任务只建在本地服务上,而且要先绑一个 agent(`work-rhythm agent`)。见[定时任务只建在 CLI 上,先绑一个 agent](2026-12-01-scheduling-is-cli-only-and-needs-a-bound-agent.md)。
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# 定时任务只建在 CLI 的本地服务上,先绑一个 agent;agent 不再在自己运行时的调度器上建任务
|
|
2
|
+
|
|
3
|
+
Decided: 2026-12-01
|
|
4
|
+
|
|
5
|
+
## Problem
|
|
6
|
+
|
|
7
|
+
[运转的中心挪到本机服务](2026-11-30-scheduling-moves-to-a-local-service.md)之后留了一条备选:跑不了本地服务时,把任务绑到 agent 运行时自带的调度器(ZCode 的 Cron、DSH 的 schedule)上,profile 里还有 `automations` 记它们。用户定了方向:后续定时任务都在 CLI 上,agent 不需要去构建定时任务;但 CLI 要配置一个 agent(定时任务和机器人响应都要它来跑),这件事要写进引导;没有绑定 agent 就不支持机器人响应,定时任务只能建立在 agent 上。引导里怎么选 agent:检测本机的,或者调用 skill 的是哪个 agent 就用当前这个。
|
|
8
|
+
|
|
9
|
+
## Decision
|
|
10
|
+
|
|
11
|
+
- 定时任务只建在 `work-rhythm rhythm` 上。去掉「备选:绑到 agent 运行时的调度器」那一节和 profile 的 `automations`;skill 明确不往运行时的调度器建任务。
|
|
12
|
+
- 新增 `work-rhythm agent`:`detect` 列出本机装了哪些预置、现在是不是有 agent 正在调这个 skill、现在绑的是哪个(`--json` 给 agent 读);`bind` 写进 `collectors/local.env` 的 `YZJ_BOT_AGENT`,先确认本机找得到;`test` 让它只读答一句;`doctor`。
|
|
13
|
+
- 引导第 6 步改成「绑定 agent,装本地服务」:默认绑正在调这个 skill 的那个 agent(按它给工具留的环境变量认:`ZCODE_*`、`DSH_SESSION_ID`、`QODER_*`、`CLAUDECODE`),它没装命令行或用户想换就从装了的里面选;一个都没装就如实说做不了,`schedule` 留空。
|
|
14
|
+
- 没绑 agent:`rhythm` 有任务就不起,`listen` 不跑,`check` 在引导做完后报「schedule 里有任务却没绑 agent」。只绑 agent 跑任务不算要开值守——`check` 改成装了值守(launchd 里有它)才核对值守的配置。
|
|
15
|
+
- 预置从两个加到四个:zcode、dsh、qoder(Qoder CLI)、claude(Claude Code)。各家的调用方式、权限模式见 [docs/agents.md](../../../docs/agents.md)。
|
|
16
|
+
|
|
17
|
+
## Alternatives considered
|
|
18
|
+
|
|
19
|
+
**保留运行时调度器作为备选。** 被否:两条路并存,用户要记两套,实测两边同开会重复推送;而且任务绑在某个会话的工作区上,换运行时就没了。
|
|
20
|
+
|
|
21
|
+
**`YZJ_BOT_AGENT` 继续手写。** 被否:用户不知道本机有哪些 agent 能无界面调用,也不知道 DSH 要用自带的 Node、Qoder 要另装命令行;`agent detect` / `bind` 把这些查清楚、拒绝绑不上的,引导里一步做完。
|
|
22
|
+
|
|
23
|
+
**「谁在调 skill」问用户。** 推迟作为兜底:环境变量能认出 ZCode、DSH,认不出来再让用户选;按前缀猜 Qoder 的变量名是猜的,没文档。
|
|
24
|
+
|
|
25
|
+
**再给 Claude Code、Codex 等多做几个预置。** 做了 claude(和 ZCode 同一套参数),没做别的:本机没有,写了也验不了;自定义命令那条路够用。
|
|
26
|
+
|
|
27
|
+
## Consequences
|
|
28
|
+
|
|
29
|
+
- Qoder 和 Claude Code 两个预置按官方文档写,没在真机上跑过(本机没装);`work-rhythm agent test` 是装了之后一步验证的办法。
|
|
30
|
+
- 「认正在调的 agent」靠环境变量,各家公司随时可能改名;认不出来只是退回让用户选,不会出错。
|
|
31
|
+
- `check` 不再把「配了 YZJ_BOT_AGENT」当成「要开值守」;装了值守才核对值守。
|
|
@@ -29,7 +29,7 @@ when_to_use: "第一次进入工作目录、初始化还没做完(setup.status
|
|
|
29
29
|
3. **让 AI 找**:`work-rhythm workdir find` 列出本机带 `00-config/profile.yaml` 的目录(路径、初始化状态、称呼),把候选给用户选,选中就登记。一个都没找到就照实说,回到另外两项。
|
|
30
30
|
|
|
31
31
|
没有选择题工具就把三项列出来让对方回数字。用户说「按默认」「随便」时选新建。
|
|
32
|
-
-
|
|
32
|
+
- 定时任务全在 `work-rhythm rhythm` 这个本地服务上,和会话无关:不管当前目录是不是 WORKDIR,都不要往 agent 运行时自带的调度器上建任务(原因见「步骤 6」)。
|
|
33
33
|
|
|
34
34
|
## 事实入口
|
|
35
35
|
|
|
@@ -42,6 +42,7 @@ when_to_use: "第一次进入工作目录、初始化还没做完(setup.status
|
|
|
42
42
|
| 接入某个 IM | `docs/im-adapters.md` |
|
|
43
43
|
| 开通提醒推送(消息渠道),或给别的 IM 新增一个渠道 | `docs/channels.md` |
|
|
44
44
|
| 执行或设置定时任务 | `docs/scheduled-tasks.md` |
|
|
45
|
+
| 给 work-rhythm 绑定 agent(定时任务和值守用哪个),或本机哪个 agent 能用 | `docs/agents.md` |
|
|
45
46
|
| 了解用户 | `00-config/profile.yaml`、`00-config/sources.yaml`、`05-goals/` |
|
|
46
47
|
| 写或改脚本、配置、文档格式之前,或者刚踩了坑 | `.agents/notes/AGENTS.md`,按它的路由表看相关的踩坑笔记 |
|
|
47
48
|
|
|
@@ -153,15 +154,16 @@ IM 是工作密度最高的信号,也决定了后面能不能自动化,所
|
|
|
153
154
|
|
|
154
155
|
然后问要不要把提醒推到 IM,要就按「消息渠道」开通:主 IM 有预置渠道的(现在是云之家),带着用户把那几步做完;没有预置的如实说现在还做不了,`notify` 留空。最后把三个开关写进 `preferences`:`granularity`(默认 `coarse`)、`daily_question`(中午进展里要不要顺带问一个问题)、`notify`(渠道的名字,没有就留空)。
|
|
155
156
|
|
|
156
|
-
### 步骤 6
|
|
157
|
+
### 步骤 6:绑定 agent,装本地服务
|
|
157
158
|
|
|
158
|
-
|
|
159
|
+
定时任务全在 `work-rhythm rhythm` 这个本地服务上:到点采集、到点把任务交给 agent 跑、跑完经消息渠道推送、在本机起网页服务。它和会话无关,agent 不在自己运行时的调度器上建任务——那条路已经不走了。服务到点要一个 agent 来跑,机器人值守(「消息渠道」)也是它来答,所以先绑一个。细节见 `docs/agents.md`。
|
|
159
160
|
|
|
160
|
-
1.
|
|
161
|
-
2.
|
|
162
|
-
3.
|
|
163
|
-
4.
|
|
164
|
-
5.
|
|
161
|
+
1. **看本机有什么**:跑 `work-rhythm agent --json`。它列出预置的四个(zcode、dsh、qoder、claude)各装没装,以及现在是不是有 agent 正在调这个 skill(按它给工具留的环境变量认)。
|
|
162
|
+
2. **定绑哪个**:默认就用正在调的这个 skill 的 agent——用户正在用它,模型和登录都是现成的;它没装命令行、或用户想换,就把装了的列出来让他选。用 `work-rhythm agent bind <名字>` 写进 `collectors/local.env`(`YZJ_BOT_AGENT`),再 `work-rhythm agent test` 让它答一句,把回答给用户看。一个都没装:如实说定时任务和机器人值守现在做不了,按 `docs/agents.md` 教他装一个,`schedule` 留空,原因记进 `setup.skipped`,下面的 4、5 不做。
|
|
163
|
+
3. **定时间**:问上下班时间,按 `docs/scheduled-tasks.md` 的默认规则换算出时间点(上班前 10 分钟、午休开始、下班前 15 分钟),用户确认后写入 `schedule`;不要的任务在 `schedule` 里写空。介绍几个标准任务(每日工作计划、中午工作进展、晚间工作复盘、遗留待处理)和可选的每周工作规律,确认要开哪些。
|
|
164
|
+
4. **说明待决的事怎么走**:不做定时巡查。计划和复盘的推送里会提醒有几件等他定,到时候对任何一个能读到这个工作目录的 agent 说「有什么要我定」,就逐件来问。
|
|
165
|
+
5. **装服务**:`work-rhythm rhythm doctor` 查配置,`work-rhythm rhythm due` 给用户看今天什么时候跑什么;`work-rhythm rhythm run <任务id> --push` 试一遍,看推送和页面。征得同意后 `install`(macOS launchd 常驻)或者让用户自己 `start`。
|
|
166
|
+
6. 把 `setup.status` 改成 `done`,更新 `setup.updated`。
|
|
165
167
|
|
|
166
168
|
### 步骤 7:交代用法
|
|
167
169
|
|
|
@@ -213,7 +215,7 @@ IM 是工作密度最高的信号,也决定了后面能不能自动化,所
|
|
|
213
215
|
3. **没有预置的,先问用户那个 IM 有没有机器人这类能力**(Webhook 机器人、应用消息)。有就按 `docs/channels.md` 的「新增一个渠道」接成内置渠道;都没有就如实说做不了,`notify` 留空,原因记进 `setup.skipped`。不要退而用用户的账号给他自己发消息:推送会跟着登录一起失效。
|
|
214
216
|
4. **核对。** `work-rhythm check` 通过后,把要发的测试内容给用户看一眼,同意了用 `work-rhythm notify "<内容>"` 发一条,请他确认收得到、客户端有提醒。
|
|
215
217
|
|
|
216
|
-
渠道还能反过来收:用户在 IM 里说的话交给本地的 agent 处理,回复再发回来,这叫「值守」。它要常驻、每条消息跑一次 agent
|
|
218
|
+
渠道还能反过来收:用户在 IM 里说的话交给本地的 agent 处理,回复再发回来,这叫「值守」。它要常驻、每条消息跑一次 agent,所以默认不开;没绑 agent 就开不了。用户要开,或问能不能在 IM 里直接对话时,按 `docs/channels.md` 的「收消息:值守」走:先讲清代价,以及权限默认只读,再确认绑了 agent(第 6 步的 `work-rhythm agent bind`,没绑就先绑),配好、试一句。
|
|
217
219
|
|
|
218
220
|
## 手动执行定时任务
|
|
219
221
|
|
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@ ln -s "$(npm root -g)/work-rhythm/.agents/skills/work-rhythm" ~/.agents/skills/w
|
|
|
34
34
|
| `today`、`goals`、`decisions` | 每日约定、长期目标、待决与决定的记录 |
|
|
35
35
|
| `sync`、`collect` | 跑内置或自己写的采集器,原始数据落 `01-inbox/` |
|
|
36
36
|
| `notify`、`listen` | 消息渠道:把提醒推给我;值守,收我在 IM 里说的话交给本地 agent |
|
|
37
|
+
| `agent` | 定时任务和机器人值守用哪个 agent:检测本机的、绑定、试一句([docs/agents.md](docs/agents.md)) |
|
|
37
38
|
| `rhythm` | 本地服务:定时采集、定时整理、经消息渠道推送、本机网页 |
|
|
38
39
|
| `check`、`selftest`、`pack` | 自检;自测;把 skill 和这个包打成可分发的目录 |
|
|
39
40
|
|
|
@@ -35,16 +35,18 @@
|
|
|
35
35
|
# 值守(work-rhythm listen,消息渠道的收消息一半,见 docs/channels.md「收消息:值守」):在 IM 里说的话交给本地的 agent 处理并回复。
|
|
36
36
|
# 不配 YZJ_BOT_AGENT 就等于没开。开了就是常驻进程,每来一条消息跑一次 agent
|
|
37
37
|
# 本地服务(work-rhythm rhythm)跑定时任务用的也是 YZJ_BOT_AGENT:不配的话定时任务跑不了,采集和网页照常
|
|
38
|
-
# YZJ_BOT_AGENT 让哪个 agent
|
|
38
|
+
# 用 work-rhythm agent bind <名字> 写最省事(会先检查本机装没装)。YZJ_BOT_AGENT 让哪个 agent 回复,预置四个,或者一条自己的命令:
|
|
39
39
|
# "dsh" DSH(DeepSeek Harness)的 headless 模式。模型和凭据跟着 DSH 桌面应用里的配置走,你在 DSH 里默认用哪个模型,机器人就用哪个。
|
|
40
40
|
# 要装了 DSH 桌面版;位置不对可用 DSH_HOME、DSH_NODE、DSH_CLI 改
|
|
41
41
|
# "zcode" ZCode 自带的命令行。注意它的模型是命令行自己的默认选择,不是 ZCode 窗口里给会话选的(本机实测是 opencode-go 的 minimax-m3.1-flash)
|
|
42
|
+
# "qoder" Qoder CLI(要另装:curl -fsSL https://qoder.com/install | bash,装完 qoder login)。模型和登录跟着 Qoder CLI 自己的配置
|
|
43
|
+
# "claude" Claude Code 的命令行
|
|
42
44
|
# 一条自己的命令:我的消息作为最后一个参数传给它,回复打到标准输出,退出码 0 算成功。路径带空格的命令先写成一个脚本再写它的路径
|
|
43
45
|
# YZJ_BOT_AGENT_MODE 是权限:plan 只读(默认,能查能答能出计划,不改文件);edit 允许改工作目录,等于我在聊天里说什么它就做什么
|
|
44
46
|
# YZJ_BOT_TIMEOUT 每条消息最多等多少秒(默认 300);YZJ_BOT_REPLY_MAX 回复最多多少字(默认 2000,超出截断并注明)
|
|
45
47
|
# 消息一到机器人先回「收到,正在处理,稍等。」,YZJ_BOT_ACK=0 关掉。
|
|
46
48
|
# 每句话后面会带给 agent 一句提示(回复要以纯文本私聊发回,直接答、简短答),YZJ_BOT_PREAMBLE="" 关掉,或换成自己的
|
|
47
|
-
# 配完跑 work-rhythm listen doctor 检查
|
|
49
|
+
# 配完跑 work-rhythm agent test 让它答一句;开值守再跑 work-rhythm listen doctor 检查
|
|
48
50
|
# YZJ_BOT_AGENT="dsh"
|
|
49
51
|
# YZJ_BOT_AGENT_MODE="plan"
|
|
50
52
|
|
package/docs/agents.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# agent:定时任务和机器人值守用哪个
|
|
2
|
+
|
|
3
|
+
定时任务全在 `work-rhythm rhythm` 这个本地服务上,agent 不在自己运行时的调度器上建任务。服务到点要把任务交给一个 agent 跑,机器人值守([channels.md](channels.md))也是它来答——所以要先给 work-rhythm 绑定一个 agent。没绑就没有定时任务(`rhythm` 拒绝起),也不支持机器人响应(`listen` 拒绝跑)。
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
work-rhythm agent # 本机装了哪些、现在是不是有 agent 正在调这个 skill、现在绑的是哪个
|
|
7
|
+
work-rhythm agent bind [名字|命令] # 绑定,写进 collectors/local.env 的 YZJ_BOT_AGENT
|
|
8
|
+
work-rhythm agent test ["一句话"] # 让绑定的 agent 只读答一句,看模型和凭据通不通
|
|
9
|
+
work-rhythm agent doctor # 绑定的 agent 配置和依赖有没有问题
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
绑哪个:**现在正在调这个 skill 的那个 agent,它装了的话就用它**——用户正在用它,模型和登录都是现成的;它没装命令行、或者用户想换,就从装了的里面选;都由用户定。一个都没装,如实说定时任务和值守现在做不了,教他装一个(下表),`schedule` 留空,原因记进 `setup.skipped`。
|
|
13
|
+
|
|
14
|
+
## 预置
|
|
15
|
+
|
|
16
|
+
| 名字 | 是什么 | 怎么找到 | 模型和凭据跟谁走 | 实测 |
|
|
17
|
+
|---|---|---|---|---|
|
|
18
|
+
| `zcode` | ZCode 自带的命令行(桌面版里就有,不用另装) | PATH 上的 `zcode`,或 `/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs`;`ZCODE_CLI` 可指定 | 它自己的默认选择,不是 ZCode 窗口里给会话选的模型 | 是 |
|
|
19
|
+
| `dsh` | DSH(DeepSeek Harness)桌面版的 headless 模式 | `~/.dsh-desktop/runtime/<版本>/dsh/` 下的入口,用它自带的 Node 跑;`DSH_HOME`、`DSH_NODE`、`DSH_CLI` 可指定 | DSH 桌面应用里配好的模型和凭据(值守自动生成一份只含模型配置、并打开凭据存储的覆盖文件带进去,密钥始终在 DSH 自己的存储里) | 是 |
|
|
20
|
+
| `qoder` | Qoder CLI。装了 Qoder 的 IDE 不等于装了它:`curl -fsSL https://qoder.com/install \| bash`(或 `npm install -g @qoder-ai/qodercli`),装完 `qoder login` | PATH 上的 `qoder` / `qodercli`;`QODER_CLI` 可指定 | Qoder CLI 自己的配置(`~/.qoder`) | 按官方文档写的,没在真机上跑过 |
|
|
21
|
+
| `claude` | Claude Code 的命令行 | PATH 上的 `claude`;`CLAUDE_CLI` 可指定 | Claude Code 自己的登录 | 按公开的用法写的,没在真机上跑过 |
|
|
22
|
+
|
|
23
|
+
其余值当成一条自己的命令:按空白拆开(引号里的算一个参数),消息作为最后一个参数传给它,回复打到标准输出,退出码 0 算成功。不支持管道、重定向——要的话包一层脚本。
|
|
24
|
+
|
|
25
|
+
各家无界面调用的写法都在 [scripts/lib/agent.js](../scripts/lib/agent.js) 的 `PRESETS` 一带:
|
|
26
|
+
|
|
27
|
+
- zcode:`zcode --cwd <工作目录> --mode <模式> [--resume <会话>] --no-color --json -p <这句话>`,回答在 JSON 的 `response`,会话在 `sessionId`。
|
|
28
|
+
- dsh:`<自带 node> --import <tsx> <入口> --profile headless --patch <覆盖文件> --permission-mode <模式> [--session-id <会话>] --json <这句话>`,`--json` 一行一个事件,回答在 `final`。
|
|
29
|
+
- qoder:`qoder --cwd <工作目录> --permission-mode <模式> [--resume <会话>] --output-format json --print <这句话>`,回答在 JSON 的 `result`,会话在 `session_id`。无界面模式下它不弹确认,要确认的操作一律被拒。
|
|
30
|
+
- claude:`claude --cwd <工作目录> --permission-mode <模式> [--resume <会话>] --output-format json -p <这句话>`。
|
|
31
|
+
|
|
32
|
+
## 权限
|
|
33
|
+
|
|
34
|
+
`YZJ_BOT_AGENT_MODE` 两个常用值,各家换成自己的叫法:
|
|
35
|
+
|
|
36
|
+
| 我们叫它 | 意思 | zcode | dsh | qoder | claude |
|
|
37
|
+
|---|---|---|---|---|---|
|
|
38
|
+
| `plan`(默认) | 只读:能查、能答、能出计划,不改文件 | `plan` | `read-only` | `plan` | `plan` |
|
|
39
|
+
| `edit` | 允许改工作目录 | `edit` | `workspace-write` | `accept_edits` | `acceptEdits` |
|
|
40
|
+
|
|
41
|
+
别的值原样传给那个 agent。qoder 的 `edit` 只自动放行改文件,shell 命令在无界面下会被拒;任务里要跑命令(`work-rhythm today` 这类)就把模式写成 `auto`(无人值守,由它的分类器决定)。值守默认 `plan`;本地服务跑任务默认 `edit`(profile 的 `rhythm.agent-mode` 可改)。
|
|
42
|
+
|
|
43
|
+
## 怎么认「现在是谁在调这个 skill」
|
|
44
|
+
|
|
45
|
+
agent 给工具留的环境变量:ZCode 留 `ZCODE_SESSION_ID`、`DSH` 留 `DSH_SESSION_ID` / `DSH_SHELL`、Qoder 的变量名没有文档、按 `QODER_` 前缀认、Claude Code 留 `CLAUDECODE` / `CLAUDE_CODE_*`。ZCode 也会留 `CLAUDE_CODE_*`,所以先认 `ZCODE_*`。认不出来(不是从 agent 的工具里跑的)就只列装了哪些,让用户选。
|
|
46
|
+
|
|
47
|
+
## 自测和实测的边界
|
|
48
|
+
|
|
49
|
+
`work-rhythm selftest` 用假的命令行工具把四个预置的参数、续会话、权限模式都过一遍;真机上哪些跑过见上表的「实测」一列。换了一个新版本、或者换了模型配置之后,用 `work-rhythm agent test` 试一句就知道还通不通。
|
package/docs/channels.md
CHANGED
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
{"msg":{"groupType":3,"type":2,"robotId":"BOT-…","robotName":"工作王","msgId":"…","content":"你好","operatorOpenid":"<和 whoami 一致的 openId>","operatorName":"我","time":1796046214771},"level":0,"cmd":"directPush","type":"robotMessage"}
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
1. **配 agent
|
|
63
|
+
1. **配 agent**:没绑 agent 就没有值守。先 `work-rhythm agent detect` 看本机有哪些,`work-rhythm agent bind <名字>` 绑定(写进 `collectors/local.env` 的 `YZJ_BOT_AGENT`,见 [agents.md](agents.md));也可以手写 `YZJ_BOT_AGENT`,三种写法。
|
|
64
64
|
- `"dsh"`:用 DSH(DeepSeek Harness)的 headless 模式。模型和凭据跟着 DSH 桌面应用里的配置走,你在 DSH 里默认用哪个模型,机器人就用哪个。要装了 DSH 桌面版。
|
|
65
65
|
- `"zcode"`:用 ZCode 自带的命令行。它的模型是命令行自己的默认选择,不是 ZCode 窗口里给会话选的,见下面「用哪个模型」。
|
|
66
66
|
- 一条自己的命令:我的消息作为最后一个参数传给它,回复打到标准输出,退出码 0 算成功。路径带空格的先写成一个脚本。
|
package/docs/scheduled-tasks.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 定时任务
|
|
2
2
|
|
|
3
|
-
运转的中心是本地服务 `work-rhythm rhythm`:到点采集,到点把任务交给 agent
|
|
3
|
+
运转的中心是本地服务 `work-rhythm rhythm`:到点采集,到点把任务交给 agent 跑一遍,跑完经消息渠道把总结推给我,再在本机起一个网页服务给我看页面。定时任务只建在这个服务上,不建在 agent 运行时自带的调度器上;换运行时也不用重建。服务要先绑一个 agent(`work-rhythm agent bind`,见 [agents.md](agents.md)),没绑就不起。Markdown 仍是唯一的记录,任务写的东西都在每日文件和那几个固定文件里;页面只是同一份内容的视图。
|
|
4
4
|
|
|
5
5
|
长期目标不单独占任务:每日工作计划负责提醒到期的检查、安排当天的一个最小动作,晚间工作复盘负责收集进展。目标文件的格式见 [formats.md](formats.md) 的「长期目标」。
|
|
6
6
|
|
|
@@ -95,21 +95,11 @@ work-rhythm rhythm install # macOS:装成常驻(开机自启、挂了拉
|
|
|
95
95
|
|
|
96
96
|
在云之家里做这件事,需要值守的 agent 有写权限(`YZJ_BOT_AGENT_MODE=edit`),不然它只能问、不能记录。
|
|
97
97
|
|
|
98
|
-
## 备选:绑到 agent 运行时的调度器
|
|
99
|
-
|
|
100
|
-
跑不了本地服务的时候(机器上没有 node 22、或者不方便常驻),可以把任务绑到 agent 运行时自带的调度器上:指令用 `tasks/<id>.md` 的全文,推送由任务最后一步自己调用 `work-rhythm notify -` 完成。
|
|
101
|
-
|
|
102
|
-
- **ZCode**:用 `CronCreate`。先用 `CronList` 查重;时间换算成 5 字段的 cron(`08:20` 工作日是 `20 8 * * 1-5`);prompt 用任务文件的全文,占位符 `<DATE>` 这类保持原样;创建前把任务名、时间给我看;建好把任务名记到 `profile.yaml` 的 `automations` 里。
|
|
103
|
-
- **DSH**:`schedule_create` 落在会话的工作目录,做法相同。
|
|
104
|
-
- 定时任务绑定在创建它的会话所在的工作区,所以必须站在 WORKDIR 里创建。
|
|
105
|
-
|
|
106
|
-
两条路只能开一条:两边同时开会重复写文件、重复推送。
|
|
107
|
-
|
|
108
98
|
## 已知限制
|
|
109
99
|
|
|
110
100
|
- 任务是一次完整的 agent 运行,推送到得比任务时间晚:`deepseek-v4.1-flash` 下每日计划约一分半。
|
|
111
101
|
- 调度器只认星期和 `work-rhythm today` 的判断:调休上班的日子加进 `workdays`,放假的日子加进 `holidays`,每年更新一次。
|
|
112
|
-
- agent 要能在工作目录里读写文件、跑脚本;`dsh` 用 `workspace-write`,`zcode` 用 `edit
|
|
102
|
+
- agent 要能在工作目录里读写文件、跑脚本;`dsh` 用 `workspace-write`,`zcode` 用 `edit`,各家见 [agents.md](agents.md)。
|
|
113
103
|
- 网页服务只在本机的浏览器里看得见。
|
|
114
104
|
- 复盘里并着遗留整理,所以它比别的任务长。
|
|
115
105
|
- 服务只在 macOS 上能装成常驻(launchd);别的系统把 `work-rhythm rhythm start` 交给 systemd 之类。
|
package/package.json
CHANGED
package/scripts/cli.js
CHANGED
|
@@ -23,6 +23,7 @@ const COMMANDS = {
|
|
|
23
23
|
check: 'check 改完脚本、配置或文档后跑一遍:语法、内链、预算、配置、密钥、笔记',
|
|
24
24
|
listen: 'listen probe|run|handle|handle-frame|reset|doctor|install|uninstall|status 值守:收我在 IM 里说的话,交给本地 agent 回复',
|
|
25
25
|
rhythm: 'rhythm start|stop|status|due|run|serve|render|doctor|install|uninstall 本地服务:定时采集、定时整理、推送、网页',
|
|
26
|
+
agent: 'agent [bind [名字]|test|doctor] 定时任务和机器人值守用哪个 agent:检测本机的、绑定、试一句',
|
|
26
27
|
workdir: 'workdir [register|find|config|blank] 工作目录在哪:找、登记、扫描本机;不带子命令是找',
|
|
27
28
|
init: 'init <目录> 新建一个工作目录(空白模板、登记)',
|
|
28
29
|
pack: 'pack [--out <目录>] 把 skill 和这个包打成可分发的目录',
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// work-rhythm agent:定时任务和机器人值守都要一个 agent 来跑,这里管「用哪个」。
|
|
2
|
+
// 用法: work-rhythm agent 看本机装了哪些、现在是不是有 agent 正在调这个 skill、现在绑的是哪个
|
|
3
|
+
// work-rhythm agent bind <名字|命令> 绑定:写进 collectors/local.env 的 YZJ_BOT_AGENT。不给名字就用正在调的这个,没有就装了的第一个
|
|
4
|
+
// work-rhythm agent test ["一句话"] 让绑定的 agent 答一句,看模型和凭据通不通(默认「你好,用一句话介绍你自己」)
|
|
5
|
+
// work-rhythm agent doctor 绑定的 agent 配置和依赖有没有问题
|
|
6
|
+
// work-rhythm agent --json detect 的结果打成 JSON,给 agent 读
|
|
7
|
+
// 预置:zcode(ZCode 自带的命令行)、dsh(DSH 的 headless 模式)、qoder(Qoder CLI)、claude(Claude Code);其余值当成一条自己的命令。
|
|
8
|
+
// 「正在调这个 skill 的是哪个」看的是它给工具留的环境变量:ZCODE_*、DSH_SESSION_ID、QODER_*、CLAUDECODE / CLAUDE_CODE_*。
|
|
9
|
+
// 没绑 agent 就没有定时任务(rhythm 拒绝起)和机器人响应(listen 拒绝跑)。各家的调用方式和权限见 docs/agents.md
|
|
10
|
+
'use strict';
|
|
11
|
+
const fs = require('node:fs');
|
|
12
|
+
const path = require('node:path');
|
|
13
|
+
const { EXIT, Fail, UsageError } = require('../lib/run');
|
|
14
|
+
const { settings } = require('../lib/config');
|
|
15
|
+
const { PRESETS, PRESET_NAMES, invokingAgent, installedAgents, bindAgent, createAgent } = require('../lib/agent');
|
|
16
|
+
|
|
17
|
+
const USAGE = `用法: work-rhythm agent [子命令]
|
|
18
|
+
看本机装了哪些、现在是不是有 agent 正在调这个 skill、现在绑的是哪个(--json 打成 JSON)
|
|
19
|
+
bind [名字|命令] 绑定,写进 collectors/local.env 的 YZJ_BOT_AGENT;不给名字就用正在调的这个,没有就装了的第一个
|
|
20
|
+
test ["一句话"] 让绑定的 agent 答一句
|
|
21
|
+
doctor 绑定的 agent 配置和依赖有没有问题
|
|
22
|
+
预置:${PRESET_NAMES.join('、')};其余值当成一条自己的命令`;
|
|
23
|
+
|
|
24
|
+
function binding(root, env) {
|
|
25
|
+
return (settings(root, env).YZJ_BOT_AGENT || '').trim();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 建议绑哪个:正在调这个 skill 的那个(它装了的话);否则装了的第一个;都没有就空
|
|
29
|
+
function suggest(list) {
|
|
30
|
+
const invoking = list.find((a) => a.invoking && a.found);
|
|
31
|
+
if (invoking) return invoking.name;
|
|
32
|
+
const first = list.find((a) => a.found);
|
|
33
|
+
return first ? first.name : '';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = {
|
|
37
|
+
usage: USAGE,
|
|
38
|
+
async run(args, ctx) {
|
|
39
|
+
const { root, stdout, stderr, env } = ctx;
|
|
40
|
+
const list = installedAgents(env);
|
|
41
|
+
const json = args.includes('--json');
|
|
42
|
+
const rest = args.filter((a) => a !== '--json');
|
|
43
|
+
const [verb, ...params] = rest;
|
|
44
|
+
const bound = binding(root, env);
|
|
45
|
+
|
|
46
|
+
switch (verb) {
|
|
47
|
+
case undefined: {
|
|
48
|
+
if (params.length) throw new UsageError(USAGE);
|
|
49
|
+
const invoking = invokingAgent(env);
|
|
50
|
+
const pick = suggest(list);
|
|
51
|
+
const report = {
|
|
52
|
+
invoking,
|
|
53
|
+
invokingFound: invoking ? list.find((a) => a.name === invoking).found : false,
|
|
54
|
+
bound: presetKindOf(bound),
|
|
55
|
+
boundValue: bound,
|
|
56
|
+
suggest: pick,
|
|
57
|
+
agents: list.map((a) => ({ name: a.name, label: a.label, found: a.found, command: a.command, problem: a.problem || undefined, invoking: a.invoking })),
|
|
58
|
+
};
|
|
59
|
+
if (json) {
|
|
60
|
+
stdout.write(`${JSON.stringify(report, null, 1)}\n`);
|
|
61
|
+
return EXIT.OK;
|
|
62
|
+
}
|
|
63
|
+
stdout.write('本机的 agent:\n');
|
|
64
|
+
for (const a of list) {
|
|
65
|
+
const how = a.found ? a.command : `没装:${a.problem}`;
|
|
66
|
+
stdout.write(` ${a.name.padEnd(7)}${a.found ? '装了' : '没装'} ${a.label}${a.invoking ? ' ← 现在是它在调这个 skill' : ''}\n ${how}\n`);
|
|
67
|
+
}
|
|
68
|
+
stdout.write(`正在调这个 skill 的:${invoking || '认不出来(不是从 agent 的工具里跑的,或者它不留标记)'}\n`);
|
|
69
|
+
stdout.write(`现在绑定的:${bound || '没绑'}${bound && presetKindOf(bound) === 'custom' ? `(一条自定义命令,${PRESET_NAMES.join('/')} 以外)` : ''}\n`);
|
|
70
|
+
if (!bound) stdout.write(`没绑 agent 就没有定时任务,也不支持机器人响应。${pick ? `建议:work-rhythm agent bind ${pick}` : '本机一个预置的 agent 都没装,先装一个(docs/agents.md)'}\n`);
|
|
71
|
+
return EXIT.OK;
|
|
72
|
+
}
|
|
73
|
+
case 'bind': {
|
|
74
|
+
if (params.length > 1) throw new UsageError(USAGE);
|
|
75
|
+
const name = params[0] || suggest(list);
|
|
76
|
+
if (!name) throw new Fail(EXIT.NOT_CONFIGURED, '本机没找到能用的 agent,也没指定要绑的命令:装一个预置的(docs/agents.md),或者 work-rhythm agent bind "<一条命令>"');
|
|
77
|
+
const r = bindAgent(root, env, name);
|
|
78
|
+
if (r.problems) throw new Fail(EXIT.NOT_CONFIGURED, `绑不了 ${name}:${r.problems.join(';')}`);
|
|
79
|
+
stdout.write(`已绑定 ${name}${r.kind === 'custom' ? '(一条自定义命令)' : `(${PRESETS[r.kind].label})`},写进了 ${path.relative(root, r.file)} 的 YZJ_BOT_AGENT。\n`);
|
|
80
|
+
stdout.write(`下一步:work-rhythm agent test 让它答一句;定时任务用 work-rhythm rhythm doctor 查配置,机器人值守用 work-rhythm listen doctor。\n`);
|
|
81
|
+
return EXIT.OK;
|
|
82
|
+
}
|
|
83
|
+
case 'test': {
|
|
84
|
+
if (params.length > 1) throw new UsageError(USAGE);
|
|
85
|
+
if (!bound) throw new Fail(EXIT.NOT_CONFIGURED, '还没绑 agent:work-rhythm agent detect 看本机有哪些,work-rhythm agent bind <名字> 绑定');
|
|
86
|
+
const started = Date.now();
|
|
87
|
+
// 只读模式跑一句;会话落在 01-inbox/_agent/ 下,不碰值守和定时任务各自的专属会话
|
|
88
|
+
const agent = createAgent({ root, agent: bound, mode: 'plan', timeoutS: 180, env: settings(root, env), log: (event, fields) => stderr.write(`${event} ${fields}\n`) });
|
|
89
|
+
const r = agent.run(params[0] || '你好,用一句话介绍你自己,并说出你用的是哪个模型。', { stateDir: path.join(root, '01-inbox', '_agent') });
|
|
90
|
+
if (r.config) throw new Fail(EXIT.NOT_CONFIGURED, r.failed);
|
|
91
|
+
if (r.failed) throw new Fail(EXIT.FAILED, `没答上来:${r.failed}`);
|
|
92
|
+
stdout.write(`${r.reply.trim()}\n(${bound},只读模式,用时 ${Math.round((Date.now() - started) / 1000)} 秒)\n`);
|
|
93
|
+
return EXIT.OK;
|
|
94
|
+
}
|
|
95
|
+
case 'doctor': {
|
|
96
|
+
if (params.length) throw new UsageError(USAGE);
|
|
97
|
+
const problems = createAgent({ root, agent: bound, env: settings(root, env) }).doctor();
|
|
98
|
+
if (problems.length) stdout.write(`${problems.join('\n')}\n`);
|
|
99
|
+
else stdout.write(`${bound} 没有问题。\n`);
|
|
100
|
+
return problems.length ? 1 : EXIT.OK;
|
|
101
|
+
}
|
|
102
|
+
default:
|
|
103
|
+
throw new UsageError(USAGE);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
function presetKindOf(name) {
|
|
109
|
+
return PRESET_NAMES.includes(name) ? name : name ? 'custom' : '';
|
|
110
|
+
}
|
package/scripts/cmd/check.js
CHANGED
|
@@ -12,6 +12,9 @@ const { notifyChannel } = require('../lib/notify');
|
|
|
12
12
|
const { hasWebhook, serviceName } = require('../lib/robot');
|
|
13
13
|
const { resolveCollector } = require('./sync');
|
|
14
14
|
const { createBot } = require('../lib/bot');
|
|
15
|
+
const launchd = require('../lib/launchd');
|
|
16
|
+
const { PRESET_NAMES } = require('../lib/agent');
|
|
17
|
+
const { loadProfile } = require('../lib/config');
|
|
15
18
|
const { GENERATED_DIRS, templateProblems } = require('../lib/template');
|
|
16
19
|
|
|
17
20
|
const SKILL_KEYS = ['name', 'description', 'when_to_use', 'license', 'metadata'];
|
|
@@ -214,8 +217,19 @@ function checkConfig({ root, packageRoot, env, say }) {
|
|
|
214
217
|
if (!which('security', env)) bad.push(`消息渠道 ${channel} 需要 security,本机没有`);
|
|
215
218
|
else if (!hasWebhook(env)) bad.push(`消息渠道 ${channel}:钥匙串里没有 ${serviceName(env)}(开通步骤见 docs/channels.md「云之家」)`);
|
|
216
219
|
}
|
|
217
|
-
// 值守(work-rhythm listen
|
|
218
|
-
|
|
220
|
+
// 值守(work-rhythm listen,渠道的收消息一半):装了(launchd 里有它)才检查——agent 现在也是定时任务的前提,
|
|
221
|
+
// 只绑了 agent 跑任务的人不该被报「值守没配渠道」。查什么由它自己的 doctor 说了算,这里不重复一遍
|
|
222
|
+
if (!envProblems.length && fs.existsSync(launchd.plistPath('bot', root))) bad.push(...createBot({ root, env: values }).doctorProblems());
|
|
223
|
+
// 定时任务只能建在 agent 上:schedule 里开着任务(指令文件也在)却没绑 agent,到点一个也跑不了
|
|
224
|
+
const profileDoc = loadProfile(root);
|
|
225
|
+
const schedule = profileDoc.schedule && typeof profileDoc.schedule === 'object' ? profileDoc.schedule : {};
|
|
226
|
+
const scheduled = Object.keys(schedule).filter((id) => String(schedule[id] || '').trim() && !['ask-decisions'].includes(id));
|
|
227
|
+
// 引导走到第 6 步(status 是 scheduled 或 done)之后才算数:之前 schedule 里是模板的默认时间,agent 是第 6 步才绑的
|
|
228
|
+
const status = profileDoc.setup && profileDoc.setup.status;
|
|
229
|
+
if (scheduled.length && ['scheduled', 'done'].includes(status) && !envProblems.length && !(values.YZJ_BOT_AGENT || '').trim()) {
|
|
230
|
+
const withPrompt = scheduled.filter((id) => fs.existsSync(path.join(root, 'tasks', `${id}.md`)));
|
|
231
|
+
if (withPrompt.length) bad.push(`schedule 里有任务(${withPrompt.join('、')})却没绑 agent,到点一个也跑不了:work-rhythm agent bind <${PRESET_NAMES.join('|')}>`);
|
|
232
|
+
}
|
|
219
233
|
bad.forEach(say);
|
|
220
234
|
return bad.length;
|
|
221
235
|
}
|
package/scripts/lib/agent.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
// 让本地的 agent 跑一句话、拿回它的回复。值守(bot.js)和本地服务(rhythm.js
|
|
2
|
-
// agent
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// 让本地的 agent 跑一句话、拿回它的回复。值守(bot.js)和本地服务(rhythm.js)共用,定时任务和机器人都靠它。
|
|
2
|
+
// agent 的值:zcode、dsh、qoder、claude 是预置(PRESETS,各家的无界面调用方式、续会话、权限模式都写在那里);
|
|
3
|
+
// 其余当成一条命令(按空白拆开,引号里的算一个参数;消息作为最后一个参数传给它,回复打到标准输出,退出码 0 算成功。
|
|
4
|
+
// 不支持管道、重定向这类 shell 写法——要的话包一层脚本)。
|
|
5
|
+
// 这里还管「本机装了哪些 agent」「现在是哪个 agent 在调这个 skill」(它给工具留的环境变量)、「把选定的 agent 绑进 local.env」,
|
|
6
|
+
// 给 work-rhythm agent 用。只用 node 自带的能力。找预置的命令行时返回 { problem } 而不是抛错,doctor 和真正运行时共用这一段。
|
|
5
7
|
'use strict';
|
|
6
8
|
const { spawnSync } = require('node:child_process');
|
|
7
9
|
const fs = require('node:fs');
|
|
@@ -65,6 +67,12 @@ function newestSubdir(dir, pick) {
|
|
|
65
67
|
return best;
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
// 在 PATH 上找一个命令。返回完整路径,找不到返回空串(不用 lib/run 的 which,免得和这里的 spawnSync 写法打架)
|
|
71
|
+
function onPath(name, env) {
|
|
72
|
+
const r = spawnSync('/usr/bin/which', [name], { encoding: 'utf8', env });
|
|
73
|
+
return r.status === 0 ? r.stdout.trim() : '';
|
|
74
|
+
}
|
|
75
|
+
|
|
68
76
|
function findZcode(env) {
|
|
69
77
|
const explicit = env.ZCODE_CLI;
|
|
70
78
|
if (explicit) {
|
|
@@ -77,6 +85,107 @@ function findZcode(env) {
|
|
|
77
85
|
return { problem: '找不到 ZCode 的命令行:装了 ZCode 桌面版的话它自带;也可以用 ZCODE_CLI 指定路径' };
|
|
78
86
|
}
|
|
79
87
|
|
|
88
|
+
// Qoder CLI(命令叫 qoder,老的 npm 包叫 qodercli):官方安装脚本 curl -fsSL https://qoder.com/install | bash,
|
|
89
|
+
// 或者 npm install -g @qoder-ai/qodercli。装了 Qoder 的 IDE 不等于装了它的命令行,找不到时提示一下
|
|
90
|
+
function findQoder(env) {
|
|
91
|
+
const explicit = env.QODER_CLI;
|
|
92
|
+
if (explicit) {
|
|
93
|
+
if (fs.existsSync(explicit)) return { command: path.resolve(explicit) };
|
|
94
|
+
return { problem: `QODER_CLI 指的文件不存在:${explicit}` };
|
|
95
|
+
}
|
|
96
|
+
for (const name of ['qoder', 'qodercli']) {
|
|
97
|
+
const found = onPath(name, env);
|
|
98
|
+
if (found) return { command: found };
|
|
99
|
+
}
|
|
100
|
+
for (const candidate of [path.join(os.homedir(), '.qoder', 'bin', 'qoder'), path.join(os.homedir(), '.local', 'bin', 'qoder')]) {
|
|
101
|
+
if (fs.existsSync(candidate)) return { command: candidate };
|
|
102
|
+
}
|
|
103
|
+
const ide = fs.existsSync('/Applications/Qoder.app') ? '本机装了 Qoder 的 IDE,但它的命令行是另装的:' : '';
|
|
104
|
+
return { problem: `找不到 Qoder 的命令行。${ide}安装:curl -fsSL https://qoder.com/install | bash(或 npm install -g @qoder-ai/qodercli),装完 qoder login;也可以用 QODER_CLI 指定路径` };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Claude Code 的命令行。ZCode 的命令行和它是同一套参数,但 ZCode 跑工具时也会留 CLAUDE_CODE_* 变量,所以认「谁在调用」时先看 ZCODE_*
|
|
108
|
+
function findClaude(env) {
|
|
109
|
+
const explicit = env.CLAUDE_CLI;
|
|
110
|
+
if (explicit) {
|
|
111
|
+
if (fs.existsSync(explicit)) return { command: path.resolve(explicit) };
|
|
112
|
+
return { problem: `CLAUDE_CLI 指的文件不存在:${explicit}` };
|
|
113
|
+
}
|
|
114
|
+
const found = onPath('claude', env);
|
|
115
|
+
if (found) return { command: found };
|
|
116
|
+
const local = path.join(os.homedir(), '.claude', 'local', 'claude');
|
|
117
|
+
if (fs.existsSync(local)) return { command: local };
|
|
118
|
+
return { problem: '找不到 Claude Code 的命令行:装了的话 claude 在 PATH 上;也可以用 CLAUDE_CLI 指定路径' };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Qoder 和 Claude Code 的 --output-format json 都是一个 JSON:回答在 result,会话在 session_id,出错时 is_error / subtype 会说。
|
|
122
|
+
// 字段名按各家文档写的;多认几个常见名字,免得版本之间改名就解析不出
|
|
123
|
+
function parseResultJson(stdout) {
|
|
124
|
+
let out;
|
|
125
|
+
try {
|
|
126
|
+
out = JSON.parse(stdout);
|
|
127
|
+
} catch {
|
|
128
|
+
return { failed: `输出不是 JSON:${tail(stdout)}` };
|
|
129
|
+
}
|
|
130
|
+
if (!out || typeof out !== 'object') return { failed: '输出不是 JSON' };
|
|
131
|
+
const reply = [out.result, out.response, out.text].find((v) => typeof v === 'string') ?? '';
|
|
132
|
+
const subtype = typeof out.subtype === 'string' ? out.subtype : '';
|
|
133
|
+
if (out.is_error === true || /error|cancel|max_turns/.test(subtype)) return { failed: `没跑完:${subtype || 'is_error'}:${tail(reply || out.error_message || '', 200)}` };
|
|
134
|
+
if (!reply.trim()) return { failed: '输出里没有回答' };
|
|
135
|
+
return { reply, sessionId: typeof out.session_id === 'string' ? out.session_id : typeof out.sessionId === 'string' ? out.sessionId : '' };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 预置。find 找命令行;plan 拼出一次无界面运行的参数;modes 是我们的权限名(plan 只读 / edit 可写工作目录)换成各家的叫法
|
|
139
|
+
const PRESETS = {
|
|
140
|
+
zcode: { label: 'ZCode 自带的命令行', modes: { plan: 'plan', edit: 'edit' }, find: findZcode },
|
|
141
|
+
dsh: { label: 'DSH(DeepSeek Harness)的 headless 模式', modes: { plan: 'read-only', edit: 'workspace-write' }, find: findDsh },
|
|
142
|
+
// Qoder:edit 用 accept_edits(改文件自动放行,shell 命令在无界面下会被拒);任务里要跑命令的话把 YZJ_BOT_AGENT_MODE 写成 auto
|
|
143
|
+
qoder: { label: 'Qoder CLI', modes: { plan: 'plan', edit: 'accept_edits' }, find: findQoder },
|
|
144
|
+
claude: { label: 'Claude Code 的命令行', modes: { plan: 'plan', edit: 'acceptEdits' }, find: findClaude },
|
|
145
|
+
};
|
|
146
|
+
const PRESET_NAMES = Object.keys(PRESETS);
|
|
147
|
+
const presetKind = (name) => (PRESET_NAMES.includes(name) ? name : 'custom');
|
|
148
|
+
|
|
149
|
+
// 现在是哪个 agent 在调这个 skill:看它给工具留的环境变量。ZCode 也留 CLAUDE_CODE_*,所以先认 ZCODE_*;
|
|
150
|
+
// Qoder 的变量名没有文档,按前缀认(QODER_CLI 是我们自己指定的路径,不算)
|
|
151
|
+
function invokingAgent(env) {
|
|
152
|
+
if (env.ZCODE_SESSION_ID || env.ZCODE_ENV || env.ZCODE_APP_VERSION) return 'zcode';
|
|
153
|
+
if (env.DSH_SESSION_ID || env.DSH_SHELL) return 'dsh';
|
|
154
|
+
if (Object.keys(env).some((k) => /^QODER_/.test(k) && k !== 'QODER_CLI')) return 'qoder';
|
|
155
|
+
if (env.CLAUDECODE === '1' || env.CLAUDE_CODE_SESSION_ID || env.CLAUDE_CODE_ENTRYPOINT) return 'claude';
|
|
156
|
+
return '';
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// 本机装了哪些预置。每个是 { name, label, found, command, problem, invoking }
|
|
160
|
+
function installedAgents(env) {
|
|
161
|
+
const invoking = invokingAgent(env);
|
|
162
|
+
return PRESET_NAMES.map((name) => {
|
|
163
|
+
const found = PRESETS[name].find(env);
|
|
164
|
+
return { name, label: PRESETS[name].label, found: !found.problem, command: found.command || found.cli || '', problem: found.problem || '', invoking: invoking === name };
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// 把选定的 agent 写进 collectors/local.env 的 YZJ_BOT_AGENT(没有这个文件就从样例复制一份)。
|
|
169
|
+
// 先确认它在本机找得到。返回 { name, kind, file } 或 { problems }
|
|
170
|
+
function bindAgent(root, env, name) {
|
|
171
|
+
const problems = createAgent({ root, agent: name, env }).doctor();
|
|
172
|
+
if (problems.length) return { problems };
|
|
173
|
+
const dir = path.join(root, 'collectors');
|
|
174
|
+
const file = path.join(dir, 'local.env');
|
|
175
|
+
if (!fs.existsSync(file)) {
|
|
176
|
+
const example = path.join(dir, 'local.env.example');
|
|
177
|
+
if (fs.existsSync(example)) fs.copyFileSync(example, file);
|
|
178
|
+
else fs.writeFileSync(file, '');
|
|
179
|
+
}
|
|
180
|
+
const value = /[\s"'$`]/.test(name) ? `'${name.replace(/'/g, `'\\''`)}'` : `"${name}"`;
|
|
181
|
+
const lines = fs.readFileSync(file, 'utf8').split('\n');
|
|
182
|
+
const at = lines.findIndex((l) => /^#?\s*YZJ_BOT_AGENT=/.test(l));
|
|
183
|
+
if (at >= 0) lines[at] = `YZJ_BOT_AGENT=${value}`;
|
|
184
|
+
else lines.push(`YZJ_BOT_AGENT=${value}`);
|
|
185
|
+
fs.writeFileSync(file, `${lines.join('\n').replace(/\n*$/, '')}\n`);
|
|
186
|
+
return { name, kind: presetKind(name), file };
|
|
187
|
+
}
|
|
188
|
+
|
|
80
189
|
// DSH 的命令行要用它自带的 Node 跑(设 ELECTRON_RUN_AS_NODE 当普通 node 用),入口是 @deepseek-ai/dsh 的 bin.js
|
|
81
190
|
function findDsh(env) {
|
|
82
191
|
const home = env.DSH_HOME || path.join(os.homedir(), '.dsh');
|
|
@@ -158,19 +267,19 @@ function parseDsh(stdout) {
|
|
|
158
267
|
// doctor() → 配置和依赖的问题,一条一个字符串;没有就是空数组
|
|
159
268
|
function createAgent({ root, agent, mode = 'plan', timeoutS = 300, preamble = '', log = () => {}, env = process.env }) {
|
|
160
269
|
const name = String(agent || '').trim();
|
|
161
|
-
const kind = name
|
|
270
|
+
const kind = presetKind(name);
|
|
162
271
|
|
|
163
272
|
function doctor() {
|
|
164
|
-
if (!name) return ['
|
|
165
|
-
if (kind
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return
|
|
273
|
+
if (!name) return [`没绑 agent:定时任务和机器人值守都要一个 agent 来跑。先 work-rhythm agent detect 看本机有哪些,再 work-rhythm agent bind <${PRESET_NAMES.join('|')}|命令>(写进 collectors/local.env 的 YZJ_BOT_AGENT)`];
|
|
274
|
+
if (kind !== 'custom') {
|
|
275
|
+
const found = PRESETS[kind].find(env);
|
|
276
|
+
if (found.problem) return [found.problem];
|
|
277
|
+
// dsh 还要用桌面应用里配好的模型
|
|
278
|
+
if (kind === 'dsh') {
|
|
279
|
+
const entries = readDshPatchEntries(found.home);
|
|
280
|
+
if (entries.problem) return [entries.problem];
|
|
281
|
+
}
|
|
282
|
+
return [];
|
|
174
283
|
}
|
|
175
284
|
// 带斜杠的按工作目录里的相对路径找,其余在 PATH 上找
|
|
176
285
|
const [first] = splitCommand(name);
|
|
@@ -212,6 +321,36 @@ function createAgent({ root, agent, mode = 'plan', timeoutS = 300, preamble = ''
|
|
|
212
321
|
};
|
|
213
322
|
}
|
|
214
323
|
|
|
324
|
+
// qoder:qoder --cwd <工作目录> --permission-mode <模式> [--resume <会话>] --output-format json --print <这句话>
|
|
325
|
+
// 模型和登录跟着 Qoder CLI 自己的配置走(~/.qoder)。无界面模式下它不弹确认,要确认的操作一律被拒,
|
|
326
|
+
// 所以 edit 对应 accept_edits(改文件自动放行);任务里要跑 shell 的话得用 auto(写在 YZJ_BOT_AGENT_MODE 里)
|
|
327
|
+
function planQoder(prompt) {
|
|
328
|
+
const q = findQoder(env);
|
|
329
|
+
if (q.problem) return q;
|
|
330
|
+
const permission = PRESETS.qoder.modes[mode] || mode;
|
|
331
|
+
const base = ['--cwd', root, '--permission-mode', permission];
|
|
332
|
+
return {
|
|
333
|
+
command: q.command,
|
|
334
|
+
env,
|
|
335
|
+
withSession: (sid) => [...base, ...(sid ? ['--resume', sid] : []), '--output-format', 'json', '--print', prompt],
|
|
336
|
+
parse: parseResultJson,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// claude:参数和 ZCode 那套一样,只是模式名和 JSON 的字段不同
|
|
341
|
+
function planClaude(prompt) {
|
|
342
|
+
const c = findClaude(env);
|
|
343
|
+
if (c.problem) return c;
|
|
344
|
+
const permission = PRESETS.claude.modes[mode] || mode;
|
|
345
|
+
const base = ['--cwd', root, '--permission-mode', permission];
|
|
346
|
+
return {
|
|
347
|
+
command: c.command,
|
|
348
|
+
env,
|
|
349
|
+
withSession: (sid) => [...base, ...(sid ? ['--resume', sid] : []), '--output-format', 'json', '-p', prompt],
|
|
350
|
+
parse: parseResultJson,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
215
354
|
// dsh:用 headless 模式答一句就退出。工作目录就是当前目录,所以 tsx 用绝对路径导入;回答在 --json 事件的 final 里。
|
|
216
355
|
// 模型和凭据跟着 DSH 桌面应用里的配置走。plan → read-only,edit → workspace-write,别的值原样传给它
|
|
217
356
|
function planDsh(prompt, stateDir) {
|
|
@@ -246,7 +385,7 @@ function createAgent({ root, agent, mode = 'plan', timeoutS = 300, preamble = ''
|
|
|
246
385
|
return reply ? { reply } : { failed: '它没有输出任何回复' };
|
|
247
386
|
}
|
|
248
387
|
const prompt = preamble ? `${message}\n\n${preamble}` : message;
|
|
249
|
-
const plan =
|
|
388
|
+
const plan = { zcode: planZcode, dsh: planDsh, qoder: planQoder, claude: planClaude }[kind](prompt, stateDir);
|
|
250
389
|
if (plan.problem) return { failed: plan.problem, config: true }; // 配置问题:调用方按「没配置好」处理
|
|
251
390
|
let used = session;
|
|
252
391
|
let r = runProcess(plan.command, plan.withSession(used), plan.env);
|
|
@@ -267,4 +406,4 @@ function createAgent({ root, agent, mode = 'plan', timeoutS = 300, preamble = ''
|
|
|
267
406
|
return { kind, run, doctor };
|
|
268
407
|
}
|
|
269
408
|
|
|
270
|
-
module.exports = { createAgent, splitCommand };
|
|
409
|
+
module.exports = { createAgent, splitCommand, PRESETS, PRESET_NAMES, invokingAgent, installedAgents, bindAgent, findZcode, findDsh, findQoder, findClaude };
|
package/scripts/lib/bot.js
CHANGED
|
@@ -185,7 +185,7 @@ function createBot({ root, env }) {
|
|
|
185
185
|
if (found.problem) throw new Fail(found.code, found.problem);
|
|
186
186
|
if (needAgent) {
|
|
187
187
|
if (!OWNER) throw new Fail(EXIT.NOT_CONFIGURED, '取不到我的 openId:在 collectors/local.env 里写 YZJ_MY_OPEN_ID,值守只处理我本人的消息');
|
|
188
|
-
if (!AGENT) throw new Fail(EXIT.NOT_CONFIGURED, '
|
|
188
|
+
if (!AGENT) throw new Fail(EXIT.NOT_CONFIGURED, '没绑 agent,值守开不了:先 work-rhythm agent detect 看本机有哪些,再 work-rhythm agent bind <名字>(写进 collectors/local.env 的 YZJ_BOT_AGENT);也可以手写它,值是预置的名字或一条把回复打到标准输出的命令');
|
|
189
189
|
}
|
|
190
190
|
return deriveWsUrl(found.webhook);
|
|
191
191
|
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { test } = require('node:test');
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const { makeSandbox, read, exists, write } = require('./harness');
|
|
7
|
+
const { invokingAgent, installedAgents } = require('../lib/agent');
|
|
8
|
+
|
|
9
|
+
// 四个预置都装上假的;PATH 上另放一个 qoder 和一个 claude,测「在 PATH 上找」那条路
|
|
10
|
+
function setup(t) {
|
|
11
|
+
const box = makeSandbox(t);
|
|
12
|
+
box.workdir();
|
|
13
|
+
const stubs = box.stubs();
|
|
14
|
+
const fake = (name, source) => {
|
|
15
|
+
const file = path.join(box.bin, name);
|
|
16
|
+
fs.writeFileSync(file, `#!/usr/bin/env node\n${source}\n`);
|
|
17
|
+
fs.chmodSync(file, 0o755);
|
|
18
|
+
};
|
|
19
|
+
const { fakeQoder, fakeClaude } = require('./stubs');
|
|
20
|
+
fake('qoder', fakeQoder);
|
|
21
|
+
fake('claude', fakeClaude);
|
|
22
|
+
// 假的 ZCode 桌面版(自带的命令行)不在 PATH 上也能找到
|
|
23
|
+
const bundled = '/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs';
|
|
24
|
+
if (!fs.existsSync(bundled)) fake('zcode', require('./stubs').fakeZcode);
|
|
25
|
+
const s = { box, stubs, env: { ...stubs, STUB_KEYCHAIN: 'ok', STUB_ROBOT_URL: 'http://127.0.0.1:1/send?yzjtoken=stubtoken0123456789abcd' } };
|
|
26
|
+
s.run = (args, env = {}) => box.run(args, { env: { ...s.env, ...env } });
|
|
27
|
+
s.bindEnv = () => ({ ...s.env, ZCODE_CLI: stubs.ZCODE_CLI, DSH_HOME: stubs.DSH_HOME, DSH_NODE: stubs.DSH_NODE, DSH_CLI: stubs.DSH_CLI });
|
|
28
|
+
// 什么都没装的环境:PATH 上没有假的,ZCode 和 DSH 也指到不存在的地方
|
|
29
|
+
s.nothing = () => ({ ...s.bindEnv(), PATH: path.join(box.root, 'nothing'), ZCODE_CLI: '/nonexistent', DSH_CLI: '', DSH_NODE: '', DSH_DESKTOP_DIR: path.join(box.root, 'nothing') });
|
|
30
|
+
return s;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------- 认「谁在调用」
|
|
34
|
+
test('invokingAgent:按各家公司给工具留的环境变量认;ZCode 也留 CLAUDE_CODE_*,所以先认 ZCODE_*', () => {
|
|
35
|
+
assert.equal(invokingAgent({}), '');
|
|
36
|
+
assert.equal(invokingAgent({ ZCODE_SESSION_ID: 's' }), 'zcode');
|
|
37
|
+
assert.equal(invokingAgent({ ZCODE_APP_VERSION: '1' }), 'zcode');
|
|
38
|
+
assert.equal(invokingAgent({ DSH_SESSION_ID: 's' }), 'dsh');
|
|
39
|
+
assert.equal(invokingAgent({ DSH_SHELL: '/bin/zsh' }), 'dsh');
|
|
40
|
+
assert.equal(invokingAgent({ QODER_SESSION_ID: 's' }), 'qoder');
|
|
41
|
+
assert.equal(invokingAgent({ QODER_CLI: '/x/qoder' }), '', 'QODER_CLI 是我们指定路径用的,不算标记');
|
|
42
|
+
assert.equal(invokingAgent({ CLAUDECODE: '1' }), 'claude');
|
|
43
|
+
assert.equal(invokingAgent({ CLAUDE_CODE_SESSION_ID: 's' }), 'claude');
|
|
44
|
+
assert.equal(invokingAgent({ ZCODE_SESSION_ID: 's', CLAUDE_CODE_SESSION_ID: 's' }), 'zcode');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// ---------------------------------------------------------------- detect
|
|
48
|
+
test('agent:列出本机装了哪些、谁在调、绑了什么;不给标记就说认不出来', (t) => {
|
|
49
|
+
const s = setup(t);
|
|
50
|
+
const env = s.bindEnv();
|
|
51
|
+
const r = s.run(['agent'], env);
|
|
52
|
+
assert.equal(r.code, 0, r.out);
|
|
53
|
+
assert.match(r.stdout, /zcode +装了 +ZCode 自带的命令行/);
|
|
54
|
+
assert.match(r.stdout, /dsh +装了 +DSH(DeepSeek Harness)的 headless 模式/);
|
|
55
|
+
assert.match(r.stdout, /qoder +装了 +Qoder CLI\n +.*\/bin\/qoder/);
|
|
56
|
+
assert.match(r.stdout, /claude +装了/);
|
|
57
|
+
assert.match(r.stdout, /正在调这个 skill 的:认不出来/);
|
|
58
|
+
assert.match(r.stdout, /现在绑定的:没绑\n没绑 agent 就没有定时任务,也不支持机器人响应。建议:work-rhythm agent bind zcode/);
|
|
59
|
+
// 现在是 DSH 在调:标出来,建议也变成 dsh
|
|
60
|
+
const dsh = s.run(['agent'], { ...env, DSH_SESSION_ID: 'sess-1' });
|
|
61
|
+
assert.match(dsh.stdout, /dsh +装了 .*← 现在是它在调这个 skill\n/);
|
|
62
|
+
assert.match(dsh.stdout, /正在调这个 skill 的:dsh\n/);
|
|
63
|
+
assert.match(dsh.stdout, /建议:work-rhythm agent bind dsh/);
|
|
64
|
+
// 没装的给安装提示(把 DSH 的目录也指到不存在的地方)
|
|
65
|
+
const none = s.run(['agent'], s.nothing());
|
|
66
|
+
assert.match(none.stdout, /zcode +没装/);
|
|
67
|
+
assert.match(none.stdout, /dsh +没装/);
|
|
68
|
+
assert.match(none.stdout, /qoder +没装 +Qoder CLI\n +没装:找不到 Qoder 的命令行。.*qoder\.com\/install/);
|
|
69
|
+
assert.match(none.stdout, /本机一个预置的 agent 都没装/);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('agent --json:给 agent 读的结构', (t) => {
|
|
73
|
+
const s = setup(t);
|
|
74
|
+
const r = s.run(['agent', '--json'], { ...s.bindEnv(), QODER_SESSION_ID: 'q' });
|
|
75
|
+
assert.equal(r.code, 0, r.out);
|
|
76
|
+
const doc = JSON.parse(r.stdout);
|
|
77
|
+
assert.equal(doc.invoking, 'qoder');
|
|
78
|
+
assert.equal(doc.invokingFound, true);
|
|
79
|
+
assert.equal(doc.bound, '');
|
|
80
|
+
assert.equal(doc.suggest, 'qoder');
|
|
81
|
+
assert.deepEqual(doc.agents.map((a) => [a.name, a.found]), [['zcode', true], ['dsh', true], ['qoder', true], ['claude', true]]);
|
|
82
|
+
assert.match(s.run(['agent', '--json'], s.bindEnv()).stdout, /"invoking": ""/);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// ---------------------------------------------------------------- bind
|
|
86
|
+
test('agent bind:不给名字就绑正在调的这个;没标记就绑装了的第一个;写进 local.env 的 YZJ_BOT_AGENT', (t) => {
|
|
87
|
+
const s = setup(t);
|
|
88
|
+
const env = s.bindEnv();
|
|
89
|
+
assert.equal(exists(`${s.box.work}/collectors/local.env`), false);
|
|
90
|
+
const r = s.run(['agent', 'bind'], { ...env, DSH_SESSION_ID: 'sess-1' });
|
|
91
|
+
assert.equal(r.code, 0, r.out);
|
|
92
|
+
assert.match(r.stdout, /已绑定 dsh(DSH(DeepSeek Harness)的 headless 模式),写进了 collectors\/local\.env 的 YZJ_BOT_AGENT。\n下一步:work-rhythm agent test/);
|
|
93
|
+
// local.env 原来没有:从样例复制一份,再把样例里注释掉的那行换成真的
|
|
94
|
+
const text = read(`${s.box.work}/collectors/local.env`);
|
|
95
|
+
assert.match(text, /^YZJ_BOT_AGENT="dsh"$/m);
|
|
96
|
+
assert.equal(text.split('\n').filter((l) => /^#?\s*YZJ_BOT_AGENT=/.test(l)).length, 1, '样例里注释掉的那行要被换掉,不留两行');
|
|
97
|
+
assert.match(text, /# 消息渠道/);
|
|
98
|
+
// 再绑一次:只改那一行
|
|
99
|
+
const again = s.run(['agent', 'bind', 'qoder'], env);
|
|
100
|
+
assert.equal(again.code, 0, again.out);
|
|
101
|
+
assert.match(read(`${s.box.work}/collectors/local.env`), /^YZJ_BOT_AGENT="qoder"$/m);
|
|
102
|
+
assert.match(s.run(['agent'], env).stdout, /现在绑定的:qoder\n/);
|
|
103
|
+
// 一条自定义命令:命令存在才让绑;有空格的值用单引号包($ 不展开)
|
|
104
|
+
const custom = `${path.join(s.box.bin, 'fake-agent')} --flag`;
|
|
105
|
+
assert.equal(s.run(['agent', 'bind'], env).code, 0);
|
|
106
|
+
assert.equal(s.run(['agent', 'bind', custom], env).code, 0);
|
|
107
|
+
assert.match(read(`${s.box.work}/collectors/local.env`), /^YZJ_BOT_AGENT='.*\/fake-agent --flag'$/m);
|
|
108
|
+
const shown = s.run(['agent'], env);
|
|
109
|
+
assert.match(shown.stdout, /现在绑定的:.*\/fake-agent --flag(一条自定义命令,zcode\/dsh\/qoder\/claude 以外)/);
|
|
110
|
+
assert.equal(shown.stdout.includes('建议:'), false, '绑了就不再建议');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('agent bind:绑不了的拒绝(退出码 3)并说清原因——预置没装、命令找不到;一个都没有时给安装指引', (t) => {
|
|
114
|
+
const s = setup(t);
|
|
115
|
+
const env = s.bindEnv();
|
|
116
|
+
const qoder = s.run(['agent', 'bind', 'qoder'], { ...env, PATH: path.join(s.box.root, 'nothing') });
|
|
117
|
+
assert.equal(qoder.code, 3);
|
|
118
|
+
assert.match(qoder.stderr, /绑不了 qoder:找不到 Qoder 的命令行。/);
|
|
119
|
+
assert.equal(exists(`${s.box.work}/collectors/local.env`), false, '绑不了就不写文件');
|
|
120
|
+
const bad = s.run(['agent', 'bind', '/no/such/agent'], env);
|
|
121
|
+
assert.equal(bad.code, 3);
|
|
122
|
+
assert.match(bad.stderr, /绑不了 \/no\/such\/agent:YZJ_BOT_AGENT 的命令找不到: \/no\/such\/agent/);
|
|
123
|
+
const none = s.run(['agent', 'bind'], s.nothing());
|
|
124
|
+
assert.equal(none.code, 3);
|
|
125
|
+
assert.match(none.stderr, /本机没找到能用的 agent,也没指定要绑的命令/);
|
|
126
|
+
assert.equal(s.run(['agent', 'bind', 'a', 'b'], env).code, 2);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// ---------------------------------------------------------------- test / doctor / 各家的调用方式
|
|
130
|
+
test('agent test:让绑定的 agent 只读答一句;没绑就退出码 3', (t) => {
|
|
131
|
+
const s = setup(t);
|
|
132
|
+
const env = s.bindEnv();
|
|
133
|
+
const none = s.run(['agent', 'test'], env);
|
|
134
|
+
assert.equal(none.code, 3);
|
|
135
|
+
assert.match(none.stderr, /还没绑 agent:work-rhythm agent detect/);
|
|
136
|
+
assert.equal(s.run(['agent', 'bind', 'qoder'], env).code, 0);
|
|
137
|
+
const r = s.run(['agent', 'test', '今天周几'], env);
|
|
138
|
+
assert.equal(r.code, 0, r.out);
|
|
139
|
+
assert.match(r.stdout, /^回复:今天周几\n(qoder,只读模式,用时 \d+ 秒)\n$/);
|
|
140
|
+
// Qoder 的参数:工作目录、只读模式、JSON 输出、--print 后面跟这句话
|
|
141
|
+
const args = read(s.stubs.STUB_QODER_ARGS);
|
|
142
|
+
assert.equal(args, `--cwd ${fs.realpathSync(s.box.work)} --permission-mode plan --output-format json --print 今天周几\n`);
|
|
143
|
+
// 默认那句话
|
|
144
|
+
s.run(['agent', 'test'], env);
|
|
145
|
+
assert.match(read(s.stubs.STUB_QODER_ARGS), /--print 你好,用一句话介绍你自己,并说出你用的是哪个模型。$/m);
|
|
146
|
+
assert.equal(s.run(['agent', 'test', 'a', 'b'], env).code, 2);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('qoder 预置:值守里第二轮用 --resume 接上;edit 模式换成 accept_edits;没跑完按失败处理', (t) => {
|
|
150
|
+
const s = setup(t);
|
|
151
|
+
s.run(['agent', 'bind', 'qoder'], s.bindEnv());
|
|
152
|
+
// 值守走的是 listen:要渠道和 openId 才肯跑
|
|
153
|
+
const profile = `${s.box.work}/00-config/profile.yaml`;
|
|
154
|
+
write(profile, read(profile).replace('notify: ""', 'notify: "yzj-robot"'));
|
|
155
|
+
// 假的 qoder 把整段提示原样回出来,所以关掉随每句话带给 agent 的那句提示
|
|
156
|
+
const env = { ...s.bindEnv(), YZJ_MY_OPEN_ID: 'me-0001', YZJ_BOT_PREAMBLE: '' };
|
|
157
|
+
const first = s.run(['listen', 'handle', '第一句'], env);
|
|
158
|
+
assert.equal(first.code, 0, first.out);
|
|
159
|
+
assert.equal(first.stdout, '回复:第一句\n');
|
|
160
|
+
const second = s.run(['listen', 'handle', '第二句'], { ...env, YZJ_BOT_AGENT_MODE: 'edit' });
|
|
161
|
+
assert.equal(second.stdout, '回复:第二句\n');
|
|
162
|
+
const args = read(s.stubs.STUB_QODER_ARGS).trim();
|
|
163
|
+
assert.ok(args.startsWith(`--cwd ${fs.realpathSync(s.box.work)} --permission-mode accept_edits --resume sess_q --output-format json --print 第二句`), args);
|
|
164
|
+
assert.equal(read(`${s.box.work}/01-inbox/_bot/session-id`).trim(), 'sess_q');
|
|
165
|
+
const failed = s.run(['listen', 'handle', '出错'], { ...env, STUB_QODER_FINAL: 'error_max_turns' });
|
|
166
|
+
assert.equal(failed.code, 5);
|
|
167
|
+
assert.match(failed.stderr, /没处理成功:没跑完:error_max_turns/);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('claude 预置:在 PATH 上找到 claude,参数是 Claude Code 那一套', (t) => {
|
|
171
|
+
const s = setup(t);
|
|
172
|
+
s.run(['agent', 'bind', 'claude'], s.bindEnv());
|
|
173
|
+
const r = s.run(['agent', 'test', '在吗'], s.bindEnv());
|
|
174
|
+
assert.equal(r.code, 0, r.out);
|
|
175
|
+
assert.equal(r.stdout, '回复:在吗\n(claude,只读模式,用时 0 秒)\n');
|
|
176
|
+
assert.equal(read(s.stubs.STUB_CLAUDE_ARGS).trim(), `--cwd ${fs.realpathSync(s.box.work)} --permission-mode plan --output-format json -p 在吗`);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('agent doctor:绑定的 agent 有没有问题;用法不对退出码为 2', (t) => {
|
|
180
|
+
const s = setup(t);
|
|
181
|
+
const env = s.bindEnv();
|
|
182
|
+
assert.equal(s.run(['agent', 'doctor'], env).code, 1);
|
|
183
|
+
assert.match(s.run(['agent', 'doctor'], env).stdout, /没绑 agent:定时任务和机器人值守都要一个 agent 来跑/);
|
|
184
|
+
s.run(['agent', 'bind', 'dsh'], env);
|
|
185
|
+
const ok = s.run(['agent', 'doctor'], env);
|
|
186
|
+
assert.equal(ok.code, 0, ok.out);
|
|
187
|
+
assert.equal(ok.stdout, 'dsh 没有问题。\n');
|
|
188
|
+
const broken = s.run(['agent', 'doctor'], { ...env, DSH_HOME: path.join(s.box.root, 'no-such-home') });
|
|
189
|
+
assert.equal(broken.code, 1);
|
|
190
|
+
assert.match(broken.stdout, /找不到 DSH 的配置/);
|
|
191
|
+
assert.equal(s.run(['agent', 'nope'], env).code, 2);
|
|
192
|
+
assert.match(s.run(['agent', '--help'], env).stderr, /work-rhythm agent: 用法: work-rhythm agent \[子命令\]/);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('installedAgents:本机真有什么就报什么,不编造', () => {
|
|
196
|
+
const list = installedAgents(process.env);
|
|
197
|
+
assert.deepEqual(list.map((a) => a.name), ['zcode', 'dsh', 'qoder', 'claude']);
|
|
198
|
+
for (const a of list) assert.equal(typeof a.found, 'boolean');
|
|
199
|
+
});
|
|
@@ -22,6 +22,13 @@ function setup(t) {
|
|
|
22
22
|
sources,
|
|
23
23
|
setNotify: (value) => write(profile, setKey(read(profile), 'notify', value)),
|
|
24
24
|
localEnv: (text) => write(`${box.work}/collectors/local.env`, text),
|
|
25
|
+
// 值守装成常驻(launchd 里有它的 plist)check 才核对值守;plist 在 HOME 下,所以把 HOME 指到临时目录
|
|
26
|
+
botInstalled: () => {
|
|
27
|
+
const home = path.join(box.root, 'home');
|
|
28
|
+
fs.mkdirSync(path.join(home, 'Library', 'LaunchAgents'), { recursive: true });
|
|
29
|
+
write(path.join(home, 'Library', 'LaunchAgents', `work-rhythm.bot.${path.basename(box.work)}.plist`), '<?xml version="1.0"?><plist/>');
|
|
30
|
+
return { HOME: home };
|
|
31
|
+
},
|
|
25
32
|
check: (env = { STUB_KEYCHAIN: 'no' }) => box.run(['check'], { env }),
|
|
26
33
|
};
|
|
27
34
|
}
|
|
@@ -175,41 +182,56 @@ test('check:没装 security 时报出来', (t) => {
|
|
|
175
182
|
assert.match(r.stdout, /消息渠道 yzj-robot 需要 security,本机没有/);
|
|
176
183
|
});
|
|
177
184
|
|
|
178
|
-
test('check
|
|
185
|
+
test('check:只绑了 agent 跑定时任务、没装值守,不报值守的事;schedule 有任务没绑 agent 才报', (t) => {
|
|
186
|
+
const s = setup(t);
|
|
187
|
+
s.localEnv('YZJ_BOT_AGENT="dsh"\n');
|
|
188
|
+
const r = s.check({ ...s.stubs });
|
|
189
|
+
assert.equal(r.code, 0, r.out);
|
|
190
|
+
assert.ok(!r.out.includes('值守'), r.out);
|
|
191
|
+
// 引导做完(status: done)、把绑定的那行去掉:schedule 里有任务(模板的默认时间)却没绑 agent,就报;引导没走到第 6 步时不报
|
|
192
|
+
write(`${s.box.work}/00-config/profile.yaml`, read(`${s.box.work}/00-config/profile.yaml`).replace('status: new', 'status: done'));
|
|
193
|
+
s.localEnv('# YZJ_BOT_AGENT="dsh"\n');
|
|
194
|
+
const r2 = s.check({ ...s.stubs });
|
|
195
|
+
assert.equal(r2.code, 1, r2.out);
|
|
196
|
+
assert.match(r2.stdout, /schedule 里有任务(daily-plan、noon-checkin、evening-review、carryover、weekly-rhythm)却没绑 agent,到点一个也跑不了:work-rhythm agent bind <zcode\|dsh\|qoder\|claude>/);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('check:值守装了之后,配的命令找不到时报出来', (t) => {
|
|
179
200
|
const s = setup(t);
|
|
180
201
|
s.setNotify('yzj-robot');
|
|
181
202
|
s.localEnv('YZJ_BOT_AGENT="/nonexistent/agent x"\nYZJ_MY_OPEN_ID="me-0001"\n');
|
|
182
|
-
const r = s.check({ STUB_KEYCHAIN: 'ok' });
|
|
203
|
+
const r = s.check({ ...s.botInstalled(), STUB_KEYCHAIN: 'ok' });
|
|
183
204
|
assert.equal(r.code, 1);
|
|
184
205
|
assert.match(r.stdout, /YZJ_BOT_AGENT 的命令找不到: \/nonexistent\/agent/);
|
|
185
206
|
assert.ok(!r.stdout.includes('值守属于 yzj-robot 渠道'));
|
|
186
207
|
});
|
|
187
208
|
|
|
188
|
-
test('check
|
|
209
|
+
test('check:值守装了之后,没写我的 openId 时报出来', (t) => {
|
|
189
210
|
const s = setup(t);
|
|
190
211
|
s.setNotify('yzj-robot');
|
|
191
212
|
s.localEnv('YZJ_BOT_AGENT="zcode"\n');
|
|
192
|
-
const r = s.check({ STUB_KEYCHAIN: 'ok' });
|
|
213
|
+
const r = s.check({ ...s.botInstalled(), STUB_KEYCHAIN: 'ok' });
|
|
193
214
|
assert.match(r.stdout, /要写 YZJ_MY_OPEN_ID/);
|
|
194
215
|
assert.ok(!r.stdout.includes('值守属于 yzj-robot 渠道'));
|
|
195
216
|
});
|
|
196
217
|
|
|
197
|
-
test('check
|
|
218
|
+
test('check:值守装了之后,notify 不是 yzj-robot 时报出来;配好之后不再报它', (t) => {
|
|
198
219
|
const s = setup(t);
|
|
220
|
+
const home = s.botInstalled();
|
|
199
221
|
s.localEnv(`YZJ_BOT_AGENT="zcode"\nYZJ_MY_OPEN_ID="me-0001"\nZCODE_CLI="${s.stubs.ZCODE_CLI}"\n`);
|
|
200
222
|
s.setNotify('""');
|
|
201
|
-
assert.match(s.check({ STUB_KEYCHAIN: 'ok' }).stdout, /值守属于 yzj-robot 渠道:preferences\.notify 要设成 yzj-robot/);
|
|
223
|
+
assert.match(s.check({ ...home, STUB_KEYCHAIN: 'ok' }).stdout, /值守属于 yzj-robot 渠道:preferences\.notify 要设成 yzj-robot/);
|
|
202
224
|
s.setNotify('yzj-robot');
|
|
203
|
-
const ok = s.check({ STUB_KEYCHAIN: 'ok' });
|
|
225
|
+
const ok = s.check({ ...home, STUB_KEYCHAIN: 'ok' });
|
|
204
226
|
assert.equal(ok.code, 0, ok.out);
|
|
205
227
|
assert.ok(!ok.stdout.includes('值守'));
|
|
206
228
|
});
|
|
207
229
|
|
|
208
|
-
test('check
|
|
230
|
+
test('check:值守装了之后,配了 dsh 却找不到它的配置时报出来', (t) => {
|
|
209
231
|
const s = setup(t);
|
|
210
232
|
s.setNotify('yzj-robot');
|
|
211
233
|
s.localEnv(`YZJ_BOT_AGENT="dsh"\nYZJ_MY_OPEN_ID="me-0001"\nDSH_HOME="${s.box.root}/no-such-home"\nDSH_NODE="${path.join(s.box.bin, 'fake-dsh-node')}"\nDSH_CLI="${path.join(s.box.bin, 'fake-dsh')}"\n`);
|
|
212
|
-
const r = s.check({ STUB_KEYCHAIN: 'ok' });
|
|
234
|
+
const r = s.check({ ...s.botInstalled(), STUB_KEYCHAIN: 'ok' });
|
|
213
235
|
assert.equal(r.code, 1);
|
|
214
236
|
assert.match(r.stdout, /找不到 DSH 的配置/);
|
|
215
237
|
});
|
|
@@ -32,7 +32,6 @@ rhythm:
|
|
|
32
32
|
port: 8787
|
|
33
33
|
push: true
|
|
34
34
|
quiet: [linky-cost-fill, linky-cost-check]
|
|
35
|
-
automations: {}
|
|
36
35
|
sources:
|
|
37
36
|
- id: git-activity
|
|
38
37
|
name: 本机代码提交
|
|
@@ -57,7 +56,6 @@ sources:
|
|
|
57
56
|
assert.equal(doc.rhythm.port, 8787);
|
|
58
57
|
assert.equal(doc.rhythm.push, true);
|
|
59
58
|
assert.deepEqual(doc.rhythm.quiet, ['linky-cost-fill', 'linky-cost-check']);
|
|
60
|
-
assert.deepEqual(doc.automations, {});
|
|
61
59
|
assert.equal(doc.sources[0].extract, '第一行\n第二行\n');
|
|
62
60
|
assert.equal(doc.sources[1].id, 'noted');
|
|
63
61
|
assert.equal(doc.sources[1].enabled, false);
|
package/scripts/test/harness.js
CHANGED
|
@@ -16,7 +16,8 @@ const BIN = path.join(PACKAGE_ROOT, 'scripts', 'work-rhythm.js');
|
|
|
16
16
|
const T = '\t';
|
|
17
17
|
|
|
18
18
|
// 这些变量是各命令的配置,本机环境里如果碰巧有,会让用例的结果跟着变。跑命令时一律不带
|
|
19
|
-
|
|
19
|
+
// CLAUDE、QODER 也抹掉:调用这个测试的 agent 会留自己的标记(ZCODE_*、CLAUDE_CODE_*、DSH_SESSION_ID),用例不能被它带偏
|
|
20
|
+
const STRIP = /^(YZJ_|GIT_ACTIVITY_|FILE_ACTIVITY_|DSH_|STUB_|ZCODE_|WORK_RHYTHM_|DECISIONS_TODAY|LINKY_TYPES|CLAUDE|QODER)/;
|
|
20
21
|
const { writeWorkdir } = require('../lib/template');
|
|
21
22
|
|
|
22
23
|
// 用户级登记指向一个不存在的文件:用例不能被本机登记的工作目录带偏
|
|
@@ -141,6 +142,8 @@ function makeSandbox(t) {
|
|
|
141
142
|
STUB_ROBOT_TOKEN: 'stubtoken0123456789abcd',
|
|
142
143
|
STUB_AGENT_CALLS: file('agent.calls'),
|
|
143
144
|
STUB_ZCODE_ARGS: file('zcode.args'),
|
|
145
|
+
STUB_QODER_ARGS: file('qoder.args'),
|
|
146
|
+
STUB_CLAUDE_ARGS: file('claude.args'),
|
|
144
147
|
STUB_DSH_ARGS: file('dsh.args'),
|
|
145
148
|
STUB_DSH_ENV: file('dsh.env'),
|
|
146
149
|
STUB_APPROVAL_NEW_MS: String(Date.UTC(2026, 10, 27, 10, 0, 0)),
|
|
@@ -177,12 +177,12 @@ test('listen:日志里不记消息内容', async (t) => {
|
|
|
177
177
|
});
|
|
178
178
|
|
|
179
179
|
// ---------------------------------------------------------------- 配置
|
|
180
|
-
test('listen
|
|
180
|
+
test('listen:没绑 agent 时退出码为 3,说清怎么绑', async (t) => {
|
|
181
181
|
const s = setup(t);
|
|
182
182
|
const { env } = await withHook(t, s);
|
|
183
183
|
const r = s.listen(['handle', 'x'], { ...env, YZJ_BOT_AGENT: '' });
|
|
184
184
|
assert.equal(r.code, 3);
|
|
185
|
-
assert.match(r.stderr,
|
|
185
|
+
assert.match(r.stderr, /没绑 agent,值守开不了:先 work-rhythm agent detect/);
|
|
186
186
|
});
|
|
187
187
|
|
|
188
188
|
test('listen:没配 YZJ_MY_OPEN_ID 时退出码为 3', async (t) => {
|
|
@@ -136,7 +136,7 @@ test('rhythm doctor:配置齐了时退出码为 0;时间写了却缺指令
|
|
|
136
136
|
// 推送开着却没配消息渠道、agent 没配,都报出来
|
|
137
137
|
s.set('notify', '""');
|
|
138
138
|
assert.match(s.rhythm(['doctor']).stdout, /rhythm.push 开着,但 preferences.notify 没配消息渠道/);
|
|
139
|
-
assert.match(s.rhythm(['doctor'], { ...s.env, YZJ_BOT_AGENT: '' }).stdout,
|
|
139
|
+
assert.match(s.rhythm(['doctor'], { ...s.env, YZJ_BOT_AGENT: '' }).stdout, /没绑 agent:定时任务和机器人值守都要一个 agent 来跑/);
|
|
140
140
|
// 端口不在范围里
|
|
141
141
|
s.set('port', '80');
|
|
142
142
|
assert.match(s.rhythm(['doctor']).stdout, /rhythm.port 要是 1024 到 65535 之间的整数(现在是 80)/);
|
|
@@ -150,7 +150,7 @@ test('rhythm start:配置有问题时不起,退出码为 3,缺指令文件
|
|
|
150
150
|
s.set('notify', '""');
|
|
151
151
|
const r = s.rhythm(['start'], { ...s.env, YZJ_BOT_AGENT: '' });
|
|
152
152
|
assert.equal(r.code, 3);
|
|
153
|
-
assert.match(r.stderr, /配置有问题,先跑 work-rhythm rhythm doctor:\n
|
|
153
|
+
assert.match(r.stderr, /配置有问题,先跑 work-rhythm rhythm doctor:\n没绑 agent/);
|
|
154
154
|
assert.match(r.stderr, /rhythm.push 开着/);
|
|
155
155
|
assert.ok(!r.stderr.includes('weekly-rhythm'), '缺指令文件的任务到点跳过就行,不该拦着不起');
|
|
156
156
|
});
|
package/scripts/test/stubs.js
CHANGED
|
@@ -98,6 +98,24 @@ fs.writeFileSync(process.env.STUB_ZCODE_ARGS || '/dev/null', args.join(' ') + '\
|
|
|
98
98
|
process.stdout.write(JSON.stringify({ sessionId: 'sess_fake', response: '回复:' + args[args.length - 1], usage: {} }) + '\\n');
|
|
99
99
|
`;
|
|
100
100
|
|
|
101
|
+
// 假的 Qoder CLI:记下参数,照官方文档 --output-format json 的样子回一个 JSON(回答在 result,会话在 session_id)。
|
|
102
|
+
// STUB_QODER_FINAL 不为空时 subtype 用它(error_max_turns 之类),is_error 置真
|
|
103
|
+
const fakeQoder = `
|
|
104
|
+
const fs = require('node:fs');
|
|
105
|
+
const args = process.argv.slice(2);
|
|
106
|
+
fs.writeFileSync(process.env.STUB_QODER_ARGS || '/dev/null', args.join(' ') + '\\n');
|
|
107
|
+
const final = process.env.STUB_QODER_FINAL || '';
|
|
108
|
+
process.stdout.write(JSON.stringify({ type: 'result', subtype: final || 'success', is_error: Boolean(final), result: final ? '出了点问题' : '回复:' + args[args.length - 1], session_id: 'sess_q' }) + '\\n');
|
|
109
|
+
`;
|
|
110
|
+
|
|
111
|
+
// 假的 Claude Code 命令行:和 Qoder 那个一样,只是会话 ID 不同
|
|
112
|
+
const fakeClaude = `
|
|
113
|
+
const fs = require('node:fs');
|
|
114
|
+
const args = process.argv.slice(2);
|
|
115
|
+
fs.writeFileSync(process.env.STUB_CLAUDE_ARGS || '/dev/null', args.join(' ') + '\\n');
|
|
116
|
+
process.stdout.write(JSON.stringify({ type: 'result', subtype: 'success', is_error: false, result: '回复:' + args[args.length - 1], session_id: 'sess_c' }) + '\\n');
|
|
117
|
+
`;
|
|
118
|
+
|
|
101
119
|
// 假的 DSH 自带 Node:记下调用时的环境,丢掉「--import <路径>」两个参数,用真正的 node 把剩下的交给入口脚本
|
|
102
120
|
const fakeDshNode = `
|
|
103
121
|
const fs = require('node:fs');
|
|
@@ -137,4 +155,4 @@ process.stdout.write(JSON.stringify({ type: 'session', sessionId: 'session_fake'
|
|
|
137
155
|
process.stdout.write(JSON.stringify({ type: 'final', sessionId: 'session_fake', reason: { kind: process.env.STUB_DSH_FINAL || 'completed' }, text: '回复:' + args[args.length - 1] }) + '\\n');
|
|
138
156
|
`;
|
|
139
157
|
|
|
140
|
-
module.exports = { yzjCli, linky, security, fakeAgent, fakeZcode, fakeDshNode, fakeDsh, mdfind, mdls };
|
|
158
|
+
module.exports = { yzjCli, linky, security, fakeAgent, fakeZcode, fakeQoder, fakeClaude, fakeDshNode, fakeDsh, mdfind, mdls };
|
package/templates/AGENTS.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
- [03-carryover/DECISIONS.md](03-carryover/DECISIONS.md) — 每次我怎么决定一件事;只是以后的参考。
|
|
18
18
|
- [04-patterns/WORK_RHYTHM.md](04-patterns/WORK_RHYTHM.md) — 工作规律画像。
|
|
19
19
|
- [05-goals/](05-goals/) — 长期目标,一个文件一个,进行中的不超过 3 个。
|
|
20
|
-
- [collectors/](collectors/) — 自己写的采集器和本机配置(`local.env`,只放本机);内置采集器在 `work-rhythm` 包里。整个目录靠 `work-rhythm <子命令>` 运转:`sync` 同步,`today` 给出今天的路径和是否工作日,`goals` 列出目标、找出到期该检查的,`decisions` 记决定、查以前的决定、归档,`notify` 按 profile 的 `notify` 把计划、复盘推给我,`rhythm` 是本地服务(定时采集、定时整理、推送、本机网页),`listen` 值守着收我在 IM
|
|
20
|
+
- [collectors/](collectors/) — 自己写的采集器和本机配置(`local.env`,只放本机);内置采集器在 `work-rhythm` 包里。整个目录靠 `work-rhythm <子命令>` 运转:`sync` 同步,`today` 给出今天的路径和是否工作日,`goals` 列出目标、找出到期该检查的,`decisions` 记决定、查以前的决定、归档,`notify` 按 profile 的 `notify` 把计划、复盘推给我,`rhythm` 是本地服务(定时采集、定时整理、推送、本机网页),`agent` 绑定定时任务和值守用哪个 agent,`listen` 值守着收我在 IM 里说的话、交给绑定的 agent 回复,`check` 自检,`selftest` 自测;每个命令的用法看 `work-rhythm <子命令> --help`。
|
|
21
21
|
- [.agents/notes/](.agents/notes/AGENTS.md) — 给 agent 的踩坑笔记和设计取舍。改脚本、配置或文档格式之前,先按它的「动手之前先看哪几篇」过一遍;踩了新坑就记进去。
|
|
22
22
|
|
|
23
23
|
## Standing orders
|
package/templates/README.md
CHANGED
|
@@ -51,7 +51,7 @@ tasks/ 定时任务的指令,一个任务一个文件,是交给 a
|
|
|
51
51
|
- 内置的采集器:本机代码提交(含子模块)、文件改动、云之家日程、云之家消息、云之家告警与发布通知、云之家里等我审批的流程、Linky 上分配给我的未完成工作项。要登录的几个默认关着,配好后再到 `sources.yaml` 打开。
|
|
52
52
|
- 不用 AI 也能同步:`work-rhythm sync`,可以直接放进 cron 或 launchd。
|
|
53
53
|
- 改完配置或文档跑一遍 `work-rhythm check`:语法、内链、预算、配置、疑似密钥、笔记格式,只读不改。
|
|
54
|
-
- 定时任务靠本地服务 `work-rhythm rhythm
|
|
54
|
+
- 定时任务靠本地服务 `work-rhythm rhythm`,不建在 agent 运行时自带的调度器上。服务要先绑一个 agent(`work-rhythm agent bind`,见 [docs/agents.md](docs/agents.md)),没绑就不起,也不支持机器人值守:到点跑采集,到点把 [tasks/](tasks/) 里的指令交给 agent 跑一遍,跑完经消息渠道把总结推给我并附一个本机页面的地址,本机还能打开网页看每日文件、遗留、规律和目标。定义和用法见 [docs/scheduled-tasks.md](docs/scheduled-tasks.md);待决的事不做定时巡查,我对任何一个 agent 说「有什么要我定」就逐件来问。
|
|
55
55
|
- 提醒推送走「消息渠道」,见 [docs/channels.md](docs/channels.md):`profile` 的 `notify` 写渠道名,`work-rhythm notify` 负责发,只发给我本人。预置的是云之家个人机器人(`yzj-robot`):在网页端建一个机器人,把它的 Webhook 地址存进系统钥匙串,就配好了。别的 IM 按「新增一个渠道」接。
|
|
56
56
|
- 渠道还能反过来收:`work-rhythm listen` 和同一个机器人保持长连接,我在云之家里说的话交给本地的 agent 处理并回复。agent 预置了 DSH(模型跟着 DSH 里的配置走)和 ZCode 的命令行,也可以写一条自己的命令。它要常驻、每条消息跑一次 agent,所以默认不开;要开按 `docs/channels.md` 的「收消息:值守」。
|
|
57
57
|
|