work-rhythm 0.1.8 → 0.2.11

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 (51) hide show
  1. package/.agents/notes/AGENTS.md +12 -1
  2. package/.agents/notes/decisions/2026-12-01-agent-runs-the-login-for-the-user.md +30 -0
  3. package/.agents/notes/decisions/2026-12-01-interjections-batch-into-one-answer-and-interrupt-reruns.md +33 -0
  4. package/.agents/notes/decisions/2026-12-01-long-runs-are-bounded-by-silence-not-wall-clock.md +35 -0
  5. package/.agents/notes/decisions/2026-12-01-question-cards-via-cli-tool-on-todays-page-answers-return-to-router.md +40 -0
  6. package/.agents/notes/decisions/2026-12-01-router-and-worker-pass-content-in-handoff-docs.md +42 -0
  7. package/.agents/notes/decisions/2026-12-01-router-runs-on-a-flash-model-with-low-effort.md +33 -0
  8. package/.agents/notes/decisions/2026-12-01-sync-feeds-refine-then-events-to-the-router.md +38 -0
  9. package/.agents/notes/pitfalls/2026-12-01-replace-string-dollar-quote-expands.md +16 -0
  10. package/.agents/notes/pitfalls/2026-12-02-rhythm-start-in-the-foreground-displaces-the-launchd-service.md +27 -0
  11. package/.agents/skills/work-rhythm/SKILL.md +20 -12
  12. package/README.md +32 -4
  13. package/collectors/local.env.example +10 -1
  14. package/docs/agents.md +53 -13
  15. package/docs/channels.md +9 -6
  16. package/docs/router-worker.md +263 -0
  17. package/docs/scheduled-tasks.md +5 -5
  18. package/docs/sources.md +20 -0
  19. package/package.json +1 -1
  20. package/scripts/cli.js +5 -3
  21. package/scripts/cmd/agent.js +188 -49
  22. package/scripts/cmd/ask.js +104 -0
  23. package/scripts/cmd/check.js +4 -0
  24. package/scripts/cmd/listen.js +18 -4
  25. package/scripts/cmd/rhythm.js +6 -2
  26. package/scripts/cmd/sync.js +11 -3
  27. package/scripts/cmd/trigger.js +143 -0
  28. package/scripts/lib/agent.js +482 -30
  29. package/scripts/lib/asks.js +145 -0
  30. package/scripts/lib/bot.js +140 -35
  31. package/scripts/lib/engine.js +707 -0
  32. package/scripts/lib/handoff.js +167 -0
  33. package/scripts/lib/markdown.js +355 -36
  34. package/scripts/lib/rhythm.js +576 -38
  35. package/scripts/lib/router.js +208 -0
  36. package/scripts/lib/run.js +43 -0
  37. package/scripts/lib/view.js +736 -0
  38. package/scripts/lib/worker.js +98 -0
  39. package/scripts/test/agent.test.js +126 -9
  40. package/scripts/test/check.test.js +7 -2
  41. package/scripts/test/harness.js +15 -1
  42. package/scripts/test/listen.test.js +2 -2
  43. package/scripts/test/rhythm.test.js +109 -6
  44. package/scripts/test/router-helper.js +110 -0
  45. package/scripts/test/router.test.js +799 -0
  46. package/scripts/test/stubs.js +113 -12
  47. package/scripts/test/timeout.test.js +99 -0
  48. package/tasks/daily-plan.md +1 -2
  49. package/templates/00-config/profile.example.yaml +9 -0
  50. package/templates/AGENTS.md +3 -1
  51. package/templates/README.md +4 -1
