work-rhythm 0.2.3 → 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 (36) hide show
  1. package/.agents/notes/AGENTS.md +5 -0
  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-question-cards-via-cli-tool-on-todays-page-answers-return-to-router.md +40 -0
  4. package/.agents/notes/decisions/2026-12-01-router-and-worker-pass-content-in-handoff-docs.md +1 -0
  5. package/.agents/notes/decisions/2026-12-01-router-runs-on-a-flash-model-with-low-effort.md +33 -0
  6. package/.agents/notes/decisions/2026-12-01-sync-feeds-refine-then-events-to-the-router.md +38 -0
  7. package/.agents/notes/pitfalls/2026-12-02-rhythm-start-in-the-foreground-displaces-the-launchd-service.md +27 -0
  8. package/.agents/skills/work-rhythm/SKILL.md +9 -3
  9. package/README.md +25 -0
  10. package/collectors/local.env.example +2 -2
  11. package/docs/agents.md +28 -5
  12. package/docs/router-worker.md +30 -8
  13. package/docs/scheduled-tasks.md +2 -2
  14. package/docs/sources.md +20 -0
  15. package/package.json +1 -1
  16. package/scripts/cli.js +1 -0
  17. package/scripts/cmd/agent.js +117 -16
  18. package/scripts/cmd/ask.js +104 -0
  19. package/scripts/cmd/sync.js +11 -3
  20. package/scripts/lib/agent.js +110 -5
  21. package/scripts/lib/asks.js +145 -0
  22. package/scripts/lib/engine.js +192 -8
  23. package/scripts/lib/handoff.js +2 -0
  24. package/scripts/lib/markdown.js +48 -19
  25. package/scripts/lib/rhythm.js +238 -38
  26. package/scripts/lib/router.js +60 -13
  27. package/scripts/lib/view.js +182 -29
  28. package/scripts/lib/worker.js +3 -2
  29. package/scripts/test/agent.test.js +109 -0
  30. package/scripts/test/harness.js +2 -0
  31. package/scripts/test/rhythm.test.js +84 -3
  32. package/scripts/test/router-helper.js +33 -3
  33. package/scripts/test/router.test.js +321 -31
  34. package/scripts/test/stubs.js +33 -2
  35. package/tasks/daily-plan.md +1 -2
  36. package/templates/00-config/profile.example.yaml +3 -1
