work-rhythm 0.1.2 → 0.1.3

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.
@@ -42,6 +42,7 @@ when_to_use: "第一次进入工作目录、初始化还没做完(setup.status
42
42
  | 接入某个 IM | `docs/im-adapters.md` |
43
43
  | 开通提醒推送(消息渠道),或给别的 IM 新增一个渠道 | `docs/channels.md` |
44
44
  | 执行或设置定时任务 | `docs/scheduled-tasks.md` |
45
+ | 列事件流(`work-rhythm events`) | `work-rhythm events --help`;格式见 `docs/formats.md` 的「事件流」 |
45
46
  | 给 work-rhythm 绑定 agent(定时任务和值守用哪个),或本机哪个 agent 能用 | `docs/agents.md` |
46
47
  | 了解用户 | `00-config/profile.yaml`、`00-config/sources.yaml`、`05-goals/` |
47
48
  | 写或改脚本、配置、文档格式之前,或者刚踩了坑 | `.agents/notes/AGENTS.md`,按它的路由表看相关的踩坑笔记 |
@@ -55,6 +56,7 @@ when_to_use: "第一次进入工作目录、初始化还没做完(setup.status
55
56
  | `setup.status` 不是 `done`,用户只是打招呼或说「开始」「帮我弄」 | 从「引导流程」的步骤 0 开始,再接着第一个没完成的步骤 |
56
57
  | 「记一下……」「刚才开了个会……」 | 记一笔 |
57
58
  | 「同步一下」「拉一下数据」 | 同步并提炼事件 |
59
+ | 「今天都发生了什么」「事件流有什么变化」「我最近在忙什么」「X 那件事怎么样了」「这个月会多不多」,或任何问工作目录里的事 | 看「看事件流、问目录里的事」 |
58
60
  | 「今天怎么安排」「做个计划」「进展」「复盘」「整理下遗留」 | 手动执行定时任务 |
59
61
  | 「看看我的工作规律」「我最近在忙什么」 | 总结工作规律 |
60
62
  | 「定个目标」「我想长期盯着 X」 | 长期目标 · 新建 |
@@ -184,9 +186,18 @@ IM 是工作密度最高的信号,也决定了后面能不能自动化,所
184
186
 
185
187
  1. 跑 `work-rhythm sync [起始日期]` 同步所有已启用的源,或者只跑某一个:`work-rhythm sync <起始日期> <源id>`(数据落在 `01-inbox/<源id>/<今天>/`)。失败的源在今天文件「## 备注」里记一行(「12:30 同步:im-yzj 失败,未登录」),继续处理其他源。
186
188
  2. 读 `01-inbox/` 里的输出,按各源在 `00-config/sources.yaml` 里的 `extract` 规则提炼事件。规则遵守 `docs/formats.md` 的「事件流」一节。
187
- 3. 合并进今天文件的「## 事件流」:替换同来源同时段的旧事件,保留 `口述` 的行,按时间排序。
189
+ 3. 合并进今天文件的「## 事件流」:替换同来源同时段的旧事件,保留 `口述` 的行,按时间排序(合并后 `work-rhythm events --today` 能把它列出来,核对一眼)。
188
190
  4. 汇报一行:新增多少条事件,哪些源失败。
189
191
 
192
+ ## 看事件流、问目录里的事
193
+
194
+ 用户问工作目录里的事——今天发生了什么、事件流有什么变化、最近在忙什么、某件事进展如何、会多不多、哪些事快搁置了——答案都在这个目录里,不要凭印象答:
195
+
196
+ 1. **先取数**:`work-rhythm events --today`(或 `--days N`、`--from/--to`;`--type`、`--source`、`--project` 筛选;`--json` 给程序读)拿到事件流,它是每日文件「## 事件流」那张表 flatten 后的样子。再按问题读对应的记录:遗留 `03-carryover/CARRYOVER.md`,决定 `work-rhythm decisions list`,目标 `work-rhythm goals list` 和 `05-goals/`,规律画像 `04-patterns/WORK_RHYTHM.md`,我是谁 `00-config/profile.yaml`。事件流还停在早上,就先 `work-rhythm sync` 并提炼一遍(上一节)。
197
+ 2. **答问题**:先结论,再依据(哪天几点、哪个来源),不展开细节。数字从取到的数据里数,不估。没有记录就说没有,不编。
198
+ 3. **顺着变化做事**:事件流里有新东西时,想着下一步——新冒出来的工作项、告警,问要不要进遗留;搁置快满 5 个工作日的提醒一句;和长期目标有关的事件,记进展(`work-rhythm goals progress <id>`);日程变了,建议调今天的计划;有该我定的事,`work-rhythm decisions add … --choice 未答` 记下,再问我。记一笔、同步、更新每日文件这类只写工作目录的动作直接做;其余都是建议,先说再做。
199
+ 4. 答完问一句:要不要据此做点什么。
200
+
190
201
  ## 接入一个数据源
191
202
 
192
203
  用户说「把 XX 接进来」,或者在引导里点名了某个记录系统(工作项、日志、文档、工时、审批……)时,不管 `docs/sources.md` 的目录里有没有它,都按这个顺序:
package/README.md CHANGED
@@ -31,7 +31,7 @@ ln -s "$(npm root -g)/work-rhythm/.agents/skills/work-rhythm" ~/.agents/skills/w
31
31
  | 命令 | 做什么 |
32
32
  |---|---|
33
33
  | `init`、`workdir` | 新建工作目录;找到、登记、扫描工作目录 |
34
- | `today`、`goals`、`decisions` | 每日约定、长期目标、待决与决定的记录 |
34
+ | `today`、`goals`、`decisions`、`events` | 每日约定、长期目标、待决与决定的记录、事件流 |
35
35
  | `sync`、`collect` | 跑内置或自己写的采集器,原始数据落 `01-inbox/` |
36
36
  | `notify`、`listen` | 消息渠道:把提醒推给我;值守,收我在 IM 里说的话交给本地 agent |
37
37
  | `agent` | 定时任务和机器人值守用哪个 agent:检测本机的、绑定、试一句([docs/agents.md](docs/agents.md)) |
package/docs/formats.md CHANGED
@@ -117,6 +117,10 @@
117
117
  - 来源填订阅源的 id(见 [00-config/sources.yaml](../00-config/sources.yaml)),用户自己说的填 `口述`。
118
118
  - 项目填简短标签,归不进去就留空。事件和某个长期目标相关时,项目列填目标的 id。
119
119
 