@@ -0,0 +1,110 @@
1
+ // 自测里假 agent 的「脑子」:认 work-rhythm 的两种提示词,决定该回什么。
2
+ // 路由那一轮(以「【work-rhythm 路由】」开头):按 STUB_ROUTER_MODE / STUB_ROUTER_REPLY 回一段决定
3
+ // 执行者那一句(「读 .agents/handoff/<短号>.md(任务书)…」):读任务书,算出回执的正文
4
+ // 各家假的命令行(stubs.js)拿到结果后按自己的输出格式包一层。不碰真实账号。
5
+ 'use strict';
6
+ const fs = require('node:fs');
7
+
8
+ const read = (rel) => {
9
+ try {
10
+ return fs.readFileSync(rel, 'utf8');
11
+ } catch {
12
+ return '';
13
+ }
14
+ };
15
+
16
+ // 默认的决定:消息类的原样转述(dispatch + 任务书),定时任务 dispatch,汇报 notify 回执正文
17
+ function defaultReply(prompt) {
18
+ const out = ['决定:'];
19
+ const sections = [];
20
+ for (const line of prompt.split('\n')) {
21
+ let m = /^\[(t-\d+)\] 来源=(message|manual) 时间=\S+ \S+ 原话:(.*)$/.exec(line);
22
+ if (m) {
23
+ out.push(`- ${m[1]} dispatch`);
24
+ sections.push(`## handoff ${m[1]}\n# 任务:转述\n\n把这句话原样回复给我:「${m[3]}」`);
25
+ continue;
26
+ }
27
+ m = /^\[(t-\d+)\] 来源=(schedule|events|answer) /.exec(line);
28
+ if (m) {
29
+ out.push(`- ${m[1]} dispatch`);
30
+ continue;
31
+ }
32
+ m = /^\[(t-\d+)\] 来源=report 时间=\S+ \S+ 对应=(t-\d+) 结果=(成功|失败)(?: 用时=\d+s)?(?: 原因=(.*?))? 回执=(\S+)/.exec(line);
33
+ if (m) {
34
+ out.push(`- ${m[1]} notify`);
35
+ const body = read(m[5]).replace(/^# .*\n\n?(- .*\n)*\n?/, '').trim();
36
+ sections.push(`## notify ${m[1]}\n${m[3] === '成功' ? body : `没做成:${m[4] || ''}`}`);
37
+ }
38
+ }
39
+ return `${out.join('\n')}\n\n${sections.join('\n\n')}\n`;
40
+ }
41
+
42
+ // 执行者的回执正文:任务书里写了「把这句话原样回复给我:「…」」就回那句;定时任务回「做了:<标题>」
43
+ function workerText(taskRel) {
44
+ const task = read(taskRel);
45
+ const m = /把这句话原样回复给我:「(.*)」/.exec(task);
46
+ if (m) return m[1];
47
+ const title = /^#?\s*任务[::]\s*(.+)$/m.exec(task);
48
+ return `做了:${title ? title[1].trim().replace(/[。.]\s*$/, '') : '按任务书做完'}`;
49
+ }
50
+
51
+ // args 是假命令行收到的参数。返回 null(不是这两种提示词)或 { kind, text, taskRel, resultRel, delay }
52
+ function forArgs(args) {
53
+ const prompt = String(args[args.length - 1] || '');
54
+ if (prompt.startsWith('【work-rhythm 路由】')) {
55
+ try {
56
+ fs.appendFileSync(process.env.STUB_ROUTER_CALLS || '/dev/null', `${prompt}\n⏎⏎⏎\n`);
57
+ } catch {
58
+ // 没指定文件就不记
59
+ }
60
+ const mode = process.env.STUB_ROUTER_MODE || '';
61
+ if (mode === 'garbage') return { kind: 'router', text: '好的,我来想想怎么安排。' };
62
+ if (mode === 'timeout') return { kind: 'hang', delay: Number(process.env.STUB_ROUTER_DELAY) || 8, text: '太晚了' };
63
+ const file = process.env.STUB_ROUTER_REPLY || '';
64
+ if (file && fs.existsSync(file)) return { kind: 'router', text: fs.readFileSync(file, 'utf8') };
65
+ return { kind: 'router', text: defaultReply(prompt) };
66
+ }
67
+ const m = /^读 (\S+)(任务书),照它做完,把回执写到 (\S+);/.exec(prompt);
68
+ if (!m) return null;
69
+ // 提炼的任务书里带着今天每日文件的路径:假的执行者往它的「## 事件流」里加几条(STUB_REFINE_ADDS=1 时)
70
+ const task = read(m[1]);
71
+ const daily = /^# 任务:把今天新采到的数据提炼成事件/m.test(task) ? /((\S+\/02-daily\/\d{4}-\d{2}\/\d{4}-\d{2}-\d{2}\.md))的「## 事件流」/.exec(task) : null;
72
+ return { kind: 'worker', text: workerText(m[1]), taskRel: m[1], resultRel: m[2], daily: daily ? daily[1] : '' };
73
+ }
74
+
75
+ // 往每日文件的「## 事件流」里加两条(没有这一节就建):假的提炼执行者用
76
+ function addEvents(file) {
77
+ if (!file || process.env.STUB_REFINE_ADDS !== '1') return;
78
+ const path = require('node:path');
79
+ fs.mkdirSync(path.dirname(file), { recursive: true });
80
+ let text = '';
81
+ try {
82
+ text = fs.readFileSync(file, 'utf8');
83
+ } catch {
84
+ text = '';
85
+ }
86
+ const rows = '| 09:00 | 会议 | 需求评审 | calendar-yzj | 导出 |\n| 10:30 | 沟通 | 和测试对完导出边界 | im-yzj | 导出 |\n';
87
+ const table = '| 时间 | 类型 | 事项 | 来源 | 项目 |\n|------|------|------|------|------|\n' + rows;
88
+ if (!/^## 事件流\s*$/m.test(text)) fs.writeFileSync(file, `${text}${text ? '\n\n' : ''}## 事件流\n\n${table}\n`);
89
+ else {
90
+ // 加在这一节的表后面:找到这一节的最后一行表格行
91
+ const lines = text.split('\n');
92
+ const start = lines.findIndex((l) => /^## 事件流\s*$/.test(l));
93
+ let end = start + 1;
94
+ while (end < lines.length && !/^## \S/.test(lines[end])) end += 1;
95
+ let last = end - 1;
96
+ while (last > start && !lines[last].trim()) last -= 1;
97
+ lines.splice(last + 1, 0, ...rows.trim().split('\n'));
98
+ fs.writeFileSync(file, lines.join('\n'));
99
+ }
100
+ }
101
+
102
+ // 执行者自己写回执(STUB_WORKER_WRITES=1 时):真的执行者写文件,假的也写
103
+ function writeResult(resultRel, text) {
104
+ if (process.env.STUB_WORKER_WRITES !== '1') return false;
105
+ fs.mkdirSync(require('node:path').dirname(resultRel), { recursive: true });
106
+ fs.writeFileSync(resultRel, `# 回执\n\n${text}\n`);
107
+ return true;
108
+ }
109
+
110
+ module.exports = { forArgs, writeResult, addEvents, defaultReply, workerText };