pi-evals 0.4.1 → 0.5.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 +8 -0
- package/README.md +23 -4
- package/dist/findings.js +4 -0
- package/dist/index.js +9 -4
- package/dist/labels-query.js +35 -0
- package/dist/labels.js +211 -0
- package/dist/live-labels.js +128 -0
- package/dist/model.js +9 -43
- package/dist/observer.js +8 -2
- package/dist/ops.js +2 -1
- package/dist/query.js +5 -1
- package/dist/render.js +1 -0
- package/dist/report/concepts.js +14 -0
- package/dist/report/sections.js +18 -3
- package/dist/work/track.js +10 -4
- package/docs/design.md +19 -1
- package/docs/schema.md +22 -4
- package/package.json +4 -2
- package/skills/analyzing-evals/SKILL.md +3 -1
- package/src/findings.ts +3 -0
- package/src/index.ts +8 -4
- package/src/labels-query.ts +36 -0
- package/src/labels.ts +248 -0
- package/src/live-labels.ts +140 -0
- package/src/model.ts +11 -47
- package/src/observer.ts +13 -3
- package/src/ops.ts +2 -1
- package/src/query.ts +4 -1
- package/src/render.ts +1 -0
- package/src/report/concepts.ts +18 -0
- package/src/report/sections.ts +42 -9
- package/src/work/track.ts +11 -2
package/dist/observer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ownerOf } from "./owners.js";
|
|
2
2
|
import { projectKey } from "./project.js";
|
|
3
|
-
import { NAMES, record, spanId, traceId } from "./schema.js";
|
|
3
|
+
import { NAMES, record, safeName, spanId, traceId } from "./schema.js";
|
|
4
4
|
import { skillFromPath, skillsFromBlocks, skillsFromCommand } from "./skills.js";
|
|
5
5
|
import { liveWriter } from "./store.js";
|
|
6
6
|
import { logicalIdOf } from "./extract/session.js";
|
|
@@ -21,10 +21,14 @@ export function observe(pi, options) {
|
|
|
21
21
|
let unsubscribe = [];
|
|
22
22
|
let write = () => { };
|
|
23
23
|
let hasUI = false;
|
|
24
|
+
let loaded = new Set();
|
|
24
25
|
const iso = (t) => new Date(t).toISOString();
|
|
25
26
|
const base = () => ({ "session.id": sessionId, "pi.project": project });
|
|
26
27
|
const emit = (fields) => write(record(fields));
|
|
27
|
-
const skillLoad = (skill, trigger, callId) =>
|
|
28
|
+
const skillLoad = (skill, trigger, callId) => {
|
|
29
|
+
loaded.add(skill);
|
|
30
|
+
emit({ name: NAMES.skill, kind: "event", ts: iso(now()), source: "live", trace_id: trace, attrs: { ...base(), "gen_ai.skill.name": skill, "pi.skill.trigger": trigger, "gen_ai.tool.call.id": callId } });
|
|
31
|
+
};
|
|
28
32
|
const snapshot = () => {
|
|
29
33
|
if (snapshotTaken)
|
|
30
34
|
return;
|
|
@@ -89,6 +93,7 @@ export function observe(pi, options) {
|
|
|
89
93
|
remoteAnswers = new Set();
|
|
90
94
|
monitorStarts = new Map();
|
|
91
95
|
monitorsDone = new Set();
|
|
96
|
+
loaded = new Set();
|
|
92
97
|
let file;
|
|
93
98
|
try {
|
|
94
99
|
file = ctx.sessionManager.getSessionFile?.();
|
|
@@ -237,4 +242,5 @@ export function observe(pi, options) {
|
|
|
237
242
|
attrs,
|
|
238
243
|
});
|
|
239
244
|
});
|
|
245
|
+
return { skills: () => [...new Set([...loaded].map((name) => safeName(name)))].filter((n) => n !== "redacted").sort() };
|
|
240
246
|
}
|
package/dist/ops.js
CHANGED
|
@@ -66,7 +66,8 @@ function snapshot(env, withCoverage = true) {
|
|
|
66
66
|
const cov = withCoverage ? coverageReader(ctx, now) : undefined;
|
|
67
67
|
return { index, build(input, preset, comparisons) {
|
|
68
68
|
const filter = rangeFilter(input, index.lastExtract ?? now.toISOString(), preset);
|
|
69
|
-
|
|
69
|
+
// A range ends at the last extract unless the user ends it; a label given since then has no session in the index yet.
|
|
70
|
+
return buildModel({ index, rows, changes, comparisons, filter, now, windowDays: ctx.settings.impactWindowDays, openEnd: input.until === undefined,
|
|
70
71
|
labelsFile: ctx.layout.labels, sessionEvalsFile: ctx.layout.sessionEvals, coverage: cov?.(filter), work });
|
|
71
72
|
} };
|
|
72
73
|
}
|
package/dist/query.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/** `evals_query`: bounded plain-text summaries of the index for an agent (names and numbers only, under 2 KB). */
|
|
2
2
|
import { coverageInRange, indexedModel, reportPath } from "./ops.js";
|
|
3
3
|
import { findings } from "./findings.js";
|
|
4
|
+
import { labelsView } from "./labels-query.js";
|
|
4
5
|
import { select } from "./report/findings.js";
|
|
5
6
|
import { itemsView } from "./work/query.js";
|
|
6
|
-
export const VIEWS = ["findings", "items", "skills", "packages", "ask_user", "monitors", "subagents", "process", "cost", "changes", "coverage"];
|
|
7
|
+
export const VIEWS = ["findings", "items", "labels", "skills", "packages", "ask_user", "monitors", "subagents", "process", "cost", "changes", "coverage"];
|
|
7
8
|
export const MAX_BYTES = 1900;
|
|
8
9
|
const pct = (r) => (r && r.value !== null ? `${(r.value * 100).toFixed(1)}% (n=${r.n})` : `n/a (n=${r?.n ?? 0})`);
|
|
9
10
|
const sec = (v) => (v === null ? "n/a" : `${(v / 1000).toFixed(1)}s`);
|
|
@@ -99,6 +100,9 @@ export function query(view, options = {}) {
|
|
|
99
100
|
else if (view === "items") {
|
|
100
101
|
body.push(...itemsView(m.work));
|
|
101
102
|
}
|
|
103
|
+
else if (view === "labels") {
|
|
104
|
+
body.push(...labelsView(m));
|
|
105
|
+
}
|
|
102
106
|
else if (view === "changes") {
|
|
103
107
|
body.push("highlighted then newest changes, sessions split at the change time, metric before -> after; flags: small = <20 sessions a side, incomplete = a window runs past the data, confounded = other commits nearby");
|
|
104
108
|
const { highlighted, folded } = select(m);
|
package/dist/render.js
CHANGED
|
@@ -27,6 +27,7 @@ export function renderHtml(m, lang = "zh", range = "custom") {
|
|
|
27
27
|
["cost", L("Cost", "費用")],
|
|
28
28
|
["coverage", L("Cleanup", "清理門檻")],
|
|
29
29
|
["labels", L("Labels", "你的標記")],
|
|
30
|
+
["corrections", L("Corrections", "被糾正")],
|
|
30
31
|
["concepts", L("Concepts", "概念")],
|
|
31
32
|
];
|
|
32
33
|
const date = m.generated.slice(0, 10);
|
package/dist/report/concepts.js
CHANGED
|
@@ -20,6 +20,19 @@ function workCards(m, L) {
|
|
|
20
20
|
],
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
+
/** When a label was given, with this report's numbers. */
|
|
24
|
+
function labelTiming(m, L) {
|
|
25
|
+
const l = m.labels, name = (d) => m.meta.detectors[d]?.label[L("en", "zh")] ?? d;
|
|
26
|
+
const pairs = l.agreement.filter((r) => r.bySource.batch.n).map((r) => [name(r.detector), `${num(r.bySource.batch.agree)}/${num(r.bySource.batch.n)}`]);
|
|
27
|
+
const en = pairs.map(([d, v]) => `${v} on "${d}"`).join(", "), zh = pairs.map(([d, v]) => `「${d}」${v}`).join("、");
|
|
28
|
+
const fact = l.sessions.batch
|
|
29
|
+
? L(`So far ${num(l.sessions.batch)} sessions were labelled after the fact; the code agreed with you ${en || "on none that it judged"}.`, `目前事後標了 ${num(l.sessions.batch)} 段工作,程式和你一致的有:${zh || "沒有程式判斷可比"}。`)
|
|
30
|
+
: L("No sessions were labelled after the fact yet.", "目前還沒有事後標記。");
|
|
31
|
+
return [
|
|
32
|
+
L("Labelled in the moment vs after the fact", "當下標記 vs 事後標記"),
|
|
33
|
+
L(`After the fact means judging later from a summary an AI wrote; in the moment means judging with /evals label while the work is in front of you. ${fact} A summary leaves things out, so when agreement is low it may be the summary or the code; labels after the fact alone cannot tell which. In-the-moment labels so far: ${num(l.bySource.live)}. Once each kind has at least 20, comparing their agreement shows where the gap comes from.`, `事後標記是事情過了,讀 AI 寫的摘要再判斷;當下標記是工作還在眼前時,用 /evals label 直接判斷。${fact}摘要會漏掉細節,所以一致比例偏低時,可能是摘要沒寫清楚,也可能是程式判斷錯了,只看事後標記分不出來。當下標記目前 ${num(l.bySource.live)} 筆;兩種各累積到至少 20 筆,比較兩邊的一致比例,才看得出落差從哪裡來。`),
|
|
34
|
+
];
|
|
35
|
+
}
|
|
23
36
|
export function concepts(m, week, c, L) {
|
|
24
37
|
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");
|
|
25
38
|
return {
|
|
@@ -44,6 +57,7 @@ export function concepts(m, week, c, L) {
|
|
|
44
57
|
: L(`There are ${num(m.changes.length)} changes on this timeline. Check what else changed before crediting a new version.`, `時間軸有 ${num(m.changes.length)} 筆調整。要把差異歸給某個版本,得先查同一期間還改了什麼。`),
|
|
45
58
|
],
|
|
46
59
|
...workCards(m, L),
|
|
60
|
+
labelTiming: labelTiming(m, L),
|
|
47
61
|
check: [
|
|
48
62
|
L("Code check", "程式檢查"),
|
|
49
63
|
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)} 段適用的工作裡查「改檔前有沒有先說怎麼驗證」。它看得出先後順序,判斷不了方法好不好。`),
|
package/dist/report/sections.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { FAILURE_TYPE_META, ruleLabel } from "../labels.js";
|
|
2
|
+
import { SMALL_SAMPLE } from "../model.js";
|
|
1
3
|
import { lesson, selfCheck } from "./concepts.js";
|
|
2
4
|
import { duration, esc, num, pct, table, usd, words } from "./format.js";
|
|
3
5
|
import { workSection } from "./work.js";
|
|
@@ -44,9 +46,21 @@ export function sections(m, lang, cards) {
|
|
|
44
46
|
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
|
|
45
47
|
? `<p>${L("Files modified in the selected dates, indexed (all projects)", "選定日期內有修改的檔案,已建索引(全部專案)")}:${num(cov.inRange?.indexed ?? 0)} / ${num(cov.inRange?.files ?? 0)}</p><p>${L("Cleanup gate across all dates", "清理門檻不分日期")} · ${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>`
|
|
46
48
|
: `<p>${L("Coverage not measured; keep cleanup off.", "沒有索引覆蓋資料,請勿開啟清理。")}</p>`);
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
const lb = m.labels, rule = (r) => ruleLabel(r, lang);
|
|
50
|
+
const pair = (c) => (c.n ? `${num(c.agree)} / ${num(c.n)}` : "—");
|
|
51
|
+
const labels = section("labels", L("Your labels", "你的標記"), meta.agreement.meaning[lang], lb.needsIndex ? `<p>${L("Run /evals extract to count labels in this period.", "請執行 /evals extract 以計算這段期間的標記。")}</p>` : lb.present && lb.n
|
|
52
|
+
? `<p>${L(`After the fact ${num(lb.bySource.batch)} (${num(lb.sessions.batch)} sessions) / In the moment ${num(lb.bySource.live)} (${num(lb.sessions.live)} sessions)`, `事後標 ${num(lb.bySource.batch)} 筆(${num(lb.sessions.batch)} 段工作) / 當下標 ${num(lb.bySource.live)} 筆(${num(lb.sessions.live)} 段工作)`)}${lb.fromWords ? L(`; ${num(lb.fromWords)} of them the agent wrote from your words`, `;其中 ${num(lb.fromWords)} 筆是代理人依你的話整理的`) : ""}</p>` +
|
|
53
|
+
T([L("Check", "檢查"), L("Agreement", "一致比例"), L("After the fact: agreed / compared", "事後標:一致 / 比對"), L("In the moment: agreed / compared", "當下標:一致 / 比對"), L("Cannot tell", "看不出來")], lb.agreement.map((r) => [rule(r.detector), `${pct(r.rate)}(${num(r.n)})`, pair(r.bySource.batch), pair(r.bySource.live), r.unclear])) +
|
|
54
|
+
`<p class="muted">${L(`Cannot tell ${num(lb.unclear)}: labels marked unclear are left out of the agreement rate.`, `看不出來 ${num(lb.unclear)}:標成「看不出來」的不算進一致比例。`)}${lb.noCode ? L(` ${num(lb.noCode)} labels have no code verdict to compare: the session is not extracted yet (run /evals extract), or the rule did not apply to it.`, `另有 ${num(lb.noCode)} 筆沒有程式判斷可比:那段工作還沒整理(執行 /evals extract 後就能比),或這條規則不適用於它。`) : ""}${lb.other ? L(` ${num(lb.other)} labels are on "Other", which no code check covers.`, `${num(lb.other)} 筆標在「其他」,沒有程式檢查可比。`) : ""}</p>` + lesson(cards.labelTiming, L)
|
|
55
|
+
: `<p>${L("No labels yet. Type /evals label in any session to say, while the work is in front of you, whether the agent followed a rule.", "還沒有標記。在任何工作階段輸入 /evals label,就能趁工作還在眼前,標記代理人有沒有照規則做。")}</p>` + lesson(cards.labelTiming, L));
|
|
56
|
+
const c = lb.corrections, few = c.n < SMALL_SAMPLE;
|
|
57
|
+
const corrections = section("corrections", L("Times the agent was corrected", "被糾正"), L("When you correct how the agent worked, it logs one line with evals_label. This counts the corrections it logged, not all its mistakes: a slip nobody caught, or one it forgot to log, is not here.", "你糾正代理人的做法時,它會用 evals_label 自己記一筆。這裡數的是它記下的被糾正次數,不是所有錯誤:沒人發現、沒被糾正,或它忘了記的,都不在這裡。"), c.n
|
|
58
|
+
? `<p class="big">${num(c.n)} <small>${L("corrections", "次")} · ${num(c.sessions)} ${L("sessions", "段工作")}</small></p>${few ? `<p class="stale">${L(`Only ${num(c.n)}: too few to show a trend. Read it as a hint of where slips may recur.`, `只有 ${num(c.n)} 次,太少,看不出趨勢;只能當提醒,看哪裡可能常出錯。`)}</p>` : ""}<div class="pair"><article class="panel"><h3>${L("By rule", "依規則")}</h3>${T([L("Rule", "規則"), L("Times", "次數")], c.byRule.map((r) => [rule(r.rule), r.n]))}</article><article class="panel"><h3>${L("By kind of slip", "依錯誤類型")}</h3>${T([L("Kind", "類型"), L("Times", "次數")], c.byType.map((r) => [FAILURE_TYPE_META[r.type]?.[lang] ?? r.type, r.n]))}</article></div>` +
|
|
59
|
+
more(L("By skill loaded and by anchorloop version", "依載入的技能、anchorloop 版本"), `<p class="muted">${L("Skills the session had loaded before the correction. One correction counts for each of them; this does not mean the skill caused it.", "被糾正時這段工作已載入的技能。一次糾正會算進每個已載入的技能,不代表是技能造成的。")}</p>` +
|
|
60
|
+
T([L("Skill", "技能"), L("Times", "次數"), L("Sessions", "工作段數")], c.bySkill.map((r) => [r.skill || L("(none loaded)", "(沒載入技能)"), r.n, r.sessions])) +
|
|
61
|
+
`<p class="muted">${L("The anchorloop version in use when the correction was logged.", "依糾正當時使用的 anchorloop 版本。")}</p>` +
|
|
62
|
+
T([L("Version", "版本"), L("Times", "次數"), L("Sessions", "工作段數")], c.byVersion.map((r) => [r.version === "unknown" ? L("unknown", "不明") : r.version, r.n, r.sessions])))
|
|
63
|
+
: `<p>${L("None logged in this period. When you correct the agent, it logs one line here.", "這段期間沒有紀錄。你糾正代理人時,它會在這裡記一筆。")}</p>`);
|
|
50
64
|
return [
|
|
51
65
|
workSection(m, lang, cards, lesson),
|
|
52
66
|
skills,
|
|
@@ -58,6 +72,7 @@ export function sections(m, lang, cards) {
|
|
|
58
72
|
cost,
|
|
59
73
|
coverage,
|
|
60
74
|
labels,
|
|
75
|
+
corrections,
|
|
61
76
|
section("concepts", L("Concepts", "概念"), L(`Use these ${Object.keys(cards).length} ideas when you read the next report.`, `下次讀報表時,可以用這 ${Object.keys(cards).length} 個概念判讀數字。`), `<div class="notes-grid">${Object.values(cards).map((c) => lesson(c, L)).join("")}</div>${selfCheck(L)}`),
|
|
62
77
|
].join("");
|
|
63
78
|
}
|
package/dist/work/track.js
CHANGED
|
@@ -46,6 +46,13 @@ function liteOf(raw) {
|
|
|
46
46
|
blockedBy: Array.isArray(t.blockedBy) ? t.blockedBy.length : 0,
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
+
/** A task's own key: its uid, else `<origin session>#<id>` for a task handed over from another session. */
|
|
50
|
+
const ownKey = (task) => task.uid ?? (task.origin ? `${task.origin}#${task.id}` : undefined);
|
|
51
|
+
/** The key of the task in progress in a live todo list, as the back-fill keys it on the session's main branch. */
|
|
52
|
+
export function liveItemKey(tasks, session) {
|
|
53
|
+
const task = tasks.map(liteOf).find((x) => x?.status === "in_progress");
|
|
54
|
+
return task && (ownKey(task) ?? `${session}#${task.id}`);
|
|
55
|
+
}
|
|
49
56
|
/** The kind of stall a waking entry ends, or undefined when the entry does not start a turn. */
|
|
50
57
|
export function wakeOf(entry) {
|
|
51
58
|
const type = entry.type;
|
|
@@ -264,10 +271,9 @@ export class WorkTracker {
|
|
|
264
271
|
}
|
|
265
272
|
newItem(session, nested, task, snap, si, main, reuse) {
|
|
266
273
|
let key;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
key = `${task.origin}#${task.id}`;
|
|
274
|
+
const own = ownKey(task);
|
|
275
|
+
if (own)
|
|
276
|
+
key = own;
|
|
271
277
|
else if (main.has(si)) {
|
|
272
278
|
const count = (reuse.get(task.id) ?? 0) + 1;
|
|
273
279
|
reuse.set(task.id, count);
|
package/docs/design.md
CHANGED
|
@@ -19,9 +19,10 @@ Decisions on 2026-11-26, binding for this package:
|
|
|
19
19
|
| 「用 pi command 操作,這樣 agent 也可以自己去看」 | `/evals` (status, extract, report, mark) is the main surface, and one tool, `evals_query`, lets an agent read bounded summaries. The CLI is a thin wrapper over the same functions. |
|
|
20
20
|
| 「報表的設計會很重要,要注重人類可讀性,最好是可以記錄我做出的架構調整所造成的影響」 | A change timeline (pins, model routing, rules, skills, agent roles, live version changes, manual marks) with the same numbers before and after each change. The data (ReportModel, `model.json`) is separate from the renderer; this release ships a plain renderer, and the designed one will replace it after a mockup round. |
|
|
21
21
|
| 「先索引,穩定後再開清理」 | No cleanup code. `/evals status` and `evals_query coverage` report how many session files older than the cut (default 60 days without changes) the index fully covers, by count and bytes: the gate before a retention tool may delete them. Extra session roots (a future trash dir) are a setting. |
|
|
22
|
+
| 「我認為應該是 /eval 當下就可以做標記,也可以讓 agent 在做錯被糾正的時候標記,這樣才有辦法正確反映當下情境」 | `/evals label` records the user's verdict on a rule in the current session, and the `evals_label` tool lets the agent log a correction it was given; see [Labels in the moment](#labels-in-the-moment-050). |
|
|
22
23
|
| 「記得我對 evals 是門外漢,你的報表和標記網頁要讓我有辦法看懂」 | Every metric and detector in the ReportModel carries a label, one sentence of meaning, the better direction, one sentence on how it is computed, and for detectors a pass and a fail example, in English and Traditional Chinese. No unexplained statistics terms in what the reader sees. |
|
|
23
24
|
|
|
24
|
-
Later phases, not built here, each with a seam left open:
|
|
25
|
+
Later phases, not built here, each with a seam left open: with-and-without-skill A/B runs (phase 3), and session cleanup through a retention tool once the index covers old sessions (phase 4; `extraRoots` reads its trash dir).
|
|
25
26
|
|
|
26
27
|
## Decisions
|
|
27
28
|
|
|
@@ -108,6 +109,23 @@ It counts tool errors over calls per package and job endings marked `error` over
|
|
|
108
109
|
If several packages qualify, the largest rise wins, then the larger recent call count, then the package name.
|
|
109
110
|
No flag means no rise met that rule, not proof that nothing went wrong.
|
|
110
111
|
|
|
112
|
+
### Labels in the moment (0.5.0)
|
|
113
|
+
|
|
114
|
+
The first 20 labelled sessions were judged after the fact from AI summaries, and the code agreed on 10 of 20 and 4 of 11.
|
|
115
|
+
A summary can leave out what decided the verdict, so the gap cannot be put on the code or on the summary.
|
|
116
|
+
A label given while the work is in front of the user does not have that problem, so the report keeps the two apart and shows agreement for each.
|
|
117
|
+
|
|
118
|
+
`/evals label` asks three plain questions (which rule, followed or not, an optional note) and needs no arguments; the one-line form is for speed.
|
|
119
|
+
A label is tied to the session and the todo item in progress, keyed as back-filled work items are, so it can later join the item.
|
|
120
|
+
`undo` appends a withdrawal instead of rewriting the file, so a label another session appends at the same moment cannot be lost.
|
|
121
|
+
`/evals label <your words>` (「/evals label 後面應該允許接 prompt。要求 agent 根據格式標注」) sends the words to the agent, which formats them into rows; the command, not the agent, supplies the note, and the right to write a human row (`on_behalf: "user"`) opens when that turn starts and closes at its end.
|
|
122
|
+
|
|
123
|
+
The agent's `evals_label` takes enumerated names and nothing else, and its tool text stays near 690 bytes, since every session pays for it.
|
|
124
|
+
Its rows never enter the agreement: an agent's own account of being corrected is not a verdict on the code.
|
|
125
|
+
They are counted as 「被糾正」 by rule, failure type, the skills loaded before the correction, and the anchorloop version at the time.
|
|
126
|
+
The count covers corrections that were logged, not every mistake; with fewer than 20, the report says it is too few to show a trend.
|
|
127
|
+
A label whose session is not extracted yet enters a date or project filter by its own time and project, and is not cut at the last extract unless the user set an end date, so it shows up at once.
|
|
128
|
+
|
|
111
129
|
### Storage choices
|
|
112
130
|
|
|
113
131
|
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).
|
package/docs/schema.md
CHANGED
|
@@ -52,15 +52,33 @@ Back-fill rebuilds each session's items from its `todo/v1` snapshots, diffed alo
|
|
|
52
52
|
|
|
53
53
|
Sessions that started before 2026-11-23T10:51:07Z (the anchorloop 3.0.0 pin) get `na` with `out_of_scope_pre_3.0` for all four.
|
|
54
54
|
|
|
55
|
-
## Labels
|
|
55
|
+
## Labels
|
|
56
56
|
|
|
57
|
-
`labels.jsonl` in the state dir, one
|
|
57
|
+
`labels.jsonl` in the state dir is appended to, one row per line, and read at every report and query, with no extract needed.
|
|
58
|
+
There are three kinds of rows:
|
|
58
59
|
|
|
59
60
|
```json
|
|
60
|
-
{ "session_id": "01a2…", "evaluation_name": "anchor_before_first_edit", "label": "fail", "at": "2026-
|
|
61
|
+
{ "session_id": "01a2…", "evaluation_name": "anchor_before_first_edit", "label": "fail", "at": "2026-11-26T05:51:51Z", "annotator": "human" }
|
|
62
|
+
{ "session_id": "01a2…", "evaluation_name": "check_after_last_edit", "label": "fail", "at": "2026-11-26T06:00:00Z", "annotator": "human", "source": "live", "item": "MP-1234", "project": "demo-repo", "note": "optional, the user's own words" }
|
|
63
|
+
{ "session_id": "01a2…", "evaluation_name": "other", "label": "fail", "at": "2026-11-26T06:10:00Z", "annotator": "agent", "source": "correction", "type": "ignored_instruction", "item": "01a2…#3", "project": "demo-repo", "skills": ["coding"] }
|
|
61
64
|
```
|
|
62
65
|
|
|
63
|
-
|
|
66
|
+
- A row without `source` is a human verdict given after the fact (the report calls it 事後標, the code `batch`).
|
|
67
|
+
- `source: "live"` is a human verdict given in the moment with `/evals label`. `/evals label undo` appends `{ …, "source": "live", "undo": "<at of the withdrawn row>" }`, which withdraws the session's latest live row still in effect.
|
|
68
|
+
- `source: "live-prompt"` is a human verdict too: the user's words after `/evals label`, which the agent turned into rows with `evals_label` and `on_behalf: "user"` during the turn those words started. The note is the user's words, taken from the command, never from the agent.
|
|
69
|
+
- `source: "correction"` is an agent's `evals_label` call: `label` is always `fail`, and `type` is one of `no_check_stated`, `no_check_run`, `skipped_rule`, `wrong_order`, `unverified_claim`, `ignored_instruction`, `other`. The tool accepts no other field or value, and refuses `on_behalf` outside such a turn.
|
|
70
|
+
|
|
71
|
+
`evaluation_name` is a process check name or `other`.
|
|
72
|
+
`label` is `pass`, `fail`, or `unclear` (the reader could not tell).
|
|
73
|
+
`item` is the key of the todo item in progress when the label was given: its `uid`, else `<origin session>#<id>` for a task carried over from another session, else `<session>#<id>`.
|
|
74
|
+
`note` is the only free text, always the user's own words, and is never shown in the report or a query result.
|
|
75
|
+
|
|
76
|
+
The report joins human rows with `index/session-evals.json` (the code labels per session) and shows how often they agree, by when the labels were given (`live` and `live-prompt` both count as in the moment).
|
|
77
|
+
`unclear` labels are left out of the agreement rate and counted on their own (「看不出來 N」); labels on `other`, or on a session the code has not judged, are counted apart.
|
|
78
|
+
Agent rows never enter the agreement; they make the 「被糾正」 section.
|
|
79
|
+
With a date or project filter, a row belongs to the range by its session's start when the session is indexed, and by its own `at` and `project` otherwise.
|
|
80
|
+
A range without an end date the user gave ends at the last extract, but a row of a session not indexed yet is not cut there, so a label given after the last extract still shows.
|
|
81
|
+
The report counts the `live-prompt` rows among 當下標 and says how many there are.
|
|
64
82
|
|
|
65
83
|
## Change timeline
|
|
66
84
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-evals",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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",
|
|
@@ -37,7 +37,9 @@
|
|
|
37
37
|
"extensions": [
|
|
38
38
|
"./src/index.ts"
|
|
39
39
|
],
|
|
40
|
-
"skills": [
|
|
40
|
+
"skills": [
|
|
41
|
+
"./skills"
|
|
42
|
+
]
|
|
41
43
|
},
|
|
42
44
|
"scripts": {
|
|
43
45
|
"build": "tsc -p tsconfig.build.json",
|
|
@@ -6,7 +6,7 @@ description: Use when the user asks how their agents, skills or packages are doi
|
|
|
6
6
|
# Analyze agent activity
|
|
7
7
|
|
|
8
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`; for what a piece of work cost, where it closed, where it stalled, or whether one way of working is cheaper, use `items`. Keep the same filters. Stop when the numbers answer the question.
|
|
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`; for what a piece of work cost, where it closed, where it stalled, or whether one way of working is cheaper, use `items`; for how far the code checks match the user's labels, or what the user corrected, use `labels`. Keep the same filters. Stop when the numbers answer the question.
|
|
10
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
11
|
|
|
12
12
|
```sh
|
|
@@ -18,6 +18,8 @@ node "$SCRIPTS/package-errors.mjs" PACKAGE [PROJECT]
|
|
|
18
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
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
20
|
|
|
21
|
+
Reading `labels`: agreement counts the user's verdicts only, split into after the fact (from summaries) and in the moment (`/evals label`); corrections are what agents logged with `evals_label`, not all their mistakes, so do not read a count as an error rate.
|
|
22
|
+
|
|
21
23
|
Reading `items`: an item is one todo task from `in_progress` to done or deleted. Subagent cost is exact; main cost is an estimate, split evenly among items in progress at the same moment, so say which part you quote. Compare only like with like (the view already separates work handed to subagents from work the main did itself); when it says "too few items to tell", say that in those words rather than reading the medians. A stall says what woke the main (`human`, `peer`, `child`, `timer`, `ci`, `device`), not why it waited; `on` names the subagent, peer session or sb wait (`W12`, `L340`, `T5`) when known.
|
|
22
24
|
|
|
23
25
|
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/findings.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { correctionsFinding } from "./labels-query.ts";
|
|
2
3
|
import type { ReportModel } from "./model.ts";
|
|
3
4
|
import { overview, readings, value, verdict } from "./report/findings.ts";
|
|
4
5
|
import { words } from "./report/format.ts";
|
|
@@ -38,6 +39,8 @@ export function findings(m: ReportModel) {
|
|
|
38
39
|
lines.push(`Cleanup (all projects/dates): ${gate} → coverage`);
|
|
39
40
|
const work = itemsFinding(m.work);
|
|
40
41
|
if (work) lines.push(work);
|
|
42
|
+
const corrected = correctionsFinding(m);
|
|
43
|
+
if (corrected) lines.push(corrected);
|
|
41
44
|
const w = m.weekly;
|
|
42
45
|
if (!w) lines.push("Need two weeks in range for error trends → packages / monitors");
|
|
43
46
|
else {
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pi-evals: the live observer, the `/evals` command (status, extract, report, mark), and the `evals_query`
|
|
2
|
+
* pi-evals: the live observer, the `/evals` command (status, extract, report, mark, label), and the `evals_query` and `evals_label` tools.
|
|
3
3
|
*/
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
@@ -7,6 +7,7 @@ import { fileURLToPath } from "node:url";
|
|
|
7
7
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import { Type } from "typebox";
|
|
9
9
|
import { scriptsDir } from "./findings.ts";
|
|
10
|
+
import { liveLabels } from "./live-labels.ts";
|
|
10
11
|
import { observe } from "./observer.ts";
|
|
11
12
|
import { context, mark, reportPath, runReport, statusText } from "./ops.ts";
|
|
12
13
|
import { query, type View, VIEWS } from "./query.ts";
|
|
@@ -23,7 +24,7 @@ export function cliPath(): { cmd: string; args: string[] } | undefined {
|
|
|
23
24
|
return found ? { cmd: process.execPath, args: [found] } : undefined;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
const SUBCOMMANDS = ["status", "findings", "extract", "report", "mark"];
|
|
27
|
+
const SUBCOMMANDS = ["status", "findings", "extract", "report", "mark", "label"];
|
|
27
28
|
|
|
28
29
|
function parseFlags(args: string[]) {
|
|
29
30
|
const out: { since?: string; days?: number; project?: string; rest: string[] } = { rest: [] };
|
|
@@ -41,7 +42,8 @@ export function createEvals(options: { env?: Env; spawnExtract?: typeof spawn; n
|
|
|
41
42
|
const spawnFn = options.spawnExtract ?? spawn;
|
|
42
43
|
return function evals(pi: ExtensionAPI): void {
|
|
43
44
|
const ctx0 = context(env);
|
|
44
|
-
observe(pi, { layout: ctx0.layout, home: ctx0.home, now: options.now });
|
|
45
|
+
const observed = observe(pi, { layout: ctx0.layout, home: ctx0.home, now: options.now });
|
|
46
|
+
const labels = liveLabels(pi, { env, now: options.now ?? Date.now, observed });
|
|
45
47
|
let settingsWarned = false;
|
|
46
48
|
pi.on("session_start", (_event, ctx) => {
|
|
47
49
|
if (settingsWarned || !ctx0.settings.error) return;
|
|
@@ -96,7 +98,7 @@ export function createEvals(options: { env?: Env; spawnExtract?: typeof spawn; n
|
|
|
96
98
|
};
|
|
97
99
|
|
|
98
100
|
pi.registerCommand("evals", {
|
|
99
|
-
description: "Usage and process records: /evals [status|findings|extract|report|mark <note
|
|
101
|
+
description: "Usage and process records: /evals [status|findings|extract|report|mark <note>|label]",
|
|
100
102
|
getArgumentCompletions: (prefix: string) => {
|
|
101
103
|
const items = SUBCOMMANDS.filter((s) => s.startsWith(prefix)).map((s) => ({ value: s, label: s }));
|
|
102
104
|
return items.length ? items : null;
|
|
@@ -135,6 +137,8 @@ export function createEvals(options: { env?: Env; spawnExtract?: typeof spawn; n
|
|
|
135
137
|
}
|
|
136
138
|
const change = mark(text, env);
|
|
137
139
|
ctx.ui.notify(`pi-evals: marked ${change.at}: ${text}`, "info");
|
|
140
|
+
} else if (sub === "label") {
|
|
141
|
+
await labels.command(words.slice(1), ctx);
|
|
138
142
|
} else {
|
|
139
143
|
ctx.ui.notify(`Unknown subcommand "${sub}". Use: ${SUBCOMMANDS.join(", ")}.`, "warning");
|
|
140
144
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** The `labels` view of `evals_query` and its line in `findings`: names and numbers, never a note. */
|
|
2
|
+
import { type ReportModel, SMALL_SAMPLE } from "./model.ts";
|
|
3
|
+
|
|
4
|
+
/** Corrections of one rule and failure type that make a findings line. */
|
|
5
|
+
export const CLUSTER = 3;
|
|
6
|
+
|
|
7
|
+
const list = (rows: { n: number }[], name: (r: never) => string, limit = 6) => rows.slice(0, limit).map((r) => `${name(r as never)} ${r.n}`).join(", ") || "none";
|
|
8
|
+
const ratio = (c: { agree: number; n: number }) => `${c.agree}/${c.n}`;
|
|
9
|
+
|
|
10
|
+
export function labelsView(m: ReportModel): string[] {
|
|
11
|
+
const l = m.labels;
|
|
12
|
+
if (l.needsIndex) return ["labels in this range need an index with session ids: the user can run /evals extract"];
|
|
13
|
+
const c = l.corrections;
|
|
14
|
+
const out = [
|
|
15
|
+
"human labels = your verdicts on a rule; after the fact (batch) or in the moment (/evals label)",
|
|
16
|
+
`human: after the fact ${l.bySource.batch} (${l.sessions.batch} sessions), in the moment ${l.bySource.live} (${l.sessions.live} sessions${l.fromWords ? `; ${l.fromWords} formatted by the agent from your words` : ""}); unclear ${l.unclear}; no code verdict ${l.noCode}; on other ${l.other}`,
|
|
17
|
+
"code vs human, agreed/compared (after the fact; in the moment):",
|
|
18
|
+
];
|
|
19
|
+
for (const a of l.agreement) out.push(`${a.detector}: ${ratio(a)} (${ratio(a.bySource.batch)}; ${ratio(a.bySource.live)})`);
|
|
20
|
+
out.push(`corrections the agent logged (not all mistakes): ${c.n} in ${c.sessions} sessions${c.n && c.n < SMALL_SAMPLE ? `; small (<${SMALL_SAMPLE}), a hint not a trend` : ""}`);
|
|
21
|
+
if (c.n) {
|
|
22
|
+
out.push(`by rule: ${list(c.byRule, (r: { rule: string }) => r.rule)}`);
|
|
23
|
+
out.push(`by type: ${list(c.byType, (r: { type: string }) => r.type)}`);
|
|
24
|
+
out.push(`by rule/type: ${list(c.byRuleType, (r: { rule: string; type: string }) => `${r.rule}/${r.type}`, 4)}`);
|
|
25
|
+
out.push(`by skill loaded (one correction counts for each): ${list(c.bySkill, (r: { skill: string }) => r.skill || "(none)")}`);
|
|
26
|
+
out.push(`by anchorloop version: ${list(c.byVersion, (r: { version: string }) => r.version)}`);
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A findings line when corrections of one rule and type recur. */
|
|
32
|
+
export function correctionsFinding(m: ReportModel): string | undefined {
|
|
33
|
+
const c = m.labels.corrections, top = c.byRuleType[0];
|
|
34
|
+
if (!top || top.n < CLUSTER) return undefined;
|
|
35
|
+
return `Corrections logged: ${top.n} of ${c.n} are ${top.rule}/${top.type} (agent-logged, not all mistakes) → labels`;
|
|
36
|
+
}
|