pi-evals 0.1.0 → 0.2.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ - The report opens on two architecture changes, with a workload chart and a comparison you can open for every entry in the timeline. Each comparison shows what was counted and what limits the conclusion.
6
+ - Five short explanations and two self-check questions introduce the numbers in the report; see [the worked example](docs/learn.zh-TW.md).
7
+ - `/evals extract` uses two workers by default to leave memory for pi. Pass `--workers N` to override; the standalone CLI retains its CPU-based default.
8
+ - Use npm’s canonical bin path so the packed CLI installs as `pi-evals` without a publish correction.
9
+
3
10
  ## 0.1.0
4
11
 
5
12
  First release.
package/README.md CHANGED
@@ -39,11 +39,12 @@ The observer loads in every session, subagents included.
39
39
  | Command | What it does |
40
40
  | --- | --- |
41
41
  | `/evals` or `/evals status` | Record counts, the last extract, index coverage of old sessions, and the report path. |
42
- | `/evals extract` | Back-fills past sessions in a background process; progress shows in the footer. Only files whose size or modification time changed are read again. |
42
+ | `/evals extract [--workers N]` | Back-fills changed sessions in a background process, with two workers by default to leave memory for pi. Progress shows in the footer. |
43
43
  | `/evals report [--since YYYY-MM-DD] [--project <key>]` | Builds the report and prints its path. |
44
44
  | `/evals mark <note>` | Adds a note to the change timeline, e.g. `/evals mark workers moved to gpt-6.2-astra`. |
45
45
 
46
- The same operations run from a shell:
46
+ The same operations run from a shell, where extraction defaults to one fewer worker than available CPUs (at least one, at most eight).
47
+ On either surface, `--workers 0` reads the files sequentially without worker threads:
47
48
 
