pi-evals 0.1.0 → 0.3.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 +13 -0
- package/README.md +29 -9
- package/dist/build.js +4 -3
- package/dist/cli.js +2 -2
- package/dist/coverage.js +8 -1
- package/dist/findings.js +50 -0
- package/dist/index.js +22 -10
- package/dist/model.js +21 -10
- package/dist/ops.js +52 -22
- package/dist/query.js +32 -13
- package/dist/ranges.js +14 -0
- package/dist/render.js +38 -170
- package/dist/report/concepts.js +37 -0
- package/dist/report/findings.js +84 -0
- package/dist/report/format.js +16 -0
- package/dist/report/sections.js +61 -0
- package/dist/report/strip.js +42 -0
- package/dist/report/style.js +85 -0
- package/dist/report/timeline.js +82 -0
- package/dist/report/week.js +44 -0
- package/dist/trends.js +58 -0
- package/docs/design.md +26 -0
- package/docs/learn.zh-TW.md +33 -0
- package/package.json +6 -3
- package/scripts/change-impact.mjs +18 -0
- package/scripts/package-errors.mjs +10 -0
- package/scripts/query-lib.mjs +36 -0
- package/scripts/skill-days.mjs +9 -0
- package/skills/analyzing-evals/SKILL.md +21 -0
- package/src/aggregate.ts +3 -0
- package/src/build.ts +4 -3
- package/src/cli.ts +2 -2
- package/src/coverage.ts +8 -1
- package/src/findings.ts +49 -0
- package/src/index.ts +22 -12
- package/src/model.ts +22 -10
- package/src/ops.ts +49 -22
- package/src/query.ts +29 -13
- package/src/ranges.ts +15 -0
- package/src/render.ts +70 -187
- package/src/report/concepts.ts +94 -0
- package/src/report/findings.ts +102 -0
- package/src/report/format.ts +24 -0
- package/src/report/sections.ts +186 -0
- package/src/report/strip.ts +40 -0
- package/src/report/style.ts +85 -0
- package/src/report/timeline.ts +127 -0
- package/src/report/week.ts +59 -0
- package/src/trends.ts +61 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { concepts, lesson } from "./concepts.js";
|
|
2
|
+
import { overview, readings, value, verdict } from "./findings.js";
|
|
3
|
+
import { esc, num, stamp, title, words } from "./format.js";
|
|
4
|
+
import { changeStrip } from "./strip.js";
|
|
5
|
+
function card(c, id, rs, L) {
|
|
6
|
+
const i = c.impact;
|
|
7
|
+
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
|
|
8
|
+
? L(`Both: ${rs[0].direction}.`, `兩項都${rs[0].direction}。`)
|
|
9
|
+
: 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>`;
|
|
10
|
+
}
|
|
11
|
+
function ruler(c, last, L) {
|
|
12
|
+
const i = c.impact;
|
|
13
|
+
const cutoff = last && last > c.at && last < i.window.after.until ? last : null;
|
|
14
|
+
const points = [
|
|
15
|
+
[i.window.before.since, L("Before starts", "開始算調整前")],
|
|
16
|
+
[c.at, L("Change", "做了調整")],
|
|
17
|
+
...(cutoff ? [[cutoff, L("Last extract", "資料截至這裡")]] : []),
|
|
18
|
+
[i.window.after.until, L("After window ends", "調整後期間結束")],
|
|
19
|
+
];
|
|
20
|
+
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>`;
|
|
21
|
+
}
|
|
22
|
+
function panel(c, side, rs, period, L) {
|
|
23
|
+
const i = c.impact;
|
|
24
|
+
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) => {
|
|
25
|
+
const x = r[side];
|
|
26
|
+
const sample = x?.value != null
|
|
27
|
+
? (r.key === "cost_per_session" ? `${num(x.n)} ${r.unit}` : `${num(Math.round(x.value * x.n))} / ${num(x.n)} ${r.unit}`)
|
|
28
|
+
: L("no eligible records", "沒有適用紀錄");
|
|
29
|
+
return `<div class="reading"><span>${esc(r.label)}</span><b>${value(r, side)} <small>(${sample})</small></b></div>`;
|
|
30
|
+
}).join("")}</article>`;
|
|
31
|
+
}
|
|
32
|
+
function detail(c, id, rs, m, w, lang, siblings) {
|
|
33
|
+
const L = words(lang), i = c.impact, lessons = concepts(m, w, c, L);
|
|
34
|
+
const peers = siblings.filter((s) => s !== c);
|
|
35
|
+
const together = peers.length
|
|
36
|
+
? 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("、")}。`)
|
|
37
|
+
: "";
|
|
38
|
+
const primary = rs[0];
|
|
39
|
+
const age = (Date.parse(m.freshness.lastExtract ?? "") - Date.parse(c.at)) / 3600000;
|
|
40
|
+
const partial = i?.incomplete && age >= 0 && age < i.window.days * 24;
|
|
41
|
+
const ageText = age < 1 ? L("less than an hour", "不到一小時") : L(`about ${Math.floor(age)} hours`, `約 ${Math.floor(age)} 小時`);
|
|
42
|
+
const heading = partial ? L(`Only ${ageText} since the change: too early to tell`, `調整後${ageText},還看不出效果`) : verdict(c, rs, L);
|
|
43
|
+
const fullPeriod = L(`${i?.window.days} days`, `${i?.window.days} 天`);
|
|
44
|
+
const beforePeriod = i?.incomplete ? L(`Planned: ${fullPeriod}`, `原定 ${fullPeriod}`) : fullPeriod;
|
|
45
|
+
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
|
|
46
|
+
? `<p class="deck">${esc(primary.label)}:${value(primary, "before")} → ${value(primary, "after")}。 ${esc(verdict(c, rs, L))}</p>`
|
|
47
|
+
: ""}</div>
|
|
48
|
+
${i
|
|
49
|
+
? `${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>`
|
|
50
|
+
: ""}
|
|
51
|
+
<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>`;
|
|
52
|
+
}
|
|
53
|
+
export function timeline(m, w, lang, range) {
|
|
54
|
+
const L = words(lang), { all, lead, highlighted, folded, headline, trust } = overview(m, lang);
|
|
55
|
+
const ids = new Map(all.map((c, i) => [c, `change-${i + 1}`]));
|
|
56
|
+
const metrics = new Map(all.map((c) => [c, readings(c, m, lang)]));
|
|
57
|
+
const byDay = new Map(), byCommit = new Map();
|
|
58
|
+
for (const c of folded) {
|
|
59
|
+
const d = c.at.slice(0, 10);
|
|
60
|
+
if (!byDay.has(d))
|
|
61
|
+
byDay.set(d, []);
|
|
62
|
+
byDay.get(d).push(c);
|
|
63
|
+
}
|
|
64
|
+
for (const c of all) {
|
|
65
|
+
if (c.sha) {
|
|
66
|
+
const key = `${c.repo}/${c.sha}`;
|
|
67
|
+
if (!byCommit.has(key))
|
|
68
|
+
byCommit.set(key, []);
|
|
69
|
+
byCommit.get(key).push(c);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
lead,
|
|
74
|
+
headline,
|
|
75
|
+
trust,
|
|
76
|
+
strip: changeStrip(m, all, highlighted, ids, lang, range),
|
|
77
|
+
count: highlighted.length,
|
|
78
|
+
cards: highlighted.map((c) => card(c, ids.get(c), metrics.get(c), L)).join(""),
|
|
79
|
+
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(""),
|
|
80
|
+
details: all.map((c) => detail(c, ids.get(c), metrics.get(c), m, w, lang, byCommit.get(`${c.repo}/${c.sha}`) ?? [])).join(""),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { esc, num } from "./format.js";
|
|
2
|
+
/** Workload over the selected dates with records; the extraction day is partial. */
|
|
3
|
+
export function periodRows(m) {
|
|
4
|
+
if (!m.series.days.length || !m.window.until || !m.window.since)
|
|
5
|
+
return [];
|
|
6
|
+
const end = Math.min(Date.parse(m.freshness.lastExtract?.slice(0, 10) ?? m.window.until), Date.parse(m.window.until));
|
|
7
|
+
const positions = new Map(m.series.days.map((d, i) => [d, i]));
|
|
8
|
+
const changes = new Map(), totals = new Map();
|
|
9
|
+
for (const c of m.changes) {
|
|
10
|
+
const day = c.at.slice(0, 10), kinds = changes.get(day) ?? new Set();
|
|
11
|
+
kinds.add(c.kind);
|
|
12
|
+
changes.set(day, kinds);
|
|
13
|
+
totals.set(day, (totals.get(day) ?? 0) + 1);
|
|
14
|
+
}
|
|
15
|
+
const rows = [];
|
|
16
|
+
for (let t = Math.max(Date.parse(m.series.days[0]), Date.parse(m.window.since)); t <= end; t += 86400000) {
|
|
17
|
+
const day = new Date(t).toISOString().slice(0, 10), i = positions.get(day) ?? -1;
|
|
18
|
+
rows.push({
|
|
19
|
+
day,
|
|
20
|
+
sessions: m.series.sessions[i] ?? 0,
|
|
21
|
+
calls: m.series.toolCalls[i] ?? 0,
|
|
22
|
+
loads: m.series.skillLoads[i] ?? 0,
|
|
23
|
+
changes: totals.get(day) ?? 0,
|
|
24
|
+
kinds: [...(changes.get(day) ?? [])],
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return rows;
|
|
28
|
+
}
|
|
29
|
+
export function workload(rows, L) {
|
|
30
|
+
const heading = `<h2>${L("Workload in this period", "這段期間的工作量")}</h2>`;
|
|
31
|
+
if (!rows.length)
|
|
32
|
+
return `<div class="panel">${heading}<p>${L("No records in this period.", "這段期間沒有紀錄。")}</p></div>`;
|
|
33
|
+
const total = (key) => num(rows.reduce((n, r) => n + r[key], 0));
|
|
34
|
+
const max = Math.max(1, ...rows.map((r) => r.sessions));
|
|
35
|
+
const points = rows.map((r, i) => [5 + i * 348 / Math.max(1, rows.length - 1), 89 - 64 * r.sessions / max]);
|
|
36
|
+
const line = points.map((p) => p.join(",")).join(" ");
|
|
37
|
+
const md = (d) => d.slice(5).replace("-", ".");
|
|
38
|
+
const desc = rows.map((r) => `${r.day}: ${num(r.sessions)} ${L("sessions", "段工作")} · ${r.changes} ${L("changes", "筆調整")}`).join("; ");
|
|
39
|
+
return `<div class="panel workload">${heading}<p class="muted">${md(rows[0].day)}–${md(rows.at(-1).day)} / ${L("Through the last extract", "統計至上次抽取")}</p><h3>${total("sessions")} ${L("sessions", "段工作")}</h3><p class="muted">${L("Sessions per day · colored dots mark changes", "每日工作段數 · 彩點表示當日調整類別")}</p>
|
|
40
|
+
<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], i) => rows[i].changes
|
|
41
|
+
? `<g><title>${esc(rows[i].day)}: ${num(rows[i].changes)} ${L("changes", "筆調整")}</title>${rows[i].kinds.map((k, j) => `<circle class="work-mark kind-${esc(k)}" cx="${x}" cy="${5 + 4 * j}" r="1.9"/>`).join("")}</g>`
|
|
42
|
+
: "").join("")}</svg>
|
|
43
|
+
<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>`;
|
|
44
|
+
}
|
package/dist/trends.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ownerFor, sumDays } from "./model.js";
|
|
2
|
+
const DAY = 86_400_000;
|
|
3
|
+
/** Counts by event date; session counts by skill in the index use session start date. */
|
|
4
|
+
export function recentDays(index, project) {
|
|
5
|
+
if (!index.lastExtract || !index.range.start)
|
|
6
|
+
return [];
|
|
7
|
+
const end = Date.parse(index.lastExtract.slice(0, 10));
|
|
8
|
+
const dates = Array.from({ length: 14 }, (_, i) => new Date(end - (14 - i) * DAY).toISOString().slice(0, 10));
|
|
9
|
+
const rows = new Map(sumDays(index, { project, since: dates[0], until: dates[13] }).perDay);
|
|
10
|
+
return dates.filter(d => d >= index.range.start.slice(0, 10)).map(day => ({ day, agg: rows.get(day) }));
|
|
11
|
+
}
|
|
12
|
+
export function trendPair(r) {
|
|
13
|
+
const side = (c) => `${c.errors}/${c.calls} (${(100 * c.errors / c.calls).toFixed(1)}%)`;
|
|
14
|
+
return `${side(r.before)} → ${side(r.after)}`;
|
|
15
|
+
}
|
|
16
|
+
const zero = () => ({ errors: 0, calls: 0 });
|
|
17
|
+
function add(into, from) { into.errors += from.errors; into.calls += from.calls; }
|
|
18
|
+
export function packageCounts(index, day) {
|
|
19
|
+
const by = new Map();
|
|
20
|
+
for (const [tool, count] of Object.entries(day?.tools ?? {})) {
|
|
21
|
+
const owner = ownerFor(index, tool), total = by.get(owner) ?? zero();
|
|
22
|
+
add(total, count);
|
|
23
|
+
by.set(owner, total);
|
|
24
|
+
}
|
|
25
|
+
return by;
|
|
26
|
+
}
|
|
27
|
+
function week(index, rows) {
|
|
28
|
+
const packages = new Map(), monitors = zero();
|
|
29
|
+
for (const { agg } of rows) {
|
|
30
|
+
for (const [owner, count] of packageCounts(index, agg)) {
|
|
31
|
+
const total = packages.get(owner) ?? zero();
|
|
32
|
+
add(total, count);
|
|
33
|
+
packages.set(owner, total);
|
|
34
|
+
}
|
|
35
|
+
if (agg)
|
|
36
|
+
add(monitors, { errors: agg.monitors.statuses.error ?? 0, calls: agg.monitors.finished });
|
|
37
|
+
}
|
|
38
|
+
return { packages, monitors };
|
|
39
|
+
}
|
|
40
|
+
function rise(before, after) {
|
|
41
|
+
if (!before || Math.min(before.calls, after.calls) < 20)
|
|
42
|
+
return;
|
|
43
|
+
// Compare integer counts before rounding the displayed rates (threshold: five percentage points).
|
|
44
|
+
const diff = after.errors * before.calls - before.errors * after.calls;
|
|
45
|
+
if (20 * diff >= before.calls * after.calls)
|
|
46
|
+
return { before, after, delta: diff / before.calls / after.calls };
|
|
47
|
+
}
|
|
48
|
+
export function weeklyRises(index, since, project) {
|
|
49
|
+
const rows = recentDays(index, project);
|
|
50
|
+
if (rows.length !== 14 || (since && Date.parse(rows[0].day) < Date.parse(since) - 86400000))
|
|
51
|
+
return;
|
|
52
|
+
const prev = week(index, rows.slice(0, 7)), curr = week(index, rows.slice(7));
|
|
53
|
+
const packages = [...curr.packages].flatMap(([name, count]) => {
|
|
54
|
+
const r = rise(prev.packages.get(name), count);
|
|
55
|
+
return r ? [{ name, ...r }] : [];
|
|
56
|
+
}).sort((a, b) => b.delta - a.delta || b.after.calls - a.after.calls || a.name.localeCompare(b.name));
|
|
57
|
+
return { start: rows[0].day, end: rows[13].day, packages, monitors: rise(prev.monitors, curr.monitors) };
|
|
58
|
+
}
|
package/docs/design.md
CHANGED
|
@@ -82,6 +82,32 @@ The ReportModel holds every number with its n and window, and the plain-language
|
|
|
82
82
|
The HTML has no scripts, no network and no external assets, uses inline SVG, and follows the system's light or dark setting.
|
|
83
83
|
It renders in Traditional Chinese by default (`--lang en` for English).
|
|
84
84
|
|
|
85
|
+
Version 0.2.0 uses the timeline and comparison layouts selected on 2026-11-26.
|
|
86
|
+
The renderer makes the following editorial choices from the model, without consulting transcripts or fetching data:
|
|
87
|
+
|
|
88
|
+
- A pin or routing change qualifies for the front page even without a comparison; another change qualifies only if both windows have at least 20 sessions.
|
|
89
|
+
- The headline gives priority to a change to the process rules themselves: an anchorloop pin within seven days of the latest change with at least 20 applicable sessions on both sides of the anchor check. Otherwise take the newest qualifying comparison with enough sessions, then the newest qualifying change. With no candidate, report why there is nothing to compare.
|
|
90
|
+
- Show the lead and at most one earlier change from a different commit. Prefer a small sample with records on both sides (to show why the numbers might mislead), then a pin or routing change with a complete window, then the next eligible change. Order the cards by time. Keep every other entry in its UTC day’s disclosure, with a direct link to its detail; no truncation.
|
|
91
|
+
- For an anchorloop pin with two comparable readings of the anchor check, compare the two process rates. Otherwise use the package error rate when available on both sides, or the overall tool error rate, alongside cost per session. Rates use their own denominators, not the total session count. A missing value is a dash, not zero.
|
|
92
|
+
- The headline names the first comparable reading and whether it rose, fell or held steady at the displayed precision. A short window, small sample or overlapping change qualifies that observation. The verdict lists every applicable caveat, including a displayed reading based on fewer than 20 applicable observations on either side. Only a complete, unconfounded comparison with enough observations and a visible difference says there was an observable change. Even that is not a causal claim.
|
|
93
|
+
- The workload chart covers the last seven complete UTC dates in the report period (or fewer if the filter starts later), not seven nonempty days. Each marker means at least one change that day. Session and tool totals in the other sections still cover the selected report period.
|
|
94
|
+
- Each detail uses the model’s actual window and session counts. Dates with records may exceed seven in a seven-day window that starts mid-day. The ruler shows the last extract only when it falls inside the after window, and its segments are not to scale.
|
|
95
|
+
|
|
96
|
+
### Date ranges and findings (0.3.0)
|
|
97
|
+
|
|
98
|
+
The 30-day page opens first; the other pages cover 14 days, 90 days or all indexed dates.
|
|
99
|
+
The last day is the UTC date of extraction, even when the extract is old, so a stale index does not become an apparently quiet month.
|
|
100
|
+
The chart now covers the selected period including the partial last day.
|
|
101
|
+
The report reads the index and checks file coverage once, then reuses the same change comparisons in each narrower period.
|
|
102
|
+
The set of currently offered skills is the reference list; “never loaded” means no loads in the selected dates and project, not that the skill has never been used.
|
|
103
|
+
Coverage counts files modified in the chosen dates and separately shows the cleanup gate across all dates and projects.
|
|
104
|
+
|
|
105
|
+
`findings` uses the timeline’s headline, trust line, selection and verdicts, without copying the text of a commit or manual note.
|
|
106
|
+
For error trends it compares the two seven-day periods immediately before the extraction date, excluding the partial day, only if both weeks fit inside the selection and the index extends to the first date.
|
|
107
|
+
It counts tool errors over calls per package and job endings marked `error` over all recorded endings; both weeks need at least 20 observations and a rise of at least five percentage points.
|
|
108
|
+
If several packages qualify, the largest rise wins, then the larger recent call count, then the package name.
|
|
109
|
+
No flag means no rise met that rule, not proof that nothing went wrong.
|
|
110
|
+
|
|
85
111
|
### Storage choices
|
|
86
112
|
|
|
87
113
|
JSON lines and JSON files, no database: the index is rebuilt from per-session summaries in about a second, and the reader needs no service (research §4: everything reduces to files plus one static page).
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# 怎麼讀一次調整的結果
|
|
2
|
+
|
|
3
|
+
2026 年 11 月 25 日更新 pi-anchorloop 後,動手前先說好驗證方法的比例從 20.3% 降到 12.5%。
|
|
4
|
+
但報表產生時,新版才用了八個多小時。
|
|
5
|
+
以下數字取自當時的報表;下次抽取後,調整後的那一組還會變。
|
|
6
|
+
|
|
7
|
+
## 紀錄:當時做了什麼
|
|
8
|
+
|
|
9
|
+
代理人讀了一份技能說明,就留下一筆載入紀錄。
|
|
10
|
+
11 月 19 日至 25 日共計有 2,619 次技能載入;知道載入了幾次,不必知道對話裡說了什麼。
|
|
11
|
+
|
|
12
|
+
## 指標:用同一個算法數紀錄
|
|
13
|
+
|
|
14
|
+
同一週,按開始時間計算,共有 5,246 段工作。
|
|
15
|
+
工作段數是工作量的指標:一段工作載入三次技能,仍只有一段工作。
|
|
16
|
+
工作段數變多,不等於工作品質更好。
|
|
17
|
+
|
|
18
|
+
## 程式檢查:查得到先後,查不到方法好壞
|
|
19
|
+
|
|
20
|
+
調整後,有 6 段工作在改檔前就說好怎麼驗證,通過了這條檢查。
|
|
21
|
+
程式查的是「先說方法,再改檔」的順序;就算順序正確,那個方法也可能驗不到要修的問題。
|
|
22
|
+
|
|
23
|
+
## 前後比較與樣本數:哪幾段工作算進去了
|
|
24
|
+
|
|
25
|
+
以更新時間 16:46 UTC 為界,前面有 5,171 段工作,後面有 164 段。
|
|
26
|
+
後面這組只有 48 段適用「動手前先說好怎麼驗證」,所以 6 段通過是 6 / 48,也就是 12.5%,不是 6 / 164。
|
|
27
|
+
看另一條規則時,適用的工作不同,樣本數也會不同。
|
|
28
|
+
|
|
29
|
+
## 同期多個調整:原因還不能指給某個版本
|
|
30
|
+
|
|
31
|
+
同一段比較期間還有 76 筆別的調整。
|
|
32
|
+
如果規則和模型分派都改過,前後即使有差異,也不能只歸給套件更新。
|
|
33
|
+
等七天的資料收齊,可以重看比例;資料收齊本身不會排除其他調整的影響。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-evals",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Usage and process records for pi: how skills, packages, ask-user, monitors and subagents are used, back-filled from past sessions, with a static report and an evals_query tool",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,12 +21,14 @@
|
|
|
21
21
|
"opentelemetry"
|
|
22
22
|
],
|
|
23
23
|
"bin": {
|
|
24
|
-
"pi-evals": "
|
|
24
|
+
"pi-evals": "dist/cli.js"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
27
|
"src",
|
|
28
28
|
"dist",
|
|
29
29
|
"docs",
|
|
30
|
+
"scripts",
|
|
31
|
+
"skills",
|
|
30
32
|
"README.md",
|
|
31
33
|
"CHANGELOG.md",
|
|
32
34
|
"LICENSE"
|
|
@@ -34,7 +36,8 @@
|
|
|
34
36
|
"pi": {
|
|
35
37
|
"extensions": [
|
|
36
38
|
"./src/index.ts"
|
|
37
|
-
]
|
|
39
|
+
],
|
|
40
|
+
"skills": ["./skills"]
|
|
38
41
|
},
|
|
39
42
|
"scripts": {
|
|
40
43
|
"build": "tsc -p tsconfig.build.json",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { QueryError, report, run, safeName } from './query-lib.mjs';
|
|
2
|
+
|
|
3
|
+
const usage = 'node change-impact.mjs UTC_TIMESTAMP_OR_SHA [PACKAGE_OR_KIND]';
|
|
4
|
+
run(usage, args => {
|
|
5
|
+
if (args.length > 2) throw new QueryError(usage);
|
|
6
|
+
const [id, which] = args, m = report();
|
|
7
|
+
const hits = m.changes.filter(c => (c.at === id || c.sha === id) && (!which || c.package === which || c.kind === which));
|
|
8
|
+
if (hits.length !== 1) throw new QueryError(hits.length ? 'Multiple entries match; specify a package or change kind.' : 'No such change in the saved report.');
|
|
9
|
+
const { at, impact: i } = hits[0];
|
|
10
|
+
const header = `${at}; extract ${m.freshness.lastExtract ?? 'never'}; ${m.window.project ? safeName(m.window.project) : 'all projects'}`;
|
|
11
|
+
if (!i) return [header, 'No earlier records.'];
|
|
12
|
+
const rows = [header, `${i.window.days} days each side; sessions ${i.before.sessions} → ${i.after.sessions}`, `Too few sessions: ${i.smallSample}; incomplete window: ${i.incomplete}; other changes: ${i.confounded}. A difference does not prove cause.`];
|
|
13
|
+
for (const key of ['tool_error_rate', 'package_error_rate', 'ask_cancel_rate', 'cost_per_session', 'skill_loads_per_session', 'notices_per_session', 'anchor_before_first_edit', 'check_after_last_edit', 'todo_evidence']) {
|
|
14
|
+
const format = r => !r || r.value == null ? 'n/a (n=0)' : `${r.value.toFixed(4)} (n=${r.n})`;
|
|
15
|
+
rows.push(`${key}: ${format(i.before[key])} → ${format(i.after[key])}`);
|
|
16
|
+
}
|
|
17
|
+
return rows;
|
|
18
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { daily, packageCounts, QueryError, run } from './query-lib.mjs';
|
|
2
|
+
|
|
3
|
+
const usage = 'node package-errors.mjs PACKAGE [PROJECT]';
|
|
4
|
+
run(usage, args => {
|
|
5
|
+
if (args.length > 2) throw new QueryError(usage);
|
|
6
|
+
const [pkg, project] = args, { rows, index, header } = daily(project);
|
|
7
|
+
const counts = rows.map(({ day, agg }) => ({ day, count: packageCounts(index, agg).get(pkg) }));
|
|
8
|
+
if (!counts.some(x => x.count)) throw new QueryError('No calls for this package in the selected days and project.');
|
|
9
|
+
return [header, `${pkg}: tool errors/calls`, ...counts.map(({ day, count }) => `${day} ${count?.errors ?? 0}/${count?.calls ?? 0} ${count?.calls ? (100 * count.errors / count.calls).toFixed(1) + '%' : 'n/a'}`)];
|
|
10
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
// Node strips types in checkouts but forbids it under node_modules. npm ships dist there.
|
|
4
|
+
const installed = new URL(import.meta.url).pathname.split('/').includes('node_modules');
|
|
5
|
+
const load = name => import(installed ? `../dist/${name}.js` : `../src/${name}.ts`);
|
|
6
|
+
const [{ layout }, { loadIndex }, { recentDays, packageCounts }, { safeName }] = await Promise.all(
|
|
7
|
+
['paths', 'build', 'trends', 'schema'].map(load),
|
|
8
|
+
);
|
|
9
|
+
export { packageCounts, safeName };
|
|
10
|
+
|
|
11
|
+
export function run(usage, fn) {
|
|
12
|
+
try {
|
|
13
|
+
const args = process.argv.slice(2);
|
|
14
|
+
if (!args.length || args.some(x => !x || safeName(x) !== x)) throw new Error(usage);
|
|
15
|
+
const text = fn(args).join('\n') + '\n';
|
|
16
|
+
if (Buffer.byteLength(text) > 2000) throw new Error('Result exceeds the output limit.');
|
|
17
|
+
process.stdout.write(text);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
// Never echo unknown arguments, local paths or JSON parse excerpts.
|
|
20
|
+
console.error(error instanceof QueryError ? error.message : `Cannot read query. ${usage}`);
|
|
21
|
+
process.exitCode = 1;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class QueryError extends Error {}
|
|
25
|
+
export function daily(project) {
|
|
26
|
+
const index = loadIndex(layout());
|
|
27
|
+
if (!index) throw new QueryError('No index. Run /evals extract first.');
|
|
28
|
+
return { rows: recentDays(index, project), index, header: `Extract ${index.lastExtract ?? 'never'}; complete UTC dates${project ? `; project ${project}` : '; all projects'}` };
|
|
29
|
+
}
|
|
30
|
+
export function report() {
|
|
31
|
+
const range = process.env.PI_EVALS_REPORT_RANGE ?? '30';
|
|
32
|
+
const files = new Map([['14', 'model-14d.json'], ['30', 'model.json'], ['90', 'model-90d.json'], ['all', 'model-all.json'], ['custom', 'model-custom.json']]);
|
|
33
|
+
if (!files.has(range)) throw new QueryError('Choose PI_EVALS_REPORT_RANGE=14, 30, 90, all or custom.');
|
|
34
|
+
try { return JSON.parse(readFileSync(join(layout().reports, files.get(range)), 'utf8')); }
|
|
35
|
+
catch { throw new QueryError('No readable report model. Run /evals report first.'); }
|
|
36
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { daily, QueryError, run } from './query-lib.mjs';
|
|
2
|
+
|
|
3
|
+
const usage = 'node skill-days.mjs SKILL [PROJECT]';
|
|
4
|
+
run(usage, args => {
|
|
5
|
+
if (args.length > 2) throw new QueryError(usage);
|
|
6
|
+
const [skill, project] = args, { rows, index, header } = daily(project);
|
|
7
|
+
if (!index.offeredSkills.includes(skill) && !Object.values(index.days).some(projects => Object.values(projects).some(a => Object.hasOwn(a.skillSessions, skill)))) throw new QueryError('Skill not found in index.');
|
|
8
|
+
return [header, `${skill}: sessions that loaded the skill, by session start date`, ...rows.map(({ day, agg }) => `${day} ${agg && Object.hasOwn(agg.skillSessions, skill) ? agg.skillSessions[skill] : 0}`)];
|
|
9
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: analyzing-evals
|
|
3
|
+
description: Use when the user asks how their agents, skills or packages are doing, what a setup change did, or how to read the pi-evals report.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Analyze agent activity
|
|
7
|
+
|
|
8
|
+
1. Call `evals_query` with `view: "findings"` first. Check the dates and last extraction; default is the latest 30 UTC dates in the index. Use `since` or `project` when the question specifies a narrower scope.
|
|
9
|
+
2. Follow **one** pointer that answers the question. For a weekly change in tool errors use `packages`; for a rule about editing use `process`. Keep the same filters. Stop when the numbers answer the question.
|
|
10
|
+
3. If one detail is still missing, run one script below. Set `SCRIPTS` to the absolute path on the `Scripts:` line or in `details.scriptsDir`. For a default npm install, the fallback is `SCRIPTS="$HOME/.pi/agent/npm/node_modules/pi-evals/scripts"`. Check `test -f "$SCRIPTS/query-lib.mjs"` before running a query; if it fails, stop rather than guessing another path. Use exact identifiers returned by the view; none of these commands reads a transcript.
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
node "$SCRIPTS/change-impact.mjs" UTC_TIMESTAMP_OR_SHA [PACKAGE_OR_KIND]
|
|
14
|
+
node "$SCRIPTS/skill-days.mjs" SKILL [PROJECT]
|
|
15
|
+
node "$SCRIPTS/package-errors.mjs" PACKAGE [PROJECT]
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The first reads the saved `reports/model.json`: check its extract time and project before using the comparison. For a different saved page, prefix the command with `PI_EVALS_REPORT_RANGE=14`, `90`, `all` or `custom`. If the file is missing or out of date, say so; `/evals report` rebuilds the preset pages.
|
|
19
|
+
The other two read the last 14 complete UTC dates in the index. Skill sessions count on their start date; package errors count on the date of the call. Neither script treats zero calls as a 0% error rate.
|
|
20
|
+
|
|
21
|
+
Lead with what rose, fell or held steady, and give the counts behind the rates. Say “too early to tell” when a side is short or too small; when other changes landed nearby, say “we cannot tell which change mattered.” Even a clear difference is not proof of cause. More sessions or skill loads measure activity, not better work.
|
package/src/aggregate.ts
CHANGED
|
@@ -164,6 +164,9 @@ export interface SessionSummary {
|
|
|
164
164
|
* version split read, so a change at 16:00 splits a day's sessions at 16:00 rather than at midnight.
|
|
165
165
|
*/
|
|
166
166
|
export interface SessionRow {
|
|
167
|
+
/** Used for the date/project-scoped labels join. Older indices lack these two fields. */
|
|
168
|
+
id?: string;
|
|
169
|
+
linked?: boolean;
|
|
167
170
|
/** Start, ISO. */
|
|
168
171
|
s: string;
|
|
169
172
|
p: string;
|
package/src/build.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { addLabel, bucketOf, bump, type DayAgg, emptyDay, mergeDay, rowOf, type
|
|
|
10
10
|
import { buildChanges, type Change, versionAt, writeChanges } from "./changes.ts";
|
|
11
11
|
import type { Checkpoint } from "./extract/run.ts";
|
|
12
12
|
import { dayOf, type Layout, type Settings } from "./paths.ts";
|
|
13
|
-
import { type EvalRecord, NAMES } from "./schema.ts";
|
|
13
|
+
import { type EvalRecord, NAMES, traceId } from "./schema.ts";
|
|
14
14
|
import { liveFiles, readRecords } from "./store.ts";
|
|
15
15
|
|
|
16
16
|
export interface DaysIndex {
|
|
@@ -200,7 +200,8 @@ export function buildIndex(options: { layout: Layout; settings: Settings; checkp
|
|
|
200
200
|
}
|
|
201
201
|
if (Object.keys(labels).length) sessionEvals[s.sessionId] = labels;
|
|
202
202
|
add(s.project, days);
|
|
203
|
-
rows.push(rowOf(s.start, s.project, s.kind === "subagent", s.cost, days, s.evals))
|
|
203
|
+
rows.push({ ...rowOf(s.start, s.project, s.kind === "subagent", s.cost, days, s.evals), id: traceId(s.sessionId, "labels"),
|
|
204
|
+
linked: s.kind === "subagent" ? Boolean(s.parentId || (s.logicalId && links.has(s.logicalId))) : undefined });
|
|
204
205
|
}
|
|
205
206
|
let liveOnly = 0;
|
|
206
207
|
for (const [id, records] of bySession) {
|
|
@@ -208,7 +209,7 @@ export function buildIndex(options: { layout: Layout; settings: Settings; checkp
|
|
|
208
209
|
liveOnly += 1;
|
|
209
210
|
const summary = liveSummary(records);
|
|
210
211
|
add(summary.project, summary.days);
|
|
211
|
-
rows.push(rowOf(summary.start, summary.project, records.some((r) => r.name === NAMES.session && r.attrs["pi.session.kind"] === "subagent"), 0, summary.days));
|
|
212
|
+
rows.push({ ...rowOf(summary.start, summary.project, records.some((r) => r.name === NAMES.session && r.attrs["pi.session.kind"] === "subagent"), 0, summary.days), id: traceId(id, "labels"), linked: false });
|
|
212
213
|
}
|
|
213
214
|
|
|
214
215
|
const owners: DaysIndex["owners"] = {};
|
package/src/cli.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { query, type View, VIEWS } from "./query.ts";
|
|
|
5
5
|
|
|
6
6
|
const USAGE = `usage:
|
|
7
7
|
pi-evals extract [--root <dir>]... [--workers <n>] [--json]
|
|
8
|
-
pi-evals report [--out <dir>] [--since YYYY-MM-DD] [--project <key>] [--lang zh|en]
|
|
8
|
+
pi-evals report [--out <dir>] [--since YYYY-MM-DD | --days N] [--project <key>] [--lang zh|en]
|
|
9
9
|
pi-evals status
|
|
10
10
|
pi-evals query <${VIEWS.join("|")}> [--since YYYY-MM-DD] [--project <key>]
|
|
11
11
|
pi-evals mark <note>`;
|
|
@@ -49,7 +49,7 @@ async function main(argv: string[]): Promise<number> {
|
|
|
49
49
|
}
|
|
50
50
|
if (cmd === "report") {
|
|
51
51
|
const lang = flag(args, "--lang") === "en" ? "en" : "zh";
|
|
52
|
-
const out = runReport({ outDir: flag(args, "--out"), filter: { since: flag(args, "--since"), project: flag(args, "--project") }, lang });
|
|
52
|
+
const out = runReport({ outDir: flag(args, "--out"), filter: { since: flag(args, "--since"), days: args.includes("--days") ? Number(flag(args, "--days")) : undefined, project: flag(args, "--project") }, lang });
|
|
53
53
|
if (!out) {
|
|
54
54
|
console.error("nothing extracted yet: run pi-evals extract");
|
|
55
55
|
return 1;
|
package/src/coverage.ts
CHANGED
|
@@ -3,6 +3,8 @@ import type { Checkpoint } from "./extract/run.ts";
|
|
|
3
3
|
import { listSessionFiles } from "./extract/run.ts";
|
|
4
4
|
|
|
5
5
|
export interface Coverage {
|
|
6
|
+
/** Files whose modification date falls in the selected report dates (all projects). */
|
|
7
|
+
inRange?: { files: number; indexed: number };
|
|
6
8
|
cutDays: number;
|
|
7
9
|
cutoff: string;
|
|
8
10
|
old: { files: number; bytes: number };
|
|
@@ -13,7 +15,7 @@ export interface Coverage {
|
|
|
13
15
|
retainedGone: number;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
export function coverage(roots: string[], checkpoint: Checkpoint, cutDays: number, now = Date.now()): Coverage {
|
|
18
|
+
export function coverage(roots: string[], checkpoint: Checkpoint, cutDays: number, now = Date.now(), activity?: Map<string, { files: number; indexed: number }>): Coverage {
|
|
17
19
|
const cutoff = now - cutDays * 86_400_000;
|
|
18
20
|
const files = listSessionFiles(roots);
|
|
19
21
|
const result: Coverage = {
|
|
@@ -32,6 +34,11 @@ export function coverage(roots: string[], checkpoint: Checkpoint, cutDays: numbe
|
|
|
32
34
|
const known = checkpoint.files[f.path];
|
|
33
35
|
const fresh = !!known && known.size === f.size && known.mtimeMs === f.mtimeMs;
|
|
34
36
|
if (fresh) result.all.indexedFiles += 1;
|
|
37
|
+
if (activity) {
|
|
38
|
+
const day = new Date(f.mtimeMs).toISOString().slice(0, 10), row = activity.get(day) ?? { files: 0, indexed: 0 };
|
|
39
|
+
row.files++; if (fresh) row.indexed++;
|
|
40
|
+
activity.set(day, row);
|
|
41
|
+
}
|
|
35
42
|
if (f.mtimeMs >= cutoff) continue;
|
|
36
43
|
result.old.files += 1;
|
|
37
44
|
result.old.bytes += f.size;
|
package/src/findings.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import type { ReportModel } from "./model.ts";
|
|
3
|
+
import { overview, readings, value, verdict } from "./report/findings.ts";
|
|
4
|
+
import { words } from "./report/format.ts";
|
|
5
|
+
import { safeName } from "./schema.ts";
|
|
6
|
+
import { trendPair } from "./trends.ts";
|
|
7
|
+
|
|
8
|
+
export const scriptsDir = fileURLToPath(new URL("../scripts", import.meta.url));
|
|
9
|
+
|
|
10
|
+
/** Shorten only identifiers, never a verdict or its drill-down pointer. */
|
|
11
|
+
function name(s: string) {
|
|
12
|
+
const chars = Array.from(safeName(s));
|
|
13
|
+
if (Buffer.byteLength(chars.join("")) <= 72) return chars.join("");
|
|
14
|
+
while (Buffer.byteLength(chars.join("")) > 69) chars.pop();
|
|
15
|
+
return chars.join("") + "…";
|
|
16
|
+
}
|
|
17
|
+
export function findings(m: ReportModel) {
|
|
18
|
+
const { headline, trust, highlighted } = overview(m, "en"), L = words("en");
|
|
19
|
+
const lines = [
|
|
20
|
+
`${m.window.since ?? "?"}..${m.window.until ?? "?"} UTC${m.window.project ? ` · ${name(m.window.project)}` : ""} · ${m.freshness.stale ? "STALE: " : ""}last extract ${m.freshness.lastExtract ?? "never"} → coverage`,
|
|
21
|
+
`Scripts: ${scriptsDir}`, `${headline} → changes`, `${trust} → changes`,
|
|
22
|
+
];
|
|
23
|
+
const extras: { line: number; prefix: string; metric: string }[] = [];
|
|
24
|
+
for (const c of highlighted) {
|
|
25
|
+
const id = c.package ? `${name(c.package)} ${name(c.to ?? "unknown")}` : c.kind;
|
|
26
|
+
const rs = readings(c, m, "en"), r = rs.find(row => row.before?.value != null && row.after?.value != null);
|
|
27
|
+
const metric = r ? `${r.label} ${value(r, "before")} → ${value(r, "after")}; ` : "";
|
|
28
|
+
const prefix = `${c.at} ${id}: `;
|
|
29
|
+
extras.push({ line: lines.length, prefix, metric });
|
|
30
|
+
lines.push(`${prefix}${verdict(c, rs, L)} → changes`);
|
|
31
|
+
}
|
|
32
|
+
const unseen = m.skills.neverLoaded.length;
|
|
33
|
+
lines.push(`${unseen}/${m.skills.offered} offered skills never loaded in range → skills`);
|
|
34
|
+
const cov = m.coverage;
|
|
35
|
+
const gate = !cov ? "not measured" : !cov.old.files ? "no old files" : cov.notIndexed.files || cov.notIndexed.bytes
|
|
36
|
+
? `blocked: ${cov.notIndexed.files}/${cov.old.files} old files not indexed` : `all ${cov.old.files} old files indexed`;
|
|
37
|
+
lines.push(`Cleanup (all projects/dates): ${gate} → coverage`);
|
|
38
|
+
const w = m.weekly;
|
|
39
|
+
if (!w) lines.push("Need two weeks in range for error trends → packages / monitors");
|
|
40
|
+
else {
|
|
41
|
+
const p = w.packages[0];
|
|
42
|
+
lines.push(`${w.start}..${w.end} UTC, earlier week vs later: ${p ? `${p.name === "unknown" ? "tools with no known package" : name(p.name)} errors/calls ${trendPair(p)}` : "no package rise flagged"} → packages`);
|
|
43
|
+
lines.push(`Same weeks: ${w.monitors ? `failed/finished jobs ${trendPair(w.monitors)}` : "no job error rise flagged"} → monitors`);
|
|
44
|
+
}
|
|
45
|
+
for (const { line, prefix, metric } of extras) {
|
|
46
|
+
if (Buffer.byteLength(lines.join("\n") + metric) <= 1499) lines[line] = prefix + metric + lines[line].slice(prefix.length);
|
|
47
|
+
}
|
|
48
|
+
return lines.join("\n");
|
|
49
|
+
}
|