pi-evals 0.0.0-stage → 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 +21 -0
- package/LICENSE +21 -0
- package/README.md +116 -2
- package/dist/aggregate.js +113 -0
- package/dist/build.js +260 -0
- package/dist/changes.js +170 -0
- package/dist/cli.js +86 -0
- package/dist/coverage.js +34 -0
- package/dist/detectors.js +154 -0
- package/dist/extract/file.js +42 -0
- package/dist/extract/run.js +149 -0
- package/dist/extract/session.js +430 -0
- package/dist/extract/worker.js +12 -0
- package/dist/index.js +165 -0
- package/dist/meta.js +233 -0
- package/dist/model.js +317 -0
- package/dist/observer.js +240 -0
- package/dist/ops.js +93 -0
- package/dist/owners.js +97 -0
- package/dist/paths.js +76 -0
- package/dist/project.js +43 -0
- package/dist/query.js +92 -0
- package/dist/render.js +31 -0
- package/dist/report/concepts.js +37 -0
- package/dist/report/findings.js +73 -0
- package/dist/report/format.js +16 -0
- package/dist/report/sections.js +61 -0
- package/dist/report/style.js +77 -0
- package/dist/report/timeline.js +91 -0
- package/dist/report/week.js +36 -0
- package/dist/schema.js +65 -0
- package/dist/skills.js +41 -0
- package/dist/store.js +51 -0
- package/docs/design.md +106 -0
- package/docs/learn.zh-TW.md +33 -0
- package/docs/schema.md +68 -0
- package/package.json +56 -4
- package/src/aggregate.ts +204 -0
- package/src/build.ts +257 -0
- package/src/changes.ts +178 -0
- package/src/cli.ts +89 -0
- package/src/coverage.ts +44 -0
- package/src/detectors.ts +182 -0
- package/src/extract/file.ts +46 -0
- package/src/extract/run.ts +198 -0
- package/src/extract/session.ts +430 -0
- package/src/extract/worker.ts +12 -0
- package/src/index.ts +160 -0
- package/src/meta.ts +259 -0
- package/src/model.ts +346 -0
- package/src/observer.ts +255 -0
- package/src/ops.ts +110 -0
- package/src/owners.ts +92 -0
- package/src/paths.ts +108 -0
- package/src/project.ts +43 -0
- package/src/query.ts +85 -0
- package/src/render.ts +63 -0
- package/src/report/concepts.ts +94 -0
- package/src/report/findings.ts +84 -0
- package/src/report/format.ts +24 -0
- package/src/report/sections.ts +188 -0
- package/src/report/style.ts +77 -0
- package/src/report/timeline.ts +143 -0
- package/src/report/week.ts +55 -0
- package/src/schema.ts +84 -0
- package/src/skills.ts +46 -0
- package/src/store.ts +49 -0
package/dist/render.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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>`;
|
|
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) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[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", "閒置天數")} > ${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
|
+
`;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { concepts, lesson } from "./concepts.js";
|
|
2
|
+
import { finding, readings, select, value, verdict } from "./findings.js";
|
|
3
|
+
import { esc, num, stamp, title, words } from "./format.js";
|
|
4
|
+
function card(c, id, rs, L) {
|
|
5
|
+
const i = c.impact;
|
|
6
|
+
return `<article class="card"><p class="eyebrow"><time datetime="${esc(c.at)}">${esc(stamp(c.at))} UTC</time></p><h3>${esc(title(c))}</h3>${rs.map((r) => `<div class="reading"><b>${esc(r.label)} ${value(r, "before")} → ${value(r, "after")}</b><small>${num(r.before?.n ?? 0)} → ${num(r.after?.n ?? 0)} ${r.unit}</small></div>`).join("")}<p class="muted">${rs[0].direction === rs[1].direction
|
|
7
|
+
? L(`Both: ${rs[0].direction}.`, `兩項都${rs[0].direction}。`)
|
|
8
|
+
: rs.map((r) => `${r.label}:${r.direction}`).join(" · ")}${i ? ` ${num(i.before.sessions)} → ${num(i.after.sessions)} ${L("sessions.", "段工作。")}` : ""}<br><span class="verdict">${esc(verdict(c, rs, L))}</span></p><a class="button" href="#${id}">${L("Change details", "看調整明細")} →</a></article>`;
|
|
9
|
+
}
|
|
10
|
+
function ruler(c, last, L) {
|
|
11
|
+
const i = c.impact;
|
|
12
|
+
const cutoff = last && last > c.at && last < i.window.after.until ? last : null;
|
|
13
|
+
const points = [
|
|
14
|
+
[i.window.before.since, L("Before starts", "開始算調整前")],
|
|
15
|
+
[c.at, L("Change", "做了調整")],
|
|
16
|
+
...(cutoff ? [[cutoff, L("Last extract", "資料截至這裡")]] : []),
|
|
17
|
+
[i.window.after.until, L("After window ends", "調整後期間結束")],
|
|
18
|
+
];
|
|
19
|
+
return `<div class="ruler-head"><h2>${L(`Compare ${i.window.days} days on each side`, `同一條規則,前後各看 ${i.window.days} 天`)}</h2><small>${L("Grouped by start time · not to scale", "依工作開始時間分組 / 時間線不按比例繪製")}</small></div><ol class="ruler${cutoff ? " partial" : ""}">${points.map(([at, text]) => `<li><time>${esc(stamp(at))}</time><i></i><span>${text}</span></li>`).join("")}</ol>`;
|
|
20
|
+
}
|
|
21
|
+
function panel(c, side, rs, period, L) {
|
|
22
|
+
const i = c.impact;
|
|
23
|
+
return `<article class="panel compare ${side}"><p class="eyebrow">${side === "before" ? L("Before", "調整前") : L("After", "調整後")} / ${esc(period)}</p><h3>${num(i[side].sessions)} ${L("sessions", "段工作")}</h3>${rs.map((r) => {
|
|
24
|
+
const x = r[side];
|
|
25
|
+
const sample = x?.value != null
|
|
26
|
+
? (r.key === "cost_per_session" ? `${num(x.n)} ${r.unit}` : `${num(Math.round(x.value * x.n))} / ${num(x.n)} ${r.unit}`)
|
|
27
|
+
: L("no eligible records", "沒有適用紀錄");
|
|
28
|
+
return `<div class="reading"><span>${esc(r.label)}</span><b>${value(r, side)} <small>(${sample})</small></b></div>`;
|
|
29
|
+
}).join("")}</article>`;
|
|
30
|
+
}
|
|
31
|
+
function detail(c, id, rs, m, w, lang, siblings) {
|
|
32
|
+
const L = words(lang), i = c.impact, lessons = concepts(m, w, c, L);
|
|
33
|
+
const peers = siblings.filter((s) => s !== c);
|
|
34
|
+
const together = peers.length
|
|
35
|
+
? L(`Same commit: ${peers.map((s) => s.package ?? m.meta.changeKinds[s.kind][lang]).join(", ")}.`, `同一次提交也調整了 ${peers.map((s) => s.package ?? m.meta.changeKinds[s.kind][lang]).join("、")}。`)
|
|
36
|
+
: "";
|
|
37
|
+
const primary = rs[0];
|
|
38
|
+
const age = (Date.parse(m.freshness.lastExtract ?? "") - Date.parse(c.at)) / 3600000;
|
|
39
|
+
const partial = i?.incomplete && age >= 0 && age < i.window.days * 24;
|
|
40
|
+
const ageText = age < 1 ? L("less than an hour", "不到一小時") : L(`about ${Math.floor(age)} hours`, `約 ${Math.floor(age)} 小時`);
|
|
41
|
+
const heading = partial ? L(`Only ${ageText} since the change: too early to tell`, `調整後${ageText},還看不出效果`) : verdict(c, rs, L);
|
|
42
|
+
const fullPeriod = L(`${i?.window.days} days`, `${i?.window.days} 天`);
|
|
43
|
+
const beforePeriod = i?.incomplete ? L(`Planned: ${fullPeriod}`, `原定 ${fullPeriod}`) : fullPeriod;
|
|
44
|
+
return `<section class="detail" id="${id}" tabindex="-1"><div class="hero"><a class="back" href="#timeline">← ${L("Timeline", "回時間軸")}</a><p class="eyebrow">${L("Architecture change", "架構調整明細")} / ${esc(stamp(c.at))} UTC</p><h2 class="hero-title">${esc(heading)}</h2><p class="deck">${esc(title(c))} ${esc(together)}</p>${i
|
|
45
|
+
? `<p class="deck">${esc(primary.label)}:${value(primary, "before")} → ${value(primary, "after")}。 ${esc(verdict(c, rs, L))}</p>`
|
|
46
|
+
: ""}</div>
|
|
47
|
+
${i
|
|
48
|
+
? `${ruler(c, m.freshness.lastExtract, L)}<p class="eyebrow">${L("Records side by side", "紀錄對照")}</p><h2>${L("Compare the two groups", "比較兩個時段的工作")}</h2><div class="pair">${panel(c, "before", rs, beforePeriod, L)}${panel(c, "after", rs, partial ? ageText : fullPeriod, L)}</div><p>${rs.map((r) => `${esc(r.label)}:${r.direction}`).join(" / ")}</p>`
|
|
49
|
+
: ""}
|
|
50
|
+
<div class="notes-grid">${lesson(lessons.sample, L)}${lesson(lessons.confounding, L)}${c.package === "pi-anchorloop" ? lesson(lessons.check, L) : ""}</div><p class="muted">${esc(c.repo)} ${esc(c.sha)} ${esc(c.subject)}</p><a href="#timeline">← ${L("Timeline", "回時間軸")}</a></section>`;
|
|
51
|
+
}
|
|
52
|
+
export function timeline(m, w, lang) {
|
|
53
|
+
const L = words(lang), { all, lead, highlighted, folded } = select(m);
|
|
54
|
+
const ids = new Map(all.map((c, i) => [c, `change-${i + 1}`]));
|
|
55
|
+
const metrics = new Map(all.map((c) => [c, readings(c, m, lang)]));
|
|
56
|
+
const byDay = new Map(), byCommit = new Map();
|
|
57
|
+
for (const c of folded) {
|
|
58
|
+
const d = c.at.slice(0, 10);
|
|
59
|
+
if (!byDay.has(d))
|
|
60
|
+
byDay.set(d, []);
|
|
61
|
+
byDay.get(d).push(c);
|
|
62
|
+
}
|
|
63
|
+
for (const c of all) {
|
|
64
|
+
if (c.sha) {
|
|
65
|
+
const key = `${c.repo}/${c.sha}`;
|
|
66
|
+
if (!byCommit.has(key))
|
|
67
|
+
byCommit.set(key, []);
|
|
68
|
+
byCommit.get(key).push(c);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const headline = lead
|
|
72
|
+
? finding(lead, metrics.get(lead), L)
|
|
73
|
+
: all.length
|
|
74
|
+
? L("Not enough sessions to compare changes yet", "這批調整的工作段數還不夠比較")
|
|
75
|
+
: L("No changes recorded in this period", "這段期間沒有調整紀錄");
|
|
76
|
+
const reason = lead?.impact;
|
|
77
|
+
const trust = lead && reason?.incomplete && reason.confounded && !reason.smallSample
|
|
78
|
+
? L(`There were ${num(reason.confounded)} other changes, and one side has less than ${reason.window.days} days of data. We cannot credit this change alone.`, `同期還有 ${num(reason.confounded)} 筆別的調整,一側的資料也未滿 ${reason.window.days} 天;目前不能把差異歸給這次調整。`)
|
|
79
|
+
: lead
|
|
80
|
+
? verdict(lead, metrics.get(lead), L)
|
|
81
|
+
: L(`There are ${num(m.totals.sessions)} sessions in this report, but no eligible comparison.`, `報表收錄 ${num(m.totals.sessions)} 段工作,目前沒有適合放在首頁的比較。`);
|
|
82
|
+
return {
|
|
83
|
+
lead,
|
|
84
|
+
headline,
|
|
85
|
+
trust,
|
|
86
|
+
count: highlighted.length,
|
|
87
|
+
cards: highlighted.map((c) => card(c, ids.get(c), metrics.get(c), L)).join(""),
|
|
88
|
+
archive: [...byDay].map(([day, list]) => `<details class="day"><summary>${esc(day)} / ${num(list.length)} ${L("changes", "筆調整")}</summary><ul>${list.map((c) => `<li><time>${esc(c.at.slice(11, 16))}</time> <a href="#${ids.get(c)}">${esc(title(c))}</a></li>`).join("")}</ul></details>`).join(""),
|
|
89
|
+
details: all.map((c) => detail(c, ids.get(c), metrics.get(c), m, w, lang, byCommit.get(`${c.repo}/${c.sha}`) ?? [])).join(""),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { esc, num } from "./format.js";
|
|
2
|
+
/** Last seven calendar days ending on the last complete UTC day in the selected period. */
|
|
3
|
+
export function week(m) {
|
|
4
|
+
const last = m.freshness.lastExtract?.slice(0, 10);
|
|
5
|
+
if (!last || !m.window.until || !m.window.since)
|
|
6
|
+
return [];
|
|
7
|
+
const end = Math.min(Date.parse(last) - 86400000, Date.parse(m.window.until));
|
|
8
|
+
const rows = [];
|
|
9
|
+
for (let t = Math.max(end - 6 * 86400000, Date.parse(m.window.since)); t <= end; t += 86400000) {
|
|
10
|
+
const day = new Date(t).toISOString().slice(0, 10), i = m.series.days.indexOf(day);
|
|
11
|
+
rows.push({
|
|
12
|
+
day,
|
|
13
|
+
sessions: m.series.sessions[i] ?? 0,
|
|
14
|
+
calls: m.series.toolCalls[i] ?? 0,
|
|
15
|
+
loads: m.series.skillLoads[i] ?? 0,
|
|
16
|
+
changes: m.changes.filter((c) => c.at.startsWith(day)).length,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return rows;
|
|
20
|
+
}
|
|
21
|
+
export function workload(rows, L) {
|
|
22
|
+
const heading = `<h2>${L("This week’s workload", "這週的工作量")}</h2>`;
|
|
23
|
+
if (!rows.length)
|
|
24
|
+
return `<div class="panel">${heading}<p>${L("No complete recorded day yet.", "尚無完整一天的紀錄。")}</p></div>`;
|
|
25
|
+
const total = (key) => num(rows.reduce((n, r) => n + r[key], 0));
|
|
26
|
+
const max = Math.max(1, ...rows.map((r) => r.sessions));
|
|
27
|
+
const points = rows.map((r, i) => [5 + i * 348 / Math.max(1, rows.length - 1), 89 - 64 * r.sessions / max]);
|
|
28
|
+
const line = points.map((p) => p.join(",")).join(" ");
|
|
29
|
+
const md = (d) => d.slice(5).replace("-", ".");
|
|
30
|
+
const desc = rows.map((r) => `${r.day}: ${num(r.sessions)} ${L("sessions", "段工作")} · ${r.changes} ${L("changes", "筆調整")}`).join("; ");
|
|
31
|
+
return `<div class="panel workload">${heading}<p class="muted">${md(rows[0].day)}–${md(rows.at(-1).day)} / ${L("Volume is not quality", "多寡不代表好壞")}</p><h3>${total("sessions")} ${L("sessions", "段工作")}</h3><p class="muted">${L("Sessions per day · dashes mark changes", "每日工作段數 · 虛線表示當天有調整")}</p>
|
|
32
|
+
<svg role="img" aria-label="${esc(desc)}" viewBox="0 0 358 96"><polygon points="5,89 ${line} ${points.at(-1)[0]},89" class="area"/><polyline points="${line}" class="trend"/>${points.map(([x, y], i) => rows[i].changes
|
|
33
|
+
? `<path d="M${x} 12V89" class="marker"/><circle cx="${x}" cy="${y}" r="3.5" class="dot"><title>${esc(rows[i].day)}: ${rows[i].changes} ${L("changes", "筆調整")}</title></circle>`
|
|
34
|
+
: "").join("")}</svg>
|
|
35
|
+
<div class="ends"><span>${md(rows[0].day)} ${num(rows[0].sessions)}</span><span>${md(rows.at(-1).day)} ${num(rows.at(-1).sessions)}</span></div><p class="footline">${L("Tool calls", "工具呼叫")} ${total("calls")} / ${L("Skill loads", "讀取技能")} ${total("loads")}</p></div>`;
|
|
36
|
+
}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one record shape (docs/schema.md): one JSON object per line, OpenTelemetry GenAI names where they exist,
|
|
3
|
+
* `pi.*` for pi facts, `anchorloop.*` for process facts, `eval.*` for evaluation metadata.
|
|
4
|
+
*
|
|
5
|
+
* Privacy is enforced here: every string attribute must look like a name (no spaces, no newlines, bounded length).
|
|
6
|
+
* Anything else is replaced by "redacted", so free text from a transcript cannot reach a record by accident.
|
|
7
|
+
*/
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
export const SCHEMA_VERSION = 1;
|
|
10
|
+
const NAME = /^[\p{L}\p{N}_@./:+#=|-]{0,160}$/u;
|
|
11
|
+
/** A string attribute that passes the name check, else "redacted". */
|
|
12
|
+
export function safeName(value) {
|
|
13
|
+
if (typeof value !== "string")
|
|
14
|
+
return "unknown";
|
|
15
|
+
return NAME.test(value) ? value : "redacted";
|
|
16
|
+
}
|
|
17
|
+
function clean(attrs) {
|
|
18
|
+
const out = {};
|
|
19
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
20
|
+
if (value === undefined)
|
|
21
|
+
continue;
|
|
22
|
+
if (typeof value === "string")
|
|
23
|
+
out[key] = safeName(value);
|
|
24
|
+
else if (Array.isArray(value))
|
|
25
|
+
out[key] = value.slice(0, 200).map(safeName);
|
|
26
|
+
else if (typeof value === "number") {
|
|
27
|
+
if (Number.isFinite(value))
|
|
28
|
+
out[key] = value;
|
|
29
|
+
}
|
|
30
|
+
else
|
|
31
|
+
out[key] = value;
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
export function record(fields) {
|
|
36
|
+
const out = { schema_version: SCHEMA_VERSION, name: safeName(fields.name), kind: fields.kind, ts: fields.ts, source: fields.source, attrs: clean(fields.attrs) };
|
|
37
|
+
if (fields.end_ts)
|
|
38
|
+
out.end_ts = fields.end_ts;
|
|
39
|
+
if (typeof fields.duration_ms === "number" && Number.isFinite(fields.duration_ms))
|
|
40
|
+
out.duration_ms = Math.max(0, Math.round(fields.duration_ms));
|
|
41
|
+
if (fields.trace_id)
|
|
42
|
+
out.trace_id = fields.trace_id;
|
|
43
|
+
if (fields.span_id)
|
|
44
|
+
out.span_id = fields.span_id;
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
const hex = (text, length) => createHash("sha1").update(text).digest("hex").slice(0, length);
|
|
48
|
+
/** 32-hex trace id, stable for a session and the entry that opened the prompt. */
|
|
49
|
+
export const traceId = (sessionId, anchor) => hex(`trace:${sessionId}:${anchor}`, 32);
|
|
50
|
+
/** 16-hex span id, stable across re-extraction. */
|
|
51
|
+
export const spanId = (sessionId, anchor) => hex(`span:${sessionId}:${anchor}`, 16);
|
|
52
|
+
export const fileKey = (path) => hex(`file:${path}`, 20);
|
|
53
|
+
/** Record names this package writes. */
|
|
54
|
+
export const NAMES = {
|
|
55
|
+
session: "pi.session",
|
|
56
|
+
prompt: "invoke_agent",
|
|
57
|
+
tool: "execute_tool",
|
|
58
|
+
skill: "pi.skill.load",
|
|
59
|
+
monitor: "pi.monitor",
|
|
60
|
+
notice: "anchorloop.close_guard.notice",
|
|
61
|
+
evaluation: "gen_ai.evaluation.result",
|
|
62
|
+
tools: "pi.tools.snapshot",
|
|
63
|
+
skills: "pi.skills.available",
|
|
64
|
+
compaction: "pi.compaction",
|
|
65
|
+
};
|
package/dist/skills.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Recognising skill loads, and listing the skills pi offers. */
|
|
2
|
+
import { posix } from "node:path";
|
|
3
|
+
const named = (name) => !!name && name !== "." && name !== "..";
|
|
4
|
+
/** A read of `<dir>/SKILL.md` loads skill `<dir>`; a read under `skills/<name>/` reads one of its resources. */
|
|
5
|
+
export function skillFromPath(path) {
|
|
6
|
+
if (typeof path !== "string" || !path)
|
|
7
|
+
return undefined;
|
|
8
|
+
const normal = posix.normalize(path.replace(/\\/g, "/"));
|
|
9
|
+
const load = normal.match(/(?:^|\/)([^/]+)\/SKILL\.md$/);
|
|
10
|
+
if (load)
|
|
11
|
+
return named(load[1]) ? { skill: load[1] } : undefined;
|
|
12
|
+
const resource = normal.match(/(?:^|\/)skills\/([^/]+)\/(.+)$/);
|
|
13
|
+
if (resource && named(resource[1]) && !resource[2].endsWith("/"))
|
|
14
|
+
return { skill: resource[1], resource: resource[2] };
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The skill a shell command prints when the whole command is one read of one SKILL.md
|
|
19
|
+
* (`cat`, `head`, `bat`, `less`, `sed -n '…p'`, optionally after `cd <dir> &&`). Searches, edits, globs and
|
|
20
|
+
* bulk listings mention SKILL.md without loading it, so they do not count.
|
|
21
|
+
*/
|
|
22
|
+
const PRINT = /^(?:cd\s+\S+\s*&&\s*)?(?:cat|bat|less|head(?:\s+-n)?(?:\s+-?\d+)?|sed\s+-n\s+'[\d,$]*p')\s+['"]?([^\s'";|&*?$]+)\/SKILL\.md['"]?\s*$/;
|
|
23
|
+
export function skillsFromCommand(command) {
|
|
24
|
+
if (typeof command !== "string" || !command.includes("SKILL.md"))
|
|
25
|
+
return [];
|
|
26
|
+
const m = command.trim().match(PRINT);
|
|
27
|
+
const name = m?.[1].split("/").at(-1);
|
|
28
|
+
return name && /^[A-Za-z0-9][\w.-]*$/.test(name) ? [name] : [];
|
|
29
|
+
}
|
|
30
|
+
/** Skill names in `<skill name="x" ...>` blocks (a `/skill:` expansion or a declared-skills message). */
|
|
31
|
+
export function skillsFromBlocks(text) {
|
|
32
|
+
if (typeof text !== "string" || !text.includes("<skill name="))
|
|
33
|
+
return [];
|
|
34
|
+
return [...text.matchAll(/<skill name="([^"]+)"/g)].map((m) => m[1]);
|
|
35
|
+
}
|
|
36
|
+
/** Names in the `<available_skills>` section of pi's system prompt. */
|
|
37
|
+
export function skillsFromCatalog(text) {
|
|
38
|
+
if (typeof text !== "string")
|
|
39
|
+
return [];
|
|
40
|
+
return [...text.matchAll(/<skill>\s*<name>([^<]+)<\/name>/g)].map((m) => m[1].trim());
|
|
41
|
+
}
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Appending live records, and reading record files back. */
|
|
2
|
+
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { dayOf } from "./paths.js";
|
|
5
|
+
/** An appender that swallows write failures after reporting the first one through `warn`. */
|
|
6
|
+
export function liveWriter(eventsDir, warn, now = Date.now) {
|
|
7
|
+
let warned = false;
|
|
8
|
+
let made = false;
|
|
9
|
+
return (records) => {
|
|
10
|
+
try {
|
|
11
|
+
if (!made) {
|
|
12
|
+
mkdirSync(eventsDir, { recursive: true });
|
|
13
|
+
made = true;
|
|
14
|
+
}
|
|
15
|
+
const list = Array.isArray(records) ? records : [records];
|
|
16
|
+
if (!list.length)
|
|
17
|
+
return;
|
|
18
|
+
appendFileSync(join(eventsDir, `${dayOf(now())}.jsonl`), list.map((r) => `${JSON.stringify(r)}\n`).join(""));
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (!warned) {
|
|
22
|
+
warned = true;
|
|
23
|
+
warn(`pi-evals: cannot write records (${error instanceof Error ? error.message : String(error)}); later failures in this session stay silent.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** Records in one JSONL file; malformed lines are skipped. */
|
|
29
|
+
export function readRecords(file) {
|
|
30
|
+
if (!existsSync(file))
|
|
31
|
+
return [];
|
|
32
|
+
const out = [];
|
|
33
|
+
for (const line of readFileSync(file, "utf8").split("\n")) {
|
|
34
|
+
if (!line)
|
|
35
|
+
continue;
|
|
36
|
+
try {
|
|
37
|
+
out.push(JSON.parse(line));
|
|
38
|
+
}
|
|
39
|
+
catch { }
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/** Live record files, oldest first. */
|
|
44
|
+
export function liveFiles(eventsDir) {
|
|
45
|
+
if (!existsSync(eventsDir))
|
|
46
|
+
return [];
|
|
47
|
+
return readdirSync(eventsDir)
|
|
48
|
+
.filter((name) => /^\d{4}-\d{2}-\d{2}\.jsonl$/.test(name))
|
|
49
|
+
.sort()
|
|
50
|
+
.map((name) => join(eventsDir, name));
|
|
51
|
+
}
|