work-rhythm 0.2.21 → 0.2.22

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.
Files changed (68) hide show
  1. package/.agents/notes/AGENTS.md +10 -3
  2. package/.agents/notes/decisions/2026-11-30-bot-inbound-uses-websocket-and-a-responder-command.md +1 -0
  3. package/.agents/notes/decisions/2026-11-30-skill-ships-with-its-template-in-a-zip.md +1 -0
  4. package/.agents/notes/decisions/2026-12-01-agent-binding-asks-for-model-and-effort.md +1 -0
  5. package/.agents/notes/decisions/2026-12-01-interjections-batch-into-one-answer-and-interrupt-reruns.md +1 -0
  6. package/.agents/notes/decisions/2026-12-01-router-and-worker-pass-content-in-handoff-docs.md +1 -0
  7. package/.agents/notes/decisions/2026-12-01-router-runs-on-a-flash-model-with-low-effort.md +1 -0
  8. package/.agents/notes/decisions/2026-12-03-codex-cli-joins-as-a-preset-verified-against-its-own-binary.md +45 -0
  9. package/.agents/notes/decisions/2026-12-03-fewer-scheduled-tasks-silent-refine-no-question-cards.md +1 -0
  10. package/.agents/notes/decisions/2026-12-03-playbook-distills-handoffs-into-ws-tool-and-skill-know-how.md +43 -0
  11. package/.agents/notes/decisions/2026-12-03-related-work-comes-back-as-one-reply.md +49 -0
  12. package/.agents/notes/decisions/2026-12-03-roster-of-worker-groups-router-picks-the-group.md +33 -0
  13. package/.agents/notes/decisions/2026-12-03-router-model-and-effort-are-configurable.md +28 -0
  14. package/.agents/notes/decisions/2026-12-03-router-only-direct-mode-removed.md +27 -0
  15. package/.agents/notes/decisions/2026-12-03-unattended-runs-decide-on-their-own.md +32 -0
  16. package/.agents/notes/decisions/2026-12-03-update-upgrades-package-and-refreshes-shipped-files.md +30 -0
  17. package/.agents/notes/decisions/2026-12-03-workers-leave-a-status-trail-that-joins-the-receipt.md +31 -0
  18. package/.agents/notes/pitfalls/2026-12-01-replace-string-dollar-quote-expands.md +2 -0
  19. package/.agents/notes/pitfalls/2026-12-03-judging-a-symlink-by-realpath-ignores-parent-links.md +18 -0
  20. package/.agents/skills/work-rhythm/SKILL.md +20 -16
  21. package/README.md +13 -10
  22. package/collectors/local.env.example +31 -36
  23. package/docs/agents.md +61 -60
  24. package/docs/channels.md +15 -19
  25. package/docs/formats.md +27 -0
  26. package/docs/router-worker.md +60 -41
  27. package/docs/scheduled-tasks.md +9 -9
  28. package/package.json +1 -1
  29. package/scripts/cli.js +9 -5
  30. package/scripts/cmd/agent.js +348 -235
  31. package/scripts/cmd/check.js +14 -7
  32. package/scripts/cmd/listen.js +33 -32
  33. package/scripts/cmd/pack.js +6 -6
  34. package/scripts/cmd/rhythm.js +13 -10
  35. package/scripts/cmd/trigger.js +23 -14
  36. package/scripts/cmd/update.js +92 -0
  37. package/scripts/lib/agent.js +235 -142
  38. package/scripts/lib/agents.js +179 -0
  39. package/scripts/lib/bot.js +44 -263
  40. package/scripts/lib/engine.js +327 -110
  41. package/scripts/lib/handoff.js +54 -8
  42. package/scripts/lib/markdown.js +19 -0
  43. package/scripts/lib/playbook.js +123 -0
  44. package/scripts/lib/rhythm.js +405 -170
  45. package/scripts/lib/router.js +45 -29
  46. package/scripts/lib/template.js +3 -3
  47. package/scripts/lib/update.js +279 -0
  48. package/scripts/lib/worker.js +11 -5
  49. package/scripts/test/agent.test.js +410 -257
  50. package/scripts/test/check.test.js +17 -6
  51. package/scripts/test/harness.js +5 -2
  52. package/scripts/test/listen.test.js +190 -158
  53. package/scripts/test/playbook.test.js +106 -0
  54. package/scripts/test/rhythm.test.js +164 -54
  55. package/scripts/test/roster.test.js +155 -0
  56. package/scripts/test/router-helper.js +17 -2
  57. package/scripts/test/router.test.js +468 -194
  58. package/scripts/test/stubs.js +51 -4
  59. package/scripts/test/timeout.test.js +160 -59
  60. package/scripts/test/update.test.js +384 -0
  61. package/tasks/daily-persona.md +30 -11
  62. package/tasks/daily-plan.md +2 -1
  63. package/tasks/noon-checkin.md +2 -1
  64. package/templates/00-config/profile.example.yaml +9 -6
  65. package/templates/04-patterns/PERSONA.md +4 -1
  66. package/templates/04-patterns/PLAYBOOK.md +13 -0
  67. package/templates/AGENTS.md +6 -2
  68. package/templates/README.md +10 -9
