work-rhythm 0.1.0 → 0.1.2

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 (44) hide show
  1. package/.agents/notes/AGENTS.md +4 -1
  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-no-workdir-offers-to-create-one-by-default.md +1 -0
  4. package/.agents/notes/decisions/2026-11-30-scheduling-moves-to-a-local-service.md +1 -0
  5. package/.agents/notes/decisions/2026-12-01-everything-is-js-behind-work-rhythm.md +1 -0
  6. package/.agents/notes/decisions/2026-12-01-repo-is-not-a-workdir-templates-hold-workdir-files.md +29 -0
  7. package/.agents/notes/decisions/2026-12-01-repo-stays-generic-personal-data-lives-in-workdirs.md +32 -0
  8. package/.agents/notes/decisions/2026-12-01-scheduling-is-cli-only-and-needs-a-bound-agent.md +31 -0
  9. package/.agents/notes/decisions/2026-12-01-workdir-is-not-a-git-repository.md +25 -0
  10. package/.agents/skills/work-rhythm/SKILL.md +16 -13
  11. package/AGENTS.md +12 -24
  12. package/README.md +35 -70
  13. package/collectors/local.env.example +5 -3
  14. package/docs/agents.md +49 -0
  15. package/docs/channels.md +2 -2
  16. package/docs/formats.md +1 -1
  17. package/docs/scheduled-tasks.md +2 -12
  18. package/package.json +2 -4
  19. package/scripts/cli.js +9 -5
  20. package/scripts/cmd/agent.js +110 -0
  21. package/scripts/cmd/check.js +90 -43
  22. package/scripts/cmd/init.js +3 -7
  23. package/scripts/cmd/pack.js +1 -2
  24. package/scripts/lib/agent.js +156 -17
  25. package/scripts/lib/bot.js +1 -1
  26. package/scripts/lib/log.js +1 -1
  27. package/scripts/lib/rhythm.js +1 -1
  28. package/scripts/lib/template.js +31 -26
  29. package/scripts/lib/workdir.js +13 -4
  30. package/scripts/test/agent.test.js +199 -0
  31. package/scripts/test/check.test.js +94 -10
  32. package/scripts/test/config.test.js +6 -9
  33. package/scripts/test/goals.test.js +1 -1
  34. package/scripts/test/harness.js +7 -6
  35. package/scripts/test/init.test.js +9 -11
  36. package/scripts/test/listen.test.js +2 -2
  37. package/scripts/test/pack.test.js +1 -1
  38. package/scripts/test/rhythm.test.js +13 -4
  39. package/scripts/test/stubs.js +19 -1
  40. package/scripts/test/workdir.test.js +2 -2
  41. package/{00-config → templates/00-config}/profile.example.yaml +0 -1
  42. package/{00-config → templates/00-config}/sources.yaml +8 -8
  43. package/templates/AGENTS.md +31 -0
  44. package/templates/README.md +73 -0
@@ -3,7 +3,10 @@ const { test } = require('node:test');
3
3
  const assert = require('node:assert/strict');
4
4
  const fs = require('node:fs');
5
5
  const path = require('node:path');
6
- const { makeSandbox, read, write, setKey } = require('./harness');
6
+ const { PACKAGE_ROOT, makeSandbox, run: rawRun, read, write, setKey } = require('./harness');
7
+ const os = require('node:os');
8
+ const { genericProblems } = require('../cmd/check').__test;
9
+ const { templateProblems } = require('../lib/template');
7
10
 
8
11
  // 搭工作目录(空白模板)。check 的退出码:0 全部通过,1 有未通过的项
9
12
  function setup(t) {
@@ -19,6 +22,13 @@ function setup(t) {
19
22
  sources,
20
23
  setNotify: (value) => write(profile, setKey(read(profile), 'notify', value)),
21
24
  localEnv: (text) => write(`${box.work}/collectors/local.env`, text),
25
+ // 值守装成常驻(launchd 里有它的 plist)check 才核对值守;plist 在 HOME 下,所以把 HOME 指到临时目录
26
+ botInstalled: () => {
27
+ const home = path.join(box.root, 'home');
28
+ fs.mkdirSync(path.join(home, 'Library', 'LaunchAgents'), { recursive: true });
29
+ write(path.join(home, 'Library', 'LaunchAgents', `work-rhythm.bot.${path.basename(box.work)}.plist`), '<?xml version="1.0"?><plist/>');
30
+ return { HOME: home };
31
+ },
22
32
  check: (env = { STUB_KEYCHAIN: 'no' }) => box.run(['check'], { env }),
23
33
  };
24
34
  }
@@ -172,45 +182,119 @@ test('check:没装 security 时报出来', (t) => {
172
182
  assert.match(r.stdout, /消息渠道 yzj-robot 需要 security,本机没有/);
173
183
  });
174
184
 
