work-rhythm 0.1.3 → 0.1.5

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.
@@ -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
+ | 改模型 / 思考强度的配置、`agent models`,或想知道 zcode 为什么配不了模型 | [绑定时问模型和思考强度](decisions/2026-12-01-agent-binding-asks-for-model-and-effort.md) |
26
27
  | 改引导第 6 步、`work-rhythm agent`、预置的 agent(`scripts/lib/agent.js`),或想知道为什么不往运行时的调度器建任务 | "+NEW+" |
27
28
  | 改值守(`scripts/lib/bot.js`、`scripts/lib/agent.js`),想换一个回复的 agent,或要改值守的权限默认值 | [值守用长连接收消息](decisions/2026-11-30-bot-inbound-uses-websocket-and-a-responder-command.md) |
28
29
  | 改本地服务(`scripts/lib/rhythm.js`)、`tasks/*.md`、`profile` 的 `rhythm:` 一节,或想知道定时任务为什么不绑在运行时的调度器上 | [运转的中心挪到本机服务](decisions/2026-11-30-scheduling-moves-to-a-local-service.md) |
@@ -0,0 +1,29 @@
1
+ # 给 work-rhythm 绑定 agent 时,模型和思考强度也要问用户、写进配置、调用时真的带上
2
+
3
+ Decided: 2026-12-01
4
+
5
+ ## Problem
6
+
7
+ [定时任务只建在 CLI 上,先绑一个 agent](2026-12-01-scheduling-is-cli-only-and-needs-a-bound-agent.md)只解决了「用哪个 agent」,没管「用哪个模型、思考强度多少」:预置只管能跑起来,模型都是各家命令行自己的默认——zcode 的无界面默认是 opencode-go 的 minimax-m3.1-flash,不是用户在窗口里给会话选的;dsh 跟着桌面应用的默认(本机是 deepseek-v4.1-flash、max)。用户要求:配置 agent 的时候用什么模型要问,思考强度也要配上。
8
+
9
+ ## Decision
10
+
11
+ - `collectors/local.env` 加两个键:`YZJ_BOT_MODEL`、`YZJ_BOT_EFFORT`(none / low / medium / high / max)。不写就用 agent 自己的默认。定时任务可以另配:profile 的 `rhythm.agent-model` / `rhythm.agent-effort`,不配就沿用这两个。
12
+ - `work-rhythm agent bind` 接受 `--model` / `--effort`;`agent model <模型>` / `agent effort <强度>`(`--clear` 清掉);`agent models <名字>` 列出能用的;`agent doctor` 校验模型在它的清单里、强度在词表里;`agent test` 请 agent 自报模型。
13
+ - 各家怎么带上:dsh 写进自动生成的覆盖文件(`agent-default-model` 的 `provider` / `model` / `reasoningEffort`,清单来自它配置里的 `llm-pi-ai`);qoder 加 `--model` / `--reasoning-effort`;claude 加 `--model` / `--effort`。
14
+ - **zcode 不支持**:ZCode 的命令行(0.18.0)没有指定模型和强度的参数(`--help` 里没有,bundle 里 `"--model"` 只属于它内置的别家命令),`/model` 只能在交互界面里切。给它写模型或强度会被 `agent bind` / `agent model` 拒绝并说明原因。
15
+ - 引导第 6 步绑定后**必须问**:列出模型清单、标出当前默认,问用哪个,再问强度(给建议:定时任务 medium / high,值守聊天 low / medium);绑的是 zcode 如实说配不了。
16
+
17
+ ## Alternatives considered
18
+
19
+ **不问,用各家默认。** 被否:用户明确要求问;而且默认往往不是想要的(zcode 的默认是 flash 档)。
20
+
21
+ **给 zcode 想办法绕(改它的 provider 配置、走 app-server 协议)。** 推迟:改用户 ZCode 的配置文件越界,app-server 协议为一件事引一整套不值;等它的命令行支持参数。
22
+
23
+ **强度词表按各家原样透传(qoder 还有 xhigh)。** 被否:五个词够用、各家都能映射;qoder 认 `xhigh` 的话直接写进 local.env 也行,命令层不列。
24
+
25
+ ## Consequences
26
+
27
+ - 真机验证:dsh 绑 `zai-coding-cn/glm-5.3-flash` + `low`,覆盖文件换了,agent 自报 glm-5.3-flash,4 秒。qoder / claude 的模型参数按官方文档写,没在真机跑过(本机没装)。
28
+ - DSH 的配置是 YAML,用 lib/config 的解析器读(先是按缩进手写解析,对不上它的缩进,列不出模型)。
29
+ - `agent test` 的默认问题改成请它自报模型,回答不再是自我介绍。
@@ -29,3 +29,4 @@ Decided: 2026-12-01
29
29
  - Qoder 和 Claude Code 两个预置按官方文档写,没在真机上跑过(本机没装);`work-rhythm agent test` 是装了之后一步验证的办法。
30
30
  - 「认正在调的 agent」靠环境变量,各家公司随时可能改名;认不出来只是退回让用户选,不会出错。
31
31
  - `check` 不再把「配了 YZJ_BOT_AGENT」当成「要开值守」;装了值守才核对值守。
32
+ - 同日后续:绑定之后还要问模型和思考强度(zcode 的命令行配不了)。见[绑定时问模型和思考强度](2026-12-01-agent-binding-asks-for-model-and-effort.md)。
@@ -24,7 +24,7 @@ when_to_use: "第一次进入工作目录、初始化还没做完(setup.status
24
24
  - 定位之后,读写文件都用绝对路径 `WORKDIR/…`;命令站在 WORKDIR 里跑,或者带上 `--workdir "$WORKDIR"`。下文的路径都省略了 `WORKDIR/` 前缀。
25
25
  - `SOURCE=pointer` 时在回复里点一句记到了哪里(「已记到 my-work」),用户在别的项目里才找得到。
26
26
  - `WORKDIR` 为空说明这台机器上还没有登记过工作目录。这不算异常,用选择题工具问一句「用哪个工作目录」,三项,**新建**排第一、标为默认:
27
- 1. **新建(默认)**:先问放到哪,默认提议 `~/workspace/my-work`(已存在就换个名字),然后 `work-rhythm init <目录>`。它用包里带的模板建出工作目录:个人信息是空白的、数据源全关、没有记录,并登记;之后从「步骤 0」接着引导。全程不联网,不需要任何仓库的访问权。脚本报「包不完整」时,让用户重新安装一次 `work-rhythm`。
27
+ 1. **新建(默认)**:先问放到哪,默认提议 `~/workspace/my-work`(目录已存在但是空的可以直接用;非空就换个名字),然后 `work-rhythm init <目录>`。它用包里带的模板建出工作目录:个人信息是空白的、数据源全关、没有记录,并登记;之后从「步骤 0」接着引导。全程不联网,不需要任何仓库的访问权。脚本报「包不完整」时,让用户重新安装一次 `work-rhythm`。
28
28
  2. **我给一个**:用户报一个已有目录,`work-rhythm workdir register <路径>` 登记后继续。
29
29
  3. **让 AI 找**:`work-rhythm workdir find` 列出本机带 `00-config/profile.yaml` 的目录(路径、初始化状态、称呼),把候选给用户选,选中就登记。一个都没找到就照实说,回到另外两项。
30
30
 
@@ -160,12 +160,14 @@ IM 是工作密度最高的信号,也决定了后面能不能自动化,所
160
160
 
161
161
  定时任务全在 `work-rhythm rhythm` 这个本地服务上:到点采集、到点把任务交给 agent 跑、跑完经消息渠道推送、在本机起网页服务。它和会话无关,agent 不在自己运行时的调度器上建任务——那条路已经不走了。服务到点要一个 agent 来跑,机器人值守(「消息渠道」)也是它来答,所以先绑一个。细节见 `docs/agents.md`。
162
162
 
163
- 1. **看本机有什么**:跑 `work-rhythm agent --json`。它列出预置的四个(zcode、dsh、qoder、claude)各装没装,以及现在是不是有 agent 正在调这个 skill(按它给工具留的环境变量认)。
164
- 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 不做。
165
- 3. **定时间**:问上下班时间,按 `docs/scheduled-tasks.md` 的默认规则换算出时间点(上班前 10 分钟、午休开始、下班前 15 分钟),用户确认后写入 `schedule`;不要的任务在 `schedule` 里写空。介绍几个标准任务(每日工作计划、中午工作进展、晚间工作复盘、遗留待处理)和可选的每周工作规律,确认要开哪些。
166
- 4. **说明待决的事怎么走**:不做定时巡查。计划和复盘的推送里会提醒有几件等他定,到时候对任何一个能读到这个工作目录的 agent 说「有什么要我定」,就逐件来问。
167
- 5. **装服务**:`work-rhythm rhythm doctor` 查配置,`work-rhythm rhythm due` 给用户看今天什么时候跑什么;`work-rhythm rhythm run <任务id> --push` 试一遍,看推送和页面。征得同意后 `install`(macOS launchd 常驻)或者让用户自己 `start`。
168
- 6. 把 `setup.status` 改成 `done`,更新 `setup.updated`。
163
+ 1. **看本机有什么**:跑 `work-rhythm agent --json`。它列出预置的四个(zcode、dsh、qoder、claude)各装没装、哪个能配模型,以及现在是不是有 agent 正在调这个 skill(按它给工具留的环境变量认)。
164
+ 2. **定绑哪个**:默认就用正在调这个 skill 的 agent——用户正在用它,登录是现成的;它没装命令行、或用户想换,就把装了的列出来让他选。用 `work-rhythm agent bind <名字>` 写进 `collectors/local.env`(`YZJ_BOT_AGENT`)。一个都没装:如实说定时任务和机器人值守现在做不了,按 `docs/agents.md` 教他装一个,`schedule` 留空,原因记进 `setup.skipped`,下面的 3–8 不做。
165
+ 3. **问模型和思考强度**(一定要问,不要替用户定):`work-rhythm agent models <名字>` 列出能用的,把清单给用户看,标清哪个是它当前的默认;问他用哪个模型,再问思考强度多少——`low` 快而省,`medium` 日常够用,`high` / `max` 想得深但慢、费 token;定时任务整理一天的事件建议 `medium` 或 `high`,机器人值守聊天建议 `low` 或 `medium`。用户说「随便」就用它当前的默认模型加 `medium`。定下来用 `work-rhythm agent bind <名字> --model <模型> --effort <强度>`(或 `agent model` / `agent effort`)写进 `collectors/local.env`。绑的是 zcode 时如实说:ZCode 的命令行没有指定模型和强度的参数,用的是它自己的默认(本机实测是 opencode-go 的 minimax-m3.1-flash),在意的话换 dsh / qoder。想给定时任务另配一套,写 profile 的 `rhythm.agent-model` / `rhythm.agent-effort`。
166
+ 4. **试一句**:`work-rhythm agent test` 让它自报模型,把回答给用户看,确认模型对得上、登录没过期。
167
+ 5. **定时间**:问上下班时间,按 `docs/scheduled-tasks.md` 的默认规则换算出时间点(上班前 10 分钟、午休开始、下班前 15 分钟),用户确认后写入 `schedule`;不要的任务在 `schedule` 里写空。介绍几个标准任务(每日工作计划、中午工作进展、晚间工作复盘、遗留待处理)和可选的每周工作规律,确认要开哪些。
168
+ 6. **说明待决的事怎么走**:不做定时巡查。计划和复盘的推送里会提醒有几件等他定,到时候对任何一个能读到这个工作目录的 agent 说「有什么要我定」,就逐件来问。
169
+ 7. **装服务**:`work-rhythm rhythm doctor` 查配置,`work-rhythm rhythm due` 给用户看今天什么时候跑什么;`work-rhythm rhythm run <任务id> --push` 试一遍,看推送和页面。征得同意后 `install`(macOS launchd 常驻)或者让用户自己 `start`。
170
+ 8. 把 `setup.status` 改成 `done`,更新 `setup.updated`。
169
171
 