@@ -0,0 +1,145 @@
1
+ // 问用户:执行者干到一半要我拿主意,不自己憋着,把问题以 JSON 丢出来(work-rhythm ask),页面上成一张卡,
2
+ // 我在页面上答了,回答变成一条触发回到路由(docs/router-worker.md 的「问用户:待办卡片」)。
3
+ // 一张卡是一个文件:01-inbox/_rhythm/asks/<id>.json,答了也留着(带着答案),监控和页面从这儿读;
4
+ // 同时在 03-carryover/DECISIONS.md 记一行「未答」——那是给人看的历史,答了再改成我的决定。
5
+ // 内容(问题、背景、我的附言)只在这个目录和 DECISIONS.md 里,不进 state.json、不进日志。
6
+ 'use strict';
7
+ const fs = require('node:fs');
8
+ const path = require('node:path');
9
+ const { EXIT, Fail, UsageError, fmtStamp, today } = require('./run');
10
+ // 给服务的信号放 01-inbox/_rhythm/queue/(和 trigger fire 同一个目录,engine.js 的 collectQueue 取走)
11
+ const queueDir = (root) => path.join(root, '01-inbox', '_rhythm', 'queue');
12
+
13
+ const ASKS_DIR = ['01-inbox', '_rhythm', 'asks'];
14
+ const CIRCLED = ['①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩'];
15
+ const MAX_QUESTION = 200;
16
+ const MAX_ITEM = 30;
17
+
18
+ const asksDir = (root) => path.join(root, ...ASKS_DIR);
19
+ const askPath = (root, id) => path.join(asksDir(root), `${id}.json`);
20
+ const ID_RE = /^a-\d{8}-\d{6}-[0-9a-f]{4}$/;
21
+
22
+ const readOrNull = (file) => {
23
+ try {
24
+ return fs.readFileSync(file, 'utf8');
25
+ } catch {
26
+ return '';
27
+ }
28
+ };
29
+
30
+ // 选项统一成 { label, detail, suggested }:传进来的可以是字符串,或 { label, detail, suggested },suggested 也可以写成序号
31
+ function normalizeOptions(options, suggested) {
32
+ const list = (Array.isArray(options) ? options : []).map((o) => (typeof o === 'string' ? { label: o } : o && typeof o === 'object' ? { ...o } : null)).filter((o) => o && String(o.label || '').trim());
33
+ const pick = suggested === undefined ? -1 : typeof suggested === 'number' ? suggested : list.findIndex((o) => o.label === suggested || String(o.label).trim() === String(suggested).trim());
34
+ return list.map((o, i) => ({ label: String(o.label).trim(), detail: String(o.detail || '').trim(), suggested: Boolean(o.suggested) || i === pick }));
35
+ }
36
+
37
+ // DECISIONS.md 的「选项」那一格:①… ②… ③…
38
+ const optionsText = (options) => options.map((o, i) => `${CIRCLED[i] || `${i + 1}.`}${o.label}`).join(' ');
39
+
40
+ // 全部的卡:没答的在前(新的在前),答过的在后(新的在前)
41
+ function listAsks(root) {
42
+ let names;
43
+ try {
44
+ names = fs.readdirSync(asksDir(root));
45
+ } catch {
46
+ return [];
47
+ }
48
+ const asks = [];
49
+ for (const name of names) {
50
+ if (!/^a-.*\.json$/.test(name)) continue;
51
+ try {
52
+ const ask = JSON.parse(fs.readFileSync(path.join(asksDir(root), name), 'utf8'));
53
+ if (ask && ask.id) asks.push(ask);
54
+ } catch {
55
+ // 写了一半的、坏掉的:跳过
56
+ }
57
+ }
58
+ return asks.sort((a, b) => (Boolean(a.answer) === Boolean(b.answer) ? b.at.localeCompare(a.at) : a.answer ? 1 : -1));
59
+ }
60
+
61
+ function readAsk(root, id) {
62
+ if (!ID_RE.test(String(id || ''))) return null;
63
+ try {
64
+ return JSON.parse(fs.readFileSync(askPath(root, id), 'utf8'));
65
+ } catch {
66
+ return null;
67
+ }
68
+ }
69
+
70
+ // 校验一份传进来的 JSON,返回规范化后的字段;不对就抛用法错
71
+ function validate(input) {
72
+ const o = input && typeof input === 'object' && !Array.isArray(input) ? input : {};
73
+ const question = String(o.question || o.item || '').trim();
74
+ if (!question) throw new UsageError('ask 要有 question(问题本身,一句话)');
75
+ if (question.length > MAX_QUESTION) throw new UsageError(`question 太长了(${question.length} 字,最多 ${MAX_QUESTION}):背景放 context`);
76
+ const options = normalizeOptions(o.options, o.suggested);
77
+ if (options.length > 10) throw new UsageError('选项最多 10 个');
78
+ const item = String(o.item || '').trim() || question;
79
+ if (item.length > MAX_ITEM) throw new UsageError(`item(记进 DECISIONS.md 的那一句话)不能超过 ${MAX_ITEM} 字:现在「${item}」;问题长的话另起一个短的 item`);
80
+ if (/[|]/.test(item)) throw new UsageError('item 不能含竖线');
81
+ return { question, context: String(o.context || '').trim(), options, record: String(o.record || '').trim(), item, from: o.from && typeof o.from === 'object' ? o.from : {} };
82
+ }
83
+
84
+ // 登记一张卡:写文件、记 DECISIONS.md(未答)、给服务留个信号(它把卡片推给我、带着页面地址)。
85
+ // 返回卡。decisions 是 cmd/decisions.js 的 run:这里直接调它,不另起进程
86
+ async function createAsk(root, input, { env = process.env, packageRoot, decisions } = {}) {
87
+ const v = validate(input);
88
+ const now = new Date();
89
+ const p = (n) => String(n).padStart(2, '0');
90
+ const stamp = `${now.getFullYear()}${p(now.getMonth() + 1)}${p(now.getDate())}-${p(now.getHours())}${p(now.getMinutes())}${p(now.getSeconds())}`;
91
+ const id = `a-${stamp}-${Math.random().toString(16).slice(2, 6)}`;
92
+ const from = { ...v.from };
93
+ // 执行者问的:服务给它留了 WRJ_TRIGGER(是哪条触发),顺手记上
94
+ if (!from.trigger && env.WRJ_TRIGGER) from.trigger = String(env.WRJ_TRIGGER);
95
+ const ask = { id, at: fmtStamp(now), question: v.question, context: v.context, options: v.options, record: v.record, item: v.item, from, answer: null };
96
+ fs.mkdirSync(asksDir(root), { recursive: true });
97
+ fs.writeFileSync(askPath(root, id), `${JSON.stringify(ask, null, 1)}\n`);
98
+ const err = [];
99
+ const code = decisions ? await decisions.run(['add', '--item', v.item, '--options', optionsText(v.options), '--choice', '未答'], { root, cwd: root, env, packageRoot, stdout: { write() {} }, stderr: { write: (x) => err.push(String(x)) } }) : 0;
100
+ if (decisions && code !== 0) throw new Fail(EXIT.FAILED, `卡片写下了(${id}),但 DECISIONS.md 没记上:${err.join('').trim()}`);
101
+ // 服务下一次看表(最多 20 秒)取走它,把卡片推给我(带着页面地址)
102
+ fs.mkdirSync(queueDir(root), { recursive: true });
103
+ fs.writeFileSync(path.join(queueDir(root), `ask-${id}.json`), `${JSON.stringify({ kind: 'ask', ask: id, text: `ask ${id}`, mode: 'plan', at: fmtStamp(now) })}\n`);
104
+ return ask;
105
+ }
106
+
107
+ // 答了:卡片里记下答案,DECISIONS.md 那一行改成我的决定
108
+ async function answerAsk(root, id, { choice, note = '', by = 'page' } = {}, { env = process.env, packageRoot, decisions } = {}) {
109
+ const ask = readAsk(root, id);
110
+ if (!ask) throw new Fail(EXIT.USAGE, `没有 ${id} 这张卡`);
111
+ const picked = String(choice || '').trim();
112
+ if (!picked) throw new UsageError('要写选了哪个选项(或者你的回答)');
113
+ if (!ask.answer) {
114
+ ask.answer = { choice: picked, note: String(note || '').trim(), at: fmtStamp(), by };
115
+ fs.writeFileSync(askPath(root, id), `${JSON.stringify(ask, null, 1)}\n`);
116
+ }
117
+ const err = [];
118
+ const code = decisions ? await decisions.run(['answer', ask.item, ask.answer.choice], { root, cwd: root, env, packageRoot, stdout: { write() {} }, stderr: { write: (x) => err.push(String(x)) } }) : 0;
119
+ if (decisions && code !== 0) throw new Fail(EXIT.FAILED, `卡片记下了答案,但 DECISIONS.md 没改成我的决定:${err.join('').trim()}`);
120
+ return ask;
121
+ }
122
+
123
+ // 给路由、给推送看的一行
124
+ function askSummary(ask) {
125
+ const opts = ask.options.map((o, i) => `${CIRCLED[i] || `${i + 1}.`}${o.label}`).join(' ');
126
+ return `「${ask.question}」${opts ? ` 选项:${opts}` : ''}`;
127
+ }
128
+
129
+ // 页面和监控的卡片:没答的卡,加上 DECISIONS.md 里「未答」但没有对应卡片的行(老办法登记的)
130
+ function cardsForPage(root, pendingCards) {
131
+ const asks = listAsks(root).filter((a) => !a.answer);
132
+ const items = new Set(asks.map((a) => a.item));
133
+ const legacy = pendingCards(root).filter((c) => !items.has(c.item)).map((c) => ({ id: '', question: c.item, context: '', options: normalizeOptions(c.options ? splitOptions(c.options) : []), record: '', item: c.item, from: {}, answer: null, at: '', date: c.date, legacy: true }));
134
+ return [...asks, ...legacy];
135
+ }
136
+
137
+ // 老办法的选项是一串「①发上游 ②周会提」或「周二;周四」
138
+ function splitOptions(text) {
139
+ const parts = String(text || '').split(/(?=[①②③④⑤⑥⑦⑧⑨⑩])/).map((x) => x.trim()).filter(Boolean);
140
+ if (parts.length > 1) return parts;
141
+ const semi = String(text || '').split(/[;;]\s*/).map((x) => x.trim()).filter(Boolean);
142
+ return semi.length > 1 ? semi : [String(text || '').trim()].filter(Boolean);
143
+ }
144
+
145
+ module.exports = { ASKS_DIR, ID_RE, asksDir, askPath, normalizeOptions, optionsText, listAsks, readAsk, createAsk, answerAsk, askSummary, cardsForPage, splitOptions, validate };
@@ -13,6 +13,8 @@ const { roles } = require('./agent');
13
13
  const handoff = require('./handoff');