175
- test('check:值守配的命令找不到时报出来', (t) => {
185
+ test('check:只绑了 agent 跑定时任务、没装值守,不报值守的事;schedule 有任务没绑 agent 才报', (t) => {
186
+ const s = setup(t);
187
+ s.localEnv('YZJ_BOT_AGENT="dsh"\n');
188
+ const r = s.check({ ...s.stubs });
189
+ assert.equal(r.code, 0, r.out);
190
+ assert.ok(!r.out.includes('值守'), r.out);
191
+ // 引导做完(status: done)、把绑定的那行去掉:schedule 里有任务(模板的默认时间)却没绑 agent,就报;引导没走到第 6 步时不报
192
+ write(`${s.box.work}/00-config/profile.yaml`, read(`${s.box.work}/00-config/profile.yaml`).replace('status: new', 'status: done'));
193
+ s.localEnv('# YZJ_BOT_AGENT="dsh"\n');
194
+ const r2 = s.check({ ...s.stubs });
195
+ assert.equal(r2.code, 1, r2.out);
196
+ assert.match(r2.stdout, /schedule 里有任务(daily-plan、noon-checkin、evening-review、carryover、weekly-rhythm)却没绑 agent,到点一个也跑不了:work-rhythm agent bind <zcode\|dsh\|qoder\|claude>/);
197
+ });
198
+
199
+ test('check:值守装了之后,配的命令找不到时报出来', (t) => {
176
200
  const s = setup(t);
177
201
  s.setNotify('yzj-robot');
178
202
  s.localEnv('YZJ_BOT_AGENT="/nonexistent/agent x"\nYZJ_MY_OPEN_ID="me-0001"\n');
179
- const r = s.check({ STUB_KEYCHAIN: 'ok' });
203
+ const r = s.check({ ...s.botInstalled(), STUB_KEYCHAIN: 'ok' });
180
204
  assert.equal(r.code, 1);
181
205
  assert.match(r.stdout, /YZJ_BOT_AGENT 的命令找不到: \/nonexistent\/agent/);
182
206
  assert.ok(!r.stdout.includes('值守属于 yzj-robot 渠道'));
183
207
  });
184
208
 
185
- test('check:值守没写我的 openId 时报出来', (t) => {
209
+ test('check:值守装了之后,没写我的 openId 时报出来', (t) => {
186
210
  const s = setup(t);
187
211
  s.setNotify('yzj-robot');
188
212
  s.localEnv('YZJ_BOT_AGENT="zcode"\n');
189
- const r = s.check({ STUB_KEYCHAIN: 'ok' });
213
+ const r = s.check({ ...s.botInstalled(), STUB_KEYCHAIN: 'ok' });
190
214
  assert.match(r.stdout, /要写 YZJ_MY_OPEN_ID/);
191
215
  assert.ok(!r.stdout.includes('值守属于 yzj-robot 渠道'));
192
216
  });
193
217
 
194
- test('check:notify 不是 yzj-robot 却配了值守时报出来;值守配好之后不再报它', (t) => {
218
+ test('check:值守装了之后,notify 不是 yzj-robot 时报出来;配好之后不再报它', (t) => {
195
219
  const s = setup(t);
220
+ const home = s.botInstalled();
196
221
  s.localEnv(`YZJ_BOT_AGENT="zcode"\nYZJ_MY_OPEN_ID="me-0001"\nZCODE_CLI="${s.stubs.ZCODE_CLI}"\n`);
197
222
  s.setNotify('""');
198
- assert.match(s.check({ STUB_KEYCHAIN: 'ok' }).stdout, /值守属于 yzj-robot 渠道:preferences\.notify 要设成 yzj-robot/);
223
+ assert.match(s.check({ ...home, STUB_KEYCHAIN: 'ok' }).stdout, /值守属于 yzj-robot 渠道:preferences\.notify 要设成 yzj-robot/);
199
224
  s.setNotify('yzj-robot');
200
- const ok = s.check({ STUB_KEYCHAIN: 'ok' });
225
+ const ok = s.check({ ...home, STUB_KEYCHAIN: 'ok' });
201
226
  assert.equal(ok.code, 0, ok.out);
202
227
  assert.ok(!ok.stdout.includes('值守'));
203
228
  });
204
229
 
205
- test('check:值守配了 dsh 却找不到它的配置时报出来', (t) => {
230
+ test('check:值守装了之后,配了 dsh 却找不到它的配置时报出来', (t) => {
206
231
  const s = setup(t);
207
232
  s.setNotify('yzj-robot');
208
233
  s.localEnv(`YZJ_BOT_AGENT="dsh"\nYZJ_MY_OPEN_ID="me-0001"\nDSH_HOME="${s.box.root}/no-such-home"\nDSH_NODE="${path.join(s.box.bin, 'fake-dsh-node')}"\nDSH_CLI="${path.join(s.box.bin, 'fake-dsh')}"\n`);
209
- const r = s.check({ STUB_KEYCHAIN: 'ok' });
234
+ const r = s.check({ ...s.botInstalled(), STUB_KEYCHAIN: 'ok' });
210
235
  assert.equal(r.code, 1);
211
236
  assert.match(r.stdout, /找不到 DSH 的配置/);
212
237
  });
213
238
 
239
+ test('check:这个包自己的仓库要全部通过——它不是工作目录,只放 skill 和 CLI,不带个人数据', (t) => {
240
+ // 站在仓库里跑:7 项,有「模板」「仓库保持通用」,没有「配置自检」
241
+ const r = rawRun(['check'], { cwd: PACKAGE_ROOT, env: { WORK_RHYTHM_CONFIG: path.join(os.tmpdir(), 'no-such-config.yaml') } });
242
+ assert.equal(r.code, 0, r.out);
243
+ assert.match(r.stdout, /== 1\/7 脚本语法 ==\n== 2\/7 文档内链 ==\n== 3\/7 预算 ==\n== 4\/7 模板 ==\n== 5\/7 疑似密钥 ==\n== 6\/7 笔记格式 ==\n== 7\/7 仓库保持通用 ==\n全部通过\n/);
244
+ });
245
+
246
+ test('站在仓库里:check 查的是仓库,不是用户级登记的那个工作目录;别的命令说清这里不是工作目录', (t) => {
247
+ const box = makeSandbox(t);
248
+ box.workdir();
249
+ const cfg = path.join(box.root, 'cfg.yaml');
250
+ write(cfg, `workdir: ${box.work}\n`);
251
+ const env = { WORK_RHYTHM_CONFIG: cfg };
252
+ // 登记指向另一个工作目录,但人站在仓库里:check 查仓库(7 项),today 不偷偷落到登记的那个上
253
+ assert.equal(rawRun(['check'], { cwd: path.join(PACKAGE_ROOT, 'scripts'), env }).code, 0);
254
+ assert.match(rawRun(['check'], { cwd: path.join(PACKAGE_ROOT, 'scripts'), env }).stdout, /== 7\/7 仓库保持通用 ==/);
255
+ const today = rawRun(['today'], { cwd: PACKAGE_ROOT, env });
256
+ assert.equal(today.code, 3);
257
+ assert.match(today.stderr, /当前目录不是工作目录(这里是 work-rhythm 自己的仓库,不是工作目录)/);
258
+ });
259
+
260
+ test('仓库保持通用:根目录出现工作目录才有的东西、个人配置,各报一条', (t) => {
261
+ const box = makeSandbox(t);
262
+ const repo = path.join(box.root, 'repo');
263
+ fs.cpSync(path.join(PACKAGE_ROOT, 'templates'), path.join(repo, 'templates'), { recursive: true });
264
+ const problems = () => {
265
+ const lines = [];
266
+ genericProblems({ root: repo, say: (l) => lines.push(l) });
267
+ return lines;
268
+ };
269
+ assert.deepEqual(problems(), []);
270
+ write(path.join(repo, '00-config', 'profile.yaml'), 'setup:\n status: done\n');
271
+ write(path.join(repo, '02-daily', '2026-01', '2026-01-01.md'), '# 2026-01-01\n');
272
+ write(path.join(repo, 'collectors', 'local.env'), 'A=1\n');
273
+ const found = problems();
274
+ assert.equal(found.length, 3);
275
+ assert.match(found.join('\n'), /仓库根目录里出现了 00-config:这个仓库只放 skill 和 CLI,不是工作目录/);
276
+ assert.match(found.join('\n'), /仓库根目录里出现了 02-daily/);
277
+ assert.match(found.join('\n'), /仓库里出现了个人配置 collectors\/local\.env/);
278
+ assert.ok(found.every((l) => !l.includes('templates/00-config')), 'templates/ 里的不算');
279
+ });
280
+
281
+ test('模板:templates/ 下每份都在、profile 空白、源全关、记录没有行;坏了就报出来', (t) => {
282
+ const box = makeSandbox(t);
283
+ const pkg = path.join(box.root, 'pkg');
284
+ fs.cpSync(path.join(PACKAGE_ROOT, 'templates'), path.join(pkg, 'templates'), { recursive: true });
285
+ assert.deepEqual(templateProblems(pkg), []);
286
+ fs.rmSync(path.join(pkg, 'templates', 'README.md'));
287
+ write(path.join(pkg, 'templates', '00-config', 'sources.yaml'), read(path.join(pkg, 'templates', '00-config', 'sources.yaml')).replace('enabled: false', 'enabled: true'));
288
+ fs.appendFileSync(path.join(pkg, 'templates', '03-carryover', 'CARRYOVER.md'), '| 2026-01-01 | 旧 | 复盘 | P1 | 待开始 | 0 | |\n');
289
+ write(path.join(pkg, 'templates', '04-patterns', 'WORK_RHYTHM.md'), '# 我的规律\n\n数据范围:近 30 天\n');
290
+ const found = templateProblems(pkg);
291
+ assert.equal(found.length, 4);
292
+ assert.match(found.join('\n'), /templates\/README\.md 不存在/);
293
+ assert.match(found.join('\n'), /sources\.yaml 里有打开的源/);
294
+ assert.match(found.join('\n'), /CARRYOVER\.md 里带了记录/);
295
+ assert.match(found.join('\n'), /「数据范围」不是「尚未开始」/);
296
+ });
297
+
214
298
  test('check:用法不对时退出码为 2', (t) => {
215
299
  const s = setup(t);
216
300
  assert.equal(s.box.run(['check', '什么']).code, 2);
@@ -2,6 +2,7 @@
2
2
  const { test } = require('node:test');
3
3
  const assert = require('node:assert/strict');
4
4
  const { parseYaml, parseLocalEnv, findWorkdir, loadProfile, loadSources } = require('../lib/config');
5
+ const path = require('node:path');
5
6
  const { PACKAGE_ROOT, makeSandbox, write, read, exists } = require('./harness');
6
7
 
7
8
  // 配置文件是用户会手改的 YAML,格式即契约:docs/formats.md 和两份 *.example 里的写法都要读得出来
@@ -31,7 +32,6 @@ rhythm:
31
32
  port: 8787
32
33
  push: true
33
34
  quiet: [linky-cost-fill, linky-cost-check]
34
- automations: {}
35
35
  sources:
36
36
  - id: git-activity
37
37
  name: 本机代码提交
@@ -56,18 +56,15 @@ sources:
56
56
  assert.equal(doc.rhythm.port, 8787);
57
57
  assert.equal(doc.rhythm.push, true);
58
58
  assert.deepEqual(doc.rhythm.quiet, ['linky-cost-fill', 'linky-cost-check']);
59
- assert.deepEqual(doc.automations, {});
60
59
  assert.equal(doc.sources[0].extract, '第一行\n第二行\n');
61
60
  assert.equal(doc.sources[1].id, 'noted');
62
61
  assert.equal(doc.sources[1].enabled, false);
63
62
  });
64
63
 
65
- test('parseYaml:空白模板和填好的实例都能读,要用的字段一个不少', () => {
66
- // 填好的实例只有开发时有(npm 包里不带它)
67
- const names = ['profile.example.yaml'];
68
- if (exists(`${PACKAGE_ROOT}/00-config/profile.yaml`)) names.push('profile.yaml');
69
- for (const name of names) {
70
- const doc = parseYaml(read(`${PACKAGE_ROOT}/00-config/${name}`));
64
+ test('parseYaml:空白模板能读,要用的字段一个不少(仓库里的 profile.yaml 是它的副本,也读一遍)', () => {
65
+ // profile.yaml 只有开发时有(npm 包里不带它)
66
+ for (const name of ['profile.example.yaml']) {
67
+ const doc = parseYaml(read(`${PACKAGE_ROOT}/templates/00-config/${name}`));
71
68
  assert.equal(typeof doc.identity.name, 'string', name);
72
69
  assert.equal(Array.isArray(doc.im.groups), true, name);
73
70
  assert.equal(typeof doc.preferences.notify, 'string', name);
@@ -77,7 +74,7 @@ test('parseYaml:空白模板和填好的实例都能读,要用的字段一
77
74
  assert.equal(Array.isArray(doc.setup.skipped), true, name);
78
75
  for (const p of doc.role.projects) assert.equal(typeof p.name, 'string', name);
79
76
  }
80
- const sources = loadSources(PACKAGE_ROOT);
77
+ const sources = loadSources(path.join(PACKAGE_ROOT, 'templates'));
81
78
  assert.equal(sources.length, 8);
82
79
  assert.equal(sources[0].id, 'git-activity');
83
80
  assert.equal(typeof sources[0].extract, 'string');
@@ -105,5 +105,5 @@ test('goals:05-goals 里没有目标时只打表头;不在工作目录里退
105
105
  assert.equal(list.code, 0);
106
106
  assert.equal(list.stdout.trimEnd().split('\n').length, 1);
107
107
  assert.equal(box.run(['goals', 'list'], { cwd: box.root }).code, 3);
108
- assert.equal(exists(`${box.work}/05-goals/.gitkeep`), true);
108
+ assert.equal(exists(`${box.work}/05-goals`), true);
109
109
  });
@@ -16,7 +16,8 @@ const BIN = path.join(PACKAGE_ROOT, 'scripts', 'work-rhythm.js');
16
16
  const T = '\t';
17
17
 
18
18
  // 这些变量是各命令的配置,本机环境里如果碰巧有,会让用例的结果跟着变。跑命令时一律不带
19
- const STRIP = /^(YZJ_|GIT_ACTIVITY_|FILE_ACTIVITY_|DSH_|STUB_|ZCODE_CLI|WORK_RHYTHM_|DECISIONS_TODAY|LINKY_TYPES)/;
19
+ // CLAUDE、QODER 也抹掉:调用这个测试的 agent 会留自己的标记(ZCODE_*、CLAUDE_CODE_*、DSH_SESSION_ID),用例不能被它带偏
20
+ const STRIP = /^(YZJ_|GIT_ACTIVITY_|FILE_ACTIVITY_|DSH_|STUB_|ZCODE_|WORK_RHYTHM_|DECISIONS_TODAY|LINKY_TYPES|CLAUDE|QODER)/;
20
21
  const { writeWorkdir } = require('../lib/template');
21
22
 
22
23
  // 用户级登记指向一个不存在的文件:用例不能被本机登记的工作目录带偏
@@ -42,7 +43,7 @@ function run(args, { cwd = PACKAGE_ROOT, env = {}, input, timeout = 120000 } = {
42
43
 
43
44
  // sources.yaml:只打开两个本机源(代码提交、文件改动),其余关着(假命令行跑不了云之家、Linky)
44
45
  function cleanSources() {
45
- const lines = read(path.join(PACKAGE_ROOT, '00-config', 'sources.yaml')).split('\n');
46
+ const lines = read(path.join(PACKAGE_ROOT, 'templates', '00-config', 'sources.yaml')).split('\n');
46
47
  let keep = false;
47
48
  return lines.map((line) => {
48
49
  if (/^\s*-?\s*id:/.test(line)) {
@@ -141,6 +142,8 @@ function makeSandbox(t) {
141
142
  STUB_ROBOT_TOKEN: 'stubtoken0123456789abcd',
142
143
  STUB_AGENT_CALLS: file('agent.calls'),
143
144
  STUB_ZCODE_ARGS: file('zcode.args'),
145
+ STUB_QODER_ARGS: file('qoder.args'),
146
+ STUB_CLAUDE_ARGS: file('claude.args'),
144
147
  STUB_DSH_ARGS: file('dsh.args'),
145
148
  STUB_DSH_ENV: file('dsh.env'),
146
149
  STUB_APPROVAL_NEW_MS: String(Date.UTC(2026, 10, 27, 10, 0, 0)),
@@ -157,14 +160,12 @@ function makeSandbox(t) {
157
160
  return sandbox;
158
161
  }
159
162
 
160
- // 搭一个工作目录,和 work-rhythm init 铺出来的一样(走同一个函数),只是 sources.yaml 换成 cleanSources()。
161
- // profile 默认是空白模板;写 'real' 用这个仓库自己填好的那份
162
- function makeWorkdir(dir, { profile = 'example' } = {}) {
163
+ // 搭一个工作目录,和 work-rhythm init 铺出来的一样(走同一个函数),只是 sources.yaml 换成 cleanSources()(打开两个本机源)
164
+ function makeWorkdir(dir) {
163
165
  fs.mkdirSync(dir, { recursive: true });
164
166
  const problems = writeWorkdir(dir, PACKAGE_ROOT);
165
167
  if (problems.length) throw new Error(`铺出来的工作目录不是空白的:${problems.join(';')}`);
166
168
  fs.writeFileSync(path.join(dir, '00-config', 'sources.yaml'), cleanSources());
167
- if (profile !== 'example') fs.writeFileSync(path.join(dir, '00-config', 'profile.yaml'), read(path.join(PACKAGE_ROOT, '00-config', 'profile.yaml')));
168
169
  return dir;
169
170
  }
170
171
 
@@ -13,14 +13,15 @@ const TODAY = () => {
13
13
 
14
14
  // 新工作目录里该有什么:配置、文档、任务指令、记录、笔记和 skill;不该有脚本和内置采集器
15
15
  const EXPECTED = [
16
- '00-config/profile.yaml', '00-config/profile.example.yaml', '00-config/sources.yaml', 'AGENTS.md', 'README.md', '.gitignore', 'CLAUDE.md',
16
+ '00-config/profile.yaml', '00-config/profile.example.yaml', '00-config/sources.yaml', 'AGENTS.md', 'README.md', 'CLAUDE.md',
17
17
  'docs/formats.md', 'docs/channels.md', 'tasks/daily-plan.md', 'collectors/local.env.example',
18
18
  '03-carryover/CARRYOVER.md', '03-carryover/DECISIONS.md', '04-patterns/WORK_RHYTHM.md',
19
- '.agents/skills/work-rhythm/SKILL.md', '.agents/notes/AGENTS.md', '02-daily/.gitkeep', '05-goals/.gitkeep',
19
+ '.agents/skills/work-rhythm/SKILL.md', '.agents/notes/AGENTS.md', '02-daily', '05-goals',
20
20
  ];
21
- const NOT_EXPECTED = ['scripts', 'templates', 'collectors/git-activity.js', 'collectors/im-yzj.sh', '01-inbox', 'collectors/local.env', '02-daily/.gitkeep.md'];
21
+ // 工作目录不是 git 仓库:没有 .git、.gitignore、.gitkeep
22
+ const NOT_EXPECTED = ['scripts', 'templates', 'collectors/git-activity.js', 'collectors/im-yzj.sh', '01-inbox', 'collectors/local.env', '.git', '.gitignore', '02-daily/.gitkeep'];
22
23
 
23
- test('init:用包里的模板建出工作目录,git init 一个不连远程的本地仓库,并登记', (t) => {
24
+ test('init:用包里的模板建出工作目录并登记;不 git init,不是 git 仓库', (t) => {
24
25
  const box = makeSandbox(t);
25
26
  const cfg = path.join(box.root, 'wr-config.yaml');
26
27
  const target = path.join(box.root, 'home', 'new-wd');
@@ -28,7 +29,7 @@ test('init:用包里的模板建出工作目录,git init 一个不连远程
28
29
  assert.equal(r.code, 0, r.out);
29
30
  const real = fs.realpathSync(target);
30
31
  assert.equal(r.stdout, `WORKDIR=${real}\n`);
31
- assert.match(r.stderr, /init: 已新建 .*new-wd:个人信息是空白的、数据源全部关着、没有记录、不连任何远程\n下一步:.*「开始引导」/);
32
+ assert.match(r.stderr, /init: 已新建 .*new-wd:个人信息是空白的、数据源全部关着、没有记录\n下一步:.*「开始引导」/);
32
33
  for (const f of EXPECTED) assert.ok(exists(path.join(target, f)), `缺 ${f}`);
33
34
  for (const f of NOT_EXPECTED) assert.ok(!exists(path.join(target, f)), `不该有 ${f}`);
34
35
  assert.match(read(`${target}/00-config/profile.yaml`), /^ status: new\b/m);
@@ -36,10 +37,7 @@ test('init:用包里的模板建出工作目录,git init 一个不连远程
36
37
  assert.ok(!/enabled:\s*true/.test(read(`${target}/00-config/sources.yaml`)), '数据源要全部关着');
37
38
  assert.match(read(`${target}/03-carryover/DECISIONS.md`), /^\| 日期 \| 事项/m);
38
39
  assert.ok(!/^\| \d/m.test(read(`${target}/03-carryover/DECISIONS.md`)), '模板里不带记录');
39
- assert.match(read(`${target}/.gitignore`), /01-inbox\/\n[\s\S]*collectors\/local\.env/);
40
40
  assert.ok(fs.lstatSync(`${target}/CLAUDE.md`).isSymbolicLink(), 'CLAUDE.md 是指向 AGENTS.md 的软链');
41
- assert.ok(exists(`${target}/.git`));
42
- assert.equal(git(target, ['remote'], GIT_ENV).stdout.trim(), '', '不连任何远程');
43
41
  assert.equal(read(cfg), `workdir: ${real}\n`);
44
42
  });
45
43
 
@@ -84,16 +82,17 @@ test('init:建出来的工作目录里 work-rhythm 的命令都能用:check
84
82
  });
85
83
 
86
84
  // ---------------------------------------------------------------- 模板本身
87
- const { writeWorkdir, blankProblems, blankText, GITIGNORE } = require('../lib/template');
85
+ const { writeWorkdir, blankProblems, blankText } = require('../lib/template');
88
86
 
89
87
  test('template:包不完整时说清缺哪份;空白核对认得出带记录、带配置、没关源的目录', (t) => {
90
88
  const box = makeSandbox(t);
91
89
  write(path.join(box.root, 'pkg', 'docs', 'a.md'), 'x');
92
- assert.throws(() => writeWorkdir(path.join(box.root, 'w'), path.join(box.root, 'pkg')), /这个包不完整:没有 00-config\/profile\.example\.yaml。重新安装一次 work-rhythm/);
90
+ assert.throws(() => writeWorkdir(path.join(box.root, 'w'), path.join(box.root, 'pkg')), /这个包不完整:templates\/00-config\/profile\.example\.yaml 不存在;[\s\S]*重新安装一次 work-rhythm/);
93
91
  // 真铺出来的是空白的(夹具为了跑采集会打开两个本机源,所以这里自己铺一份)
94
92
  const dir = path.join(box.root, 'fresh');
95
93
  fs.mkdirSync(dir);
96
94
  assert.deepEqual(writeWorkdir(dir, PACKAGE_ROOT), []);
95
+ assert.deepEqual(fs.readdirSync(path.join(dir, '02-daily')), [], '02-daily 是空目录,不用 .gitkeep 占位');
97
96
  assert.deepEqual(blankProblems(dir), []);
98
97
  write(`${dir}/02-daily/2026-01/2026-01-01.md`, '# 2026-01-01\n');
99
98
  write(`${dir}/05-goals/x.md`, '---\nid: x\n---\n');
@@ -111,7 +110,6 @@ test('template:包不完整时说清缺哪份;空白核对认得出带记录
111
110
  '带了不该带的 collectors/local.env',
112
111
  '带了不该带的 01-inbox',
113
112
  ]);
114
- assert.match(GITIGNORE, /01-inbox\/\n[\s\S]*collectors\/local\.env/);
115
113
  });
116
114
 
117
115
  test('template:空白化的几条规则', () => {
@@ -177,12 +177,12 @@ test('listen:日志里不记消息内容', async (t) => {
177
177
  });
178
178
 
179
179
  // ---------------------------------------------------------------- 配置
180
- test('listen:没配 YZJ_BOT_AGENT 时退出码为 3', async (t) => {
180
+ test('listen:没绑 agent 时退出码为 3,说清怎么绑', async (t) => {
181
181
  const s = setup(t);
182
182
  const { env } = await withHook(t, s);
183
183
  const r = s.listen(['handle', 'x'], { ...env, YZJ_BOT_AGENT: '' });
184
184
  assert.equal(r.code, 3);
185
- assert.match(r.stderr, /没配 YZJ_BOT_AGENT/);
185
+ assert.match(r.stderr, /没绑 agent,值守开不了:先 work-rhythm agent detect/);
186
186
  });
187
187
 
188
188
  test('listen:没配 YZJ_MY_OPEN_ID 时退出码为 3', async (t) => {
@@ -52,7 +52,7 @@ test('npm pack:包里带的是脚本、采集器、文档、skill 和空白模
52
52
  'package.json', 'scripts/work-rhythm.js', 'scripts/cli.js', 'scripts/cmd/init.js', 'scripts/lib/template.js', 'scripts/test/harness.js',
53
53
  'collectors/git-activity.js', 'collectors/im-yzj.js', 'collectors/local.env.example',
54
54
  'docs/formats.md', 'docs/channels.md', 'tasks/daily-plan.md', '.agents/skills/work-rhythm/SKILL.md', '.agents/notes/AGENTS.md',
55
- '00-config/profile.example.yaml', '00-config/sources.yaml', 'templates/03-carryover/DECISIONS.md', 'templates/03-carryover/CARRYOVER.md', 'templates/04-patterns/WORK_RHYTHM.md',
55
+ 'templates/00-config/profile.example.yaml', 'templates/00-config/sources.yaml', 'templates/03-carryover/DECISIONS.md', 'templates/03-carryover/CARRYOVER.md', 'templates/04-patterns/WORK_RHYTHM.md', 'templates/AGENTS.md', 'templates/README.md',
56
56
  'AGENTS.md', 'README.md',
57
57
  ]) assert.ok(files.includes(need), `包里没有 ${need}`);
58
58
  for (const banned of ['collectors/local.env', '01-inbox/x/raw.json', '00-config/profile.yaml', '02-daily/2026-01/2026-01-01.md', '03-carryover/DECISIONS.md', '04-patterns/WORK_RHYTHM.md', '.gitignore', '.npmignore']) {
@@ -136,7 +136,7 @@ test('rhythm doctor:配置齐了时退出码为 0;时间写了却缺指令
136
136
  // 推送开着却没配消息渠道、agent 没配,都报出来
137
137
  s.set('notify', '""');
138
138
  assert.match(s.rhythm(['doctor']).stdout, /rhythm.push 开着,但 preferences.notify 没配消息渠道/);
139
- assert.match(s.rhythm(['doctor'], { ...s.env, YZJ_BOT_AGENT: '' }).stdout, /没配 YZJ_BOT_AGENT/);
139
+ assert.match(s.rhythm(['doctor'], { ...s.env, YZJ_BOT_AGENT: '' }).stdout, /没绑 agent:定时任务和机器人值守都要一个 agent 来跑/);
140
140
  // 端口不在范围里
141
141
  s.set('port', '80');
142
142
  assert.match(s.rhythm(['doctor']).stdout, /rhythm.port 要是 1024 到 65535 之间的整数(现在是 80)/);
@@ -150,7 +150,7 @@ test('rhythm start:配置有问题时不起,退出码为 3,缺指令文件
150
150
  s.set('notify', '""');
151
151
  const r = s.rhythm(['start'], { ...s.env, YZJ_BOT_AGENT: '' });
152
152
  assert.equal(r.code, 3);
153
- assert.match(r.stderr, /配置有问题,先跑 work-rhythm rhythm doctor:\n没配 YZJ_BOT_AGENT/);
153
+ assert.match(r.stderr, /配置有问题,先跑 work-rhythm rhythm doctor:\n没绑 agent/);
154
154
  assert.match(r.stderr, /rhythm.push 开着/);
155
155
  assert.ok(!r.stderr.includes('weekly-rhythm'), '缺指令文件的任务到点跳过就行,不该拦着不起');
156
156
  });
@@ -162,6 +162,7 @@ describe('rhythm start:服务在跑的时候', () => {
162
162
  let port;
163
163
  let proc;
164
164
  let clean;
165
+ let farSpec;
165
166
  const stop = async () => {
166
167
  s.rhythm(['stop']);
167
168
  await proc.exited;
@@ -170,7 +171,13 @@ describe('rhythm start:服务在跑的时候', () => {
170
171
  clean = hookContext();
171
172
  hook = await webhook(clean);
172
173
  s = setup(clean);
173
- s.set('daily-plan', '"08:50"');
174
+ // 服务一启动就会补跑 5 分钟内到点的任务并推送,所以这组用例里的时间不能撞上「现在」:写死 08:50 的话,
175
+ // 哪个工作日 08:52 跑测试,就会多推一条、用例变红。唯一留着的时间写成离现在 6 小时 7 分钟之后(星期跟着那个时刻走,
176
+ // 不限工作日,周末也能跑),别的任务和采集全关
177
+ const far = new Date(Date.now() + 6 * 3600 * 1000 + 7 * 60 * 1000);
178
+ farSpec = `${['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][far.getDay()]} ${pad(far.getHours())}:${pad(far.getMinutes())}`;
179
+ s.set('daily-plan', `"${farSpec}"`);
180
+ for (const key of ['noon-checkin', 'evening-review', 'carryover', 'weekly-rhythm', 'sync']) s.set(key, '""');
174
181
  port = await freePort();
175
182
  s.set('port', String(port));
176
183
  s.set('quiet', '[linky-cost-fill, linky-cost-check]');
@@ -187,7 +194,9 @@ describe('rhythm start:服务在跑的时候', () => {
187
194
  const r = s.rhythm(['status']);
188
195
  assert.equal(r.code, 0, r.out);
189
196
  assert.match(r.stdout, /在跑(pid \d+),页面 http:\/\/127\.0\.0\.1:\d+\n/);
190
- assert.match(r.stdout, /接下来:\n[\d-]+ 周.-?\n 08:50 daily-plan\n/);
197
+ assert.match(r.stdout, /接下来:\n[\d-]+ 周.-?\n/);
198
+ // 往后两天里能看到那个任务
199
+ assert.match(s.rhythm(['due', '--days', '2']).stdout, new RegExp(` ${farSpec.slice(4)} daily-plan\\n`));
191
200
  assert.equal(exists(`${s.box.work}/01-inbox/_rhythm/service.pid`), true);
192
201
  assert.match(read(`${s.box.work}/01-inbox/_rhythm.log`), /服务开始 pid=\d+ 页面=http:\/\/127\.0\.0\.1:\d+/);
193
202
  });
@@ -98,6 +98,24 @@ fs.writeFileSync(process.env.STUB_ZCODE_ARGS || '/dev/null', args.join(' ') + '\
98
98
  process.stdout.write(JSON.stringify({ sessionId: 'sess_fake', response: '回复:' + args[args.length - 1], usage: {} }) + '\\n');
99
99
  `;
100
100
 
101
+ // 假的 Qoder CLI:记下参数,照官方文档 --output-format json 的样子回一个 JSON(回答在 result,会话在 session_id)。
102
+ // STUB_QODER_FINAL 不为空时 subtype 用它(error_max_turns 之类),is_error 置真
103
+ const fakeQoder = `
104
+ const fs = require('node:fs');
105
+ const args = process.argv.slice(2);
106
+ fs.writeFileSync(process.env.STUB_QODER_ARGS || '/dev/null', args.join(' ') + '\\n');
107
+ const final = process.env.STUB_QODER_FINAL || '';
108
+ process.stdout.write(JSON.stringify({ type: 'result', subtype: final || 'success', is_error: Boolean(final), result: final ? '出了点问题' : '回复:' + args[args.length - 1], session_id: 'sess_q' }) + '\\n');
109
+ `;
110
+
111
+ // 假的 Claude Code 命令行:和 Qoder 那个一样,只是会话 ID 不同
112
+ const fakeClaude = `
113
+ const fs = require('node:fs');
114
+ const args = process.argv.slice(2);
115
+ fs.writeFileSync(process.env.STUB_CLAUDE_ARGS || '/dev/null', args.join(' ') + '\\n');
116
+ process.stdout.write(JSON.stringify({ type: 'result', subtype: 'success', is_error: false, result: '回复:' + args[args.length - 1], session_id: 'sess_c' }) + '\\n');
117
+ `;
118
+
101
119
  // 假的 DSH 自带 Node:记下调用时的环境,丢掉「--import <路径>」两个参数,用真正的 node 把剩下的交给入口脚本
102
120
  const fakeDshNode = `
103
121
  const fs = require('node:fs');
@@ -137,4 +155,4 @@ process.stdout.write(JSON.stringify({ type: 'session', sessionId: 'session_fake'
137
155
  process.stdout.write(JSON.stringify({ type: 'final', sessionId: 'session_fake', reason: { kind: process.env.STUB_DSH_FINAL || 'completed' }, text: '回复:' + args[args.length - 1] }) + '\\n');
138
156
  `;
139
157
 
140
- module.exports = { yzjCli, linky, security, fakeAgent, fakeZcode, fakeDshNode, fakeDsh, mdfind, mdls };
158
+ module.exports = { yzjCli, linky, security, fakeAgent, fakeZcode, fakeQoder, fakeClaude, fakeDshNode, fakeDsh, mdfind, mdls };
@@ -113,7 +113,7 @@ test('workdir register / find / config', (t) => {
113
113
  // ---------------------------------------------------------------- 清空白
114
114
  test('workdir blank:把用过的目录清成空白的工作目录,个人信息、记录、本机配置、原始数据都不留', (t) => {
115
115
  const box = makeSandbox(t);
116
- const dir = box.workdir({ profile: 'real' });
116
+ const dir = box.workdir();
117
117
  write(`${dir}/02-daily/2026-01/2026-01-01.md`, '# 2026-01-01\n');
118
118
  write(`${dir}/05-goals/old.md`, '---\nid: old\n---\n');
119
119
  fs.appendFileSync(`${dir}/03-carryover/CARRYOVER.md`, '| 01-01 | 旧事项 | 复盘 | P1 | 待开始 | 0 | |\n');
@@ -130,7 +130,7 @@ test('workdir blank:把用过的目录清成空白的工作目录,个人信
130
130
  assert.match(read(`${dir}/00-config/profile.yaml`), /status: new/);
131
131
  assert.ok(!/enabled:\s*true/.test(read(`${dir}/00-config/sources.yaml`)));
132
132
  assert.equal(sources.split('\n').length, read(`${dir}/00-config/sources.yaml`).split('\n').length, '只改开关,不丢行');
133
- for (const d of ['02-daily', '05-goals']) assert.deepEqual(fs.readdirSync(path.join(dir, d)), ['.gitkeep']);
133
+ for (const d of ['02-daily', '05-goals']) assert.deepEqual(fs.readdirSync(path.join(dir, d)), []);
134
134
  for (const gone of ['03-carryover/archive', 'collectors/local.env', '01-inbox']) assert.equal(exists(path.join(dir, gone)), false, `${gone} 还在`);
135
135
  assert.ok(!read(`${dir}/03-carryover/CARRYOVER.md`).includes('旧事项'));
136
136
  assert.ok(!read(`${dir}/03-carryover/DECISIONS.md`).includes('旧事项'));
@@ -51,4 +51,3 @@ rhythm: # 本地服务(work-rhythm rhythm,见 docs/schedul
51
51
  push: true # 任务跑完要不要经消息渠道推送(渠道是上面 preferences.notify 配的那个)
52
52
  quiet: [] # 这些任务不推送,例如 [linky-cost-fill, linky-cost-check]
53
53
 
54
- automations: {} # 已创建的定时任务:id → "<调度器>: <任务名或 ID>",由 skill 维护
@@ -19,7 +19,7 @@ defaults:
19
19
  sources:
20
20
  - id: git-activity
21
21
  name: 本机代码提交
22
- enabled: true
22
+ enabled: false
23
23
  signal: 编码
24
24
  collector: git-activity
25
25
  cadence: on-demand
@@ -30,7 +30,7 @@ sources:
30
30
 
31
31
  - id: file-activity
32
32
  name: 文件改动
33
- enabled: true
33
+ enabled: false
34
34
  signal: 编码, 文档
35
35
  collector: file-activity
36
36
  cadence: on-demand
@@ -42,7 +42,7 @@ sources:
42
42
 
43
43
  - id: ai-sessions
44
44
  name: AI 会话
45
- enabled: true
45
+ enabled: false
46
46
  signal: 编码, 文档
47
47
  collector: none
48
48
  cadence: on-demand
@@ -55,7 +55,7 @@ sources:
55
55
 
56
56
  - id: calendar-yzj
57
57
  name: 云之家日程
58
- enabled: true
58
+ enabled: false
59
59
  signal: 会议
60
60
  collector: calendar-yzj
61
61
  cadence: on-demand
@@ -66,7 +66,7 @@ sources:
66
66
 
67
67
  - id: im-yzj
68
68
  name: 云之家消息
69
- enabled: true
69
+ enabled: false
70
70
  signal: 沟通
71
71
  collector: im-yzj
72
72
  cadence: on-demand
@@ -77,7 +77,7 @@ sources:
77
77
 
78
78
  - id: ops-yzj
79
79
  name: 云之家告警与发布通知
80
- enabled: true
80
+ enabled: false
81
81
  signal: 事务
82
82
  collector: im-yzj
83
83
  cadence: on-demand
@@ -90,7 +90,7 @@ sources:
90
90
 
91
91
  - id: linky-issues
92
92
  name: Linky 我的工作项
93
- enabled: true
93
+ enabled: false
94
94
  signal: 工作项
95
95
  collector: linky-issues
96
96
  cadence: on-demand
@@ -102,7 +102,7 @@ sources:
102
102
 
103
103
  - id: approval-yzj
104
104
  name: 云之家待办审批
105
- enabled: true
105
+ enabled: false
106
106
  signal: 审批
107
107
  collector: approval-yzj
108
108
  cadence: on-demand
@@ -0,0 +1,31 @@
1
+ # 个人工作目录(work-rhythm)
2
+
3
+ 用 AI 记录我每天的工作事件、维护工作数据订阅源,并据此做计划、跟进、复盘,逐步总结出我的工作规律。上手见 [README.md](README.md),流程与判断规则见 [work-rhythm skill](.agents/skills/work-rhythm/SKILL.md)。
4
+
5
+ ## 事实入口
6
+
7
+ - [00-config/profile.yaml](00-config/profile.yaml) — 我是谁:身份、角色、作息、定时任务时间。做任何规划之前先读。
8
+ - [00-config/sources.yaml](00-config/sources.yaml) — 订阅源:有哪些数据、怎么取、取什么。
9
+ - [docs/formats.md](docs/formats.md) — 每日文件、事件类型、遗留清单、规律画像的格式定义。
10
+ - [docs/sources.md](docs/sources.md) — 数据源候选目录、采集脚本契约、新增一个源的步骤。
11
+ - [docs/im-adapters.md](docs/im-adapters.md) — 各 IM 的接入方式。
12
+ - [docs/channels.md](docs/channels.md) — 消息渠道:AI 把提醒推给我的那条路;云之家预置了个人机器人。
13
+ - [docs/scheduled-tasks.md](docs/scheduled-tasks.md) — 定时任务:本地服务 `work-rhythm rhythm` 的用法,任务的指令在 [tasks/](tasks/),还有会逐件问我的「待决询问」。
14
+ - [tasks/](tasks/) — 定时任务的指令,一个任务一个文件;时间写在 profile 的 `schedule` 里。
15
+ - [02-daily/](02-daily/) — 每天一个文件:计划、进展、复盘、事件流、备注。
16
+ - [03-carryover/CARRYOVER.md](03-carryover/CARRYOVER.md) — 遗留待处理。
17
+ - [03-carryover/DECISIONS.md](03-carryover/DECISIONS.md) — 每次我怎么决定一件事;只是以后的参考。
18
+ - [04-patterns/WORK_RHYTHM.md](04-patterns/WORK_RHYTHM.md) — 工作规律画像。
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`。
21
+ - [.agents/notes/](.agents/notes/AGENTS.md) — 给 agent 的踩坑笔记和设计取舍。改脚本、配置或文档格式之前,先按它的「动手之前先看哪几篇」过一遍;踩了新坑就记进去。
22
+
23
+ ## Standing orders
24
+
25
+ - 记录、同步、计划、复盘、加数据源、设定时任务一律走 [work-rhythm skill](.agents/skills/work-rhythm/SKILL.md)。
26
+ - 事件一行一事、不记内容细节,类型用 [docs/formats.md](docs/formats.md) 里的词表。
27
+ - 外部系统(IM、日历、审批、工作项系统)只读;发消息、改日程、处理审批、流转工作项之前先问我。
28
+ - 各系统的原始数据只落 `01-inbox/`(只是原料,不是记录),聊天原文、单据内容不写进 `02-daily/`;密钥、令牌、密码不进任何文件。
29
+ - 取不到的数据写「未取到」,不编造日程、事件或别人的话;别处系统里已经管着的状态(如工作项的当前状态)不在这里另存一份。
30
+ - 怎么处理一件事由我决定:AI 摆事实、给选项、标出建议;每次的决定记进 [03-carryover/DECISIONS.md](03-carryover/DECISIONS.md),只作参考,选定之前不动外部系统。
31
+ - 每次会话开始先看 `setup.status`:不是 `done` 就先读 profile,用两三句话说明这个目录能帮我做什么、初始化走到哪一步,问我要不要现在继续;想跳过就跳过,记进 `setup.skipped`。