work-rhythm 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/notes/AGENTS.md +1 -0
- package/.agents/notes/decisions/2026-12-01-agent-binding-asks-for-model-and-effort.md +29 -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 +20 -7
- package/README.md +1 -1
- package/collectors/local.env.example +7 -0
- package/docs/agents.md +27 -10
- package/docs/formats.md +4 -0
- package/package.json +1 -1
- package/scripts/cli.js +14 -4
- package/scripts/cmd/agent.js +151 -43
- package/scripts/cmd/check.js +9 -1
- package/scripts/cmd/collect.js +10 -1
- package/scripts/cmd/decisions.js +17 -6
- package/scripts/cmd/events.js +103 -0
- package/scripts/cmd/goals.js +16 -20
- package/scripts/cmd/init.js +7 -1
- package/scripts/cmd/listen.js +7 -2
- package/scripts/cmd/notify.js +9 -1
- package/scripts/cmd/pack.js +7 -1
- package/scripts/cmd/rhythm.js +7 -2
- package/scripts/cmd/selftest.js +7 -1
- package/scripts/cmd/sync.js +12 -1
- package/scripts/cmd/today.js +13 -1
- package/scripts/cmd/workdir.js +5 -2
- package/scripts/lib/agent.js +139 -25
- package/scripts/lib/bot.js +2 -1
- package/scripts/lib/rhythm.js +10 -2
- package/scripts/test/agent.test.js +132 -6
- package/scripts/test/events.test.js +89 -0
- package/scripts/test/harness.js +8 -0
- package/scripts/test/help.test.js +71 -0
- package/scripts/test/listen.test.js +8 -4
- package/scripts/test/rhythm.test.js +21 -0
- package/templates/AGENTS.md +1 -1
- package/templates/README.md +1 -0
|
@@ -0,0 +1,71 @@
|
|
|
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 { BIN, run, makeSandbox, webhook } = require('./harness');
|
|
8
|
+
|
|
9
|
+
const COMMANDS = ['today', 'goals', 'decisions', 'sync', 'collect', 'notify', 'check', 'listen', 'rhythm', 'agent', 'workdir', 'init', 'pack', 'selftest'];
|
|
10
|
+
|
|
11
|
+
// agent 顺手就会敲「work-rhythm notify --help」:以前这会把「--help」当成要发的文字发出去。现在任何位置的 --help 都只打用法
|
|
12
|
+
test('--help:每个子命令都能问,退出码 0,第一行是「work-rhythm <子命令> … —— 做什么」,并写了退出码', async (t) => {
|
|
13
|
+
const hook = await webhook(t);
|
|
14
|
+
const box = makeSandbox(t);
|
|
15
|
+
box.workdir();
|
|
16
|
+
// 钥匙串指向假 webhook、渠道开着:要是 --help 被当成文字发出去,这里就会收到
|
|
17
|
+
writeProfile(box.work, 'notify: "yzj-robot"');
|
|
18
|
+
for (const name of COMMANDS) {
|
|
19
|
+
const r = box.run([name, '--help'], { env: { STUB_KEYCHAIN: 'ok', STUB_ROBOT_URL: hook.url } });
|
|
20
|
+
assert.equal(r.code, 0, `${name} --help: ${r.out}`);
|
|
21
|
+
assert.match(r.stdout, new RegExp(`^work-rhythm ${name}[ \\[]`), name);
|
|
22
|
+
assert.match(r.stdout, /—— /, `${name} 的第一行要说清做什么`);
|
|
23
|
+
assert.match(r.stdout, /退出码/, `${name} 的用法里要写退出码`);
|
|
24
|
+
assert.equal(r.stderr, '', name);
|
|
25
|
+
}
|
|
26
|
+
assert.deepEqual(hook.requests(), [], '--help 不能发出任何消息');
|
|
27
|
+
assert.equal(fs.existsSync(path.join(box.work, '--help')), false, 'init --help 不能建出一个叫 --help 的目录');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('--help:写在任何位置、几种写法都认;不在工作目录里也能问', (t) => {
|
|
31
|
+
const box = makeSandbox(t);
|
|
32
|
+
const outside = path.join(box.root, 'elsewhere');
|
|
33
|
+
fs.mkdirSync(outside);
|
|
34
|
+
const forms = [['today', '-h'], ['help', 'today'], ['--help', 'today'], ['rhythm', 'run', '--help'], ['decisions', 'add', '-h'], ['goals', 'list', '--help']];
|
|
35
|
+
for (const args of forms) {
|
|
36
|
+
const r = run(args, { cwd: outside });
|
|
37
|
+
assert.equal(r.code, 0, args.join(' '));
|
|
38
|
+
assert.match(r.stdout, /^work-rhythm (today|rhythm|decisions|goals)\b/);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('--help:顶层用法列出全部子命令、退出码约定,以及「每个子命令的详细用法」;不认识的子命令退出码 2 并带出用法', (t) => {
|
|
43
|
+
const box = makeSandbox(t);
|
|
44
|
+
const top = run(['--help'], { cwd: box.root });
|
|
45
|
+
assert.equal(top.code, 0);
|
|
46
|
+
for (const name of COMMANDS) assert.match(top.stdout, new RegExp(`\\n ${name} `), name);
|
|
47
|
+
assert.match(top.stdout, /每个子命令的详细用法: work-rhythm <子命令> --help/);
|
|
48
|
+
assert.match(top.stdout, /退出码约定: 0 成功 · 2 用法不对 · 3 没配置好/);
|
|
49
|
+
assert.match(top.stdout, /work-rhythm skill/);
|
|
50
|
+
const bad = run(['nope', '--help'], { cwd: box.root });
|
|
51
|
+
assert.equal(bad.code, 2);
|
|
52
|
+
assert.match(bad.stderr, /不认识的子命令「nope」/);
|
|
53
|
+
assert.match(bad.stderr, /用法: work-rhythm <子命令>/);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('用法不对的时候,错误信息后面带一句用法在哪', (t) => {
|
|
57
|
+
const box = makeSandbox(t);
|
|
58
|
+
box.workdir();
|
|
59
|
+
const r = box.run(['today', '2026-13-40']);
|
|
60
|
+
assert.equal(r.code, 2);
|
|
61
|
+
assert.match(r.stderr, /work-rhythm today: 无法识别日期「2026-13-40」/);
|
|
62
|
+
assert.match(r.stderr, /(用法: work-rhythm today --help)/);
|
|
63
|
+
const goals = box.run(['goals', 'nope']);
|
|
64
|
+
assert.equal(goals.code, 2);
|
|
65
|
+
assert.match(goals.stderr, /(用法: work-rhythm goals --help)/);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
function writeProfile(dir, line) {
|
|
69
|
+
const file = path.join(dir, '00-config', 'profile.yaml');
|
|
70
|
+
fs.writeFileSync(file, fs.readFileSync(file, 'utf8').replace(/^ notify:.*$/m, ` ${line}`));
|
|
71
|
+
}
|
|
@@ -244,13 +244,17 @@ test('listen doctor:问题逐条报出来,退出码为 1;配好了什么
|
|
|
244
244
|
assert.equal(ok.stdout, '');
|
|
245
245
|
});
|
|
246
246
|
|
|
247
|
-
test('listen:用法不对时退出码为 2
|
|
247
|
+
test('listen:用法不对时退出码为 2,并告诉它用法在哪;--help 打完整用法、退出码 0', async (t) => {
|
|
248
248
|
const s = setup(t);
|
|
249
|
-
|
|
249
|
+
const nope = s.listen(['nope']);
|
|
250
|
+
assert.equal(nope.code, 2);
|
|
251
|
+
assert.match(nope.stderr, /work-rhythm listen: work-rhythm listen <子命令> —— 值守/);
|
|
252
|
+
assert.match(nope.stderr, /(用法: work-rhythm listen --help)/);
|
|
250
253
|
assert.equal(s.listen([]).code, 2);
|
|
251
254
|
const r = s.listen(['--help']);
|
|
252
|
-
assert.
|
|
253
|
-
assert.match(r.
|
|
255
|
+
assert.equal(r.code, 0);
|
|
256
|
+
assert.match(r.stdout, /work-rhythm listen <子命令> —— 值守/);
|
|
257
|
+
assert.match(r.stdout, /handle-frame/);
|
|
254
258
|
});
|
|
255
259
|
|
|
256
260
|
test('listen reset:丢掉机器人的专属会话', async (t) => {
|
|
@@ -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
|
+
});
|
package/templates/AGENTS.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
- [03-carryover/DECISIONS.md](03-carryover/DECISIONS.md) — 每次我怎么决定一件事;只是以后的参考。
|
|
18
18
|
- [04-patterns/WORK_RHYTHM.md](04-patterns/WORK_RHYTHM.md) — 工作规律画像。
|
|
19
19
|
- [05-goals/](05-goals/) — 长期目标,一个文件一个,进行中的不超过 3 个。
|
|
20
|
-
- [collectors/](collectors/) — 自己写的采集器和本机配置(`local.env`,只放本机);内置采集器在 `work-rhythm` 包里。整个目录靠 `work-rhythm <子命令>` 运转:`sync` 同步,`today` 给出今天的路径和是否工作日,`goals` 列出目标、找出到期该检查的,`decisions` 记决定、查以前的决定、归档,`notify` 按 profile 的 `notify` 把计划、复盘推给我,`rhythm` 是本地服务(定时采集、定时整理、推送、本机网页),`agent` 绑定定时任务和值守用哪个 agent,`listen` 值守着收我在 IM 里说的话、交给绑定的 agent 回复,`check` 自检,`selftest` 自测;每个命令的用法看 `work-rhythm <子命令> --help`。
|
|
20
|
+
- [collectors/](collectors/) — 自己写的采集器和本机配置(`local.env`,只放本机);内置采集器在 `work-rhythm` 包里。整个目录靠 `work-rhythm <子命令>` 运转:`sync` 同步,`today` 给出今天的路径和是否工作日,`goals` 列出目标、找出到期该检查的,`decisions` 记决定、查以前的决定、归档,`events` 列出事件流,`notify` 按 profile 的 `notify` 把计划、复盘推给我,`rhythm` 是本地服务(定时采集、定时整理、推送、本机网页),`agent` 绑定定时任务和值守用哪个 agent,`listen` 值守着收我在 IM 里说的话、交给绑定的 agent 回复,`check` 自检,`selftest` 自测;每个命令的用法看 `work-rhythm <子命令> --help`。
|
|
21
21
|
- [.agents/notes/](.agents/notes/AGENTS.md) — 给 agent 的踩坑笔记和设计取舍。改脚本、配置或文档格式之前,先按它的「动手之前先看哪几篇」过一遍;踩了新坑就记进去。
|
|
22
22
|
|
|
23
23
|
## Standing orders
|
package/templates/README.md
CHANGED
|
@@ -50,6 +50,7 @@ tasks/ 定时任务的指令,一个任务一个文件,是交给 a
|
|
|
50
50
|
- 订阅源在 [00-config/sources.yaml](00-config/sources.yaml):每个源是一个可以独立运行的采集脚本,加一条「提炼成什么事件」的规则。候选有哪些、怎么新增见 [docs/sources.md](docs/sources.md),各 IM 的接法见 [docs/im-adapters.md](docs/im-adapters.md)。
|
|
51
51
|
- 内置的采集器:本机代码提交(含子模块)、文件改动、云之家日程、云之家消息、云之家告警与发布通知、云之家里等我审批的流程、Linky 上分配给我的未完成工作项。要登录的几个默认关着,配好后再到 `sources.yaml` 打开。
|
|
52
52
|
- 不用 AI 也能同步:`work-rhythm sync`,可以直接放进 cron 或 launchd。
|
|
53
|
+
- 问 AI「今天都发生了什么」「我最近在忙什么」,它先 `work-rhythm events` 取事件流再答,不凭印象。
|
|
53
54
|
- 改完配置或文档跑一遍 `work-rhythm check`:语法、内链、预算、配置、疑似密钥、笔记格式,只读不改。
|
|
54
55
|
- 定时任务靠本地服务 `work-rhythm rhythm`,不建在 agent 运行时自带的调度器上。服务要先绑一个 agent(`work-rhythm agent bind`,见 [docs/agents.md](docs/agents.md)),没绑就不起,也不支持机器人值守:到点跑采集,到点把 [tasks/](tasks/) 里的指令交给 agent 跑一遍,跑完经消息渠道把总结推给我并附一个本机页面的地址,本机还能打开网页看每日文件、遗留、规律和目标。定义和用法见 [docs/scheduled-tasks.md](docs/scheduled-tasks.md);待决的事不做定时巡查,我对任何一个 agent 说「有什么要我定」就逐件来问。
|
|
55
56
|
- 提醒推送走「消息渠道」,见 [docs/channels.md](docs/channels.md):`profile` 的 `notify` 写渠道名,`work-rhythm notify` 负责发,只发给我本人。预置的是云之家个人机器人(`yzj-robot`):在网页端建一个机器人,把它的 Webhook 地址存进系统钥匙串,就配好了。别的 IM 按「新增一个渠道」接。
|