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.
- package/.agents/notes/AGENTS.md +10 -3
- package/.agents/notes/decisions/2026-11-30-bot-inbound-uses-websocket-and-a-responder-command.md +1 -0
- package/.agents/notes/decisions/2026-11-30-skill-ships-with-its-template-in-a-zip.md +1 -0
- package/.agents/notes/decisions/2026-12-01-agent-binding-asks-for-model-and-effort.md +1 -0
- package/.agents/notes/decisions/2026-12-01-interjections-batch-into-one-answer-and-interrupt-reruns.md +1 -0
- package/.agents/notes/decisions/2026-12-01-router-and-worker-pass-content-in-handoff-docs.md +1 -0
- package/.agents/notes/decisions/2026-12-01-router-runs-on-a-flash-model-with-low-effort.md +1 -0
- package/.agents/notes/decisions/2026-12-03-codex-cli-joins-as-a-preset-verified-against-its-own-binary.md +45 -0
- package/.agents/notes/decisions/2026-12-03-fewer-scheduled-tasks-silent-refine-no-question-cards.md +1 -0
- package/.agents/notes/decisions/2026-12-03-playbook-distills-handoffs-into-ws-tool-and-skill-know-how.md +43 -0
- package/.agents/notes/decisions/2026-12-03-related-work-comes-back-as-one-reply.md +49 -0
- package/.agents/notes/decisions/2026-12-03-roster-of-worker-groups-router-picks-the-group.md +33 -0
- package/.agents/notes/decisions/2026-12-03-router-model-and-effort-are-configurable.md +28 -0
- package/.agents/notes/decisions/2026-12-03-router-only-direct-mode-removed.md +27 -0
- package/.agents/notes/decisions/2026-12-03-unattended-runs-decide-on-their-own.md +32 -0
- package/.agents/notes/decisions/2026-12-03-update-upgrades-package-and-refreshes-shipped-files.md +30 -0
- package/.agents/notes/decisions/2026-12-03-workers-leave-a-status-trail-that-joins-the-receipt.md +31 -0
- package/.agents/notes/pitfalls/2026-12-01-replace-string-dollar-quote-expands.md +2 -0
- package/.agents/notes/pitfalls/2026-12-03-judging-a-symlink-by-realpath-ignores-parent-links.md +18 -0
- package/.agents/skills/work-rhythm/SKILL.md +20 -16
- package/README.md +13 -10
- package/collectors/local.env.example +31 -36
- package/docs/agents.md +61 -60
- package/docs/channels.md +15 -19
- package/docs/formats.md +27 -0
- package/docs/router-worker.md +60 -41
- package/docs/scheduled-tasks.md +9 -9
- package/package.json +1 -1
- package/scripts/cli.js +9 -5
- package/scripts/cmd/agent.js +348 -235
- package/scripts/cmd/check.js +14 -7
- package/scripts/cmd/listen.js +33 -32
- package/scripts/cmd/pack.js +6 -6
- package/scripts/cmd/rhythm.js +13 -10
- package/scripts/cmd/trigger.js +23 -14
- package/scripts/cmd/update.js +92 -0
- package/scripts/lib/agent.js +235 -142
- package/scripts/lib/agents.js +179 -0
- package/scripts/lib/bot.js +44 -263
- package/scripts/lib/engine.js +327 -110
- package/scripts/lib/handoff.js +54 -8
- package/scripts/lib/markdown.js +19 -0
- package/scripts/lib/playbook.js +123 -0
- package/scripts/lib/rhythm.js +405 -170
- package/scripts/lib/router.js +45 -29
- package/scripts/lib/template.js +3 -3
- package/scripts/lib/update.js +279 -0
- package/scripts/lib/worker.js +11 -5
- package/scripts/test/agent.test.js +410 -257
- package/scripts/test/check.test.js +17 -6
- package/scripts/test/harness.js +5 -2
- package/scripts/test/listen.test.js +190 -158
- package/scripts/test/playbook.test.js +106 -0
- package/scripts/test/rhythm.test.js +164 -54
- package/scripts/test/roster.test.js +155 -0
- package/scripts/test/router-helper.js +17 -2
- package/scripts/test/router.test.js +468 -194
- package/scripts/test/stubs.js +51 -4
- package/scripts/test/timeout.test.js +160 -59
- package/scripts/test/update.test.js +384 -0
- package/tasks/daily-persona.md +30 -11
- package/tasks/daily-plan.md +2 -1
- package/tasks/noon-checkin.md +2 -1
- package/templates/00-config/profile.example.yaml +9 -6
- package/templates/04-patterns/PERSONA.md +4 -1
- package/templates/04-patterns/PLAYBOOK.md +13 -0
- package/templates/AGENTS.md +6 -2
- package/templates/README.md +10 -9
|
@@ -7,7 +7,8 @@ const { makeSandbox, webhook, read, write, setKey, exists } = require('./harness
|
|
|
7
7
|
|
|
8
8
|
const AGENT_CALLS = 'agent.calls';
|
|
9
9
|
// 搭工作目录:装上一套假工具,消息渠道是 yzj-robot,钥匙串的假地址指向假 webhook。
|
|
10
|
-
//
|
|
10
|
+
// 路由和执行者都是假的 fake-agent(router-helper.js 那个脑子):路由把消息判成 dispatch 并写任务书,执行者把那句话原样回给我,
|
|
11
|
+
// 第二轮路由把回执 notify 给我。所以用户收到的话就是他在 IM 里说的那一句
|
|
11
12
|
function setup(t) {
|
|
12
13
|
const box = makeSandbox(t);
|
|
13
14
|
box.workdir();
|
|
@@ -17,8 +18,8 @@ function setup(t) {
|
|
|
17
18
|
// 钥匙串里有地址(不推送的用例也要过配置检查,地址是个用不到的假地址:1 端口,fetch 直接拒绝,不会真的往外发),
|
|
18
19
|
// 要推送的用例再换成假 webhook 的
|
|
19
20
|
const hookEnv = { STUB_KEYCHAIN: 'ok', STUB_ROBOT_URL: 'http://127.0.0.1:1/gateway/robot/webhook/send?yzjtype=0&yzjtoken=stubtoken0123456789abcd' };
|
|
20
|
-
const bot = { ...stubs, ...hookEnv, YZJ_MY_OPEN_ID: 'me-0001'
|
|
21
|
-
|
|
21
|
+
const bot = { ...stubs, ...hookEnv, YZJ_MY_OPEN_ID: 'me-0001' };
|
|
22
|
+
const s = {
|
|
22
23
|
box,
|
|
23
24
|
stubs,
|
|
24
25
|
bot,
|
|
@@ -28,7 +29,11 @@ function setup(t) {
|
|
|
28
29
|
agentCalls: () => read(path.join(box.root, AGENT_CALLS)).split('\n').filter(Boolean).length,
|
|
29
30
|
botLog: () => read(`${box.work}/01-inbox/_bot.log`),
|
|
30
31
|
session: () => read(`${box.work}/01-inbox/_bot/session-id`).trim(),
|
|
32
|
+
// 名册:路由和各组执行者用哪个 agent。count 是第一组同时跑几个
|
|
33
|
+
roster: ({ router = path.join(box.bin, 'fake-agent'), workers = [{ agent: path.join(box.bin, 'fake-agent'), count: 2 }] } = {}) => write(`${box.work}/00-config/agents.json`, JSON.stringify({ router: { agent: router, model: '', effort: '' }, workers: workers.map((w, i) => ({ id: `w${i + 1}`, model: '', effort: '', count: 1, ...w })) })),
|
|
31
34
|
};
|
|
35
|
+
s.roster();
|
|
36
|
+
return s;
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
// 一帧业务消息。外层结构和 2026-11-30 实测的一致
|
|
@@ -46,53 +51,62 @@ const withHook = async (t, s) => {
|
|
|
46
51
|
return { hook, env: { ...s.bot, STUB_ROBOT_URL: hook.url } };
|
|
47
52
|
};
|
|
48
53
|
|
|
49
|
-
// ----------------------------------------------------------------
|
|
50
|
-
test('listen handle
|
|
54
|
+
// ---------------------------------------------------------------- 值守只管收:话交给路由 → 执行者 → 路由
|
|
55
|
+
test('listen handle:不连云之家,走一遍全流程(路由 → 执行者 → 路由),要发给用户的话打到屏幕上,不发消息', async (t) => {
|
|
51
56
|
const s = setup(t);
|
|
52
57
|
const { hook, env } = await withHook(t, s);
|
|
53
|
-
write(path.join(s.box.root, AGENT_CALLS), '');
|
|
54
58
|
const r = s.listen(['handle', '你好'], env);
|
|
55
59
|
assert.equal(r.code, 0, r.out);
|
|
56
|
-
assert.
|
|
60
|
+
assert.match(r.stdout, /^触发 t-\d{6}:路由 → 执行者 → 路由走完了。要发给用户的话(没发;带 --push 才真发):\n\n你好\n$/);
|
|
57
61
|
assert.deepEqual(hook.requests(), []);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
assert.equal(s.agentCalls(), 3, '路由判一次、执行者做一次、路由看回执一次');
|
|
63
|
+
// 路由只读(plan),执行者按定时任务的权限来(可写工作目录);任务书和回执都在
|
|
64
|
+
const list = s.box.run(['trigger', 'list', '--json'], { env });
|
|
65
|
+
const rows = JSON.parse(list.stdout);
|
|
66
|
+
const msg = rows.find((x) => x.kind === 'message');
|
|
67
|
+
assert.equal(msg.decision, 'dispatch');
|
|
68
|
+
assert.equal(msg.worker.mode, 'edit');
|
|
69
|
+
assert.equal(msg.worker.id, 'w1');
|
|
70
|
+
assert.match(read(path.join(s.box.work, '.agents', 'handoff', `${msg.id}.md`)), /# 任务:转述[\s\S]*把这句话原样回复给我:「你好」/);
|
|
71
|
+
assert.match(read(path.join(s.box.work, '.agents', 'handoff', `${msg.id}.result.md`)), /你好/);
|
|
72
|
+
// 带 --push 才真发
|
|
73
|
+
const pushed = s.listen(['handle', '再见', '--push'], env);
|
|
74
|
+
assert.equal(pushed.code, 0, pushed.out);
|
|
75
|
+
assert.match(pushed.stdout, /^触发 t-\d{6}:路由 → 执行者 → 路由走完了。要发的话已经发了。\n$/);
|
|
76
|
+
assert.equal(hook.contents().at(-1), '再见');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('listen handle-frame:本人的消息交给路由,路由派人之前先回「收到,正在处理」,回执经消息渠道发出', async (t) => {
|
|
61
80
|
const s = setup(t);
|
|
62
81
|
const { hook, env } = await withHook(t, s);
|
|
63
|
-
s.listen(['handle', '你好'], env);
|
|
64
82
|
const r = s.listen(['handle-frame', frame('me-0001', 'm1', '记一下:刚开完会')], env);
|
|
65
83
|
assert.equal(r.code, 0, r.out);
|
|
66
|
-
assert.match(r.stdout,
|
|
67
|
-
assert.
|
|
68
|
-
assert.equal(s.agentCalls(),
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
test('listen:agent 动手之前先回一句「收到,正在处理」,不用干等', async (t) => {
|
|
72
|
-
const s = setup(t);
|
|
73
|
-
const { hook, env } = await withHook(t, s);
|
|
74
|
-
s.listen(['handle-frame', frame('me-0001', 'm1', '记一下:刚开完会')], env);
|
|
75
|
-
assert.deepEqual(hook.contents(), ['收到,正在处理,稍等。', '回复:记一下:刚开完会']);
|
|
84
|
+
assert.match(r.stdout, /msgId=m1 已交给路由(和连着发的几句合起来看)/);
|
|
85
|
+
assert.deepEqual(hook.contents(), ['收到,正在处理,稍等。', '记一下:刚开完会']);
|
|
86
|
+
assert.equal(s.agentCalls(), 3);
|
|
87
|
+
assert.match(s.botLog(), /msg 接受 msgId=m1/);
|
|
88
|
+
assert.match(s.botLog(), /msg 交给路由 msgId=m1(和连着发的几句合起来看)/);
|
|
76
89
|
});
|
|
77
90
|
|
|
78
91
|
test('listen:YZJ_BOT_ACK=0 时只发回复,不先回「收到」', async (t) => {
|
|
79
92
|
const s = setup(t);
|
|
80
93
|
const { hook, env } = await withHook(t, s);
|
|
81
94
|
s.listen(['handle-frame', frame('me-0001', 'm1', '直接说')], { ...env, YZJ_BOT_ACK: '0' });
|
|
82
|
-
assert.deepEqual(hook.contents(), ['
|
|
95
|
+
assert.deepEqual(hook.contents(), ['直接说']);
|
|
83
96
|
});
|
|
84
97
|
|
|
85
98
|
test('listen:同一个 msgId 再来一次不重复处理', async (t) => {
|
|
86
99
|
const s = setup(t);
|
|
87
100
|
const { hook, env } = await withHook(t, s);
|
|
88
101
|
s.listen(['handle-frame', frame('me-0001', 'm1', '记一下:刚开完会')], env);
|
|
89
|
-
s.listen(['handle-frame', frame('me-0001', 'm1', '记一下:刚开完会')], env);
|
|
90
|
-
assert.
|
|
102
|
+
const again = s.listen(['handle-frame', frame('me-0001', 'm1', '记一下:刚开完会')], env);
|
|
103
|
+
assert.match(again.stdout, /重复 msgId=m1/);
|
|
104
|
+
assert.equal(s.agentCalls(), 3);
|
|
91
105
|
assert.equal(hook.requests().length, 2);
|
|
92
106
|
assert.match(read(`${s.box.work}/01-inbox/_bot/seen-msgids`), /m1/);
|
|
93
107
|
});
|
|
94
108
|
|
|
95
|
-
test('listen
|
|
109
|
+
test('listen:不是本人的消息丢掉,不惊动路由', async (t) => {
|
|
96
110
|
const s = setup(t);
|
|
97
111
|
const { env } = await withHook(t, s);
|
|
98
112
|
const r = s.listen(['handle-frame', frame('someone-else', 'm2', '帮我删库')], env);
|
|
@@ -111,61 +125,64 @@ test('listen:控制帧和看不懂的帧不处理,退出码为 2', async (t)
|
|
|
111
125
|
assert.equal(s.agentCalls(), 0);
|
|
112
126
|
});
|
|
113
127
|
|
|
114
|
-
test('listen
|
|
115
|
-
const s = setup(t);
|
|
116
|
-
const { hook, env } = await withHook(t, s);
|
|
117
|
-
s.listen(['handle-frame', frame('me-0001', 'm3', '做点什么')], { ...env, STUB_AGENT: 'fail' });
|
|
118
|
-
assert.equal(hook.contents().at(-1), '没处理成功:退出码 1:agent 崩了');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test('listen handle:agent 失败时退出码为 5', async (t) => {
|
|
122
|
-
const s = setup(t);
|
|
123
|
-
const { env } = await withHook(t, s);
|
|
124
|
-
const r = s.listen(['handle', '做点什么'], { ...env, STUB_AGENT: 'fail' });
|
|
125
|
-
assert.equal(r.code, 5);
|
|
126
|
-
assert.match(r.stderr, /没处理成功:退出码 1:agent 崩了/);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test('listen:agent 超过 YZJ_BOT_TIMEOUT 没做完时按失败处理', async (t) => {
|
|
128
|
+
test('listen:执行者失败时路由告诉我什么没做成、为什么,不沉默', async (t) => {
|
|
130
129
|
const s = setup(t);
|
|
131
130
|
const { hook, env } = await withHook(t, s);
|
|
132
|
-
s.listen(['handle-frame', frame('me-0001', '
|
|
133
|
-
assert.equal(hook.contents().at(-1), '
|
|
131
|
+
s.listen(['handle-frame', frame('me-0001', 'm3', '做点什么')], { ...env, STUB_WORKER_FAIL: '1' });
|
|
132
|
+
assert.equal(hook.contents().at(-1), '没做成:退出码 1:执行者崩了');
|
|
134
133
|
});
|
|
135
134
|
|
|
136
|
-
test('listen
|
|
135
|
+
test('listen:路由没出决定(回了句看不懂的)时走兜底——原话直接当任务书交给执行者(只读),回执原样发回,不丢消息', async (t) => {
|
|
137
136
|
const s = setup(t);
|
|
138
137
|
const { hook, env } = await withHook(t, s);
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
// 执行者换成一条自定义命令:把它收到的参数原样打出来(回执就是这几行)
|
|
139
|
+
s.box.stub('echo-args', "process.stdout.write(process.argv.slice(2).join('\\n') + '\\n');");
|
|
140
|
+
s.roster({ workers: [{ agent: `${path.join(s.box.bin, 'echo-args')} --name "a b" 'c d'` }] });
|
|
141
|
+
const r = s.listen(['handle', '一句话'], { ...env, STUB_ROUTER_MODE: 'garbage' });
|
|
142
|
+
assert.equal(r.code, 0, r.out);
|
|
143
|
+
// 命令按空白拆开,引号里的算一个参数,任务书那句话跟在最后
|
|
144
|
+
assert.match(r.stdout, /要发给用户的话(没发;带 --push 才真发):\n\n--name\na b\nc d\n读 \.agents\/handoff\/t-\d{6}\.md(任务书),/);
|
|
145
|
+
const msg = JSON.parse(s.box.run(['trigger', 'list', '--json'], { env }).stdout).find((x) => x.kind === 'message');
|
|
146
|
+
assert.equal(msg.decision, 'fallback');
|
|
147
|
+
assert.equal(msg.worker.mode, 'plan', '兜底是只读的');
|
|
148
|
+
const pushed = s.listen(['handle-frame', frame('me-0001', 'm5', '再来一句')], { ...env, STUB_ROUTER_MODE: 'garbage' });
|
|
149
|
+
assert.equal(pushed.code, 0, pushed.out);
|
|
150
|
+
assert.match(hook.contents().at(-1), /^收到,正在处理,稍等。$|^--name\na b\nc d\n读 /);
|
|
151
|
+
assert.ok(hook.contents().at(-1).startsWith('--name\na b\nc d\n读 '), hook.contents().at(-1));
|
|
141
152
|
});
|
|
142
153
|
|
|
143
154
|
test('listen:回复超过 YZJ_BOT_REPLY_MAX 时截到上限并注明', async (t) => {
|
|
144
155
|
const s = setup(t);
|
|
145
156
|
const { hook, env } = await withHook(t, s);
|
|
146
|
-
s.listen(['handle-frame', frame('me-0001', 'm6', '
|
|
157
|
+
s.listen(['handle-frame', frame('me-0001', 'm6', '一二三四五')], { ...env, YZJ_BOT_REPLY_MAX: '3', YZJ_BOT_ACK: '0' });
|
|
147
158
|
const content = hook.contents().at(-1);
|
|
148
|
-
assert.equal(
|
|
149
|
-
assert.match(content, /截到 10 字/);
|
|
159
|
+
assert.equal(content, '一二三\n…(回复太长,截到 3 字)');
|
|
150
160
|
});
|
|
151
161
|
|
|
152
|
-
test('listen:/new
|
|
162
|
+
test('listen:/new 丢掉路由自己的专属会话,回一句确认,不惊动路由', async (t) => {
|
|
153
163
|
const s = setup(t);
|
|
154
164
|
const { hook, env } = await withHook(t, s);
|
|
155
|
-
s.
|
|
156
|
-
|
|
165
|
+
write(`${s.box.work}/01-inbox/_bot/session-id`, 'old-session\n');
|
|
166
|
+
const r = s.listen(['handle-frame', frame('me-0001', 'm7', '/new')], env);
|
|
167
|
+
assert.equal(r.code, 0, r.out);
|
|
168
|
+
assert.match(r.stdout, /已丢掉路由自己的专属会话,下一句从绑定的那个会话接着走。/);
|
|
169
|
+
assert.equal(hook.contents().at(-1), '已开新会话,下一句从绑定的那个会话接着走。');
|
|
170
|
+
assert.equal(exists(`${s.box.work}/01-inbox/_bot/session-id`), false);
|
|
157
171
|
assert.equal(s.agentCalls(), 0);
|
|
158
172
|
});
|
|
159
173
|
|
|
160
|
-
test('listen
|
|
174
|
+
test('listen:回复发不出去时照样处理完;/new 的那句确认发不出去就说一声', async (t) => {
|
|
161
175
|
const s = setup(t);
|
|
162
176
|
const hook = await webhook(t, { mode: 'http' });
|
|
163
177
|
const env = { ...s.bot, STUB_ROBOT_URL: hook.url };
|
|
164
178
|
const r = s.listen(['handle-frame', frame('me-0001', 'm1', '发不出去')], env);
|
|
165
179
|
assert.equal(r.code, 0, r.out);
|
|
166
|
-
assert.match(r.stdout,
|
|
167
|
-
assert.equal(s.agentCalls(),
|
|
168
|
-
|
|
180
|
+
assert.match(r.stdout, /msgId=m1 已交给路由/);
|
|
181
|
+
assert.equal(s.agentCalls(), 3);
|
|
182
|
+
const reset = s.listen(['handle-frame', frame('me-0001', 'm2', '/new')], env);
|
|
183
|
+
assert.equal(reset.code, 0, reset.out);
|
|
184
|
+
assert.match(reset.stdout, /已丢掉路由自己的专属会话,下一句从绑定的那个会话接着走,但这句没发出去。/);
|
|
185
|
+
assert.match(s.botLog(), /\/new 回复没发出去/);
|
|
169
186
|
});
|
|
170
187
|
|
|
171
188
|
test('listen:日志里不记消息内容', async (t) => {
|
|
@@ -173,16 +190,23 @@ test('listen:日志里不记消息内容', async (t) => {
|
|
|
173
190
|
const { env } = await withHook(t, s);
|
|
174
191
|
s.listen(['handle-frame', frame('me-0001', 'm10', '一句不该进日志的话')], env);
|
|
175
192
|
assert.match(s.botLog(), /msg 接受 msgId=m10/);
|
|
176
|
-
|
|
193
|
+
for (const log of [s.botLog(), read(`${s.box.work}/01-inbox/_rhythm.log`)]) assert.equal(log.includes('一句不该进日志的话'), false, log);
|
|
177
194
|
});
|
|
178
195
|
|
|
179
196
|
// ---------------------------------------------------------------- 配置
|
|
180
|
-
test('listen
|
|
197
|
+
test('listen:路由和执行者没配好时退出码为 3,说清怎么配', async (t) => {
|
|
181
198
|
const s = setup(t);
|
|
182
199
|
const { env } = await withHook(t, s);
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
assert.
|
|
200
|
+
write(`${s.box.work}/00-config/agents.json`, '');
|
|
201
|
+
const none = s.listen(['handle', 'x'], env);
|
|
202
|
+
assert.equal(none.code, 3);
|
|
203
|
+
assert.match(none.stderr, /路由和执行者的 agent 配得不对:路由 没绑 agent:work-rhythm agent bind router <名字>,或者在本机网页的 \/agents 里配;执行者 w1 没绑 agent:work-rhythm agent bind worker <名字>/);
|
|
204
|
+
assert.equal(s.listen(['handle-frame', frame('me-0001', 'm1', 'x')], env).code, 3);
|
|
205
|
+
// 配了一个找不到的命令
|
|
206
|
+
s.roster({ router: '/nonexistent/agent' });
|
|
207
|
+
const bad = s.listen(['handle', 'x'], env);
|
|
208
|
+
assert.equal(bad.code, 3);
|
|
209
|
+
assert.match(bad.stderr, /路由和执行者的 agent 配得不对:路由(\/nonexistent\/agent):自定义命令找不到: \/nonexistent\/agent/);
|
|
186
210
|
});
|
|
187
211
|
|
|
188
212
|
test('listen:没配 YZJ_MY_OPEN_ID 时退出码为 3', async (t) => {
|
|
@@ -214,31 +238,36 @@ test('listen:消息不带外层、直接是业务消息的写法也认', async
|
|
|
214
238
|
const s = setup(t);
|
|
215
239
|
const { hook, env } = await withHook(t, s);
|
|
216
240
|
const r = s.listen(['handle-frame', JSON.stringify({ type: 2, robotId: 'BOT-bot', robotName: '工作王', operatorOpenid: 'me-0001', operatorName: '自测', time: 1764510000000, msgId: 'm9', content: '不带外层的写法', groupType: 3 })], env);
|
|
217
|
-
assert.match(r.stdout,
|
|
218
|
-
assert.equal(hook.contents().at(-1), '
|
|
241
|
+
assert.match(r.stdout, /msgId=m9 已交给路由/);
|
|
242
|
+
assert.equal(hook.contents().at(-1), '不带外层的写法');
|
|
219
243
|
});
|
|
220
244
|
|
|
221
245
|
test('listen:配置写在 collectors/local.env 里也读得到', async (t) => {
|
|
222
246
|
const s = setup(t);
|
|
223
247
|
const { env } = await withHook(t, s);
|
|
248
|
+
write(`${s.box.work}/00-config/agents.json`, '');
|
|
224
249
|
write(`${s.box.work}/collectors/local.env`, `YZJ_MY_OPEN_ID="me-0001"\nYZJ_BOT_AGENT="${path.join(s.box.bin, 'fake-agent')}"\n`);
|
|
225
250
|
// 命令行上的同名变量给了别的值:local.env 里的为准(和原来 source 的效果一样)
|
|
226
251
|
const r = s.listen(['handle', '写在配置里'], { ...env, YZJ_BOT_AGENT: '/nonexistent-from-env' });
|
|
227
252
|
assert.equal(r.code, 0, r.out);
|
|
228
|
-
assert.
|
|
253
|
+
assert.match(r.stdout, /\n\n写在配置里\n$/);
|
|
229
254
|
});
|
|
230
255
|
|
|
231
256
|
test('listen doctor:问题逐条报出来,退出码为 1;配好了什么都不说', async (t) => {
|
|
232
257
|
const s = setup(t);
|
|
233
258
|
const { env } = await withHook(t, s);
|
|
234
259
|
s.setNotify('""');
|
|
235
|
-
const bad = s.listen(['doctor'], { ...env, STUB_KEYCHAIN: 'no', YZJ_MY_OPEN_ID: ''
|
|
260
|
+
const bad = s.listen(['doctor'], { ...env, STUB_KEYCHAIN: 'no', YZJ_MY_OPEN_ID: '' });
|
|
236
261
|
assert.equal(bad.code, 1);
|
|
237
262
|
assert.match(bad.stdout, /值守属于 yzj-robot 渠道/);
|
|
238
263
|
assert.match(bad.stdout, /钥匙串里没有 work-rhythm-yzj-robot-webhook/);
|
|
239
264
|
assert.match(bad.stdout, /要写 YZJ_MY_OPEN_ID/);
|
|
240
|
-
assert.match(bad.stdout, /YZJ_BOT_AGENT 的命令找不到: \/nonexistent\/agent/);
|
|
241
265
|
s.setNotify('"yzj-robot"');
|
|
266
|
+
s.roster({ router: '/nonexistent/agent' });
|
|
267
|
+
const agent = s.listen(['doctor'], env);
|
|
268
|
+
assert.equal(agent.code, 1);
|
|
269
|
+
assert.match(agent.stdout, /路由(\/nonexistent\/agent):自定义命令找不到: \/nonexistent\/agent/);
|
|
270
|
+
s.roster();
|
|
242
271
|
const ok = s.listen(['doctor'], env);
|
|
243
272
|
assert.equal(ok.code, 0, ok.out);
|
|
244
273
|
assert.equal(ok.stdout, '');
|
|
@@ -257,166 +286,169 @@ test('listen:用法不对时退出码为 2,并告诉它用法在哪;--help
|
|
|
257
286
|
assert.match(r.stdout, /handle-frame/);
|
|
258
287
|
});
|
|
259
288
|
|
|
260
|
-
test('listen reset
|
|
289
|
+
test('listen reset:丢掉路由自己的专属会话', async (t) => {
|
|
261
290
|
const s = setup(t);
|
|
262
291
|
const { env } = await withHook(t, s);
|
|
263
292
|
write(`${s.box.work}/01-inbox/_bot/session-id`, 'old-session\n');
|
|
264
293
|
const r = s.listen(['reset'], env);
|
|
265
294
|
assert.equal(r.code, 0);
|
|
266
|
-
assert.match(r.stdout,
|
|
295
|
+
assert.match(r.stdout, /已丢掉路由自己的专属会话/);
|
|
267
296
|
assert.equal(exists(`${s.box.work}/01-inbox/_bot/session-id`), false);
|
|
268
297
|
});
|
|
269
298
|
|
|
270
|
-
// ----------------------------------------------------------------
|
|
271
|
-
//
|
|
272
|
-
function
|
|
273
|
-
return { ...s.stubs, ...s.bot
|
|
299
|
+
// ---------------------------------------------------------------- 预置:路由只读、执行者可写,第二轮用路由自己的会话接上
|
|
300
|
+
// 在工作目录里无界面运行:路由那轮是 plan,执行者那轮是 edit
|
|
301
|
+
function preset(s, name) {
|
|
302
|
+
return { ...s.stubs, ...s.bot };
|
|
274
303
|
}
|
|
275
304
|
const real = (s) => fs.realpathSync(s.box.work);
|
|
305
|
+
// 假的命令行把每次调用的参数记成一行,提示词里有换行:按参数的开头把记录切成一次一次
|
|
306
|
+
const callsOf = (text, head) => text.split(/\n(?=--)/).map((l) => l.trim()).filter((l) => l.startsWith(head));
|
|
276
307
|
|
|
277
|
-
test('listen:zcode
|
|
278
|
-
const s = setup(t);
|
|
279
|
-
const env = zcode(s);
|
|
280
|
-
s.listen(['reset'], env);
|
|
281
|
-
const r = s.listen(['handle', '第一句'], env);
|
|
282
|
-
assert.equal(r.code, 0, r.out);
|
|
283
|
-
assert.match(r.stdout, /回复:第一句/);
|
|
284
|
-
assert.match(r.stdout, /这句来自云之家/);
|
|
285
|
-
const args = read(s.stubs.STUB_ZCODE_ARGS);
|
|
286
|
-
assert.ok(args.includes(`--cwd ${real(s)} --mode plan --no-color --json -p 第一句`), args);
|
|
287
|
-
assert.ok(!args.includes('--resume'), args);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
test('listen:zcode 预置第二轮用机器人的专属会话接上', async (t) => {
|
|
308
|
+
test('listen:zcode 预置——路由以 plan 模式判一次,执行者以 edit 模式做,第二轮路由用自己的专属会话接上', async (t) => {
|
|
291
309
|
const s = setup(t);
|
|
292
|
-
const env =
|
|
293
|
-
s.
|
|
294
|
-
s.listen(['handle', '
|
|
295
|
-
assert.
|
|
310
|
+
const { hook, env } = await withHook(t, s);
|
|
311
|
+
s.roster({ router: 'zcode', workers: [{ agent: 'zcode' }] });
|
|
312
|
+
const first = s.listen(['handle', '第一句'], env);
|
|
313
|
+
assert.equal(first.code, 0, first.out);
|
|
314
|
+
assert.match(first.stdout, /\n\n第一句\n$/);
|
|
315
|
+
const calls = callsOf(read(s.stubs.STUB_ZCODE_ALL), '--cwd ');
|
|
316
|
+
assert.equal(calls.length, 3, calls.map((c) => c.slice(0, 80)).join('\n'));
|
|
317
|
+
// 路由第一轮:只读,提示词是「【work-rhythm 路由】」;不带 --resume
|
|
318
|
+
assert.ok(calls[0].startsWith(`--cwd ${real(s)} --mode plan --no-color --json -p 【work-rhythm 路由】`), calls[0]);
|
|
319
|
+
assert.ok(!calls[0].includes('--resume'), calls[0]);
|
|
320
|
+
// 执行者:可写工作目录,读任务书那句话
|
|
321
|
+
assert.ok(calls[1].startsWith(`--cwd ${real(s)} --mode edit --no-color --json -p 读 .agents/handoff/t-`), calls[1]);
|
|
322
|
+
// 路由第二轮(看回执):接着它自己这一轮开的会话
|
|
323
|
+
assert.ok(calls[2].startsWith(`--cwd ${real(s)} --mode plan --resume sess_fake --no-color --json -p 【work-rhythm 路由】`), calls[2]);
|
|
296
324
|
assert.equal(s.session(), 'sess_fake');
|
|
325
|
+
// 下一件事还是从这个会话接着走
|
|
326
|
+
s.listen(['handle', '第二句'], env);
|
|
327
|
+
assert.ok(read(s.stubs.STUB_ZCODE_ALL).includes('--mode plan --resume sess_fake --no-color --json -p 【work-rhythm 路由】'));
|
|
328
|
+
assert.equal(hook.requests().length, 0, '不带 --push 不发');
|
|
297
329
|
});
|
|
298
330
|
|
|
299
|
-
test('listen:zcode 预置遇到 /new
|
|
331
|
+
test('listen:zcode 预置遇到 /new 丢掉专属会话,下一件事重新开一个', async (t) => {
|
|
300
332
|
const s = setup(t);
|
|
301
|
-
const env =
|
|
333
|
+
const { env } = await withHook(t, s);
|
|
334
|
+
s.roster({ router: 'zcode', workers: [{ agent: 'zcode' }] });
|
|
302
335
|
s.listen(['handle', '第一句'], env);
|
|
336
|
+
write(s.stubs.STUB_ZCODE_ALL, '');
|
|
303
337
|
s.listen(['handle-frame', frame('me-0001', 'm8', '/new')], env);
|
|
304
338
|
assert.equal(exists(`${s.box.work}/01-inbox/_bot/session-id`), false);
|
|
339
|
+
s.listen(['handle', '第二句'], env);
|
|
340
|
+
assert.ok(!callsOf(read(s.stubs.STUB_ZCODE_ALL), '--cwd ')[0].includes('--resume'), '重开之后第一轮不带 --resume');
|
|
305
341
|
});
|
|
306
342
|
|
|
307
343
|
test('listen:ZCODE_CLI 指的文件不存在时退出码为 3', async (t) => {
|
|
308
344
|
const s = setup(t);
|
|
309
|
-
const env =
|
|
310
|
-
|
|
345
|
+
const { env } = await withHook(t, s);
|
|
346
|
+
s.roster({ router: 'zcode', workers: [{ agent: 'zcode' }] });
|
|
347
|
+
assert.equal(s.listen(['handle', 'x'], { ...env, ZCODE_CLI: '/nonexistent' }).code, 3);
|
|
311
348
|
});
|
|
312
349
|
|
|
313
|
-
|
|
314
|
-
// 用 DSH 自带的 Node 跑它的 headless 模式,带一份只含模型配置、并打开凭据存储的覆盖文件。
|
|
315
|
-
// 模型和凭据跟着 DSH 桌面应用里的配置走,这份覆盖文件是值守从那份配置里摘出来的
|
|
316
|
-
function dsh(s) {
|
|
317
|
-
return { ...s.stubs, ...s.bot, YZJ_BOT_AGENT: 'dsh' };
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
test('listen:dsh 预置用 DSH 自带的 Node 以 headless 模式跑,覆盖文件只带模型配置并打开凭据存储,默认只读', async (t) => {
|
|
350
|
+
test('listen:dsh 预置——路由 read-only,执行者 workspace-write,覆盖文件只带模型配置并打开凭据存储', async (t) => {
|
|
321
351
|
const s = setup(t);
|
|
322
|
-
const env =
|
|
323
|
-
|
|
324
|
-
s.listen(['reset'], env);
|
|
352
|
+
const { env } = await withHook(t, s);
|
|
353
|
+
s.roster({ router: 'dsh', workers: [{ agent: 'dsh' }] });
|
|
325
354
|
const r = s.listen(['handle', '第一句'], env);
|
|
326
355
|
assert.equal(r.code, 0, r.out);
|
|
327
|
-
assert.match(r.stdout,
|
|
328
|
-
|
|
356
|
+
assert.match(r.stdout, /\n\n第一句\n$/);
|
|
357
|
+
const calls = callsOf(read(s.stubs.STUB_DSH_ALL), '--profile ');
|
|
358
|
+
assert.equal(calls.length, 3, calls.map((c) => c.slice(0, 80)).join('\n'));
|
|
359
|
+
assert.ok(calls[0].includes('--profile headless --patch') && calls[0].includes('--permission-mode read-only --json 【work-rhythm 路由】'), calls[0]);
|
|
360
|
+
assert.ok(calls[1].includes('--permission-mode workspace-write --json 读 .agents/handoff/t-'), calls[1]);
|
|
361
|
+
assert.ok(calls[2].includes('--permission-mode read-only --session-id session_fake --json 【work-rhythm 路由】'), calls[2]);
|
|
329
362
|
assert.equal(read(s.stubs.STUB_DSH_ENV), `run_as_node=1 dsh_home=${s.stubs.DSH_HOME}\n`);
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
assert.ok(
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
test('listen:dsh 预置第二轮用专属会话接上;模式写 edit 就是允许改工作目录', async (t) => {
|
|
336
|
-
const s = setup(t);
|
|
337
|
-
const env = dsh(s);
|
|
338
|
-
s.listen(['handle', '第一句'], env);
|
|
339
|
-
s.listen(['handle', '第二句'], { ...env, YZJ_BOT_AGENT_MODE: 'edit' });
|
|
340
|
-
assert.ok(read(s.stubs.STUB_DSH_ARGS).includes('--permission-mode workspace-write --session-id session_fake --json 第二句'), read(s.stubs.STUB_DSH_ARGS));
|
|
363
|
+
assert.equal(read(`${s.stubs.STUB_DSH_ARGS}.cwd`).trim(), real(s), '以工作目录为 cwd');
|
|
364
|
+
const patch = read(calls[0].match(/--patch (\S+)/)[1]);
|
|
365
|
+
for (const need of ['- id: credentials', ' disabled: false', '- id: agent-default-model', '- id: llm-pi-ai']) assert.ok(patch.includes(need), `${need} 不在覆盖文件里`);
|
|
366
|
+
assert.ok(!patch.includes('ui-theme'), '无关的条目不该带进去');
|
|
341
367
|
assert.equal(s.session(), 'session_fake');
|
|
342
368
|
});
|
|
343
369
|
|
|
344
|
-
test('listen handle:dsh
|
|
370
|
+
test('listen handle:dsh 的 final 事件说没跑完时——路由和执行者都失败,走兜底把原因告诉我,不沉默', async (t) => {
|
|
345
371
|
const s = setup(t);
|
|
346
|
-
const env =
|
|
347
|
-
|
|
372
|
+
const { hook, env } = await withHook(t, s);
|
|
373
|
+
s.roster({ router: 'dsh', workers: [{ agent: 'dsh' }] });
|
|
374
|
+
const r = s.listen(['handle', '出错的一句'], { ...env, STUB_DSH_FINAL: 'error' });
|
|
375
|
+
assert.equal(r.code, 0, r.out);
|
|
376
|
+
assert.match(r.stdout, /「t-\d{6}」没跑完:没跑完:error\n$/);
|
|
377
|
+
assert.deepEqual(hook.requests(), []);
|
|
348
378
|
});
|
|
349
379
|
|
|
350
380
|
test('listen:找不到 DSH 的配置时退出码为 3', async (t) => {
|
|
351
381
|
const s = setup(t);
|
|
352
|
-
const env =
|
|
353
|
-
|
|
382
|
+
const { env } = await withHook(t, s);
|
|
383
|
+
s.roster({ router: 'dsh', workers: [{ agent: 'dsh' }] });
|
|
384
|
+
const r = s.listen(['handle', 'x'], { ...env, DSH_HOME: path.join(s.box.root, 'no-such-home') });
|
|
354
385
|
assert.equal(r.code, 3);
|
|
355
386
|
assert.match(r.stderr, /找不到 DSH 的配置/);
|
|
356
387
|
});
|
|
357
388
|
|
|
358
|
-
|
|
359
|
-
const s = setup(t);
|
|
360
|
-
const { env } = await withHook(t, s);
|
|
361
|
-
// 假的 agent 把收到的参数一行一个记下来
|
|
362
|
-
s.box.stub('echo-args', "process.stdout.write(process.argv.slice(2).join('\\n') + '\\n');");
|
|
363
|
-
const r = s.listen(['handle', '一句话'], { ...env, YZJ_BOT_AGENT: `${path.join(s.box.bin, 'echo-args')} --name "a b" 'c d'` });
|
|
364
|
-
assert.equal(r.code, 0, r.out);
|
|
365
|
-
assert.equal(r.stdout, '--name\na b\nc d\n一句话\n');
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
// ---------------------------------------------------------------- 会话:接着绑定的那个走
|
|
389
|
+
// ---------------------------------------------------------------- 会话:路由接着绑定的那个走
|
|
369
390
|
function botReady(s, hook, localEnv) {
|
|
370
391
|
s.setNotify('"yzj-robot"');
|
|
371
392
|
write(`${s.box.work}/collectors/local.env`, localEnv);
|
|
372
|
-
|
|
393
|
+
s.roster({ router: 'dsh', workers: [{ agent: 'dsh' }] });
|
|
394
|
+
return { ...s.stubs, STUB_KEYCHAIN: 'ok', STUB_ROBOT_URL: hook.url };
|
|
373
395
|
}
|
|
396
|
+
// 一轮里 dsh 被调用三次:路由、执行者、路由。只看路由那两次的参数
|
|
397
|
+
const routerCalls = (s) => callsOf(read(s.stubs.STUB_DSH_ALL), '--profile ').filter((l) => l.includes('【work-rhythm 路由】'));
|
|
374
398
|
|
|
375
|
-
test('listen:绑了会话(
|
|
399
|
+
test('listen:绑了会话(YZJ_ROUTER_SESSION)时,路由的每一轮都从那个会话接着走,不用它自己的', async (t) => {
|
|
376
400
|
const hook = await webhook(t);
|
|
377
401
|
const s = setup(t);
|
|
378
|
-
const env = botReady(s, hook, 'YZJ_MY_OPEN_ID="me-0001"\
|
|
402
|
+
const env = botReady(s, hook, 'YZJ_MY_OPEN_ID="me-0001"\nYZJ_ROUTER_SESSION="session-desktop"\n');
|
|
379
403
|
const first = s.listen(['handle', '第一句'], env);
|
|
380
404
|
assert.equal(first.code, 0, first.out);
|
|
381
|
-
|
|
405
|
+
const calls = routerCalls(s);
|
|
406
|
+
assert.equal(calls.length, 2);
|
|
407
|
+
for (const c of calls) assert.match(c, /--session-id session-desktop --json 【work-rhythm 路由】/, c);
|
|
408
|
+
assert.equal(s.session(), '', '绑了会话就不用自己的');
|
|
382
409
|
s.listen(['handle', '第二句'], env);
|
|
383
|
-
|
|
384
|
-
assert.
|
|
410
|
+
assert.equal(routerCalls(s).length, 4);
|
|
411
|
+
assert.ok(routerCalls(s).every((c) => c.includes('--session-id session-desktop')));
|
|
385
412
|
});
|
|
386
413
|
|
|
387
|
-
test('listen
|
|
414
|
+
test('listen:绑定的会话接不上时退回路由自己的专属会话,以后不再去试那个绑定的;/new 之后又从绑定的开始', async (t) => {
|
|
388
415
|
const hook = await webhook(t);
|
|
389
416
|
const s = setup(t);
|
|
390
|
-
const env = { ...botReady(s, hook, 'YZJ_MY_OPEN_ID="me-0001"\
|
|
417
|
+
const env = { ...botReady(s, hook, 'YZJ_MY_OPEN_ID="me-0001"\nYZJ_ROUTER_SESSION="session-gone"\n'), STUB_DSH_REJECT_SESSION: 'session-gone' };
|
|
391
418
|
// 第一句:先试绑定的(被拒),改开新会话(fake 回 session_fake),记下来
|
|
392
419
|
const first = s.listen(['handle', '第一句'], env);
|
|
393
420
|
assert.equal(first.code, 0, first.out);
|
|
394
421
|
assert.equal(s.session(), 'session_fake');
|
|
395
|
-
assert.match(s.
|
|
396
|
-
// 第二句:直接用自己的 session_fake
|
|
422
|
+
assert.match(read(`${s.box.work}/01-inbox/_rhythm.log`), /agent 接不上旧会话,改开新会话/);
|
|
423
|
+
// 第二句:直接用自己的 session_fake,不再碰绑定的
|
|
424
|
+
write(s.stubs.STUB_DSH_ALL, '');
|
|
397
425
|
s.listen(['handle', '第二句'], env);
|
|
398
|
-
assert.
|
|
399
|
-
assert.equal(s.
|
|
426
|
+
assert.ok(routerCalls(s).every((c) => c.includes('--session-id session_fake --json')), routerCalls(s).join('\n'));
|
|
427
|
+
assert.equal(read(`${s.box.work}/01-inbox/_rhythm.log`).split('agent 接不上旧会话').length - 1, 1);
|
|
400
428
|
assert.equal(exists(`${s.box.work}/01-inbox/_bot/bound-session-lost`), true, '接不上这件事要记下来,下一个进程才知道');
|
|
401
429
|
// /new:丢掉自己的,下一句又从绑定的开始(绑定的还是接不上,就再退回来)
|
|
402
|
-
const reset = s.listen(['handle-frame',
|
|
403
|
-
assert.equal(reset.code, 0);
|
|
404
|
-
assert.equal(hook.contents().at(-1), '
|
|
430
|
+
const reset = s.listen(['handle-frame', frame('me-0001', 'n1', '/new')], env);
|
|
431
|
+
assert.equal(reset.code, 0, reset.out);
|
|
432
|
+
assert.equal(hook.contents().at(-1), '已开新会话,下一句从绑定的那个会话接着走。');
|
|
433
|
+
write(s.stubs.STUB_DSH_ALL, '');
|
|
405
434
|
s.listen(['handle', '第三句'], env);
|
|
406
435
|
assert.equal(s.session(), 'session_fake');
|
|
407
|
-
assert.equal(s
|
|
436
|
+
assert.equal(routerCalls(s)[0].includes('--session-id session-gone'), true, '第三句又试了绑定的那个(/new 把记录清了)');
|
|
437
|
+
assert.equal(read(`${s.box.work}/01-inbox/_rhythm.log`).split('agent 接不上旧会话').length - 1, 2);
|
|
408
438
|
// 换绑一个会话(agent session <id>):记录也清掉,下一句从新绑的开始
|
|
409
439
|
s.box.run(['agent', 'session', 'session-desktop2'], { env });
|
|
410
440
|
assert.equal(exists(`${s.box.work}/01-inbox/_bot/bound-session-lost`), false);
|
|
441
|
+
write(s.stubs.STUB_DSH_ALL, '');
|
|
442
|
+
s.listen(['handle', '第四句'], env);
|
|
443
|
+
assert.ok(routerCalls(s)[0].includes('--session-id session-desktop2'));
|
|
411
444
|
});
|
|
412
445
|
|
|
413
446
|
test('listen install / uninstall / status:值守跑在本地服务那一个进程里——开关写进 local.env,老的单独常驻收掉,服务没装就装', (t) => {
|
|
414
447
|
const s = setup(t);
|
|
415
|
-
s.setNotify('"yzj-robot"');
|
|
416
|
-
write(`${s.box.work}/collectors/local.env`, 'YZJ_MY_OPEN_ID="me-0001"\nYZJ_BOT_AGENT="dsh"\n');
|
|
417
448
|
const home = path.join(s.box.root, 'home');
|
|
418
449
|
fs.mkdirSync(path.join(home, 'Library', 'LaunchAgents'), { recursive: true });
|
|
419
450
|
const env = { ...s.stubs, HOME: home, STUB_KEYCHAIN: 'ok', STUB_LAUNCHCTL_RUNNING: '1', STUB_ROBOT_URL: 'http://127.0.0.1:1/send?yzjtoken=stubtoken0123456789abcd' };
|
|
451
|
+
write(`${s.box.work}/collectors/local.env`, 'YZJ_MY_OPEN_ID="me-0001"\n');
|
|
420
452
|
const agents = path.join(home, 'Library', 'LaunchAgents');
|
|
421
453
|
// 老的单独常驻还在:install 要把它收掉
|
|
422
454
|
write(path.join(agents, 'work-rhythm.bot.work.plist'), '<plist/>');
|
|
@@ -443,8 +475,8 @@ test('listen install / uninstall / status:值守跑在本地服务那一个进
|
|
|
443
475
|
assert.match(read(`${s.box.work}/collectors/local.env`), /^YZJ_BOT_LISTEN="0"$/m);
|
|
444
476
|
assert.match(read(s.stubs.STUB_LAUNCHCTL), /bootout gui\/\d+\/work-rhythm\.bot\.work\nkickstart -k gui\/\d+\/work-rhythm\.service\.work\n/);
|
|
445
477
|
assert.equal(s.listen(['status'], { ...env, STUB_LAUNCHCTL_RUNNING: '1' }).stdout, '本地服务在跑(work-rhythm rhythm status 看详情);值守关着。\n');
|
|
446
|
-
//
|
|
447
|
-
write(`${s.box.work}/collectors/local.env`, '
|
|
478
|
+
// 配置不齐不让开:开关都不写(这里只差 openId)
|
|
479
|
+
write(`${s.box.work}/collectors/local.env`, 'YZJ_BOT_LISTEN="0"\n');
|
|
448
480
|
const bad = s.listen(['install'], env);
|
|
449
481
|
assert.equal(bad.code, 3);
|
|
450
482
|
assert.ok(!/YZJ_BOT_LISTEN=1/.test(read(`${s.box.work}/collectors/local.env`)));
|
|
@@ -452,12 +484,12 @@ test('listen install / uninstall / status:值守跑在本地服务那一个进
|
|
|
452
484
|
|
|
453
485
|
test('listen:agent 是在工作目录里跑的(dsh 的 cwd、zcode / qoder / claude 的 --cwd 都是工作目录)', async (t) => {
|
|
454
486
|
const s = setup(t);
|
|
455
|
-
const env = { ...
|
|
487
|
+
const env = { ...s.bot, QODER_CLI: path.join(s.box.bin, 'fake-qoder'), CLAUDE_CLI: path.join(s.box.bin, 'fake-claude') };
|
|
456
488
|
for (const name of ['dsh', 'zcode', 'qoder', 'claude']) {
|
|
457
|
-
|
|
489
|
+
s.roster({ router: name, workers: [{ agent: name }] });
|
|
458
490
|
const r = s.listen(['handle', '在吗'], env);
|
|
459
491
|
assert.equal(r.code, 0, `${name}: ${r.out}`);
|
|
460
|
-
if (name === 'dsh') assert.equal(read(`${s.stubs.STUB_DSH_ARGS}.cwd`).trim(),
|
|
461
|
-
else assert.ok(read(s.stubs[`STUB_${name.toUpperCase()}_ARGS`]).startsWith(`--cwd ${
|
|
492
|
+
if (name === 'dsh') assert.equal(read(`${s.stubs.STUB_DSH_ARGS}.cwd`).trim(), real(s));
|
|
493
|
+
else assert.ok(read(s.stubs[`STUB_${name.toUpperCase()}_ARGS`]).startsWith(`--cwd ${real(s)} `), `${name} 的 --cwd`);
|
|
462
494
|
}
|
|
463
495
|
});
|