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
package/src/labels-query.ts
CHANGED
|
@@ -16,6 +16,7 @@ export function labelsView(m: ReportModel): string[] {
|
|
|
16
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
17
|
"code vs human, agreed/compared (after the fact; in the moment):",
|
|
18
18
|
];
|
|
19
|
+
if (l.asks.n) out.splice(2, 0, `/ask-ai questions: ${l.asks.n}; followed by a label in the same session within 30 min: ${l.asks.labelled}`);
|
|
19
20
|
for (const a of l.agreement) out.push(`${a.detector}: ${ratio(a)} (${ratio(a.bySource.batch)}; ${ratio(a.bySource.live)})`);
|
|
20
21
|
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
22
|
if (c.n) {
|
package/src/live-labels.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { agentLabel, appendLabel, cleanNote, FAILURE_TYPES, type FailureType, it
|
|
|
9
9
|
import type { Observed } from "./observer.ts";
|
|
10
10
|
import { context } from "./ops.ts";
|
|
11
11
|
import { projectKey } from "./project.ts";
|
|
12
|
+
import { turnWindow } from "./turn-window.ts";
|
|
12
13
|
|
|
13
14
|
type Env = Record<string, string | undefined>;
|
|
14
15
|
type Ctx = Pick<ExtensionCommandContext, "cwd" | "sessionManager">;
|
|
@@ -29,33 +30,8 @@ export function promptFor(words: string): string {
|
|
|
29
30
|
|
|
30
31
|
export function liveLabels(pi: ExtensionAPI, options: { env: Env; now: () => number; observed: Observed }) {
|
|
31
32
|
const { env, now, observed } = options;
|
|
32
|
-
/** The
|
|
33
|
-
|
|
34
|
-
let speaking: { session: string; prompt: string; note?: string } | undefined;
|
|
35
|
-
const textOf = (content: unknown) =>
|
|
36
|
-
typeof content === "string" ? content : Array.isArray(content) ? content.map((p) => (p && typeof p === "object" && typeof (p as { text?: unknown }).text === "string" ? (p as { text: string }).text : "")).join("") : "";
|
|
37
|
-
const start = (text: string | undefined) => {
|
|
38
|
-
if (waiting && text === waiting.prompt) {
|
|
39
|
-
speaking = { ...waiting };
|
|
40
|
-
waiting = undefined;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
pi.on("before_agent_start", (event) => start((event as { prompt?: string }).prompt));
|
|
44
|
-
// A prompt queued behind a running turn starts its own run without before_agent_start: its user message opens it.
|
|
45
|
-
pi.on("message_end", (event) => {
|
|
46
|
-
const message = (event as { message?: { role?: string; content?: unknown } }).message;
|
|
47
|
-
if (message?.role !== "user") return;
|
|
48
|
-
const text = textOf(message.content);
|
|
49
|
-
// Another message from the user in the same run is not part of the words the agent is formatting.
|
|
50
|
-
if (speaking && text !== speaking.prompt) speaking = undefined;
|
|
51
|
-
start(text);
|
|
52
|
-
});
|
|
53
|
-
pi.on("agent_end", () => {
|
|
54
|
-
speaking = undefined;
|
|
55
|
-
});
|
|
56
|
-
pi.on("session_start", () => {
|
|
57
|
-
waiting = speaking = undefined;
|
|
58
|
-
});
|
|
33
|
+
/** The turn that may speak for the user: the one the user's words started. */
|
|
34
|
+
const speaking = turnWindow<{ note?: string }>(pi);
|
|
59
35
|
const where = (ctx: Ctx) => {
|
|
60
36
|
const c = context(env);
|
|
61
37
|
const session = ctx.sessionManager.getSessionId();
|
|
@@ -83,8 +59,9 @@ export function liveLabels(pi: ExtensionAPI, options: { env: Env; now: () => num
|
|
|
83
59
|
note = words.slice(2).join(" ");
|
|
84
60
|
if (!rule || !verdict) {
|
|
85
61
|
const text = cleanNote(words.join(" "))!;
|
|
86
|
-
|
|
87
|
-
|
|
62
|
+
const prompt = promptFor(text);
|
|
63
|
+
speaking.arm({ session: w.session, prompt, data: { note: text } });
|
|
64
|
+
pi.sendUserMessage(prompt, ctx.isIdle() ? undefined : { deliverAs: "followUp" });
|
|
88
65
|
return say(`pi-evals:已把你的話交給代理人,請它整理成標記${ctx.isIdle() ? "" : "(等目前的工作告一段落)"};它會回報記了什麼,不對就用 /evals label undo 撤銷。`);
|
|
89
66
|
}
|
|
90
67
|
} else {
|
|
@@ -122,7 +99,7 @@ export function liveLabels(pi: ExtensionAPI, options: { env: Env; now: () => num
|
|
|
122
99
|
),
|
|
123
100
|
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
124
101
|
const session = ctx.sessionManager.getSessionId();
|
|
125
|
-
const voice = speaking?.
|
|
102
|
+
const voice = speaking.current(session)?.data;
|
|
126
103
|
const { rule, label, type, onBehalf } = agentLabel(params, !!voice);
|
|
127
104
|
const w = where(ctx);
|
|
128
105
|
if (onBehalf) {
|
package/src/meta.ts
CHANGED
|
@@ -18,6 +18,8 @@ export interface MetricMeta {
|
|
|
18
18
|
|
|
19
19
|
export interface DetectorMeta extends MetricMeta {
|
|
20
20
|
example: { pass: Text; fail: Text };
|
|
21
|
+
/** The package version whose arrival this detector measures: its results are also split by that package's version, and the pin change that brings it is highlighted. */
|
|
22
|
+
introducedIn?: { package: string; version: string };
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
const t = (en: string, zh: string): Text => ({ en, zh });
|
|
@@ -290,6 +292,23 @@ export const DETECTOR_META: Record<string, DetectorMeta> = {
|
|
|
290
292
|
fail: t("Edits and ends; the guard adds 'no passing run of `npm test`'.", "改檔就結束,收尾檢查加上「沒有 `npm test` 的通過紀錄」。"),
|
|
291
293
|
},
|
|
292
294
|
},
|
|
295
|
+
plan_names_graph: {
|
|
296
|
+
introducedIn: { package: "pi-straw-boss", version: "0.101.0" },
|
|
297
|
+
label: t("Plan says how the work splits", "排工作時說清楚怎麼分工"),
|
|
298
|
+
meaning: t(
|
|
299
|
+
"When a Straw Boss main (coordinator or standing) writes its plan as todos, it names the plan's shape: one loop it runs itself, parallel workers it merges, or an orchestrator handing work out.",
|
|
300
|
+
"Straw Boss 的主代理(協調或常駐)把計畫寫成待辦時,有說明這份計畫的分工方式:自己一路做完、分給幾個人平行做再合併,或由主代理派工給工作者。",
|
|
301
|
+
),
|
|
302
|
+
goodDirection: "higher",
|
|
303
|
+
howComputed: t(
|
|
304
|
+
"Passes when the open todos left by the main's first todo create carry a graph (the todo's graph field, or an older metadata.graph), or when its next todo call adds one, as sb 0.101.0 and later ask on that create. Fails when it went on planning without one. Sessions that are not such a main, or never planned, do not count.",
|
|
305
|
+
"主代理第一次建立待辦後,還沒完成的待辦有標分工方式(待辦的 graph 欄位,或舊版的 metadata.graph)即通過;第一次沒標、但下一次動待辦時補上的也算通過(sb 0.101.0 起會在那次建立待辦時提醒)。沒標就繼續排工作的不通過。不是這類主代理、或從沒排過工作的不算。",
|
|
306
|
+
),
|
|
307
|
+
example: {
|
|
308
|
+
pass: t("Creates three todos with graph 'fan-out/fan-in', then dispatches them.", "建立三項待辦並標上「fan-out/fan-in」,再派出去。"),
|
|
309
|
+
fail: t("Creates three todos with no graph, gets sb's reminder, and adds a fourth without one.", "建立三項待辦沒標分工方式,收到 sb 提醒後又加了第四項,仍然沒標。"),
|
|
310
|
+
},
|
|
311
|
+
},
|
|
293
312
|
};
|
|
294
313
|
|
|
295
314
|
export const NOTICE_META: Record<string, Text> = {
|
package/src/model.ts
CHANGED
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { ASK_BUCKETS, type DayAgg, emptyDay, mergeDay, type SessionRow } from "./aggregate.ts";
|
|
7
7
|
import type { DaysIndex } from "./build.ts";
|
|
8
|
-
import { type Change, versionAt } from "./changes.ts";
|
|
8
|
+
import { atLeast, type Change, versionAt } from "./changes.ts";
|
|
9
9
|
import type { Coverage } from "./coverage.ts";
|
|
10
10
|
import { DETECTORS, ERA_START } from "./detectors.ts";
|
|
11
11
|
import { CHANGE_KIND_META, CLOSE_KIND_META, DETECTOR_META, METRICS, NOTICE_META, STALL_KIND_META } from "./meta.ts";
|
|
12
12
|
import { staticOwner } from "./owners.ts";
|
|
13
13
|
import { weeklyRises } from "./trends.ts";
|
|
14
|
+
import { asksModel } from "./asks.ts";
|
|
14
15
|
import { labelsModel } from "./labels.ts";
|
|
15
16
|
import { ANCHORLOOP, type ItemsFile } from "./work/join.ts";
|
|
16
17
|
import { workModel } from "./work/model.ts";
|
|
@@ -125,6 +126,38 @@ export function impactMetrics(rows: SessionRow[], ownerOf: (tool: string) => str
|
|
|
125
126
|
anchor_before_first_edit: d("anchor_before_first_edit"),
|
|
126
127
|
check_after_last_edit: d("check_after_last_edit"),
|
|
127
128
|
todo_evidence: d("todo_evidence"),
|
|
129
|
+
plan_names_graph: d("plan_names_graph"),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Dotted versions in numeric order; anything else (unknown, a sha) after them. */
|
|
134
|
+
const byVersion = (a: string, b: string) => {
|
|
135
|
+
const pa = /^\d+(\.\d+)*$/.test(a) ? a.split(".").map(Number) : undefined, pb = /^\d+(\.\d+)*$/.test(b) ? b.split(".").map(Number) : undefined;
|
|
136
|
+
if (!pa || !pb) return pa ? -1 : pb ? 1 : a.localeCompare(b);
|
|
137
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) if ((pa[i] ?? 0) !== (pb[i] ?? 0)) return (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
138
|
+
return 0;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/** A detector's results by the version of the package it measures, at each session's start, and before and from the version that brought it. */
|
|
142
|
+
export function packageSplit(rows: SessionRow[], changes: Change[], detector: string, since: { package: string; version: string }) {
|
|
143
|
+
const versions = new Map<string, { pass: number; fail: number }>();
|
|
144
|
+
const sides = { before: { pass: 0, fail: 0 }, after: { pass: 0, fail: 0 } };
|
|
145
|
+
for (const r of rows) {
|
|
146
|
+
const v = r.ev[detector];
|
|
147
|
+
if (v === undefined) continue;
|
|
148
|
+
const version = versionAt(changes, since.package, r.s) ?? "unknown";
|
|
149
|
+
const cell = versions.get(version) ?? { pass: 0, fail: 0 };
|
|
150
|
+
cell[v ? "pass" : "fail"] += 1;
|
|
151
|
+
versions.set(version, cell);
|
|
152
|
+
const later = atLeast(version, since.version);
|
|
153
|
+
if (later !== undefined) sides[later ? "after" : "before"][v ? "pass" : "fail"] += 1;
|
|
154
|
+
}
|
|
155
|
+
const withRate = (x: { pass: number; fail: number }) => ({ ...x, passRate: rate(x.pass, x.pass + x.fail) });
|
|
156
|
+
return {
|
|
157
|
+
...since,
|
|
158
|
+
versions: [...versions].sort(([a], [b]) => byVersion(a, b)).map(([version, x]) => ({ version, ...withRate(x) })),
|
|
159
|
+
before: withRate(sides.before),
|
|
160
|
+
after: withRate(sides.after),
|
|
128
161
|
};
|
|
129
162
|
}
|
|
130
163
|
|
|
@@ -180,6 +213,8 @@ export function buildModel(options: {
|
|
|
180
213
|
filter: Filter;
|
|
181
214
|
windowDays: number;
|
|
182
215
|
labelsFile: string;
|
|
216
|
+
/** `asks.jsonl`, when the caller has one. */
|
|
217
|
+
asksFile?: string;
|
|
183
218
|
sessionEvalsFile: string;
|
|
184
219
|
coverage?: Coverage;
|
|
185
220
|
/** Joined work items (`index/items.json`), when built. */
|
|
@@ -215,8 +250,9 @@ export function buildModel(options: {
|
|
|
215
250
|
const selected = projectRows.filter(r => inRange(r.s)), children = selected.filter(r => r.k);
|
|
216
251
|
const scoped = Boolean(filter.since || filter.until || filter.project);
|
|
217
252
|
const hasSessionIds = selected.every(r => r.id !== undefined);
|
|
218
|
-
const labelIds = scoped && existsSync(options.labelsFile) ? new Set(selected.flatMap(r => r.id ? [r.id] : [])) : undefined;
|
|
253
|
+
const labelIds = scoped && (existsSync(options.labelsFile) || (!!options.asksFile && existsSync(options.asksFile))) ? new Set(selected.flatMap(r => r.id ? [r.id] : [])) : undefined;
|
|
219
254
|
const indexedIds = labelIds && new Set(options.rows.flatMap(r => r.id ? [r.id] : []));
|
|
255
|
+
const labelScope = { ...filter, until: options.openEnd ? undefined : filter.until, selected: labelIds, indexed: indexedIds };
|
|
220
256
|
const calls = Object.values(total.tools).reduce((s, t) => s + t.calls, 0);
|
|
221
257
|
const errors = Object.values(total.tools).reduce((s, t) => s + t.errors, 0);
|
|
222
258
|
const tokens = total.usage.input + total.usage.output + total.usage.cacheRead + total.usage.cacheWrite;
|
|
@@ -305,6 +341,7 @@ export function buildModel(options: {
|
|
|
305
341
|
return { day, pass: x.pass, fail: x.fail };
|
|
306
342
|
}),
|
|
307
343
|
byVersion: (versions.get(d.name) ?? []).map((v) => ({ ...v, passRate: rate(v.pass, v.pass + v.fail) })),
|
|
344
|
+
byPackage: DETECTOR_META[d.name]?.introducedIn ? packageSplit(selected, sortedChanges, d.name, DETECTOR_META[d.name].introducedIn!) : null,
|
|
308
345
|
})),
|
|
309
346
|
notices: total.notices,
|
|
310
347
|
},
|
|
@@ -324,7 +361,8 @@ export function buildModel(options: {
|
|
|
324
361
|
.filter((c) => inRange(c.at))
|
|
325
362
|
.map((c) => ({ ...c, impact: index.range.start && c.at > index.range.start ? impactFromRows(projectRows, c, sortedChanges, options.windowDays, index.range, owner) : null })),
|
|
326
363
|
labels: {
|
|
327
|
-
...labelsModel(options.labelsFile, options.sessionEvalsFile,
|
|
364
|
+
...labelsModel(options.labelsFile, options.sessionEvalsFile, labelScope, (at) => versionAt(sortedChanges, ANCHORLOOP, at)),
|
|
365
|
+
asks: asksModel(options.asksFile, options.labelsFile, labelScope),
|
|
328
366
|
needsIndex: !!labelIds && !hasSessionIds,
|
|
329
367
|
},
|
|
330
368
|
coverage: options.coverage ?? null,
|
package/src/ops.ts
CHANGED
|
@@ -80,7 +80,7 @@ function snapshot(env?: Env, withCoverage = true) {
|
|
|
80
80
|
const filter = rangeFilter(input, index.lastExtract ?? now.toISOString(), preset);
|
|
81
81
|
// A range ends at the last extract unless the user ends it; a label given since then has no session in the index yet.
|
|
82
82
|
return buildModel({ index, rows, changes, comparisons, filter, now, windowDays: ctx.settings.impactWindowDays, openEnd: input.until === undefined,
|
|
83
|
-
labelsFile: ctx.layout.labels, sessionEvalsFile: ctx.layout.sessionEvals, coverage: cov?.(filter), work });
|
|
83
|
+
labelsFile: ctx.layout.labels, asksFile: ctx.layout.asks, sessionEvalsFile: ctx.layout.sessionEvals, coverage: cov?.(filter), work });
|
|
84
84
|
} };
|
|
85
85
|
}
|
|
86
86
|
export function indexedModel(filter: RangeInput, env?: Env, withCoverage = true) {
|
package/src/paths.ts
CHANGED
|
@@ -83,6 +83,8 @@ export interface Layout {
|
|
|
83
83
|
changes: string;
|
|
84
84
|
marks: string;
|
|
85
85
|
labels: string;
|
|
86
|
+
/** One row per /ask-ai, never the question. */
|
|
87
|
+
asks: string;
|
|
86
88
|
status: string;
|
|
87
89
|
reports: string;
|
|
88
90
|
/** Joined work items (what the report reads), their records, and the lines-changed cache. */
|
|
@@ -103,6 +105,7 @@ export function layout(state = stateDir()): Layout {
|
|
|
103
105
|
changes: join(state, "changes.jsonl"),
|
|
104
106
|
marks: join(state, "marks.jsonl"),
|
|
105
107
|
labels: join(state, "labels.jsonl"),
|
|
108
|
+
asks: join(state, "asks.jsonl"),
|
|
106
109
|
status: join(state, "index", "status.json"),
|
|
107
110
|
reports: join(state, "reports"),
|
|
108
111
|
items: join(state, "index", "items.json"),
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `plan_names_graph`: whether a Straw Boss main of kind coordinator or standing names its plan's graph when it plans.
|
|
3
|
+
*
|
|
4
|
+
* The graph is a todo's own `graph` (pi-todo-ledger 0.4.0: `single-loop`, `fan-out/fan-in`, `orchestrator-worker`), else a
|
|
5
|
+
* legacy `metadata.graph`, read as pi-straw-boss reads it (`items.ts` `todosOf`, `duty.ts` `graphOf`, MIT, Copyright (c) 2026
|
|
6
|
+
* Wei Hung, sb 0.103.0). From sb 0.101.0 a main whose `todo` create leaves open todos with no graph gets planning.md §1-§2
|
|
7
|
+
* on that result (`planhint.ts`); the next todo call shows whether the main took it. A train's steps (`metadata.sb`) are not
|
|
8
|
+
* the plan. The main's kind comes from its role prompt (system section or a role steer) and its kind entries.
|
|
9
|
+
*/
|
|
10
|
+
import type { DetectorResult } from "./detectors.ts";
|
|
11
|
+
|
|
12
|
+
/** The planning-rule block's first line (sb `planhint.ts` OPENING). */
|
|
13
|
+
const RULE_OPENING = "sb: your open todos name no graph.";
|
|
14
|
+
const GRAPHS = new Set(["single-loop", "fan-out/fan-in", "orchestrator-worker"]);
|
|
15
|
+
const JUDGED = new Set(["coordinator", "standing"]);
|
|
16
|
+
const MAIN_PROMPT = /You are the main agent of Herdr tab .*?,? of kind ([a-z]+)/;
|
|
17
|
+
const STANDING_PROMPT = /You are the standing main of Herdr tab /;
|
|
18
|
+
|
|
19
|
+
type Obj = Record<string, unknown>;
|
|
20
|
+
const obj = (v: unknown): Obj => (v && typeof v === "object" ? (v as Obj) : {});
|
|
21
|
+
|
|
22
|
+
/** A legacy `metadata.graph` as mains wrote it, normalised like sb's `graphOf`. */
|
|
23
|
+
export function legacyGraph(v: unknown): string | undefined {
|
|
24
|
+
if (v === "orchestrator-worker") return v;
|
|
25
|
+
if (v === "fan-out/fan-in" || v === "fan-out") return "fan-out/fan-in";
|
|
26
|
+
if (v === "single" || (typeof v === "string" && v.startsWith("single-loop"))) return "single-loop";
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A todo's graph: its own field when it is a graph name, else its legacy metadata. */
|
|
31
|
+
export function graphOfTodo(todo: unknown): string | undefined {
|
|
32
|
+
const t = obj(todo);
|
|
33
|
+
if (typeof t.graph === "string" && GRAPHS.has(t.graph)) return t.graph;
|
|
34
|
+
return legacyGraph(obj(t.metadata).graph);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The plan's open todos: not completed or deleted, and not a train's step. */
|
|
38
|
+
function openOf(tasks: unknown[]): Obj[] {
|
|
39
|
+
return tasks.map(obj).filter((t) => t.status !== "completed" && t.status !== "deleted" && !obj(t.metadata).sb);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function text(content: unknown): string {
|
|
43
|
+
if (typeof content === "string") return content;
|
|
44
|
+
return Array.isArray(content) ? content.map((p) => (obj(p).type === "text" ? String(obj(p).text ?? "") : "")).join("\n") : "";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class PlanGraphTracker {
|
|
48
|
+
private kind: string | undefined;
|
|
49
|
+
private wasMain = false;
|
|
50
|
+
private tasks: unknown[] | undefined;
|
|
51
|
+
private calls = new Map<string, boolean>();
|
|
52
|
+
/** The first plan (a create leaving open todos) named no graph; `rule`: sb's block came with it. */
|
|
53
|
+
private missed: { rule: boolean } | undefined;
|
|
54
|
+
private result: DetectorResult | undefined;
|
|
55
|
+
|
|
56
|
+
feed(entry: Obj): void {
|
|
57
|
+
if (this.result) return;
|
|
58
|
+
const type = entry.type;
|
|
59
|
+
if (type === "custom") {
|
|
60
|
+
const data = obj(entry.data);
|
|
61
|
+
if (entry.customType === "todo/v1" && Array.isArray(data.tasks)) this.tasks = data.tasks;
|
|
62
|
+
else if (entry.customType === "straw-boss" && typeof data.duty === "string" && this.kind) this.setKind(data.duty);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (type === "custom_message" && entry.customType === "straw-boss") {
|
|
66
|
+
const briefed = obj(obj(entry.details).briefed);
|
|
67
|
+
const role = briefed.name ?? briefed.role;
|
|
68
|
+
if (typeof role === "string") this.setKind(role === "main" && typeof briefed.duty === "string" ? briefed.duty : undefined);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (type !== "message") return;
|
|
72
|
+
const message = obj(entry.message);
|
|
73
|
+
if (message.role === "system") {
|
|
74
|
+
const section = obj(message.sections)["straw-boss"];
|
|
75
|
+
if (typeof section !== "string") return;
|
|
76
|
+
this.setKind(STANDING_PROMPT.test(section) ? "standing" : MAIN_PROMPT.exec(section)?.[1]);
|
|
77
|
+
} else if (message.role === "assistant" && Array.isArray(message.content)) {
|
|
78
|
+
for (const raw of message.content) {
|
|
79
|
+
const part = obj(raw);
|
|
80
|
+
if (part.type === "toolCall" && part.name === "todo" && typeof part.id === "string") this.calls.set(part.id, obj(part.arguments).action === "create");
|
|
81
|
+
}
|
|
82
|
+
} else if (message.role === "toolResult" && typeof message.toolCallId === "string" && this.calls.has(message.toolCallId)) {
|
|
83
|
+
const create = this.calls.get(message.toolCallId)!;
|
|
84
|
+
this.calls.delete(message.toolCallId);
|
|
85
|
+
if (message.isError === true || !this.kind || !JUDGED.has(this.kind)) return;
|
|
86
|
+
const listed = obj(message.details).tasks;
|
|
87
|
+
this.todoResult(create, Array.isArray(listed) ? listed : (this.tasks ?? []), text(message.content).includes(RULE_OPENING));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private setKind(kind: string | undefined) {
|
|
92
|
+
this.kind = kind;
|
|
93
|
+
if (kind && JUDGED.has(kind)) this.wasMain = true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private todoResult(create: boolean, tasks: unknown[], rule: boolean) {
|
|
97
|
+
const name = "plan_names_graph";
|
|
98
|
+
const open = openOf(tasks);
|
|
99
|
+
const named = open.some((t) => graphOfTodo(t));
|
|
100
|
+
if (!this.missed) {
|
|
101
|
+
if (!create || !open.length) return;
|
|
102
|
+
if (named) this.result = { name, label: "pass", explanation: "graph_at_first_create" };
|
|
103
|
+
else this.missed = { rule };
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this.result = named
|
|
107
|
+
? { name, label: "pass", explanation: this.missed.rule ? "graph_after_rule" : "graph_next_todo_call" }
|
|
108
|
+
: { name, label: "fail", explanation: "kept_planning_without_graph" };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
results(): DetectorResult {
|
|
112
|
+
const name = "plan_names_graph";
|
|
113
|
+
if (this.result) return this.result;
|
|
114
|
+
if (this.missed) return { name, label: "fail", explanation: "plan_without_graph" };
|
|
115
|
+
return { name, label: "na", explanation: this.wasMain ? "no_plan" : "not_sb_main" };
|
|
116
|
+
}
|
|
117
|
+
}
|
package/src/query.ts
CHANGED
|
@@ -81,6 +81,11 @@ export function query(view: View, options: { since?: string; days?: number; proj
|
|
|
81
81
|
body.push(`${d.name} (${label}): ${pct(d.passRate)}, not applicable ${d.na}`);
|
|
82
82
|
const versions = d.byVersion.filter((v) => v.pass + v.fail > 0).map((v) => `${v.version} ${pct(v.passRate)}`);
|
|
83
83
|
if (versions.length) body.push(` by anchorloop version: ${versions.slice(-4).join("; ")}`);
|
|
84
|
+
const p = d.byPackage;
|
|
85
|
+
if (p) {
|
|
86
|
+
const byV = p.versions.filter((v) => v.pass + v.fail > 0).map((v) => `${v.version} ${pct(v.passRate)}`);
|
|
87
|
+
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)}`);
|
|
88
|
+
}
|
|
84
89
|
}
|
|
85
90
|
body.push(`close-guard reminders: ${Object.entries(m.process.notices).map(([k, v]) => `${k} ${v}`).join(", ") || "none"}`);
|
|
86
91
|
} else if (view === "cost") {
|
package/src/report/findings.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import { crosses } from "../changes.ts";
|
|
1
2
|
import type { Rate, ReportModel } from "../model.ts";
|
|
2
3
|
import { type Change, type Lang, num, pct, usd, type Words, words } from "./format.ts";
|
|
3
4
|
|
|
4
|
-
type Key = "anchor_before_first_edit" | "check_after_last_edit" | "package_error_rate" | "tool_error_rate" | "cost_per_session";
|
|
5
|
+
type Key = "anchor_before_first_edit" | "check_after_last_edit" | "plan_names_graph" | "package_error_rate" | "tool_error_rate" | "cost_per_session";
|
|
6
|
+
|
|
7
|
+
/** The detector whose package version this pin change brings in (or skips past), with that version. */
|
|
8
|
+
export function introduced(c: Pick<Change, "kind" | "package" | "from" | "to">, m: Pick<ReportModel, "meta">): { detector: Key; version: string } | undefined {
|
|
9
|
+
for (const [name, md] of Object.entries(m.meta.detectors)) {
|
|
10
|
+
if (md.introducedIn && crosses(c, md.introducedIn.package, md.introducedIn.version)) return { detector: name as Key, version: md.introducedIn.version };
|
|
11
|
+
}
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
5
14
|
export interface Reading {
|
|
6
15
|
key: Key;
|
|
7
16
|
label: string;
|
|
@@ -14,7 +23,10 @@ export function readings(c: Change, m: ReportModel, lang: Lang): Reading[] {
|
|
|
14
23
|
const L = words(lang), i = c.impact;
|
|
15
24
|
const has = (k: Key) => i?.before[k]?.value != null && i.after[k]?.value != null;
|
|
16
25
|
const process = c.package === "pi-anchorloop" && has("anchor_before_first_edit");
|
|
17
|
-
const
|
|
26
|
+
const brings = introduced(c, m);
|
|
27
|
+
const keys: Key[] = brings
|
|
28
|
+
? [brings.detector, "cost_per_session"]
|
|
29
|
+
: process
|
|
18
30
|
? ["anchor_before_first_edit", "check_after_last_edit"]
|
|
19
31
|
: [has("package_error_rate") ? "package_error_rate" : "tool_error_rate", "cost_per_session"];
|
|
20
32
|
return keys.map((key) => {
|
|
@@ -64,7 +76,8 @@ export function select(m: ReportModel) {
|
|
|
64
76
|
const rest = candidates.filter((c) => c !== lead && c.at <= lead.at && (!lead.sha || c.sha !== lead.sha));
|
|
65
77
|
const second = rest.find((c) => c.impact?.smallSample && c.impact.before.sessions && c.impact.after.sessions) ??
|
|
66
78
|
rest.find((c) => (c.kind === "pin" || c.kind === "model-routing") && c.impact && !c.impact.incomplete) ?? rest[0];
|
|
67
|
-
|
|
79
|
+
// A pin change that brings a detector's package version is always shown: it is what that detector measures.
|
|
80
|
+
const highlighted = all.filter((c) => c === lead || c === second || !!introduced(c, m));
|
|
68
81
|
return { all, lead, highlighted, folded: all.filter((c) => !highlighted.includes(c)) };
|
|
69
82
|
}
|
|
70
83
|
/** Editorial choices shared by the HTML timeline and the compact query. */
|
package/src/report/sections.ts
CHANGED
|
@@ -113,7 +113,11 @@ export function sections(m: ReportModel, lang: Lang, cards: ReturnType<typeof co
|
|
|
113
113
|
more(
|
|
114
114
|
L("By day and version", "查看每日與各版本的通過數"),
|
|
115
115
|
T([L("Day", "日期"), L("Pass", "通過"), L("Fail", "未通過")], d.perDay.map((r) => [r.day, r.pass, r.fail])) +
|
|
116
|
-
T([L("Version", "版本"), L("Pass", "通過"), L("Fail", "未通過")], d.byVersion.map((r) => [r.version, r.pass, r.fail]))
|
|
116
|
+
T([L("Version", "版本"), L("Pass", "通過"), L("Fail", "未通過")], d.byVersion.map((r) => [r.version, r.pass, r.fail])) +
|
|
117
|
+
(d.byPackage
|
|
118
|
+
? `<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>` +
|
|
119
|
+
T([L(`${d.byPackage.package} version`, `${d.byPackage.package} 版本`), L("Pass", "通過"), L("Fail", "未通過")], d.byPackage.versions.map((r) => [r.version, r.pass, r.fail]))
|
|
120
|
+
: ""),
|
|
117
121
|
)
|
|
118
122
|
}</article>`;
|
|
119
123
|
}).join("")
|
|
@@ -154,6 +158,9 @@ export function sections(m: ReportModel, lang: Lang, cards: ReturnType<typeof co
|
|
|
154
158
|
);
|
|
155
159
|
const lb = m.labels, rule = (r: string) => ruleLabel(r, lang);
|
|
156
160
|
const pair = (c: { agree: number; n: number }) => (c.n ? `${num(c.agree)} / ${num(c.n)}` : "—");
|
|
161
|
+
const asked = lb.asks.n
|
|
162
|
+
? `<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>`
|
|
163
|
+
: "";
|
|
157
164
|
const labels = section(
|
|
158
165
|
"labels",
|
|
159
166
|
L("Your labels", "你的標記"),
|
|
@@ -168,13 +175,13 @@ export function sections(m: ReportModel, lang: Lang, cards: ReturnType<typeof co
|
|
|
168
175
|
) +
|
|
169
176
|
`<p class="muted">${L(`Cannot tell ${num(lb.unclear)}: labels marked unclear are left out of the agreement rate.`, `看不出來 ${num(lb.unclear)}:標成「看不出來」的不算進一致比例。`)}${
|
|
170
177
|
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 後就能比),或這條規則不適用於它。`) : ""
|
|
171
|
-
}${lb.other ? L(` ${num(lb.other)} labels are on "Other", which no code check covers.`, `${num(lb.other)} 筆標在「其他」,沒有程式檢查可比。`) : ""}</p>` + lesson(cards.labelTiming, L)
|
|
178
|
+
}${lb.other ? L(` ${num(lb.other)} labels are on "Other", which no code check covers.`, `${num(lb.other)} 筆標在「其他」,沒有程式檢查可比。`) : ""}</p>` + asked + lesson(cards.labelTiming, L)
|
|
172
179
|
: `<p>${
|
|
173
180
|
L(
|
|
174
181
|
"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.",
|
|
175
182
|
"還沒有標記。在任何工作階段輸入 /evals label,就能趁工作還在眼前,標記代理人有沒有照規則做。",
|
|
176
183
|
)
|
|
177
|
-
}</p>` + lesson(cards.labelTiming, L),
|
|
184
|
+
}</p>` + asked + lesson(cards.labelTiming, L),
|
|
178
185
|
);
|
|
179
186
|
const c = lb.corrections, few = c.n < SMALL_SAMPLE;
|
|
180
187
|
const corrections = section(
|
package/src/report/strip.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReportModel } from "../model.ts";
|
|
2
2
|
import type { Preset } from "../ranges.ts";
|
|
3
|
+
import { introduced } from "./findings.ts";
|
|
3
4
|
import { type Change, esc, type Lang, num, words } from "./format.ts";
|
|
4
5
|
|
|
5
6
|
const KINDS = ["pin", "model-routing", "rule", "agent-role", "skill", "manual"] as const;
|
|
@@ -32,7 +33,8 @@ export function changeStrip(m: ReportModel, all: Change[], picks: Change[], ids:
|
|
|
32
33
|
if (cells.length > 5) marks.push(`<text class="slot-count" x="${left + 14}" y="28" text-anchor="middle">×${cells.length}</text>`);
|
|
33
34
|
}
|
|
34
35
|
const links = picks.map((c,i) => {
|
|
35
|
-
const {px, py, dot} = labeled.get(c)!, end = px > 700,
|
|
36
|
+
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})`) : "",
|
|
37
|
+
caption = c.package ? `${c.package} ${c.to ?? ""}${skipped}` : `${label(c.kind)} · ${c.at.slice(5,16).replace("T", " ")}`;
|
|
36
38
|
const y = 87 + i * 23;
|
|
37
39
|
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>`;
|
|
38
40
|
}).join("");
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The turn a command's own message starts: armed when the command sends it, open from the moment that message starts
|
|
3
|
+
* the run (`before_agent_start`, or its user message when it was queued behind a running turn), and closed at
|
|
4
|
+
* `agent_end`, on another message from the user, or at a new session.
|
|
5
|
+
*/
|
|
6
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
|
|
8
|
+
export interface Turn<T> {
|
|
9
|
+
session: string;
|
|
10
|
+
prompt: string;
|
|
11
|
+
data: T;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const textOf = (content: unknown) =>
|
|
15
|
+
typeof content === "string" ? content : Array.isArray(content) ? content.map((p) => (p && typeof p === "object" && typeof (p as { text?: unknown }).text === "string" ? (p as { text: string }).text : "")).join("") : "";
|
|
16
|
+
|
|
17
|
+
export function turnWindow<T>(pi: ExtensionAPI) {
|
|
18
|
+
let waiting: Turn<T> | undefined;
|
|
19
|
+
let open: Turn<T> | undefined;
|
|
20
|
+
const start = (text: string | undefined) => {
|
|
21
|
+
if (waiting && text === waiting.prompt) {
|
|
22
|
+
open = waiting;
|
|
23
|
+
waiting = undefined;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
pi.on("before_agent_start", (event) => start((event as { prompt?: string }).prompt));
|
|
27
|
+
pi.on("message_end", (event) => {
|
|
28
|
+
const message = (event as { message?: { role?: string; content?: unknown } }).message;
|
|
29
|
+
if (message?.role !== "user") return;
|
|
30
|
+
const text = textOf(message.content);
|
|
31
|
+
if (open && text !== open.prompt) open = undefined;
|
|
32
|
+
start(text);
|
|
33
|
+
});
|
|
34
|
+
pi.on("agent_end", () => {
|
|
35
|
+
open = undefined;
|
|
36
|
+
});
|
|
37
|
+
pi.on("session_start", () => {
|
|
38
|
+
waiting = open = undefined;
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
/** The message the command is about to send; its turn opens when that message starts a run. */
|
|
42
|
+
arm(turn: Turn<T>) {
|
|
43
|
+
waiting = turn;
|
|
44
|
+
},
|
|
45
|
+
/** The open turn of this session, if any. */
|
|
46
|
+
current(session: string): Turn<T> | undefined {
|
|
47
|
+
return open?.session === session ? open : undefined;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|