14
14
  const { createRouter } = require('./router');
15
15
  const { createPool, runWorker } = require('./worker');
16
+ const { parseEvents } = require('../cmd/events');
17
+ const asks = require('./asks');
16
18
 
17
19
  const ACK_TEXT = '收到,正在处理,稍等。'; // 和值守(bot.js)那句一样
18
20
  // 上一句还没答完又来一句(插话):先回这句,告诉他会和上一句一起考虑
@@ -31,6 +33,8 @@ const pad6 = (n) => String(n).padStart(6, '0');
31
33
  const s = (v) => String(v || '').trim();
32
34
  const stampMs = (stamp) => new Date(String(stamp).replace(' ', 'T')).getTime();
33
35
  const queueDir = (root) => path.join(root, '01-inbox', '_rhythm', 'queue');
36
+ const triggersStore = new Map();
37
+ const triggersOf = (root) => (triggersStore.has(root) ? triggersStore.get(root)() : {});
34
38
 
35
39
  // 每跑完一条记一行(只有元数据)。直通模式下的 rhythm run 也记,manual 标出来
36
40
  function appendHistory(data, row) {
@@ -79,8 +83,116 @@ function resultBody(text) {
79
83
  return lines.slice(i).join('\n').trim();
80
84
  }
81
85
 
86
+ // ---------------------------------------------------------------- 采集之后:提炼、新事件、待办卡片
87
+ const dailyFile = (root, date) => path.join(root, '02-daily', date.slice(0, 7), `${date}.md`);
88
+ const eventKey = (e) => `${e.date}|${e.time}|${e.type}|${e.item}|${e.source}`;
89
+ const readOrNull = (file) => {
90
+ try {
91
+ return fs.readFileSync(file, 'utf8');
92
+ } catch {
93
+ return '';
94
+ }
95
+ };
96
+ // 今天每日文件里的事件流(docs/formats.md),文件还没有就是空
97
+ function dayEvents(root, date) {
98
+ return parseEvents(readOrNull(dailyFile(root, date)), date);
99
+ }
100
+
101
+ // 待办卡片:DECISIONS.md 里「决定」还是「未答」的行(work-rhythm decisions add --choice 未答 登记的)。
102
+ // 返回 [{ date, item, options, by }],新的在前
103
+ function pendingCards(root) {
104
+ const lines = readOrNull(path.join(root, '03-carryover', 'DECISIONS.md')).split('\n');
105
+ const start = lines.findIndex((l) => /^##\s*决定\s*$/.test(l));
106
+ if (start < 0) return [];
107
+ const NAMES = { 日期: 'date', 事项: 'item', 选项: 'options', 决定: 'choice', 理由: 'reason', 谁来做: 'by', 落实: 'done' };
108
+ const out = [];
109
+ let columns = null;
110
+ for (let i = start + 1; i < lines.length && !/^##\s/.test(lines[i]); i += 1) {
111
+ const line = lines[i].trim();
112
+ if (!line.startsWith('|')) continue;
113
+ const cells = line.replace(/\\\|/g, '\u0000').split('|').slice(1, -1).map((c) => c.trim().replace(/\u0000/g, '|'));
114
+ if (!cells.length || cells.every((c) => /^:?-+:?$/.test(c))) continue;
115
+ if (!columns) {
116
+ columns = cells.map((name) => NAMES[name] || '');
117
+ continue;
118
+ }
119
+ const row = {};
120
+ columns.forEach((field, n) => {
121
+ if (field) row[field] = cells[n] || '';
122
+ });
123
+ if (row.item && row.choice === '未答') out.push({ date: row.date, item: row.item, options: row.options || '', by: row.by || '' });
124
+ }
125
+ return out.reverse();
126
+ }
127
+
128
+ // 提炼的任务书:定时采集之后,把 01-inbox 里今天的新数据按 sources.yaml 的规则炼成事件、并进事件流
129
+ function refineBody(file) {
130
+ return [
131
+ '# 任务:把今天新采到的数据提炼成事件',
132
+ '',
133
+ '1. 读 00-config/sources.yaml:每个启用的源有「提炼成什么事件」的规则(extract)。',
134
+ '2. 读 01-inbox/<源id>/<今天>/ 下各源的输出(刚同步过;哪个源没有目录就跳过)。',
135
+ '3. 按各源的规则提炼事件,对照 docs/formats.md 的「事件流」:类型用词表里的词,一行一事、不记内容细节;项目能归就归。',
136
+ `4. 合并进今天每日文件(${file})的「## 事件流」:替换同来源同时段的旧事件,保留来源是「口述」的行,按时间排序;文件不存在就按格式创建。只改这一节。`,
137
+ '5. 回执里写:各源分别提炼出几条、合并后事件流一共几条;哪个源的数据读不到就写「未取到」,不要编。',
138
+ '',
139
+ '',
140
+ ].join('\n');
141
+ }
142
+
143
+ // 回答之后的任务书:我在页面上答了一张卡。带着原问题、选项、我的回答、要记到哪;问这件事的执行者的任务书和回执也指给它
144
+ function answerBody(c) {
145
+ const ask = c.ask || {};
146
+ const opts = (ask.options || []).map((o, i) => `${['①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩'][i] || `${i + 1}.`}${o.label}${o.suggested ? '(当时建议的)' : ''}`).join(' ');
147
+ const from = ask.from && ask.from.trigger ? triggersOf(c.root)[ask.from.trigger] : null;
148
+ const lines = [
149
+ '# 任务:我回答了,接着做',
150
+ '',
151
+ `当时问我的:「${ask.question}」${opts ? ` 选项:${opts}` : ''}${ask.context ? `\n背景:${ask.context}` : ''}`,
152
+ '',
153
+ `我的回答:${ask.answer ? ask.answer.choice : ''}${ask.answer && ask.answer.note ? ` 附言:${ask.answer.note}` : ''}`,
154
+ '',
155
+ from ? `这是执行者 ${ask.from.trigger} 问的:它的任务书在 ${handoff.relTask(ask.from.trigger)},回执在 ${handoff.relResult(ask.from.trigger)},先读它们,接着它做到的地方往下做。` : '这是我(或桌面上某个 agent)问的:按原问题把该做的做完。',
156
+ ask.record ? `把这次的结果记到:${ask.record}(按那里的格式;记完在回执里写明记到了哪里)。` : '把这次的结果按 docs/formats.md 记进该记的地方;记完在回执里写明记到了哪里。',
157
+ '',
158
+ '能当场做的当场做;要动外部系统(发消息、改日程、流转工作项)的,先把要发、要改的内容写进回执给我看,不要自己发。取不到的数据写「未取到」,不要编。',
159
+ '',
160
+ '',
161
+ ];
162
+ return lines.join('\n');
163
+ }
164
+
165
+ // 重点与待办的任务书:路由把一批新事件派出去时用(路由可以再补一段)。c.root 是工作目录
166
+ function focusBody(c) {
167
+ const list = (c.events || []).map((e) => `- ${e.time} ${e.type} ${e.item}${e.project ? `(${e.source},${e.project})` : e.source ? `(${e.source})` : ''}`).join('\n');
168
+ const bad = (c.sources || []).filter((x) => !x.ok).map((x) => `${x.id}:${x.detail || `退出码 ${x.code}`}`).join(';');
169
+ const file = dailyFile(c.root || '.', c.date || today());
170
+ return [
171
+ '# 任务:根据新到的事件更新今日重点和待办',
172
+ '',
173
+ `今天新到的事件(${(c.events || []).length} 条):`,
174
+ list || '(没有新事件)',
175
+ ...(bad ? ['', `这次采集有源没取到数据(回执里说清,涉及的事标「未取到」):${bad}`] : []),
176
+ '',
177
+ `1. 读今天每日文件(${file})的「## 计划」「## 事件流」「## 备注」,03-carryover/CARRYOVER.md 的未了结,05-goals/ 里进行中的目标。`,
178
+ '2. 据此更新「## 计划」里的今日重点(不超过 3 条,每条带建议时间块和理由)。只改这一处;例行的事(通勤、打卡)不算重点。「待你定」不要再写进计划文件:需要我拿主意的事走下面的卡片。',
179
+ '3. 需要我拿主意的事,逐件用 work-rhythm ask 丢出来(它会成一张卡,实时显示在今日页的「待你定」里)。先 work-rhythm ask list 看有没有同一件事还没答的,有就不重复问;没有就:',
180
+ ' work-rhythm ask --json \'{"question":"<一句话的问题>","context":"<两三句背景:为什么现在要定、卡在哪>","options":[{"label":"<选项>","detail":"<一句话说明>","suggested":true},{"label":"<选项>"}],"record":"<我答了之后总结记到哪,如 03-carryover/CARRYOVER.md 的未了结>","item":"<不超过 30 字的短事项>"}\'',
181
+ ' 2–4 个选项,其中一个标 suggested 并在 detail 里说理由;真没有可选的就不写 options(我会自己写回答)。没有要问的就不问。',
182
+ '4. 回执按这个格式写(路由会转给用户,纯文本、不放链接):',
183
+ ' 今日重点:',
184
+ ' - …',
185
+ ' 待办卡片(我会在今日页的「待你定」里点选项,不用你催):',
186
+ ' 1. <事项>:<选项,标出建议的>',
187
+ ' 2. …',
188
+ ' 没有卡片就不写这一段。',
189
+ '',
190
+ '',
191
+ ].join('\n');
192
+ }
193
+
82
194
  // cfg 来自 rhythm.js 的 loadConfig(router、routerTimeout、workers、handoffKeep、historyKeep、taskTimeout、agentMode、agentModel、
83
- // agentEffort、push、quiet、links、baseUrl、serviceAlive、ack、botMode、botTimeout、replyMax、botPreamble)。state 是 { data, save }
195
+ // agentEffort、push、quiet、links、baseUrl、serviceAlive、ack、botMode、botTimeout、replyMax、botPreamble、refine、refineInterval)。state 是 { data, save }
84
196
  function createEngine({ root, env, cfg, log = () => {}, push = async () => false, state, since = Date.now() }) {
85
197
  const routerSpec = roles(env).router;
86
198
  // 执行者的模型和强度:YZJ_WORKER_* > profile 的 rhythm.agent-* > YZJ_BOT_*
@@ -92,6 +204,7 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
92
204
  const agentLabel = `${workerSpec.agent}${workerSpec.model ? `(${workerSpec.model})` : ''}`;
93
205
  const triggers = () => state.data.triggers;
94
206
  const save = () => state.save();
207
+ triggersStore.set(root, triggers);
95
208
  // 内存里的正文:短号 → { text, taskBody, taskFile, taskTitle, opening, linkTask, orig }
96
209
  const live = new Map();
97
210
  const queue = []; // 等路由的短号
@@ -106,7 +219,12 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
106
219
 
107
220
  // 权限和超时由触发来源定。重做的沿用原来那条的
108
221
  function terms(t) {
109
- if (t.kind === 'schedule') return { mode: cfg.agentMode, timeoutS: cfg.taskTimeout };
222
+ if (t.kind === 'schedule' || t.kind === 'events') return { mode: cfg.agentMode, timeoutS: cfg.taskTimeout };
223
+ if (t.kind === 'answer') {
224
+ const o = live.get(t.id) && live.get(t.id).ask && live.get(t.id).ask.from && triggers()[live.get(t.id).ask.from.trigger];
225
+ if (o && o.worker && o.worker.mode) return { mode: o.worker.mode, timeoutS: o.worker.timeoutS || cfg.taskTimeout };
226
+ return { mode: cfg.agentMode, timeoutS: cfg.taskTimeout };
227
+ }
110
228
  if (t.kind === 'message') return { mode: cfg.botMode, timeoutS: cfg.botTimeout };
111
229
  if (t.kind === 'report') {
112
230
  const o = live.get(t.id) && live.get(t.id).orig;
@@ -137,10 +255,12 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
137
255
  }
138
256
 
139
257
  // 新的触发进队列。key 一样的只处理一次。返回记录,或者 null(重复的)
140
- function enqueue(kind, { key = '', text = '', task = '', taskFile = '', taskBody = '', taskTitle = '', mode = '', of = '', ok = false, seconds = 0, reason = '', opening = '', quiet = false, linkTask = '', orig = null } = {}) {
258
+ function enqueue(kind, { key = '', text = '', task = '', taskFile = '', taskBody = '', taskTitle = '', mode = '', of = '', ok = false, seconds = 0, reason = '', opening = '', quiet = false, linkTask = '', orig = null, events = null, sources = null, ask = null, date = '', root: eventRoot } = {}) {
141
259
  if (key && Object.values(triggers()).some((x) => x.key === key)) return null;
142
260
  const t = record(kind, { key, task, of, quiet });
143
- live.set(t.id, { text, taskFile, taskBody, taskTitle, mode, opening, linkTask, orig, ok, seconds, reason });
261
+ live.set(t.id, { text, taskFile, taskBody, taskTitle, mode, opening, linkTask, orig, ok, seconds, reason, events, sources, ask, date, root: eventRoot || root });
262
+ if (kind === 'events') t.title = `新事件 ${(events || []).length} 条 → 今日重点与待办`;
263
+ if (kind === 'answer' && ask) t.title = `回答:${ask.item || ask.question || ''}`;
144
264
  queue.push(t.id);
145
265
  save();
146
266
  log('触发入队', `${t.id} ${kind}`);
@@ -203,6 +323,11 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
203
323
  save();
204
324
  log('执行者结束', `${t.id} ${ok ? '成功' : r.stopped ? '叫停' : '失败'} ${r.seconds}s`);
205
325
  const c = live.get(t.id) || {};
326
+ // 提炼是 CLI 自己起的一步:做完了不算汇报,算出新增的事件打包成一条 events 触发给路由
327
+ if (t.kind === 'refine') {
328
+ afterRefine(t, r, c);
329
+ return r;
330
+ }
206
331
  // 被插话停掉的:不汇报,接着它重跑的那次会汇报
207
332
  if (t.suppressReport) {
208
333
  delete t.suppressReport;
@@ -217,7 +342,7 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
217
342
  }
218
343
  enqueue('report', {
219
344
  key: `report-${t.id}`, of: t.id, ok, seconds: r.seconds, reason: r.stopped ? '用户叫停' : r.failed, quiet: t.quiet,
220
- opening: ok ? handoff.opening(resultBody(handoff.readText(handoff.resultPath(root, t.id)))) : '', linkTask: t.kind === 'schedule' ? t.task : '', orig: t, task: c.linkTask,
345
+ opening: ok ? handoff.opening(resultBody(handoff.readText(handoff.resultPath(root, t.id)))) : '', linkTask: t.kind === 'schedule' ? t.task : t.kind === 'events' || t.kind === 'answer' ? 'todos' : '', orig: t, task: c.linkTask,
221
346
  });
222
347
  return r;
223
348
  }
@@ -243,7 +368,7 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
243
368
  let r;
244
369
  try {
245
370
  r = await runWorker({
246
- root, env, log, id: t.id, mode, timeoutS, idleS: cfg.workerIdle, spec: workerSpec, resume: sid,
371
+ root, env, log, id: t.id, mode, timeoutS, idleS: cfg.workerIdle, spec: workerSpec, resume: sid, extraEnv: { WRJ_TRIGGER: t.id, WRJ_ROLE: 'worker' },
247
372
  onSession: (sid) => {
248
373
  if (t.worker.sessionId !== sid) {
249
374
  t.worker.sessionId = sid;
@@ -277,6 +402,8 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
277
402
  let body = s(handoffBody);
278
403
  const { mode, timeoutS } = terms(t);
279
404
  if (t.kind === 'schedule') body = `${s(c.taskBody)}${body ? `\n\n## 路由的补充\n\n${body}` : ''}\n\n${NOTE_BY_SERVICE}`;
405
+ else if (t.kind === 'events') body = `${focusBody({ ...c, root })}${body ? `\n## 路由的补充\n\n${body}` : ''}\n\n${NOTE_BY_SERVICE}`;
406
+ else if (t.kind === 'answer') body = `${answerBody(c)}${body ? `\n## 路由的补充\n\n${body}` : ''}\n\n${NOTE_BY_SERVICE}`;
280
407
  else if (t.kind === 'report') body = `# 任务:重做 ${t.of}\n\n上一次的结果:${c.ok ? handoff.opening(handoff.readText(handoff.resultPath(root, t.of))) : c.reason}\n旧任务书在 ${handoff.relTask(t.of)},旧回执在 ${handoff.relResult(t.of)},先读它们。\n\n${body || '按原任务书重做一遍。'}`;
281
408
  else if (!body) body = `# 任务:照用户的话做\n\n用户原话:「${c.text}」\n\n照它做。这是一句追问、单凭这句话做不了的话,在回执里说清楚缺什么。`;
282
409
  t.title = handoff.titleOf(body) || t.task || '';
@@ -295,7 +422,9 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
295
422
  if (!target || !openItems().some((o) => o.id === targetId)) {
296
423
  return fallback(t, c, `continue 指向的 ${targetId || '(没写)'} 不在手头的事里`);
297
424
  }
298
- const body = `接着 ${targetId} 那件事做。旧任务书在 ${handoff.relTask(targetId)},旧回执在 ${handoff.relResult(targetId)},先读它们。\n\n用户追加:「${c.text}」\n\n按追加的要求继续。这次的结果单独写进回执,不要改旧回执。`;
425
+ const body = t.kind === 'answer'
426
+ ? `接着 ${targetId} 那件事做——它问了我一句话,我答了。旧任务书在 ${handoff.relTask(targetId)},旧回执在 ${handoff.relResult(targetId)},先读它们。\n\n${answerBody(c)}\n\n这次的结果单独写进回执,不要改旧回执。`
427
+ : `接着 ${targetId} 那件事做。旧任务书在 ${handoff.relTask(targetId)},旧回执在 ${handoff.relResult(targetId)},先读它们。\n\n用户追加:「${c.text}」\n\n按追加的要求继续。这次的结果单独写进回执,不要改旧回执。`;
299
428
  const mode = (target.worker && target.worker.mode) || cfg.botMode;
300
429
  const timeoutS = (target.worker && target.worker.timeoutS) || cfg.taskTimeout;
301
430
  t.title = `${target.title || targetId}(续)`;
@@ -422,6 +551,48 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
422
551
  pump();
423
552
  }
424
553
 
554
+ // 定时采集之后(rhythm.js 调):有新数据、或者有源没取到,就起一轮提炼;做完把新增的事件打包给路由
555
+ async function afterSync({ results = [], changed = false } = {}) {
556
+ if (!router || !cfg.refine) return null;
557
+ const bad = results.filter((x) => !x.ok);
558
+ // 没有新数据:不炼。有源出事就把采集状态直接给路由(不用等提炼),路由决定要不要告诉用户
559
+ if (!changed) {
560
+ log('提炼跳过', '没有新数据');
561
+ if (bad.length) enqueue('events', { key: `events-sync-${Date.now()}`, ok: true, events: [], sources: results, date: today(), root });
562
+ return null;
563
+ }
564
+ // 新数据等够间隔再炼(rhythm.refine-interval 分钟);这期间有源出事也直接告诉路由
565
+ const last = state.data.refinedAt;
566
+ if (last && Date.now() - stampMs(last) < cfg.refineInterval * 60000) {
567
+ log('提炼跳过', `上一次 ${last},不到 ${cfg.refineInterval} 分钟`);
568
+ if (bad.length) enqueue('events', { key: `events-sync-${Date.now()}`, ok: true, events: [], sources: results, date: today(), root });
569
+ return null;
570
+ }
571
+ const date = today();
572
+ const t = record('refine', { key: `refine-${date}-${Date.now()}`, decision: 'refine', title: '把今天新采到的数据提炼成事件' });
573
+ live.set(t.id, { results, date, before: new Set(dayEvents(root, date).map(eventKey)), root });
574
+ handoff.writeTask(root, { ...t, text: '' }, refineBody(dailyFile(root, date)), { mode: cfg.agentMode, timeoutS: cfg.taskTimeout });
575
+ save();
576
+ log('提炼开始', t.id);
577
+ return launch(t, { mode: cfg.agentMode, timeoutS: cfg.taskTimeout });
578
+ }
579
+
580
+ // 提炼做完:比对话件里的事件流,新增的打包成 events 触发给路由。没新增、也没源出事就不打扰路由
581
+ function afterRefine(t, r, c) {
582
+ state.data.refinedAt = fmtStamp();
583
+ save();
584
+ const date = c.date || today();
585
+ let events = [];
586
+ if (r.ok) {
587
+ const before = c.before || new Set();
588
+ events = dayEvents(root, date).filter((e) => !before.has(eventKey(e)));
589
+ log('提炼结束', `${t.id} 新增 ${events.length} 条事件`);
590
+ }
591
+ const bad = (c.results || []).filter((x) => !x.ok);
592
+ if (!r.ok) enqueue('events', { key: `events-${t.id}`, of: t.id, ok: false, reason: r.failed, events: [], sources: c.results || [], date, root });
593
+ else if (events.length || bad.length) enqueue('events', { key: `events-${t.id}`, of: t.id, ok: true, events, sources: c.results || [], date, root });
594
+ }
595
+
425
596
  // 服务启动时:上次没跑完的执行者各补一份失败的回执,变成汇报交回路由;停服务时没来得及汇报的也补上
426
597
  function recover() {
427
598
  for (const t of Object.values(triggers())) {
@@ -467,6 +638,15 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
467
638
  }
468
639
  const item = JSON.parse(fs.readFileSync(file, 'utf8'));
469
640
  fs.unlinkSync(file);
641
+ // 执行者用 work-rhythm ask 丢出来的卡:直接把问题推给我、带着今日页的地址(实时显示在那儿),不花路由一轮
642
+ if (item.kind === 'ask') {
643
+ const ask = asks.readAsk(root, item.ask);
644
+ if (ask && !ask.answer) {
645
+ log('待你定', `${ask.id} ${ask.item}`);
646
+ send(null, `等你定:${asks.askSummary(ask)}${ask.context ? `\n${ask.context}` : ''}`, { linkTask: 'todos' });
647
+ }
648
+ continue;
649
+ }
470
650
  enqueue('manual', { key: `fired-${name.slice(0, -5)}`, text: s(item.text), mode: s(item.mode) || 'plan' });
471
651
  } catch (error) {
472
652
  log('排队文件读不了', `${name} ${error.message}`);
@@ -493,6 +673,10 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
493
673
  recover,
494
674
  shutdown,
495
675
  tick,
676
+ afterSync,
677
+ // 页面上答了一张卡:一条 answer 触发给路由(rhythm.js 调;ask 里带着答案)。
678
+ // 去重键用卡片 id;老办法登记的「未答」行没有卡片文件(id 是空的),用事项——不然第二张就会被当成重复丢掉
679
+ answer: (ask) => (router ? enqueue('answer', { key: `answer-${ask.id || ask.item}`, of: ask.from && ask.from.trigger ? ask.from.trigger : '', ask, root }) : null),
496
680
  // 命令行走一遍:要发的文字交到这里,不真发
497
681
  setSink(fn) {
498
682
  sink = fn;
@@ -520,4 +704,4 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
520
704
  };
521
705
  }
522
706
 
523
- module.exports = { createEngine, appendHistory, pruneState, historyStats, fire, queueDir, resultBody, ACK_TEXT, uid };
707
+ module.exports = { createEngine, appendHistory, pruneState, historyStats, fire, queueDir, resultBody, pendingCards, dayEvents, eventKey, refineBody, focusBody, ACK_TEXT, uid };
@@ -63,6 +63,8 @@ function taskText(t, body, extra = {}) {
63
63
  manual: `manual(命令行 trigger fire,${when})· 原话:「${t.text || ''}」`,
64
64
  schedule: `schedule(到点 ${when})· 任务:${t.task || ''}(${t.taskFile || ''})`,
65
65
  report: `report(${when})· 重做 ${t.of || ''} 那件事`,
66
+ events: `events(${when})· 定时采集之后新到的一批事件`,
67
+ refine: `refine(${when})· 定时采集之后提炼新数据`,
66
68
  }[t.kind] || t.kind;
67
69
  const lines = [
68
70
  `# 任务书 ${t.id}`,
@@ -207,7 +207,7 @@ const BASE_CSS = `
207
207
  --shadow:0 1px 2px rgba(20,18,14,.04),0 4px 16px rgba(20,18,14,.03);
208
208
  --radius:14px;
209
209
  --radius-sm:9px;
210
- --max-w:980px;
210
+ --max-w:1160px; /* 整个站就这一个宽度:换页签时版心不跳 */
211
211
  --font:-apple-system,BlinkMacSystemFont,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","Helvetica Neue",Arial,sans-serif;
212
212
  --mono:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,monospace;
213
213
  }
@@ -252,7 +252,6 @@ const BASE_CSS = `
252
252
  *,*::before,*::after{box-sizing:border-box}
253
253
  html{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}
254
254
  body{margin:0;padding:0 0 56px;background:var(--bg);color:var(--ink);font:15px/1.68 var(--font);font-feature-settings:"tnum"}
255
- body.is-wide{--max-w:1160px}
256
255
  a{color:var(--accent-ink);text-decoration:none;text-underline-offset:3px}
257
256
  a:hover{text-decoration:underline}
258
257
 
@@ -270,13 +269,11 @@ a:hover{text-decoration:underline}
270
269
 
271
270
  /* 主容器 */
272
271
  .wrap{max-width:var(--max-w);margin:24px auto 0;padding:0 24px}
273
- main.sheet{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:32px 36px;box-shadow:var(--shadow)}
274
272
  main.stack{display:flex;flex-direction:column;gap:16px}
275
273
 
276
274
  /* 通用排版 */
277
275
  h1{font-size:25px;line-height:1.3;font-weight:700;letter-spacing:-.02em;margin:0 0 16px;color:var(--ink)}
278
276
  h2{font-size:16.5px;line-height:1.4;font-weight:650;letter-spacing:-.01em;margin:28px 0 12px;padding-bottom:8px;border-bottom:1px solid var(--border-soft);color:var(--ink)}
279
- main.sheet>h2:first-child{margin-top:0}
280
277
  h3{font-size:14.5px;font-weight:650;margin:20px 0 8px;color:var(--ink)}
281
278
  p{margin:0 0 11px;color:var(--ink-2)}
282
279
  p:last-child{margin-bottom:0}
@@ -303,6 +300,8 @@ tbody tr:hover{background:var(--surface-2)}
303
300
 
304
301
  /* 卡片与通用组件 */
305
302
  .card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:22px 24px;box-shadow:var(--shadow)}
303
+ .card>*:first-child{margin-top:0}
304
+ .card>*:last-child{margin-bottom:0}
306
305
  .card-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:0 0 14px;padding-bottom:11px;border-bottom:1px solid var(--border-soft)}
307
306
  .card-head h2{margin:0;padding:0;border:0;font-size:16px;display:inline-flex;align-items:center;gap:8px}
308
307
  .card.is-empty{padding:14px 22px;background:var(--surface-2);border-style:dashed;box-shadow:none;display:flex;align-items:center;justify-content:space-between;gap:12px}
@@ -320,7 +319,6 @@ tbody tr:hover{background:var(--surface-2)}
320
319
  .dot.is-rose{background:#dc2626}
321
320
 
322
321
  /* 每日页头部与日期切换 */
323
- .day-hero{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:18px 22px 14px;box-shadow:var(--shadow)}
324
322
  .day-hero-top{display:flex;align-items:center;justify-content:space-between;gap:16px;flex-wrap:wrap}
325
323
  .day-eyebrow{font-size:12.5px;color:var(--muted);display:flex;align-items:center;gap:8px;margin-bottom:3px}
326
324
  .day-title{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap}
@@ -439,18 +437,50 @@ tbody tr:hover{background:var(--surface-2)}
439
437
  .report-list{display:flex;flex-direction:column;gap:8px}
440
438
  .report-item{display:flex;align-items:center;justify-content:space-between;padding:12px 16px;border-radius:10px;background:var(--surface-2);border:1px solid var(--border-soft);color:var(--ink);font-weight:540;transition:all .15s}
441
439
  .report-item:hover{background:var(--surface-3);border-color:var(--border);text-decoration:none}
442
- .mon-bar{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;font-size:13px;color:var(--muted);padding:0 2px}
443
- .mon-bar label{display:inline-flex;align-items:center;gap:6px;cursor:pointer}
440
+ .mon-check{display:inline-flex;align-items:center;gap:6px;cursor:pointer;font-size:13px;color:var(--muted);white-space:nowrap}
444
441
  .mon-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px}
445
- .mon-card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:18px 20px;box-shadow:var(--shadow)}
446
- .mon-card h2{margin:0 0 10px;padding:0 0 8px;font-size:14.5px;border-bottom:1px solid var(--border-soft);display:flex;align-items:center;justify-content:space-between}
447
- .mon-card p{font-size:13.5px;line-height:1.7}
442
+ .mon-grid p{font-size:13.5px;line-height:1.7}
448
443
  .mon-kv{display:flex;flex-wrap:wrap;gap:6px;margin-top:4px}
449
444
  .mon-log pre{max-height:360px;font-size:12px}
445
+ .mon-todos{display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:10px}
446
+ .mon-todo{display:flex;gap:10px;align-items:flex-start;padding:12px 14px;border-radius:10px;background:var(--surface-2);border:1px solid var(--border-soft);font-size:13.5px;line-height:1.6}
447
+ .mon-todo .pill{flex-shrink:0;margin-top:2px}
448
+ .mon-todo-body{min-width:0;flex:1}
449
+ .todo-opts{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px}
450
+ .todo-opt{padding:7px 13px;border-radius:9px;font:inherit;font-size:13.5px;color:var(--ink);background:var(--surface);border:1px solid var(--border);cursor:pointer}
451
+ .todo-opt:hover:not(:disabled){border-color:var(--accent);color:var(--accent-ink);background:var(--accent-bg)}
452
+ .todo-opt.is-picked{border-color:var(--accent);background:var(--accent-bg);color:var(--accent-ink);font-weight:600}
453
+ .todo-opt:disabled{opacity:.55;cursor:default}
454
+ .mon-todo.is-done .todo-opt{opacity:.4}
455
+ .mon-todo.is-done .todo-opt.is-picked{opacity:1}
456
+ .todo-input{flex:1 1 200px;padding:7px 11px;border-radius:9px;font:inherit;font-size:13.5px;color:var(--ink);border:1px solid var(--border);background:var(--surface)}
457
+ .todo-after{margin-top:8px;font-size:13px;color:var(--green-ink,#137333)}
458
+ .ask-list{display:flex;flex-direction:column;gap:12px}
459
+ .ask-card{padding:14px 16px;border-radius:11px;background:var(--surface-2);border:1px solid var(--border);transition:border-color .15s}
460
+ .ask-card.is-done{opacity:.72;border-color:var(--green-bd)}
461
+ .ask-head{display:flex;align-items:flex-start;justify-content:space-between;gap:10px}
462
+ .ask-q{font-size:15px;font-weight:600;color:var(--ink);line-height:1.5}
463
+ .ask-ctx{margin-top:6px;font-size:13.5px;color:var(--ink-2);line-height:1.6}
464
+ .ask-meta{margin-top:6px;font-size:12px;color:var(--muted)}
465
+ .ask-opts{display:flex;flex-wrap:wrap;gap:8px;margin-top:10px}
466
+ .ask-opt{display:inline-flex;align-items:center;gap:6px;padding:7px 13px;border-radius:9px;font:inherit;font-size:13.5px;color:var(--ink);background:var(--surface);border:1px solid var(--border);cursor:pointer;text-align:left}
467
+ .ask-opt:hover:not(:disabled){border-color:var(--accent);color:var(--accent-ink);background:var(--accent-bg)}
468
+ .ask-opt.is-suggested{border-color:var(--amber-bd);background:var(--amber-bg)}
469
+ .ask-opt.is-picked{border-color:var(--accent);background:var(--accent-bg);color:var(--accent-ink);font-weight:600}
470
+ .ask-opt:disabled{opacity:.55;cursor:default}
471
+ .ask-opt-detail{font-size:12px;color:var(--muted);font-weight:400}
472
+ .ask-form{display:flex;gap:8px;margin-top:10px;flex-wrap:wrap}
473
+ .ask-after{margin-top:8px;font-size:13px;color:var(--green-ink)}
474
+ .ask-after.is-err{color:var(--rose-ink)}
475
+ .page-head,.day-hero{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:18px 22px;box-shadow:var(--shadow)}
476
+ .day-hero{padding-bottom:14px}
477
+ .page-head{display:flex;align-items:baseline;justify-content:space-between;gap:8px 16px;flex-wrap:wrap}
478
+ .page-head h1{margin:0;font-size:22px;letter-spacing:-.02em}
479
+ .page-head-meta{display:flex;align-items:baseline;gap:12px;flex-wrap:wrap;margin-left:auto}
480
+ .page-head .muted{font-size:13.5px}
450
481
 
451
482
  @media (max-width:780px){
452
483
  .topbar-inner,.wrap{padding-left:14px;padding-right:14px}
453
- main.sheet{padding:22px 18px}
454
484
  .card,.day-hero{padding:18px 16px}
455
485
  .kpi-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
456
486
  .tl-row{grid-template-columns:48px 58px 1fr;gap:8px}
@@ -459,18 +489,17 @@ tbody tr:hover{background:var(--surface-2)}
459
489
  }
460
490
  @media print{
461
491
  body{background:#fff;padding:0}
462
- .topbar,.day-arrows,.day-strip,.kpi-grid,.filter-bar,.pending-hint-link{display:none}
492
+ .topbar,.day-arrows,.day-strip,.kpi-grid,.filter-bar,.pending-hint-link,.ask-form,.ask-opts{display:none}
463
493
  .day-panel{display:block !important}
464
494
  .wrap{margin:0;padding:0;max-width:none}
465
- .card,main.sheet,.day-hero{box-shadow:none;border-color:#ddd}
495
+ .card,.day-hero,.page-head{box-shadow:none;border-color:#ddd}
466
496
  }
467
497
  `;
468
498
 
469
499
  // 整页:样式内联,不引外部资源(docs/formats.md 的「视图」)
470
- function page(title, body, nav = '', opts = {}) {
471
- const wide = opts.wide ? ' is-wide' : '';
472
- const surface = opts.surface === 'plain' ? 'stack' : 'sheet';
473
- const bodyClass = [wide.trim(), opts.bodyClass || ''].filter(Boolean).join(' ');
500
+ // 一张完整的页面:顶栏(nav 是站内导航的 HTML)+ main.stack 里放 body。
501
+ // 宽度只有 --max-w 一个,壳只有 stack 一种(页头卡片 + 正文卡片,见 view.js 的 renderDocPage)——换页签时版心不跳
502
+ function page(title, body, nav = '') {
474
503
  const header = nav
475
504
  ? `<header class="topbar"><div class="topbar-inner"><a class="brand" href="/"><span class="brand-mark" aria-hidden="true"></span><span>work-rhythm</span></a><nav aria-label="主导航">${nav}</nav></div></header>`
476
505
  : '';
@@ -483,10 +512,10 @@ function page(title, body, nav = '', opts = {}) {
483
512
  <title>${escapeHtml(title)} · work-rhythm</title>
484
513
  <style>${BASE_CSS}</style>
485
514
  </head>
486
- <body${bodyClass ? ` class="${escapeHtml(bodyClass)}"` : ''}>
515
+ <body>
487
516
  ${header}
488
517
  <div class="wrap">
489
- <main class="${surface}">
518
+ <main class="stack">
490
519
  ${body}
491
520
  </main>
492
521
  </div>