48
49
  ```sh
49
50
  pi-evals extract [--root <dir>]... [--workers <n>] [--json]
@@ -64,7 +65,16 @@ The tool never starts an extract.
64
65
  One HTML file with no scripts, no network requests and no external assets; charts are inline SVG, and it follows the system's light or dark setting.
65
66
  It is written as `report.html` next to `model.json`, the ReportModel it is rendered from.
66
67
  Every number in the model carries a plain-language label, what it means, which direction is better, and how it is computed, in English and Traditional Chinese.
67
- The renderer reads only the model, so a redesigned report can replace it without touching the data.
68
+ ### Reading the report
69
+
70
+ Start with the sentence above the timeline: it says what changed in the numbers; the next line tells you what limits the comparison.
71
+ Open a card to see which sessions started before and after the change.
72
+ Read the count beside each rate: a check that applies to 48 sessions can say nothing about the other 116 sessions in a group of 164.
73
+ If the window is short, or other changes landed in the same period, do not credit a difference to the new version alone.
74
+
75
+ The sidebar shows workload for the last seven complete UTC dates, with markers on days you changed the setup.
76
+ The date disclosures keep the rest of the timeline available without putting hundreds of cards on the first screen.
77
+ Use the section links for usage, process checks, cost and cleanup coverage, or read the [five concepts with a worked example](docs/learn.zh-TW.md).
68
78
 
69
79
  ## Settings
70
80
 
package/dist/index.js CHANGED
@@ -48,14 +48,14 @@ export function createEvals(options = {}) {
48
48
  catch { }
49
49
  });
50
50
  let running;
51
- const extractInChild = (ctx) => {
51
+ const extractInChild = (ctx, workers) => {
52
52
  const cli = cliPath();
53
53
  if (!cli) {
54
54
  ctx.ui.notify("pi-evals: cannot find its CLI (dist/cli.js); run npm run build in the package.", "error");
55
55
  return Promise.resolve();
56
56
  }
57
57
  return new Promise((resolve) => {
58
- const child = spawnFn(cli.cmd, [...cli.args, "extract", "--json"], { env: { ...process.env, ...env }, stdio: ["ignore", "pipe", "pipe"] });
58
+ const child = spawnFn(cli.cmd, [...cli.args, "extract", "--json", "--workers", String(workers)], { env: { ...process.env, ...env }, stdio: ["ignore", "pipe", "pipe"] });
59
59
  let buffer = "";
60
60
  let last = "";
61
61
  let errText = "";
@@ -111,8 +111,13 @@ export function createEvals(options = {}) {
111
111
  ctx.ui.notify("pi-evals: an extract is already running.", "warning");
112
112
  return;
113
113
  }
114
+ const workers = words.length === 1 ? 2 : words.length === 3 && words[1] === "--workers" && /^\d+$/.test(words[2]) ? Number(words[2]) : NaN;
115
+ if (!Number.isSafeInteger(workers)) {
116
+ ctx.ui.notify("Usage: /evals extract [--workers <non-negative integer>]", "warning");
117
+ return;
118
+ }
114
119
  ctx.ui.notify("pi-evals: extract started in the background; progress shows in the footer.", "info");
115
- running = extractInChild(ctx).finally(() => {
120
+ running = extractInChild(ctx, workers).finally(() => {
116
121
  running = undefined;
117
122
  });
118
123
  }
package/dist/render.js CHANGED
@@ -1,172 +1,31 @@
1
- const esc = (v) => String(v ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
2
- const pct = (r) => (r && r.value !== null ? `${(r.value * 100).toFixed(1)}%` : "—");
3
- const nOf = (r) => (r ? r.n : 0);
4
- const ms = (v) => {
5
- if (v === null || v === undefined)
6
- return "—";
7
- if (v < 1000)
8
- return `${v} ms`;
9
- if (v < 60_000)
10
- return `${(v / 1000).toFixed(1)} s`;
11
- if (v < 3_600_000)
12
- return `${(v / 60_000).toFixed(1)} min`;
13
- return `${(v / 3_600_000).toFixed(1)} h`;
14
- };
15
- const usd = (v) => (v === null || v === undefined ? "—" : `$${v.toFixed(2)}`);
16
- const num = (v) => v.toLocaleString("en-US");
17
- function bars(rows, width = 560) {
18
- if (!rows.length)
19
- return `<p class="empty">—</p>`;
20
- const max = Math.max(...rows.map((r) => r.value), 1);
21
- const h = 18;
22
- const labelW = 220;
23
- const body = rows
24
- .map((r, i) => {
25
- const w = Math.max(1, Math.round(((width - labelW - 90) * r.value) / max));
26
- const y = i * (h + 4);
27
- return `<text x="0" y="${y + 13}" class="lbl">${esc(r.label.length > 34 ? `${r.label.slice(0, 33)}…` : r.label)}</text><rect x="${labelW}" y="${y}" width="${w}" height="${h}" class="bar"/><text x="${labelW + w + 6}" y="${y + 13}" class="val">${esc(r.note ?? num(r.value))}</text>`;
28
- })
29
- .join("");
30
- return `<svg role="img" width="${width}" height="${rows.length * (h + 4)}" viewBox="0 0 ${width} ${rows.length * (h + 4)}">${body}</svg>`;
31
- }
32
- function columns(days, values, width = 720, height = 120) {
33
- if (!days.length)
34
- return `<p class="empty">—</p>`;
35
- const max = Math.max(...values, 1);
36
- const w = Math.max(2, Math.floor(width / days.length) - 1);
37
- const body = values
38
- .map((v, i) => {
39
- const bh = Math.round(((height - 16) * v) / max);
40
- return `<rect x="${i * (w + 1)}" y="${height - 14 - bh}" width="${w}" height="${bh}" class="bar"><title>${esc(days[i])}: ${esc(num(v))}</title></rect>`;
41
- })
42
- .join("");
43
- const axis = `<text x="0" y="${height - 2}" class="val">${esc(days[0])}</text><text x="${width}" y="${height - 2}" class="val" text-anchor="end">${esc(days.at(-1))}</text>`;
44
- return `<svg role="img" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">${body}${axis}</svg>`;
45
- }
46
- function table(head, rows) {
47
- if (!rows.length)
48
- return `<p class="empty">—</p>`;
49
- return `<table><thead><tr>${head.map((h) => `<th>${esc(h)}</th>`).join("")}</tr></thead><tbody>${rows.map((r) => `<tr>${r.map((c) => `<td>${typeof c === "number" ? esc(num(c)) : c}</td>`).join("")}</tr>`).join("")}</tbody></table>`;
50
- }
51
- export function renderHtml(model, lang = "zh") {
52
- const tx = (t) => esc(t ? t[lang] : "");
53
- const m = model.meta.metrics;
54
- const explain = (id) => {
55
- const meta = m[id];
56
- if (!meta)
57
- return "";
58
- const dir = meta.goodDirection === "higher" ? (lang === "zh" ? "越高越好" : "higher is better") : meta.goodDirection === "lower" ? (lang === "zh" ? "越低越好" : "lower is better") : "";
59
- return `<p class="meaning"><b>${tx(meta.label)}</b>: ${tx(meta.meaning)}${dir ? ` <span class="dir">(${dir})</span>` : ""}<br><span class="how">${tx(meta.howComputed)}</span></p>`;
60
- };
61
- const L = (en, zh) => (lang === "zh" ? zh : en);
62
- const sections = [];
63
- const fresh = model.freshness;
64
- sections.push(`<section><h2>${L("Overview", "總覽")}</h2>
65
- <p>${L("Window", "期間")}: ${esc(model.window.since ?? "—")} → ${esc(model.window.until ?? "—")} (${model.window.days} ${L("days", "天")})${model.window.project ? ` · ${L("project", "專案")} ${esc(model.window.project)}` : ""}</p>
66
- <p class="${fresh.stale ? "warn" : ""}">${L("Last extract", "上次抽取")}: ${esc(fresh.lastExtract ?? "—")}${fresh.stale ? ` — ${L("data is stale; run /evals extract", "資料過時,請執行 /evals extract")}` : ""}</p>
67
- ${table([L("Number", "數字"), L("Value", "數值")], [
68
- [tx(m.sessions.label), model.totals.sessions],
69
- [tx(m.subagent_sessions.label), model.totals.subagentSessions],
70
- [tx(m.prompts.label), model.totals.prompts],
71
- [tx(m.tool_calls.label), model.totals.toolCalls],
72
- [tx(m.tool_error_rate.label), `${pct(model.totals.toolErrorRate)} (n=${num(nOf(model.totals.toolErrorRate))})`],
73
- [tx(m.cost.label), usd(model.totals.cost)],
74
- ])}
75
- ${explain("sessions")}
76
- <h3>${L("Sessions per day", "每日工作階段")}</h3>${columns(model.series.days, model.series.sessions)}
77
- <h3>${L("Cost per day (USD)", "每日費用(美元)")}</h3>${columns(model.series.days, model.series.cost)}</section>`);
78
- const sk = model.skills;
79
- sections.push(`<section><h2>${L("Skills", "技能")}</h2>${explain("skill_loads")}
80
- <h3>${L("Loads per day", "每日載入")}</h3>${columns(model.series.days, model.series.skillLoads)}
81
- <h3>${L("Most loaded", "最常載入")}</h3>${bars(sk.top.slice(0, 25).map((s) => ({ label: s.name, value: s.loads, note: `${num(s.loads)} · ${num(s.sessions)} ${L("sessions", "階段")}` })))}
82
- ${explain("skill_sessions")}
83
- <h3>${L("How skills were loaded", "載入方式")}</h3>${table([L("Way", "方式"), L("Loads", "次數")], Object.entries(sk.triggers).map(([k, v]) => [esc(k), v]))}
84
- <h3>${L("By project (top 30)", "各專案(前 30)")}</h3>${table([L("Project", "專案"), L("Skill", "技能"), L("Loads", "次數")], sk.byProject.slice(0, 30).map((r) => [esc(r.project), esc(r.skill), r.loads]))}
85
- <h3>${tx(m.never_loaded.label)} (${sk.neverLoaded.length} / ${sk.offered})</h3>${explain("never_loaded")}<p>${sk.neverLoaded.map(esc).join(", ") || "—"}</p></section>`);
86
- sections.push(`<section><h2>${L("Packages", "套件")}</h2>${explain("package_calls")}${explain("tool_error_rate")}${explain("avg_duration_ms")}
87
- ${table([L("Package", "套件"), L("Version", "版本"), L("Calls", "呼叫"), L("Errors", "錯誤"), tx(m.tool_error_rate.label), tx(m.avg_duration_ms.label)], model.packages.map((p) => [esc(p.owner), esc(p.version ?? "—"), p.calls, p.errors, pct(p.errorRate), ms(p.avgMs)]))}
88
- <h3>${L("Tools (top 40)", "工具(前 40)")}</h3>${table([L("Tool", "工具"), L("Package", "套件"), L("Calls", "呼叫"), tx(m.tool_error_rate.label), tx(m.avg_duration_ms.label)], model.tools.slice(0, 40).map((t) => [esc(t.name), esc(t.owner), t.calls, pct(t.errorRate), ms(t.avgMs)]))}</section>`);
89
- const ask = model.askUser;
90
- const bucketLabel = (up, i, all) => (up === null ? `≥ ${ms(all[i - 1]?.upToMs ?? 0)}` : `< ${ms(up)}`);
91
- sections.push(`<section><h2>${L("Questions to you", "問你的問題")}</h2>${explain("ask_calls")}${explain("ask_wait_ms")}${explain("ask_cancel_rate")}
92
- ${table([L("Number", "數字"), L("Value", "數值")], [
93
- [tx(m.ask_calls.label), ask.calls],
94
- [tx(m.ask_wait_ms.label), `${ms(ask.avgWaitMs)} (n=${num(ask.waitN)})`],
95
- [tx(m.ask_cancel_rate.label), `${pct(ask.cancelRate)} (n=${num(nOf(ask.cancelRate))})`],
96
- ])}
97
- <h3>${L("How long you took", "你花多久回答")}</h3>${bars(ask.buckets.map((b, i) => ({ label: bucketLabel(b.upToMs, i, ask.buckets), value: b.n })))}
98
- <h3>${L("Where the answer came from", "回答來源")}</h3>${table([L("Source", "來源"), L("Questions", "題數")], Object.entries(ask.sources).map(([k, v]) => [esc(k), v]))}</section>`);
99
- const mon = model.monitors;
100
- sections.push(`<section><h2>${L("Background jobs", "背景工作")}</h2>${explain("monitor_outcomes")}${explain("monitor_duration_ms")}
101
- <p>${L("Started", "啟動")}: ${num(mon.started)} · ${L("Ending recorded", "有結束紀錄")}: ${num(mon.finished)} · ${tx(m.monitor_duration_ms.label)}: ${ms(mon.avgMs)} (n=${num(mon.durationN)})</p>
102
- ${bars(Object.entries(mon.statuses).map(([k, v]) => ({ label: k, value: v })))}</section>`);
103
- const sub = model.subagents;
104
- sections.push(`<section><h2>${L("Subagents", "子代理")}</h2>${explain("subagent_launches")}
105
- ${table([L("Role", "角色"), L("Model", "模型"), L("Launches", "次數")], sub.launches.slice(0, 40).map((r) => [esc(r.role), esc(r.model), r.n]))}
106
- ${explain("subagent_cost")}${bars(sub.costByRole.slice(0, 20).map((r) => ({ label: r.role, value: r.cost, note: usd(r.cost) })))}
107
- <p>${L("Subagent sessions linked to a parent", "能對回母工作階段的子代理")}: ${num(sub.linked)} / ${num(sub.subagentTotal)}</p></section>`);
108
- const proc = model.process;
109
- const dm = model.meta.detectors;
110
- sections.push(`<section><h2>${L("Process: does the work follow the anchorloop rules?", "流程:工作有沒有照 anchorloop 規則走?")}</h2>
111
- <p>${L(`Only sessions from ${proc.eraStart} (anchorloop 3.0.0) on are judged; older ones are out of scope, not failures.`, `只評 ${proc.eraStart}(anchorloop 3.0.0)之後的工作階段;更早的不在範圍內,不算失敗。`)}</p>${explain("pass_rate")}
112
- ${proc.detectors
113
- .map((d) => {
114
- const meta = dm[d.name];
115
- const daily = d.perDay.map((x) => (x.pass + x.fail ? Math.round((100 * x.pass) / (x.pass + x.fail)) : 0));
116
- return `<div class="detector"><h3>${tx(meta?.label)}: ${pct(d.passRate)} <small>(n=${num(nOf(d.passRate))}, ${L("not applicable", "不適用")} ${num(d.na)})</small></h3>
117
- <p>${tx(meta?.meaning)}<br><span class="how">${tx(meta?.howComputed)}</span></p>
118
- <p class="ex">✔ ${tx(meta?.example.pass)}<br>✘ ${tx(meta?.example.fail)}</p>
119
- <h4>${L("Share followed per day (%)", "每日遵守比例(%)")}</h4>${columns(model.series.days, daily, 720, 80)}
120
- ${table([L("anchorloop version", "anchorloop 版本"), L("Followed", "遵守"), L("Not followed", "未遵守"), tx(m.pass_rate.label)], d.byVersion.map((v) => [esc(v.version), v.pass, v.fail, pct(v.passRate)]))}</div>`;
121
- })
122
- .join("")}
123
- <h3>${L("Close-guard reminders", "收尾提醒")}</h3>${table([L("Kind", "種類"), L("Count", "次數")], Object.entries(proc.notices).map(([k, v]) => [tx(model.meta.notices[k]) || esc(k), v]))}</section>`);
124
- sections.push(`<section><h2>${L("Cost", "費用")}</h2>${explain("cost")}${explain("cost_per_session")}${explain("skill_cost")}
125
- <p>${tx(m.cost_per_session.label)}: ${model.cost.perSession.value === null ? "—" : usd(model.cost.perSession.value)} (n=${num(model.cost.perSession.n)})</p>
126
- <h3>${L("By skill loaded (top 25)", "依載入技能(前 25)")}</h3>${bars(model.cost.bySkill.map((r) => ({ label: r.skill, value: r.cost, note: `${usd(r.cost)} · ${num(r.sessions)}` })))}
127
- <h3>${L("Model replies by model", "各模型回覆數")}</h3>${table([L("Model", "模型"), L("Replies", "回覆")], model.cost.byModel.slice(0, 20).map((r) => [esc(r.model), r.replies]))}</section>`);
128
- const changes = model.changes.slice(-40).reverse();
129
- const imp = (c) => {
130
- if (!c.impact)
131
- return L("no data before this change", "變更前沒有資料");
132
- const i = c.impact;
133
- const row = (key, label) => {
134
- const b = i.before[key];
135
- const a = i.after[key];
136
- if (b === undefined || a === undefined)
137
- return "";
138
- const show = (x) => (typeof x === "number" ? num(x) : key === "cost_per_session" ? (x.value === null ? "—" : usd(x.value)) : key.endsWith("per_session") ? (x.value === null ? "—" : x.value.toFixed(2)) : pct(x));
139
- return `<tr><td>${esc(label)}</td><td>${show(b)}</td><td>${show(a)}</td></tr>`;
140
- };
141
- const kinds = Object.entries(i.confounders)
142
- .map(([k, v]) => `${tx(model.meta.changeKinds[k])} ${v}`)
143
- .join(", ");
144
- const flags = [
145
- i.smallSample ? `<span class="warn">${tx(m.small_sample.label)}</span>` : "",
146
- i.incomplete ? `<span class="warn">${tx(m.incomplete_window.label)} (${L("days with data", "有資料的天數")}: ${i.daysWithData.before} / ${i.daysWithData.after})</span>` : "",
147
- i.confounded ? `<span class="warn">${tx(m.confounded.label)}: ${i.confounded} (${esc(kinds)})</span>` : "",
148
- ]
149
- .filter(Boolean)
150
- .join(" · ");
151
- return `<table><thead><tr><th></th><th>${L("before", "之前")}</th><th>${L("after", "之後")}</th></tr></thead><tbody>${row("sessions", tx(m.sessions.label))}${row("tool_error_rate", tx(m.tool_error_rate.label))}${row("package_error_rate", L("This package's error rate", "此套件出錯比例"))}${row("ask_cancel_rate", tx(m.ask_cancel_rate.label))}${row("cost_per_session", tx(m.cost_per_session.label))}${row("skill_loads_per_session", tx(m.skill_loads_per_session.label))}${row("notices_per_session", tx(m.notices_per_session.label))}${row("anchor_before_first_edit", tx(dm.anchor_before_first_edit.label))}${row("check_after_last_edit", tx(dm.check_after_last_edit.label))}</tbody></table>${flags}`;
152
- };
153
- sections.push(`<section><h2>${L("Your changes and what followed", "你的變更與之後的變化")}</h2>${explain("impact")}${explain("small_sample")}${explain("incomplete_window")}${explain("confounded")}
154
- ${changes.map((c) => `<details><summary>${esc(c.at.slice(0, 10))} · ${tx(model.meta.changeKinds[c.kind])} · ${esc(c.package ? `${c.package} ${c.from ?? "∅"} → ${c.to ?? "∅"}` : c.subject)}${c.repo ? ` <small>${esc(c.repo)} ${esc(c.sha ?? "")}</small>` : ""}</summary><p>${esc(c.subject)}</p>${imp(c)}</details>`).join("") || `<p class="empty">—</p>`}</section>`);
155
- const lab = model.labels;
156
- sections.push(`<section><h2>${L("Your labels", "你的標記")}</h2>${explain("agreement")}
157
- ${lab.present ? table([L("Check", "檢查"), L("Labelled", "已標記"), L("Agree", "一致"), tx(m.agreement.label)], lab.agreement.map((a) => [tx(dm[a.detector]?.label) || esc(a.detector), a.n, a.agree, pct(a.rate)])) : `<p class="empty">${L("No labels yet. Labelling sessions comes in a later phase.", "還沒有標記。標記工作階段會在之後的階段加入。")}</p>`}</section>`);
158
- const cov = model.coverage;
159
- if (cov)
160
- sections.push(`<section><h2>${tx(m.coverage.label)}</h2>${explain("coverage")}
161
- <p>${L(`Inactive more than ${cov.cutDays} days`, `閒置超過 ${cov.cutDays} 天`)}: ${num(cov.old.files)} ${L("files", "個檔案")} (${(cov.old.bytes / 1e9).toFixed(2)} GB) · ${L("indexed", "已建索引")} ${num(cov.indexed.files)} · ${L("not indexed", "未建索引")} ${num(cov.notIndexed.files)} (${(cov.notIndexed.bytes / 1e9).toFixed(2)} GB)</p></section>`);
162
- return `<!doctype html><html lang="${lang === "zh" ? "zh-Hant-TW" : "en"}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>pi-evals report</title>
163
- <style>
164
- :root{color-scheme:light dark;--fg:#1d1d1f;--bg:#fff;--muted:#666;--bar:#4a7bd0;--line:#ddd;--warn:#b35c00}
165
- @media (prefers-color-scheme:dark){:root{--fg:#e6e6e6;--bg:#151515;--muted:#9a9a9a;--bar:#7aa2f7;--line:#333;--warn:#f0a050}}
166
- body{font:15px/1.55 system-ui,-apple-system,"PingFang TC","Noto Sans TC",sans-serif;color:var(--fg);background:var(--bg);max-width:980px;margin:2rem auto;padding:0 1rem}
167
- section{border-top:1px solid var(--line);padding:1rem 0}h1{font-size:1.6rem}h2{font-size:1.3rem}h3{font-size:1.05rem;margin-top:1.2rem}
168
- table{border-collapse:collapse;margin:.5rem 0}td,th{border-bottom:1px solid var(--line);padding:.25rem .6rem;text-align:left;vertical-align:top}
169
- .bar{fill:var(--bar)}.lbl,.val{fill:var(--fg);font-size:12px}.meaning{color:var(--fg)}.how,.dir,small{color:var(--muted)}.warn{color:var(--warn)}.empty{color:var(--muted)}
170
- .ex{color:var(--muted);font-size:.92em}details{margin:.3rem 0}summary{cursor:pointer}
171
- </style></head><body><h1>pi-evals</h1><p class="how">${L("Generated", "產生時間")} ${esc(model.generated)} · ${L("numbers only: no transcript text is stored or shown", "只有數字:不儲存也不顯示對話內容")}</p>${sections.join("\n")}</body></html>`;
1
+ import { concepts, lesson } from "./report/concepts.js";
2
+ import { esc, num, words } from "./report/format.js";
3
+ import { sections } from "./report/sections.js";
4
+ import { css } from "./report/style.js";
5
+ import { timeline } from "./report/timeline.js";
6
+ import { week, workload } from "./report/week.js";
7
+ export function renderHtml(m, lang = "zh") {
8
+ const L = words(lang), w = week(m), t = timeline(m, w, lang), c = concepts(m, w, t.lead, L);
9
+ const nav = [
10
+ ["archive", L("All changes", "所有調整")],
11
+ ["skills", L("Skills", "技能")],
12
+ ["packages", L("Tools", "套件與工具")],
13
+ ["ask", L("Questions", "提問")],
14
+ ["monitors", L("Jobs", "背景工作")],
15
+ ["subagents", L("Subagents", "子代理")],
16
+ ["process", L("Process checks", "流程檢查")],
17
+ ["cost", L("Cost", "費用")],
18
+ ["coverage", L("Cleanup", "清理門檻")],
19
+ ["labels", L("Labels", "你的標記")],
20
+ ["concepts", L("Concepts", "概念")],
21
+ ];
22
+ const date = m.generated.slice(0, 10);
23
+ return `<!doctype html><html lang="${lang === "zh" ? "zh-Hant-TW" : "en"}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>pi-evals · ${L("Change timeline", "調整時間軸")}</title><style>${css}</style></head><body><header><a href="#timeline" class="brand"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><rect width="30" height="30" rx="8" fill="#174e47"/><path d="M7 22V15M15 22V8M23 22V12" fill="none" stroke="white" stroke-width="3"/></svg>pi-evals<span>${L("Agent work, observed", "代理工作觀察")}</span></a><small>${esc(date)} ${L("report", "更新")} / ${L("All times UTC", "時間皆為 UTC")}</small></header>
24
+ <main id="timeline"><div class="hero"><p class="eyebrow">${L("Change journal / Newest first", "調整紀事 / 依更新時間排列")}</p><h1>${esc(t.headline)}</h1><p class="deck">${esc(t.trust)}</p>${m.freshness.stale
25
+ ? `<p class="stale">${L("Last extract", "上次抽取")}:${esc(m.freshness.lastExtract ?? "—")} · ${L("Refresh with /evals extract.", "資料過時,請執行 /evals extract。")}</p>`
26
+ : ""}</div>
27
+ <div class="spine"><h2>${L(`${t.count} changes worth a closer look`, `${t.count === 2 ? "兩" : t.count === 1 ? "一" : "零"}筆值得回看的調整`)}</h2><div class="layout"><div class="rail">${t.cards || `<p>${L("Nothing to highlight yet.", "還沒有適合比較的調整。")}</p>`}</div><aside class="side">${workload(w, L)}${lesson(c.record, L)}${lesson(c.metric, L)}</aside></div><details><summary>${L("How to read the comparisons", "怎麼讀時間軸上的比較?")}</summary><div class="notes-grid">${lesson(c.sample, L)}${lesson(c.confounding, L)}${lesson(c.check, L)}</div></details></div>
28
+ <nav class="jump" aria-label="${L("Report sections", "報表章節")}">${nav.map(([id, text]) => `<a href="#${id}">${text}</a>`).join("")}</nav><section class="topic" id="archive"><h2>${L("Other changes by day", "按日期查其餘調整")}</h2><p>${L("Open a day for its changes. Each link opens the before-and-after comparison.", "展開一天,點選調整名稱,就能看到它的前後比較。")}</p>${t.archive || "—"}</section>
29
+ <p class="muted">${esc(m.window.project ?? L("All projects", "全部專案"))} · ${esc(m.window.since ?? "—")} → ${esc(m.window.until ?? "—")} · ${num(m.totals.sessions)} ${L("sessions", "段工作")} · ${num(m.totals.prompts)} ${L("prompts", "次提示")}</p>${sections(m, lang, c)}</main>
30
+ ${t.details}<footer><b>PI-EVALS / ${L("Change timeline", "調整時間軸")}</b><span>${esc(m.window.project ?? L("All projects", "全部專案"))} · ${L("Transcript text not included", "統計不含對話原文")}</span></footer></body></html>`;
172
31
  }
@@ -0,0 +1,37 @@
1
+ import { esc, num } from "./format.js";
2
+ export function concepts(m, week, c, L) {
3
+ const i = c?.impact, n = num(week.reduce((s, r) => s + r.sessions, 0)), d = m.process.detectors.find((r) => r.name === "anchor_before_first_edit");
4
+ return {
5
+ record: [
6
+ L("Record", "紀錄"),
7
+ L(`A tool call leaves a record: ${num(week.reduce((s, r) => s + r.calls, 0))} calls in this chart’s period. The words exchanged are not kept.`, `一次工具呼叫留下一筆紀錄。圖中這幾天共 ${num(week.reduce((s, r) => s + r.calls, 0))} 次,不保留對話原文。`),
8
+ ],
9
+ metric: [
10
+ L("Metric", "指標"),
11
+ L(`Count sessions by their start date: ${n} in the chart. This measures workload, not whether the work was good.`, `把工作按開始日期計數,圖中共有 ${n} 段。這個指標量的是工作量,不是工作品質。`),
12
+ ],
13
+ sample: [
14
+ L("Before, after and sample size", "前後比較與樣本數"),
15
+ i
16
+ ? L(`Split sessions at the change time: ${num(i.before.sessions)} before and ${num(i.after.sessions)} after. Only sessions to which a rule applies count in its percentage.`, `依開始時間分組:調整前 ${num(i.before.sessions)} 段、調整後 ${num(i.after.sessions)} 段。算一條規則的通過比例時,只數適用的工作段。`)
17
+ : L(`There are ${num(m.totals.sessions)} sessions in the report. Without records on both sides, we cannot compare a change.`, `報表裡有 ${num(m.totals.sessions)} 段工作。調整前後都要有紀錄,才有兩組數字能比。`),
18
+ ],
19
+ confounding: [
20
+ L("Other changes at the same time", "同期多個調整"),
21
+ i
22
+ ? L(`There were ${num(i.confounded)} other changes in these windows. If a rule and a package changed together, their effects cannot be separated here.`, `這段期間另有 ${num(i.confounded)} 筆調整。規則和套件若一起改,只比前後分不出哪一項影響了結果。`)
23
+ : L(`There are ${num(m.changes.length)} changes on this timeline. Check what else changed before crediting a new version.`, `時間軸有 ${num(m.changes.length)} 筆調整。要把差異歸給某個版本,得先查同一期間還改了什麼。`),
24
+ ],
25
+ check: [
26
+ L("Code check", "程式檢查"),
27
+ L(`In ${num(d?.passRate.n ?? 0)} eligible sessions, code checked whether the agent named a check before editing. It cannot judge whether that check tested the right thing.`, `程式在 ${num(d?.passRate.n ?? 0)} 段適用的工作裡查「改檔前有沒有先說怎麼驗證」。它看得出先後順序,判斷不了方法好不好。`),
28
+ ],
29
+ };
30
+ }
31
+ export function lesson(entry, L) {
32
+ return `<aside class="lesson"><strong class="eyebrow">${L("Reading the numbers", "讀數字")} / ${esc(entry[0])}</strong><p>${esc(entry[1])}</p></aside>`;
33
+ }
34
+ export function selfCheck(L) {
35
+ const item = (q, a) => `<p>${q}</p><details><summary>${L("Answer", "看答案")}</summary><p>${a}</p></details>`;
36
+ return `<h3>${L("Check your reading", "試著判讀")}</h3>${item(L("1. Tool errors fell after a pin. Did the new version fix them?", "1. 更新後工具出錯比例下降,就能說是新版本修好了嗎?"), L("Not from this alone. Check the window, the sample and what else changed.", "還不能。先看前後各有幾段工作、資料收齊了沒,以及同期還改了什麼。"))}${item(L("2. A session passed the check for naming a test before editing. Did the test cover the bug?", "2. 一段工作通過「動手前先說好怎麼驗證」,表示測試驗到了那個錯誤嗎?"), L("The order was right. Whether the test could catch the bug is a different question.", "只知道順序對。那個測試抓不抓得到錯誤,要另外看測試內容。"))}`;
37
+ }
@@ -0,0 +1,73 @@
1
+ import { num, pct, usd, words } from "./format.js";
2
+ export function readings(c, m, lang) {
3
+ const L = words(lang), i = c.impact;
4
+ const has = (k) => i?.before[k]?.value != null && i.after[k]?.value != null;
5
+ const process = c.package === "pi-anchorloop" && has("anchor_before_first_edit");
6
+ const keys = process
7
+ ? ["anchor_before_first_edit", "check_after_last_edit"]
8
+ : [has("package_error_rate") ? "package_error_rate" : "tool_error_rate", "cost_per_session"];
9
+ return keys.map((key) => {
10
+ const meta = m.meta.detectors[key] ?? m.meta.metrics[key === "package_error_rate" ? "tool_error_rate" : key];
11
+ return {
12
+ key,
13
+ label: key === "package_error_rate" ? L("Package tool error rate", "套件工具出錯比例") : meta.label[lang],
14
+ direction: meta.goodDirection === "higher" ? L("higher is better", "越高越好") : L("lower is better", "越低越好"),
15
+ unit: key.endsWith("error_rate") ? L("calls", "次呼叫") : L("sessions", "段"),
16
+ before: i?.before[key],
17
+ after: i?.after[key],
18
+ };
19
+ });
20
+ }
21
+ export const value = (r, side) => r.key === "cost_per_session" ? usd(r[side]?.value ?? null) : pct(r[side]);
22
+ const comparable = (r) => r.before?.value != null && r.after?.value != null;
23
+ export function verdict(c, rs, L) {
24
+ const i = c.impact;
25
+ if (!i)
26
+ return L("Too early to tell: no earlier records.", "還看不出來:調整前沒有紀錄。");
27
+ const notes = [];
28
+ if (i.smallSample)
29
+ notes.push(L("too few sessions", "樣本太少"));
30
+ else if (rs.some((r) => comparable(r) && Math.min(r.before.n, r.after.n) < 20)) {
31
+ notes.push(L("a reading is based on fewer than 20 observations", "有指標的樣本不到 20"));
32
+ }
33
+ if (i.incomplete)
34
+ notes.push(L(`less than ${i.window.days} days on one side`, `一側未滿 ${i.window.days} 天`));
35
+ if (!rs.some(comparable))
36
+ notes.push(L("no comparable readings", "沒有可比較的數字"));
37
+ const other = i.confounded ? L(`${num(i.confounded)} other changes in the same period`, `同期還有 ${num(i.confounded)} 筆別的調整`) : "";
38
+ if (notes.length || other) {
39
+ return [notes.length ? L(`Too early to tell: ${notes.join("; ")}`, `還看不出來(${notes.join("、")})`) : "", other].filter(Boolean)
40
+ .join(" · ");
41
+ }
42
+ return rs.some((r) => comparable(r) && value(r, "before") !== value(r, "after"))
43
+ ? L("An observable difference, not proof of cause.", "看得出變化,但不能證明原因。")
44
+ : L("No visible difference at this precision.", "依顯示精度,前後數字持平。");
45
+ }
46
+ export const eligible = (c) => c.kind === "pin" || c.kind === "model-routing" || (!!c.impact && !c.impact.smallSample);
47
+ export function select(m) {
48
+ const all = [...m.changes].sort((a, b) => b.at.localeCompare(a.at));
49
+ const candidates = all.filter(eligible);
50
+ const recent = candidates.filter((c) => Date.parse(c.at) >= Date.parse(all[0]?.at ?? "") - 7 * 86400000);
51
+ const lead = recent.find((c) => c.package === "pi-anchorloop" && (c.impact?.before.anchor_before_first_edit.n ?? 0) >= 20 &&
52
+ (c.impact?.after.anchor_before_first_edit.n ?? 0) >= 20) ??
53
+ candidates.find((c) => c.impact && !c.impact.smallSample) ?? candidates[0];
54
+ const rest = candidates.filter((c) => c !== lead && c.at <= lead.at && (!lead.sha || c.sha !== lead.sha));
55
+ const second = rest.find((c) => c.impact?.smallSample && c.impact.before.sessions && c.impact.after.sessions) ??
56
+ rest.find((c) => (c.kind === "pin" || c.kind === "model-routing") && c.impact && !c.impact.incomplete) ?? rest[0];
57
+ const highlighted = all.filter((c) => c === lead || c === second);
58
+ return { all, lead, highlighted, folded: all.filter((c) => !highlighted.includes(c)) };
59
+ }
60
+ export function finding(c, rs, L) {
61
+ const r = rs.find(comparable);
62
+ if (!r)
63
+ return L("There are not enough records to compare this change", "這次調整還沒有足夠紀錄可比較");
64
+ const dir = value(r, "before") === value(r, "after")
65
+ ? L(" held steady", "持平")
66
+ : r.after.value > r.before.value
67
+ ? L(" rose", "上升")
68
+ : L(" fell", "下降");
69
+ const label = r.key === "anchor_before_first_edit" ? L("The share naming a check before editing", "先說驗證方法的比例") : r.label;
70
+ return `${label}${dir}${c.impact?.confounded || c.impact?.smallSample || c.impact?.incomplete || Math.min(r.before.n, r.after.n) < 20
71
+ ? L("; the reason is unclear", ",原因還不明")
72
+ : ""}`;
73
+ }
@@ -0,0 +1,16 @@
1
+ export const words = (lang) => (en, zh) => lang === "zh" ? zh : en;
2
+ export const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
3
+ const formatter = new Intl.NumberFormat("en-US");
4
+ export const num = (n) => formatter.format(n);
5
+ export const pct = (r) => r?.value != null ? `${(100 * r.value).toFixed(1)}%` : "—";
6
+ export const usd = (v) => v == null ? "—" : `$${v.toFixed(2)}`;
7
+ export const duration = (v) => v == null ? "—" : v < 1000 ? `${v} ms` : v < 60_000 ? `${(v / 1000).toFixed(1)} s` : `${(v / 60_000).toFixed(1)} min`;
8
+ export const stamp = (at) => `${at.slice(5, 10).replace("-", ".")} ${at.slice(11, 16)}`;
9
+ export const title = (c) => c.package ? `${c.package} ${c.from ?? "∅"} → ${c.to ?? "∅"}` : c.subject;
10
+ /** Cells are text, never markup. */
11
+ export function table(headers, rows, L) {
12
+ if (!rows.length)
13
+ return `<p class="muted">${L("No records in this period.", "這段期間沒有紀錄。")}</p>`;
14
+ const cell = (x) => esc(typeof x === "number" ? num(x) : x);
15
+ return `<div class="scroll"><table><thead><tr>${headers.map((h) => `<th scope="col">${esc(h)}</th>`).join("")}</tr></thead><tbody>${rows.map((r) => `<tr>${r.map((c) => `<td>${cell(c)}</td>`).join("")}</tr>`).join("")}</tbody></table></div>`;
16
+ }
@@ -0,0 +1,61 @@
1
+ import { lesson, selfCheck } from "./concepts.js";
2
+ import { duration, esc, num, pct, table, usd, words } from "./format.js";
3
+ export function sections(m, lang, cards) {
4
+ const L = words(lang), meta = m.meta.metrics;
5
+ const label = (id) => meta[id].label[lang];
6
+ const T = (head, rows) => table(head, rows, L);
7
+ const section = (id, title, intro, body) => `<section id="${id}" class="topic"><p class="eyebrow">PI-EVALS / ${L("Field notes", "工作紀錄")}</p><h2>${title}</h2><p class="intro">${esc(intro)}</p>${body}</section>`;
8
+ const more = (title, html) => `<details><summary>${esc(title)}</summary>${html}</details>`;
9
+ const daily = (values) => T([L("Date (UTC)", "日期(UTC)"), L("Value", "數值")], m.series.days.map((d, i) => [d, values[i]]));
10
+ const entries = (map) => Object.entries(map);
11
+ const sk = m.skills, a = m.askUser, mon = m.monitors, s = m.subagents;
12
+ const skills = section("skills", L("Which skills got opened?", "哪些技能真的有人打開?"), meta.skill_loads.meaning[lang], `<div class="pair"><article class="panel"><h3>${L("Most used", "最常載入")}</h3>${T([L("Skill", "技能"), L("Loads", "次數"), L("Sessions", "工作段數")], sk.top.slice(0, 8).map((r) => [r.name, r.loads, r.sessions]))}</article><article class="panel tint"><h3>${L("Offered but never opened", "有提供,但沒人載入")}</h3><p class="big">${num(sk.neverLoaded.length)} / ${num(sk.offered)}</p><p>${esc(meta.never_loaded.howComputed[lang])}</p>${more(L("Skill names", "看技能名稱"), `<p>${sk.neverLoaded.map(esc).join("、") || "—"}</p>`)}</article></div>` +
13
+ more(L("Loads by day, project and trigger", "查看每日載入、各專案與載入方式"), daily(m.series.skillLoads) +
14
+ T([L("Project", "專案"), L("Skill", "技能"), L("Loads", "次數")], sk.byProject.map((r) => [r.project, r.skill, r.loads])) +
15
+ T([L("Trigger", "方式"), L("Loads", "次數")], entries(sk.triggers))));
16
+ const packages = section("packages", L("Packages and tools", "套件與工具"), meta.package_calls.meaning[lang], T([L("Package", "套件"), L("Version", "版本"), L("Calls", "呼叫次數"), label("tool_error_rate"), label("avg_duration_ms")], m.packages.map((r) => [r.owner, r.version ?? "—", r.calls, pct(r.errorRate), duration(r.avgMs)])) +
17
+ more(L("Tools by calls", "依呼叫次數查看工具"), T([L("Tool", "工具"), L("Package", "套件"), L("Calls", "次數"), label("tool_error_rate")], m.tools.map((r) => [r.name, r.owner, r.calls, pct(r.errorRate)]))));
18
+ const ask = section("ask", L("When the agent stopped to ask", "代理人何時停下來問你"), L("See how often you were asked, how long an answer took and how often you dismissed the question.", "這裡可以看到代理人問了幾次、答一題平均要等多久,以及你取消了多少提問。"), T([L("Measure", "指標"), L("Reading", "數值"), L("Counted", "計算次數")], [[label("ask_calls"), a.calls, a.calls], [
19
+ label("ask_wait_ms"),
20
+ duration(a.avgWaitMs),
21
+ a.waitN,
22
+ ], [label("ask_cancel_rate"), pct(a.cancelRate), a.cancelRate.n]]) +
23
+ more(L("Wait times and answer sources", "查看等待時間分布與回答來源"), T([L("Wait", "等待時間"), L("Count", "次數")], a.buckets.map((b, i) => [
24
+ b.upToMs == null
25
+ ? `≥ ${duration(a.buckets[i - 1]?.upToMs ?? 0)}`
26
+ : `${duration(i ? a.buckets[i - 1].upToMs : 0)} – < ${duration(b.upToMs)}`,
27
+ b.n,
28
+ ])) + T([L("Source", "來源"), L("Count", "次數")], entries(a.sources))));
29
+ const monitors = section("monitors", L("Background jobs", "背景工作"), meta.monitor_outcomes.meaning[lang], `<p>${L("Started", "啟動")} ${num(mon.started)} / ${L("Ending recorded", "有結束紀錄")} ${num(mon.finished)} / ${label("monitor_duration_ms")} ${duration(mon.avgMs)}(${num(mon.durationN)})</p>${T([L("Outcome", "結果"), L("Count", "次數")], entries(mon.statuses))}<p class="muted">${esc(meta.monitor_outcomes.howComputed[lang])}</p>`);
30
+ const sub = section("subagents", L("Work handed to other agents", "交給子代理的工作"), meta.subagent_launches.meaning[lang], T([L("Role", "角色"), L("Model", "模型"), L("Launches", "啟動次數")], s.launches.slice(0, 40).map((r) => [r.role, r.model, r.n])) +
31
+ more(label("subagent_cost"), T([L("Role", "角色"), L("USD", "美元")], s.costByRole.map((r) => [r.role, usd(r.cost)]))) +
32
+ `<p>${L("Linked to a parent across the index", "整份索引中能對回母工作階段的子代理")}:${num(s.linked)} / ${num(s.subagentTotal)}</p>`);
33
+ const process = section("process", L("Did the agent follow the steps?", "工作有沒有照說好的步驟走?"), L(`Only sessions starting from ${m.process.eraStart} are judged. Earlier work is not a failure.`, `只檢查 ${m.process.eraStart} 起的工作;更早的工作不算失敗。`), lesson(cards.check, L) + `<div class="pair checks">${m.process.detectors.map((d) => {
34
+ const md = m.meta.detectors[d.name];
35
+ return `<article class="panel"><p class="eyebrow">${L("Code check", "程式檢查")} / ${L("higher is better", "越高越好")}</p><h3>${esc(md.label[lang])}</h3><p class="big">${pct(d.passRate)} <small>${num(d.pass)} / ${num(d.passRate.n)} ${L("sessions", "段")}</small></p><p>${esc(md.howComputed[lang])}</p><p><b>${L("Pass", "通過")}</b> ${esc(md.example.pass[lang])}<br><b>${L("Fail", "未通過")}</b> ${esc(md.example.fail[lang])}</p>${more(L("By day and version", "查看每日與各版本的通過數"), T([L("Day", "日期"), L("Pass", "通過"), L("Fail", "未通過")], d.perDay.map((r) => [r.day, r.pass, r.fail])) +
36
+ T([L("Version", "版本"), L("Pass", "通過"), L("Fail", "未通過")], d.byVersion.map((r) => [r.version, r.pass, r.fail])))}</article>`;
37
+ }).join("")}</div>` +
38
+ more(L("Close-guard reminders", "收尾提醒"), T([L("Kind", "種類"), L("Count", "次數")], entries(m.process.notices).map(([k, n]) => [m.meta.notices[k]?.[lang] ?? k, n]))));
39
+ const cost = section("cost", L("What the work cost", "工作花了多少錢"), meta.cost.meaning[lang], `<p class="big">${usd(m.cost.total)} <small>USD</small></p><p>${label("cost_per_session")} ${usd(m.cost.perSession.value)}(${num(m.cost.perSession.n)} ${L("sessions", "段")})</p><p>${esc(meta.skill_cost.meaning[lang])}</p>` +
40
+ T([L("Skill", "技能"), L("USD", "美元"), L("Sessions", "工作段數")], m.cost.bySkill.map((r) => [r.skill, usd(r.cost), r.sessions])) +
41
+ more(L("Daily spend and model replies", "查看每日費用與各模型回覆數"), daily(m.series.cost) + T([L("Model", "模型"), L("Replies", "回覆數")], m.cost.byModel.map((r) => [r.model, r.replies]))));
42
+ const cov = m.coverage;
43
+ const coverage = section("coverage", L("When is cleanup safe?", "何時可以開啟清理?"), L("Only consider cleanup when all old files match the index, by both file count and bytes. This report never deletes a file.", "所有舊檔的大小和修改時間都要和索引相符,未建索引的檔案數和位元組數都歸零,才考慮開啟清理。報表不會刪檔。"), cov
44
+ ? `<p>${L("Inactive days", "閒置天數")} &gt; ${cov.cutDays} / ${L("Files indexed", "已建索引")} ${num(cov.indexed.files)} / ${num(cov.old.files)}</p><p>${L("Not indexed", "未建索引")}:${num(cov.notIndexed.files)} ${L("files", "個檔案")} · ${num(cov.notIndexed.bytes)} bytes</p>`
45
+ : `<p>${L("Coverage not measured; keep cleanup off.", "沒有索引覆蓋資料,請勿開啟清理。")}</p>`);
46
+ const labels = section("labels", L("Your labels", "你的標記"), meta.agreement.meaning[lang], m.labels.present && m.labels.n
47
+ ? T([L("Check", "檢查"), L("Labelled", "已標記"), L("Agreement", "一致比例")], m.labels.agreement.map((r) => [m.meta.detectors[r.detector]?.label[lang] ?? r.detector, r.n, pct(r.rate)]))
48
+ : `<p>${L("No labels yet. In phase 2 you will judge sessions yourself and compare your answers with the code checks.", "還沒有標記。第二階段會讓你親自判讀工作紀錄,再對照程式與你的判斷是否一致。")}</p>`);
49
+ return [
50
+ skills,
51
+ packages,
52
+ ask,
53
+ monitors,
54
+ sub,
55
+ process,
56
+ cost,
57
+ coverage,
58
+ labels,
59
+ section("concepts", L("Concepts", "概念"), L("Use these five ideas when you read the next report.", "下次讀報表時,可以用這五個概念判讀數字。"), `<div class="notes-grid">${Object.values(cards).map((c) => lesson(c, L)).join("")}</div>${selfCheck(L)}`),
60
+ ].join("");
61
+ }
@@ -0,0 +1,77 @@
1
+ /** Embedded in report.html so the page also works when copied or opened offline. */
2
+ export const css = `
3
+ :root {
4
+ color-scheme:light dark; --bg:#f9faf6; --paper:#fff; --ink:#172e36; --sub:#4f6366;
5
+ --green:#16665c; --line:#cdd8d3; --tint:#e4f1eb; --area:#dceae3; --warm:#855126; --accent:#16665c;
6
+ }
7
+ @media(prefers-color-scheme:dark) { :root {
8
+ --bg:#152320; --paper:#1e302d; --ink:#ebf5ef; --sub:#bdcfc8; --green:#98dcca;
9
+ --line:#465d56; --tint:#243e36; --area:#355348; --warm:#eabc90;
10
+ } }
11
+ * {box-sizing:border-box}
12
+ body {margin:0 auto;max-width:1280px;padding:0 clamp(18px,4.375vw,56px);background:var(--bg);color:var(--ink);
13
+ font:17px/1.58 -apple-system,BlinkMacSystemFont,"PingFang TC","Noto Sans TC","Segoe UI",sans-serif;
14
+ font-variant-numeric:tabular-nums;overflow-wrap:anywhere}
15
+ a,summary {color:var(--green)}
16
+ a:focus-visible,summary:focus-visible {outline:3px solid var(--warm);outline-offset:3px}
17
+ header,.hero,.topic {border-bottom:1px solid var(--line)}
18
+ header,footer,.ends,.ruler-head,.reading {display:flex;align-items:center;justify-content:space-between;gap:12px}
19
+ header {min-height:75px;flex-wrap:wrap}
20
+ .brand {display:flex;align-items:center;gap:12px;text-decoration:none;color:var(--ink);font-size:21px;font-weight:700}
21
+ .brand span {font-size:17px;font-weight:400;padding-left:20px;margin-left:16px;border-left:1px solid var(--line);color:var(--sub)}
22
+ small,.muted,.intro,.deck,.ends {color:var(--sub)}
23
+ small,.muted,.ends,summary,.footline,.button {font-size:15px}
24
+ .hero {padding:36px 0 20px}
25
+ .hero h1,.hero-title {font-size:clamp(29px,3.125vw,40px);line-height:1.25;margin:18px 0}
26
+ .deck,.intro {font-size:19px;margin:0}.hero .deck+.deck {margin-top:24px}
27
+ .eyebrow {font-size:14px;font-weight:650;letter-spacing:1px;color:var(--green);margin:0}
28
+ .stale,.verdict {color:var(--warm)}
29
+ h2 {font-size:25px;line-height:1.35;margin:0 0 14px}
30
+ h3,.big {font-size:29px;line-height:1.35;margin:14px 0 18px}
31
+ .spine {padding-top:25px}
32
+ .layout {display:grid;grid-template-columns:minmax(0,709fr) minmax(0,419fr);gap:40px;align-items:start}
33
+ .rail {position:relative;padding-left:54px}
34
+ .rail:before {content:"";position:absolute;left:22px;top:20px;bottom:20px;border-left:2px solid var(--line)}
35
+ .card,.panel,.lesson {background:var(--paper);border:1px solid var(--line);border-radius:12px;padding:22px 25px}
36
+ .card {position:relative;padding-block:19px 17px}.card+.card {margin-top:30px}
37
+ .card:before,.ruler i {width:10px;height:10px;background:var(--green);border:3px solid var(--bg);outline:2px solid var(--green);border-radius:50%}
38
+ .card:before {content:"";position:absolute;left:-37px;top:31px}
39
+ .card h3 {margin:9px 0 14px}.reading {line-height:1.45;margin:12px 0}.card .reading {margin:9px 0}
40
+ .reading b {font-size:18px}.reading small {flex-shrink:0}.card .muted {margin:9px 0}
41
+ .button {display:inline-block;padding:9px 22px;border-radius:8px;background:var(--accent);color:white;text-decoration:none;margin-top:3px;min-width:156px;text-align:center}
42
+ .workload h2 {margin-bottom:0}.workload h3 {margin:25px 0 12px}.workload .muted {margin:5px 0}
43
+ .workload svg {width:100%;height:auto;display:block;margin-top:8px}
44
+ .area {fill:var(--area)}.trend {stroke:var(--green);stroke-width:2.5;stroke-linejoin:round;fill:none}
45
+ .marker {stroke:var(--warm);stroke-dasharray:3 4}.dot {fill:var(--green)}.ends {margin:4px 0}
46
+ .footline {border-top:1px solid var(--line);padding-top:13px;margin:12px 0 0}
47
+ .lesson,.tint,.after {background:var(--tint)}.lesson {padding:16px 19px}.lesson p {margin:5px 0 0}.side>.lesson {margin-top:16px}
48
+ .topic {padding:38px 0}.topic h2 {margin:9px 0}.intro {margin:0 0 18px}
49
+ .jump {display:flex;flex-wrap:wrap;gap:8px 18px;padding:20px 0;border-block:1px solid var(--line);margin:32px 0 0}
50
+ .day li {margin:.45rem 0}.day time {color:var(--sub)}details {margin:12px 0}summary {cursor:pointer;font-weight:600}
51
+ .scroll {overflow-x:auto}table {width:100%;border-collapse:collapse;margin:.4rem 0;background:var(--paper)}
52
+ th,td {text-align:start;padding:7px 12px;border-bottom:1px solid var(--line)}th {font-size:15px;color:var(--green)}
53
+ .pair,.notes-grid {display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:20px}
54
+ .checks {margin-top:18px}.checks h3,.topic .panel h3 {font-size:22px}
55
+ .detail {display:none;padding-bottom:24px;scroll-margin-top:75px}.detail:target {display:block;outline:none}
56
+ body:has(.detail:target) main {display:none}.back {float:right;font-size:15px}
57
+ .ruler-head {margin:30px 0 24px}.ruler-head h2 {margin:0}
58
+ .ruler {position:relative;list-style:none;margin:0 0 30px;padding:0;height:86px}
59
+ .ruler:before,.ruler.partial:after {content:"";position:absolute;top:39px;left:6%;right:6%;height:2px;background:var(--green)}
60
+ .ruler.partial:after {left:65.5%;right:6.5%;background:var(--bg);border-top:2px dashed var(--line)}
61
+ .ruler li {position:absolute;width:118px;transform:translateX(-50%);text-align:center;font-size:15px;color:var(--sub)}
62
+ .ruler li:first-child {left:6%}.ruler li:nth-child(2) {left:50%}.ruler li:nth-child(3) {left:65%}.ruler li:last-child {left:94%}
63
+ .ruler time {color:var(--green);white-space:nowrap}.ruler i {display:block;position:relative;margin:11px auto}
64
+ .compare h3 {border-bottom:1px solid var(--line);padding-bottom:12px}.compare .reading {min-height:32px}.detail>.eyebrow {margin-bottom:8px}
65
+ .notes-grid {margin:16px 0}.notes-grid .lesson {font-size:16px}
66
+ footer {font-size:14px;margin-top:24px;padding:18px 0 25px;color:var(--sub);border-top:1px solid var(--line)}
67
+ @media(max-width:850px) {
68
+ .layout,.pair,.notes-grid {grid-template-columns:1fr}.layout {gap:22px}.rail {padding-left:27px}.rail:before {left:7px}.card:before {left:-26px}
69
+ .reading {flex-wrap:wrap}.ruler-head,footer {align-items:flex-start;flex-direction:column}
70
+ }
71
+ @media(max-width:640px) {
72
+ header {padding:12px 0;gap:5px}.hero {padding:24px 0}.brand span {margin-left:4px;padding-left:10px}
73
+ .card,.panel {padding:16px}.ruler {height:auto}.ruler:before,.ruler:after,.ruler li i {display:none}
74
+ .ruler li {position:static;width:auto;transform:none;display:flex;align-items:center;gap:8px;text-align:left}
75
+ .card h3 {font-size:23px}.back {float:none;display:block;margin-bottom:8px}
76
+ }
77
+ `;