pi-evals 0.5.2 → 0.6.1
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 +12 -0
- package/README.md +21 -3
- package/dist/ask-ai.js +58 -0
- package/dist/asks.js +53 -0
- package/dist/changes.js +15 -0
- package/dist/detectors.js +25 -3
- package/dist/extract/run.js +5 -7
- package/dist/extract/session.js +1 -1
- package/dist/index.js +3 -1
- package/dist/labels-query.js +2 -0
- package/dist/live-labels.js +7 -31
- package/dist/meta.js +11 -0
- package/dist/model.js +42 -3
- package/dist/ops.js +1 -1
- package/dist/paths.js +1 -0
- package/dist/plan-graph.js +116 -0
- package/dist/query.js +5 -0
- package/dist/report/findings.js +17 -4
- package/dist/report/sections.js +10 -3
- package/dist/report/strip.js +2 -1
- package/dist/turn-window.js +37 -0
- package/docs/design.md +5 -3
- package/docs/schema.md +14 -1
- package/package.json +1 -1
- package/skills/analyzing-evals/SKILL.md +8 -0
- package/src/ask-ai.ts +70 -0
- package/src/asks.ts +60 -0
- package/src/changes.ts +14 -0
- package/src/detectors.ts +7 -3
- package/src/extract/run.ts +11 -6
- package/src/extract/session.ts +1 -1
- package/src/index.ts +3 -1
- package/src/labels-query.ts +1 -0
- package/src/live-labels.ts +7 -30
- package/src/meta.ts +19 -0
- package/src/model.ts +41 -3
- package/src/ops.ts +1 -1
- package/src/paths.ts +3 -0
- package/src/plan-graph.ts +117 -0
- package/src/query.ts +5 -0
- package/src/report/findings.ts +16 -3
- package/src/report/sections.ts +10 -3
- package/src/report/strip.ts +3 -1
- package/src/turn-window.ts +50 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/** The planning-rule block's first line (sb `planhint.ts` OPENING). */
|
|
2
|
+
const RULE_OPENING = "sb: your open todos name no graph.";
|
|
3
|
+
const GRAPHS = new Set(["single-loop", "fan-out/fan-in", "orchestrator-worker"]);
|
|
4
|
+
const JUDGED = new Set(["coordinator", "standing"]);
|
|
5
|
+
const MAIN_PROMPT = /You are the main agent of Herdr tab .*?,? of kind ([a-z]+)/;
|
|
6
|
+
const STANDING_PROMPT = /You are the standing main of Herdr tab /;
|
|
7
|
+
const obj = (v) => (v && typeof v === "object" ? v : {});
|
|
8
|
+
/** A legacy `metadata.graph` as mains wrote it, normalised like sb's `graphOf`. */
|
|
9
|
+
export function legacyGraph(v) {
|
|
10
|
+
if (v === "orchestrator-worker")
|
|
11
|
+
return v;
|
|
12
|
+
if (v === "fan-out/fan-in" || v === "fan-out")
|
|
13
|
+
return "fan-out/fan-in";
|
|
14
|
+
if (v === "single" || (typeof v === "string" && v.startsWith("single-loop")))
|
|
15
|
+
return "single-loop";
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
/** A todo's graph: its own field when it is a graph name, else its legacy metadata. */
|
|
19
|
+
export function graphOfTodo(todo) {
|
|
20
|
+
const t = obj(todo);
|
|
21
|
+
if (typeof t.graph === "string" && GRAPHS.has(t.graph))
|
|
22
|
+
return t.graph;
|
|
23
|
+
return legacyGraph(obj(t.metadata).graph);
|
|
24
|
+
}
|
|
25
|
+
/** The plan's open todos: not completed or deleted, and not a train's step. */
|
|
26
|
+
function openOf(tasks) {
|
|
27
|
+
return tasks.map(obj).filter((t) => t.status !== "completed" && t.status !== "deleted" && !obj(t.metadata).sb);
|
|
28
|
+
}
|
|
29
|
+
function text(content) {
|
|
30
|
+
if (typeof content === "string")
|
|
31
|
+
return content;
|
|
32
|
+
return Array.isArray(content) ? content.map((p) => (obj(p).type === "text" ? String(obj(p).text ?? "") : "")).join("\n") : "";
|
|
33
|
+
}
|
|
34
|
+
export class PlanGraphTracker {
|
|
35
|
+
kind;
|
|
36
|
+
wasMain = false;
|
|
37
|
+
tasks;
|
|
38
|
+
calls = new Map();
|
|
39
|
+
/** The first plan (a create leaving open todos) named no graph; `rule`: sb's block came with it. */
|
|
40
|
+
missed;
|
|
41
|
+
result;
|
|
42
|
+
feed(entry) {
|
|
43
|
+
if (this.result)
|
|
44
|
+
return;
|
|
45
|
+
const type = entry.type;
|
|
46
|
+
if (type === "custom") {
|
|
47
|
+
const data = obj(entry.data);
|
|
48
|
+
if (entry.customType === "todo/v1" && Array.isArray(data.tasks))
|
|
49
|
+
this.tasks = data.tasks;
|
|
50
|
+
else if (entry.customType === "straw-boss" && typeof data.duty === "string" && this.kind)
|
|
51
|
+
this.setKind(data.duty);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (type === "custom_message" && entry.customType === "straw-boss") {
|
|
55
|
+
const briefed = obj(obj(entry.details).briefed);
|
|
56
|
+
const role = briefed.name ?? briefed.role;
|
|
57
|
+
if (typeof role === "string")
|
|
58
|
+
this.setKind(role === "main" && typeof briefed.duty === "string" ? briefed.duty : undefined);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (type !== "message")
|
|
62
|
+
return;
|
|
63
|
+
const message = obj(entry.message);
|
|
64
|
+
if (message.role === "system") {
|
|
65
|
+
const section = obj(message.sections)["straw-boss"];
|
|
66
|
+
if (typeof section !== "string")
|
|
67
|
+
return;
|
|
68
|
+
this.setKind(STANDING_PROMPT.test(section) ? "standing" : MAIN_PROMPT.exec(section)?.[1]);
|
|
69
|
+
}
|
|
70
|
+
else if (message.role === "assistant" && Array.isArray(message.content)) {
|
|
71
|
+
for (const raw of message.content) {
|
|
72
|
+
const part = obj(raw);
|
|
73
|
+
if (part.type === "toolCall" && part.name === "todo" && typeof part.id === "string")
|
|
74
|
+
this.calls.set(part.id, obj(part.arguments).action === "create");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (message.role === "toolResult" && typeof message.toolCallId === "string" && this.calls.has(message.toolCallId)) {
|
|
78
|
+
const create = this.calls.get(message.toolCallId);
|
|
79
|
+
this.calls.delete(message.toolCallId);
|
|
80
|
+
if (message.isError === true || !this.kind || !JUDGED.has(this.kind))
|
|
81
|
+
return;
|
|
82
|
+
const listed = obj(message.details).tasks;
|
|
83
|
+
this.todoResult(create, Array.isArray(listed) ? listed : (this.tasks ?? []), text(message.content).includes(RULE_OPENING));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
setKind(kind) {
|
|
87
|
+
this.kind = kind;
|
|
88
|
+
if (kind && JUDGED.has(kind))
|
|
89
|
+
this.wasMain = true;
|
|
90
|
+
}
|
|
91
|
+
todoResult(create, tasks, rule) {
|
|
92
|
+
const name = "plan_names_graph";
|
|
93
|
+
const open = openOf(tasks);
|
|
94
|
+
const named = open.some((t) => graphOfTodo(t));
|
|
95
|
+
if (!this.missed) {
|
|
96
|
+
if (!create || !open.length)
|
|
97
|
+
return;
|
|
98
|
+
if (named)
|
|
99
|
+
this.result = { name, label: "pass", explanation: "graph_at_first_create" };
|
|
100
|
+
else
|
|
101
|
+
this.missed = { rule };
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
this.result = named
|
|
105
|
+
? { name, label: "pass", explanation: this.missed.rule ? "graph_after_rule" : "graph_next_todo_call" }
|
|
106
|
+
: { name, label: "fail", explanation: "kept_planning_without_graph" };
|
|
107
|
+
}
|
|
108
|
+
results() {
|
|
109
|
+
const name = "plan_names_graph";
|
|
110
|
+
if (this.result)
|
|
111
|
+
return this.result;
|
|
112
|
+
if (this.missed)
|
|
113
|
+
return { name, label: "fail", explanation: "plan_without_graph" };
|
|
114
|
+
return { name, label: "na", explanation: this.wasMain ? "no_plan" : "not_sb_main" };
|
|
115
|
+
}
|
|
116
|
+
}
|
package/dist/query.js
CHANGED
|
@@ -88,6 +88,11 @@ export function query(view, options = {}) {
|
|
|
88
88
|
const versions = d.byVersion.filter((v) => v.pass + v.fail > 0).map((v) => `${v.version} ${pct(v.passRate)}`);
|
|
89
89
|
if (versions.length)
|
|
90
90
|
body.push(` by anchorloop version: ${versions.slice(-4).join("; ")}`);
|
|
91
|
+
const p = d.byPackage;
|
|
92
|
+
if (p) {
|
|
93
|
+
const byV = p.versions.filter((v) => v.pass + v.fail > 0).map((v) => `${v.version} ${pct(v.passRate)}`);
|
|
94
|
+
body.push(` by ${p.package} version: ${byV.slice(-6).join("; ") || "n/a"}; before ${p.version} ${pct(p.before.passRate)}, from ${p.version} ${pct(p.after.passRate)}`);
|
|
95
|
+
}
|
|
91
96
|
}
|
|
92
97
|
body.push(`close-guard reminders: ${Object.entries(m.process.notices).map(([k, v]) => `${k} ${v}`).join(", ") || "none"}`);
|
|
93
98
|
}
|
package/dist/report/findings.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
+
import { crosses } from "../changes.js";
|
|
1
2
|
import { num, pct, usd, words } from "./format.js";
|
|
3
|
+
/** The detector whose package version this pin change brings in (or skips past), with that version. */
|
|
4
|
+
export function introduced(c, m) {
|
|
5
|
+
for (const [name, md] of Object.entries(m.meta.detectors)) {
|
|
6
|
+
if (md.introducedIn && crosses(c, md.introducedIn.package, md.introducedIn.version))
|
|
7
|
+
return { detector: name, version: md.introducedIn.version };
|
|
8
|
+
}
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
2
11
|
export function readings(c, m, lang) {
|
|
3
12
|
const L = words(lang), i = c.impact;
|
|
4
13
|
const has = (k) => i?.before[k]?.value != null && i.after[k]?.value != null;
|
|
5
14
|
const process = c.package === "pi-anchorloop" && has("anchor_before_first_edit");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
15
|
+
const brings = introduced(c, m);
|
|
16
|
+
const keys = brings
|
|
17
|
+
? [brings.detector, "cost_per_session"]
|
|
18
|
+
: process
|
|
19
|
+
? ["anchor_before_first_edit", "check_after_last_edit"]
|
|
20
|
+
: [has("package_error_rate") ? "package_error_rate" : "tool_error_rate", "cost_per_session"];
|
|
9
21
|
return keys.map((key) => {
|
|
10
22
|
const meta = m.meta.detectors[key] ?? m.meta.metrics[key === "package_error_rate" ? "tool_error_rate" : key];
|
|
11
23
|
return {
|
|
@@ -54,7 +66,8 @@ export function select(m) {
|
|
|
54
66
|
const rest = candidates.filter((c) => c !== lead && c.at <= lead.at && (!lead.sha || c.sha !== lead.sha));
|
|
55
67
|
const second = rest.find((c) => c.impact?.smallSample && c.impact.before.sessions && c.impact.after.sessions) ??
|
|
56
68
|
rest.find((c) => (c.kind === "pin" || c.kind === "model-routing") && c.impact && !c.impact.incomplete) ?? rest[0];
|
|
57
|
-
|
|
69
|
+
// A pin change that brings a detector's package version is always shown: it is what that detector measures.
|
|
70
|
+
const highlighted = all.filter((c) => c === lead || c === second || !!introduced(c, m));
|
|
58
71
|
return { all, lead, highlighted, folded: all.filter((c) => !highlighted.includes(c)) };
|
|
59
72
|
}
|
|
60
73
|
/** Editorial choices shared by the HTML timeline and the compact query. */
|
package/dist/report/sections.js
CHANGED
|
@@ -36,7 +36,11 @@ export function sections(m, lang, cards) {
|
|
|
36
36
|
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) => {
|
|
37
37
|
const md = m.meta.detectors[d.name];
|
|
38
38
|
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])) +
|
|
39
|
-
T([L("Version", "版本"), L("Pass", "通過"), L("Fail", "未通過")], d.byVersion.map((r) => [r.version, r.pass, r.fail]))
|
|
39
|
+
T([L("Version", "版本"), L("Pass", "通過"), L("Fail", "未通過")], d.byVersion.map((r) => [r.version, r.pass, r.fail])) +
|
|
40
|
+
(d.byPackage
|
|
41
|
+
? `<p>${esc(L(`By ${d.byPackage.package} version: before ${d.byPackage.version} ${pct(d.byPackage.before.passRate)}, from ${d.byPackage.version} ${pct(d.byPackage.after.passRate)}.`, `依 ${d.byPackage.package} 版本:${d.byPackage.version} 之前 ${pct(d.byPackage.before.passRate)},${d.byPackage.version} 起 ${pct(d.byPackage.after.passRate)}。`))}</p>` +
|
|
42
|
+
T([L(`${d.byPackage.package} version`, `${d.byPackage.package} 版本`), L("Pass", "通過"), L("Fail", "未通過")], d.byPackage.versions.map((r) => [r.version, r.pass, r.fail]))
|
|
43
|
+
: ""))}</article>`;
|
|
40
44
|
}).join("")}</div>` +
|
|
41
45
|
more(L("Close-guard reminders", "收尾提醒"), T([L("Kind", "種類"), L("Count", "次數")], entries(m.process.notices).map(([k, n]) => [m.meta.notices[k]?.[lang] ?? k, n]))));
|
|
42
46
|
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>` +
|
|
@@ -48,11 +52,14 @@ export function sections(m, lang, cards) {
|
|
|
48
52
|
: `<p>${L("Coverage not measured; keep cleanup off.", "沒有索引覆蓋資料,請勿開啟清理。")}</p>`);
|
|
49
53
|
const lb = m.labels, rule = (r) => ruleLabel(r, lang);
|
|
50
54
|
const pair = (c) => (c.n ? `${num(c.agree)} / ${num(c.n)}` : "—");
|
|
55
|
+
const asked = lb.asks.n
|
|
56
|
+
? `<p>${L(`You asked with /ask-ai ${num(lb.asks.n)} times; ${num(lb.asks.labelled)} of them were followed within 30 minutes by a label in the same session.`, `你用 /ask-ai 問了 ${num(lb.asks.n)} 次,其中 ${num(lb.asks.labelled)} 次在同一段工作裡、30 分鐘內接著標記了。`)}</p>`
|
|
57
|
+
: "";
|
|
51
58
|
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
59
|
? `<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
60
|
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));
|
|
61
|
+
`<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>` + asked + lesson(cards.labelTiming, L)
|
|
62
|
+
: `<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>` + asked + lesson(cards.labelTiming, L));
|
|
56
63
|
const c = lb.corrections, few = c.n < SMALL_SAMPLE;
|
|
57
64
|
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
65
|
? `<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>` +
|
package/dist/report/strip.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { introduced } from "./findings.js";
|
|
1
2
|
import { esc, num, words } from "./format.js";
|
|
2
3
|
const KINDS = ["pin", "model-routing", "rule", "agent-role", "skill", "manual"];
|
|
3
4
|
/** Dense time slots get a count; every change still has its own mark and title. */
|
|
@@ -34,7 +35,7 @@ export function changeStrip(m, all, picks, ids, lang, range) {
|
|
|
34
35
|
marks.push(`<text class="slot-count" x="${left + 14}" y="28" text-anchor="middle">×${cells.length}</text>`);
|
|
35
36
|
}
|
|
36
37
|
const links = picks.map((c, i) => {
|
|
37
|
-
const { px, py, dot } = labeled.get(c), end = px > 700, caption = c.package ? `${c.package} ${c.to ?? ""}` : `${label(c.kind)} · ${c.at.slice(5, 16).replace("T", " ")}`;
|
|
38
|
+
const { px, py, dot } = labeled.get(c), end = px > 700, brings = introduced(c, m), skipped = brings && brings.version !== c.to ? L(` (includes ${brings.version})`, `(含 ${brings.version})`) : "", caption = c.package ? `${c.package} ${c.to ?? ""}${skipped}` : `${label(c.kind)} · ${c.at.slice(5, 16).replace("T", " ")}`;
|
|
38
39
|
const y = 87 + i * 23;
|
|
39
40
|
return `<a href="#${ids.get(c)}"><title>${esc(caption)}</title><path class="guide" d="M${px} ${py}V${y - 6}h${end ? -7 : 7}"/>${dot}<text x="${px + (end ? -10 : 10)}" y="${y}" text-anchor="${end ? "end" : "start"}">${esc(Array.from(caption).length > 48 ? Array.from(caption).slice(0, 47).join("") + "…" : caption)}</text></a>`;
|
|
40
41
|
}).join("");
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const textOf = (content) => typeof content === "string" ? content : Array.isArray(content) ? content.map((p) => (p && typeof p === "object" && typeof p.text === "string" ? p.text : "")).join("") : "";
|
|
2
|
+
export function turnWindow(pi) {
|
|
3
|
+
let waiting;
|
|
4
|
+
let open;
|
|
5
|
+
const start = (text) => {
|
|
6
|
+
if (waiting && text === waiting.prompt) {
|
|
7
|
+
open = waiting;
|
|
8
|
+
waiting = undefined;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
pi.on("before_agent_start", (event) => start(event.prompt));
|
|
12
|
+
pi.on("message_end", (event) => {
|
|
13
|
+
const message = event.message;
|
|
14
|
+
if (message?.role !== "user")
|
|
15
|
+
return;
|
|
16
|
+
const text = textOf(message.content);
|
|
17
|
+
if (open && text !== open.prompt)
|
|
18
|
+
open = undefined;
|
|
19
|
+
start(text);
|
|
20
|
+
});
|
|
21
|
+
pi.on("agent_end", () => {
|
|
22
|
+
open = undefined;
|
|
23
|
+
});
|
|
24
|
+
pi.on("session_start", () => {
|
|
25
|
+
waiting = open = undefined;
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
/** The message the command is about to send; its turn opens when that message starts a run. */
|
|
29
|
+
arm(turn) {
|
|
30
|
+
waiting = turn;
|
|
31
|
+
},
|
|
32
|
+
/** The open turn of this session, if any. */
|
|
33
|
+
current(session) {
|
|
34
|
+
return open?.session === session ? open : undefined;
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
package/docs/design.md
CHANGED
|
@@ -45,7 +45,7 @@ The privacy test was written first and failed on exactly that: a secret placed i
|
|
|
45
45
|
|
|
46
46
|
The session files hold almost everything (instrumentation §5): tool calls with `durationMs` (from October on; older calls use the time between call and result), the ask-user results in both the current and the retired `pi-ask-user` shapes, the skill catalog pi offered (the system message's `skills` section), monitor endings delivered as `pi-loop-monitor` messages, and close-guard notices.
|
|
47
47
|
Extraction streams each file line by line on a pool of worker threads and writes one record file per session file atomically.
|
|
48
|
-
It is incremental by path, size and modification time, so a later extract reads only active sessions;
|
|
48
|
+
It is incremental by path, size and modification time, so a later extract reads only active sessions; each file's summary carries the extractor version that wrote it, and a summary from another version is read again. The stamp is per file because an extract stopped after a version bump (0.6.0's first run was killed by a 900 s timeout) saved a checkpoint marked with the new version while most summaries were still old, and the next run skipped them.
|
|
49
49
|
A subagent session is linked to its parent three ways: the parent's `subagent` result (`details.id`, the child's logical id), `~/.pi/agent/dispatch-ledger/<parent>.json`, and the artifacts path in the child's brief.
|
|
50
50
|
Live records and back-fill meet by session id: back-fill counts win, and live adds monitor lifecycles and answer sources.
|
|
51
51
|
|
|
@@ -56,18 +56,20 @@ It appends to the state dir, never to the session file, and a failed write warns
|
|
|
56
56
|
|
|
57
57
|
### Process detectors
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
Five session-scoped checks, each a `gen_ai.evaluation.result` with `annotator_kind` CODE.
|
|
60
60
|
Anchor and change reading is ported from anchorloop's close guard (`pi/close-guard.ts` `read()`, 3.3.0), whose repository rules keep the guard small, so the evals live outside it (inventory §1).
|
|
61
61
|
|
|
62
62
|
- `anchor_before_first_edit`: before the first successful `write` or `edit`, the agent states the check (`anchor_first`: an `Anchor:` line, a labelled `Gates:`, `Checks:`, `Verify:` or `驗證:` line, a todo anchor, or a todo's sb check spec), its brief does (`anchor_in_brief`: such a line, or a check command it names), or the first change is a test file (`test_first`, red first). The brief counts because anchorloop has the coordinator put the unit's anchor there. 0.5.0 read only the `Anchor:` line and todo anchor and failed a brief's anchor as `anchor_only_in_brief`; 30 human labels (2026-11-26) passed all of these shapes.
|
|
63
63
|
- `check_after_last_edit`: after the last change, every command of the anchor has a passing run (bash, or a monitor by its exit code; `anchor_green`), the agent recorded passing todo evidence (`evidence_after_change`), or, when no anchor command ran and failed, the latest test, build, lint or type-check run passed (`check_run_after_change`). A check run is a segment of the command that starts with a known runner (`npm test`, `vitest`, `tsc`, `pytest`, `dotnet test` and the like) or a script named for checking (`check-*.py`, `gates.sh`, `measure.mjs`, `tests/*.py`); a command that only mentions tests (`rg test`, `git commit`) is not one. Edits to Markdown or text files do not move the last change, so a report or changelog written after the check does not undo it; a session that changed only such files is `prose_only` unless a check ran. With no anchor and no check it fails as `no_check_after_change`.
|
|
64
64
|
- `todo_evidence`: completed tasks in the final todo list carry evidence; the value is the share that do.
|
|
65
65
|
- `close_guard_quiet`: an editing session got no close-guard reminder about a missing or failing check (an evidence hand-off reminder does not count).
|
|
66
|
+
- `plan_names_graph`: a Straw Boss main of kind coordinator or standing names its plan's graph when it plans. The kind comes from the sb role prompt (system section `straw-boss`: "of kind <kind>", or "the standing main"), role steers (`details.briefed`), and kind entries (`data.duty`); an integrator, a member or a session with no sb role is `not_sb_main`. The plan is the open todos (not completed or deleted, not a train's `metadata.sb` step) a `todo` result lists. It passes when the first create that leaves open todos has one with a graph (the todo's `graph`, a name of pi-todo-ledger 0.4.0's three, else a legacy `metadata.graph` normalised as sb's `graphOf`; `graph_at_first_create`), or when the next todo call's open todos have one (`graph_after_rule` when sb's planning-rule block came on the create, sb 0.101.0 and later, else `graph_next_todo_call`). It fails when the next todo call still names none (`kept_planning_without_graph`) or there is none (`plan_without_graph`).
|
|
66
67
|
|
|
67
|
-
Only sessions that started after anchorloop 3.0.0 reached this setup are judged: the pin commit in weihung-basic-agent, 2026-11-23T10:51:07Z. Older sessions are out of scope rather than failing (inventory, Gotchas), and they are left out of the "not applicable" counts.
|
|
68
|
+
Only sessions that started after anchorloop 3.0.0 reached this setup are judged by the four anchorloop checks (`plan_names_graph` is judged in every session: sb mains live for weeks): the pin commit in weihung-basic-agent, 2026-11-23T10:51:07Z. Older sessions are out of scope rather than failing (inventory, Gotchas), and they are left out of the "not applicable" counts.
|
|
68
69
|
Like the guard, an edit made through bash is not seen as a change.
|
|
69
70
|
These are process checks on observable events, which suits a process skill whose path is the product (research §1); they say how often the rules were followed, not whether the work was right.
|
|
70
71
|
A session's anchorloop version is the newest pin in the change timeline at or before the session's start, so a pin at 16:46 splits that day's sessions at 16:46.
|
|
72
|
+
A detector that measures a package version's arrival names it in its metadata (`introducedIn`; `plan_names_graph`: pi-straw-boss 0.101.0). The process view and the report then also split its results by that package's version at each session's start, and before and from that version; the pin change that brings the version, or skips past it (0.100.2 → 0.102.0), is always highlighted on the change strip and captioned with the version it includes. A session picks up a new package version only after `/reload` or a restart, and it is split by its start, so a long-lived main reloaded after the pin still counts on the earlier side; read the "from" side as fresh sessions only.
|
|
71
73
|
|
|
72
74
|
### Change impact
|
|
73
75
|
|
package/docs/schema.md
CHANGED
|
@@ -49,8 +49,9 @@ Back-fill rebuilds each session's items from its `todo/v1` snapshots, diffed alo
|
|
|
49
49
|
| `check_after_last_edit` | `anchor_green`, `evidence_after_change`, `check_run_after_change` | `no_passing_run_after_change`, `no_check_after_change` | `no_edit`, `prose_only`, `anchor_without_command` |
|
|
50
50
|
| `todo_evidence` | `all_evidenced` | `completed_without_evidence` (value = share with evidence) | `no_completed_task` |
|
|
51
51
|
| `close_guard_quiet` | `no_notice` | the commonest notice kind | `no_edit` |
|
|
52
|
+
| `plan_names_graph` | `graph_at_first_create`, `graph_after_rule`, `graph_next_todo_call` | `kept_planning_without_graph`, `plan_without_graph` | `not_sb_main`, `no_plan` |
|
|
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
|
|
54
|
+
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 the four anchorloop checks; `plan_names_graph` is judged in every session, since sb mains live for weeks.
|
|
54
55
|
|
|
55
56
|
## Labels
|
|
56
57
|
|
|
@@ -82,6 +83,18 @@ With a date or project filter, a row belongs to the range by its session's start
|
|
|
82
83
|
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.
|
|
83
84
|
The report counts the `live-prompt` rows among 當下標 and says how many there are.
|
|
84
85
|
|
|
86
|
+
## Asks
|
|
87
|
+
|
|
88
|
+
`asks.jsonl` in the state dir gets one row per `/ask-ai`, appended when the command runs and read at every report and query:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{ "session_id": "01a2…", "at": "2026-11-26T06:00:00Z", "kind": "ask_ai", "project": "demo-repo", "item": "MP-1234" }
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`item` is the todo item in progress, keyed as in labels, and is absent when none is.
|
|
95
|
+
The row holds no question text, and the agent's answer is not stored anywhere.
|
|
96
|
+
The report counts asks in range (scoped like live labels) and how many had a human label in the same session at most 30 minutes after the ask; the `labels` view of `evals_query` gives the same two numbers.
|
|
97
|
+
|
|
85
98
|
## Change timeline
|
|
86
99
|
|
|
87
100
|
`changes.jsonl`, rebuilt by every extract, one change per line:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-evals",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
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",
|
|
@@ -23,3 +23,11 @@ Reading `labels`: agreement counts the user's verdicts only, split into after th
|
|
|
23
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.
|
|
24
24
|
|
|
25
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.
|
|
26
|
+
|
|
27
|
+
## When a number looks wrong
|
|
28
|
+
|
|
29
|
+
1. Check freshness first: the last extract time, and the `extractor` stamp on the summaries in `index/checkpoint.json` against the current version. A run stopped mid-way once left old summaries under a new checkpoint (check agreement read 11/20; a clean rebuild gave 23/24). If they disagree, say the number is stale and do not interpret it.
|
|
30
|
+
2. Before trusting a detector's rate, check it against the user's labels: the `labels` view, then the disagreeing sessions one by one, and which way they lean. All code=fail with human=pass means the detector undercounts (an anchor rate read 20% that was about 73%).
|
|
31
|
+
3. Error analysis: read the disagreeing sessions' structure (entry types, tool names, order; no transcript text into records), group the misses by cause, count each group, and fix the biggest first.
|
|
32
|
+
4. When loosening a detector, keep a guard set of real should-fail sessions that must stay fail. A rule ambiguity (an anchor stated after the first edit) is the user's decision: ask, record it as a `recheck` label, and do not settle it silently in code.
|
|
33
|
+
5. Have the user label about 30 sessions by hand before trusting any automated grader; human labels are the reference. Observational numbers are monitoring; whether skill X helped needs a controlled experiment, not this report.
|
package/src/ask-ai.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/ask-ai <question>`: the user asks, and the agent answers now. The question goes to the agent wrapped in a short
|
|
3
|
+
* answer-first instruction, and while that turn runs the tools that change things or start work are refused, so a
|
|
4
|
+
* question is not taken for a reproach and turned into new work before the user can label how it went.
|
|
5
|
+
*/
|
|
6
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import { appendAsk } from "./asks.ts";
|
|
8
|
+
import { itemOnBranch } from "./labels.ts";
|
|
9
|
+
import { context } from "./ops.ts";
|
|
10
|
+
import { projectKey } from "./project.ts";
|
|
11
|
+
import { turnWindow } from "./turn-window.ts";
|
|
12
|
+
|
|
13
|
+
type Env = Record<string, string | undefined>;
|
|
14
|
+
type Input = Record<string, unknown>;
|
|
15
|
+
|
|
16
|
+
const always = () => true;
|
|
17
|
+
/** Tools refused during an `/ask-ai` turn, each with the inputs it is refused for; any other tool runs. */
|
|
18
|
+
export const ASK_AI_BLOCKED: Readonly<Record<string, (input: Input) => boolean>> = {
|
|
19
|
+
write: always,
|
|
20
|
+
edit: always,
|
|
21
|
+
subagent: always,
|
|
22
|
+
boss_pair: always,
|
|
23
|
+
MonitorCreate: always,
|
|
24
|
+
LoopCreate: always,
|
|
25
|
+
call_tower: always,
|
|
26
|
+
todo: (input) => input.action !== "list" && input.action !== "get",
|
|
27
|
+
intercom: (input) => input.action === "send" || input.action === "ask" || input.action === "handover",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const USAGE = "pi-evals 用法:/ask-ai <你的問題>,代理人會先直接回答,不改任何東西、不開始新工作。";
|
|
31
|
+
|
|
32
|
+
/** The question, last and verbatim, after the instruction to answer it now and do nothing else. */
|
|
33
|
+
export function askPrompt(question: string): string {
|
|
34
|
+
return [
|
|
35
|
+
"[/ask-ai] Answer the user's question below now, directly and first, in the user's language. Read only what you need to answer; change nothing, start no work, dispatch nothing. If it asks how you worked, say plainly what happened and whether it followed the rule. End with at most one line of suggested next step, then wait for the user.",
|
|
36
|
+
"",
|
|
37
|
+
`Question: ${question}`,
|
|
38
|
+
].join("\n");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function askAi(pi: ExtensionAPI, options: { env: Env; now: () => number }) {
|
|
42
|
+
const { env, now } = options;
|
|
43
|
+
const asking = turnWindow<undefined>(pi);
|
|
44
|
+
|
|
45
|
+
pi.on("tool_call", (event, ctx) => {
|
|
46
|
+
const { toolName, input } = event as { toolName: string; input?: Input };
|
|
47
|
+
const refuse = Object.hasOwn(ASK_AI_BLOCKED, toolName) ? ASK_AI_BLOCKED[toolName] : undefined;
|
|
48
|
+
if (!refuse || !refuse(input ?? {}) || !asking.current(ctx.sessionManager.getSessionId())) return undefined;
|
|
49
|
+
return { block: true, reason: `Refused during /ask-ai: answer the user's question first, change nothing and start no work; ${toolName} can run after the user replies.` };
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
pi.registerCommand("ask-ai", {
|
|
53
|
+
description: "Ask the agent a question and have it answer now, without starting work: /ask-ai <question>",
|
|
54
|
+
handler: async (args: string, ctx: ExtensionCommandContext) => {
|
|
55
|
+
const question = args.trim();
|
|
56
|
+
if (!question) return ctx.ui.notify(USAGE, "warning");
|
|
57
|
+
const c = context(env);
|
|
58
|
+
const session = ctx.sessionManager.getSessionId();
|
|
59
|
+
let branch: unknown[] | undefined;
|
|
60
|
+
try {
|
|
61
|
+
branch = ctx.sessionManager.getBranch?.();
|
|
62
|
+
} catch {}
|
|
63
|
+
appendAsk(c.layout.asks, { session_id: session, at: new Date(now()).toISOString(), kind: "ask_ai", project: projectKey(ctx.cwd, c.home), item: itemOnBranch(branch, session) });
|
|
64
|
+
const prompt = askPrompt(question);
|
|
65
|
+
asking.arm({ session, prompt, data: undefined });
|
|
66
|
+
// While the agent works, the question goes in after its current tool calls, not after the whole run.
|
|
67
|
+
pi.sendUserMessage(prompt, ctx.isIdle() ? undefined : { deliverAs: "steer" });
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
package/src/asks.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `asks.jsonl` (append-only): one row per `/ask-ai`, when and where it was asked. Never the question or the answer.
|
|
3
|
+
* The report counts them and how many were followed by a label in the same session within 30 minutes.
|
|
4
|
+
*/
|
|
5
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
6
|
+
import { dirname } from "node:path";
|
|
7
|
+
import { type LabelScope, readLabels } from "./labels.ts";
|
|
8
|
+
import { traceId } from "./schema.ts";
|
|
9
|
+
|
|
10
|
+
export interface AskRow {
|
|
11
|
+
session_id: string;
|
|
12
|
+
at: string;
|
|
13
|
+
kind: "ask_ai";
|
|
14
|
+
project?: string;
|
|
15
|
+
item?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** How long after an ask a label in the same session counts as following it. */
|
|
19
|
+
export const ASK_LABEL_WINDOW_MS = 30 * 60 * 1000;
|
|
20
|
+
|
|
21
|
+
export function appendAsk(file: string, row: AskRow): void {
|
|
22
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
23
|
+
appendFileSync(file, `${JSON.stringify(row)}\n`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function readAsks(file: string): AskRow[] {
|
|
27
|
+
if (!existsSync(file)) return [];
|
|
28
|
+
return readFileSync(file, "utf8")
|
|
29
|
+
.split("\n")
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.flatMap((line) => {
|
|
32
|
+
try {
|
|
33
|
+
const row = JSON.parse(line) as AskRow;
|
|
34
|
+
return row && row.kind === "ask_ai" && typeof row.session_id === "string" && typeof row.at === "string" ? [row] : [];
|
|
35
|
+
} catch {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Asks in scope (a session in the index belongs by its start; one not indexed yet by the ask's own time and project),
|
|
43
|
+
* and how many a human label in the same session followed within `ASK_LABEL_WINDOW_MS`.
|
|
44
|
+
*/
|
|
45
|
+
export function asksModel(asksFile: string | undefined, labelsFile: string, scope: LabelScope): { n: number; labelled: number } {
|
|
46
|
+
if (!asksFile) return { n: 0, labelled: 0 };
|
|
47
|
+
const inDates = (at: string) => (!scope.since || at.slice(0, 10) >= scope.since) && (!scope.until || at.slice(0, 10) <= scope.until);
|
|
48
|
+
const asks = readAsks(asksFile).filter((r) => {
|
|
49
|
+
if (!scope.selected) return true;
|
|
50
|
+
const id = traceId(r.session_id, "labels");
|
|
51
|
+
return scope.selected.has(id) || (!scope.indexed?.has(id) && inDates(r.at) && (!scope.project || r.project === scope.project));
|
|
52
|
+
});
|
|
53
|
+
if (!asks.length) return { n: 0, labelled: 0 };
|
|
54
|
+
const labels = readLabels(labelsFile).filter((l) => l.annotator !== "agent" && typeof l.at === "string");
|
|
55
|
+
const labelled = asks.filter((a) => {
|
|
56
|
+
const t = Date.parse(a.at);
|
|
57
|
+
return labels.some((l) => l.session_id === a.session_id && Date.parse(l.at) >= t && Date.parse(l.at) - t <= ASK_LABEL_WINDOW_MS);
|
|
58
|
+
}).length;
|
|
59
|
+
return { n: asks.length, labelled };
|
|
60
|
+
}
|
package/src/changes.ts
CHANGED
|
@@ -176,3 +176,17 @@ export function versionAt(changes: Change[], pkg: string | string[], at: string)
|
|
|
176
176
|
}
|
|
177
177
|
return version;
|
|
178
178
|
}
|
|
179
|
+
|
|
180
|
+
/** Whether a dotted version is at or after `min`, by numeric parts; a version that is not dotted numbers (a git sha) is undefined. */
|
|
181
|
+
export function atLeast(version: string | undefined, min: string): boolean | undefined {
|
|
182
|
+
const parts = (v: string | undefined) => (v && /^\d+(\.\d+)*$/.test(v) ? v.split(".").map(Number) : undefined);
|
|
183
|
+
const a = parts(version), b = parts(min);
|
|
184
|
+
if (!a || !b) return undefined;
|
|
185
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) > (b[i] ?? 0);
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Whether a pin change brings `pkg` to `version` or past it, from a version before it (or none): a version it skipped counts. */
|
|
190
|
+
export function crosses(c: Pick<Change, "kind" | "package" | "from" | "to">, pkg: string, version: string): boolean {
|
|
191
|
+
return c.kind === "pin" && c.package === pkg && atLeast(c.to, version) === true && atLeast(c.from, version) !== true;
|
|
192
|
+
}
|
package/src/detectors.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* in a monitor (by its exit code), passing evidence recorded after the last change, or, when no anchor command ran,
|
|
16
16
|
* a test, build, lint or type-check run after it.
|
|
17
17
|
*/
|
|
18
|
+
import { PlanGraphTracker } from "./plan-graph.ts";
|
|
18
19
|
import type { Label } from "./schema.ts";
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -22,7 +23,7 @@ import type { Label } from "./schema.ts";
|
|
|
22
23
|
* (commit 9f72366, 2026-11-23T10:51:07Z). Sessions that started earlier are out of scope.
|
|
23
24
|
*/
|
|
24
25
|
export const ERA_START = "2026-11-23T10:51:07.000Z";
|
|
25
|
-
export const DETECTORS = ["anchor_before_first_edit", "check_after_last_edit", "todo_evidence", "close_guard_quiet"] as const;
|
|
26
|
+
export const DETECTORS = ["anchor_before_first_edit", "check_after_last_edit", "todo_evidence", "close_guard_quiet", "plan_names_graph"] as const;
|
|
26
27
|
export type DetectorName = (typeof DETECTORS)[number];
|
|
27
28
|
export interface DetectorResult {
|
|
28
29
|
name: DetectorName;
|
|
@@ -123,11 +124,13 @@ export class ProcessTracker {
|
|
|
123
124
|
private sawUser = false;
|
|
124
125
|
private briefAnchor = false;
|
|
125
126
|
private notices = new Map<NoticeKind, number>();
|
|
127
|
+
private plan = new PlanGraphTracker();
|
|
126
128
|
|
|
127
129
|
/** Notice kinds seen so far, for `anchorloop.close_guard.notice` records. */
|
|
128
130
|
feed(raw: unknown): NoticeKind | undefined {
|
|
129
131
|
const entry = raw as Entry;
|
|
130
132
|
const seq = ++this.seq;
|
|
133
|
+
if (entry && typeof entry === "object") this.plan.feed(entry as Record<string, unknown>);
|
|
131
134
|
if (entry?.type === "custom" && entry.customType === "todo/v1" && entry.data?.v === 1 && Array.isArray(entry.data.tasks)) {
|
|
132
135
|
this.tasks = entry.data.tasks;
|
|
133
136
|
return undefined;
|
|
@@ -212,8 +215,9 @@ export class ProcessTracker {
|
|
|
212
215
|
}
|
|
213
216
|
|
|
214
217
|
results(inScope: boolean): DetectorResult[] {
|
|
215
|
-
|
|
216
|
-
return [
|
|
218
|
+
// The anchorloop era bounds the anchorloop rules only; the sb planning rule is judged in every session (long-lived mains started earlier).
|
|
219
|
+
if (!inScope) return [...DETECTORS_ALL.filter((name) => name !== "plan_names_graph").map((name): DetectorResult => ({ name, label: "na", explanation: "out_of_scope_pre_3.0" })), this.plan.results()];
|
|
220
|
+
return [this.anchorFirst(), this.checkAfter(), this.todoEvidence(), this.quiet(), this.plan.results()];
|
|
217
221
|
}
|
|
218
222
|
|
|
219
223
|
private anchorFirst(): DetectorResult {
|
package/src/extract/run.ts
CHANGED
|
@@ -15,10 +15,16 @@ export interface FileEntry {
|
|
|
15
15
|
key: string;
|
|
16
16
|
month: string;
|
|
17
17
|
summary: SessionSummary;
|
|
18
|
+
/**
|
|
19
|
+
* The extractor version that wrote this summary. A summary is current only when it equals EXTRACTOR_VERSION, so an
|
|
20
|
+
* extract stopped after a version bump leaves the files it did not reach stale for the next run. Entries from 0.6.0
|
|
21
|
+
* and before carry none and are read again.
|
|
22
|
+
*/
|
|
23
|
+
extractor?: number;
|
|
18
24
|
}
|
|
19
25
|
|
|
20
|
-
/** Bump when extraction changes what it derives;
|
|
21
|
-
export const EXTRACTOR_VERSION =
|
|
26
|
+
/** Bump when extraction changes what it derives; every summary written by another version is read again. */
|
|
27
|
+
export const EXTRACTOR_VERSION = 6;
|
|
22
28
|
|
|
23
29
|
export interface Checkpoint {
|
|
24
30
|
v: 1;
|
|
@@ -141,12 +147,11 @@ export async function extract(options: {
|
|
|
141
147
|
const started = Date.now();
|
|
142
148
|
const checkpoint = loadCheckpoint(options.layout.checkpoint);
|
|
143
149
|
const files = listSessionFiles(options.roots);
|
|
144
|
-
|
|
150
|
+
// The checkpoint-wide field only says which version last ran; staleness is per entry (an interrupted run saves both kinds).
|
|
145
151
|
checkpoint.extractor = EXTRACTOR_VERSION;
|
|
146
152
|
const changed = files.filter((f) => {
|
|
147
153
|
const known = checkpoint.files[f.path];
|
|
148
|
-
|
|
149
|
-
return !known || known.size !== f.size || known.mtimeMs !== f.mtimeMs;
|
|
154
|
+
return !known || known.extractor !== EXTRACTOR_VERSION || known.size !== f.size || known.mtimeMs !== f.mtimeMs;
|
|
150
155
|
});
|
|
151
156
|
const stats: ExtractStats = { files: files.length, changed: changed.length, failed: 0, bytes: 0, records: 0, ms: 0, errors: [] };
|
|
152
157
|
const byPath = new Map(changed.map((f) => [f.path, f]));
|
|
@@ -175,7 +180,7 @@ export async function extract(options: {
|
|
|
175
180
|
} else {
|
|
176
181
|
stats.records += result.records;
|
|
177
182
|
const key = fileKey(file.path);
|
|
178
|
-
checkpoint.files[file.path] = { size: file.size, mtimeMs: file.mtimeMs, key, month: monthOf(file.path), summary: result.summary };
|
|
183
|
+
checkpoint.files[file.path] = { size: file.size, mtimeMs: file.mtimeMs, key, month: monthOf(file.path), summary: result.summary, extractor: EXTRACTOR_VERSION };
|
|
179
184
|
if (result.catalog?.length) {
|
|
180
185
|
const hash = createHash("sha1").update(result.catalog.join("\n")).digest("hex").slice(0, 16);
|
|
181
186
|
result.summary.catalog = hash;
|
package/src/extract/session.ts
CHANGED
|
@@ -396,7 +396,7 @@ export class SessionReader {
|
|
|
396
396
|
const evals: SessionSummary["evals"] = {};
|
|
397
397
|
for (const result of this.tracker.results(inScope)) {
|
|
398
398
|
evals[result.name] = { label: result.label, value: result.value, explanation: result.explanation };
|
|
399
|
-
if (
|
|
399
|
+
if (result.explanation !== "out_of_scope_pre_3.0") {
|
|
400
400
|
const t = (startDay.detectors[result.name] ??= { pass: 0, fail: 0, na: 0 });
|
|
401
401
|
t[result.label] += 1;
|
|
402
402
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pi-evals: the live observer, the `/evals` command (status, extract, report, mark, label), and the `evals_query` and `evals_label` tools.
|
|
2
|
+
* pi-evals: the live observer, the `/evals` command (status, extract, report, mark, label), `/ask-ai`, 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";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import { Type } from "typebox";
|
|
9
|
+
import { askAi } from "./ask-ai.ts";
|
|
9
10
|
import { scriptsDir } from "./findings.ts";
|
|
10
11
|
import { liveLabels } from "./live-labels.ts";
|
|
11
12
|
import { observe } from "./observer.ts";
|
|
@@ -44,6 +45,7 @@ export function createEvals(options: { env?: Env; spawnExtract?: typeof spawn; n
|
|
|
44
45
|
const ctx0 = context(env);
|
|
45
46
|
const observed = observe(pi, { layout: ctx0.layout, home: ctx0.home, now: options.now });
|
|
46
47
|
const labels = liveLabels(pi, { env, now: options.now ?? Date.now, observed });
|
|
48
|
+
askAi(pi, { env, now: options.now ?? Date.now });
|
|
47
49
|
let settingsWarned = false;
|
|
48
50
|
pi.on("session_start", (_event, ctx) => {
|
|
49
51
|
if (settingsWarned || !ctx0.settings.error) return;
|