170
172
  ### 步骤 7:交代用法
171
173
 
@@ -42,6 +42,13 @@
42
42
  # "qoder" Qoder CLI(要另装:curl -fsSL https://qoder.com/install | bash,装完 qoder login)。模型和登录跟着 Qoder CLI 自己的配置
43
43
  # "claude" Claude Code 的命令行
44
44
  # 一条自己的命令:我的消息作为最后一个参数传给它,回复打到标准输出,退出码 0 算成功。路径带空格的命令先写成一个脚本再写它的路径
45
+ # 用哪个模型、思考强度多少(引导时会问你;只有 dsh / qoder / claude 认,zcode 的命令行没有这两个参数,用它自己的默认):
46
+ # work-rhythm agent models <名字> 列出能用的
47
+ # work-rhythm agent model <模型> dsh 写「provider/模型id」或模型id,qoder / claude 写它们认的模型名;不写用 agent 自己的默认
48
+ # work-rhythm agent effort <强度> none / low / medium / high / max;不写用 agent 自己的默认
49
+ # 定时任务想另配一套,写 profile 的 rhythm.agent-model / rhythm.agent-effort
50
+ # YZJ_BOT_MODEL="opencode-go/deepseek-v4.1-flash"
51
+ # YZJ_BOT_EFFORT="medium"
45
52
  # YZJ_BOT_AGENT_MODE 是权限:plan 只读(默认,能查能答能出计划,不改文件);edit 允许改工作目录,等于我在聊天里说什么它就做什么
46
53
  # YZJ_BOT_TIMEOUT 每条消息最多等多少秒(默认 300);YZJ_BOT_REPLY_MAX 回复最多多少字(默认 2000,超出截断并注明)
47
54
  # 消息一到机器人先回「收到,正在处理,稍等。」,YZJ_BOT_ACK=0 关掉。
package/docs/agents.md CHANGED
@@ -3,10 +3,12 @@
3
3
  定时任务全在 `work-rhythm rhythm` 这个本地服务上,agent 不在自己运行时的调度器上建任务。服务到点要把任务交给一个 agent 跑,机器人值守([channels.md](channels.md))也是它来答——所以要先给 work-rhythm 绑定一个 agent。没绑就没有定时任务(`rhythm` 拒绝起),也不支持机器人响应(`listen` 拒绝跑)。
4
4
 
5
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 配置和依赖有没有问题
6
+ work-rhythm agent # 本机装了哪些、现在是不是有 agent 正在调这个 skill、现在绑的是哪个、模型和强度是多少
7
+ work-rhythm agent bind [名字|命令] # 绑定,写进 collectors/local.env 的 YZJ_BOT_AGENT;--model / --effort 一起写
8
+ work-rhythm agent models [名字] # 这个 agent 能用哪些模型
9
+ work-rhythm agent model <模型> # 只换模型;agent effort <强度> 只换思考强度(--clear 清掉)
10
+ work-rhythm agent test ["一句话"] # 让绑定的 agent 只读答一句(自报模型),看模型和凭据通不通
11
+ work-rhythm agent doctor # 绑定的 agent、模型、强度有没有问题
10
12
  ```
11
13
 
12
14
  绑哪个:**现在正在调这个 skill 的那个 agent,它装了的话就用它**——用户正在用它,模型和登录都是现成的;它没装命令行、或者用户想换,就从装了的里面选;都由用户定。一个都没装,如实说定时任务和值守现在做不了,教他装一个(下表),`schedule` 留空,原因记进 `setup.skipped`。
@@ -15,10 +17,10 @@ work-rhythm agent doctor # 绑定的 agent 配置和依赖有没有
15
17
 
16
18
  | 名字 | 是什么 | 怎么找到 | 模型和凭据跟谁走 | 实测 |
17
19
  |---|---|---|---|---|
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 自己的登录 | 按公开的用法写的,没在真机上跑过 |
20
+ | `zcode` | ZCode 自带的命令行(桌面版里就有,不用另装) | PATH 上的 `zcode`,或 `/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs`;`ZCODE_CLI` 可指定 | 它自己的默认选择,不是 ZCode 窗口里给会话选的模型;命令行没有指定模型和强度的参数,配不了 | 是 |
21
+ | `dsh` | DSH(DeepSeek Harness)桌面版的 headless 模式 | `~/.dsh-desktop/runtime/<版本>/dsh/` 下的入口,用它自带的 Node 跑;`DSH_HOME`、`DSH_NODE`、`DSH_CLI` 可指定 | DSH 桌面应用里配好的模型和凭据(值守自动生成一份只含模型配置、并打开凭据存储的覆盖文件带进去,密钥始终在 DSH 自己的存储里);模型和强度可用 `YZJ_BOT_MODEL` / `YZJ_BOT_EFFORT` 换,清单来自它的配置 | 是 |
22
+ | `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`);模型和强度可用 `YZJ_BOT_MODEL` / `YZJ_BOT_EFFORT` 换 | 按官方文档写的,没在真机上跑过 |
23
+ | `claude` | Claude Code 的命令行 | PATH 上的 `claude`;`CLAUDE_CLI` 可指定 | Claude Code 自己的登录;模型和强度可换 | 按公开的用法写的,没在真机上跑过 |
22
24
 
23
25
  其余值当成一条自己的命令:按空白拆开(引号里的算一个参数),消息作为最后一个参数传给它,回复打到标准输出,退出码 0 算成功。不支持管道、重定向——要的话包一层脚本。
24
26
 
@@ -26,8 +28,23 @@ work-rhythm agent doctor # 绑定的 agent 配置和依赖有没有
26
28
 
27
29
  - zcode:`zcode --cwd <工作目录> --mode <模式> [--resume <会话>] --no-color --json -p <这句话>`,回答在 JSON 的 `response`,会话在 `sessionId`。
28
30
  - 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
+ - qoder:`qoder --cwd <工作目录> --permission-mode <模式> [--model <模型>] [--reasoning-effort <强度>] [--resume <会话>] --output-format json --print <这句话>`,回答在 JSON 的 `result`,会话在 `session_id`。无界面模式下它不弹确认,要确认的操作一律被拒。
32
+ - claude:`claude --cwd <工作目录> --permission-mode <模式> [--model <模型>] [--effort <强度>] [--resume <会话>] --output-format json -p <这句话>`。
33
+
34
+ ## 模型和思考强度
35
+
36
+ 引导第 6 步绑定 agent 时要问用户两件事:用哪个模型、思考强度多少。写在 `collectors/local.env`:
37
+
38
+ | 键 | 意思 | 怎么取值 |
39
+ |---|---|---|
40
+ | `YZJ_BOT_MODEL` | 模型。不写用 agent 自己的默认 | `work-rhythm agent models <名字>` 列出能用的;dsh 写 `provider/模型id`(如 `zai-coding-cn/glm-5.3-flash`)或只写模型id;qoder 写它认的档位或模型名(`auto` / `lite` / `performance` / 具体模型);claude 写 `opus` / `sonnet` / `haiku` 或全名 |
41
+ | `YZJ_BOT_EFFORT` | 思考强度。不写用 agent 自己的默认 | `none` / `low` / `medium` / `high` / `max`:`low` 快而省,`medium` 日常够用,`high` / `max` 想得深但慢、费 token |
42
+
43
+ 改用 `work-rhythm agent model <模型>` / `agent effort <强度>`(`--clear` 清掉),或者绑的时候一起写 `agent bind <名字> --model … --effort …`;写完 `work-rhythm agent test` 让它自报模型核对。
44
+
45
+ 各家怎么带上:dsh 写进自动生成的覆盖文件(`agent-default-model` 的 `provider` / `model` / `reasoningEffort`,2026-12-01 实测换模型生效);qoder 加 `--model` / `--reasoning-effort`(它还认 `xhigh`,我们没列,要的话直接写进 local.env);claude 加 `--model` / `--effort`。**zcode 不支持**:ZCode 的命令行(0.18.0)没有指定模型和强度的参数,`/model` 只能在交互界面里切,无界面跑用它自己的默认选择;给它写了 `YZJ_BOT_MODEL` 会在 `agent doctor` 里报出来,调用时也不生效。
46
+
47
+ 定时任务可以用和值守不一样的一套:profile 的 `rhythm` 一节写 `agent-model` / `agent-effort`(可选项),不配就沿用上面两个。
31
48
 
32
49
  ## 权限
33
50
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "work-rhythm",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "个人工作目录:记录每天的工作事件、按订阅源采集数据、做计划和复盘;带本地服务(定时采集、定时整理、经消息渠道推送、本机网页)",
5
5
  "license": "UNLICENSED",
6
6
  "type": "commonjs",
@@ -1,34 +1,48 @@
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
1
+ // work-rhythm agent:定时任务和机器人值守都要一个 agent 来跑,这里管「用哪个 agent、哪个模型、思考强度多少」。
2
+ // 用法: work-rhythm agent 看本机装了哪些、现在是不是有 agent 正在调这个 skill、现在绑的是哪个、模型和强度
3
+ // work-rhythm agent models [名字] 这个 agent 能用哪些模型(不给名字就是绑定的那个)
4
+ // work-rhythm agent bind <名字|命令> [--model <模型>] [--effort <强度>]
5
+ // 绑定,写进 collectors/local.env 的 YZJ_BOT_AGENT;模型和强度写了就一起写
6
+ // work-rhythm agent model <模型id> | agent model --clear 只换模型
7
+ // work-rhythm agent effort <强度> | agent effort --clear 只换思考强度
8
+ // work-rhythm agent test ["一句话"] 让绑定的 agent 答一句(自报模型),看模型和凭据通不通
9
+ // work-rhythm agent doctor 绑定的 agent、模型、强度有没有问题
10
+ // work-rhythm agent --json 打成 JSON,给 agent 读
11
+ // 预置:zcode、dsh、qoder、claude;其余值当成一条自己的命令。
12
+ // 「正在调这个 skill 的是哪个」看它给工具留的环境变量。模型和强度只有支持的预置才认(zcode 的命令行没有这两个参数)。
13
+ // 没绑 agent 就没有定时任务(rhythm 拒绝起)和机器人响应(listen 拒绝跑)。细节见 docs/agents.md
10
14
  'use strict';
11
15
  const fs = require('node:fs');
12
16
  const path = require('node:path');
13
17
  const { EXIT, Fail, UsageError } = require('../lib/run');
14
18
  const { settings } = require('../lib/config');
15
- const { PRESETS, PRESET_NAMES, invokingAgent, installedAgents, bindAgent, createAgent } = require('../lib/agent');
19
+ const { PRESETS, PRESET_NAMES, MODEL_SUPPORT, EFFORTS, invokingAgent, installedAgents, bindAgent, createAgent, listModels } = require('../lib/agent');
16
20
 
17
- const USAGE = `work-rhythm agent [子命令] —— 定时任务和机器人值守用哪个 agent:检测本机的、绑定、试一句
21
+ const USAGE = `work-rhythm agent [子命令] —— 定时任务和机器人值守用哪个 agent、哪个模型、思考强度多少:检测本机的、绑定、试一句
18
22
 
19
23
  用法: work-rhythm agent [子命令]
20
- 看本机装了哪些、现在是不是有 agent 正在调这个 skill、现在绑的是哪个(--json 打成 JSON)
24
+ 看本机装了哪些、现在是不是有 agent 正在调这个 skill、现在绑的是哪个、模型和强度是多少(--json 打成 JSON)
25
+ models [名字] 这个 agent 能用哪些模型(不给名字就是绑定的那个);dsh 读它的配置,qoder 问命令行,claude 给常见的别名
21
26
  bind [名字|命令] 绑定,写进 collectors/local.env 的 YZJ_BOT_AGENT;不给名字就用正在调的这个,没有就装了的第一个
22
- test ["一句话"] 让绑定的 agent 答一句
23
- doctor 绑定的 agent 配置和依赖有没有问题
24
- 预置:${PRESET_NAMES.join('、')};其余值当成一条自己的命令(消息作为最后一个参数,回复打到标准输出)。
25
- 退出码: 0;1 doctor 查出问题;2 用法不对;3 没绑或绑不上(本机找不到那个 agent);5 test 没答上来。
27
+ [--model <模型>] 一起写模型:dsh 写「provider/模型id」或模型id;qoder、claude 写它们认的模型名。不写不动原来的
28
+ [--effort <强度>] 一起写思考强度:none / low / medium / high / max。不写不动原来的
29
+ model <模型id> 只换模型;model --clear 清掉,用 agent 自己的默认
30
+ effort <强度> 只换思考强度(none / low / medium / high / max);effort --clear 清掉
31
+ test ["一句话"] 让绑定的 agent 答一句(默认请它自报模型),只读
32
+ doctor 绑定的 agent、模型、强度有没有问题
33
+ 预置:${PRESET_NAMES.join('、')}。模型和强度只有 ${PRESET_NAMES.filter((n) => MODEL_SUPPORT[n].model).join('、')} 支持(zcode 的命令行没有这两个参数,用它自己的默认);
34
+ 其余值当成一条自己的命令(消息作为最后一个参数,回复打到标准输出)。
35
+ 定时任务可以另配模型和强度:profile 的 rhythm.agent-model / rhythm.agent-effort,不配就和这里一样。
36
+ 退出码: 0;1 doctor 查出问题;2 用法不对;3 没绑或绑不上(本机找不到那个 agent、模型不在它的清单里、它不支持这个设置);5 test 没答上来。
26
37
  各家怎么被调用、权限模式见 docs/agents.md。`;
