work-rhythm 0.1.7 → 0.2.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.
- package/.agents/notes/AGENTS.md +8 -1
- package/.agents/notes/decisions/2026-12-01-interjections-batch-into-one-answer-and-interrupt-reruns.md +33 -0
- package/.agents/notes/decisions/2026-12-01-long-runs-are-bounded-by-silence-not-wall-clock.md +35 -0
- package/.agents/notes/decisions/2026-12-01-router-and-worker-pass-content-in-handoff-docs.md +41 -0
- package/.agents/notes/pitfalls/2026-12-01-launchd-install-bakes-invoking-node.md +28 -0
- package/.agents/notes/pitfalls/2026-12-01-replace-string-dollar-quote-expands.md +16 -0
- package/.agents/skills/work-rhythm/SKILL.md +14 -12
- package/README.md +7 -4
- package/collectors/local.env.example +10 -1
- package/docs/agents.md +28 -11
- package/docs/channels.md +9 -6
- package/docs/router-worker.md +241 -0
- package/docs/scheduled-tasks.md +4 -4
- package/package.json +1 -1
- package/scripts/cli.js +4 -3
- package/scripts/cmd/agent.js +78 -40
- package/scripts/cmd/check.js +4 -0
- package/scripts/cmd/listen.js +20 -4
- package/scripts/cmd/rhythm.js +9 -2
- package/scripts/cmd/trigger.js +143 -0
- package/scripts/lib/agent.js +377 -30
- package/scripts/lib/bot.js +140 -35
- package/scripts/lib/engine.js +523 -0
- package/scripts/lib/handoff.js +165 -0
- package/scripts/lib/launchd.js +49 -3
- package/scripts/lib/markdown.js +328 -38
- package/scripts/lib/rhythm.js +377 -33
- package/scripts/lib/router.js +161 -0
- package/scripts/lib/run.js +43 -0
- package/scripts/lib/view.js +583 -0
- package/scripts/lib/worker.js +97 -0
- package/scripts/test/agent.test.js +17 -9
- package/scripts/test/check.test.js +7 -2
- package/scripts/test/harness.js +13 -1
- package/scripts/test/listen.test.js +3 -3
- package/scripts/test/rhythm.test.js +42 -8
- package/scripts/test/router-helper.js +80 -0
- package/scripts/test/router.test.js +509 -0
- package/scripts/test/stubs.js +82 -12
- package/scripts/test/timeout.test.js +99 -0
- package/templates/00-config/profile.example.yaml +7 -0
- package/templates/AGENTS.md +3 -1
- package/templates/README.md +4 -1
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
// 本机网页的结构化视图:把固定格式的 Markdown 渲染成可交互的数字概览卡、卡片与时间线。
|
|
2
|
+
// 记录层仍是 Markdown(docs/formats.md 的「视图」),任何不认识的段落都原样回退到 md.render(),不丢信息。
|
|
3
|
+
'use strict';
|
|
4
|
+
const md = require('./markdown');
|
|
5
|
+
|
|
6
|
+
const esc = md.escapeHtml;
|
|
7
|
+
|
|
8
|
+
// 把工作目录里的相对 .md 链接转成本机服务的页面地址;外部链接和未知路径原样放行
|
|
9
|
+
function rewriteWorkspaceHref(url) {
|
|
10
|
+
const s = String(url || '');
|
|
11
|
+
if (!s || /^(https?:|mailto:|#|\/)/i.test(s)) return s;
|
|
12
|
+
const clean = s.split('#')[0].split('?')[0];
|
|
13
|
+
if (/(?:^|\/)CARRYOVER\.md$/i.test(clean)) return '/carryover';
|
|
14
|
+
if (/(?:^|\/)DECISIONS\.md$/i.test(clean)) return '/decisions';
|
|
15
|
+
if (/(?:^|\/)WORK_RHYTHM\.md$/i.test(clean)) return '/rhythm';
|
|
16
|
+
const day = /(?:^|\/)(\d{4}-\d{2}-\d{2})\.md$/i.exec(clean);
|
|
17
|
+
if (day) return `/day/${day[1]}`;
|
|
18
|
+
if (/(?:^|\/)05-goals\/[^/]+\.md$/i.test(clean)) return '/goals';
|
|
19
|
+
return s;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const MD_OPTS = { rewriteHref: rewriteWorkspaceHref };
|
|
23
|
+
|
|
24
|
+
// 按 ## 拆开一份每日文件,保留 H1、序言和每个小节的原文
|
|
25
|
+
function splitSections(markdown) {
|
|
26
|
+
const lines = String(markdown || '').replace(/\r\n?/g, '\n').split('\n');
|
|
27
|
+
let title = '';
|
|
28
|
+
const intro = [];
|
|
29
|
+
const sections = [];
|
|
30
|
+
let cur = null;
|
|
31
|
+
for (const line of lines) {
|
|
32
|
+
if (!cur && !title && /^#\s+(.+)$/.test(line)) {
|
|
33
|
+
title = line.replace(/^#\s+/, '').trim();
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const h2 = /^##\s+(.+)$/.exec(line);
|
|
37
|
+
if (h2) {
|
|
38
|
+
cur = { title: h2[1].trim(), lines: [] };
|
|
39
|
+
sections.push(cur);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (cur) cur.lines.push(line);
|
|
43
|
+
else intro.push(line);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
title,
|
|
47
|
+
intro: intro.join('\n').trim(),
|
|
48
|
+
sections: sections.map((s) => ({ title: s.title, body: s.lines.join('\n').trim() })),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 解析小节里的顶层条目:- **标签**:值(可带缩进子块)。穿插的非标签段落也按顺序保留为 raw 块
|
|
53
|
+
function parseLabeledBlocks(body) {
|
|
54
|
+
const lines = String(body || '').split('\n');
|
|
55
|
+
const blocks = [];
|
|
56
|
+
let i = 0;
|
|
57
|
+
while (i < lines.length) {
|
|
58
|
+
const line = lines[i];
|
|
59
|
+
if (!line.trim()) {
|
|
60
|
+
i += 1;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const m = /^-\s+\*\*([^*\n]+)\*\*\s*[::]\s*(.*)$/.exec(line);
|
|
64
|
+
if (m) {
|
|
65
|
+
const label = m[1].trim();
|
|
66
|
+
const head = m[2].trim();
|
|
67
|
+
i += 1;
|
|
68
|
+
const children = [];
|
|
69
|
+
while (i < lines.length) {
|
|
70
|
+
const l = lines[i];
|
|
71
|
+
if (!l.trim()) {
|
|
72
|
+
const next = lines.slice(i + 1).find((x) => x.trim());
|
|
73
|
+
if (next && /^ {2,}/.test(next)) children.push('');
|
|
74
|
+
else break;
|
|
75
|
+
i += 1;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (/^ {2,}/.test(l)) {
|
|
79
|
+
children.push(l.slice(2));
|
|
80
|
+
i += 1;
|
|
81
|
+
} else {
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
while (children.length && !children[children.length - 1].trim()) children.pop();
|
|
86
|
+
blocks.push({ kind: 'kv', label, head, childText: children.join('\n') });
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const raw = [line];
|
|
90
|
+
i += 1;
|
|
91
|
+
while (i < lines.length && !/^-\s+\*\*([^*\n]+)\*\*\s*[::]/.test(lines[i])) {
|
|
92
|
+
raw.push(lines[i]);
|
|
93
|
+
i += 1;
|
|
94
|
+
}
|
|
95
|
+
const text = raw.join('\n').trim();
|
|
96
|
+
if (text) blocks.push({ kind: 'raw', text });
|
|
97
|
+
}
|
|
98
|
+
return blocks;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 从缩进子块里拆出「有序/无序子项」和尾部引用提示(如待你定末尾的 > 说明)
|
|
102
|
+
function parseSubItems(childText) {
|
|
103
|
+
const lines = String(childText || '').split('\n');
|
|
104
|
+
const items = [];
|
|
105
|
+
const quotes = [];
|
|
106
|
+
const extra = [];
|
|
107
|
+
for (const line of lines) {
|
|
108
|
+
const t = line.trim();
|
|
109
|
+
if (!t) continue;
|
|
110
|
+
const li = /^(?:\d+[.)]|[-*+])\s+(.*)$/.exec(t);
|
|
111
|
+
if (li) {
|
|
112
|
+
items.push(li[1].trim());
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (t.startsWith('>')) {
|
|
116
|
+
quotes.push(t.replace(/^>\s?/, '').trim());
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (items.length && !quotes.length) items[items.length - 1] += ` ${t}`;
|
|
120
|
+
else extra.push(line);
|
|
121
|
+
}
|
|
122
|
+
return { items, quotes, extra: extra.join('\n').trim() };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 渲染单条「今日重点」:如果有「 —— 」把主动作与时间建议/理由拆成两层,保留全部原文
|
|
126
|
+
function renderFocusItem(text, idx) {
|
|
127
|
+
const num = String(idx + 1).padStart(2, '0');
|
|
128
|
+
const parts = String(text).split(/\s+——\s+/);
|
|
129
|
+
const main = parts[0];
|
|
130
|
+
const rest = parts.slice(1).join(' —— ');
|
|
131
|
+
let subHtml = '';
|
|
132
|
+
if (rest) {
|
|
133
|
+
const timeMatch = /^(建议\s*\d{1,2}:\d{2}\s*[–—-]\s*\d{1,2}:\d{2}|\d{1,2}:\d{2}\s*[–—-]\s*\d{1,2}:\d{2}|\d+\s*分钟(?:内)?)(?:[,,、]\s*)?(.*)$/.exec(rest);
|
|
134
|
+
if (timeMatch) {
|
|
135
|
+
const restNote = timeMatch[2] ? `<span>${md.inline(timeMatch[2], MD_OPTS)}</span>` : '';
|
|
136
|
+
subHtml = `<div class="focus-sub"><span class="time-tag">${esc(timeMatch[1])}</span>${restNote}</div>`;
|
|
137
|
+
} else {
|
|
138
|
+
subHtml = `<div class="focus-sub"><span>${md.inline(rest, MD_OPTS)}</span></div>`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return `<li class="focus-item"><span class="focus-num">${num}</span><div class="focus-body"><div class="focus-main">${md.inline(main, MD_OPTS)}</div>${subHtml}</div></li>`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// 渲染「待你定」独立卡片
|
|
145
|
+
function renderPendingPanel(block) {
|
|
146
|
+
const sub = parseSubItems(block.childText);
|
|
147
|
+
const list = sub.items.length ? sub.items : (block.head ? [block.head] : []);
|
|
148
|
+
const tip = sub.quotes.length ? `<div class="callout-tip">${sub.quotes.map((q) => md.inline(q, MD_OPTS)).join('<br>')}</div>` : '';
|
|
149
|
+
const body = `<div class="callout-amber" id="pending-decisions"><div class="kv-k"><span class="dot is-amber"></span>待你定 · ${list.length} 件</div><ol>${list.map((it) => `<li>${md.inline(it, MD_OPTS)}</li>`).join('')}</ol>${tip}${sub.extra ? md.render(sub.extra, MD_OPTS) : ''}</div>`;
|
|
150
|
+
return { count: list.length, html: `<section class="card"><div class="card-head"><h2>待你定</h2><span class="pill is-amber">${list.length} 件</span></div>${body}</section>` };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 渲染「计划」小节(把待你定拆出给专属数字卡片后,在底部留一条快捷跳转)
|
|
154
|
+
function renderPlanBlocks(title, blocks, pendingCount) {
|
|
155
|
+
if (!blocks.length) return emptyCard(title);
|
|
156
|
+
const parts = [];
|
|
157
|
+
for (const b of blocks) {
|
|
158
|
+
if (b.kind === 'raw') {
|
|
159
|
+
parts.push(`<div class="kv-row"><div class="kv-v">${md.render(b.text, MD_OPTS)}</div></div>`);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (b.label === '今日日程' && !b.childText) {
|
|
163
|
+
parts.push(`<div class="schedule-banner"><span class="kv-k"><span class="dot is-accent"></span>${esc(b.label)}</span><div class="kv-v">${md.inline(b.head, MD_OPTS)}</div></div>`);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (b.label === '今日重点') {
|
|
167
|
+
const sub = parseSubItems(b.childText);
|
|
168
|
+
const list = sub.items.length ? sub.items : (b.head ? [b.head] : []);
|
|
169
|
+
if (list.length) {
|
|
170
|
+
parts.push(`<div class="focus-box"><div class="focus-head"><span class="kv-k">今日重点</span><span class="pill is-accent">${list.length} 项</span></div><ol class="focus-list">${list.map(renderFocusItem).join('')}</ol>${sub.extra ? `<div class="kv-v" style="margin-top:10px">${md.render(sub.extra, MD_OPTS)}</div>` : ''}</div>`);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const dotClass = b.label === '留意' ? 'is-amber' : b.label === '目标检查' ? 'is-green' : '';
|
|
175
|
+
let headHtml = b.head ? `<div>${md.inline(b.head, MD_OPTS)}</div>` : '';
|
|
176
|
+
if (b.label === '遗留带入' && b.head && /[①②③④⑤⑥⑦⑧⑨⑩]/.test(b.head)) {
|
|
177
|
+
const segs = [...b.head.matchAll(/([①②③④⑤⑥⑦⑧⑨⑩])\s*([^①②③④⑤⑥⑦⑧⑨⑩]+)/g)];
|
|
178
|
+
if (segs.length >= 2) {
|
|
179
|
+
headHtml = `<div class="circled-list">${segs.map((s) => `<div class="circled-item"><span class="circled-num">${s[1]}</span><span>${md.inline(s[2].trim(), MD_OPTS)}</span></div>`).join('')}</div>`;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const childHtml = b.childText ? md.render(b.childText, MD_OPTS) : '';
|
|
183
|
+
parts.push(`<div class="kv-row"><div class="kv-k">${dotClass ? `<span class="dot ${dotClass}"></span>` : ''}${esc(b.label)}</div><div class="kv-v">${headHtml}${childHtml}</div></div>`);
|
|
184
|
+
}
|
|
185
|
+
if (pendingCount > 0) {
|
|
186
|
+
parts.push(`<button type="button" class="pending-hint-link" data-jump="pending"><span>还有 ${pendingCount} 件「待你定」需要拍板</span><span>查看明细 →</span></button>`);
|
|
187
|
+
}
|
|
188
|
+
return `<section class="card"><div class="card-head"><h2>${esc(title)}</h2></div><div class="section-stack">${parts.join('\n')}</div></section>`;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// 渲染「进展」与「复盘」小节
|
|
192
|
+
function renderKvSection(section) {
|
|
193
|
+
if (!section.body) return emptyCard(section.title);
|
|
194
|
+
const blocks = parseLabeledBlocks(section.body);
|
|
195
|
+
const parts = [];
|
|
196
|
+
for (const b of blocks) {
|
|
197
|
+
if (b.kind === 'raw') {
|
|
198
|
+
parts.push(`<div class="kv-row"><div class="kv-v">${md.render(b.text, MD_OPTS)}</div></div>`);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
if (b.label === '今天的去处' && b.head && !b.childText) {
|
|
202
|
+
const chips = b.head.split(/\s*·\s*/).filter(Boolean);
|
|
203
|
+
if (chips.length > 1) {
|
|
204
|
+
parts.push(`<div class="kv-row"><div class="kv-k">${esc(b.label)}</div><div class="stat-chips">${chips.map((c) => `<span class="stat-chip">${md.inline(c, MD_OPTS)}</span>`).join('')}</div></div>`);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const dotMap = { 已完成: 'is-green', 进行中: 'is-accent', 风险或卡点: 'is-rose', 未完事项: 'is-amber', 目标: 'is-green' };
|
|
209
|
+
const dot = dotMap[b.label] || '';
|
|
210
|
+
const headHtml = b.head ? `<div>${md.inline(b.head, MD_OPTS)}</div>` : '';
|
|
211
|
+
const childHtml = b.childText ? md.render(b.childText, MD_OPTS) : '';
|
|
212
|
+
parts.push(`<div class="kv-row"><div class="kv-k">${dot ? `<span class="dot ${dot}"></span>` : ''}${esc(b.label)}</div><div class="kv-v">${headHtml}${childHtml}</div></div>`);
|
|
213
|
+
}
|
|
214
|
+
return `<section class="card"><div class="card-head"><h2>${esc(section.title)}</h2></div><div class="kv-list">${parts.join('\n')}</div></section>`;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// 解析事件流表格(时间 | 类型 | 事项 | 来源 | 项目)
|
|
218
|
+
function parseEventsTable(body) {
|
|
219
|
+
const lines = String(body || '').split('\n');
|
|
220
|
+
let start = -1;
|
|
221
|
+
for (let i = 0; i + 1 < lines.length; i += 1) {
|
|
222
|
+
if (lines[i].includes('|') && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(lines[i + 1])) {
|
|
223
|
+
start = i;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (start < 0) return null;
|
|
228
|
+
const splitCells = (l) => {
|
|
229
|
+
let s = l.trim();
|
|
230
|
+
if (s.startsWith('|')) s = s.slice(1);
|
|
231
|
+
if (s.endsWith('|')) s = s.slice(0, -1);
|
|
232
|
+
return s.split('|').map((c) => c.trim());
|
|
233
|
+
};
|
|
234
|
+
const header = splitCells(lines[start]);
|
|
235
|
+
if (header.length < 3 || header[0] !== '时间' || header[1] !== '类型') return null;
|
|
236
|
+
let end = start + 2;
|
|
237
|
+
const rows = [];
|
|
238
|
+
while (end < lines.length && lines[end].includes('|') && lines[end].trim()) {
|
|
239
|
+
rows.push(splitCells(lines[end]));
|
|
240
|
+
end += 1;
|
|
241
|
+
}
|
|
242
|
+
const before = lines.slice(0, start).join('\n').trim();
|
|
243
|
+
const after = lines.slice(end).join('\n').trim();
|
|
244
|
+
return { rows, before, after };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function eventTypeClass(type, desc) {
|
|
248
|
+
if (type === '会议') return 't-meeting';
|
|
249
|
+
if (type === '沟通') return 't-comm';
|
|
250
|
+
if (type === '编码') return 't-code';
|
|
251
|
+
if (type === '评审') return 't-review';
|
|
252
|
+
if (type === '工作项') return 't-issue';
|
|
253
|
+
if (type === '审批') return 't-approval';
|
|
254
|
+
if (type === '学习') return 't-learn';
|
|
255
|
+
if (/告警|终败|失败/.test(String(desc || ''))) return 't-alert';
|
|
256
|
+
return '';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function renderEventsSection(section) {
|
|
260
|
+
if (!section.body) return { count: 0, sub: '暂无事件', html: emptyCard(section.title, '暂无事件') };
|
|
261
|
+
const parsed = parseEventsTable(section.body);
|
|
262
|
+
if (!parsed) {
|
|
263
|
+
return { count: 1, sub: '事件记录', html: `<section class="card"><div class="card-head"><h2>${esc(section.title)}</h2></div>${md.render(section.body, MD_OPTS)}</section>` };
|
|
264
|
+
}
|
|
265
|
+
if (!parsed.rows.length && !parsed.before && !parsed.after) {
|
|
266
|
+
return { count: 0, sub: '暂无事件', html: emptyCard(section.title, '暂无事件') };
|
|
267
|
+
}
|
|
268
|
+
const counts = new Map();
|
|
269
|
+
for (const r of parsed.rows) {
|
|
270
|
+
const t = r[1] || '其他';
|
|
271
|
+
counts.set(t, (counts.get(t) || 0) + 1);
|
|
272
|
+
}
|
|
273
|
+
const typeEntries = [...counts.entries()];
|
|
274
|
+
const sub = typeEntries.slice(0, 3).map(([k, v]) => `${k} ${v}`).join(' · ') || '事件记录';
|
|
275
|
+
const filterBar = typeEntries.length > 1
|
|
276
|
+
? `<div class="filter-bar" role="group" aria-label="按类型筛选"><button type="button" class="filter-pill is-active" data-filter="all">全部 ${parsed.rows.length}</button>${typeEntries.map(([k, v]) => `<button type="button" class="filter-pill" data-filter="${esc(k)}">${esc(k)} ${v}</button>`).join('')}</div>`
|
|
277
|
+
: '';
|
|
278
|
+
const rowsHtml = parsed.rows.map((r) => {
|
|
279
|
+
const [time = '', type = '', desc = '', source = '', project = ''] = r;
|
|
280
|
+
const cls = eventTypeClass(type, desc);
|
|
281
|
+
const meta = [
|
|
282
|
+
project ? `<span class="meta-tag is-proj">${esc(project)}</span>` : '',
|
|
283
|
+
source ? `<span class="meta-tag">${esc(source)}</span>` : '',
|
|
284
|
+
].filter(Boolean).join('');
|
|
285
|
+
return `<div class="tl-row" data-type="${esc(type || '其他')}"><span class="tl-time">${esc(time)}</span><span class="tl-type${cls ? ` ${cls}` : ''}">${esc(type)}</span><div class="tl-desc">${md.inline(desc, MD_OPTS)}</div><div class="tl-meta">${meta}</div></div>`;
|
|
286
|
+
}).join('\n');
|
|
287
|
+
const extraBefore = parsed.before ? md.render(parsed.before, MD_OPTS) : '';
|
|
288
|
+
const extraAfter = parsed.after ? `<div style="margin-top:12px">${md.render(parsed.after, MD_OPTS)}</div>` : '';
|
|
289
|
+
const html = `<section class="card"><div class="card-head"><h2>${esc(section.title)}</h2><span class="pill">${parsed.rows.length} 条</span></div>${filterBar}${extraBefore}<div class="timeline">${rowsHtml}</div>${extraAfter}</section>`;
|
|
290
|
+
return { count: parsed.rows.length, sub, html };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function renderNotesSection(section) {
|
|
294
|
+
if (!section.body) return { count: 0, hasAlert: false, sub: '暂无备注', html: emptyCard(section.title, '暂无备注') };
|
|
295
|
+
const lines = section.body.split('\n').filter((l) => l.trim());
|
|
296
|
+
const allBullets = lines.every((l) => /^-\s+/.test(l));
|
|
297
|
+
const hasAlert = /告警|失败|终败/.test(section.body);
|
|
298
|
+
if (!allBullets) {
|
|
299
|
+
return { count: lines.length, hasAlert, sub: hasAlert ? '含告警提醒' : '备注记录', html: `<section class="card"><div class="card-head"><h2>${esc(section.title)}</h2></div>${md.render(section.body, MD_OPTS)}</section>` };
|
|
300
|
+
}
|
|
301
|
+
const items = lines.map((l) => {
|
|
302
|
+
const text = l.replace(/^-\s+/, '').trim();
|
|
303
|
+
const m = /^(\d{1,2}:\d{2}(?:[–—-]\d{1,2}:\d{2})?)\s+(.+)$/.exec(text);
|
|
304
|
+
const alert = /告警|失败|终败/.test(text) ? ' is-alert' : '';
|
|
305
|
+
if (m) {
|
|
306
|
+
return `<li class="note-item${alert}"><span class="note-time">${esc(m[1])}</span><span>${md.inline(m[2], MD_OPTS)}</span></li>`;
|
|
307
|
+
}
|
|
308
|
+
return `<li class="note-item${alert}"><span>${md.inline(text, MD_OPTS)}</span></li>`;
|
|
309
|
+
}).join('\n');
|
|
310
|
+
const html = `<section class="card"><div class="card-head"><h2>${esc(section.title)}</h2><span class="pill${hasAlert ? ' is-rose' : ''}">${lines.length} 条</span></div><ul class="note-list">${items}</ul></section>`;
|
|
311
|
+
return { count: lines.length, hasAlert, sub: hasAlert ? '含告警提醒' : '同步与备注', html };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function emptyCard(title, hint = '暂未记录') {
|
|
315
|
+
return `<section class="card is-empty"><h2>${esc(title)}</h2><span class="empty-hint">${esc(hint)}</span></section>`;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// 从计划小节提炼 1 行副标题(严格取自原文:会议数/时长、遗留条数)
|
|
319
|
+
function summarizePlan(blocks) {
|
|
320
|
+
const hints = [];
|
|
321
|
+
const sched = blocks.find((b) => b.label === '今日日程');
|
|
322
|
+
if (sched && sched.head) {
|
|
323
|
+
const m = /共\s*\d+\s*个会(?:[,,]\s*约\s*[\d.]+\s*h)?/.exec(sched.head);
|
|
324
|
+
if (m) hints.push(m[0].replace(/^共\s*/, ''));
|
|
325
|
+
}
|
|
326
|
+
const carry = blocks.find((b) => b.label === '遗留带入');
|
|
327
|
+
if (carry && carry.head) {
|
|
328
|
+
const circled = carry.head.match(/[①②③④⑤⑥⑦⑧⑨⑩]/g);
|
|
329
|
+
if (circled) hints.push(`遗留 ${circled.length} 条`);
|
|
330
|
+
}
|
|
331
|
+
return hints.join(' · ') || '日程与安排';
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// 从复盘小节提炼 1 行副标题(优先取「今天的去处」前两段)
|
|
335
|
+
function summarizeReview(blocks) {
|
|
336
|
+
const where = blocks.find((b) => b.label === '今天的去处');
|
|
337
|
+
if (where && where.head) {
|
|
338
|
+
const segs = where.head.split(/\s*·\s*/).filter(Boolean).slice(0, 2);
|
|
339
|
+
if (segs.length) return segs.join(' · ');
|
|
340
|
+
}
|
|
341
|
+
return blocks.length ? '晚间复盘' : '暂未复盘';
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// 每日页客户端交互:点数字卡片切换明细、展开全部、事件流按类型筛选、hash 记忆
|
|
345
|
+
const DAY_SCRIPT = `<script>(function(){
|
|
346
|
+
var cards=[].slice.call(document.querySelectorAll('.kpi-card[data-key]'));
|
|
347
|
+
var panels=[].slice.call(document.querySelectorAll('.day-panel[data-panel]'));
|
|
348
|
+
var box=document.querySelector('.day-panels');
|
|
349
|
+
var toggle=document.querySelector('[data-toggle-all]');
|
|
350
|
+
if(!cards.length||!box)return;
|
|
351
|
+
function select(key,pushHash){
|
|
352
|
+
box.classList.remove('show-all');
|
|
353
|
+
if(toggle){toggle.classList.remove('is-active');toggle.textContent='展开全部';toggle.setAttribute('aria-pressed','false');}
|
|
354
|
+
cards.forEach(function(c){
|
|
355
|
+
var on=c.getAttribute('data-key')===key;
|
|
356
|
+
c.classList.toggle('is-selected',on);
|
|
357
|
+
c.setAttribute('aria-pressed',on?'true':'false');
|
|
358
|
+
});
|
|
359
|
+
panels.forEach(function(p){
|
|
360
|
+
p.classList.toggle('is-open',p.getAttribute('data-panel')===key);
|
|
361
|
+
});
|
|
362
|
+
if(pushHash&&history.replaceState)history.replaceState(null,'','#'+key);
|
|
363
|
+
}
|
|
364
|
+
function showAll(pushHash){
|
|
365
|
+
box.classList.add('show-all');
|
|
366
|
+
if(toggle){toggle.classList.add('is-active');toggle.textContent='单卡视图';toggle.setAttribute('aria-pressed','true');}
|
|
367
|
+
cards.forEach(function(c){c.classList.remove('is-selected');c.setAttribute('aria-pressed','false');});
|
|
368
|
+
if(pushHash&&history.replaceState)history.replaceState(null,'','#all');
|
|
369
|
+
}
|
|
370
|
+
cards.forEach(function(c){c.addEventListener('click',function(){select(c.getAttribute('data-key'),true);});});
|
|
371
|
+
if(toggle)toggle.addEventListener('click',function(){
|
|
372
|
+
if(box.classList.contains('show-all'))select(cards[0].getAttribute('data-key'),true);
|
|
373
|
+
else showAll(true);
|
|
374
|
+
});
|
|
375
|
+
[].slice.call(document.querySelectorAll('[data-jump]')).forEach(function(btn){
|
|
376
|
+
btn.addEventListener('click',function(){
|
|
377
|
+
var k=btn.getAttribute('data-jump');
|
|
378
|
+
if(cards.some(function(c){return c.getAttribute('data-key')===k;}))select(k,true);
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
[].slice.call(document.querySelectorAll('.filter-pill[data-filter]')).forEach(function(btn){
|
|
382
|
+
btn.addEventListener('click',function(){
|
|
383
|
+
var type=btn.getAttribute('data-filter');
|
|
384
|
+
var bar=btn.closest('.filter-bar');
|
|
385
|
+
var card=btn.closest('.card');
|
|
386
|
+
if(!bar||!card)return;
|
|
387
|
+
[].slice.call(bar.querySelectorAll('.filter-pill')).forEach(function(b){b.classList.toggle('is-active',b===btn);});
|
|
388
|
+
[].slice.call(card.querySelectorAll('.tl-row')).forEach(function(r){
|
|
389
|
+
r.classList.toggle('is-hidden',type!=='all'&&r.getAttribute('data-type')!==type);
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
var hash=(location.hash||'').replace(/^#/,'');
|
|
394
|
+
if(hash==='all')showAll(false);
|
|
395
|
+
else if(hash==='pending-decisions'&&cards.some(function(c){return c.getAttribute('data-key')==='pending';}))select('pending',false);
|
|
396
|
+
else if(hash&&cards.some(function(c){return c.getAttribute('data-key')===hash;}))select(hash,false);
|
|
397
|
+
})();</script>`;
|
|
398
|
+
|
|
399
|
+
function renderKpiCard(item, selected) {
|
|
400
|
+
const cls = ['kpi-card', item.tone || '', item.empty ? 'is-empty-kpi' : '', selected ? 'is-selected' : ''].filter(Boolean).join(' ');
|
|
401
|
+
const dot = item.dot ? `<span class="dot ${item.dot}"></span>` : '';
|
|
402
|
+
const unit = item.unit ? `<span class="kpi-unit">${esc(item.unit)}</span>` : '';
|
|
403
|
+
return `<button type="button" class="${cls}" data-key="${esc(item.key)}" aria-pressed="${selected ? 'true' : 'false'}">
|
|
404
|
+
<div class="kpi-top"><span class="kpi-label">${dot}${esc(item.label)}</span><span class="kpi-arrow">明细 ↗</span></div>
|
|
405
|
+
<div class="kpi-num">${esc(item.num)}${unit}</div>
|
|
406
|
+
<div class="kpi-sub">${esc(item.sub)}</div>
|
|
407
|
+
</button>`;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function renderDaily({ date, weekday, isToday, markdown, dates = [] }) {
|
|
411
|
+
const [year, month, day] = String(date || '').split('-');
|
|
412
|
+
const humanDate = month && day ? `${Number(month)} 月 ${Number(day)} 日` : date;
|
|
413
|
+
// dates 按新到旧排序:prev 是更早的一天(下标 +1),next 是更新的一天(下标 -1)
|
|
414
|
+
const idx = dates.indexOf(date);
|
|
415
|
+
const prevDate = idx >= 0 ? dates[idx + 1] : dates.find((d) => d < date);
|
|
416
|
+
const nextDate = idx > 0 ? dates[idx - 1] : [...dates].reverse().find((d) => d > date);
|
|
417
|
+
const navArrows = (withToggle) => `<div class="day-arrows">${prevDate ? `<a class="day-btn" href="/day/${prevDate}">← ${prevDate.slice(5)}</a>` : '<span class="day-btn is-disabled">← 更早</span>'}${nextDate ? `<a class="day-btn" href="/day/${nextDate}">${nextDate.slice(5)} →</a>` : '<span class="day-btn is-disabled">更新 →</span>'}${withToggle ? '<button type="button" class="day-btn" data-toggle-all aria-pressed="false">展开全部</button>' : ''}</div>`;
|
|
418
|
+
const stripDates = dates.slice(0, 14);
|
|
419
|
+
const strip = stripDates.length
|
|
420
|
+
? `<div class="day-strip" aria-label="最近的日子">${stripDates.map((d) => `<a class="day-chip${d === date ? ' is-current' : ''}" href="/day/${d}">${d.slice(5)}</a>`).join('')}</div>`
|
|
421
|
+
: '<div class="day-strip"><span class="muted">还没有其他日期的文件</span></div>';
|
|
422
|
+
|
|
423
|
+
if (!markdown) {
|
|
424
|
+
const hero = `<header class="day-hero"><div class="day-hero-top"><div><div class="day-eyebrow"><span>${esc(year || '')}${year ? ' 年' : ''}</span>${isToday ? '<span class="pill is-accent">今天</span>' : ''}</div><div class="day-title"><h1>${esc(humanDate)}</h1><span class="day-weekday">${esc(weekday || '')}</span></div></div>${navArrows(false)}</div>${strip}</header>`;
|
|
425
|
+
const empty = '<section class="card"><p class="muted" style="margin:0">今天还没有每日文件。等定时任务跑完,或对 AI 说「做今天的计划」后,这里就会更新。</p></section>';
|
|
426
|
+
return `${hero}\n${empty}`;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const doc = splitSections(markdown);
|
|
430
|
+
const byTitle = new Map(doc.sections.map((s) => [s.title, s]));
|
|
431
|
+
const items = [];
|
|
432
|
+
|
|
433
|
+
// 1. 计划 & 待你定
|
|
434
|
+
const planSec = byTitle.get('计划');
|
|
435
|
+
let pendingItem = null;
|
|
436
|
+
if (planSec) {
|
|
437
|
+
const allBlocks = planSec.body ? parseLabeledBlocks(planSec.body) : [];
|
|
438
|
+
const pendingBlock = allBlocks.find((b) => b.kind === 'kv' && b.label === '待你定');
|
|
439
|
+
const restBlocks = allBlocks.filter((b) => b !== pendingBlock);
|
|
440
|
+
let pendingCount = 0;
|
|
441
|
+
if (pendingBlock) {
|
|
442
|
+
const p = renderPendingPanel(pendingBlock);
|
|
443
|
+
if (p.count > 0) {
|
|
444
|
+
pendingCount = p.count;
|
|
445
|
+
pendingItem = { key: 'pending', label: '待你定', num: p.count, unit: '件', sub: '需要你拍板', dot: 'is-amber', tone: 'is-amber', empty: false, html: p.html };
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
const focusBlock = restBlocks.find((b) => b.kind === 'kv' && b.label === '今日重点');
|
|
449
|
+
let focusCount = 0;
|
|
450
|
+
if (focusBlock) {
|
|
451
|
+
const sub = parseSubItems(focusBlock.childText);
|
|
452
|
+
focusCount = sub.items.length || (focusBlock.head ? 1 : 0);
|
|
453
|
+
}
|
|
454
|
+
const num = focusCount || restBlocks.length;
|
|
455
|
+
items.push({
|
|
456
|
+
key: 'plan',
|
|
457
|
+
label: focusCount ? '今日重点' : '计划',
|
|
458
|
+
num,
|
|
459
|
+
unit: focusCount ? '项' : (num ? '块' : ''),
|
|
460
|
+
sub: restBlocks.length ? summarizePlan(restBlocks) : '暂未制定计划',
|
|
461
|
+
dot: 'is-accent',
|
|
462
|
+
tone: '',
|
|
463
|
+
empty: !restBlocks.length,
|
|
464
|
+
html: renderPlanBlocks(planSec.title, restBlocks, pendingCount),
|
|
465
|
+
});
|
|
466
|
+
if (pendingItem) items.push(pendingItem);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// 2. 进展 & 复盘(进展为空且复盘有内容时,把进展空态收进复盘明细底部,保持顶部数字卡紧凑)
|
|
470
|
+
const progSec = byTitle.get('进展');
|
|
471
|
+
const revSec = byTitle.get('复盘');
|
|
472
|
+
const progHas = Boolean(progSec && progSec.body);
|
|
473
|
+
const revHas = Boolean(revSec && revSec.body);
|
|
474
|
+
if (progSec && (progHas || !revHas)) {
|
|
475
|
+
const blocks = progHas ? parseLabeledBlocks(progSec.body) : [];
|
|
476
|
+
items.push({
|
|
477
|
+
key: 'progress',
|
|
478
|
+
label: '进展',
|
|
479
|
+
num: blocks.length,
|
|
480
|
+
unit: blocks.length ? '项' : '',
|
|
481
|
+
sub: progHas ? '午间进展更新' : '暂未记录',
|
|
482
|
+
dot: progHas ? 'is-green' : '',
|
|
483
|
+
tone: '',
|
|
484
|
+
empty: !progHas,
|
|
485
|
+
html: renderKvSection(progSec),
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
if (revSec) {
|
|
489
|
+
const blocks = revHas ? parseLabeledBlocks(revSec.body) : [];
|
|
490
|
+
const foldedProg = progSec && !progHas && revHas ? `\n${emptyCard(progSec.title)}` : '';
|
|
491
|
+
items.push({
|
|
492
|
+
key: 'review',
|
|
493
|
+
label: '复盘',
|
|
494
|
+
num: blocks.length,
|
|
495
|
+
unit: blocks.length ? '项' : '',
|
|
496
|
+
sub: summarizeReview(blocks),
|
|
497
|
+
dot: revHas ? 'is-green' : '',
|
|
498
|
+
tone: '',
|
|
499
|
+
empty: !revHas,
|
|
500
|
+
html: `${renderKvSection(revSec)}${foldedProg}`,
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// 3. 事件流
|
|
505
|
+
const evSec = byTitle.get('事件流');
|
|
506
|
+
if (evSec) {
|
|
507
|
+
const ev = renderEventsSection(evSec);
|
|
508
|
+
items.push({
|
|
509
|
+
key: 'events',
|
|
510
|
+
label: '事件流',
|
|
511
|
+
num: ev.count,
|
|
512
|
+
unit: '条',
|
|
513
|
+
sub: ev.sub,
|
|
514
|
+
dot: ev.count ? 'is-accent' : '',
|
|
515
|
+
tone: '',
|
|
516
|
+
empty: ev.count === 0,
|
|
517
|
+
html: ev.html,
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// 4. 备注
|
|
522
|
+
const noteSec = byTitle.get('备注');
|
|
523
|
+
if (noteSec) {
|
|
524
|
+
const nt = renderNotesSection(noteSec);
|
|
525
|
+
items.push({
|
|
526
|
+
key: 'notes',
|
|
527
|
+
label: '备注',
|
|
528
|
+
num: nt.count,
|
|
529
|
+
unit: '条',
|
|
530
|
+
sub: nt.sub,
|
|
531
|
+
dot: nt.hasAlert ? 'is-rose' : '',
|
|
532
|
+
tone: nt.hasAlert ? 'is-rose' : '',
|
|
533
|
+
empty: nt.count === 0,
|
|
534
|
+
html: nt.html,
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// 5. 其余自定义小节
|
|
539
|
+
const known = new Set(['计划', '进展', '复盘', '事件流', '备注']);
|
|
540
|
+
let extraIdx = 0;
|
|
541
|
+
for (const sec of doc.sections) {
|
|
542
|
+
if (known.has(sec.title)) continue;
|
|
543
|
+
extraIdx += 1;
|
|
544
|
+
const html = sec.body
|
|
545
|
+
? `<section class="card"><div class="card-head"><h2>${esc(sec.title)}</h2></div>${md.render(sec.body, MD_OPTS)}</section>`
|
|
546
|
+
: emptyCard(sec.title);
|
|
547
|
+
items.push({
|
|
548
|
+
key: `extra-${extraIdx}`,
|
|
549
|
+
label: sec.title,
|
|
550
|
+
num: sec.body ? sec.body.split('\n').filter((l) => l.trim()).length : 0,
|
|
551
|
+
unit: '行',
|
|
552
|
+
sub: sec.body ? '自定义小节' : '暂未记录',
|
|
553
|
+
dot: '',
|
|
554
|
+
tone: '',
|
|
555
|
+
empty: !sec.body,
|
|
556
|
+
html,
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const firstActive = (items.find((it) => !it.empty) || items[0] || {}).key || '';
|
|
561
|
+
const hero = `<header class="day-hero"><div class="day-hero-top"><div><div class="day-eyebrow"><span>${esc(date)}</span>${isToday ? '<span class="pill is-accent">今天</span>' : ''}</div><div class="day-title"><h1>${esc(humanDate)}</h1><span class="day-weekday">${esc(weekday || '')}</span></div></div>${navArrows(items.length > 1)}</div>${strip}</header>`;
|
|
562
|
+
const introHtml = doc.intro ? `<section class="card">${md.render(doc.intro, MD_OPTS)}</section>` : '';
|
|
563
|
+
const kpiGrid = items.length
|
|
564
|
+
? `<section class="kpi-grid" aria-label="今日概览卡片">${items.map((it) => renderKpiCard(it, it.key === firstActive)).join('\n')}</section>`
|
|
565
|
+
: '';
|
|
566
|
+
const panelsHtml = items.length
|
|
567
|
+
? `<div class="day-panels">${items.map((it) => `<div class="day-panel${it.key === firstActive ? ' is-open' : ''}" data-panel="${esc(it.key)}">${it.html}</div>`).join('\n')}</div>`
|
|
568
|
+
: '';
|
|
569
|
+
|
|
570
|
+
return `${hero}\n${introHtml}\n${kpiGrid}\n${panelsHtml}\n${DAY_SCRIPT}`;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function renderGoals(items) {
|
|
574
|
+
return items.map(({ name, text }) => `<section class="card"><div class="day-eyebrow" style="margin-bottom:8px"><span class="pill is-green">长期目标</span><code>${esc(name.replace(/\.md$/, ''))}</code></div>${md.render(text, MD_OPTS)}</section>`).join('\n');
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
function renderReports(files) {
|
|
578
|
+
if (!files.length) return '<section class="card"><div class="card-head"><h2>报告</h2></div><p class="muted">还没有生成的报告。</p></section>';
|
|
579
|
+
const list = files.map((f) => `<a class="report-item" href="/reports/${esc(f)}"><span>${esc(f)}</span><span class="muted">打开 →</span></a>`).join('\n');
|
|
580
|
+
return `<section class="card"><div class="card-head"><h2>报告</h2><span class="pill">${files.length} 份</span></div><div class="report-list">${list}</div></section>`;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
module.exports = { rewriteWorkspaceHref, renderDaily, renderGoals, renderReports, MD_OPTS };
|