120
+ ### agent 怎么读
121
+
122
+ `work-rhythm events` 把一段时间里的这张表列出来(`--days N`、`--from/--to`、`--type`、`--source`、`--project`、`--json`),按日期、时间排好;写完之后用它核对一眼。
123
+
120
124
  ### 合并
121
125
 
122
126
  - 同一来源、同一类型、30 分钟内连续发生的活动合成一条;编码类放宽到 90 分钟。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "work-rhythm",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "个人工作目录:记录每天的工作事件、按订阅源采集数据、做计划和复盘;带本地服务(定时采集、定时整理、经消息渠道推送、本机网页)",
5
5
  "license": "UNLICENSED",
6
6
  "type": "commonjs",
package/scripts/cli.js CHANGED
@@ -19,6 +19,7 @@ const COMMANDS = {
19
19
  decisions: 'decisions add | answer | done | list | archive … 待决与决定的记录',
20
20
  sync: 'sync [起始日期] [源 id …] 依次运行已启用的源,原始数据落 01-inbox/<源>/<今天>',
21
21
  collect: 'collect <源id> <输出目录> [起始日期] 只跑一个采集器',
22
+ events: 'events [--days N] [--today] [--type …] [--json] 列出每日文件里的事件流:什么时候、做了什么、属于哪个项目',
22
23
  notify: 'notify "<文字>" | - 把一段文字经消息渠道推给我本人,或从标准输入读',
23
24
  check: 'check 改完脚本、配置或文档后跑一遍:语法、内链、预算、配置、密钥、笔记',
24
25
  listen: 'listen probe|run|handle|handle-frame|reset|doctor|install|uninstall|status 值守:收我在 IM 里说的话,交给本地 agent 回复',
@@ -39,11 +40,14 @@ const usage = (name) => {
39
40
  const lines = Object.entries(COMMANDS).map(([key, text]) => ` ${text}`);
40
41
  return `work-rhythm ${VERSION} —— 个人工作目录的日常运转
41
42
  用法: work-rhythm <子命令> [参数] [--workdir <目录>]
42
- 在某个工作目录里运行,就作用在那个目录上;不在时往上找带 00-config/profile.yaml 的目录,也可以用 --workdir 指定。
43
+ 每个子命令的详细用法: work-rhythm <子命令> --help(写在子命令后面也行,任何位置都认)
44
+ 在工作目录里运行就作用在那个目录上;不在时往上找带 00-config/profile.yaml 的目录,也可以用 --workdir 指定
45
+ 退出码约定: 0 成功 · 2 用法不对 · 3 没配置好(含「不在工作目录里」)· 4 缺依赖 · 5 运行失败;
46
+ check 和各 doctor 用 1 表示「查出了问题」。子命令有别的约定时它的 --help 里会写
43
47
 
44
48
  ${lines.join('\n')}
45
49
  --help [子命令] | --version
46
- 消息渠道见 docs/channels.md,定时任务见 docs/scheduled-tasks.md。`;
50
+ 流程和规则在 work-rhythm skill(.agents/skills/work-rhythm/SKILL.md);消息渠道见 docs/channels.md,定时任务见 docs/scheduled-tasks.md,agent 见 docs/agents.md。`;
47
51
  };
48
52
 
49
53
  async function main(argv) {
@@ -77,6 +81,12 @@ async function main(argv) {
77
81
  stderr.write(`work-rhythm: 不认识的子命令「${name}」\n\n${usage()}\n`);
78
82
  return EXIT.USAGE;
79
83
  }
84
+ // 「work-rhythm notify --help」这种:任何位置出现 --help / -h,或者第一个参数是 help,都只打用法、什么都不做。
85
+ // 必须在分发之前截住——不然 notify 会把「--help」当成要发的文字发出去,init 会建一个叫 --help 的目录
86
+ if (rest.includes('--help') || rest.includes('-h') || rest[0] === 'help') {
87
+ stdout.write(`${usage(name)}\n`);
88
+ return EXIT.OK;
89
+ }
80
90
  // 作用在哪个目录:--workdir 指定的,或从当前目录往上找;站在这个包自己的仓库里就是仓库(只有 check 查它);最后看用户级的登记
81
91
  const found = resolveRoot({ cwd: process.cwd(), option: rootOption, env: process.env, packageRoot: PACKAGE_ROOT });
82
92
  const ctx = { root: found.root, rootSource: found.source, cwd: process.cwd(), stdin: process.stdin, stdout, stderr, env: process.env, packageRoot: PACKAGE_ROOT };
@@ -90,9 +100,9 @@ async function main(argv) {
90
100
  try {
91
101
  return await require(`./cmd/${name}`).run(rest, ctx);
92
102
  } catch (error) {
93
- // 用法不对、没配置好、缺依赖、没跑成:消息打给用户,按它带的退出码结束
103
+ // 用法不对、没配置好、缺依赖、没跑成:消息打给用户,按它带的退出码结束。用法错的顺带告诉它用法在哪
94
104
  if (error instanceof Fail) {
95
- stderr.write(`work-rhythm ${name}: ${error.message}\n`);
105
+ stderr.write(`work-rhythm ${name}: ${error.message}${error.code === EXIT.USAGE ? `\n(用法: work-rhythm ${name} --help)` : ''}\n`);
96
106
  return error.code;
97
107
  }
98
108
  throw error;
@@ -14,12 +14,16 @@ const { EXIT, Fail, UsageError } = require('../lib/run');
14
14
  const { settings } = require('../lib/config');
15
15
  const { PRESETS, PRESET_NAMES, invokingAgent, installedAgents, bindAgent, createAgent } = require('../lib/agent');
16
16
 
17
- const USAGE = `用法: work-rhythm agent [子命令]
17
+ const USAGE = `work-rhythm agent [子命令] —— 定时任务和机器人值守用哪个 agent:检测本机的、绑定、试一句
18
+
19
+ 用法: work-rhythm agent [子命令]
18
20
  看本机装了哪些、现在是不是有 agent 正在调这个 skill、现在绑的是哪个(--json 打成 JSON)
19
21
  bind [名字|命令] 绑定,写进 collectors/local.env 的 YZJ_BOT_AGENT;不给名字就用正在调的这个,没有就装了的第一个
20
22
  test ["一句话"] 让绑定的 agent 答一句
21
23
  doctor 绑定的 agent 配置和依赖有没有问题
22
- 预置:${PRESET_NAMES.join('、')};其余值当成一条自己的命令`;
24
+ 预置:${PRESET_NAMES.join('、')};其余值当成一条自己的命令(消息作为最后一个参数,回复打到标准输出)。
25
+ 退出码: 0;1 doctor 查出问题;2 用法不对;3 没绑或绑不上(本机找不到那个 agent);5 test 没答上来。
26
+ 各家怎么被调用、权限模式见 docs/agents.md。`;
23
27
 
24
28
  function binding(root, env) {
25
29
  return (settings(root, env).YZJ_BOT_AGENT || '').trim();
@@ -341,4 +341,12 @@ async function run(args, ctx) {
341
341
  return bad ? 1 : EXIT.OK;
342
342
  }
343
343
 
344
- module.exports = { usage: '用法: work-rhythm check 改完脚本、配置或文档后跑一遍,只读', run, __test: { genericProblems, checkTemplates } };
344
+ const USAGE = `work-rhythm check —— 改完配置或文档后跑一遍:脚本语法、文档内链、预算、配置自检、疑似密钥、笔记格式。只读,不改任何文件
345
+
346
+ 用法:
347
+ work-rhythm check
348
+ 在工作目录里是 6 项;站在这个包自己的仓库里是另一套 7 项(多了「模板」「仓库保持通用」,没有「配置自检」)。
349
+ 每项的问题逐条打出来;疑似密钥只报位置、不打印内容。
350
+ 退出码: 0 全部通过;1 有未通过的项;2 用法不对;3 不在工作目录里。`;
351
+
352
+ module.exports = { usage: USAGE, run, __test: { genericProblems, checkTemplates } };
@@ -8,8 +8,17 @@ const { EXIT, UsageError } = require('../lib/run');
8
8
  const { loadSources } = require('../lib/config');
9
9
  const { resolveCollector, spawnCollector } = require('./sync');
10
10
 
11
+ const USAGE = `work-rhythm collect <源id> <输出目录> [起始日期] [采集器自己的参数…] —— 只跑一个采集器(任务里「取今日日程」「取告警」这种只要一个源的数据时用)
12
+
13
+ 用法:
14
+ work-rhythm collect calendar-yzj 01-inbox/calendar-yzj/2026-12-01 2026-12-01
15
+ 输出目录写成 01-inbox/<源id>/<日期>:和 im-yzj 共用采集器的源(如 ops-yzj)靠它认出自己该读哪个变量。
16
+ sources.yaml 里有的源按它登记的采集器跑;没有的,把 <源id> 当成内置采集器的 id。
17
+ 起始日期默认今天;采集器自己的参数原样传给它(比如 im-yzj 的页数)。
18
+ 退出码就是采集器的:0 成功;2 参数错;3 未配置;4 缺依赖;5 远端失败或结果不完整(这时不留上一次的旧文件)。`;
19
+
11
20
  module.exports = {
12
- usage: '用法: work-rhythm collect <源id> <输出目录> [起始日期]',
21
+ usage: USAGE,
13
22
  async run(args, ctx) {
14
23
  const { root, env, packageRoot } = ctx;
15
24
  const [id, out] = args;
@@ -11,12 +11,7 @@ const fs = require('node:fs');
11
11
  const path = require('node:path');
12
12
  const { EXIT, addDays, today, writeFileAtomic } = require('../lib/run');
13
13
 
14
- const USAGE = `用法: work-rhythm decisions <子命令>
15
- add --item <事项> [--options <选项>] --choice <决定> [--reason <理由>] [--by <我|AI|一起>] [--date <YYYY-MM-DD>]
16
- answer <事项> <决定> [--reason <理由>] [--by <我|AI|一起>]
17
- done <事项> <落实>
18
- list [天数] [--today]
19
- archive [天数]`;
14
+
20
15
 
21
16
  const KEEP_DAYS = 60;
22
17
  const COLUMNS = ['日期', '事项', '选项', '决定', '理由', '谁来做', '落实'];
@@ -112,6 +107,22 @@ function parseFlags(args, names) {
112
107
  return { opts, positional };
113
108
  }
114
109
 
110
+ const USAGE = `work-rhythm decisions <子命令> —— 待决与决定的记录(03-carryover/DECISIONS.md)。它只是以后的参考,不替我决定
111
+
112
+ 用法:
113
+ work-rhythm decisions add --item <事项> [--options <选项>] --choice <决定> [--reason <理由>] [--by <我|AI|一起>] [--date <YYYY-MM-DD>]
114
+ 记一条。事项不超过 30 字、不含竖线;「待决询问」刚问出去还没答时 --choice 写「未答」
115
+ work-rhythm decisions answer <事项> <决定> [--reason <理由>] [--by <我|AI|一起>]
116
+ 我答了之后,把最近一条还没答的改成我的决定
117
+ work-rhythm decisions done <事项> <落实>
118
+ 补「落实」那一格:只补最近一条还没写的
119
+ work-rhythm decisions list [天数] [--today]
120
+ 看记录(TSV),默认最近 60 天,要更早的就连归档一起查;--today 只看今天的
121
+ work-rhythm decisions archive [天数]
122
+ 把超过天数(默认 60)的行挪进 03-carryover/archive/
123
+ 问之前先 list,有类似的决定就带一句「上次是这么定的」。
124
+ 退出码: 0;2 参数不对、事项不合规、找不到那一条、没有待答的记录;3 不在工作目录里。`;
125
+
115
126
  module.exports = {
116
127
  usage: USAGE,
117
128
  archive,
@@ -0,0 +1,103 @@
1
+ // 列出每日文件里的事件流:agent 要「基于事件流干事儿」「问问最近在忙什么」时,先从这里拿数据,不用自己翻一堆 Markdown
2
+ // 读的是 02-daily/YYYY-MM/YYYY-MM-DD.md 里「## 事件流」那张表(docs/formats.md),只读不改
3
+ 'use strict';
4
+ const fs = require('node:fs');
5
+ const path = require('node:path');
6
+ const { EXIT, UsageError, parseDate, addDays, today, fmtDate } = require('../lib/run');
7
+
8
+ const USAGE = `work-rhythm events [选项] —— 列出每日文件「## 事件流」里的事件(什么时候、做了什么、属于哪个项目),只读
9
+
10
+ 用法:
11
+ work-rhythm events 最近 7 天(含今天)
12
+ work-rhythm events --today 只看今天
13
+ work-rhythm events --days 14 最近 14 天
14
+ work-rhythm events --from 2026-11-20 --to 2026-11-30
15
+ work-rhythm events --type 会议,沟通 只看这些类型(词表见 docs/formats.md 的「事件类型」)
16
+ work-rhythm events --source calendar-yzj 只看这些来源(订阅源的 id,或「口述」)
17
+ work-rhythm events --project 导出 只看这些项目标签(和长期目标相关的事件,项目列是目标 id)
18
+ work-rhythm events --json 每条一个对象,给程序读
19
+ 输出是 TSV(制表符分隔),第一行表头 date、time、type、item、source、project,按日期、时间排好序。
20
+ 事件是「一行一事」的记录,不含细节;要细节看 01-inbox/ 的快照或问用户。
21
+ 退出码: 0(没有事件也是 0,只有表头);2 选项或日期不对;3 不在工作目录里。`;
22
+
23
+ const FIELDS = ['date', 'time', 'type', 'item', 'source', 'project'];
24
+ const COLUMNS = { 时间: 'time', 类型: 'type', 事项: 'item', 来源: 'source', 项目: 'project' };
25
+
26
+ // 「## 事件流」那一节里的表:表头给出列名,分隔线跳过。格子里转义的竖线先换成占位符再切。后面几格缺的留空
27
+ function parseEvents(markdown, date) {
28
+ const lines = String(markdown).split('\n');
29
+ const start = lines.findIndex((l) => /^##\s*事件流\s*$/.test(l));
30
+ if (start < 0) return [];
31
+ const events = [];
32
+ let columns = null;
33
+ for (let i = start + 1; i < lines.length && !/^##\s/.test(lines[i]); i += 1) {
34
+ const line = lines[i].trim();
35
+ if (!line.startsWith('|')) continue;
36
+ const cells = line.replace(/\\\|/g, '\u0000').split('|').slice(1, -1).map((c) => c.trim().replace(/\u0000/g, '|'));
37
+ if (!cells.length || cells.every((c) => /^:?-+:?$/.test(c))) continue;
38
+ if (!columns) {
39
+ columns = cells.map((name) => COLUMNS[name] || '');
40
+ continue;
41
+ }
42
+ // 至少要有时间和类型两格;只有一格的(写坏的行、夹在表里的说明)不算事件
43
+ if (cells.length < 2) continue;
44
+ const event = { date, time: '', type: '', item: '', source: '', project: '' };
45
+ columns.forEach((field, n) => {
46
+ if (field) event[field] = cells[n] || '';
47
+ });
48
+ if (event.time) events.push(event);
49
+ }
50
+ return events;
51
+ }
52
+
53
+ function readDay(root, date) {
54
+ try {
55
+ return parseEvents(fs.readFileSync(path.join(root, '02-daily', date.slice(0, 7), `${date}.md`), 'utf8'), date);
56
+ } catch {
57
+ return [];
58
+ }
59
+ }
60
+
61
+ const parseList = (value) => String(value || '').split(',').map((s) => s.trim()).filter(Boolean);
62
+
63
+ async function run(args, ctx) {
64
+ const { root, stdout } = ctx;
65
+ const opts = { from: '', to: today(), days: 7, types: [], sources: [], projects: [], json: false };
66
+ for (let i = 0; i < args.length; i += 1) {
67
+ const a = args[i];
68
+ const value = (what) => {
69
+ const v = args[i + 1];
70
+ if (v === undefined || v.startsWith('--')) throw new UsageError(`${a} 后面要跟一个值(${what})`);
71
+ i += 1;
72
+ return v;
73
+ };
74
+ if (a === '--today') opts.days = 1;
75
+ else if (a === '--days') {
76
+ const n = Number(value('天数'));
77
+ if (!Number.isInteger(n) || n < 1) throw new UsageError('--days 要是正整数');
78
+ opts.days = n;
79
+ } else if (a === '--from') opts.from = fmtDate(parseDate(value('YYYY-MM-DD'), '起始日期'));
80
+ else if (a === '--to') opts.to = fmtDate(parseDate(value('YYYY-MM-DD'), '结束日期'));
81
+ else if (a === '--type') opts.types = parseList(value('类型,逗号分隔'));
82
+ else if (a === '--source') opts.sources = parseList(value('来源 id,逗号分隔'));
83
+ else if (a === '--project') opts.projects = parseList(value('项目标签,逗号分隔'));
84
+ else if (a === '--json') opts.json = true;
85
+ else throw new UsageError(`不认识的选项 ${a}`);
86
+ }
87
+ const from = opts.from || addDays(opts.to, -(opts.days - 1));
88
+ if (from > opts.to) throw new UsageError(`起始日期 ${from} 晚于结束日期 ${opts.to}`);
89
+ let list = [];
90
+ for (let d = from; d <= opts.to; d = addDays(d, 1)) list.push(...readDay(root, d));
91
+ const keep = (event, wanted, field) => !wanted.length || wanted.includes(event[field]);
92
+ list = list.filter((e) => keep(e, opts.types, 'type') && keep(e, opts.sources, 'source') && keep(e, opts.projects, 'project'));
93
+ list.sort((a, b) => (a.date < b.date ? -1 : a.date > b.date ? 1 : a.time.localeCompare(b.time)));
94
+ if (opts.json) {
95
+ stdout.write(`${JSON.stringify(list)}\n`);
96
+ return EXIT.OK;
97
+ }
98
+ stdout.write(`${FIELDS.join('\t')}\n`);
99
+ for (const e of list) stdout.write(`${[e.date, e.time, e.type, e.item.replace(/\t/g, ' '), e.source, e.project].join('\t')}\n`);
100
+ return EXIT.OK;
101
+ }
102
+
103
+ module.exports = { usage: USAGE, run, parseEvents };
@@ -7,9 +7,8 @@
7
7
  'use strict';
8
8
  const fs = require('node:fs');
9
9
  const path = require('node:path');
10
- const { EXIT, noon, today, daysBetween, readText, writeFileAtomic } = require('../lib/run');
10
+ const { EXIT, UsageError, noon, today, daysBetween, readText, writeFileAtomic } = require('../lib/run');
11
11
 
12
- const USAGE = '用法: work-rhythm goals list | due [日期] | touch <id> [日期] | progress <id> [日期]';
13
12
  const HEADER_LIST = 'id\tstatus\ttitle\tsince_review\tsince_progress';
14
13
  const HEADER_DUE = 'id\ttitle\tsince_review\treview_every';
15
14
 
@@ -88,6 +87,16 @@ const goalFiles = (root) => {
88
87
  return names.map((n) => path.join(dir, n));
89
88
  };
90
89
 
90
+ const USAGE = `work-rhythm goals list | due [日期] | touch <id> [日期] | progress <id> [日期] —— 长期目标的小工具(目标文件在 05-goals/<id>.md)
91
+
92
+ 用法:
93
+ work-rhythm goals list 进行中和暂停的目标,带距上次检查、距上次进展的天数
94
+ work-rhythm goals due [YYYY-MM-DD] 今天(或指定那天)该检查的目标:距上次检查超过 review_every 天的
95
+ work-rhythm goals touch <id> [YYYY-MM-DD] 检查完之后,只改 last_review
96
+ work-rhythm goals progress <id> [YYYY-MM-DD] 有进展之后,只改 last_progress
97
+ 输出是 TSV(制表符分隔),第一行表头。日期默认今天。到期与否由这里算,不要手算日期。
98
+ 退出码: 0;2 子命令、id 或日期不对;3 不在工作目录里。`;
99
+
91
100
  module.exports = {
92
101
  usage: USAGE,
93
102
  async run(args, ctx) {
@@ -105,10 +114,7 @@ module.exports = {
105
114
  }
106
115
  if (cmd === 'due') {
107
116
  const date = rest[0] || today();
108
- if (!noon(date)) {
109
- stderr.write(`goals: 无法识别日期 '${date}'\n`);
110
- return EXIT.USAGE;
111
- }
117
+ if (!noon(date)) throw new UsageError(`无法识别日期 '${date}'`);
112
118
  stdout.write(`${HEADER_DUE}\n`);
113
119
  for (const f of goalFiles(root)) {
114
120
  if (field(f, 'status') !== 'active') continue;
@@ -122,24 +128,14 @@ module.exports = {
122
128
  }
123
129
  if (cmd === 'touch' || cmd === 'progress') {
124
130
  const [id, dateArg] = rest;
125
- if (!id) {
126
- stderr.write(`用法: work-rhythm goals ${cmd} <id> [日期]\n`);
127
- return EXIT.USAGE;
128
- }
131
+ if (!id) throw new UsageError(`goals ${cmd} 要写 <id>:work-rhythm goals ${cmd} <id> [日期]`);
129
132
  const date = dateArg || today();
130
133
  const file = path.join(root, '05-goals', `${id}.md`);
131
- if (!fs.existsSync(file)) {
132
- stderr.write(`goals: 找不到 05-goals/${id}.md\n`);
133
- return EXIT.USAGE;
134
- }
135
- if (!noon(date)) {
136
- stderr.write(`goals: 无法识别日期 '${date}'\n`);
137
- return EXIT.USAGE;
138
- }
134
+ if (!fs.existsSync(file)) throw new UsageError(`找不到 05-goals/${id}.md`);
135
+ if (!noon(date)) throw new UsageError(`无法识别日期 '${date}'`);
139
136
  setField(file, cmd === 'touch' ? 'last_review' : 'last_progress', date);
140
137
  return EXIT.OK;
141
138
  }
142
- stderr.write(`${USAGE}\n`);
143
- return EXIT.USAGE;
139
+ throw new UsageError(`不认识的子命令「${cmd}」,只有 list / due / touch / progress`);
144
140
  },
145
141
  };
@@ -11,7 +11,13 @@ const { EXIT, Fail, UsageError } = require('../lib/run');
11
11
  const { register } = require('../lib/workdir');
12
12
  const { writeWorkdir } = require('../lib/template');
13
13
 
14
- const USAGE = '用法: work-rhythm init <目录>';
14
+ const USAGE = `work-rhythm init <目录> —— 新建一个工作目录:用包里带的模板铺出来(个人信息空白、数据源全关、没有记录),并登记
15
+
16
+ 用法:
17
+ work-rhythm init ~/workspace/my-work
18
+ work-rhythm init my-work 相对路径按当前目录算;上级目录没有就一起建
19
+ 建好之后对 AI 说「开始引导」。工作目录只是机器上的一个目录:不 git init,不同步到任何仓库。
20
+ 退出码: 0 建好;2 用法不对,或目录已经存在(拿它当工作目录用 work-rhythm workdir register);5 包不完整或铺出来的不是空白的(会把建了一半的目录删掉)。`;
15
21
 
16
22
  module.exports = {
17
23
  usage: USAGE,
@@ -11,7 +11,9 @@ const { settings } = require('../lib/config');
11
11
  const { createBot } = require('../lib/bot');
12
12
  const launchd = require('../lib/launchd');
13
13
 
14
- const USAGE = `用法: work-rhythm listen <子命令>
14
+ const USAGE = `work-rhythm listen <子命令> —— 值守:消息渠道的收消息一半。在 IM 里说的话交给绑定的 agent 处理,回复发回来
15
+
16
+ 用法: work-rhythm listen <子命令>
15
17
  probe [--seconds N] 连上去看握手和收到的每一帧,不调 agent,到时退出(默认 60 秒)。第一次验证用
16
18
  run 值守:一直连着,收到消息就处理
17
19
  handle "<消息>" 不连云之家,只走一遍「交给 agent → 打印回复」,调试 agent 配置
@@ -19,7 +21,10 @@ const USAGE = `用法: work-rhythm listen <子命令>
19
21
  reset 丢掉机器人的专属会话,下一句从新会话开始(在聊天里发 /new 也一样)
20
22
  doctor 检查值守的配置和依赖,有问题逐条报出来
21
23
  install | uninstall | status macOS launchd 常驻:开机自启、挂了拉起
22
- 退出码: 0 完成;2 用法不对;3 没配置好;4 缺依赖;5 连不上或没处理成功。详见 lib/bot.js 的文件头和 docs/channels.md`;
24
+ 前提:先绑 agent(work-rhythm agent bind),没绑就没有值守。消息一到先回「收到,正在处理」,agent 的回答随后到。
25
+ 日志 01-inbox/_bot.log 只记时间、msgId、耗时,不记消息内容。
26
+ 退出码: 0 完成;2 用法不对;3 没配置好(没绑 agent、钥匙串里没有地址、不是 yzj-robot 渠道);4 缺依赖;5 连不上或没处理成功。
27
+ 步骤见 docs/channels.md「收消息:值守」。`;
23
28
 
24
29
  const positiveInt = (value, fallback) => {
25
30
  const n = Number(value);
@@ -14,7 +14,15 @@ const { EXIT, Fail, UsageError } = require('../lib/run');
14
14
  const { settings } = require('../lib/config');
15
15
  const { pushText, notifyChannel } = require('../lib/notify');
16
16
 
17
- const USAGE = '用法: work-rhythm notify "<文字>" 或 … | work-rhythm notify -';
17
+ const USAGE = `work-rhythm notify "<文字>" 或 … | work-rhythm notify - —— 把一段文字经消息渠道推给我本人(渠道写在 profile 的 preferences.notify)
18
+
19
+ 用法:
20
+ work-rhythm notify "今天的重点三件" 文字直接给
21
+ … | work-rhythm notify - 文字从标准输入读(计划、复盘这类多行的用它)
22
+ 只发纯文本,只发给我本人;云之家机器人每分钟最多 30 条。状态和信息写到标准错误,标准输出不留东西。
23
+ 退出码: 0 已发出(渠道留空时什么都不发,也是 0);2 用法不对或渠道不认识;3 没配置好(钥匙串里没有地址、取不到我的 openId);
24
+ 4 缺 security;5 发送失败(网络、接口拒绝)。
25
+ 定时任务由本地服务代为推送时(指令末尾注明了「会替你推送」),不要再自己发。发消息前要先问用户。渠道怎么开通见 docs/channels.md。`;
18
26
 
19
27
  async function readStdin(stream) {
20
28
  const chunks = [];
@@ -13,7 +13,13 @@ const { NAME, VERSION } = require('../cli');
13
13
  // npm 给 tgz 起的名字:去掉 @、把 / 换成 -,再接版本号(work-rhythm@0.1.0 → work-rhythm-0.1.0.tgz)
14
14
  const TGZ = `${NAME.replace(/^@/, '').replace('/', '-')}-${VERSION}.tgz`;
15
15
 
16
- const USAGE = '用法: work-rhythm pack [--out <目录>]';
16
+ const USAGE = `work-rhythm pack [--out <目录>] —— 把 skill 和这个包打成可分发的目录,给不用 npm 的人
17
+
18
+ 用法:
19
+ work-rhythm pack 生成 01-inbox/outbox/work-rhythm-skill-<版本>/(站在工作目录里时)
20
+ work-rhythm pack --out <目录> 放到指定目录
21
+ 里面是 work-rhythm/(skill)、给人看的安装说明、VERSION、这个包的 tgz;本机有 zip 再压一份 .zip。
22
+ 退出码: 0;2 用法不对;3 这个包不完整;4 缺 npm;5 npm pack 或写入失败。`;
17
23
 
18
24
  // VERSION 文件:包的版本,加上它来自哪个提交(工作区有没提交的改动时如实标出来)
19
25
  function versionNote(packageRoot, env) {
@@ -11,7 +11,9 @@ const { EXIT, Fail, UsageError } = require('../lib/run');
11
11
  const { settings } = require('../lib/config');
12
12
  const { createRhythm } = require('../lib/rhythm');
13
13
 
14
- const USAGE = `用法: work-rhythm rhythm <子命令>
14
+ const USAGE = `work-rhythm rhythm <子命令> —— 本地服务:定时采集、定时把任务交给 agent 整理、经消息渠道推送、本机网页
15
+
16
+ 用法: work-rhythm rhythm <子命令>
15
17
  start [--tick 秒] 前台跑:到点跑采集和任务,起网页服务。要常驻用 install;--tick 是多久看一次表(默认 20,调试用)
16
18
  stop | status 停掉;看在不在跑、下次什么时候跑什么
17
19
  due [--at 时间] [--days 天数] 从某个时间起,列出什么时候跑什么
@@ -20,7 +22,10 @@ const USAGE = `用法: work-rhythm rhythm <子命令>
20
22
  render <文件.md> 把一份 Markdown 渲染成页面,打到标准输出(自测、调试用)
21
23
  doctor 检查配置和依赖,有问题逐条报出来
22
24
  install | uninstall macOS launchd 常驻:开机自启、挂了拉起
23
- 退出码: 0 完成;2 用法不对;3 没配置好;4 缺依赖;5 运行失败。详见 lib/rhythm.js 的文件头和 docs/scheduled-tasks.md`;
25
+ 定时任务只建在这个服务上,要先绑 agent(work-rhythm agent bind)。任务到点后:把 tasks/<id>.md 的指令交给 agent 跑一遍
26
+ (它会同步数据、整理事件流、写每日文件),agent 最后写的总结经消息渠道推给我,并附本机页面地址。
27
+ 退出码: 0 完成;2 用法不对;3 没配置好(没绑 agent、配置有问题、已经在跑);4 缺依赖;5 运行失败;doctor 查出问题时是 1。
28
+ 定义和用法见 docs/scheduled-tasks.md,agent 见 docs/agents.md。`;
24
29
 
25
30
  const positiveInt = (value, fallback) => {
26
31
  const n = Number(value);
@@ -6,7 +6,13 @@ const path = require('node:path');
6
6
  const { spawnSync } = require('node:child_process');
7
7
  const { UsageError } = require('../lib/run');
8
8
 
9
- const USAGE = '用法: work-rhythm selftest [传给 node --test 的参数]';
9
+ const USAGE = `work-rhythm selftest [--test-name-pattern=…] —— 自测:跑 scripts/test/ 下的用例(node --test),二十秒左右
10
+
11
+ 用法:
12
+ work-rhythm selftest 全部
13
+ work-rhythm selftest --test-name-pattern=notify 只跑名字匹配的
14
+ 用假的命令行工具和本机的假 webhook,不碰真实账号、不发真消息。改完代码、发包之前跑一遍。
15
+ 退出码就是 node --test 的:0 全过;有失败时非 0;2 用法不对。`;
10
16
 
11
17
  module.exports = {
12
18
  usage: USAGE,
@@ -70,4 +70,15 @@ async function run(args, ctx, { deadlineMs } = {}) {
70
70
  return fail;
71
71
  }
72
72
 
73
- module.exports = { usage: '用法: work-rhythm sync [起始日期] [源 id …]', run, resolveCollector, spawnCollector };
73
+ const USAGE = `work-rhythm sync [起始日期] [源 id …] —— 同步订阅源:依次跑 00-config/sources.yaml 里启用的采集器,原始数据落 01-inbox/<源id>/<今天>/
74
+
75
+ 用法:
76
+ work-rhythm sync 从今天起,所有启用的源
77
+ work-rhythm sync 2026-12-01 从那天起,所有启用的源
78
+ work-rhythm sync 2026-12-01 im-yzj 只跑这一个源(可以写多个)
79
+ 只跑一个源、自己指定输出目录,用 work-rhythm collect。每个源的全部输出和报错记在 01-inbox/_sync.log。
80
+ 标准输出每个源一行:ok <源id>,或者 FAIL <源id>(详见 01-inbox/_sync.log)。
81
+ 退出码 = 失败的源数(0 是全部成功);3 不在工作目录里。
82
+ 采集只是取原料:把数据提炼成事件、合并进每日文件的「## 事件流」是 agent 做的(work-rhythm skill 的「同步并提炼事件」)。`;
83
+
84
+ module.exports = { usage: USAGE, run, resolveCollector, spawnCollector };
@@ -3,7 +3,6 @@
3
3
  const { loadProfile } = require('../lib/config');
4
4
  const { EXIT, UsageError, parseDate, fmtDate, today, weekdayCn, weekdayAbbr } = require('../lib/run');
5
5
 
6
- const USAGE = '用法: work-rhythm today [YYYY-MM-DD]\n输出四行:DATE=、WEEKDAY=、DAILY_FILE=、IS_WORKDAY=';
7
6
 
8
7
  // 是否工作日看 profile 的 preferences:workdays 里有没有这一天(Mon…Sun),holidays 里有没有这个日期。
9
8
  // workdays 写成了空列表,就天天都不上班;没写这一项,就天天都上班
@@ -18,6 +17,19 @@ function resolve(root, dateArg) {
18
17
 
19
18
  const output = (info) => `DATE=${info.date}\nWEEKDAY=${info.weekday}\nDAILY_FILE=${info.dailyFile}\nIS_WORKDAY=${info.isWorkday}\n`;
20
19
 
20
+ const USAGE = `work-rhythm today [YYYY-MM-DD] —— 今天在工作目录里的约定:日期、星期、每日文件路径、是否工作日
21
+
22
+ 用法:
23
+ work-rhythm today 今天
24
+ work-rhythm today 2026-12-05 指定的一天
25
+ 输出四行(给脚本和 agent 读的):
26
+ DATE=2026-12-05
27
+ WEEKDAY=五
28
+ DAILY_FILE=02-daily/2026-12/2026-12-05.md 路径相对工作目录
29
+ IS_WORKDAY=1 0 是休息日:不安排工作,定时任务不跑
30
+ 是否工作日看 00-config/profile.yaml 的 preferences.workdays / holidays,不要自己算。
31
+ 退出码: 0;2 日期写错(格式 YYYY-MM-DD);3 不在工作目录里(用 --workdir 指定)。`;
32
+
21
33
  module.exports = {
22
34
  usage: USAGE,
23
35
  resolve,
@@ -14,13 +14,16 @@ const { EXIT, Fail, UsageError } = require('../lib/run');
14
14
  const { isWorkdir, configPath, register, resolveRoot, findAll } = require('../lib/workdir');
15
15
  const { blank } = require('../lib/template');
16
16
 
17
- const USAGE = `用法: work-rhythm workdir [子命令]
17
+ const USAGE = `work-rhythm workdir [子命令] —— 工作目录在哪:找、登记、扫描本机、清空白
18
+
19
+ 用法: work-rhythm workdir [子命令]
18
20
  找工作目录:打印 WORKDIR=<路径> 和 SOURCE=cwd|pointer;找不到时 WORKDIR 为空,退出码 1
19
21
  register [目录] 把目录(默认当前目录)登记为工作目录,写进用户级配置
20
22
  find [起点目录 …] 找本机疑似工作目录的目录(带 00-config/profile.yaml 的);制表符分隔:路径、初始化状态、称呼
21
23
  config 打印用户级配置文件的位置
22
24
  blank <目录> 把一个目录清成空白的工作目录
23
- 新建用 work-rhythm init <目录>`;
25
+ 新建用 work-rhythm init <目录>。
26
+ 退出码: 找不到时 1(WORKDIR 为空);0 完成;2 用法不对或目录不是工作目录;5 清空白时失败;3 不在工作目录里(register / blank)。`;
24
27
 
25
28
  module.exports = {
26
29
  usage: USAGE,
@@ -189,7 +189,9 @@ test('agent doctor:绑定的 agent 有没有问题;用法不对退出码为
189
189
  assert.equal(broken.code, 1);
190
190
  assert.match(broken.stdout, /找不到 DSH 的配置/);
191
191
  assert.equal(s.run(['agent', 'nope'], env).code, 2);
192
- assert.match(s.run(['agent', '--help'], env).stderr, /work-rhythm agent: 用法: work-rhythm agent \[子命令\]/);
192
+ const help = s.run(['agent', '--help'], env);
193
+ assert.equal(help.code, 0);
194
+ assert.match(help.stdout, /work-rhythm agent \[子命令\] —— 定时任务和机器人值守用哪个 agent/);
193
195
  });
194
196
 
195
197
  test('installedAgents:本机真有什么就报什么,不编造', () => {
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+ const { test } = require('node:test');
3
+ const assert = require('node:assert/strict');
4
+ const fs = require('node:fs');
5
+ const path = require('node:path');
6
+ const { makeSandbox, run: rawRun, read, write, addDaysHelper } = require('./harness');
7
+ const { addDays, today } = require('../lib/run');
8
+
9
+ const T = '\t';
10
+ const DAY = (offset) => addDays(today(), offset);
11
+ // 一份每日文件:事件流前后有别的小节,表里有一行格子里带转义的竖线
12
+ function daily(dir, offset, rows, extra = '') {
13
+ const date = DAY(offset);
14
+ const table = rows.length ? `| 时间 | 类型 | 事项 | 来源 | 项目 |\n|------|------|------|------|------|\n${rows.join('\n')}\n` : '| 时间 | 类型 | 事项 | 来源 | 项目 |\n|------|------|------|------|------|\n';
15
+ write(path.join(dir, '02-daily', date.slice(0, 7), `${date}.md`), `# ${date}\n\n## 计划\n\n- **今日重点**:\n\n## 事件流\n\n${table}${extra}\n## 备注\n\n| 09:05 | 沟通 | 备注里的表不算 | x | x |\n\n## 事件流补充\n\n| 10:00 | 其他 | 别的小节里的也不算 | x | x |\n`);
16
+ }
17
+
18
+ test('events:把 7 天内的每日文件里的事件流按日期、时间列成一张表;别的小节里的表不算', (t) => {
19
+ const box = makeSandbox(t);
20
+ const dir = box.workdir();
21
+ daily(dir, 0, ['| 09:05 | 沟通 | 同步接口联调进度 | im-yzj | 导出 |', '| 08:30 | 编码 | 提交 3 次 | git-activity | 导出 |']);
22
+ daily(dir, -1, ['| 14:00 | 会议 | 周会(30min) | calendar-yzj | |']);
23
+ daily(dir, -6, ['| 10:00 | 文档 | 写接口文档 | file-activity | 导出 |']);
24
+ daily(dir, -7, ['| 10:00 | 文档 | 八天前的,不在 7 天里 | file-activity | 旧 |']);
25
+ const r = box.run(['events']);
26
+ assert.equal(r.code, 0, r.out);
27
+ assert.equal(r.stdout, [
28
+ `date${T}time${T}type${T}item${T}source${T}project`,
29
+ `${DAY(-6)}${T}10:00${T}文档${T}写接口文档${T}file-activity${T}导出`,
30
+ `${DAY(-1)}${T}14:00${T}会议${T}周会(30min)${T}calendar-yzj${T}`,
31
+ `${DAY(0)}${T}08:30${T}编码${T}提交 3 次${T}git-activity${T}导出`,
32
+ `${DAY(0)}${T}09:05${T}沟通${T}同步接口联调进度${T}im-yzj${T}导出`,
33
+ '',
34
+ ].join('\n'));
35
+ });
36
+
37
+ test('events:--today、--days、--from/--to 各定一个范围,两头都含', (t) => {
38
+ const box = makeSandbox(t);
39
+ const dir = box.workdir();
40
+ for (const offset of [0, -1, -2, -3]) daily(dir, offset, [`| 09:00 | 其他 | 第 ${offset} 天 | x | |`]);
41
+ const dates = (args) => box.run(['events', ...args]).stdout.trim().split('\n').slice(1).map((l) => l.split(T)[0]);
42
+ assert.deepEqual(dates(['--today']), [DAY(0)]);
43
+ assert.deepEqual(dates(['--days', '3']), [DAY(-2), DAY(-1), DAY(0)]);
44
+ assert.deepEqual(dates(['--from', DAY(-3), '--to', DAY(-2)]), [DAY(-3), DAY(-2)]);
45
+ assert.deepEqual(dates(['--from', DAY(-2)]), [DAY(-2), DAY(-1), DAY(0)]);
46
+ });
47
+
48
+ test('events:按类型、来源、项目筛,可以逗号分隔写多个;--json 每条一个对象', (t) => {
49
+ const box = makeSandbox(t);
50
+ const dir = box.workdir();
51
+ daily(dir, 0, [
52
+ '| 09:05 | 沟通 | 同步进度 | im-yzj | 导出 |',
53
+ '| 10:00 | 会议 | 需求评审 | calendar-yzj | |',
54
+ '| 13:45 | 沟通 | 发材料 | 口述 | demo-goal |',
55
+ ]);
56
+ const items = (args) => box.run(['events', '--today', ...args]).stdout.trim().split('\n').slice(1).map((l) => l.split(T)[3]);
57
+ assert.deepEqual(items(['--type', '沟通,会议']), ['同步进度', '需求评审', '发材料']);
58
+ assert.deepEqual(items(['--type', '会议']), ['需求评审']);
59
+ assert.deepEqual(items(['--source', '口述']), ['发材料']);
60
+ assert.deepEqual(items(['--project', 'demo-goal']), ['发材料']);
61
+ assert.deepEqual(items(['--project', '导出,demo-goal']), ['同步进度', '发材料']);
62
+ const json = JSON.parse(box.run(['events', '--today', '--json']).stdout);
63
+ assert.deepEqual(json[2], { date: DAY(0), time: '13:45', type: '沟通', item: '发材料', source: '口述', project: 'demo-goal' });
64
+ assert.equal(json.length, 3);
65
+ });
66
+
67
+ test('events:没有文件、没有事件流、空表都只有表头;看不懂的行跳过;格子里转义的竖线算一个格子', (t) => {
68
+ const box = makeSandbox(t);
69
+ const dir = box.workdir();
70
+ assert.equal(box.run(['events']).stdout, `date${T}time${T}type${T}item${T}source${T}project\n`);
71
+ const date = DAY(0);
72
+ write(path.join(dir, '02-daily', date.slice(0, 7), `${date}.md`), `# ${date}\n\n## 事件流\n\n| 时间 | 类型 | 事项 | 来源 | 项目 |\n|------|------|------|------|------|\n这行不是表格\n| 10:00 | 文档 | 带 \\| 竖线的事项 | file-activity | |\n| 没有时间的行 |\n\n## 备注\n`);
73
+ assert.equal(box.run(['events', '--today']).stdout, `date${T}time${T}type${T}item${T}source${T}project\n${date}${T}10:00${T}文档${T}带 | 竖线的事项${T}file-activity${T}\n`);
74
+ // 事项里混进制表符时换成空格,表不会串列
75
+ write(path.join(dir, '02-daily', date.slice(0, 7), `${date}.md`), `# ${date}\n\n## 事件流\n\n| 时间 | 类型 | 事项 | 来源 | 项目 |\n|---|---|---|---|---|\n| 11:00 | 其他 | a\tb | x | |\n`);
76
+ assert.equal(box.run(['events', '--today']).stdout.split('\n')[1].split(T).length, 6);
77
+ });
78
+
79
+ test('events:选项不对、日期不对、起始晚于结束时退出码为 2', (t) => {
80
+ const box = makeSandbox(t);
81
+ box.workdir();
82
+ assert.equal(box.run(['events', '--nope']).code, 2);
83
+ assert.equal(box.run(['events', '--days']).code, 2);
84
+ assert.equal(box.run(['events', '--days', '0']).code, 2);
85
+ assert.equal(box.run(['events', '--from', '不是日期']).code, 2);
86
+ assert.equal(box.run(['events', '--from', DAY(1), '--to', DAY(0)]).code, 2);
87
+ assert.match(box.run(['events', '--from', DAY(1), '--to', DAY(0)]).stderr, /起始日期 .* 晚于结束日期/);
88
+ assert.equal(rawRun(['events'], { cwd: box.root }).code, 3);
89
+ });
@@ -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,列出子命令', async (t) => {
247
+ test('listen:用法不对时退出码为 2,并告诉它用法在哪;--help 打完整用法、退出码 0', async (t) => {
248
248
  const s = setup(t);
249
- assert.equal(s.listen(['nope']).code, 2);
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.match(r.stderr, /work-rhythm listen: 用法: work-rhythm listen <子命令>/);
253
- assert.match(r.stderr, /handle-frame/);
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) => {
@@ -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
@@ -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 按「新增一个渠道」接。