work-rhythm 0.1.8 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/notes/AGENTS.md +12 -1
- package/.agents/notes/decisions/2026-12-01-agent-runs-the-login-for-the-user.md +30 -0
- 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-question-cards-via-cli-tool-on-todays-page-answers-return-to-router.md +40 -0
- package/.agents/notes/decisions/2026-12-01-router-and-worker-pass-content-in-handoff-docs.md +42 -0
- package/.agents/notes/decisions/2026-12-01-router-runs-on-a-flash-model-with-low-effort.md +33 -0
- package/.agents/notes/decisions/2026-12-01-sync-feeds-refine-then-events-to-the-router.md +38 -0
- package/.agents/notes/pitfalls/2026-12-01-replace-string-dollar-quote-expands.md +16 -0
- package/.agents/notes/pitfalls/2026-12-02-rhythm-start-in-the-foreground-displaces-the-launchd-service.md +27 -0
- package/.agents/skills/work-rhythm/SKILL.md +20 -12
- package/README.md +32 -4
- package/collectors/local.env.example +10 -1
- package/docs/agents.md +53 -13
- package/docs/channels.md +9 -6
- package/docs/router-worker.md +263 -0
- package/docs/scheduled-tasks.md +5 -5
- package/docs/sources.md +20 -0
- package/package.json +1 -1
- package/scripts/cli.js +5 -3
- package/scripts/cmd/agent.js +188 -49
- package/scripts/cmd/ask.js +104 -0
- package/scripts/cmd/check.js +4 -0
- package/scripts/cmd/listen.js +18 -4
- package/scripts/cmd/rhythm.js +6 -2
- package/scripts/cmd/sync.js +11 -3
- package/scripts/cmd/trigger.js +143 -0
- package/scripts/lib/agent.js +482 -30
- package/scripts/lib/asks.js +145 -0
- package/scripts/lib/bot.js +140 -35
- package/scripts/lib/engine.js +707 -0
- package/scripts/lib/handoff.js +167 -0
- package/scripts/lib/markdown.js +355 -36
- package/scripts/lib/rhythm.js +576 -38
- package/scripts/lib/router.js +208 -0
- package/scripts/lib/run.js +43 -0
- package/scripts/lib/view.js +736 -0
- package/scripts/lib/worker.js +98 -0
- package/scripts/test/agent.test.js +126 -9
- package/scripts/test/check.test.js +7 -2
- package/scripts/test/harness.js +15 -1
- package/scripts/test/listen.test.js +2 -2
- package/scripts/test/rhythm.test.js +109 -6
- package/scripts/test/router-helper.js +110 -0
- package/scripts/test/router.test.js +799 -0
- package/scripts/test/stubs.js +113 -12
- package/scripts/test/timeout.test.js +99 -0
- package/tasks/daily-plan.md +1 -2
- package/templates/00-config/profile.example.yaml +9 -0
- package/templates/AGENTS.md +3 -1
- package/templates/README.md +4 -1
|
@@ -0,0 +1,736 @@
|
|
|
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
|
+
// 渲染「待你定」卡片列表片段(/asks.html 也直接返回这段,供今日页实时轮询)
|
|
145
|
+
function renderAsksFragment(cards) {
|
|
146
|
+
const list = Array.isArray(cards) ? cards : [];
|
|
147
|
+
const sig = list.map((c) => `${c.id || c.item}:${c.at || c.date || ''}`).join('|');
|
|
148
|
+
if (!list.length) {
|
|
149
|
+
return `<div class="ask-list" data-ask-count="0" data-ask-sig=""><p class="muted">现在没有待你定的事。执行者用 <code>work-rhythm ask</code> 丢出问题后,这里会实时出现。</p></div>`;
|
|
150
|
+
}
|
|
151
|
+
const items = list.map((c, i) => {
|
|
152
|
+
const opts = Array.isArray(c.options) ? c.options : [];
|
|
153
|
+
const optsHtml = opts.length
|
|
154
|
+
? `<div class="ask-opts">${opts.map((o) => `<button type="button" class="ask-opt${o.suggested ? ' is-suggested' : ''}" data-choice="${esc(o.label)}"><span>${esc(o.label)}</span>${o.suggested ? '<span class="pill is-amber">建议</span>' : ''}${o.detail ? `<span class="ask-opt-detail">${esc(o.detail)}</span>` : ''}</button>`).join('')}</div>`
|
|
155
|
+
: '';
|
|
156
|
+
const notePlaceholder = opts.length ? '附言或自己写回答(可选,点按钮时会一起带上)' : '写下你的回答…';
|
|
157
|
+
const formHtml = `<form class="ask-form"><input type="text" class="todo-input" name="note" placeholder="${esc(notePlaceholder)}" autocomplete="off"><button type="submit" class="ask-opt">提交</button></form>`;
|
|
158
|
+
const meta = [c.at ? c.at.slice(5, 16) : (c.date || ''), c.from && c.from.trigger ? `来自 ${c.from.trigger}` : '', c.record ? `记到 ${c.record}` : ''].filter(Boolean).join(' · ');
|
|
159
|
+
return `<article class="ask-card" data-ask-id="${esc(c.id || '')}" data-ask-item="${esc(c.item || c.question || '')}">
|
|
160
|
+
<div class="ask-head"><div class="ask-q">${esc(c.question || c.item || '')}</div><span class="pill is-amber">#${i + 1}</span></div>
|
|
161
|
+
${c.context ? `<div class="ask-ctx">${md.inline(c.context, MD_OPTS)}</div>` : ''}
|
|
162
|
+
${meta ? `<div class="ask-meta">${esc(meta)}</div>` : ''}
|
|
163
|
+
${optsHtml}
|
|
164
|
+
${formHtml}
|
|
165
|
+
<div class="ask-after" hidden></div>
|
|
166
|
+
</article>`;
|
|
167
|
+
}).join('\n');
|
|
168
|
+
return `<div class="ask-list" data-ask-count="${list.length}" data-ask-sig="${esc(sig)}">${items}</div>`;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// 渲染「待你定」独立卡片(实时更新)
|
|
172
|
+
function renderPendingCard(cards, { token = '', live = false } = {}) {
|
|
173
|
+
const list = Array.isArray(cards) ? cards : [];
|
|
174
|
+
const count = list.length;
|
|
175
|
+
const body = `<div id="pending-decisions-body">${renderAsksFragment(list)}</div>`;
|
|
176
|
+
const html = `<section class="card" id="pending-decisions" data-ask-token="${esc(token)}"${live ? ' data-ask-live="1"' : ''}><div class="card-head"><h2>待你定</h2><span class="pill${count ? ' is-amber' : ''}" id="pending-pill">${count} 件</span></div>${body}</section>`;
|
|
177
|
+
return { count, html };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// 渲染「计划」小节(把待你定拆出给专属数字卡片后,在底部留一条快捷跳转)
|
|
181
|
+
function renderPlanBlocks(title, blocks, pendingCount) {
|
|
182
|
+
if (!blocks.length) return emptyCard(title);
|
|
183
|
+
const parts = [];
|
|
184
|
+
for (const b of blocks) {
|
|
185
|
+
if (b.kind === 'raw') {
|
|
186
|
+
parts.push(`<div class="kv-row"><div class="kv-v">${md.render(b.text, MD_OPTS)}</div></div>`);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (b.label === '今日日程' && !b.childText) {
|
|
190
|
+
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>`);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (b.label === '今日重点') {
|
|
194
|
+
const sub = parseSubItems(b.childText);
|
|
195
|
+
const list = sub.items.length ? sub.items : (b.head ? [b.head] : []);
|
|
196
|
+
if (list.length) {
|
|
197
|
+
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>`);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const dotClass = b.label === '留意' ? 'is-amber' : b.label === '目标检查' ? 'is-green' : '';
|
|
202
|
+
let headHtml = b.head ? `<div>${md.inline(b.head, MD_OPTS)}</div>` : '';
|
|
203
|
+
if (b.label === '遗留带入' && b.head && /[①②③④⑤⑥⑦⑧⑨⑩]/.test(b.head)) {
|
|
204
|
+
const segs = [...b.head.matchAll(/([①②③④⑤⑥⑦⑧⑨⑩])\s*([^①②③④⑤⑥⑦⑧⑨⑩]+)/g)];
|
|
205
|
+
if (segs.length >= 2) {
|
|
206
|
+
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>`;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const childHtml = b.childText ? md.render(b.childText, MD_OPTS) : '';
|
|
210
|
+
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>`);
|
|
211
|
+
}
|
|
212
|
+
if (pendingCount > 0) {
|
|
213
|
+
parts.push(`<button type="button" class="pending-hint-link" data-jump="pending"><span>还有 ${pendingCount} 件「待你定」需要拍板</span><span>查看明细 →</span></button>`);
|
|
214
|
+
}
|
|
215
|
+
return `<section class="card"><div class="card-head"><h2>${esc(title)}</h2></div><div class="section-stack">${parts.join('\n')}</div></section>`;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// 渲染「进展」与「复盘」小节
|
|
219
|
+
function renderKvSection(section) {
|
|
220
|
+
if (!section.body) return emptyCard(section.title);
|
|
221
|
+
const blocks = parseLabeledBlocks(section.body);
|
|
222
|
+
const parts = [];
|
|
223
|
+
for (const b of blocks) {
|
|
224
|
+
if (b.kind === 'raw') {
|
|
225
|
+
parts.push(`<div class="kv-row"><div class="kv-v">${md.render(b.text, MD_OPTS)}</div></div>`);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (b.label === '今天的去处' && b.head && !b.childText) {
|
|
229
|
+
const chips = b.head.split(/\s*·\s*/).filter(Boolean);
|
|
230
|
+
if (chips.length > 1) {
|
|
231
|
+
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>`);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const dotMap = { 已完成: 'is-green', 进行中: 'is-accent', 风险或卡点: 'is-rose', 未完事项: 'is-amber', 目标: 'is-green' };
|
|
236
|
+
const dot = dotMap[b.label] || '';
|
|
237
|
+
const headHtml = b.head ? `<div>${md.inline(b.head, MD_OPTS)}</div>` : '';
|
|
238
|
+
const childHtml = b.childText ? md.render(b.childText, MD_OPTS) : '';
|
|
239
|
+
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>`);
|
|
240
|
+
}
|
|
241
|
+
return `<section class="card"><div class="card-head"><h2>${esc(section.title)}</h2></div><div class="kv-list">${parts.join('\n')}</div></section>`;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// 解析事件流表格(时间 | 类型 | 事项 | 来源 | 项目)
|
|
245
|
+
function parseEventsTable(body) {
|
|
246
|
+
const lines = String(body || '').split('\n');
|
|
247
|
+
let start = -1;
|
|
248
|
+
for (let i = 0; i + 1 < lines.length; i += 1) {
|
|
249
|
+
if (lines[i].includes('|') && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(lines[i + 1])) {
|
|
250
|
+
start = i;
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (start < 0) return null;
|
|
255
|
+
const splitCells = (l) => {
|
|
256
|
+
let s = l.trim();
|
|
257
|
+
if (s.startsWith('|')) s = s.slice(1);
|
|
258
|
+
if (s.endsWith('|')) s = s.slice(0, -1);
|
|
259
|
+
return s.split('|').map((c) => c.trim());
|
|
260
|
+
};
|
|
261
|
+
const header = splitCells(lines[start]);
|
|
262
|
+
if (header.length < 3 || header[0] !== '时间' || header[1] !== '类型') return null;
|
|
263
|
+
let end = start + 2;
|
|
264
|
+
const rows = [];
|
|
265
|
+
while (end < lines.length && lines[end].includes('|') && lines[end].trim()) {
|
|
266
|
+
rows.push(splitCells(lines[end]));
|
|
267
|
+
end += 1;
|
|
268
|
+
}
|
|
269
|
+
const before = lines.slice(0, start).join('\n').trim();
|
|
270
|
+
const after = lines.slice(end).join('\n').trim();
|
|
271
|
+
return { rows, before, after };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function eventTypeClass(type, desc) {
|
|
275
|
+
if (type === '会议') return 't-meeting';
|
|
276
|
+
if (type === '沟通') return 't-comm';
|
|
277
|
+
if (type === '编码') return 't-code';
|
|
278
|
+
if (type === '评审') return 't-review';
|
|
279
|
+
if (type === '工作项') return 't-issue';
|
|
280
|
+
if (type === '审批') return 't-approval';
|
|
281
|
+
if (type === '学习') return 't-learn';
|
|
282
|
+
if (/告警|终败|失败/.test(String(desc || ''))) return 't-alert';
|
|
283
|
+
return '';
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function renderEventsSection(section) {
|
|
287
|
+
if (!section.body) return { count: 0, sub: '暂无事件', html: emptyCard(section.title, '暂无事件') };
|
|
288
|
+
const parsed = parseEventsTable(section.body);
|
|
289
|
+
if (!parsed) {
|
|
290
|
+
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>` };
|
|
291
|
+
}
|
|
292
|
+
if (!parsed.rows.length && !parsed.before && !parsed.after) {
|
|
293
|
+
return { count: 0, sub: '暂无事件', html: emptyCard(section.title, '暂无事件') };
|
|
294
|
+
}
|
|
295
|
+
const counts = new Map();
|
|
296
|
+
for (const r of parsed.rows) {
|
|
297
|
+
const t = r[1] || '其他';
|
|
298
|
+
counts.set(t, (counts.get(t) || 0) + 1);
|
|
299
|
+
}
|
|
300
|
+
const typeEntries = [...counts.entries()];
|
|
301
|
+
const sub = typeEntries.slice(0, 3).map(([k, v]) => `${k} ${v}`).join(' · ') || '事件记录';
|
|
302
|
+
const filterBar = typeEntries.length > 1
|
|
303
|
+
? `<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>`
|
|
304
|
+
: '';
|
|
305
|
+
const rowsHtml = parsed.rows.map((r) => {
|
|
306
|
+
const [time = '', type = '', desc = '', source = '', project = ''] = r;
|
|
307
|
+
const cls = eventTypeClass(type, desc);
|
|
308
|
+
const meta = [
|
|
309
|
+
project ? `<span class="meta-tag is-proj">${esc(project)}</span>` : '',
|
|
310
|
+
source ? `<span class="meta-tag">${esc(source)}</span>` : '',
|
|
311
|
+
].filter(Boolean).join('');
|
|
312
|
+
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>`;
|
|
313
|
+
}).join('\n');
|
|
314
|
+
const extraBefore = parsed.before ? md.render(parsed.before, MD_OPTS) : '';
|
|
315
|
+
const extraAfter = parsed.after ? `<div style="margin-top:12px">${md.render(parsed.after, MD_OPTS)}</div>` : '';
|
|
316
|
+
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>`;
|
|
317
|
+
return { count: parsed.rows.length, sub, html };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function renderNotesSection(section) {
|
|
321
|
+
if (!section.body) return { count: 0, hasAlert: false, sub: '暂无备注', html: emptyCard(section.title, '暂无备注') };
|
|
322
|
+
const lines = section.body.split('\n').filter((l) => l.trim());
|
|
323
|
+
const allBullets = lines.every((l) => /^-\s+/.test(l));
|
|
324
|
+
const hasAlert = /告警|失败|终败/.test(section.body);
|
|
325
|
+
if (!allBullets) {
|
|
326
|
+
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>` };
|
|
327
|
+
}
|
|
328
|
+
const items = lines.map((l) => {
|
|
329
|
+
const text = l.replace(/^-\s+/, '').trim();
|
|
330
|
+
const m = /^(\d{1,2}:\d{2}(?:[–—-]\d{1,2}:\d{2})?)\s+(.+)$/.exec(text);
|
|
331
|
+
const alert = /告警|失败|终败/.test(text) ? ' is-alert' : '';
|
|
332
|
+
if (m) {
|
|
333
|
+
return `<li class="note-item${alert}"><span class="note-time">${esc(m[1])}</span><span>${md.inline(m[2], MD_OPTS)}</span></li>`;
|
|
334
|
+
}
|
|
335
|
+
return `<li class="note-item${alert}"><span>${md.inline(text, MD_OPTS)}</span></li>`;
|
|
336
|
+
}).join('\n');
|
|
337
|
+
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>`;
|
|
338
|
+
return { count: lines.length, hasAlert, sub: hasAlert ? '含告警提醒' : '同步与备注', html };
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function emptyCard(title, hint = '暂未记录') {
|
|
342
|
+
return `<section class="card is-empty"><h2>${esc(title)}</h2><span class="empty-hint">${esc(hint)}</span></section>`;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// 从计划小节提炼 1 行副标题(严格取自原文:会议数/时长、遗留条数)
|
|
346
|
+
function summarizePlan(blocks) {
|
|
347
|
+
const hints = [];
|
|
348
|
+
const sched = blocks.find((b) => b.label === '今日日程');
|
|
349
|
+
if (sched && sched.head) {
|
|
350
|
+
const m = /共\s*\d+\s*个会(?:[,,]\s*约\s*[\d.]+\s*h)?/.exec(sched.head);
|
|
351
|
+
if (m) hints.push(m[0].replace(/^共\s*/, ''));
|
|
352
|
+
}
|
|
353
|
+
const carry = blocks.find((b) => b.label === '遗留带入');
|
|
354
|
+
if (carry && carry.head) {
|
|
355
|
+
const circled = carry.head.match(/[①②③④⑤⑥⑦⑧⑨⑩]/g);
|
|
356
|
+
if (circled) hints.push(`遗留 ${circled.length} 条`);
|
|
357
|
+
}
|
|
358
|
+
return hints.join(' · ') || '日程与安排';
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// 从复盘小节提炼 1 行副标题(优先取「今天的去处」前两段)
|
|
362
|
+
function summarizeReview(blocks) {
|
|
363
|
+
const where = blocks.find((b) => b.label === '今天的去处');
|
|
364
|
+
if (where && where.head) {
|
|
365
|
+
const segs = where.head.split(/\s*·\s*/).filter(Boolean).slice(0, 2);
|
|
366
|
+
if (segs.length) return segs.join(' · ');
|
|
367
|
+
}
|
|
368
|
+
return blocks.length ? '晚间复盘' : '暂未复盘';
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// 每日页客户端交互,两段各自独立:「待你定」的卡片(回答、实时刷新)和数字卡片(点一张切换明细、展开全部、按类型筛选、hash 记忆)。
|
|
372
|
+
// 顺序不能反:今天还没有每日文件时没有数字卡片,那一段会直接返回,卡片那一段必须在它前面
|
|
373
|
+
const DAY_SCRIPT = `<script>
|
|
374
|
+
/* 「待你定」的卡片:点选项、提交回答、实时刷新。它不依赖下面的数字卡片——今天还没有每日文件时页面上没有数字卡片,卡片也要能答 */
|
|
375
|
+
(function(){
|
|
376
|
+
var askBox=document.getElementById('pending-decisions');
|
|
377
|
+
if(askBox){
|
|
378
|
+
var askToken=askBox.getAttribute('data-ask-token')||'';
|
|
379
|
+
var askBody=document.getElementById('pending-decisions-body');
|
|
380
|
+
var askPill=document.getElementById('pending-pill');
|
|
381
|
+
var pendingKpi=document.querySelector('.kpi-card[data-key="pending"]');
|
|
382
|
+
function syncCount(n){
|
|
383
|
+
if(askPill){askPill.textContent=n+' 件';askPill.classList.toggle('is-amber',n>0);}
|
|
384
|
+
if(pendingKpi){
|
|
385
|
+
var num=pendingKpi.querySelector('.kpi-num');
|
|
386
|
+
if(num)num.innerHTML=String(n)+'<span class="kpi-unit">件</span>';
|
|
387
|
+
var sub=pendingKpi.querySelector('.kpi-sub');
|
|
388
|
+
if(sub)sub.textContent=n>0?'需要你拍板 · 实时更新':'暂无待定 · 实时更新';
|
|
389
|
+
pendingKpi.classList.toggle('is-empty-kpi',n===0);
|
|
390
|
+
pendingKpi.classList.toggle('is-amber',n>0);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
function submitAsk(card,choice,note){
|
|
394
|
+
if(!choice)return;
|
|
395
|
+
var id=card.getAttribute('data-ask-id')||'';
|
|
396
|
+
var item=card.getAttribute('data-ask-item')||'';
|
|
397
|
+
var after=card.querySelector('.ask-after');
|
|
398
|
+
var btns=[].slice.call(card.querySelectorAll('button,input'));
|
|
399
|
+
btns.forEach(function(b){b.disabled=true;});
|
|
400
|
+
fetch('/api/asks/answer',{
|
|
401
|
+
method:'POST',
|
|
402
|
+
headers:{'Content-Type':'application/json','X-Wrj-Token':askToken},
|
|
403
|
+
body:JSON.stringify({id:id,item:item,choice:choice,note:note||''})
|
|
404
|
+
}).then(function(r){return r.json().then(function(d){return {ok:r.ok,d:d};});}).then(function(res){
|
|
405
|
+
if(!res.ok){
|
|
406
|
+
btns.forEach(function(b){b.disabled=false;});
|
|
407
|
+
if(after){after.hidden=false;after.className='ask-after is-err';after.textContent=(res.d&&res.d.error)||'提交失败';}
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
card.classList.add('is-done');
|
|
411
|
+
if(after){after.hidden=false;after.className='ask-after';after.textContent=res.d.message||'已记下,已交给路由处理。';}
|
|
412
|
+
setTimeout(pollAsks,1200);
|
|
413
|
+
}).catch(function(e){
|
|
414
|
+
btns.forEach(function(b){b.disabled=false;});
|
|
415
|
+
if(after){after.hidden=false;after.className='ask-after is-err';after.textContent='网络错误:'+(e&&e.message||e);}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
askBox.addEventListener('click',function(ev){
|
|
419
|
+
var btn=ev.target.closest('button.ask-opt[data-choice]');
|
|
420
|
+
if(!btn)return;
|
|
421
|
+
var card=btn.closest('.ask-card');
|
|
422
|
+
if(!card||card.classList.contains('is-done'))return;
|
|
423
|
+
btn.classList.add('is-picked');
|
|
424
|
+
var inp=card.querySelector('input[name="note"]');
|
|
425
|
+
submitAsk(card,btn.getAttribute('data-choice'),inp?inp.value.trim():'');
|
|
426
|
+
});
|
|
427
|
+
askBox.addEventListener('submit',function(ev){
|
|
428
|
+
var form=ev.target.closest('form.ask-form');
|
|
429
|
+
if(!form)return;
|
|
430
|
+
ev.preventDefault();
|
|
431
|
+
var card=form.closest('.ask-card');
|
|
432
|
+
if(!card||card.classList.contains('is-done'))return;
|
|
433
|
+
var inp=form.querySelector('input[name="note"]');
|
|
434
|
+
var val=inp?inp.value.trim():'';
|
|
435
|
+
if(!val)return;
|
|
436
|
+
submitAsk(card,val,'');
|
|
437
|
+
});
|
|
438
|
+
function pollAsks(){
|
|
439
|
+
if(askBox.getAttribute('data-ask-live')!=='1')return;
|
|
440
|
+
if(document.visibilityState==='hidden')return;
|
|
441
|
+
var active=document.activeElement;
|
|
442
|
+
if(active&&askBox.contains(active)&&active.tagName==='INPUT'&&active.value.trim())return;
|
|
443
|
+
fetch('/asks.html',{cache:'no-store'}).then(function(r){return r.ok?r.text():'';}).then(function(html){
|
|
444
|
+
if(!html||!askBody)return;
|
|
445
|
+
var tmp=document.createElement('div');tmp.innerHTML=html;
|
|
446
|
+
var next=tmp.firstElementChild;
|
|
447
|
+
var cur=askBody.firstElementChild;
|
|
448
|
+
if(!next)return;
|
|
449
|
+
var n=Number(next.getAttribute('data-ask-count')||'0');
|
|
450
|
+
if(!cur||cur.getAttribute('data-ask-sig')!==next.getAttribute('data-ask-sig')){
|
|
451
|
+
askBody.innerHTML=html;
|
|
452
|
+
}
|
|
453
|
+
syncCount(n);
|
|
454
|
+
}).catch(function(){});
|
|
455
|
+
}
|
|
456
|
+
if(askBox.getAttribute('data-ask-live')==='1')setInterval(pollAsks,5000);
|
|
457
|
+
}
|
|
458
|
+
})();
|
|
459
|
+
/* 数字卡片:点一张切换明细、展开全部、事件流按类型筛选、hash 记忆。没有每日文件时页面上没有它们,这一段什么都不做 */
|
|
460
|
+
(function(){
|
|
461
|
+
var cards=[].slice.call(document.querySelectorAll('.kpi-card[data-key]'));
|
|
462
|
+
var panels=[].slice.call(document.querySelectorAll('.day-panel[data-panel]'));
|
|
463
|
+
var box=document.querySelector('.day-panels');
|
|
464
|
+
var toggle=document.querySelector('[data-toggle-all]');
|
|
465
|
+
if(!cards.length||!box)return;
|
|
466
|
+
function select(key,pushHash){
|
|
467
|
+
box.classList.remove('show-all');
|
|
468
|
+
if(toggle){toggle.classList.remove('is-active');toggle.textContent='展开全部';toggle.setAttribute('aria-pressed','false');}
|
|
469
|
+
cards.forEach(function(c){
|
|
470
|
+
var on=c.getAttribute('data-key')===key;
|
|
471
|
+
c.classList.toggle('is-selected',on);
|
|
472
|
+
c.setAttribute('aria-pressed',on?'true':'false');
|
|
473
|
+
});
|
|
474
|
+
panels.forEach(function(p){
|
|
475
|
+
p.classList.toggle('is-open',p.getAttribute('data-panel')===key);
|
|
476
|
+
});
|
|
477
|
+
if(pushHash&&history.replaceState)history.replaceState(null,'','#'+key);
|
|
478
|
+
}
|
|
479
|
+
function showAll(pushHash){
|
|
480
|
+
box.classList.add('show-all');
|
|
481
|
+
if(toggle){toggle.classList.add('is-active');toggle.textContent='单卡视图';toggle.setAttribute('aria-pressed','true');}
|
|
482
|
+
cards.forEach(function(c){c.classList.remove('is-selected');c.setAttribute('aria-pressed','false');});
|
|
483
|
+
if(pushHash&&history.replaceState)history.replaceState(null,'','#all');
|
|
484
|
+
}
|
|
485
|
+
cards.forEach(function(c){c.addEventListener('click',function(){select(c.getAttribute('data-key'),true);});});
|
|
486
|
+
if(toggle)toggle.addEventListener('click',function(){
|
|
487
|
+
if(box.classList.contains('show-all'))select(cards[0].getAttribute('data-key'),true);
|
|
488
|
+
else showAll(true);
|
|
489
|
+
});
|
|
490
|
+
[].slice.call(document.querySelectorAll('[data-jump]')).forEach(function(btn){
|
|
491
|
+
btn.addEventListener('click',function(){
|
|
492
|
+
var k=btn.getAttribute('data-jump');
|
|
493
|
+
if(cards.some(function(c){return c.getAttribute('data-key')===k;}))select(k,true);
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
[].slice.call(document.querySelectorAll('.filter-pill[data-filter]')).forEach(function(btn){
|
|
497
|
+
btn.addEventListener('click',function(){
|
|
498
|
+
var type=btn.getAttribute('data-filter');
|
|
499
|
+
var bar=btn.closest('.filter-bar');
|
|
500
|
+
var card=btn.closest('.card');
|
|
501
|
+
if(!bar||!card)return;
|
|
502
|
+
[].slice.call(bar.querySelectorAll('.filter-pill')).forEach(function(b){b.classList.toggle('is-active',b===btn);});
|
|
503
|
+
[].slice.call(card.querySelectorAll('.tl-row')).forEach(function(r){
|
|
504
|
+
r.classList.toggle('is-hidden',type!=='all'&&r.getAttribute('data-type')!==type);
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
var hash=(location.hash||'').replace(/^#/,'');
|
|
509
|
+
if(hash==='all')showAll(false);
|
|
510
|
+
else if(hash==='pending-decisions'&&cards.some(function(c){return c.getAttribute('data-key')==='pending';}))select('pending',false);
|
|
511
|
+
else if(hash&&cards.some(function(c){return c.getAttribute('data-key')===hash;}))select(hash,false);
|
|
512
|
+
})();
|
|
513
|
+
</script>`;
|
|
514
|
+
|
|
515
|
+
function renderKpiCard(item, selected) {
|
|
516
|
+
const cls = ['kpi-card', item.tone || '', item.empty ? 'is-empty-kpi' : '', selected ? 'is-selected' : ''].filter(Boolean).join(' ');
|
|
517
|
+
const dot = item.dot ? `<span class="dot ${item.dot}"></span>` : '';
|
|
518
|
+
const unit = item.unit ? `<span class="kpi-unit">${esc(item.unit)}</span>` : '';
|
|
519
|
+
return `<button type="button" class="${cls}" data-key="${esc(item.key)}" aria-pressed="${selected ? 'true' : 'false'}">
|
|
520
|
+
<div class="kpi-top"><span class="kpi-label">${dot}${esc(item.label)}</span><span class="kpi-arrow">明细 ↗</span></div>
|
|
521
|
+
<div class="kpi-num">${esc(item.num)}${unit}</div>
|
|
522
|
+
<div class="kpi-sub">${esc(item.sub)}</div>
|
|
523
|
+
</button>`;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function renderDaily({ date, weekday, isToday, markdown, dates = [], asks = null, token = '' }) {
|
|
527
|
+
const [year, month, day] = String(date || '').split('-');
|
|
528
|
+
const humanDate = month && day ? `${Number(month)} 月 ${Number(day)} 日` : date;
|
|
529
|
+
// dates 按新到旧排序:prev 是更早的一天(下标 +1),next 是更新的一天(下标 -1)
|
|
530
|
+
const idx = dates.indexOf(date);
|
|
531
|
+
const prevDate = idx >= 0 ? dates[idx + 1] : dates.find((d) => d < date);
|
|
532
|
+
const nextDate = idx > 0 ? dates[idx - 1] : [...dates].reverse().find((d) => d > date);
|
|
533
|
+
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>`;
|
|
534
|
+
const stripDates = dates.slice(0, 14);
|
|
535
|
+
const strip = stripDates.length
|
|
536
|
+
? `<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>`
|
|
537
|
+
: '<div class="day-strip"><span class="muted">还没有其他日期的文件</span></div>';
|
|
538
|
+
|
|
539
|
+
const hasLiveAsks = Array.isArray(asks);
|
|
540
|
+
if (!markdown) {
|
|
541
|
+
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>`;
|
|
542
|
+
const empty = '<section class="card"><p class="muted">今天还没有每日文件。等定时任务跑完,或对 AI 说「做今天的计划」后,这里就会更新。</p></section>';
|
|
543
|
+
const liveCard = hasLiveAsks ? `\n${renderPendingCard(asks, { token, live: Boolean(isToday) }).html}\n${DAY_SCRIPT}` : '';
|
|
544
|
+
return `${hero}\n${empty}${liveCard}`;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const doc = splitSections(markdown);
|
|
548
|
+
const byTitle = new Map(doc.sections.map((s) => [s.title, s]));
|
|
549
|
+
const items = [];
|
|
550
|
+
|
|
551
|
+
// 1. 计划 & 待你定(今日页的「待你定」是实时卡片,不再读每日文件里的旧文字列表)
|
|
552
|
+
const planSec = byTitle.get('计划');
|
|
553
|
+
let pendingItem = null;
|
|
554
|
+
const pendingCount = hasLiveAsks ? asks.length : 0;
|
|
555
|
+
if (hasLiveAsks) {
|
|
556
|
+
const p = renderPendingCard(asks, { token, live: Boolean(isToday) });
|
|
557
|
+
pendingItem = {
|
|
558
|
+
key: 'pending',
|
|
559
|
+
label: '待你定',
|
|
560
|
+
num: p.count,
|
|
561
|
+
unit: '件',
|
|
562
|
+
sub: p.count ? '需要你拍板 · 实时更新' : '暂无待定 · 实时更新',
|
|
563
|
+
dot: 'is-amber',
|
|
564
|
+
tone: p.count ? 'is-amber' : '',
|
|
565
|
+
empty: p.count === 0,
|
|
566
|
+
html: p.html,
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
if (planSec) {
|
|
570
|
+
const allBlocks = planSec.body ? parseLabeledBlocks(planSec.body) : [];
|
|
571
|
+
const restBlocks = allBlocks.filter((b) => !(b.kind === 'kv' && b.label === '待你定'));
|
|
572
|
+
const focusBlock = restBlocks.find((b) => b.kind === 'kv' && b.label === '今日重点');
|
|
573
|
+
let focusCount = 0;
|
|
574
|
+
if (focusBlock) {
|
|
575
|
+
const sub = parseSubItems(focusBlock.childText);
|
|
576
|
+
focusCount = sub.items.length || (focusBlock.head ? 1 : 0);
|
|
577
|
+
}
|
|
578
|
+
const num = focusCount || restBlocks.length;
|
|
579
|
+
items.push({
|
|
580
|
+
key: 'plan',
|
|
581
|
+
label: focusCount ? '今日重点' : '计划',
|
|
582
|
+
num,
|
|
583
|
+
unit: focusCount ? '项' : (num ? '块' : ''),
|
|
584
|
+
sub: restBlocks.length ? summarizePlan(restBlocks) : '暂未制定计划',
|
|
585
|
+
dot: 'is-accent',
|
|
586
|
+
tone: '',
|
|
587
|
+
empty: !restBlocks.length,
|
|
588
|
+
html: renderPlanBlocks(planSec.title, restBlocks, pendingCount),
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
if (pendingItem) items.push(pendingItem);
|
|
592
|
+
|
|
593
|
+
// 2. 进展 & 复盘(进展为空且复盘有内容时,把进展空态收进复盘明细底部,保持顶部数字卡紧凑)
|
|
594
|
+
const progSec = byTitle.get('进展');
|
|
595
|
+
const revSec = byTitle.get('复盘');
|
|
596
|
+
const progHas = Boolean(progSec && progSec.body);
|
|
597
|
+
const revHas = Boolean(revSec && revSec.body);
|
|
598
|
+
if (progSec && (progHas || !revHas)) {
|
|
599
|
+
const blocks = progHas ? parseLabeledBlocks(progSec.body) : [];
|
|
600
|
+
items.push({
|
|
601
|
+
key: 'progress',
|
|
602
|
+
label: '进展',
|
|
603
|
+
num: blocks.length,
|
|
604
|
+
unit: blocks.length ? '项' : '',
|
|
605
|
+
sub: progHas ? '午间进展更新' : '暂未记录',
|
|
606
|
+
dot: progHas ? 'is-green' : '',
|
|
607
|
+
tone: '',
|
|
608
|
+
empty: !progHas,
|
|
609
|
+
html: renderKvSection(progSec),
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
if (revSec) {
|
|
613
|
+
const blocks = revHas ? parseLabeledBlocks(revSec.body) : [];
|
|
614
|
+
const foldedProg = progSec && !progHas && revHas ? `\n${emptyCard(progSec.title)}` : '';
|
|
615
|
+
items.push({
|
|
616
|
+
key: 'review',
|
|
617
|
+
label: '复盘',
|
|
618
|
+
num: blocks.length,
|
|
619
|
+
unit: blocks.length ? '项' : '',
|
|
620
|
+
sub: summarizeReview(blocks),
|
|
621
|
+
dot: revHas ? 'is-green' : '',
|
|
622
|
+
tone: '',
|
|
623
|
+
empty: !revHas,
|
|
624
|
+
html: `${renderKvSection(revSec)}${foldedProg}`,
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// 3. 事件流
|
|
629
|
+
const evSec = byTitle.get('事件流');
|
|
630
|
+
if (evSec) {
|
|
631
|
+
const ev = renderEventsSection(evSec);
|
|
632
|
+
items.push({
|
|
633
|
+
key: 'events',
|
|
634
|
+
label: '事件流',
|
|
635
|
+
num: ev.count,
|
|
636
|
+
unit: '条',
|
|
637
|
+
sub: ev.sub,
|
|
638
|
+
dot: ev.count ? 'is-accent' : '',
|
|
639
|
+
tone: '',
|
|
640
|
+
empty: ev.count === 0,
|
|
641
|
+
html: ev.html,
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// 4. 备注
|
|
646
|
+
const noteSec = byTitle.get('备注');
|
|
647
|
+
if (noteSec) {
|
|
648
|
+
const nt = renderNotesSection(noteSec);
|
|
649
|
+
items.push({
|
|
650
|
+
key: 'notes',
|
|
651
|
+
label: '备注',
|
|
652
|
+
num: nt.count,
|
|
653
|
+
unit: '条',
|
|
654
|
+
sub: nt.sub,
|
|
655
|
+
dot: nt.hasAlert ? 'is-rose' : '',
|
|
656
|
+
tone: nt.hasAlert ? 'is-rose' : '',
|
|
657
|
+
empty: nt.count === 0,
|
|
658
|
+
html: nt.html,
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// 5. 其余自定义小节
|
|
663
|
+
const known = new Set(['计划', '进展', '复盘', '事件流', '备注']);
|
|
664
|
+
let extraIdx = 0;
|
|
665
|
+
for (const sec of doc.sections) {
|
|
666
|
+
if (known.has(sec.title)) continue;
|
|
667
|
+
extraIdx += 1;
|
|
668
|
+
const html = sec.body
|
|
669
|
+
? `<section class="card"><div class="card-head"><h2>${esc(sec.title)}</h2></div>${md.render(sec.body, MD_OPTS)}</section>`
|
|
670
|
+
: emptyCard(sec.title);
|
|
671
|
+
items.push({
|
|
672
|
+
key: `extra-${extraIdx}`,
|
|
673
|
+
label: sec.title,
|
|
674
|
+
num: sec.body ? sec.body.split('\n').filter((l) => l.trim()).length : 0,
|
|
675
|
+
unit: '行',
|
|
676
|
+
sub: sec.body ? '自定义小节' : '暂未记录',
|
|
677
|
+
dot: '',
|
|
678
|
+
tone: '',
|
|
679
|
+
empty: !sec.body,
|
|
680
|
+
html,
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const firstActive = (items.find((it) => !it.empty) || items[0] || {}).key || '';
|
|
685
|
+
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>`;
|
|
686
|
+
const introHtml = doc.intro ? `<section class="card">${md.render(doc.intro, MD_OPTS)}</section>` : '';
|
|
687
|
+
const kpiGrid = items.length
|
|
688
|
+
? `<section class="kpi-grid" aria-label="今日概览卡片">${items.map((it) => renderKpiCard(it, it.key === firstActive)).join('\n')}</section>`
|
|
689
|
+
: '';
|
|
690
|
+
const panelsHtml = items.length
|
|
691
|
+
? `<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>`
|
|
692
|
+
: '';
|
|
693
|
+
|
|
694
|
+
return `${hero}\n${introHtml}\n${kpiGrid}\n${panelsHtml}\n${DAY_SCRIPT}`;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// 所有页面同一张页头:左边标题,右边是说明和操作(meta 是调用方自己拼的 HTML,不转义)
|
|
698
|
+
function pageHead(title, { subtitle = '', meta = '' } = {}) {
|
|
699
|
+
const side = [subtitle ? `<span class="muted">${esc(subtitle)}</span>` : '', meta].filter(Boolean).join('');
|
|
700
|
+
return `<header class="page-head"><h1>${esc(title)}</h1>${side ? `<div class="page-head-meta">${side}</div>` : ''}</header>`;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// 一份 Markdown 文档的页面:页头 + 每个「## 」小节一张卡片(第一个「# 」标题当页头的标题)
|
|
704
|
+
function renderDocPage(title, markdown, { subtitle = '', meta = '', empty = '还没有内容。' } = {}) {
|
|
705
|
+
const doc = splitSections(String(markdown || ''));
|
|
706
|
+
const head = pageHead(doc.title || title, { subtitle, meta });
|
|
707
|
+
if (!String(markdown || '').trim()) {
|
|
708
|
+
return `${head}\n<section class="card"><p class="muted">${esc(empty)}</p></section>`;
|
|
709
|
+
}
|
|
710
|
+
const parts = [head];
|
|
711
|
+
if (doc.intro) parts.push(`<section class="card">${md.render(doc.intro, MD_OPTS)}</section>`);
|
|
712
|
+
for (const sec of doc.sections) {
|
|
713
|
+
parts.push(sec.body
|
|
714
|
+
? `<section class="card"><div class="card-head"><h2>${esc(sec.title)}</h2></div>${md.render(sec.body, MD_OPTS)}</section>`
|
|
715
|
+
: emptyCard(sec.title));
|
|
716
|
+
}
|
|
717
|
+
if (!doc.intro && !doc.sections.length) {
|
|
718
|
+
parts.push(`<section class="card">${md.render(markdown, MD_OPTS)}</section>`);
|
|
719
|
+
}
|
|
720
|
+
return parts.join('\n');
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
function renderGoals(items) {
|
|
724
|
+
const head = pageHead('目标', { subtitle: `${items.length} 份长期目标` });
|
|
725
|
+
if (!items.length) return `${head}\n<section class="card"><p class="muted">还没有长期目标。</p></section>`;
|
|
726
|
+
return `${head}\n${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')}`;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function renderReports(files) {
|
|
730
|
+
const head = pageHead('报告', { subtitle: `${files.length} 份` });
|
|
731
|
+
if (!files.length) return `${head}\n<section class="card"><p class="muted">还没有生成的报告。</p></section>`;
|
|
732
|
+
const list = files.map((f) => `<a class="report-item" href="/reports/${esc(f)}"><span>${esc(f)}</span><span class="muted">打开 →</span></a>`).join('\n');
|
|
733
|
+
return `${head}\n<section class="card"><div class="report-list">${list}</div></section>`;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
module.exports = { rewriteWorkspaceHref, renderDaily, renderAsksFragment, pageHead, renderDocPage, renderGoals, renderReports, MD_OPTS };
|