@@ -0,0 +1,106 @@
1
+ 'use strict';
2
+ const { test } = require('node:test');
3
+ const assert = require('node:assert/strict');
4
+ const fs = require('node:fs');
5
+ const os = require('node:os');
6
+ const path = require('node:path');
7
+ const pb = require('../lib/playbook');
8
+
9
+ // 一份带三条经验的现场手册:表头是模板里的写法,格子里有转义的竖线、有空的格子
10
+ function workdir(t, body) {
11
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'wrj-pb-'));
12
+ t.after(() => fs.rmSync(root, { recursive: true, force: true }));
13
+ fs.mkdirSync(path.join(root, '04-patterns'));
14
+ if (body !== undefined) fs.writeFileSync(path.join(root, '04-patterns', 'PLAYBOOK.md'), body);
15
+ return root;
16
+ }
17
+ const SAMPLE = `# 现场手册
18
+
19
+ > 由 daily-persona 每晚静默沉淀。
20
+
21
+ ## 按触发查
22
+
23
+ | 触发(什么样的活) | 工作区 | 工具 / skill | 怎么做 | 坑 | 证据 | 更新 |
24
+ |------|------|------|------|------|------|------|
25
+ | 查会议纪要的耗时/trace | minutes | kwork-langfuse | cd 进 skill 目录跑 session_history.py <sessionId> | 查到的是 langfuse-dev,不是 ops 生产 | t-000164 | 2026-12-03 |
26
+ | 导出接口联调 | report-service | yzj-cli \\| linky-cli | 先看 Linky 快照 | 群消息有延迟 | t-000140 | 2026-11-30 |
27
+ | 查告警跟进 | | alerts-morning | 读 01-inbox/reports/ 最近一份 | | t-000150 | 2026-12-01 |
28
+
29
+ ## 按来源归纳(订阅源 → 常派出去的活)
30
+
31
+ | 来源 | 常见的事 | 派给谁 / 哪个 ws | 备注 |
32
+ |------|------|------|------|
33
+ | im-yzj | 跟进群里的讨论 | 工作目录 | 不记原文 |
34
+ `;
35
+
36
+ test('现场手册:把「按触发查」那张表读成条目;表头按开头对、转义的竖线算一个格子、空格子留空', (t) => {
37
+ const root = workdir(t, SAMPLE);
38
+ const list = pb.entries(root);
39
+ assert.equal(list.length, 3);
40
+ assert.deepEqual(list[0], {
41
+ trigger: '查会议纪要的耗时/trace', ws: 'minutes', tool: 'kwork-langfuse',
42
+ how: 'cd 进 skill 目录跑 session_history.py <sessionId>', pit: '查到的是 langfuse-dev,不是 ops 生产', evidence: 't-000164', updated: '2026-12-03',
43
+ });
44
+ assert.equal(list[1].tool, 'yzj-cli | linky-cli', '转义的竖线还原成一个字符');
45
+ assert.deepEqual([list[2].ws, list[2].pit], ['', '']);
46
+ });
47
+
48
+ test('现场手册:文件没有、还是空模板时什么都不报,清单和匹配都是空', (t) => {
49
+ const none = workdir(t);
50
+ assert.deepEqual(pb.entries(none), []);
51
+ assert.deepEqual(pb.summary(none), []);
52
+ assert.equal(pb.section(none, '查 trace'), '');
53
+ const empty = workdir(t, '# 现场手册\n\n## 按触发查\n\n| 触发(什么样的活) | 工作区 | 工具 / skill | 怎么做 | 坑 | 证据 | 更新 |\n|------|------|------|------|------|------|------|\n');
54
+ assert.deepEqual(pb.entries(empty), []);
55
+ });
56
+
57
+ test('现场手册:给路由的清单按更新时间新的在前,一行一条带上工作区和工具,最多 40 条', (t) => {
58
+ const root = workdir(t, SAMPLE);
59
+ const rows = pb.summary(root);
60
+ assert.deepEqual(rows, [
61
+ '- 查会议纪要的耗时/trace → minutes · kwork-langfuse:cd 进 skill 目录跑 session_history.py <sessionId>',
62
+ '- 查告警跟进 → 工作目录 · alerts-morning:读 01-inbox/reports/ 最近一份',
63
+ '- 导出接口联调 → report-service · yzj-cli | linky-cli:先看 Linky 快照',
64
+ ]);
65
+ // 41 条时只带 40 条
66
+ const many = ['## 按触发查', '', '| 触发 | 工作区 | 工具 | 怎么做 | 坑 | 证据 | 更新 |', '|---|---|---|---|---|---|---|'];
67
+ for (let i = 1; i <= 41; i += 1) many.push(`| 活 ${i} | ws${i} | tool${i} | | | t-${i} | 2026-11-${String(i).padStart(2, '0')} |`);
68
+ assert.equal(pb.summary(workdir(t, many.join('\n'))).length, 40);
69
+ });
70
+
71
+ test('现场手册:按原话匹配条目附进任务书——匹配得越多的越靠前,最多 5 条;无关的话一条不附;太长的做法截到 600 字', (t) => {
72
+ const root = workdir(t, SAMPLE);
73
+ // 「纪要」「trace」都在第一条的触发里
74
+ const s1 = pb.section(root, '帮我查一下昨天那份会议纪要的 trace 为什么这么慢');
75
+ assert.match(s1, /^## 现场手册(以前做同类活留下的经验,照它少走弯路)\n\n### 查会议纪要的耗时\/trace\n\n- 工作区:minutes\n- 工具 \/ skill:kwork-langfuse\n- 怎么做:cd 进 skill 目录跑 session_history\.py <sessionId>\n- 坑:查到的是 langfuse-dev,不是 ops 生产\n- 来源:t-000164,2026-12-03\n$/);
76
+ // 只沾到一个词的不算同一类活:「导出接口联调的告警要看吗」命中「导出接口联调」,不会把「查告警跟进」也拖进来(「告警」只是 1 个片段)
77
+ const s2 = pb.section(root, '导出接口联调的告警要看吗');
78
+ assert.deepEqual([...s2.matchAll(/^### (.+)$/gm)].map((m) => m[1]), ['导出接口联调']);
79
+ // 两条都真沾边时按得分排,新的在前
80
+ const both = pb.section(root, '会议纪要的 trace 和导出接口联调都要看');
81
+ assert.deepEqual([...both.matchAll(/^### (.+)$/gm)].map((m) => m[1]), ['导出接口联调', '查会议纪要的耗时/trace']);
82
+ // 无关的话不附
83
+ assert.equal(pb.section(root, '今天天气怎么样'), '');
84
+ assert.equal(pb.section(root, ''), '');
85
+ // 太长截掉
86
+ const long = ['## 按触发查', '', '| 触发 | 工作区 | 工具 | 怎么做 | 坑 | 证据 | 更新 |', '|---|---|---|---|---|---|---|', `| 很长的活 | ws | tool | ${'步'.repeat(700)} | | t-1 | 2026-12-03 |`].join('\n');
87
+ const s3 = pb.section(workdir(t, long), '很长的活');
88
+ assert.ok(s3.includes(`${'步'.repeat(600)}…`) && !s3.includes('步'.repeat(601)));
89
+ // 最多 5 条
90
+ const many = ['## 按触发查', '', '| 触发 | 工作区 | 工具 | 怎么做 | 坑 | 证据 | 更新 |', '|---|---|---|---|---|---|---|'];
91
+ for (let i = 1; i <= 8; i += 1) many.push(`| 共同词 活 ${i} | ws | tool${i} | | | t-${i} | 2026-12-0${i} |`);
92
+ assert.equal([...pb.section(workdir(t, many.join('\n')), '共同词').matchAll(/^### /gm)].length, 5);
93
+ });
94
+
95
+ test('现场手册接进了路由和任务书:turnPrompt 带上手册清单;没有手册时不出现', (t) => {
96
+ const root = workdir(t, SAMPLE);
97
+ const { turnPrompt } = require('../lib/router');
98
+ const prompt = turnPrompt([{ id: 't-000001', kind: 'message', at: '2026-12-04 09:00:00', text: '查会议纪要的 trace' }], [], '', null, new Date('2026-12-04T09:00:00'), [], pb.summary(root));
99
+ const a = prompt.indexOf('现场手册(以前做同类活留下的经验');
100
+ const b = prompt.indexOf('手头的事(在跑的和今天做完的):');
101
+ const c = prompt.indexOf('触发:');
102
+ assert.ok(a > 0 && a < b && b < c, '手册清单要在手头的事之前');
103
+ assert.ok(prompt.includes('- 查会议纪要的耗时/trace → minutes · kwork-langfuse:'));
104
+ assert.ok(prompt.includes('- 查告警跟进 → 工作目录 · alerts-morning'));
105
+ assert.ok(!turnPrompt([], [], '', null, new Date(), [], []).includes('现场手册'));
106
+ });
@@ -11,18 +11,25 @@ const TODAY = () => {
11
11
  return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
12
12
  };
13
13
  const AGENT = (box) => path.join(box.bin, 'fake-agent');
14
+ // 名册:路由和一组执行者都是假的 fake-agent,那一组同时跑 2 个
15
+ const BOUND = (box) => ({ router: { agent: AGENT(box), model: '', effort: '' }, workers: [{ id: 'w1', agent: AGENT(box), model: '', effort: '', count: 2 }] });
14
16
  // 不推送的用例里钥匙串的假地址指向 1 端口:fetch 直接拒绝,不会真的往外发。要推送的用例换成假 webhook 的地址
15
17
  const DUMMY_URL = 'http://127.0.0.1:1/gateway/robot/webhook/send?yzjtype=0&yzjtoken=stubtoken0123456789abcd';
16
- const ENVS = (box, url = DUMMY_URL) => ({ ...box.stubs(), STUB_KEYCHAIN: 'ok', STUB_ROBOT_URL: url, YZJ_MY_OPEN_ID: 'me-0001', YZJ_BOT_AGENT: AGENT(box) });
18
+ const ENVS = (box, url = DUMMY_URL) => ({ ...box.stubs(), STUB_KEYCHAIN: 'ok', STUB_ROBOT_URL: url, YZJ_MY_OPEN_ID: 'me-0001' });
17
19
 
18
- // 搭工作目录:消息渠道是 yzj-robot,agent 是假的 fake-agent。set 改 profile.yaml 里缩进两格的键(schedule 的任务、rhythm 的设置)
20
+ // 搭工作目录:消息渠道是 yzj-robot,路由和执行者都是假的 fake-agent(写在名册里)。set 改 profile.yaml 里缩进两格的键(schedule 的任务、rhythm 的设置)
19
21
  function setup(t) {
20
22
  const box = makeSandbox(t);
21
23
  box.workdir();
22
24
  const profile = `${box.work}/00-config/profile.yaml`;
23
25
  write(profile, setKey(read(profile), 'notify', '"yzj-robot"'));
24
26
  const set = (key, value) => write(profile, setKey(read(profile), key, value));
27
+ const rosterFile = `${box.work}/00-config/agents.json`;
25
28
  const s = { box, profile, set, env: ENVS(box) };
29
+ s.roster = (doc) => write(rosterFile, `${JSON.stringify(doc)}\n`);
30
+ s.roster(BOUND(box));
31
+ // 路由和执行者都没绑
32
+ s.unbind = () => s.roster({ router: {}, workers: [] });
26
33
  // 不传 env 就用 s.env(用例可以改它)
27
34
  s.rhythm = (args, env) => box.run(['rhythm', ...args], { env: env || s.env });
28
35
  return s;
@@ -109,23 +116,36 @@ echo hi
109
116
  });
110
117
 
111
118
  // ---------------------------------------------------------------- 任务
112
- test('rhythm run:任务交给 YZJ_BOT_AGENT 指的命令,回复打出来;不带 --push 不推送', async (t) => {
119
+ test('rhythm run:任务走路由 → 执行者 → 路由,要发给用户的话打出来;不带 --push 不推送', async (t) => {
113
120
  const hook = await webhook(t);
114
121
  const s = setup(t);
115
122
  const r = s.rhythm(['run', 'daily-plan'], { ...s.env, STUB_ROBOT_URL: hook.url });
116
123
  assert.equal(r.code, 0, r.out);
117
- assert.match(r.stdout, /回复:/);
124
+ // 路由写给用户的话(假的把回执正文 notify 回来):命令行里走这一遍,没带 --push 就打到屏幕上
125
+ assert.equal(r.stdout, '要发给用户的话(没发;带 --push 才真发):\n\n做了:每日工作计划\n');
118
126
  assert.deepEqual(hook.requests(), []);
127
+ // 任务书是指令文件的全文加回执要求。定时任务是无人值守的:不向我要决定
128
+ const task = read(`${s.box.work}/.agents/handoff/t-000001.md`);
129
+ assert.match(task, /^# 任务书 t-000001\n\n- 来源:schedule(到点 [^)]*)· 任务:daily-plan(tasks\/daily-plan\.md)\n- 派给:执行者 · 权限 edit · 不限时\n/);
130
+ assert.match(task, /这次是无人值守的:需要拿主意的地方按你的判断定下来,在回执里写一句你是怎么定的;不要列「要我拿主意」,不要等我答复。/);
131
+ assert.match(read(`${s.box.work}/01-inbox/_rhythm.log`), /任务 daily-plan 成功 用时 \d+s\n$/);
119
132
  });
120
133
 
121
- test('rhythm run:agent 失败时退出码为 5;没有这个任务也是 5', async (t) => {
134
+ test('rhythm run:执行者失败时退出码为 5,原因带出来;没有这个任务也是 5;路由和执行者没绑是 3', async (t) => {
135
+ const hook = await webhook(t);
122
136
  const s = setup(t);
123
- assert.equal(s.rhythm(['run', 'daily-plan'], { ...s.env, STUB_AGENT: 'fail' }).code, 5);
124
- const r = s.rhythm(['run', 'no-such-task']);
137
+ const r = s.rhythm(['run', 'daily-plan'], { ...s.env, STUB_WORKER_FAIL: '1', STUB_ROBOT_URL: hook.url });
125
138
  assert.equal(r.code, 5);
126
- assert.match(r.stdout, /没跑成:缺 tasks\/no-such-task.md/);
139
+ assert.equal(r.stdout, '没跑成:退出码 1:执行者崩了\n');
140
+ assert.match(read(`${s.box.work}/.agents/handoff/t-000001.result.md`), /^# 回执 t-000001\n\n- 结果:失败 · 原因:退出码 1:执行者崩了/);
141
+ assert.equal(s.rhythm(['run', 'no-such-task']).code, 5);
142
+ assert.match(s.rhythm(['run', 'no-such-task']).stdout, /没跑成:缺 tasks\/no-such-task.md/);
127
143
  assert.equal(s.rhythm(['run']).code, 2);
128
144
  assert.equal(s.rhythm(['run', 'daily-plan', '--nope']).code, 2);
145
+ s.unbind();
146
+ const unbound = s.rhythm(['run', 'daily-plan']);
147
+ assert.equal(unbound.code, 3);
148
+ assert.match(unbound.stderr, /路由和执行者的 agent 配得不对:路由 没绑 agent/);
129
149
  });
130
150
 
131
151
  test('rhythm doctor:配置齐了时退出码为 0;时间写了却缺指令文件的任务报出来', (t) => {
@@ -135,12 +155,14 @@ test('rhythm doctor:配置齐了时退出码为 0;时间写了却缺指令
135
155
  fs.renameSync(`${s.box.work}/tasks/weekly-rhythm.md`, `${s.box.root}/weekly-rhythm.md`);
136
156
  const r = s.rhythm(['doctor']);
137
157
  assert.equal(r.code, 1);
138
- assert.match(r.stdout, /任务 weekly-rhythm 的时间写了「Fri 16:30」,但缺 tasks\/weekly-rhythm.md,没法跑/);
139
- // 推送开着却没配消息渠道、agent 没配,都报出来
158
+ assert.match(r.stdout, /任务 weekly-rhythm 的时间写了「Fri 16:30」,但缺 tasks\/weekly-rhythm\.md,没法跑/);
159
+ // 推送开着却没配消息渠道、agent 没绑,都报出来
140
160
  s.set('notify', '""');
141
161
  assert.match(s.rhythm(['doctor']).stdout, /rhythm.push 开着,但 preferences.notify 没配消息渠道/);
142
- assert.match(s.rhythm(['doctor'], { ...s.env, YZJ_BOT_AGENT: '' }).stdout, /没绑 agent:定时任务和机器人值守都要一个 agent 来跑/);
162
+ s.unbind();
163
+ assert.match(s.rhythm(['doctor']).stdout, /路由 没绑 agent:work-rhythm agent bind router <名字>,或者在本机网页的 \/agents 里配\n执行者 没绑 agent|路由 没绑 agent[^\n]*\n一组执行者都没有/);
143
164
  // 端口不在范围里
165
+ s.roster(BOUND(s.box));
144
166
  s.set('port', '80');
145
167
  assert.match(s.rhythm(['doctor']).stdout, /rhythm.port 要是 1024 到 65535 之间的整数(现在是 80)/);
146
168
  });
@@ -152,9 +174,10 @@ test('rhythm start:配置有问题时不起,退出码为 3,缺指令文件
152
174
  s.set('weekly-rhythm', '"Fri 16:30"');
153
175
  fs.renameSync(`${s.box.work}/tasks/weekly-rhythm.md`, `${s.box.root}/weekly-rhythm.md`);
154
176
  s.set('notify', '""');
155
- const r = s.rhythm(['start'], { ...s.env, YZJ_BOT_AGENT: '' });
177
+ s.unbind();
178
+ const r = s.rhythm(['start']);
156
179
  assert.equal(r.code, 3);
157
- assert.match(r.stderr, /配置有问题,先跑 work-rhythm rhythm doctor:\n没绑 agent/);
180
+ assert.match(r.stderr, /配置有问题,先跑 work-rhythm rhythm doctor:\n路由 没绑 agent/);
158
181
  assert.match(r.stderr, /rhythm.push 开着/);
159
182
  assert.ok(!r.stderr.includes('weekly-rhythm'), '缺指令文件的任务到点跳过就行,不该拦着不起');
160
183
  });
@@ -213,17 +236,15 @@ describe('rhythm start:服务在跑的时候', () => {
213
236
  assert.match(r.stderr, /服务已经在跑了/);
214
237
  });
215
238
 
216
- test('run --push:agent 的总结经消息渠道发给我,后面附页面地址', () => {
239
+ test('run --push:路由写给用户的话经消息渠道发给我,后面附页面地址', () => {
217
240
  hook.clear();
218
241
  const r = s.rhythm(['run', 'daily-plan', '--push']);
219
242
  assert.equal(r.code, 0, r.out);
220
- // 假的 agent 把整段指令回出来,所以只看结尾
221
- assert.match(r.stdout, /\n\n(已推送)\n$/);
243
+ assert.equal(r.stdout, '(已推送)\n');
222
244
  const requests = hook.requests();
223
245
  assert.equal(requests.length, 1);
224
246
  const body = JSON.parse(requests[0].body);
225
- assert.match(body.content, /回复:/);
226
- assert.ok(body.content.includes(`→ 今天的文件:http://127.0.0.1:${port}/day/${TODAY()}`), body.content);
247
+ assert.equal(body.content, `做了:每日工作计划\n\n→ 今天的文件:http://127.0.0.1:${port}/day/${TODAY()}`);
227
248
  assert.deepEqual(body.notifyParams, [{ type: 'openIds', values: ['me-0001'] }]);
228
249
  });
229
250
 
@@ -232,14 +253,17 @@ describe('rhythm start:服务在跑的时候', () => {
232
253
  const r = s.rhythm(['run', 'linky-cost-fill', '--push']);
233
254
  assert.equal(r.code, 0, r.out);
234
255
  assert.ok(!r.stdout.includes('已推送'));
256
+ assert.match(r.stdout, /(静默的任务,不推送;结果写在工作目录里)/);
235
257
  assert.deepEqual(hook.requests(), []);
236
258
  });
237
259
 
238
260
  test('run --push:任务没跑完也告诉我原因', () => {
239
261
  hook.clear();
240
- const r = s.rhythm(['run', 'daily-plan', '--push'], { ...s.env, STUB_AGENT: 'fail' });
262
+ const r = s.rhythm(['run', 'daily-plan', '--push'], { ...s.env, STUB_WORKER_FAIL: '1' });
241
263
  assert.equal(r.code, 5);
242
- assert.match(hook.contents().at(-1), /「daily-plan」没跑完:退出码 1:agent 崩了/);
264
+ assert.match(r.stdout, /没跑成:退出码 1:执行者崩了/);
265
+ // 服务在跑,后面照样附上今天页面的地址
266
+ assert.deepEqual(hook.contents(), [`没做成:退出码 1:执行者崩了\n\n→ 今天的文件:http://127.0.0.1:${port}/day/${TODAY()}`]);
243
267
  });
244
268
 
245
269
  test('网页:今日、遗留打得开,最近的日子和站内链接都对;没有的日子、越出范围的地址、写请求都拒掉', async () => {
@@ -277,7 +301,7 @@ describe('rhythm start:服务在跑的时候', () => {
277
301
  t.after(() => {
278
302
  for (const rel of ['05-goals/ship-v1.md', '01-inbox/reports/2026-11-30-alerts.html']) fs.rmSync(`${s.box.work}/${rel}`, { force: true });
279
303
  });
280
- const pages = ['/', '/carryover', '/decisions', '/rhythm', '/goals', '/reports', '/monitor', '/nope'];
304
+ const pages = ['/', '/carryover', '/decisions', '/rhythm', '/goals', '/reports', '/monitor', '/agents', '/nope'];
281
305
  for (const p of pages) {
282
306
  const html = await (await fetch(`${base}${p}`)).text();
283
307
  assert.match(html, /<main class="stack">\n<header class="(?:page-head|day-hero)">/, `${p} 的壳和别的页签不一样`);
@@ -289,10 +313,84 @@ describe('rhythm start:服务在跑的时候', () => {
289
313
  const refused = await fetch(`${base}/`, { method: 'POST' });
290
314
  assert.equal(refused.status, 405);
291
315
  assert.match(await refused.text(), /<main class="stack">\n<header class="page-head"><h1>只支持打开页面<\/h1>/);
292
- // 监控页的三块状态和别的卡片是同一种卡片,页头右边是自动刷新和 status.json
316
+ // 监控页的三块状态和别的卡片是同一种卡片,页头右边是自动刷新和 status.json;路由、执行者两张卡带着去 /agents 配的入口
293
317
  const monitor = await (await fetch(`${base}/monitor`)).text();
294
318
  assert.match(monitor, /<header class="page-head"><h1>监控中心<\/h1><div class="page-head-meta">[\s\S]*?<input type="checkbox" id="refresh" checked>[\s\S]*?<a class="day-btn" href="\/status\.json">status\.json<\/a><\/div><\/header>/);
295
- for (const name of ['服务', '路由', '执行者']) assert.match(monitor, new RegExp(`<section class="card">\\s*<div class="card-head"><h2>${name}</h2></div>`), `监控页的「${name}」应是普通卡片`);
319
+ for (const name of ['服务', '路由', '执行者']) assert.match(monitor, new RegExp(`<section class="card">\\s*<div class="card-head"><h2>${name}(?: <a class="day-btn" href="/agents">配置</a>)?</h2></div>`), `监控页的「${name}」应是普通卡片`);
320
+ });
321
+
322
+ test('/agents 页:路由和每组执行者的 agent、模型、强度、数量都能配;保存要令牌、只认 JSON、配得不对就拒;保存后新的触发生效、不用重启', async () => {
323
+ const base = `http://127.0.0.1:${port}`;
324
+ const page = await (await fetch(`${base}/agents`)).text();
325
+ assert.match(page, /<header class="page-head"><h1>路由与执行者<\/h1><div class="page-head-meta"><span class="muted">00-config\/agents\.json · 保存后对新的触发生效<\/span>/);
326
+ assert.match(page, /<h2>路由 <span class="muted">只做判断:给每条触发一个决定、写任务书,只读<\/span><\/h2><span class="pill">在跑<\/span>/);
327
+ assert.match(page, /<h2>执行者 <span class="muted">[^<]*<\/span><\/h2><span class="pill" id="ag-count-pill">1 组 · 共 2 个<\/span>/);
328
+ // 路由一行、执行者一组一行:agent 下拉(装了的预置都在,qoder 排第一;也可以填一条自定义命令)、模型、强度、数量
329
+ const presets = '<option value="qoder">qoder(?:(没装))?</option><option value="dsh">dsh</option><option value="zcode">zcode</option><option value="claude">claude(?:(没装))?</option><option value="codex">codex</option><option value="kimi">kimi</option>';
330
+ assert.match(page, new RegExp(`<div class="ag-row" data-where="router">\\n <label class="ag-f">agent\\n <select class="ag-agent" aria-label="agent">${presets}<option value="__custom__" selected>自定义命令…</option></select>`));
331
+ assert.ok(page.includes(`<input class="ag-custom" type="text" spellcheck="false" placeholder="一条命令:消息作为最后一个参数,回复打到标准输出" value="${AGENT(s.box)}">`), '自定义命令填的是名册里那条');
332
+ assert.match(page, /<div class="ag-row" data-where="w1">\n <label class="ag-f">agent\n <select class="ag-agent" aria-label="agent">/);
333
+ assert.match(page, /<label class="ag-f ag-f-n">数量\n <input class="ag-count" type="number" min="1" max="16" step="1" value="2">/, '执行者那一行有数量(1 到 16)');
334
+ // 「加一组」用一份空着的模板;保存按钮在下面
335
+ assert.match(page, /<template id="ag-tpl"><div class="ag-row" data-where="">/);
336
+ assert.match(page, /<button type="button" class="day-btn" id="ag-add">\+ 加一组<\/button>/);
337
+ assert.match(page, /<button type="button" class="ag-save" id="ag-save">保存<\/button>/);
338
+ assert.match(page, /'X-Wrj-Token': TOKEN/, '页面脚本带着令牌');
339
+ // 读接口和页面是同一份数据
340
+ const data = await (await fetch(`${base}/agents.json`)).json();
341
+ assert.deepEqual([data.source, data.router.agent, data.workers.map((w) => [w.id, w.count]), data.maxCount, data.installed.map((a) => a.name)], ['file', AGENT(s.box), [['w1', 2]], 16, ['qoder', 'dsh', 'zcode', 'claude', 'codex', 'kimi']]);
342
+ // 保存:令牌不对 403、不是 JSON 415、配得不对 400(问题逐条给)
343
+ const token = read(`${s.box.work}/01-inbox/_rhythm/web-token`).trim();
344
+ const post = async (body, headers = {}) => {
345
+ const res = await fetch(`${base}/agents`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Wrj-Token': token, ...headers }, body: JSON.stringify(body) });
346
+ return [res.status, await res.json()];
347
+ };
348
+ // 页面上已有的那行带着它的编号发回来(w1 保留),新加的那行没有编号(接着往下发)
349
+ const next = { router: { agent: 'dsh', model: 'deepseek-v4.1-flash', effort: 'high' }, workers: [{ id: 'w1', agent: 'zcode', count: 3 }, { agent: 'dsh', model: '', effort: 'low', count: 1 }] };
350
+ assert.deepEqual(await post(next, { 'X-Wrj-Token': 'nope' }), [403, { problems: ['令牌不对:这个接口只给本机页面用'] }]);
351
+ assert.deepEqual(await post(next, { 'Content-Type': 'text/plain' }), [415, { problems: ['只认 application/json'] }]);
352
+ assert.deepEqual((await post({ router: { agent: '/nonexistent/x' }, workers: [{ agent: 'dsh', count: 1 }] }))[0], 400);
353
+ const tooMany = await post({ router: { agent: 'dsh' }, workers: [{ agent: 'dsh', count: 99 }] });
354
+ assert.equal(tooMany[0], 400, JSON.stringify(tooMany[1]));
355
+ assert.match(tooMany[1].problems.join('\n'), /数量/, '数量超了就拒');
356
+ const noGroup = await post({ router: { agent: 'dsh' }, workers: [] });
357
+ assert.equal(noGroup[0], 400, JSON.stringify(noGroup[1]));
358
+ assert.match(noGroup[1].problems.join('\n'), /至少留一组执行者/, '一组都不留就拒');
359
+ assert.equal(JSON.parse(read(`${s.box.work}/00-config/agents.json`)).router.agent, AGENT(s.box), '拒了的请求不改文件');
360
+ // 保存成功:写进名册(已有的保留编号、新组接着发;seq 记下发过的最大编号),注意只提一句
361
+ const [status, body] = await post(next);
362
+ assert.equal(status, 200, JSON.stringify(body));
363
+ assert.equal(body.ok, true);
364
+ assert.match(body.notes.join('\n'), /在跑的那几件不受影响,新来的触发按这份配置走/);
365
+ // 发下去的编号带回页面:页面拿它记住每一行的编号,再保存时还是这几组
366
+ assert.deepEqual(body.workers, [{ id: 'w1', count: 3 }, { id: 'w2', count: 1 }]);
367
+ const twice = await post({ router: next.router, workers: body.workers.map((w, i) => ({ ...w, ...next.workers[i] })) });
368
+ assert.equal(twice[0], 200, JSON.stringify(twice[1]));
369
+ assert.deepEqual(JSON.parse(read(`${s.box.work}/00-config/agents.json`)).workers.map((w) => w.id), ['w1', 'w2'], '带着编号再保存一次:编号不变');
370
+ assert.deepEqual(JSON.parse(read(`${s.box.work}/00-config/agents.json`)), {
371
+ router: { agent: 'dsh', model: 'deepseek-v4.1-flash', effort: 'high' },
372
+ workers: [{ id: 'w1', agent: 'zcode', model: '', effort: '', count: 3 }, { id: 'w2', agent: 'dsh', model: '', effort: 'low', count: 1 }],
373
+ seq: 2,
374
+ });
375
+ // 不用重启:status.json 和 rhythm status 马上就是新的
376
+ const json = await (await fetch(`${base}/status.json`)).json();
377
+ assert.deepEqual([json.agents.router.agent, json.agents.router.model, json.agents.router.effort, json.workers.limit, json.workers.groups.map((g) => [g.id, g.agent, g.count])], ['dsh', 'deepseek-v4.1-flash', 'high', 4, [['w1', 'zcode', 3], ['w2', 'dsh', 1]]]);
378
+ assert.match(s.rhythm(['status']).stdout, /路由:dsh,模型 deepseek-v4\.1-flash,强度 high,今天 \d+ 轮;[^\n]*\n执行者:w1 zcode ×3;w2 dsh low ×1;改在 /);
379
+ // 新来的触发按这份配置走:路由是 dsh,执行者是 zcode
380
+ hook.clear();
381
+ const r = s.rhythm(['run', 'daily-plan', '--push'], { ...s.env, STUB_ROUTER_REPLY: '' });
382
+ assert.equal(r.code, 0, r.out);
383
+ assert.ok(read(s.env.STUB_DSH_ALL).split('\n').some((l) => l.includes('【work-rhythm 路由】')), '路由是 dsh');
384
+ assert.ok(read(s.env.STUB_ZCODE_ALL).split('\n').some((l) => l.includes(' 读 .agents/handoff/')), '执行者是 zcode(第一组)');
385
+ assert.match(hook.contents().at(-1), /做了:每日工作计划/);
386
+ // 页面上显示的也是新的
387
+ const page2 = await (await fetch(`${base}/agents`)).text();
388
+ assert.match(page2, /<span class="pill" id="ag-count-pill">2 组 · 共 4 个<\/span>/);
389
+ assert.match(page2, /<div class="ag-row" data-where="w2">/);
390
+ // 改回去:后面的用例还要用假的 fake-agent
391
+ const back = await post(BOUND(s.box));
392
+ assert.equal(back[0], 200, JSON.stringify(back));
393
+ assert.equal(JSON.parse(read(`${s.box.work}/00-config/agents.json`)).workers.length, 1);
296
394
  });
297
395
 
298
396
  test('stop 之后 status 说没在跑', async () => {
@@ -308,7 +406,7 @@ describe('rhythm start:服务在跑的时候', () => {
308
406
  hook.clear();
309
407
  s.rhythm(['run', 'daily-plan', '--push']);
310
408
  const content = hook.contents().at(-1);
311
- assert.match(content, /回复:/);
409
+ assert.equal(content, '做了:每日工作计划');
312
410
  assert.ok(!content.includes('127.0.0.1'), content);
313
411
  });
314
412
  });
@@ -332,11 +430,11 @@ test('rhythm run sync:有源失败时退出码为 5,原因带出来', async
332
430
  write(file, `${read(file)}\n - id: nofile\n name: 自测用\n enabled: true\n collector: collectors/nope.sh\n`);
333
431
  const r = s.rhythm(['run', 'sync']);
334
432
  assert.equal(r.code, 5);
335
- assert.match(r.stdout, /采集失败:退出码 1:[\s\S]*FAIL nofile(采集脚本不存在: collectors\/nope.sh)/);
433
+ assert.match(r.stdout, /采集失败:退出码 1:[\s\S]*FAIL nofile(采集脚本不存在: collectors\/nope\.sh)/);
336
434
  });
337
435
 
338
436
  // ---------------------------------------------------------------- 调度
339
- test('rhythm start:到点真的把任务交给 agent,总结推送给我,状态里记一笔', async (t) => {
437
+ test('rhythm start:到点的任务在服务里变成触发,路由 → 执行者 → 路由,路由写给用户的话推送给我;运行记录里记一笔,同一时间点只跑一次', async (t) => {
340
438
  const hook = await webhook(t);
341
439
  const s = setup(t);
342
440
  const now = new Date();
@@ -354,17 +452,27 @@ test('rhythm start:到点真的把任务交给 agent,总结推送给我,
354
452
  s.rhythm(['stop'], env);
355
453
  await proc.exited;
356
454
  });
357
- assert.ok(await proc.waitFor('rc=0', 90000), proc.text());
455
+ // 两件都做完(第二件的短号是 t-000003:第一件的汇报占了 t-000002)
456
+ assert.ok(await proc.waitFor('执行者结束 t-000003', 90000), proc.text());
457
+ // 等两件的汇报都走完、推送到了
458
+ const until = Date.now() + 20000;
459
+ while (Date.now() < until && hook.contents().length < 2) await new Promise((resolve) => setTimeout(resolve, 200));
358
460
  const log = proc.text();
359
- assert.match(log, /到点 (daily-plan|noon-checkin) \d\d:\d\d\n[\s\S]*开始跑 (daily-plan|noon-checkin) pid=\d+[\s\S]*跑完 (daily-plan|noon-checkin) rc=0/);
360
- assert.ok(hook.contents().some((c) => c.includes('回复:')), '任务跑了却没推送');
461
+ assert.match(log, /到点 (daily-plan|noon-checkin) \d\d:\d\d\n[\s\S]*触发入队 t-000001 schedule\n[\s\S]*路由出决定 1 条\n[\s\S]*执行者结束 t-000001 成功 \d+s\n[\s\S]*触发入队 t-000002 report/);
462
+ assert.match(log, /到点 (daily-plan|noon-checkin) \d\d:\d\d\n[\s\S]*触发入队 t-000003 schedule/);
463
+ const contents = hook.contents();
464
+ assert.equal(contents.length, 2, contents.join('|'));
465
+ assert.deepEqual(contents.map((c) => c.split('\n')[0]).sort(), ['做了:中午工作进展', '做了:每日工作计划'].sort());
466
+ for (const c of contents) assert.match(c, new RegExp(`\\n\\n→ [^\\n]+:http://127\\.0\\.0\\.1:\\d+/day/\\d{4}-\\d{2}-\\d{2}$`), '推送后面附页面地址');
467
+ // 运行记录里两条都是成功的;状态里记着它们
361
468
  const state = JSON.parse(read(`${s.box.work}/01-inbox/_rhythm/state.json`));
362
- assert.ok(Object.values(state.runs).some((r) => r.ok === true), JSON.stringify(state.runs));
469
+ const rows = state.history.filter((h) => h.kind === 'schedule');
470
+ assert.deepEqual(rows.map((h) => [h.task, h.ok]).sort(), [['daily-plan', true], ['noon-checkin', true]]);
471
+ assert.ok(Object.values(state.triggers).filter((x) => x.kind === 'schedule').every((x) => x.notified), '两件都推送过');
363
472
  // 同一时间点只跑一次
364
473
  await new Promise((resolve) => setTimeout(resolve, 1500));
365
- assert.equal(Object.values(state.runs).length >= 1, true);
366
474
  assert.ok(log.split('\n').filter((l) => l.includes('到点 ')).length <= 2, '同一个时间点跑了不止一次');
367
- assert.match(read(`${s.box.work}/01-inbox/_rhythm.log`), /任务 (daily-plan|noon-checkin) 成功 用时 \d+s 已推送/);
475
+ assert.equal(s.rhythm(['run', 'daily-plan']).code, 0, '到点跑过之后手动还能再跑');
368
476
  });
369
477
 
370
478
  // ---------------------------------------------------------------- 用法
@@ -377,28 +485,33 @@ test('rhythm:不认识的子命令退出码为 2,--help 列出全部', (t) =
377
485
  for (const cmd of ['start', 'stop', 'status', 'due', 'run', 'serve', 'render', 'doctor', 'install', 'uninstall']) assert.match(r.stdout, new RegExp(`(?:\\n | \\| )${cmd}[ |\\[]`), `用法里没有 ${cmd}`);
378
486
  });
379
487
 
380
- test('rhythm:profile 的 agent-model / agent-effort 给定时任务另配一套,写进 dsh 的覆盖文件;没配就沿用 local.env 的', async (t) => {
488
+ test('rhythm:路由和执行者各用各的模型和强度,dsh 的覆盖文件按(模型、强度)各一份;老写法的 agent-model / agent-effort 认第一组执行者的', async (t) => {
381
489
  const hook = await webhook(t);
382
490
  const s = setup(t);
383
491
  const env = { ...s.env, STUB_ROBOT_URL: hook.url };
384
- write(`${s.box.work}/collectors/local.env`, 'YZJ_BOT_AGENT="dsh"\n');
385
- // agent-model / agent-effort 是可选键,模板里没有:补在 rhythm: 一节的 quiet 后面
386
- const profile = `${s.box.work}/00-config/profile.yaml`;
387
- const addRhythm = (lines) => write(profile, read(profile).replace(/^( quiet:.*)$/m, `$1\n${lines.join('\n')}`));
388
- addRhythm([' agent-model: "opencode-go/glm-5.3-flash"', ' agent-effort: "low"']);
492
+ const patchDir = `${s.box.work}/01-inbox`;
493
+ const patches = (dir) => fs.readdirSync(path.join(patchDir, dir)).filter((n) => /^dsh-headless.*\.patch\.yml$/.test(n)).map((n) => read(path.join(patchDir, dir, n)));
494
+ s.roster({ router: { agent: 'dsh', model: 'opencode-go/glm-5.3-flash', effort: 'low' }, workers: [{ id: 'w1', agent: 'dsh', model: 'opencode-go/deepseek-v4.1-flash', effort: 'high', count: 1 }] });
389
495
  assert.equal(s.rhythm(['doctor'], env).code, 0, s.rhythm(['doctor'], env).out);
390
496
  const r = s.rhythm(['run', 'daily-plan'], env);
391
497
  assert.equal(r.code, 0, r.out);
392
- // 覆盖文件按模型和强度分文件名(路由和执行者用的模型不一样、并发跑的时候不互相覆盖):在 _rhythm 下按前缀找
393
- const patchDir = `${s.box.work}/01-inbox/_rhythm`;
394
- const patches = () => fs.readdirSync(patchDir).filter((n) => /^dsh-headless.*\.patch\.yml$/.test(n)).map((n) => read(path.join(patchDir, n)));
395
- assert.ok(patches().some((p) => / provider: opencode-go\n model: glm-5\.3-flash\n reasoningEffort: low\n/.test(p)), patches().join('\n'));
396
- // 没配的时候沿用 local.env 的 YZJ_BOT_MODEL / YZJ_BOT_EFFORT
397
- write(profile, read(profile).replace(/^ agent-(model|effort):.*\n/gm, ''));
398
- 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');
498
+ // 路由的覆盖文件在 _bot 下,执行者的在 _rhythm/workers 下(路由和执行者用的模型不一样、并发跑的时候不互相覆盖)
499
+ assert.ok(patches('_bot').some((p) => / provider: opencode-go\n model: glm-5\.3-flash\n reasoningEffort: low\n/.test(p)), patches('_bot').join('\n'));
500
+ assert.ok(patches('_rhythm/workers').some((p) => / provider: opencode-go\n model: deepseek-v4\.1-flash\n reasoningEffort: high\n/.test(p)), patches('_rhythm/workers').join('\n'));
501
+ assert.equal(patches('_rhythm/workers').length, 1);
502
+ // 老写法(没有名册):profile 的 agent-model / agent-effort 是第一组执行者的模型和强度
503
+ fs.rmSync(`${s.box.work}/00-config/agents.json`);
504
+ for (const f of [...fs.readdirSync(path.join(patchDir, '_rhythm', 'workers')), ...fs.readdirSync(path.join(patchDir, '_bot'))]) if (/^dsh-headless/.test(f)) fs.rmSync(path.join(patchDir, '_rhythm', 'workers', f), { force: true });
505
+ write(`${s.box.work}/collectors/local.env`, 'YZJ_BOT_AGENT="dsh"\nYZJ_ROUTER_MODEL="opencode-go/glm-5.3-flash"\nYZJ_ROUTER_EFFORT="low"\n');
506
+ // agent-model / agent-effort 是可选键,模板里没有:补在 rhythm: 一节的 quiet 后面
507
+ write(s.profile, read(s.profile).replace(/^( quiet:.*)$/m, '$1\n agent-model: "opencode-go/glm-5.3-flash"\n agent-effort: "low"'));
508
+ assert.equal(s.rhythm(['run', 'daily-plan'], env).code, 0, s.rhythm(['run', 'daily-plan'], env).out);
509
+ assert.ok(patches('_rhythm/workers').some((p) => / model: glm-5\.3-flash\n reasoningEffort: low\n/.test(p)), patches('_rhythm/workers').join('\n'));
510
+ // 老键 YZJ_WORKER_MODEL / YZJ_WORKER_EFFORT 优先于 profile 的
511
+ write(`${s.box.work}/collectors/local.env`, 'YZJ_BOT_AGENT="dsh"\nYZJ_ROUTER_MODEL="opencode-go/glm-5.3-flash"\nYZJ_ROUTER_EFFORT="low"\nYZJ_WORKER_MODEL="opencode-go/deepseek-v4.1-flash"\nYZJ_WORKER_EFFORT="high"\n');
399
512
  assert.equal(s.rhythm(['run', 'daily-plan'], env).code, 0);
400
- assert.ok(patches().some((p) => / model: deepseek-v4\.1-flash\n reasoningEffort: high\n/.test(p)), patches().join('\n'));
401
- assert.equal(patches().length, 2, '两套模型各一份覆盖文件');
513
+ assert.ok(patches('_rhythm/workers').some((p) => / model: deepseek-v4\.1-flash\n reasoningEffort: high\n/.test(p)), patches('_rhythm/workers').join('\n'));
514
+ assert.equal(patches('_rhythm/workers').length, 2, '两套模型各一份覆盖文件');
402
515
  });
403
516
 
404
517
  // ---------------------------------------------------------------- 值守跟着服务一起跑
@@ -407,9 +520,7 @@ test('rhythm:YZJ_BOT_LISTEN=1 时值守在服务的同一个进程里跑;配
407
520
  const s = setup(t);
408
521
  const port = await freePort();
409
522
  s.set('port', String(port));
410
- const profile = `${s.box.work}/00-config/profile.yaml`;
411
- write(profile, read(profile).replace(/^ notify:.*$/m, ' notify: "yzj-robot"'));
412
- write(`${s.box.work}/collectors/local.env`, 'YZJ_BOT_AGENT="dsh"\n');
523
+ write(s.profile, read(s.profile).replace(/^ notify:.*$/m, ' notify: "yzj-robot"'));
413
524
  const botEnv = { ...s.env, STUB_ROBOT_URL: 'wss://127.0.0.1:1/xuntong/websocket?yzjtoken=stubtoken0123456789abcd' };
414
525
  // 值守开着、配置齐:服务日志里有「值守开始」,同一个 pid;机器人连不上(假地址)只是重连,不影响服务和网页
415
526
  const proc = s.box.spawn(['rhythm', 'start', '--tick', '1'], { env: { ...botEnv, YZJ_BOT_LISTEN: '1', YZJ_MY_OPEN_ID: 'me-0001' } });
@@ -421,14 +532,13 @@ test('rhythm:YZJ_BOT_LISTEN=1 时值守在服务的同一个进程里跑;配
421
532
  assert.ok(await proc.waitFor('值守开始', 8000), proc.text());
422
533
  const servicePid = read(`${s.box.work}/01-inbox/_rhythm/service.pid`).trim();
423
534
  const botLog = read(`${s.box.work}/01-inbox/_bot.log`);
424
- assert.match(botLog, new RegExp(`值守开始 pid=${servicePid} agent=dsh mode=plan`), '值守和服务是同一个进程');
425
- assert.match(botLog, /会话=值守自己的专属会话/);
535
+ assert.match(botLog, new RegExp(`值守开始 pid=${servicePid} 消息交给路由`), '值守和服务是同一个进程');
426
536
  assert.equal((await fetch(`http://127.0.0.1:${port}/`)).status, 200);
427
537
  assert.match(s.rhythm(['status'], { ...botEnv, YZJ_BOT_LISTEN: '1' }).stdout, /值守:开着,最近 .*/);
428
- // 没有问题;只有一行「注意」说路由没开(不算问题,退出码 0)
538
+ // 配置齐:doctor 没有问题,也没有「注意」
429
539
  const fine = s.rhythm(['doctor'], { ...botEnv, YZJ_BOT_LISTEN: '1', YZJ_MY_OPEN_ID: 'me-0001' });
430
540
  assert.equal(fine.code, 0, fine.out);
431
- assert.match(fine.stdout, /^注意:路由没开(profile 的 rhythm\.router 没写)[\s\S]*\n$/);
541
+ assert.equal(fine.stdout, '', fine.stdout);
432
542
  // 显式写 0 关掉的时候
433
543
  assert.match(s.rhythm(['status'], { ...botEnv, YZJ_BOT_LISTEN: '0' }).stdout, /值守:关着/);
434
544
  // 配置不齐(没写我的 openId):doctor 报出来;服务照样起,只记「值守没开」