27
38
 
28
39
  function binding(root, env) {
29
- return (settings(root, env).YZJ_BOT_AGENT || '').trim();
40
+ const s = settings(root, env);
41
+ return { agent: (s.YZJ_BOT_AGENT || '').trim(), model: (s.YZJ_BOT_MODEL || '').trim(), effort: (s.YZJ_BOT_EFFORT || '').trim() };
30
42
  }
31
43
 
44
+ const kindOf = (name) => (PRESET_NAMES.includes(name) ? name : name ? 'custom' : '');
45
+
32
46
  // 建议绑哪个:正在调这个 skill 的那个(它装了的话);否则装了的第一个;都没有就空
33
47
  function suggest(list) {
34
48
  const invoking = list.find((a) => a.invoking && a.found);
@@ -37,6 +51,54 @@ function suggest(list) {
37
51
  return first ? first.name : '';
38
52
  }
39
53
 
54
+ // 模型和强度对这个 agent 意味着什么,一句话
55
+ function describeModel(kind, model, effort) {
56
+ if (kind === 'custom') return model || effort ? '自定义命令:模型和强度写在你的命令里,这里不传' : '';
57
+ const support = MODEL_SUPPORT[kind] || {};
58
+ const parts = [];
59
+ parts.push(model ? (support.model ? `模型 ${model}` : `写了模型 ${model},但 ${kind} 不支持,不生效`) : '模型用它自己的默认');
60
+ parts.push(effort ? (support.effort ? `思考强度 ${effort}` : `写了思考强度 ${effort},但 ${kind} 不支持,不生效`) : '思考强度用它自己的默认');
61
+ return parts.join(',');
62
+ }
63
+
64
+ // 把某个预置能用的模型列出来
65
+ function showModels(kind, env, stdout) {
66
+ const r = listModels(kind, env);
67
+ if (r.problem) throw new Fail(EXIT.NOT_CONFIGURED, r.problem);
68
+ if (r.text) {
69
+ stdout.write(r.text.endsWith('\n') ? r.text : `${r.text}\n`);
70
+ return;
71
+ }
72
+ const current = r.current || {};
73
+ stdout.write(`${kind} 能用的模型:\n`);
74
+ for (const m of r.models) {
75
+ const marks = [];
76
+ if (current.model === m.id) marks.push('当前默认');
77
+ if (m.reasoning) marks.push('支持思考强度');
78
+ stdout.write(` ${(m.provider ? `${m.provider}/${m.id}` : m.id).padEnd(40)} ${m.name || ''}${marks.length ? ` ${marks.join(' · ')}` : ''}\n`);
79
+ }
80
+ if (current.effort) stdout.write(`当前默认的思考强度:${current.effort}\n`);
81
+ if (!r.models.length) stdout.write(' (没列出来:看它的文档或 --list-models)\n');
82
+ }
83
+
84
+ // bind 的参数:<名字> 可选(最多一个),--model X / --effort X 可选,顺序随意
85
+ function parseBind(params) {
86
+ const names = [];
87
+ const opts = {};
88
+ for (let i = 0; i < params.length; i += 1) {
89
+ const a = params[i];
90
+ if (a === '--model' || a === '--effort') {
91
+ const v = params[i + 1];
92
+ if (v === undefined || v.startsWith('--')) throw new UsageError(`${a} 后面要跟一个值\n${USAGE}`);
93
+ opts[a.slice(2)] = v;
94
+ i += 1;
95
+ } else if (a.startsWith('--')) throw new UsageError(`不认识的参数 ${a}\n${USAGE}`);
96
+ else names.push(a);
97
+ }
98
+ if (names.length > 1) throw new UsageError(USAGE);
99
+ return { name: names[0], opts };
100
+ }
101
+
40
102
  module.exports = {
41
103
  usage: USAGE,
42
104
  async run(args, ctx) {
@@ -46,61 +108,107 @@ module.exports = {
46
108
  const rest = args.filter((a) => a !== '--json');
47
109
  const [verb, ...params] = rest;
48
110
  const bound = binding(root, env);
111
+ const boundKind = kindOf(bound.agent);
49
112
 
50
113
  switch (verb) {
51
114
  case undefined: {
52
115
  if (params.length) throw new UsageError(USAGE);
53
116
  const invoking = invokingAgent(env);
54
117
  const pick = suggest(list);
55
- const report = {
56
- invoking,
57
- invokingFound: invoking ? list.find((a) => a.name === invoking).found : false,
58
- bound: presetKindOf(bound),
59
- boundValue: bound,
60
- suggest: pick,
61
- agents: list.map((a) => ({ name: a.name, label: a.label, found: a.found, command: a.command, problem: a.problem || undefined, invoking: a.invoking })),
62
- };
118
+ const support = boundKind && boundKind !== 'custom' ? MODEL_SUPPORT[boundKind] : null;
63
119
  if (json) {
64
- stdout.write(`${JSON.stringify(report, null, 1)}\n`);
120
+ stdout.write(`${JSON.stringify({
121
+ invoking,
122
+ invokingFound: invoking ? list.find((a) => a.name === invoking).found : false,
123
+ bound: boundKind,
124
+ boundValue: bound.agent,
125
+ model: bound.model,
126
+ effort: bound.effort,
127
+ modelSupported: support ? support.model : null,
128
+ effortSupported: support ? support.effort : null,
129
+ suggest: pick,
130
+ agents: list.map((a) => ({ name: a.name, label: a.label, found: a.found, command: a.command, problem: a.problem || undefined, invoking: a.invoking, modelSupported: MODEL_SUPPORT[a.name].model, effortSupported: MODEL_SUPPORT[a.name].effort })),
131
+ }, null, 1)}\n`);
65
132
  return EXIT.OK;
66
133
  }
67
134
  stdout.write('本机的 agent:\n');
68
135
  for (const a of list) {
69
136
  const how = a.found ? a.command : `没装:${a.problem}`;
70
- stdout.write(` ${a.name.padEnd(7)}${a.found ? '装了' : '没装'} ${a.label}${a.invoking ? ' ← 现在是它在调这个 skill' : ''}\n ${how}\n`);
137
+ stdout.write(` ${a.name.padEnd(7)}${a.found ? '装了' : '没装'} ${a.label}${a.invoking ? ' ← 现在是它在调这个 skill' : ''}\n ${how}\n 模型和思考强度:${MODEL_SUPPORT[a.name].model ? `能配,work-rhythm agent models ${a.name} 看能用哪些` : '不能配,用它自己的默认'}\n`);
71
138
  }
72
139
  stdout.write(`正在调这个 skill 的:${invoking || '认不出来(不是从 agent 的工具里跑的,或者它不留标记)'}\n`);
73
- stdout.write(`现在绑定的:${bound || '没绑'}${bound && presetKindOf(bound) === 'custom' ? `(一条自定义命令,${PRESET_NAMES.join('/')} 以外)` : ''}\n`);
74
- if (!bound) stdout.write(`没绑 agent 就没有定时任务,也不支持机器人响应。${pick ? `建议:work-rhythm agent bind ${pick}` : '本机一个预置的 agent 都没装,先装一个(docs/agents.md)'}\n`);
140
+ stdout.write(`现在绑定的:${bound.agent || '没绑'}${boundKind === 'custom' ? '(一条自定义命令)' : ''}\n`);
141
+ if (bound.agent) {
142
+ const described = describeModel(boundKind, bound.model, bound.effort);
143
+ if (described) stdout.write(` ${described}\n`);
144
+ }
145
+ if (!bound.agent) stdout.write(`没绑 agent 就没有定时任务,也不支持机器人响应。${pick ? `建议:work-rhythm agent bind ${pick}` : '本机一个预置的 agent 都没装,先装一个(docs/agents.md)'}\n`);
75
146
  return EXIT.OK;
76
147
  }
77
- case 'bind': {
148
+ case 'models': {
78
149
  if (params.length > 1) throw new UsageError(USAGE);
79
- const name = params[0] || suggest(list);
150
+ const kind = params[0] || boundKind;
151
+ if (!kind) throw new Fail(EXIT.NOT_CONFIGURED, '还没绑 agent:work-rhythm agent models <名字>,或先 work-rhythm agent bind');
152
+ if (kind === 'custom') throw new Fail(EXIT.NOT_CONFIGURED, '自定义命令的模型写在你自己的命令里,这里列不出来');
153
+ if (!MODEL_SUPPORT[kind].model) throw new Fail(EXIT.NOT_CONFIGURED, `${kind} 不支持指定模型(ZCode 的命令行没有这个参数):用它自己的默认,或者换 dsh / qoder / claude`);
154
+ showModels(kind, env, stdout);
155
+ return EXIT.OK;
156
+ }
157
+ case 'bind': {
158
+ const { name: given, opts } = parseBind(params);
159
+ const name = given || suggest(list);
80
160
  if (!name) throw new Fail(EXIT.NOT_CONFIGURED, '本机没找到能用的 agent,也没指定要绑的命令:装一个预置的(docs/agents.md),或者 work-rhythm agent bind "<一条命令>"');
81
- const r = bindAgent(root, env, name);
161
+ const r = bindAgent(root, env, name, { model: opts.model, effort: opts.effort });
82
162
  if (r.problems) throw new Fail(EXIT.NOT_CONFIGURED, `绑不了 ${name}:${r.problems.join(';')}`);
83
- stdout.write(`已绑定 ${name}${r.kind === 'custom' ? '(一条自定义命令)' : `(${PRESETS[r.kind].label})`},写进了 ${path.relative(root, r.file)} 的 YZJ_BOT_AGENT。\n`);
84
- stdout.write(`下一步:work-rhythm agent test 让它答一句;定时任务用 work-rhythm rhythm doctor 查配置,机器人值守用 work-rhythm listen doctor。\n`);
163
+ const kind = kindOf(name);
164
+ const support = kind !== 'custom' ? MODEL_SUPPORT[kind] : null;
165
+ const after = binding(root, env);
166
+ stdout.write(`已绑定 ${name}${kind === 'custom' ? '(一条自定义命令)' : `(${PRESETS[kind].label})`},写进了 ${path.relative(root, r.file)} 的 YZJ_BOT_AGENT。\n`);
167
+ stdout.write(` ${describeModel(kind, after.model, after.effort)}\n`);
168
+ if (support && !after.model && !after.effort) {
169
+ stdout.write(` 模型和思考强度还没配:work-rhythm agent models ${name} 看能用哪些,work-rhythm agent model <模型> / agent effort <强度> 配上;不配就用它自己的默认。\n`);
170
+ }
171
+ stdout.write('下一步:work-rhythm agent test 让它答一句(会自报模型);定时任务用 work-rhythm rhythm doctor 查配置,机器人值守用 work-rhythm listen doctor。\n');
172
+ return EXIT.OK;
173
+ }
174
+ case 'model':
175
+ case 'effort': {
176
+ const isModel = verb === 'model';
177
+ let value;
178
+ if (params.length === 1 && params[0] === '--clear') value = '';
179
+ else if (params.length === 1 && !params[0].startsWith('--')) value = params[0];
180
+ else throw new UsageError(USAGE);
181
+ if (!isModel && value && !EFFORTS.includes(value)) throw new UsageError(`思考强度写的是「${value}」,只能是 ${EFFORTS.join(' / ')}`);
182
+ if (!bound.agent) throw new Fail(EXIT.NOT_CONFIGURED, '还没绑 agent:work-rhythm agent bind <名字>');
183
+ const support = boundKind !== 'custom' ? MODEL_SUPPORT[boundKind] : null;
184
+ const what = isModel ? '模型' : '思考强度';
185
+ if (value && support && !support[isModel ? 'model' : 'effort']) {
186
+ throw new Fail(EXIT.NOT_CONFIGURED, `${boundKind} 不支持指定${what}(${boundKind === 'zcode' ? 'ZCode 的命令行没有这个参数' : '见 docs/agents.md'}):换一个支持的 agent,或者不配、用它自己的默认`);
187
+ }
188
+ const r = bindAgent(root, env, bound.agent, isModel ? { model: value } : { effort: value });
189
+ if (r.problems) throw new Fail(EXIT.NOT_CONFIGURED, `写不了:${r.problems.join(';')}`);
190
+ const after = binding(root, env);
191
+ stdout.write(value ? `${what}已设为 ${value},写进了 ${path.relative(root, r.file)}。\n` : `${what}已清掉,用 ${boundKind} 自己的默认。\n`);
192
+ stdout.write(` ${describeModel(boundKind, after.model, after.effort)}\n下一步:work-rhythm agent test 让它答一句,看自报的模型对不对。\n`);
85
193
  return EXIT.OK;
86
194
  }
87
195
  case 'test': {
88
196
  if (params.length > 1) throw new UsageError(USAGE);
89
- if (!bound) throw new Fail(EXIT.NOT_CONFIGURED, '还没绑 agent:work-rhythm agent detect 看本机有哪些,work-rhythm agent bind <名字> 绑定');
197
+ if (!bound.agent) throw new Fail(EXIT.NOT_CONFIGURED, '还没绑 agent:work-rhythm agent detect 看本机有哪些,work-rhythm agent bind <名字> 绑定');
90
198
  const started = Date.now();
91
199
  // 只读模式跑一句;会话落在 01-inbox/_agent/ 下,不碰值守和定时任务各自的专属会话
92
- const agent = createAgent({ root, agent: bound, mode: 'plan', timeoutS: 180, env: settings(root, env), log: (event, fields) => stderr.write(`${event} ${fields}\n`) });
93
- const r = agent.run(params[0] || '你好,用一句话介绍你自己,并说出你用的是哪个模型。', { stateDir: path.join(root, '01-inbox', '_agent') });
200
+ const agent = createAgent({ root, agent: bound.agent, mode: 'plan', timeoutS: 180, env: settings(root, env), model: bound.model, effort: bound.effort, log: (event, fields) => stderr.write(`${event} ${fields}\n`) });
201
+ const r = agent.run(params[0] || '你好。请只用两句话回答:1)你是哪个模型?说模型名。2)1+1 等于几?', { stateDir: path.join(root, '01-inbox', '_agent') });
94
202
  if (r.config) throw new Fail(EXIT.NOT_CONFIGURED, r.failed);
95
203
  if (r.failed) throw new Fail(EXIT.FAILED, `没答上来:${r.failed}`);
96
- stdout.write(`${r.reply.trim()}\n(${bound},只读模式,用时 ${Math.round((Date.now() - started) / 1000)} 秒)\n`);
204
+ stdout.write(`${r.reply.trim()}\n(${bound.agent}${bound.model ? `,配置的模型 ${bound.model}` : ''}${bound.effort ? `,思考强度 ${bound.effort}` : ''};只读模式,用时 ${Math.round((Date.now() - started) / 1000)} 秒)\n`);
97
205
  return EXIT.OK;
98
206
  }
99
207
  case 'doctor': {
100
208
  if (params.length) throw new UsageError(USAGE);
101
- const problems = createAgent({ root, agent: bound, env: settings(root, env) }).doctor();
209
+ const problems = createAgent({ root, agent: bound.agent, env: settings(root, env), model: bound.model, effort: bound.effort }).doctor();
102
210
  if (problems.length) stdout.write(`${problems.join('\n')}\n`);
103
- else stdout.write(`${bound} 没有问题。\n`);
211
+ else stdout.write(`${bound.agent} 没有问题${bound.model || bound.effort ? `(${describeModel(boundKind, bound.model, bound.effort)})` : ''}。\n`);
104
212
  return problems.length ? 1 : EXIT.OK;
105
213
  }
106
214
  default:
@@ -108,7 +216,3 @@ module.exports = {
108
216
  }
109
217
  },
110
218
  };
111
-
112
- function presetKindOf(name) {
113
- return PRESET_NAMES.includes(name) ? name : name ? 'custom' : '';
114
- }
@@ -17,7 +17,9 @@ const USAGE = `work-rhythm init <目录> —— 新建一个工作目录:用
17
17
  work-rhythm init ~/workspace/my-work
18
18
  work-rhythm init my-work 相对路径按当前目录算;上级目录没有就一起建
19
19
  建好之后对 AI 说「开始引导」。工作目录只是机器上的一个目录:不 git init,不同步到任何仓库。
20
- 退出码: 0 建好;2 用法不对,或目录已经存在(拿它当工作目录用 work-rhythm workdir register);5 包不完整或铺出来的不是空白的(会把建了一半的目录删掉)。`;
20
+ 目标目录还不存在就建(上级目录没有也一起建);已经存在但是空的(只有 .DS_Store 也算空)就直接铺进去;已经存在而且不是空的拒绝,
21
+ 免得盖掉别人的东西——那已经是某个目录了,拿它当工作目录用 work-rhythm workdir register。
22
+ 退出码: 0 建好;2 用法不对,或目录已存在且非空;5 包不完整或铺出来的不是空白的(会把写了一半的东西清掉:新建的目录整个删掉,原有的空目录清回空的)。`;
21
23
 
22
24
  module.exports = {
23
25
  usage: USAGE,
@@ -25,18 +27,29 @@ module.exports = {
25
27
  const { stdout, stderr, cwd, env, packageRoot } = ctx;
26
28
  if (args.length !== 1) throw new UsageError(USAGE);
27
29
  const target = path.resolve(cwd, args[0]);
28
- if (fs.existsSync(target)) throw new Fail(EXIT.USAGE, `${target} 已经存在。拿它当工作目录用 work-rhythm workdir register;要新建就换个位置`);
30
+ // 目录已经存在:空的话可以直接铺进去(用户先 mkdir 了、或者编辑器先建了目录);不是空的别碰
31
+ const existed = fs.existsSync(target);
32
+ if (existed) {
33
+ if (!fs.statSync(target).isDirectory()) throw new Fail(EXIT.USAGE, `${target} 已经存在,而且不是目录;换个位置`);
34
+ const clutter = fs.readdirSync(target).filter((name) => name !== '.DS_Store');
35
+ if (clutter.length) throw new Fail(EXIT.USAGE, `${target} 已经存在而且不是空的(${clutter.length} 项,比如 ${clutter[0]}),不动它。它要是本来就是工作目录,用 work-rhythm workdir register;要新建就换个位置,或者先把里面的东西清走`);
36
+ }
29
37
  // 上级目录没有就一起建
30
38
  fs.mkdirSync(target, { recursive: true });
39
+ // 铺到一半失败:新建的目录整个删掉;原本就存在的空目录清回空的,目录本身留着
40
+ const undo = () => {
41
+ if (!existed) fs.rmSync(target, { recursive: true, force: true });
42
+ else for (const name of fs.readdirSync(target)) fs.rmSync(path.join(target, name), { recursive: true, force: true });
43
+ };
31
44
  let problems;
32
45
  try {
33
46
  problems = writeWorkdir(target, packageRoot);
34
47
  } catch (error) {
35
- fs.rmSync(target, { recursive: true, force: true });
48
+ undo();
36
49
  throw new Fail(EXIT.FAILED, error.message);
37
50
  }
38
51
  if (problems.length) {
39
- fs.rmSync(target, { recursive: true, force: true });
52
+ undo();
40
53
  throw new Fail(EXIT.FAILED, `铺出来的不是空白的工作目录,已经撤掉:${problems.join(';')}`);
41
54
  }
42
55
  // 有些助手只认 CLAUDE.md
@@ -10,6 +10,7 @@ const fs = require('node:fs');
10
10
  const os = require('node:os');
11
11
  const path = require('node:path');
12
12
  const { which } = require('./run');
13
+ const { parseYaml } = require('./config');
13
14
 
14
15
  const BUNDLED_ZCODE = '/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs';
15
16
 
@@ -165,10 +166,13 @@ function installedAgents(env) {
165
166
  });
166
167
  }
167
168
 
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();
169
+ // 把选定的 agent 写进 collectors/local.env 的 YZJ_BOT_AGENT(没有这个文件就从样例复制一份),顺带可以写模型和思考强度。
170
+ // 先确认它在本机找得到、模型和强度它认。返回 { name, kind, file } 或 { problems }
171
+ function bindAgent(root, env, name, { model, effort } = {}) {
172
+ // undefined = 不动原来的;空串 = 清掉
173
+ model = model === undefined ? undefined : String(model).trim();
174
+ effort = effort === undefined ? undefined : String(effort).trim();
175
+ const problems = createAgent({ root, agent: name, env, model: model || '', effort: effort || '' }).doctor();
172
176
  if (problems.length) return { problems };
173
177
  const dir = path.join(root, 'collectors');
174
178
  const file = path.join(dir, 'local.env');
@@ -177,13 +181,24 @@ function bindAgent(root, env, name) {
177
181
  if (fs.existsSync(example)) fs.copyFileSync(example, file);
178
182
  else fs.writeFileSync(file, '');
179
183
  }
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}`);
184
+ const value = quote(name);
185
+ let lines = fs.readFileSync(file, 'utf8').split('\n');
186
+ lines = setLocalEnvKey(lines, 'YZJ_BOT_AGENT', value);
187
+ // 模型和思考强度:给了字符串就写(空串是清掉),没给(undefined)不动原来的
188
+ if (model !== undefined) lines = setLocalEnvKey(lines, 'YZJ_BOT_MODEL', quote(model));
189
+ if (effort !== undefined) lines = setLocalEnvKey(lines, 'YZJ_BOT_EFFORT', quote(effort));
185
190
  fs.writeFileSync(file, `${lines.join('\n').replace(/\n*$/, '')}\n`);
186
- return { name, kind: presetKind(name), file };
191
+ return { name, kind: presetKind(name), file, model, effort };
192
+ }
193
+
194
+ const quote = (value) => (value === '' ? '""' : /[\s"'$`]/.test(value) ? `'${value.replace(/'/g, `'\\''`)}'` : `"${value}"`);
195
+
196
+ // 往 local.env 的行里写一个键:有就换那一行(连注释掉的那行一起换),没有就追加
197
+ function setLocalEnvKey(lines, key, value) {
198
+ const at = lines.findIndex((l) => new RegExp(`^#?\\s*${key}=`).test(l));
199
+ if (at >= 0) lines[at] = `${key}=${value}`;
200
+ else lines.push(`${key}=${value}`);
201
+ return lines;
187
202
  }
188
203
 
189
204
  // DSH 的命令行要用它自带的 Node 跑(设 ELECTRON_RUN_AS_NODE 当普通 node 用),入口是 @deepseek-ai/dsh 的 bin.js
@@ -214,8 +229,9 @@ function findDsh(env) {
214
229
  }
215
230
 
216
231
  // headless 默认不带桌面应用里的模型和凭据(会去找 deepseek-official 要 API key)。把它的配置里模型那两条摘出来,
217
- // 外加打开它的凭据存储,写成一份覆盖文件带进去。密钥始终在 DSH 自己的存储里,不经过这里
218
- function readDshPatchEntries(home) {
232
+ // 外加打开它的凭据存储,写成一份覆盖文件带进去。密钥始终在 DSH 自己的存储里,不经过这里。
233
+ // model / effort 给了就把 agent-default-model 换成它们(模型清单和凭据还是桌面应用那份)
234
+ function readDshPatchEntries(home, { model = '', effort = '' } = {}) {
219
235
  const src = path.join(home, 'profiles', 'web', 'cordis.patch.yml');
220
236
  let text;
221
237
  try {
@@ -223,13 +239,77 @@ function readDshPatchEntries(home) {
223
239
  } catch {
224
240
  return { problem: `找不到 DSH 的配置 ${src}:dsh 预置要用桌面应用里配好的模型` };
225
241
  }
226
- const picked = text.split(/^(?=- id: )/m)
227
- .filter((block) => /^- id: (agent-default-model|llm-pi-ai)[ \t]*$/m.test(block))
228
- .map((block) => block.trimEnd());
229
- if (picked.length < 2) return { problem: `${src} 里没找齐 agent-default-model 和 llm-pi-ai 两条` };
230
- return { lines: ['# 值守自动生成,不要手改:让 DSH 的 headless 模式用桌面应用里配置的模型和凭据', '- id: credentials', ' disabled: false', ...picked] };
242
+ const blocks = text.split(/^(?=- id: )/m).filter((block) => /^- id: /.test(block)).map((block) => block.trimEnd());
243
+ const byId = {};
244
+ for (const block of blocks) byId[/^- id: (.*?)[ \t]*$/m.exec(block)[1]] = block;
245
+ if (!byId['agent-default-model'] || !byId['llm-pi-ai']) return { problem: `${src} 里没找齐 agent-default-model 和 llm-pi-ai 两条` };
246
+ let defaultBlock = byId['agent-default-model'];
247
+ if (model || effort) {
248
+ const current = dshDefaultModel(text);
249
+ if (current.problem) return current;
250
+ const provider = model.includes('/') ? model.split('/')[0] : (model ? dshProviderOf(text, model) : current.provider);
251
+ if (!provider) return { problem: `DSH 的配置里没有 ${model} 这个模型(可用 work-rhythm agent models dsh 列)` };
252
+ const picked = model && !model.includes('/') ? model : (model ? model.split('/').slice(1).join('/') : current.model);
253
+ const effortLine = effort && effort !== 'none' ? `\n reasoningEffort: ${effort}` : '';
254
+ defaultBlock = `- id: agent-default-model\n name: "@deepseek-ai/dsh-agent-default-model"\n config:\n provider: ${provider}\n model: ${picked}${effortLine}`;
255
+ }
256
+ return { lines: ['# 值守自动生成,不要手改:让 DSH 的 headless 模式用桌面应用里配置的模型和凭据', '- id: credentials', ' disabled: false', defaultBlock, byId['llm-pi-ai']] };
257
+ }
258
+
259
+ // 桌面应用配置里 agent-default-model 的 provider / model / reasoningEffort。配置是 YAML,用 lib/config 的解析器读
260
+ function dshConfig(text) {
261
+ const doc = parseYaml(text);
262
+ const entries = Array.isArray(doc) ? doc : [];
263
+ const pick = (id) => entries.find((e) => e && e.id === id);
264
+ return { defaultModel: pick('agent-default-model'), llm: pick('llm-pi-ai') };
265
+ }
266
+
267
+ function dshDefaultModel(text) {
268
+ const entry = dshConfig(text).defaultModel;
269
+ const cfg = entry && entry.config;
270
+ if (!cfg || !cfg.provider || !cfg.model) return { problem: 'DSH 的配置里 agent-default-model 没写 provider 或 model' };
271
+ return { provider: String(cfg.provider), model: String(cfg.model), effort: cfg.reasoningEffort ? String(cfg.reasoningEffort) : '' };
272
+ }
273
+
274
+ // DSH 配置里各 provider 的模型清单:[{ provider, id, name, reasoning }]。读的是 llm-pi-ai 那条的 providers
275
+ function dshModels(text) {
276
+ const llm = dshConfig(text).llm;
277
+ const providers = llm && llm.config && llm.config.providers && typeof llm.config.providers === 'object' ? llm.config.providers : {};
278
+ const out = [];
279
+ for (const [provider, p] of Object.entries(providers)) {
280
+ for (const m of (p && Array.isArray(p.models) ? p.models : [])) {
281
+ if (!m || !m.id) continue;
282
+ out.push({ provider, id: String(m.id), name: m.name ? String(m.name) : '', reasoning: Boolean(m.compat && m.compat.supportsReasoningEffort) });
283
+ }
284
+ }
285
+ return out;
231
286
  }
232
287
 
288
+ function dshProviderOf(text, modelId) {
289
+ return dshModels(text).find((m) => m.id === modelId)?.provider || '';
290
+ }
291
+
292
+ // 思考强度的词表(我们的叫法):各家换成自己的,zcode 没有入口
293
+ const EFFORTS = ['none', 'low', 'medium', 'high', 'max'];
294
+
295
+ // 一个预置能不能指定模型和思考强度:modelArgs(model, effort) 返回要加的参数(没有就返回空数组)
296
+ const MODEL_SUPPORT = {
297
+ zcode: { model: false, effort: false },
298
+ dsh: { model: true, effort: true, via: 'patch' },
299
+ qoder: {
300
+ model: true,
301
+ effort: true,
302
+ via: 'args',
303
+ args: (model, effort) => [...(model ? ['--model', model] : []), ...(effort && effort !== 'none' ? ['--reasoning-effort', effort] : [])],
304
+ },
305
+ claude: {
306
+ model: true,
307
+ effort: true,
308
+ via: 'args',
309
+ args: (model, effort) => [...(model ? ['--model', model] : []), ...(EFFORTS.includes(effort) && effort !== 'none' ? ['--effort', effort] : [])],
310
+ },
311
+ };
312
+
233
313
  // DSH 的 --json 是一行一个事件:session 给会话 ID,final 给回答和结束原因
234
314
  function parseDsh(stdout) {
235
315
  let final = null;
@@ -261,22 +341,29 @@ function parseDsh(stdout) {
261
341
  // timeoutS 一次运行最多等多少秒
262
342
  // preamble 随每句话带给 agent 的提示(可以为空)
263
343
  // log 记日志的函数 (event, fields)
344
+ // model 用哪个模型(各家的模型 id;空串用它自己的默认)
345
+ // effort 思考强度:none / low / medium / high / max(空串用它自己的默认)
264
346
  // 返回 { kind, run, doctor }:
265
347
  // run(message, { session, onSessionLost }) → { reply, sessionId } 或 { failed, config? }。
266
348
  // 给了 session 就接着它跑;接不上(过期、被删)时调 onSessionLost(),再开新会话跑一次
267
349
  // doctor() → 配置和依赖的问题,一条一个字符串;没有就是空数组
268
- function createAgent({ root, agent, mode = 'plan', timeoutS = 300, preamble = '', log = () => {}, env = process.env }) {
350
+ function createAgent({ root, agent, mode = 'plan', timeoutS = 300, preamble = '', log = () => {}, env = process.env, model = '', effort = '' }) {
269
351
  const name = String(agent || '').trim();
270
352
  const kind = presetKind(name);
353
+ model = String(model || '').trim();
354
+ effort = String(effort || '').trim();
271
355
 
272
356
  function doctor() {
357
+ if (model && kind !== 'custom' && !MODEL_SUPPORT[kind].model) return [`预置 ${kind} 不支持指定模型(${kind === 'zcode' ? 'ZCode 的命令行没有这个参数,用的是它自己的默认模型' : '见 docs/agents.md'}):把 collectors/local.env 里的 YZJ_BOT_MODEL 去掉,或者换一个支持的 agent`];
358
+ if (effort && kind !== 'custom' && !MODEL_SUPPORT[kind].effort) return [`预置 ${kind} 不支持指定思考强度:把 collectors/local.env 里的 YZJ_BOT_EFFORT 去掉`];
359
+ if (effort && kind !== 'custom' && !EFFORTS.includes(effort)) return [`思考强度写的是「${effort}」,只能是 ${EFFORTS.join(' / ')}`];
273
360
  if (!name) return [`没绑 agent:定时任务和机器人值守都要一个 agent 来跑。先 work-rhythm agent detect 看本机有哪些,再 work-rhythm agent bind <${PRESET_NAMES.join('|')}|命令>(写进 collectors/local.env 的 YZJ_BOT_AGENT)`];
274
361
  if (kind !== 'custom') {
275
362
  const found = PRESETS[kind].find(env);
276
363
  if (found.problem) return [found.problem];
277
- // dsh 还要用桌面应用里配好的模型
364
+ // dsh 还要用桌面应用里配好的模型;指定了模型的话要在它的清单里
278
365
  if (kind === 'dsh') {
279
- const entries = readDshPatchEntries(found.home);
366
+ const entries = readDshPatchEntries(found.home, { model, effort });
280
367
  if (entries.problem) return [entries.problem];
281
368
  }
282
369
  return [];
@@ -328,7 +415,7 @@ function createAgent({ root, agent, mode = 'plan', timeoutS = 300, preamble = ''
328
415
  const q = findQoder(env);
329
416
  if (q.problem) return q;
330
417
  const permission = PRESETS.qoder.modes[mode] || mode;
331
- const base = ['--cwd', root, '--permission-mode', permission];
418
+ const base = ['--cwd', root, '--permission-mode', permission, ...MODEL_SUPPORT.qoder.args(model, effort)];
332
419
  return {
333
420
  command: q.command,
334
421
  env,
@@ -342,7 +429,7 @@ function createAgent({ root, agent, mode = 'plan', timeoutS = 300, preamble = ''
342
429
  const c = findClaude(env);
343
430
  if (c.problem) return c;
344
431
  const permission = PRESETS.claude.modes[mode] || mode;
345
- const base = ['--cwd', root, '--permission-mode', permission];
432
+ const base = ['--cwd', root, '--permission-mode', permission, ...MODEL_SUPPORT.claude.args(model, effort)];
346
433
  return {
347
434
  command: c.command,
348
435
  env,
@@ -356,7 +443,7 @@ function createAgent({ root, agent, mode = 'plan', timeoutS = 300, preamble = ''
356
443
  function planDsh(prompt, stateDir) {
357
444
  const d = findDsh(env);
358
445
  if (d.problem) return d;
359
- const entries = readDshPatchEntries(d.home);
446
+ const entries = readDshPatchEntries(d.home, { model, effort });
360
447
  if (entries.problem) return entries;
361
448
  const patchFile = path.join(stateDir, 'dsh-headless.patch.yml');
362
449
  fs.mkdirSync(stateDir, { recursive: true });
@@ -399,11 +486,38 @@ function createAgent({ root, agent, mode = 'plan', timeoutS = 300, preamble = ''
399
486
  if (r.status !== 0) return { failed: `退出码 ${r.status}:${tail(r.stderr)}` };
400
487
  const out = plan.parse(r.stdout);
401
488
  if (out.failed) return out;
402
- log('agent 完成', `${secs()}s ${kind} mode=${mode} session=${used ? '续' : '新'}`);
489
+ log('agent 完成', `${secs()}s ${kind} mode=${mode}${model ? ` model=${model}` : ''}${effort ? ` effort=${effort}` : ''} session=${used ? '续' : '新'}`);
403
490
  return out.reply.trim() ? { reply: out.reply.trim(), sessionId: out.sessionId || '' } : { failed: '它回了空内容' };
404
491
  }
405
492
 
406
493
  return { kind, run, doctor };
407
494
  }
408
495
 
409
- module.exports = { createAgent, splitCommand, PRESETS, PRESET_NAMES, invokingAgent, installedAgents, bindAgent, findZcode, findDsh, findQoder, findClaude };
496
+ // 一个预置能选哪些模型:[{ provider, id, name, reasoning }]。dsh 读它的配置;qoder 问命令行(--list-models);claude 给常见的几个别名;
497
+ // zcode 不支持。返回 { models } 或 { problem }
498
+ function listModels(kind, env) {
499
+ if (!PRESETS[kind] || !MODEL_SUPPORT[kind].model) return { models: [] };
500
+ const found = PRESETS[kind].find(env);
501
+ if (found.problem) return { problem: found.problem };
502
+ if (kind === 'dsh') {
503
+ let text;
504
+ try {
505
+ text = fs.readFileSync(path.join(found.home, 'profiles', 'web', 'cordis.patch.yml'), 'utf8');
506
+ } catch {
507
+ return { problem: `找不到 DSH 的配置:${path.join(found.home, 'profiles', 'web', 'cordis.patch.yml')}` };
508
+ }
509
+ const current = dshDefaultModel(text);
510
+ return { models: dshModels(text), current: current.problem ? {} : current };
511
+ }
512
+ if (kind === 'qoder') {
513
+ const r = spawnSync(found.command, ['--list-models'], { encoding: 'utf8', env, timeout: 60000 });
514
+ if (r.status !== 0) return { problem: `qoder --list-models 没跑成:${tail(r.stderr || r.stdout, 200)}` };
515
+ return { text: r.stdout.trim() };
516
+ }
517
+ if (kind === 'claude') {
518
+ return { models: ['opus', 'sonnet', 'haiku'].map((id) => ({ id, name: id === 'opus' ? 'Opus(最强)' : id === 'sonnet' ? 'Sonnet(均衡)' : 'Haiku(最快)', reasoning: true })) };
519
+ }
520
+ return { models: [] };
521
+ }
522
+
523
+ module.exports = { createAgent, splitCommand, PRESETS, PRESET_NAMES, MODEL_SUPPORT, EFFORTS, invokingAgent, installedAgents, bindAgent, listModels, findZcode, findDsh, findQoder, findClaude };
@@ -163,7 +163,8 @@ function createBot({ root, env }) {
163
163
  // 收到就先回一句,agent 慢的时候我不用干等
164
164
  const ACK = env.YZJ_BOT_ACK !== '0';
165
165
  const PREAMBLE = env.YZJ_BOT_PREAMBLE !== undefined ? env.YZJ_BOT_PREAMBLE : DEFAULT_PREAMBLE;
166
- const agent = createAgent({ root, agent: AGENT, mode: AGENT_MODE, timeoutS: TIMEOUT_S, preamble: PREAMBLE, log, env });
166
+ // 模型和思考强度(collectors/local.env 的 YZJ_BOT_MODEL / YZJ_BOT_EFFORT),只有支持的预置才认;不写就用 agent 自己的默认
167
+ const agent = createAgent({ root, agent: AGENT, mode: AGENT_MODE, timeoutS: TIMEOUT_S, preamble: PREAMBLE, log, env, model: (env.YZJ_BOT_MODEL || '').trim(), effort: (env.YZJ_BOT_EFFORT || '').trim() });
167
168
 
168
169
  // ---------------------------------------------------------------- 配置
169
170
  // 检查值守的配置和依赖:有问题一条一个字符串;没问题就是空数组。check 配了值守时也调它
@@ -55,6 +55,9 @@ function loadConfig(root) {
55
55
  push: rhythm.push !== false,
56
56
  quiet: asList(rhythm.quiet),
57
57
  agentMode: typeof rhythm['agent-mode'] === 'string' && rhythm['agent-mode'].trim() ? rhythm['agent-mode'].trim() : 'edit',
58
+ // 定时任务用的模型和思考强度(可选项,profile 里不写也行):不配就和值守一样,用 local.env 的 YZJ_BOT_MODEL / YZJ_BOT_EFFORT
59
+ agentModel: typeof rhythm['agent-model'] === 'string' ? rhythm['agent-model'].trim() : '',
60
+ agentEffort: typeof rhythm['agent-effort'] === 'string' ? rhythm['agent-effort'].trim() : '',
58
61
  taskTimeout: positiveInt(rhythm['task-timeout'], 1200),
59
62
  syncTimeout: positiveInt(rhythm['sync-timeout'], 600),
60
63
  notifyChannel: typeof preferences.notify === 'string' ? preferences.notify.trim() : '',
@@ -221,7 +224,7 @@ function createRhythm({ root, env, packageRoot }) {
221
224
  const willPush = wantPush && cfg.push && !cfg.quiet.includes(id);
222
225
  // 服务会替它推送时在指令末尾注明,免得它自己再发一遍
223
226
  const full = willPush ? `${prompt}\n\n(这次运行由 work-rhythm rhythm 发起:你最后写的那段总结会被它推送给用户,你自己不要再发。)` : prompt;
224
- const agent = createAgent({ root, agent: env.YZJ_BOT_AGENT, mode: cfg.agentMode, timeoutS: cfg.taskTimeout, log, env });
227
+ const agent = makeAgent();
225
228
  const t0 = Date.now();
226
229
  const r = agent.run(full, { stateDir: STATE_DIR });
227
230
  const seconds = Math.round((Date.now() - t0) / 1000);
@@ -254,6 +257,11 @@ function createRhythm({ root, env, packageRoot }) {
254
257
  return r.ok ? EXIT.OK : EXIT.FAILED;
255
258
  }
256
259
 
260
+ // 跑任务的 agent:绑定的那个(YZJ_BOT_AGENT),模型和强度先看 profile 的 rhythm.agent-model / agent-effort,没配再看 local.env
261
+ function makeAgent() {
262
+ return createAgent({ root, agent: env.YZJ_BOT_AGENT, mode: cfg.agentMode, timeoutS: cfg.taskTimeout, log, env, model: cfg.agentModel || (env.YZJ_BOT_MODEL || '').trim(), effort: cfg.agentEffort || (env.YZJ_BOT_EFFORT || '').trim() });
263
+ }
264
+
257
265
  // 调度器用它:任务另起一个子进程跑(带着 --push),不堵住计时
258
266
  function startJob(job) {
259
267
  fs.mkdirSync(STATE_DIR, { recursive: true });
@@ -379,7 +387,7 @@ function createRhythm({ root, env, packageRoot }) {
379
387
  if (!(cfg.port >= 1024 && cfg.port <= 65535)) problems.push(`rhythm.port 要是 1024 到 65535 之间的整数(现在是 ${cfg.port})`);
380
388
  // 只有真有任务要跑时,agent 和推送才必须配好;只采集、只看页面的用不着
381
389
  if (jobs().some((job) => job.kind === 'task' && job.hasPrompt)) {
382
- problems.push(...createAgent({ root, agent: env.YZJ_BOT_AGENT, mode: cfg.agentMode, env }).doctor());
390
+ problems.push(...makeAgent().doctor());
383
391
  if (cfg.push && !cfg.notifyChannel) problems.push('rhythm.push 开着,但 preferences.notify 没配消息渠道:要么配一个,要么把 push 写成 false');
384
392
  }
385
393
  return problems;
@@ -89,7 +89,7 @@ test('agent bind:不给名字就绑正在调的这个;没标记就绑装了
89
89
  assert.equal(exists(`${s.box.work}/collectors/local.env`), false);
90
90
  const r = s.run(['agent', 'bind'], { ...env, DSH_SESSION_ID: 'sess-1' });
91
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/);
92
+ assert.match(r.stdout, /已绑定 dsh(DSH(DeepSeek Harness)的 headless 模式),写进了 collectors\/local\.env 的 YZJ_BOT_AGENT。\n 模型用它自己的默认,思考强度用它自己的默认\n 模型和思考强度还没配:work-rhythm agent models dsh 看能用哪些[\s\S]*\n下一步:work-rhythm agent test/);
93
93
  // local.env 原来没有:从样例复制一份,再把样例里注释掉的那行换成真的
94
94
  const text = read(`${s.box.work}/collectors/local.env`);
95
95
  assert.match(text, /^YZJ_BOT_AGENT="dsh"$/m);
@@ -106,7 +106,8 @@ test('agent bind:不给名字就绑正在调的这个;没标记就绑装了
106
106
  assert.equal(s.run(['agent', 'bind', custom], env).code, 0);
107
107
  assert.match(read(`${s.box.work}/collectors/local.env`), /^YZJ_BOT_AGENT='.*\/fake-agent --flag'$/m);
108
108
  const shown = s.run(['agent'], env);
109
- assert.match(shown.stdout, /现在绑定的:.*\/fake-agent --flag(一条自定义命令,zcode\/dsh\/qoder\/claude 以外)/);
109
+ assert.match(shown.stdout, /现在绑定的:.*\/fake-agent --flag(一条自定义命令)\n/);
110
+ assert.equal(shown.stdout.includes('模型用它自己的默认'), false, '自定义命令不谈模型和强度');
110
111
  assert.equal(shown.stdout.includes('建议:'), false, '绑了就不再建议');
111
112
  });
112
113
 
@@ -136,13 +137,13 @@ test('agent test:让绑定的 agent 只读答一句;没绑就退出码 3', (
136
137
  assert.equal(s.run(['agent', 'bind', 'qoder'], env).code, 0);
137
138
  const r = s.run(['agent', 'test', '今天周几'], env);
138
139
  assert.equal(r.code, 0, r.out);
139
- assert.match(r.stdout, /^回复:今天周几\n(qoder,只读模式,用时 \d+ 秒)\n$/);
140
+ assert.match(r.stdout, /^回复:今天周几\n(qoder;只读模式,用时 \d+ 秒)\n$/);
140
141
  // Qoder 的参数:工作目录、只读模式、JSON 输出、--print 后面跟这句话
141
142
  const args = read(s.stubs.STUB_QODER_ARGS);
142
143
  assert.equal(args, `--cwd ${fs.realpathSync(s.box.work)} --permission-mode plan --output-format json --print 今天周几\n`);
143
144
  // 默认那句话
144
145
  s.run(['agent', 'test'], env);
145
- assert.match(read(s.stubs.STUB_QODER_ARGS), /--print 你好,用一句话介绍你自己,并说出你用的是哪个模型。$/m);
146
+ assert.match(read(s.stubs.STUB_QODER_ARGS), /--print 你好。请只用两句话回答:1)你是哪个模型?说模型名。2)1\+1 等于几?$/m);
146
147
  assert.equal(s.run(['agent', 'test', 'a', 'b'], env).code, 2);
147
148
  });
148
149
 
@@ -172,7 +173,7 @@ test('claude 预置:在 PATH 上找到 claude,参数是 Claude Code 那一
172
173
  s.run(['agent', 'bind', 'claude'], s.bindEnv());
173
174
  const r = s.run(['agent', 'test', '在吗'], s.bindEnv());
174
175
  assert.equal(r.code, 0, r.out);
175
- assert.equal(r.stdout, '回复:在吗\n(claude,只读模式,用时 0 秒)\n');
176
+ assert.equal(r.stdout, '回复:在吗\n(claude;只读模式,用时 0 秒)\n');
176
177
  assert.equal(read(s.stubs.STUB_CLAUDE_ARGS).trim(), `--cwd ${fs.realpathSync(s.box.work)} --permission-mode plan --output-format json -p 在吗`);
177
178
  });
178
179
 
@@ -199,3 +200,126 @@ test('installedAgents:本机真有什么就报什么,不编造', () => {
199
200
  assert.deepEqual(list.map((a) => a.name), ['zcode', 'dsh', 'qoder', 'claude']);
200
201
  for (const a of list) assert.equal(typeof a.found, 'boolean');
201
202
  });
203
+
204
+ // ---------------------------------------------------------------- 模型和思考强度
205
+ const patchOf = (box) => read(`${box.work}/01-inbox/_bot/dsh-headless.patch.yml`);
206
+
207
+ test('agent bind --model --effort:写进 local.env;dsh 把它写进自动生成的覆盖文件,agent 真的按它跑', (t) => {
208
+ const s = setup(t);
209
+ const env = s.bindEnv();
210
+ const r = s.run(['agent', 'bind', 'dsh', '--model', 'opencode-go/glm-5.3-flash', '--effort', 'high'], env);
211
+ assert.equal(r.code, 0, r.out);
212
+ assert.match(r.stdout, /模型 opencode-go\/glm-5\.3-flash,思考强度 high/);
213
+ const local = read(`${s.box.work}/collectors/local.env`);
214
+ assert.match(local, /^YZJ_BOT_AGENT="dsh"$/m);
215
+ assert.match(local, /^YZJ_BOT_MODEL="opencode-go\/glm-5\.3-flash"$/m);
216
+ assert.match(local, /^YZJ_BOT_EFFORT="high"$/m);
217
+ // 样例里注释掉的那两行被换成真的,不留重复
218
+ assert.equal(local.split('\n').filter((l) => /^#?\s*YZJ_BOT_MODEL=/.test(l)).length, 1);
219
+ // 真跑一次(listen handle 要渠道和 openId):覆盖文件里 agent-default-model 换了,llm-pi-ai 原样带着(凭据在它那)
220
+ write(`${s.box.work}/00-config/profile.yaml`, read(`${s.box.work}/00-config/profile.yaml`).replace('notify: ""', 'notify: "yzj-robot"'));
221
+ const h = s.run(['listen', 'handle', '在吗'], { ...env, YZJ_MY_OPEN_ID: 'me-0001', YZJ_BOT_PREAMBLE: '' });
222
+ assert.equal(h.code, 0, h.out);
223
+ const patch = patchOf(s.box);
224
+ assert.match(patch, /- id: agent-default-model\n name: "@deepseek-ai\/dsh-agent-default-model"\n config:\n provider: opencode-go\n model: glm-5\.3-flash\n reasoningEffort: high\n/);
225
+ assert.match(patch, /- id: llm-pi-ai\n/);
226
+ assert.match(h.stderr, /agent 完成 \d+s dsh mode=plan model=opencode-go\/glm-5\.3-flash effort=high/);
227
+ // 只写模型 id 不写 provider:到它的清单里找;找不到就拒
228
+ assert.equal(s.run(['agent', 'model', 'no-such-model'], env).code, 3);
229
+ assert.match(s.run(['agent', 'model', 'no-such-model'], env).stderr, /DSH 的配置里没有 no-such-model 这个模型/);
230
+ const byId = s.run(['agent', 'model', 'deepseek-v4.1-flash'], env);
231
+ assert.equal(byId.code, 0, byId.out);
232
+ s.run(['listen', 'handle', '在吗'], { ...env, YZJ_MY_OPEN_ID: 'me-0001', YZJ_BOT_PREAMBLE: '' });
233
+ assert.match(patchOf(s.box), / provider: opencode-go\n model: deepseek-v4\.1-flash\n reasoningEffort: high\n/);
234
+ // effort none:覆盖文件里不写 reasoningEffort
235
+ s.run(['agent', 'effort', 'none'], env);
236
+ s.run(['listen', 'handle', '在吗'], { ...env, YZJ_MY_OPEN_ID: 'me-0001', YZJ_BOT_PREAMBLE: '' });
237
+ const none = patchOf(s.box);
238
+ assert.match(none, / model: deepseek-v4\.1-flash\n- id: llm-pi-ai/);
239
+ assert.ok(!none.includes('reasoningEffort'), 'effort none 时不写 reasoningEffort');
240
+ });
241
+
242
+ test('agent model / effort:只改那一项,别的不动;--clear 清掉;强度不在词表里退出码 2;没绑时退出码 3', (t) => {
243
+ const s = setup(t);
244
+ const env = s.bindEnv();
245
+ assert.equal(s.run(['agent', 'effort', 'low'], env).code, 3);
246
+ s.run(['agent', 'bind', 'qoder'], env);
247
+ const r = s.run(['agent', 'effort', 'max'], env);
248
+ assert.equal(r.code, 0, r.out);
249
+ assert.match(r.stdout, /思考强度已设为 max,写进了 collectors\/local\.env。\n 模型用它自己的默认,思考强度 max\n/);
250
+ assert.equal(s.run(['agent', 'effort', 'xhigh'], env).code, 2);
251
+ assert.match(s.run(['agent', 'effort', 'xhigh'], env).stderr, /思考强度写的是「xhigh」,只能是 none \/ low \/ medium \/ high \/ max/);
252
+ s.run(['agent', 'model', 'performance'], env);
253
+ const local = read(`${s.box.work}/collectors/local.env`);
254
+ assert.match(local, /^YZJ_BOT_AGENT="qoder"$/m);
255
+ assert.match(local, /^YZJ_BOT_MODEL="performance"$/m);
256
+ assert.match(local, /^YZJ_BOT_EFFORT="max"$/m);
257
+ // qoder / claude 的参数:--model 和 --reasoning-effort / --effort;effort none 不传
258
+ const test = s.run(['agent', 'test', '在吗'], env);
259
+ assert.equal(test.code, 0, test.out);
260
+ assert.match(test.stdout, /(qoder,配置的模型 performance,思考强度 max;只读模式/);
261
+ assert.ok(read(s.stubs.STUB_QODER_ARGS).trim().startsWith(`--cwd ${fs.realpathSync(s.box.work)} --permission-mode plan --model performance --reasoning-effort max --output-format json --print 在吗`), read(s.stubs.STUB_QODER_ARGS));
262
+ s.run(['agent', 'bind', 'claude'], env);
263
+ s.run(['agent', 'model', 'opus'], env);
264
+ s.run(['agent', 'effort', 'none'], env);
265
+ s.run(['agent', 'test', '在吗'], env);
266
+ assert.equal(read(s.stubs.STUB_CLAUDE_ARGS).trim(), `--cwd ${fs.realpathSync(s.box.work)} --permission-mode plan --model opus --output-format json -p 在吗`);
267
+ // 清掉
268
+ const clear = s.run(['agent', 'model', '--clear'], env);
269
+ assert.match(clear.stdout, /模型已清掉,用 claude 自己的默认。\n 模型用它自己的默认,思考强度 none\n/);
270
+ assert.match(read(`${s.box.work}/collectors/local.env`), /^YZJ_BOT_MODEL=""$/m);
271
+ s.run(['agent', 'effort', '--clear'], env);
272
+ assert.equal(s.run(['agent', 'doctor'], env).code, 0);
273
+ });
274
+
275
+ test('zcode 不支持指定模型和强度:绑的时候带上就拒绝,单独设也拒绝,都说清原因', (t) => {
276
+ const s = setup(t);
277
+ const env = s.bindEnv();
278
+ const r = s.run(['agent', 'bind', 'zcode', '--model', 'glm-5.3'], env);
279
+ assert.equal(r.code, 3);
280
+ assert.match(r.stderr, /绑不了 zcode:预置 zcode 不支持指定模型(ZCode 的命令行没有这个参数,用的是它自己的默认模型)/);
281
+ assert.equal(exists(`${s.box.work}/collectors/local.env`), false);
282
+ s.run(['agent', 'bind', 'zcode'], env);
283
+ const m = s.run(['agent', 'effort', 'high'], env);
284
+ assert.equal(m.code, 3);
285
+ assert.match(m.stderr, /zcode 不支持指定思考强度/);
286
+ assert.match(s.run(['agent', 'models', 'zcode'], env).stderr, /zcode 不支持指定模型/);
287
+ assert.match(s.run(['agent'], env).stdout, / zcode +装了[\s\S]*?模型和思考强度:不能配,用它自己的默认/);
288
+ });
289
+
290
+ test('agent models:dsh 从它的配置里列模型,标出当前默认和支持思考强度的;qoder 把 --list-models 的输出带出来', (t) => {
291
+ const s = setup(t);
292
+ const env = s.bindEnv();
293
+ const r = s.run(['agent', 'models', 'dsh'], env);
294
+ assert.equal(r.code, 0, r.out);
295
+ assert.equal(r.stdout, [
296
+ 'dsh 能用的模型:',
297
+ ' opencode-go/deepseek-v4.1-flash DeepSeek V4.1 Flash 当前默认',
298
+ ' opencode-go/glm-5.3-flash GLM-5.3-Flash 支持思考强度',
299
+ '',
300
+ ].join('\n'));
301
+ assert.equal(s.run(['agent', 'models'], env).code, 3, '没绑的时候不给名字就报');
302
+ s.run(['agent', 'bind', 'qoder'], env);
303
+ // 假的 qoder 不认 --list-models,会把最后一个参数回出来——列模型这条路在这里只验「调了它、把输出带出来」
304
+ const q = s.run(['agent', 'models'], env);
305
+ assert.equal(q.code, 0, q.out);
306
+ assert.match(q.stdout, /--list-models/);
307
+ assert.equal(s.run(['agent', 'models', 'a', 'b'], env).code, 2);
308
+ });
309
+
310
+ test('agent --json:带模型、强度,以及这个 agent 支不支持', (t) => {
311
+ const s = setup(t);
312
+ s.run(['agent', 'bind', 'dsh', '--effort', 'low'], s.bindEnv());
313
+ const doc = JSON.parse(s.run(['agent', '--json'], s.bindEnv()).stdout);
314
+ assert.equal(doc.bound, 'dsh');
315
+ assert.equal(doc.model, '');
316
+ assert.equal(doc.effort, 'low');
317
+ assert.equal(doc.modelSupported, true);
318
+ assert.equal(doc.effortSupported, true);
319
+ const zcode = doc.agents.find((a) => a.name === 'zcode');
320
+ assert.equal(zcode.found, true);
321
+ assert.equal(typeof zcode.command, 'string');
322
+ assert.equal(zcode.modelSupported, false);
323
+ assert.equal(zcode.effortSupported, false);
324
+ assert.equal(doc.agents.find((a) => a.name === 'dsh').modelSupported, true);
325
+ });
@@ -133,6 +133,14 @@ function makeSandbox(t) {
133
133
  ' providers:',
134
134
  ' opencode-go:',
135
135
  ' apiKeyEnv: OPENCODE_GO_API_KEY',
136
+ ' models:',
137
+ ' - id: deepseek-v4.1-flash',
138
+ ' name: DeepSeek V4.1 Flash',
139
+ ' - id: glm-5.3-flash',
140
+ ' name: GLM-5.3-Flash',
141
+ ' compat:',
142
+ ' supportsReasoningEffort: true',
143
+ ' thinkingFormat: zai',
136
144
  '',
137
145
  ].join('\n'));
138
146
  const file = (name) => path.join(root, name);
@@ -41,7 +41,7 @@ test('init:用包里的模板建出工作目录并登记;不 git init,不
41
41
  assert.equal(read(cfg), `workdir: ${real}\n`);
42
42
  });
43
43
 
44
- test('init:相对路径按当前目录算,上级目录没有就一起建;目录已经存在、参数不对时退出码为 2', (t) => {
44
+ test('init:相对路径按当前目录算,上级目录没有就一起建;目录已存在且非空、参数不对时退出码为 2', (t) => {
45
45
  const box = makeSandbox(t);
46
46
  const cfg = path.join(box.root, 'wr-config.yaml');
47
47
  const env = { WORK_RHYTHM_CONFIG: cfg };
@@ -53,11 +53,49 @@ test('init:相对路径按当前目录算,上级目录没有就一起建;
53
53
  assert.ok(exists(path.join(box.root, 'no', 'such', 'dir', 'x', '00-config', 'profile.yaml')));
54
54
  const again = rawRun(['init', path.join(box.root, 'my-work')], { cwd: box.root, env });
55
55
  assert.equal(again.code, 2);
56
- assert.match(again.stderr, /已经存在。拿它当工作目录用 work-rhythm workdir register;要新建就换个位置/);
56
+ assert.match(again.stderr, /已经存在而且不是空的(\d+ 项,比如 [^)]+),不动它。它要是本来就是工作目录,用 work-rhythm workdir register;要新建就换个位置/);
57
57
  assert.equal(rawRun(['init'], { cwd: box.root, env }).code, 2);
58
58
  assert.equal(rawRun(['init', 'a', 'b'], { cwd: box.root, env }).code, 2);
59
59
  });
60
60
 
61
+ test('init:目录已经存在但是空的,直接铺进去;只有 .DS_Store 也算空;非空的和一个普通文件都拒绝,什么都不动', (t) => {
62
+ const box = makeSandbox(t);
63
+ const cfg = path.join(box.root, 'wr-config.yaml');
64
+ const env = { WORK_RHYTHM_CONFIG: cfg };
65
+ const empty = path.join(box.root, 'home', 'empty');
66
+ fs.mkdirSync(empty, { recursive: true }); // 用户先 mkdir 了
67
+ const r = rawRun(['init', empty], { cwd: box.root, env });
68
+ assert.equal(r.code, 0, r.out);
69
+ assert.equal(r.stdout, `WORKDIR=${fs.realpathSync(empty)}\n`);
70
+ for (const f of ['00-config/profile.yaml', 'AGENTS.md', 'docs/formats.md']) assert.ok(exists(path.join(empty, f)), `缺 ${f}`);
71
+ assert.equal(read(cfg), `workdir: ${fs.realpathSync(empty)}\n`);
72
+ // Finder 建过 .DS_Store 的空目录
73
+ const finder = path.join(box.root, 'home', 'finder');
74
+ fs.mkdirSync(finder, { recursive: true });
75
+ write(path.join(finder, '.DS_Store'), '\0\0\0');
76
+ assert.equal(rawRun(['init', finder], { cwd: box.root, env }).code, 0);
77
+ assert.ok(exists(path.join(finder, '.DS_Store')), '人家的 .DS_Store 留着');
78
+ // 非空:拒绝,里面的东西一样不动
79
+ const used = path.join(box.root, 'home', 'used');
80
+ write(path.join(used, 'notes', 'a.md'), '我的东西');
81
+ const refused = rawRun(['init', used], { cwd: box.root, env });
82
+ assert.equal(refused.code, 2);
83
+ assert.match(refused.stderr, /已经存在而且不是空的(1 项,比如 notes),不动它/);
84
+ assert.equal(exists(path.join(used, 'notes', 'a.md')), true);
85
+ assert.equal(exists(path.join(used, '00-config')), false);
86
+ // 是个普通文件:也拒绝
87
+ const file = path.join(box.root, 'home', 'a-file');
88
+ write(file, 'x');
89
+ const notDir = rawRun(['init', file], { cwd: box.root, env });
90
+ assert.equal(notDir.code, 2);
91
+ assert.match(notDir.stderr, /已经存在,而且不是目录/);
92
+ assert.equal(read(file), 'x');
93
+ // 隐藏文件不算空:只有 .DS_Store 放行
94
+ const hidden = path.join(box.root, 'home', 'hidden');
95
+ write(path.join(hidden, '.gitkeep'), '');
96
+ assert.equal(rawRun(['init', hidden], { cwd: box.root, env }).code, 2);
97
+ });
98
+
61
99
  test('init:建出来的工作目录里 work-rhythm 的命令都能用:check、today、sync', (t) => {
62
100
  const box = makeSandbox(t);
63
101
  const cfg = path.join(box.root, 'wr-config.yaml');
@@ -331,3 +331,24 @@ test('rhythm:不认识的子命令退出码为 2,--help 列出全部', (t) =
331
331
  assert.match(r.stdout, /用法: work-rhythm rhythm <子命令>/);
332
332
  for (const cmd of ['start', 'stop', 'status', 'due', 'run', 'serve', 'render', 'doctor', 'install', 'uninstall']) assert.match(r.stdout, new RegExp(`(?:\\n | \\| )${cmd}[ |\\[]`), `用法里没有 ${cmd}`);
333
333
  });
334
+
335
+ test('rhythm:profile 的 agent-model / agent-effort 给定时任务另配一套,写进 dsh 的覆盖文件;没配就沿用 local.env 的', async (t) => {
336
+ const hook = await webhook(t);
337
+ const s = setup(t);
338
+ const env = { ...s.env, STUB_ROBOT_URL: hook.url };
339
+ write(`${s.box.work}/collectors/local.env`, 'YZJ_BOT_AGENT="dsh"\n');
340
+ // agent-model / agent-effort 是可选键,模板里没有:补在 rhythm: 一节的 quiet 后面
341
+ const profile = `${s.box.work}/00-config/profile.yaml`;
342
+ const addRhythm = (lines) => write(profile, read(profile).replace(/^( quiet:.*)$/m, `$1\n${lines.join('\n')}`));
343
+ addRhythm([' agent-model: "opencode-go/glm-5.3-flash"', ' agent-effort: "low"']);
344
+ assert.equal(s.rhythm(['doctor'], env).code, 0, s.rhythm(['doctor'], env).out);
345
+ const r = s.rhythm(['run', 'daily-plan'], env);
346
+ assert.equal(r.code, 0, r.out);
347
+ const patch = read(`${s.box.work}/01-inbox/_rhythm/dsh-headless.patch.yml`);
348
+ assert.match(patch, / provider: opencode-go\n model: glm-5\.3-flash\n reasoningEffort: low\n/);
349
+ // 没配的时候沿用 local.env 的 YZJ_BOT_MODEL / YZJ_BOT_EFFORT
350
+ write(profile, read(profile).replace(/^ agent-(model|effort):.*\n/gm, ''));
351
+ write(`${s.box.work}/collectors/local.env`, 'YZJ_BOT_AGENT="dsh"\nYZJ_BOT_MODEL="opencode-go/deepseek-v4.1-flash"\nYZJ_BOT_EFFORT="high"\n');
352
+ assert.equal(s.rhythm(['run', 'daily-plan'], env).code, 0);
353
+ assert.match(read(`${s.box.work}/01-inbox/_rhythm/dsh-headless.patch.yml`), / model: deepseek-v4\.1-flash\n reasoningEffort: high\n/);
354
+ });