work-rhythm 0.1.5 → 0.1.7
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 +2 -0
- package/.agents/notes/decisions/2026-11-30-bot-inbound-uses-websocket-and-a-responder-command.md +1 -0
- package/.agents/notes/decisions/2026-11-30-scheduling-moves-to-a-local-service.md +1 -0
- package/.agents/notes/decisions/2026-12-01-binding-carries-the-current-session.md +29 -0
- package/.agents/notes/decisions/2026-12-01-bot-lives-in-the-service-process.md +28 -0
- package/.agents/notes/decisions/2026-12-01-repo-is-not-a-workdir-templates-hold-workdir-files.md +1 -0
- package/.agents/notes/decisions/2026-12-01-scheduling-is-cli-only-and-needs-a-bound-agent.md +1 -0
- package/.agents/skills/work-rhythm/SKILL.md +2 -2
- package/README.md +16 -7
- package/collectors/local.env.example +6 -1
- package/docs/agents.md +10 -1
- package/docs/channels.md +5 -2
- package/docs/scheduled-tasks.md +1 -1
- package/package.json +1 -1
- package/scripts/cmd/agent.js +71 -7
- package/scripts/cmd/check.js +2 -1
- package/scripts/cmd/listen.js +46 -14
- package/scripts/cmd/rhythm.js +12 -2
- package/scripts/lib/agent.js +47 -9
- package/scripts/lib/bot.js +61 -7
- package/scripts/lib/config.js +22 -1
- package/scripts/lib/launchd.js +8 -1
- package/scripts/lib/rhythm.js +33 -2
- package/scripts/test/agent.test.js +80 -1
- package/scripts/test/harness.js +1 -0
- package/scripts/test/listen.test.js +97 -0
- package/scripts/test/rhythm.test.js +65 -0
- package/scripts/test/stubs.js +11 -1
|
@@ -352,3 +352,68 @@ test('rhythm:profile 的 agent-model / agent-effort 给定时任务另配一
|
|
|
352
352
|
assert.equal(s.rhythm(['run', 'daily-plan'], env).code, 0);
|
|
353
353
|
assert.match(read(`${s.box.work}/01-inbox/_rhythm/dsh-headless.patch.yml`), / model: deepseek-v4\.1-flash\n reasoningEffort: high\n/);
|
|
354
354
|
});
|
|
355
|
+
|
|
356
|
+
// ---------------------------------------------------------------- 值守跟着服务一起跑
|
|
357
|
+
test('rhythm:YZJ_BOT_LISTEN=1 时值守在服务的同一个进程里跑;配置不齐只记一笔,服务照常;status 里看得到', async (t) => {
|
|
358
|
+
const hook = await webhook(t);
|
|
359
|
+
const s = setup(t);
|
|
360
|
+
const port = await freePort();
|
|
361
|
+
s.set('port', String(port));
|
|
362
|
+
const profile = `${s.box.work}/00-config/profile.yaml`;
|
|
363
|
+
write(profile, read(profile).replace(/^ notify:.*$/m, ' notify: "yzj-robot"'));
|
|
364
|
+
write(`${s.box.work}/collectors/local.env`, 'YZJ_BOT_AGENT="dsh"\n');
|
|
365
|
+
const botEnv = { ...s.env, STUB_ROBOT_URL: 'wss://127.0.0.1:1/xuntong/websocket?yzjtoken=stubtoken0123456789abcd' };
|
|
366
|
+
// 值守开着、配置齐:服务日志里有「值守开始」,同一个 pid;机器人连不上(假地址)只是重连,不影响服务和网页
|
|
367
|
+
const proc = s.box.spawn(['rhythm', 'start', '--tick', '1'], { env: { ...botEnv, YZJ_BOT_LISTEN: '1', YZJ_MY_OPEN_ID: 'me-0001' } });
|
|
368
|
+
t.after(async () => {
|
|
369
|
+
s.rhythm(['stop'], botEnv);
|
|
370
|
+
await proc.exited;
|
|
371
|
+
});
|
|
372
|
+
assert.ok(await proc.waitFor('页面:'), proc.text());
|
|
373
|
+
assert.ok(await proc.waitFor('值守开始', 8000), proc.text());
|
|
374
|
+
const servicePid = read(`${s.box.work}/01-inbox/_rhythm/service.pid`).trim();
|
|
375
|
+
const botLog = read(`${s.box.work}/01-inbox/_bot.log`);
|
|
376
|
+
assert.match(botLog, new RegExp(`值守开始 pid=${servicePid} agent=dsh mode=plan`), '值守和服务是同一个进程');
|
|
377
|
+
assert.match(botLog, /会话=值守自己的专属会话/);
|
|
378
|
+
assert.equal((await fetch(`http://127.0.0.1:${port}/`)).status, 200);
|
|
379
|
+
assert.match(s.rhythm(['status'], { ...botEnv, YZJ_BOT_LISTEN: '1' }).stdout, /值守:开着,最近 .*/);
|
|
380
|
+
assert.match(s.rhythm(['doctor'], { ...botEnv, YZJ_BOT_LISTEN: '1', YZJ_MY_OPEN_ID: 'me-0001' }).stdout, /^$/);
|
|
381
|
+
// 关着的时候什么都不起
|
|
382
|
+
assert.match(s.rhythm(['status'], botEnv).stdout, /值守:关着/);
|
|
383
|
+
// 配置不齐(没写我的 openId):doctor 报出来;服务照样起,只记「值守没开」
|
|
384
|
+
const bad = s.rhythm(['doctor'], { ...botEnv, YZJ_BOT_LISTEN: '1', YZJ_MY_OPEN_ID: '' });
|
|
385
|
+
assert.equal(bad.code, 1);
|
|
386
|
+
assert.match(bad.stdout, /值守只处理我本人的消息:collectors\/local\.env 里要写 YZJ_MY_OPEN_ID/);
|
|
387
|
+
// 先把前一个停掉,再起一个配置不齐的
|
|
388
|
+
s.rhythm(['stop'], botEnv);
|
|
389
|
+
await proc.exited;
|
|
390
|
+
const proc2 = s.box.spawn(['rhythm', 'start', '--tick', '1'], { env: { ...botEnv, YZJ_BOT_LISTEN: '1', YZJ_MY_OPEN_ID: '' } });
|
|
391
|
+
t.after(async () => {
|
|
392
|
+
s.rhythm(['stop'], botEnv);
|
|
393
|
+
await proc2.exited;
|
|
394
|
+
});
|
|
395
|
+
assert.ok(await proc2.waitFor('页面:'), proc2.text());
|
|
396
|
+
assert.ok(await proc2.waitFor('值守没开', 8000), proc2.text());
|
|
397
|
+
assert.equal((await fetch(`http://127.0.0.1:${port}/`)).status, 200);
|
|
398
|
+
s.rhythm(['stop'], botEnv);
|
|
399
|
+
await proc2.exited;
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
test('rhythm install:装的是服务那一个常驻,老的单独值守常驻顺手收掉;restart 在 launchd 管着时重启', (t) => {
|
|
403
|
+
const s = setup(t);
|
|
404
|
+
const home = path.join(s.box.root, 'home');
|
|
405
|
+
const agents = path.join(home, 'Library', 'LaunchAgents');
|
|
406
|
+
fs.mkdirSync(agents, { recursive: true });
|
|
407
|
+
write(path.join(agents, 'work-rhythm.bot.work.plist'), '<plist/>');
|
|
408
|
+
const env = { ...s.env, HOME: home };
|
|
409
|
+
assert.equal(s.rhythm(['install'], env).code, 0, s.rhythm(['install'], env).out);
|
|
410
|
+
assert.ok(exists(path.join(agents, 'work-rhythm.service.work.plist')));
|
|
411
|
+
assert.equal(exists(path.join(agents, 'work-rhythm.bot.work.plist')), false, '老的单独值守常驻收掉');
|
|
412
|
+
assert.match(read(s.env.STUB_LAUNCHCTL), /bootout gui\/\d+\/work-rhythm\.bot\.work\n/);
|
|
413
|
+
const restart = s.rhythm(['restart'], env);
|
|
414
|
+
assert.equal(restart.code, 3, 'launchd 说没在跑就不重启');
|
|
415
|
+
assert.match(restart.stderr, /服务不是 launchd 管的常驻/);
|
|
416
|
+
const again = s.rhythm(['restart'], { ...env, STUB_LAUNCHCTL_RUNNING: '1' });
|
|
417
|
+
assert.equal(again.code, 0, again.out);
|
|
418
|
+
assert.match(read(s.env.STUB_LAUNCHCTL), /kickstart -k gui\/\d+\/work-rhythm\.service\.work\n$/);
|
|
419
|
+
});
|
package/scripts/test/stubs.js
CHANGED
|
@@ -122,10 +122,18 @@ const fs = require('node:fs');
|
|
|
122
122
|
const { spawnSync } = require('node:child_process');
|
|
123
123
|
const args = process.argv.slice(2);
|
|
124
124
|
fs.writeFileSync(process.env.STUB_DSH_ENV || '/dev/null', 'run_as_node=' + (process.env.ELECTRON_RUN_AS_NODE || '') + ' dsh_home=' + (process.env.DSH_HOME || '') + '\\n');
|
|
125
|
+
fs.writeFileSync((process.env.STUB_DSH_ARGS || '/dev/null') + '.cwd', process.cwd() + '\\n');
|
|
125
126
|
const r = spawnSync(process.execPath, [args[2], ...args.slice(3)], { stdio: 'inherit' });
|
|
126
127
|
process.exit(r.status === null ? 1 : r.status);
|
|
127
128
|
`;
|
|
128
129
|
|
|
130
|
+
// 假的 launchctl:把每次调用记进 STUB_LAUNCHCTL(一行一次),不真的动 launchd。print 在 STUB_LAUNCHCTL_RUNNING=1 时退出码 0(在跑),否则 1
|
|
131
|
+
const launchctl = `
|
|
132
|
+
const fs = require('node:fs');
|
|
133
|
+
fs.appendFileSync(process.env.STUB_LAUNCHCTL || '/dev/null', process.argv.slice(2).join(' ') + '\\n');
|
|
134
|
+
process.exit(process.argv[2] === 'print' && process.env.STUB_LAUNCHCTL_RUNNING !== '1' ? 1 : 0);
|
|
135
|
+
`;
|
|
136
|
+
|
|
129
137
|
// 假的 mdfind(Spotlight):记下查询串,按 STUB_MDFIND 列出路径。STUB_MDFIND=empty 时什么都不返回(目录没被索引的那种)
|
|
130
138
|
const mdfind = `
|
|
131
139
|
const fs = require('node:fs');
|
|
@@ -151,8 +159,10 @@ const args = process.argv.slice(2);
|
|
|
151
159
|
const patch = args[args.indexOf('--patch') + 1];
|
|
152
160
|
fs.writeFileSync(process.env.STUB_DSH_ARGS || '/dev/null', args.join(' ') + '\\n');
|
|
153
161
|
fs.writeFileSync((process.env.STUB_DSH_ARGS || '/dev/null') + '.patch', (fs.readFileSync(patch, 'utf8').match(/^- id: |^ disabled:/gm) || []).join('\\n') + '\\n');
|
|
162
|
+
// STUB_DSH_REJECT_SESSION 指的会话 id 出现在参数里就退出 1(接不上那个会话)
|
|
163
|
+
if (process.env.STUB_DSH_REJECT_SESSION && args.includes(process.env.STUB_DSH_REJECT_SESSION)) process.exit(1);
|
|
154
164
|
process.stdout.write(JSON.stringify({ type: 'session', sessionId: 'session_fake', cwd: 'x' }) + '\\n');
|
|
155
165
|
process.stdout.write(JSON.stringify({ type: 'final', sessionId: 'session_fake', reason: { kind: process.env.STUB_DSH_FINAL || 'completed' }, text: '回复:' + args[args.length - 1] }) + '\\n');
|
|
156
166
|
`;
|
|
157
167
|
|
|
158
|
-
module.exports = { yzjCli, linky, security, fakeAgent, fakeZcode, fakeQoder, fakeClaude, fakeDshNode, fakeDsh, mdfind, mdls };
|
|
168
|
+
module.exports = { yzjCli, linky, security, launchctl, fakeAgent, fakeZcode, fakeQoder, fakeClaude, fakeDshNode, fakeDsh, mdfind, mdls };
|