pi-evals 0.5.0 → 0.5.2
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 +11 -0
- package/dist/detectors.js +106 -24
- package/dist/extract/run.js +1 -1
- package/dist/labels.js +14 -1
- package/dist/meta.js +2 -2
- package/docs/design.md +2 -2
- package/docs/schema.md +4 -2
- package/package.json +1 -1
- package/src/detectors.ts +110 -26
- package/src/extract/run.ts +1 -1
- package/src/labels.ts +19 -3
- package/src/meta.ts +8 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.2
|
|
4
|
+
|
|
5
|
+
- A later human label on the same session, rule and item replaces the earlier one in the report and agreement; `labels.jsonl` keeps both. New `source: "recheck"` for your second look at a label given after the fact (counted as 事後標). Each 「其他」 label stays its own event, and agent corrections are never replaced.
|
|
6
|
+
|
|
7
|
+
## 0.5.1
|
|
8
|
+
|
|
9
|
+
- The two anchor checks read the forms agents actually use, checked against 30 sessions you labelled by hand. An anchor counts when the agent or its brief names the check before the first edit: an `Anchor:` line, a `Gates:`, `Checks:`, `Verify:`, `Done when` or `驗證:` line, a todo anchor or sb check spec, or a check command named in the brief. It also counts when the first change is a test file (red first). A brief's anchor is no longer failed as `anchor_only_in_brief`.
|
|
10
|
+
- 「最後一次修改後有跑檢查」 passes on any of these: anchor commands run in a monitor (judged by exit code), passing todo evidence recorded after the last change, or a test, build, lint or type-check run after it. A failing anchor run still fails. Markdown or text written after the check (a report, a changelog) does not undo the check. A session that edits and runs no check now fails (`no_check_after_change`) instead of being left out. A session that edits only prose is `prose_only`.
|
|
11
|
+
- Agreement with your labels: anchor 15/30 → 24/30, check 4/17 → 23/24. Five held-out sessions that edited and ran no check stay failed on both rules.
|
|
12
|
+
- Re-extracts every session once (extractor version 5).
|
|
13
|
+
|
|
3
14
|
## 0.5.0
|
|
4
15
|
|
|
5
16
|
- `/evals label` labels the current session while the work is in front of you: pick a rule (or 「其他」), then 照做, 沒照做 or 看不出來, then an optional note. `/evals label <rule> pass|fail|unclear [note]` does it in one line, and `/evals label undo` withdraws the session's last one. `/evals label <your words>` hands your words to the agent, which turns them into labels and says what it recorded; the verdict and the note stay yours. Each label keeps the todo item in progress.
|
package/dist/detectors.js
CHANGED
|
@@ -22,18 +22,54 @@ function commandsOf(text, bare) {
|
|
|
22
22
|
const ticked = [...text.matchAll(/`([^`\n]+)`/g)].map((m) => squeeze(m[1])).filter(Boolean);
|
|
23
23
|
return ticked.length || !bare ? ticked : [squeeze(text)].filter(Boolean);
|
|
24
24
|
}
|
|
25
|
+
const LABEL = String.raw `(?:reality anchor|anchor|checks?|gates?|verify|verification|done when|驗證|檢查|驗收)`;
|
|
26
|
+
const LABELLED = new RegExp(String.raw `^[ \t>*_#-]*${LABEL}[*_]*\s*[::][*_]*\s*(.+)$`, "gim");
|
|
25
27
|
function anchorLine(text) {
|
|
26
|
-
|
|
27
|
-
return lines.at(-1)?.[1];
|
|
28
|
+
return [...text.matchAll(LABELLED)].at(-1)?.[1];
|
|
28
29
|
}
|
|
30
|
+
/** Tools and scripts whose run checks a change: tests, builds, linters, type checkers, and named check scripts. */
|
|
31
|
+
const RUNNER = new RegExp([
|
|
32
|
+
String.raw `(?:npm|pnpm|yarn|bun)(?:\s+--?[\w=.'"*/@-]+)*(?:\s+run)?(?:\s+-s)?(?:\s+--?[\w=.'"*/@-]+)*\s+(?:t|test|check|lint|build|typecheck|type-check|verify|e2e|gates?)(?:[:\w-]*)\b`,
|
|
33
|
+
String.raw `(?:(?:npx|bunx|pnpm\s+(?:exec|dlx)|yarn\s+dlx|uv\s+run(?:\s+--?[\w=-]+)*|poetry\s+run)\s+)?(?:vitest|jest|mocha|pytest|tsc|vue-tsc|eslint|ruff|mypy|pyright|biome|svelte-check|shellcheck|dprint\s+check|playwright\s+test|cypress\s+run|astro\s+check)\b`,
|
|
34
|
+
String.raw `node\s+(?:--[\w-]+\s+)*--test\b`,
|
|
35
|
+
String.raw `(?:deno|bun)\s+(?:test|check|lint)\b`,
|
|
36
|
+
String.raw `(?:go\s+(?:test|vet|build)|cargo\s+(?:test|check|build|clippy)|dotnet\s+(?:test|build)|swift\s+(?:test|build)|make\s+(?:test|check|lint)|mvn\s+(?:test|verify)|\S*gradlew?\s+(?:test|build|check))\b`,
|
|
37
|
+
String.raw `python3?(?:\s+-[A-Za-z]+)*\s+-m\s+(?:pytest|unittest|py_compile|mypy)\b`,
|
|
38
|
+
String.raw `ansible-playbook\b.*--(?:check|syntax-check)\b`,
|
|
39
|
+
].join("|"), "i");
|
|
40
|
+
/** A script whose name says it checks: scripts/check-links.mjs, gates.sh, measure.mjs, validate.py. */
|
|
41
|
+
const CHECK_SCRIPT = String.raw `(?:\S*/)?(?:[\w-]*[-_.])?(?:tests?|checks?|gates?|verify|validate|lint|measure)(?:[-_.][\w.-]*)?\.(?:py|sh|mjs|js|ts)\b`;
|
|
42
|
+
const INTERPRETER = String.raw `(?:(?:bash|sh|python3?|node|bun|uv\s+run(?:\s+--?[\w=-]+)*\s+python3?)(?:\s+-[A-Za-z]+)*\s+)`;
|
|
43
|
+
// A run: a runner, a check script, or any script under tests/ (python3 tests/overlay.py, tests/run.sh).
|
|
44
|
+
// A dotnet wrapper script that builds or tests: scripts/dev/dotnet-local.py test <project>.
|
|
45
|
+
const DOTNET_SCRIPT = String.raw `\S*dotnet[\w-]*\.py\s+(?:build|test)\b`;
|
|
46
|
+
const RUN_START = new RegExp(String.raw `^(?:(?:\S*/)?(?:${RUNNER.source})|${INTERPRETER}?(?:${CHECK_SCRIPT}|${DOTNET_SCRIPT}|\S*\btests?/\S+))`, "i");
|
|
47
|
+
// A mention in prose, as in a brief: a runner or a check script anywhere in a line.
|
|
48
|
+
const MENTION = new RegExp(String.raw `(?:^|[\s\x60("'>/])(?:${RUNNER.source}|${CHECK_SCRIPT})`, "im");
|
|
49
|
+
// Shell lead-ins stripped from each command segment before matching.
|
|
50
|
+
const LEAD = /^(?:[({!]\s*|(?:time|exec|command|nice|sudo\s+-n|timeout\s+\d+[smh]?|set\s+-\S+(?:\s+\S+)?)\s+|[A-Za-z_][A-Za-z0-9_]*=(?:'[^']*'|"[^"]*"|\S*)\s+)+/;
|
|
51
|
+
/** Whether a shell command runs a check: one of its `&&`, `||`, `;`, `|` or line segments starts with a check runner. */
|
|
52
|
+
export function isCheckRun(command) {
|
|
53
|
+
return command.split(/&&|\|\||[;|\n]/).some((part) => {
|
|
54
|
+
const segment = part.trim().replace(LEAD, "");
|
|
55
|
+
return segment.length > 0 && RUN_START.test(segment);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Prose a test run cannot check: a report, notes, a changelog. Writing one after the check does not undo the check.
|
|
59
|
+
const PROSE_FILE = /\.(?:md|markdown|txt|rst)$/i;
|
|
60
|
+
const TEST_FILE = /(?:^|\/)(?:tests?|__tests__|specs?)\/|[._-](?:test|spec)\.[A-Za-z]+$|_test\.(?:go|py|rb)$|(?:^|\/)test_[^/]+\.py$|Tests?\.cs$/;
|
|
29
61
|
export class ProcessTracker {
|
|
30
62
|
seq = 0;
|
|
31
63
|
calls = new Map();
|
|
32
64
|
runs = [];
|
|
65
|
+
monitors = new Map();
|
|
66
|
+
evidenceAt = -1;
|
|
33
67
|
anchor;
|
|
34
|
-
|
|
68
|
+
ownAnchor = false;
|
|
69
|
+
anchored;
|
|
35
70
|
firstChange = -1;
|
|
36
71
|
lastChange = -1;
|
|
72
|
+
lastNonProse = -1;
|
|
37
73
|
tasks;
|
|
38
74
|
sawUser = false;
|
|
39
75
|
briefAnchor = false;
|
|
@@ -46,6 +82,13 @@ export class ProcessTracker {
|
|
|
46
82
|
this.tasks = entry.data.tasks;
|
|
47
83
|
return undefined;
|
|
48
84
|
}
|
|
85
|
+
if (entry?.type === "custom_message" && entry.customType === "pi-loop-monitor") {
|
|
86
|
+
const outcome = entry.details?.monitorOutcome;
|
|
87
|
+
const command = outcome && this.monitors.get(String(outcome.monitorId));
|
|
88
|
+
if (command && typeof outcome.exitCode === "number")
|
|
89
|
+
this.pushRun(seq, command, outcome.exitCode === 0);
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
49
92
|
if (entry?.type === "custom_message" && entry.customType === NOTICE_TYPE) {
|
|
50
93
|
const kind = noticeKind(entry.content);
|
|
51
94
|
this.notices.set(kind, (this.notices.get(kind) ?? 0) + 1);
|
|
@@ -57,7 +100,11 @@ export class ProcessTracker {
|
|
|
57
100
|
if (message.role === "user" && !this.sawUser) {
|
|
58
101
|
this.sawUser = true;
|
|
59
102
|
const text = Array.isArray(message.content) ? message.content.map((p) => (p?.type === "text" ? (p.text ?? "") : "")).join("\n") : String(message.content ?? "");
|
|
60
|
-
|
|
103
|
+
const line = anchorLine(text);
|
|
104
|
+
// The brief's anchor is the worker's anchor (anchorloop: "Put the unit's Anchor: line in the brief").
|
|
105
|
+
if (line !== undefined)
|
|
106
|
+
this.anchor = commandsOf(line, false);
|
|
107
|
+
this.briefAnchor = line !== undefined || MENTION.test(text);
|
|
61
108
|
}
|
|
62
109
|
else if (message.role === "assistant" && Array.isArray(message.content)) {
|
|
63
110
|
for (const part of message.content) {
|
|
@@ -67,17 +114,25 @@ export class ProcessTracker {
|
|
|
67
114
|
this.setAnchor(commandsOf(line, false));
|
|
68
115
|
}
|
|
69
116
|
else if (part?.type === "toolCall" && typeof part.id === "string") {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
117
|
+
const args = part.arguments ?? {};
|
|
118
|
+
const command = (part.name === "bash" || part.name === "MonitorCreate") && typeof args.command === "string" ? squeeze(args.command) : undefined;
|
|
119
|
+
const path = typeof args.path === "string" ? args.path : undefined;
|
|
120
|
+
let evidence = false;
|
|
121
|
+
if (part.name === "todo") {
|
|
122
|
+
const batch = Array.isArray(args.tasks) ? args.tasks : [];
|
|
123
|
+
for (const item of [args, ...batch]) {
|
|
75
124
|
const meta = item?.metadata;
|
|
76
125
|
const value = [item?.anchor, meta?.anchor].find((v) => typeof v === "string" && v.trim());
|
|
126
|
+
const spec = meta?.sb?.spec?.check;
|
|
77
127
|
if (value)
|
|
78
128
|
this.setAnchor(commandsOf(value, true));
|
|
129
|
+
else if (spec)
|
|
130
|
+
this.setAnchor(typeof spec.run === "string" && spec.run.trim() ? [squeeze(spec.run)] : []);
|
|
131
|
+
if (Array.isArray(item?.evidence) && item.evidence.some((e) => e?.result === "pass"))
|
|
132
|
+
evidence = true;
|
|
79
133
|
}
|
|
80
134
|
}
|
|
135
|
+
this.calls.set(part.id, { name: String(part.name), command, path, evidence });
|
|
81
136
|
}
|
|
82
137
|
}
|
|
83
138
|
}
|
|
@@ -91,20 +146,34 @@ export class ProcessTracker {
|
|
|
91
146
|
if ((call.name === "write" || call.name === "edit") && ok) {
|
|
92
147
|
if (this.firstChange < 0) {
|
|
93
148
|
this.firstChange = seq;
|
|
94
|
-
this.
|
|
149
|
+
this.anchored = this.ownAnchor ? "anchor_first" : this.briefAnchor ? "anchor_in_brief" : call.path && TEST_FILE.test(call.path) ? "test_first" : undefined;
|
|
95
150
|
}
|
|
96
151
|
this.lastChange = seq;
|
|
152
|
+
if (!call.path || !PROSE_FILE.test(call.path))
|
|
153
|
+
this.lastNonProse = seq;
|
|
97
154
|
}
|
|
98
155
|
else if (call.name === "bash" && call.command) {
|
|
99
|
-
this.
|
|
100
|
-
|
|
101
|
-
|
|
156
|
+
this.pushRun(seq, call.command, ok);
|
|
157
|
+
}
|
|
158
|
+
else if (call.name === "MonitorCreate" && call.command && ok) {
|
|
159
|
+
const id = /Monitor #(\d+) started/.exec(resultText(message.content))?.[1];
|
|
160
|
+
if (id)
|
|
161
|
+
this.monitors.set(id, call.command);
|
|
162
|
+
}
|
|
163
|
+
else if (call.name === "todo" && call.evidence && ok) {
|
|
164
|
+
this.evidenceAt = seq;
|
|
102
165
|
}
|
|
103
166
|
}
|
|
104
167
|
return undefined;
|
|
105
168
|
}
|
|
106
169
|
setAnchor(commands) {
|
|
107
170
|
this.anchor = commands;
|
|
171
|
+
this.ownAnchor = true;
|
|
172
|
+
}
|
|
173
|
+
pushRun(seq, command, ok) {
|
|
174
|
+
this.runs.push({ seq, command, ok });
|
|
175
|
+
if (this.runs.length > MAX_RUNS)
|
|
176
|
+
this.runs.splice(0, this.runs.length - MAX_RUNS);
|
|
108
177
|
}
|
|
109
178
|
results(inScope) {
|
|
110
179
|
if (!inScope)
|
|
@@ -115,23 +184,33 @@ export class ProcessTracker {
|
|
|
115
184
|
const name = "anchor_before_first_edit";
|
|
116
185
|
if (this.firstChange < 0)
|
|
117
186
|
return { name, label: "na", explanation: "no_edit" };
|
|
118
|
-
if (this.
|
|
119
|
-
return { name, label: "pass", explanation:
|
|
120
|
-
return { name, label: "fail", explanation:
|
|
187
|
+
if (this.anchored)
|
|
188
|
+
return { name, label: "pass", explanation: this.anchored };
|
|
189
|
+
return { name, label: "fail", explanation: "change_before_anchor" };
|
|
121
190
|
}
|
|
122
191
|
checkAfter() {
|
|
123
192
|
const name = "check_after_last_edit";
|
|
124
193
|
if (this.lastChange < 0)
|
|
125
194
|
return { name, label: "na", explanation: "no_edit" };
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
195
|
+
const prose = this.lastNonProse < 0;
|
|
196
|
+
const last = prose ? this.lastChange : this.lastNonProse;
|
|
197
|
+
const commands = this.anchor ?? [];
|
|
198
|
+
const latest = commands.map((command) => this.runs.findLast((run) => run.command.includes(command)));
|
|
199
|
+
if (commands.length && latest.every((run) => !!run && run.seq > last && run.ok))
|
|
200
|
+
return { name, label: "pass", explanation: "anchor_green" };
|
|
201
|
+
if (this.evidenceAt > last)
|
|
202
|
+
return { name, label: "pass", explanation: "evidence_after_change" };
|
|
203
|
+
// An anchor command that ran after the change and failed is a failing check, whatever else passed.
|
|
204
|
+
if (latest.some((run) => !!run && run.seq > last && !run.ok))
|
|
205
|
+
return { name, label: "fail", explanation: "no_passing_run_after_change" };
|
|
206
|
+
const check = this.runs.findLast((run) => run.seq > last && isCheckRun(run.command));
|
|
207
|
+
if (check)
|
|
208
|
+
return check.ok ? { name, label: "pass", explanation: "check_run_after_change" } : { name, label: "fail", explanation: "no_passing_run_after_change" };
|
|
209
|
+
if (prose)
|
|
210
|
+
return { name, label: "na", explanation: "prose_only" };
|
|
211
|
+
if (this.anchor && !commands.length)
|
|
129
212
|
return { name, label: "na", explanation: "anchor_without_command" };
|
|
130
|
-
|
|
131
|
-
const last = this.runs.findLast((run) => run.command.includes(command));
|
|
132
|
-
return !!last && last.seq > this.lastChange && last.ok;
|
|
133
|
-
});
|
|
134
|
-
return green ? { name, label: "pass", explanation: "anchor_green" } : { name, label: "fail", explanation: "no_passing_run_after_change" };
|
|
213
|
+
return { name, label: "fail", explanation: commands.length ? "no_passing_run_after_change" : "no_check_after_change" };
|
|
135
214
|
}
|
|
136
215
|
todoEvidence() {
|
|
137
216
|
const name = "todo_evidence";
|
|
@@ -152,3 +231,6 @@ export class ProcessTracker {
|
|
|
152
231
|
}
|
|
153
232
|
}
|
|
154
233
|
const DETECTORS_ALL = [...DETECTORS];
|
|
234
|
+
function resultText(content) {
|
|
235
|
+
return Array.isArray(content) ? content.map((p) => (p?.type === "text" ? (p.text ?? "") : "")).join("\n") : String(content ?? "");
|
|
236
|
+
}
|
package/dist/extract/run.js
CHANGED
|
@@ -7,7 +7,7 @@ import { Worker } from "node:worker_threads";
|
|
|
7
7
|
import { fileKey } from "../schema.js";
|
|
8
8
|
import { extractFile } from "./file.js";
|
|
9
9
|
/** Bump when extraction changes what it derives; a checkpoint from another version re-reads every file. */
|
|
10
|
-
export const EXTRACTOR_VERSION =
|
|
10
|
+
export const EXTRACTOR_VERSION = 5;
|
|
11
11
|
export function loadCheckpoint(file) {
|
|
12
12
|
if (!existsSync(file))
|
|
13
13
|
return { v: 1, extractor: EXTRACTOR_VERSION, files: {}, catalogs: {} };
|
package/dist/labels.js
CHANGED
|
@@ -45,8 +45,21 @@ function parse(file) {
|
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Rows in effect, in file order. A withdrawal cancels its session's latest live row still in effect before it, and a
|
|
50
|
+
* later human verdict on the same session, rule and item replaces an earlier one (the file keeps both). Each "other"
|
|
51
|
+
* label is its own event, and agent rows are never replaced.
|
|
52
|
+
*/
|
|
49
53
|
export function readLabels(file) {
|
|
54
|
+
const rows = withdrawn(file);
|
|
55
|
+
const latest = new Map();
|
|
56
|
+
rows.forEach((r, i) => {
|
|
57
|
+
if (r.annotator !== "agent" && r.evaluation_name !== "other")
|
|
58
|
+
latest.set(`${r.session_id}\u0000${r.evaluation_name}\u0000${r.item ?? ""}`, i);
|
|
59
|
+
});
|
|
60
|
+
return rows.filter((r, i) => r.annotator === "agent" || r.evaluation_name === "other" || latest.get(`${r.session_id}\u0000${r.evaluation_name}\u0000${r.item ?? ""}`) === i);
|
|
61
|
+
}
|
|
62
|
+
function withdrawn(file) {
|
|
50
63
|
const rows = parse(file);
|
|
51
64
|
const gone = new Set();
|
|
52
65
|
const live = new Map();
|
package/dist/meta.js
CHANGED
|
@@ -222,7 +222,7 @@ export const DETECTOR_META = {
|
|
|
222
222
|
label: t("Said how to check before editing", "動手前先說好怎麼驗證"),
|
|
223
223
|
meaning: t("The agent named the check that proves the work (its Anchor) before changing any file.", "代理人在改任何檔案前,先說出用什麼檢查證明工作完成(Anchor)。"),
|
|
224
224
|
goodDirection: "higher",
|
|
225
|
-
howComputed: t("Passes when an Anchor
|
|
225
|
+
howComputed: t("Passes when, before the first successful edit or write, the agent or its brief named the check (an Anchor, Gates, Checks or 驗證 line, a todo anchor or check spec, or a check command in the brief), or the first change was a test file; sessions without edits do not count.", "第一次成功修改或寫檔之前,代理人或交辦內容已說出檢查(Anchor、Gates、Checks、驗證 等標示行,待辦的 anchor 或檢查設定,或交辦內容裡的檢查指令),或第一個修改的就是測試檔,即通過;沒改檔的工作階段不算。"),
|
|
226
226
|
example: {
|
|
227
227
|
pass: t("Writes 'Anchor: `npm test`', then edits src/app.ts.", "先寫「Anchor: `npm test`」,再修改 src/app.ts。"),
|
|
228
228
|
fail: t("Edits src/app.ts first and names the check afterwards.", "先修改 src/app.ts,之後才說要怎麼檢查。"),
|
|
@@ -232,7 +232,7 @@ export const DETECTOR_META = {
|
|
|
232
232
|
label: t("Ran the check after the last edit", "最後一次修改後有跑檢查"),
|
|
233
233
|
meaning: t("After its final change, the agent ran the check it named and the check passed.", "最後一次修改後,代理人有跑它說好的檢查,而且通過。"),
|
|
234
234
|
goodDirection: "higher",
|
|
235
|
-
howComputed: t("Passes when every command in the
|
|
235
|
+
howComputed: t("Passes when, after the last edit, every Anchor command passed (in bash or a monitor), the agent recorded passing evidence, or a test, build, lint or type-check run passed; a failing Anchor run fails it. Edits to Markdown or text after the check do not count as edits. Sessions with no edit, only prose edits, or an Anchor that is not a command and no run do not count.", "最後一次修改後,Anchor 每個指令都通過(bash 或 monitor),或代理人記下通過的證據,或有測試、建置、lint、型別檢查通過,即通過;Anchor 指令失敗則不通過。檢查之後才改的 Markdown 或文字檔不算修改。沒改檔、只改文字,或 Anchor 不是指令又沒有執行的不算。"),
|
|
236
236
|
example: {
|
|
237
237
|
pass: t("Edits a file, then runs `npm test`, which exits 0.", "改完檔案後執行 `npm test`,結束碼 0。"),
|
|
238
238
|
fail: t("Runs `npm test`, edits one more file, and stops.", "跑完 `npm test` 又改了一個檔案就結束。"),
|
package/docs/design.md
CHANGED
|
@@ -59,8 +59,8 @@ It appends to the state dir, never to the session file, and a failed write warns
|
|
|
59
59
|
Four 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
|
-
- `anchor_before_first_edit`: an `Anchor:` line or todo anchor
|
|
63
|
-
- `check_after_last_edit`: every command of the anchor has a passing run
|
|
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
|
+
- `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
66
|
|
package/docs/schema.md
CHANGED
|
@@ -45,8 +45,8 @@ Back-fill rebuilds each session's items from its `todo/v1` snapshots, diffed alo
|
|
|
45
45
|
|
|
46
46
|
| `gen_ai.evaluation.name` | `pass` | `fail` explanations | `na` explanations |
|
|
47
47
|
| --- | --- | --- | --- |
|
|
48
|
-
| `anchor_before_first_edit` | `anchor_first` | `change_before_anchor
|
|
49
|
-
| `check_after_last_edit` | `anchor_green` | `no_passing_run_after_change` | `no_edit`, `
|
|
48
|
+
| `anchor_before_first_edit` | `anchor_first`, `anchor_in_brief`, `test_first` | `change_before_anchor` | `no_edit` |
|
|
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
52
|
|
|
@@ -66,6 +66,8 @@ There are three kinds of rows:
|
|
|
66
66
|
- A row without `source` is a human verdict given after the fact (the report calls it 事後標, the code `batch`).
|
|
67
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
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: "recheck"` is a human verdict given again after the fact; it replaces the earlier label.
|
|
70
|
+
- A later human row on the same `session_id`, `evaluation_name` and `item` replaces an earlier one (the file keeps both); each `other` row and every agent row stays its own.
|
|
69
71
|
- `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
72
|
|
|
71
73
|
`evaluation_name` is a process check name or `other`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-evals",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
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",
|
package/src/detectors.ts
CHANGED
|
@@ -7,9 +7,13 @@
|
|
|
7
7
|
* MIT, Copyright (c) 2026 Wei Hung, anchorloop 3.3.0 at 7614445): the last `Anchor:` line or todo anchor,
|
|
8
8
|
* backticked commands (a todo's bare value is one command), a change is a successful `write` or `edit`,
|
|
9
9
|
* a bash run passes on exit code 0 (else on `isError` false), and a run matches an anchor command when it contains it.
|
|
10
|
-
* Like the guard, an edit made through bash is not seen as a change.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Like the guard, an edit made through bash is not seen as a change.
|
|
11
|
+
*
|
|
12
|
+
* Unlike the guard, these read the other shapes agents state and run a check in (0.5.1, from human labels): an anchor
|
|
13
|
+
* in the brief (`Anchor:`, `Gates:`, `Checks:`, or a check command it names), a labelled check line in the agent's
|
|
14
|
+
* words (`驗證:`, `Verify:`), a todo's sb check spec, or a first change to a test file (red first); and a check run
|
|
15
|
+
* in a monitor (by its exit code), passing evidence recorded after the last change, or, when no anchor command ran,
|
|
16
|
+
* a test, build, lint or type-check run after it.
|
|
13
17
|
*/
|
|
14
18
|
import type { Label } from "./schema.ts";
|
|
15
19
|
|
|
@@ -48,11 +52,50 @@ function commandsOf(text: string, bare: boolean): string[] {
|
|
|
48
52
|
return ticked.length || !bare ? ticked : [squeeze(text)].filter(Boolean);
|
|
49
53
|
}
|
|
50
54
|
|
|
55
|
+
const LABEL = String.raw`(?:reality anchor|anchor|checks?|gates?|verify|verification|done when|驗證|檢查|驗收)`;
|
|
56
|
+
const LABELLED = new RegExp(String.raw`^[ \t>*_#-]*${LABEL}[*_]*\s*[::][*_]*\s*(.+)$`, "gim");
|
|
57
|
+
|
|
51
58
|
function anchorLine(text: string): string | undefined {
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
return [...text.matchAll(LABELLED)].at(-1)?.[1];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Tools and scripts whose run checks a change: tests, builds, linters, type checkers, and named check scripts. */
|
|
63
|
+
const RUNNER = new RegExp(
|
|
64
|
+
[
|
|
65
|
+
String.raw`(?:npm|pnpm|yarn|bun)(?:\s+--?[\w=.'"*/@-]+)*(?:\s+run)?(?:\s+-s)?(?:\s+--?[\w=.'"*/@-]+)*\s+(?:t|test|check|lint|build|typecheck|type-check|verify|e2e|gates?)(?:[:\w-]*)\b`,
|
|
66
|
+
String.raw`(?:(?:npx|bunx|pnpm\s+(?:exec|dlx)|yarn\s+dlx|uv\s+run(?:\s+--?[\w=-]+)*|poetry\s+run)\s+)?(?:vitest|jest|mocha|pytest|tsc|vue-tsc|eslint|ruff|mypy|pyright|biome|svelte-check|shellcheck|dprint\s+check|playwright\s+test|cypress\s+run|astro\s+check)\b`,
|
|
67
|
+
String.raw`node\s+(?:--[\w-]+\s+)*--test\b`,
|
|
68
|
+
String.raw`(?:deno|bun)\s+(?:test|check|lint)\b`,
|
|
69
|
+
String.raw`(?:go\s+(?:test|vet|build)|cargo\s+(?:test|check|build|clippy)|dotnet\s+(?:test|build)|swift\s+(?:test|build)|make\s+(?:test|check|lint)|mvn\s+(?:test|verify)|\S*gradlew?\s+(?:test|build|check))\b`,
|
|
70
|
+
String.raw`python3?(?:\s+-[A-Za-z]+)*\s+-m\s+(?:pytest|unittest|py_compile|mypy)\b`,
|
|
71
|
+
String.raw`ansible-playbook\b.*--(?:check|syntax-check)\b`,
|
|
72
|
+
].join("|"),
|
|
73
|
+
"i",
|
|
74
|
+
);
|
|
75
|
+
/** A script whose name says it checks: scripts/check-links.mjs, gates.sh, measure.mjs, validate.py. */
|
|
76
|
+
const CHECK_SCRIPT = String.raw`(?:\S*/)?(?:[\w-]*[-_.])?(?:tests?|checks?|gates?|verify|validate|lint|measure)(?:[-_.][\w.-]*)?\.(?:py|sh|mjs|js|ts)\b`;
|
|
77
|
+
const INTERPRETER = String.raw`(?:(?:bash|sh|python3?|node|bun|uv\s+run(?:\s+--?[\w=-]+)*\s+python3?)(?:\s+-[A-Za-z]+)*\s+)`;
|
|
78
|
+
// A run: a runner, a check script, or any script under tests/ (python3 tests/overlay.py, tests/run.sh).
|
|
79
|
+
// A dotnet wrapper script that builds or tests: scripts/dev/dotnet-local.py test <project>.
|
|
80
|
+
const DOTNET_SCRIPT = String.raw`\S*dotnet[\w-]*\.py\s+(?:build|test)\b`;
|
|
81
|
+
const RUN_START = new RegExp(String.raw`^(?:(?:\S*/)?(?:${RUNNER.source})|${INTERPRETER}?(?:${CHECK_SCRIPT}|${DOTNET_SCRIPT}|\S*\btests?/\S+))`, "i");
|
|
82
|
+
// A mention in prose, as in a brief: a runner or a check script anywhere in a line.
|
|
83
|
+
const MENTION = new RegExp(String.raw`(?:^|[\s\x60("'>/])(?:${RUNNER.source}|${CHECK_SCRIPT})`, "im");
|
|
84
|
+
// Shell lead-ins stripped from each command segment before matching.
|
|
85
|
+
const LEAD = /^(?:[({!]\s*|(?:time|exec|command|nice|sudo\s+-n|timeout\s+\d+[smh]?|set\s+-\S+(?:\s+\S+)?)\s+|[A-Za-z_][A-Za-z0-9_]*=(?:'[^']*'|"[^"]*"|\S*)\s+)+/;
|
|
86
|
+
|
|
87
|
+
/** Whether a shell command runs a check: one of its `&&`, `||`, `;`, `|` or line segments starts with a check runner. */
|
|
88
|
+
export function isCheckRun(command: string): boolean {
|
|
89
|
+
return command.split(/&&|\|\||[;|\n]/).some((part) => {
|
|
90
|
+
const segment = part.trim().replace(LEAD, "");
|
|
91
|
+
return segment.length > 0 && RUN_START.test(segment);
|
|
92
|
+
});
|
|
54
93
|
}
|
|
55
94
|
|
|
95
|
+
// Prose a test run cannot check: a report, notes, a changelog. Writing one after the check does not undo the check.
|
|
96
|
+
const PROSE_FILE = /\.(?:md|markdown|txt|rst)$/i;
|
|
97
|
+
const TEST_FILE = /(?:^|\/)(?:tests?|__tests__|specs?)\/|[._-](?:test|spec)\.[A-Za-z]+$|_test\.(?:go|py|rb)$|(?:^|\/)test_[^/]+\.py$|Tests?\.cs$/;
|
|
98
|
+
|
|
56
99
|
type Part = { type?: string; text?: string; id?: string; name?: string; arguments?: Record<string, unknown> };
|
|
57
100
|
interface Task { status?: string; evidence?: unknown }
|
|
58
101
|
type Entry = {
|
|
@@ -60,17 +103,22 @@ type Entry = {
|
|
|
60
103
|
customType?: string;
|
|
61
104
|
content?: unknown;
|
|
62
105
|
data?: { v?: number; tasks?: Task[] };
|
|
106
|
+
details?: { monitorOutcome?: { monitorId?: unknown; exitCode?: unknown } };
|
|
63
107
|
message?: { role?: string; content?: unknown; toolCallId?: string; isError?: boolean; structuredContent?: { exit_code?: unknown } };
|
|
64
108
|
};
|
|
65
109
|
|
|
66
110
|
export class ProcessTracker {
|
|
67
111
|
private seq = 0;
|
|
68
|
-
private calls = new Map<string, { name: string; command?: string }>();
|
|
112
|
+
private calls = new Map<string, { name: string; command?: string; path?: string; evidence?: boolean }>();
|
|
69
113
|
private runs: { seq: number; command: string; ok: boolean }[] = [];
|
|
114
|
+
private monitors = new Map<string, string>();
|
|
115
|
+
private evidenceAt = -1;
|
|
70
116
|
private anchor: string[] | undefined;
|
|
71
|
-
private
|
|
117
|
+
private ownAnchor = false;
|
|
118
|
+
private anchored: "anchor_first" | "anchor_in_brief" | "test_first" | undefined;
|
|
72
119
|
private firstChange = -1;
|
|
73
120
|
private lastChange = -1;
|
|
121
|
+
private lastNonProse = -1;
|
|
74
122
|
private tasks: Task[] | undefined;
|
|
75
123
|
private sawUser = false;
|
|
76
124
|
private briefAnchor = false;
|
|
@@ -84,6 +132,12 @@ export class ProcessTracker {
|
|
|
84
132
|
this.tasks = entry.data.tasks;
|
|
85
133
|
return undefined;
|
|
86
134
|
}
|
|
135
|
+
if (entry?.type === "custom_message" && entry.customType === "pi-loop-monitor") {
|
|
136
|
+
const outcome = entry.details?.monitorOutcome;
|
|
137
|
+
const command = outcome && this.monitors.get(String(outcome.monitorId));
|
|
138
|
+
if (command && typeof outcome.exitCode === "number") this.pushRun(seq, command, outcome.exitCode === 0);
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
87
141
|
if (entry?.type === "custom_message" && entry.customType === NOTICE_TYPE) {
|
|
88
142
|
const kind = noticeKind(entry.content);
|
|
89
143
|
this.notices.set(kind, (this.notices.get(kind) ?? 0) + 1);
|
|
@@ -94,23 +148,32 @@ export class ProcessTracker {
|
|
|
94
148
|
if (message.role === "user" && !this.sawUser) {
|
|
95
149
|
this.sawUser = true;
|
|
96
150
|
const text = Array.isArray(message.content) ? (message.content as Part[]).map((p) => (p?.type === "text" ? (p.text ?? "") : "")).join("\n") : String(message.content ?? "");
|
|
97
|
-
|
|
151
|
+
const line = anchorLine(text);
|
|
152
|
+
// The brief's anchor is the worker's anchor (anchorloop: "Put the unit's Anchor: line in the brief").
|
|
153
|
+
if (line !== undefined) this.anchor = commandsOf(line, false);
|
|
154
|
+
this.briefAnchor = line !== undefined || MENTION.test(text);
|
|
98
155
|
} else if (message.role === "assistant" && Array.isArray(message.content)) {
|
|
99
156
|
for (const part of message.content as Part[]) {
|
|
100
157
|
if (part?.type === "text" && typeof part.text === "string") {
|
|
101
158
|
const line = anchorLine(part.text);
|
|
102
159
|
if (line !== undefined) this.setAnchor(commandsOf(line, false));
|
|
103
160
|
} else if (part?.type === "toolCall" && typeof part.id === "string") {
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
161
|
+
const args = part.arguments ?? {};
|
|
162
|
+
const command = (part.name === "bash" || part.name === "MonitorCreate") && typeof args.command === "string" ? squeeze(args.command) : undefined;
|
|
163
|
+
const path = typeof args.path === "string" ? args.path : undefined;
|
|
164
|
+
let evidence = false;
|
|
165
|
+
if (part.name === "todo") {
|
|
166
|
+
const batch = Array.isArray(args.tasks) ? args.tasks : [];
|
|
167
|
+
for (const item of [args, ...batch] as Record<string, unknown>[]) {
|
|
168
|
+
const meta = item?.metadata as { anchor?: unknown; sb?: { spec?: { check?: { run?: unknown } } } } | undefined;
|
|
110
169
|
const value = [item?.anchor, meta?.anchor].find((v) => typeof v === "string" && v.trim()) as string | undefined;
|
|
170
|
+
const spec = meta?.sb?.spec?.check;
|
|
111
171
|
if (value) this.setAnchor(commandsOf(value, true));
|
|
172
|
+
else if (spec) this.setAnchor(typeof spec.run === "string" && spec.run.trim() ? [squeeze(spec.run)] : []);
|
|
173
|
+
if (Array.isArray(item?.evidence) && item.evidence.some((e) => (e as { result?: unknown })?.result === "pass")) evidence = true;
|
|
112
174
|
}
|
|
113
175
|
}
|
|
176
|
+
this.calls.set(part.id, { name: String(part.name), command, path, evidence });
|
|
114
177
|
}
|
|
115
178
|
}
|
|
116
179
|
} else if (message.role === "toolResult" && typeof message.toolCallId === "string") {
|
|
@@ -122,12 +185,17 @@ export class ProcessTracker {
|
|
|
122
185
|
if ((call.name === "write" || call.name === "edit") && ok) {
|
|
123
186
|
if (this.firstChange < 0) {
|
|
124
187
|
this.firstChange = seq;
|
|
125
|
-
this.
|
|
188
|
+
this.anchored = this.ownAnchor ? "anchor_first" : this.briefAnchor ? "anchor_in_brief" : call.path && TEST_FILE.test(call.path) ? "test_first" : undefined;
|
|
126
189
|
}
|
|
127
190
|
this.lastChange = seq;
|
|
191
|
+
if (!call.path || !PROSE_FILE.test(call.path)) this.lastNonProse = seq;
|
|
128
192
|
} else if (call.name === "bash" && call.command) {
|
|
129
|
-
this.
|
|
130
|
-
|
|
193
|
+
this.pushRun(seq, call.command, ok);
|
|
194
|
+
} else if (call.name === "MonitorCreate" && call.command && ok) {
|
|
195
|
+
const id = /Monitor #(\d+) started/.exec(resultText(message.content))?.[1];
|
|
196
|
+
if (id) this.monitors.set(id, call.command);
|
|
197
|
+
} else if (call.name === "todo" && call.evidence && ok) {
|
|
198
|
+
this.evidenceAt = seq;
|
|
131
199
|
}
|
|
132
200
|
}
|
|
133
201
|
return undefined;
|
|
@@ -135,6 +203,12 @@ export class ProcessTracker {
|
|
|
135
203
|
|
|
136
204
|
private setAnchor(commands: string[]) {
|
|
137
205
|
this.anchor = commands;
|
|
206
|
+
this.ownAnchor = true;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private pushRun(seq: number, command: string, ok: boolean) {
|
|
210
|
+
this.runs.push({ seq, command, ok });
|
|
211
|
+
if (this.runs.length > MAX_RUNS) this.runs.splice(0, this.runs.length - MAX_RUNS);
|
|
138
212
|
}
|
|
139
213
|
|
|
140
214
|
results(inScope: boolean): DetectorResult[] {
|
|
@@ -145,20 +219,26 @@ export class ProcessTracker {
|
|
|
145
219
|
private anchorFirst(): DetectorResult {
|
|
146
220
|
const name = "anchor_before_first_edit";
|
|
147
221
|
if (this.firstChange < 0) return { name, label: "na", explanation: "no_edit" };
|
|
148
|
-
if (this.
|
|
149
|
-
return { name, label: "fail", explanation:
|
|
222
|
+
if (this.anchored) return { name, label: "pass", explanation: this.anchored };
|
|
223
|
+
return { name, label: "fail", explanation: "change_before_anchor" };
|
|
150
224
|
}
|
|
151
225
|
|
|
152
226
|
private checkAfter(): DetectorResult {
|
|
153
227
|
const name = "check_after_last_edit";
|
|
154
228
|
if (this.lastChange < 0) return { name, label: "na", explanation: "no_edit" };
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
229
|
+
const prose = this.lastNonProse < 0;
|
|
230
|
+
const last = prose ? this.lastChange : this.lastNonProse;
|
|
231
|
+
const commands = this.anchor ?? [];
|
|
232
|
+
const latest = commands.map((command) => this.runs.findLast((run) => run.command.includes(command)));
|
|
233
|
+
if (commands.length && latest.every((run) => !!run && run.seq > last && run.ok)) return { name, label: "pass", explanation: "anchor_green" };
|
|
234
|
+
if (this.evidenceAt > last) return { name, label: "pass", explanation: "evidence_after_change" };
|
|
235
|
+
// An anchor command that ran after the change and failed is a failing check, whatever else passed.
|
|
236
|
+
if (latest.some((run) => !!run && run.seq > last && !run.ok)) return { name, label: "fail", explanation: "no_passing_run_after_change" };
|
|
237
|
+
const check = this.runs.findLast((run) => run.seq > last && isCheckRun(run.command));
|
|
238
|
+
if (check) return check.ok ? { name, label: "pass", explanation: "check_run_after_change" } : { name, label: "fail", explanation: "no_passing_run_after_change" };
|
|
239
|
+
if (prose) return { name, label: "na", explanation: "prose_only" };
|
|
240
|
+
if (this.anchor && !commands.length) return { name, label: "na", explanation: "anchor_without_command" };
|
|
241
|
+
return { name, label: "fail", explanation: commands.length ? "no_passing_run_after_change" : "no_check_after_change" };
|
|
162
242
|
}
|
|
163
243
|
|
|
164
244
|
private todoEvidence(): DetectorResult {
|
|
@@ -180,3 +260,7 @@ export class ProcessTracker {
|
|
|
180
260
|
}
|
|
181
261
|
|
|
182
262
|
const DETECTORS_ALL: DetectorName[] = [...DETECTORS];
|
|
263
|
+
|
|
264
|
+
function resultText(content: unknown): string {
|
|
265
|
+
return Array.isArray(content) ? (content as Part[]).map((p) => (p?.type === "text" ? (p.text ?? "") : "")).join("\n") : String(content ?? "");
|
|
266
|
+
}
|
package/src/extract/run.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface FileEntry {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/** Bump when extraction changes what it derives; a checkpoint from another version re-reads every file. */
|
|
21
|
-
export const EXTRACTOR_VERSION =
|
|
21
|
+
export const EXTRACTOR_VERSION = 5;
|
|
22
22
|
|
|
23
23
|
export interface Checkpoint {
|
|
24
24
|
v: 1;
|
package/src/labels.ts
CHANGED
|
@@ -16,8 +16,11 @@ export const VERDICTS = ["pass", "fail", "unclear"] as const;
|
|
|
16
16
|
export type Verdict = (typeof VERDICTS)[number];
|
|
17
17
|
export const FAILURE_TYPES = ["no_check_stated", "no_check_run", "skipped_rule", "wrong_order", "unverified_claim", "ignored_instruction", "other"] as const;
|
|
18
18
|
export type FailureType = (typeof FAILURE_TYPES)[number];
|
|
19
|
-
/**
|
|
20
|
-
|
|
19
|
+
/**
|
|
20
|
+
* `live-prompt`: the user's words after `/evals label`, which the agent turned into rows on the user's behalf.
|
|
21
|
+
* `recheck`: the user's later verdict on a label given after the fact; it replaces that label.
|
|
22
|
+
*/
|
|
23
|
+
export type LabelSource = "batch" | "live" | "live-prompt" | "correction" | "recheck";
|
|
21
24
|
export const NOTE_MAX = 500;
|
|
22
25
|
|
|
23
26
|
const t = (en: string, zh: string): Text => ({ en, zh });
|
|
@@ -71,8 +74,21 @@ function parse(file: string): LabelRow[] {
|
|
|
71
74
|
});
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* Rows in effect, in file order. A withdrawal cancels its session's latest live row still in effect before it, and a
|
|
79
|
+
* later human verdict on the same session, rule and item replaces an earlier one (the file keeps both). Each "other"
|
|
80
|
+
* label is its own event, and agent rows are never replaced.
|
|
81
|
+
*/
|
|
75
82
|
export function readLabels(file: string): LabelRow[] {
|
|
83
|
+
const rows = withdrawn(file);
|
|
84
|
+
const latest = new Map<string, number>();
|
|
85
|
+
rows.forEach((r, i) => {
|
|
86
|
+
if (r.annotator !== "agent" && r.evaluation_name !== "other") latest.set(`${r.session_id}\u0000${r.evaluation_name}\u0000${r.item ?? ""}`, i);
|
|
87
|
+
});
|
|
88
|
+
return rows.filter((r, i) => r.annotator === "agent" || r.evaluation_name === "other" || latest.get(`${r.session_id}\u0000${r.evaluation_name}\u0000${r.item ?? ""}`) === i);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function withdrawn(file: string): LabelRow[] {
|
|
76
92
|
const rows = parse(file);
|
|
77
93
|
const gone = new Set<number>();
|
|
78
94
|
const live = new Map<string, number[]>();
|
package/src/meta.ts
CHANGED
|
@@ -248,7 +248,10 @@ export const DETECTOR_META: Record<string, DetectorMeta> = {
|
|
|
248
248
|
label: t("Said how to check before editing", "動手前先說好怎麼驗證"),
|
|
249
249
|
meaning: t("The agent named the check that proves the work (its Anchor) before changing any file.", "代理人在改任何檔案前,先說出用什麼檢查證明工作完成(Anchor)。"),
|
|
250
250
|
goodDirection: "higher",
|
|
251
|
-
howComputed: t(
|
|
251
|
+
howComputed: t(
|
|
252
|
+
"Passes when, before the first successful edit or write, the agent or its brief named the check (an Anchor, Gates, Checks or 驗證 line, a todo anchor or check spec, or a check command in the brief), or the first change was a test file; sessions without edits do not count.",
|
|
253
|
+
"第一次成功修改或寫檔之前,代理人或交辦內容已說出檢查(Anchor、Gates、Checks、驗證 等標示行,待辦的 anchor 或檢查設定,或交辦內容裡的檢查指令),或第一個修改的就是測試檔,即通過;沒改檔的工作階段不算。",
|
|
254
|
+
),
|
|
252
255
|
example: {
|
|
253
256
|
pass: t("Writes 'Anchor: `npm test`', then edits src/app.ts.", "先寫「Anchor: `npm test`」,再修改 src/app.ts。"),
|
|
254
257
|
fail: t("Edits src/app.ts first and names the check afterwards.", "先修改 src/app.ts,之後才說要怎麼檢查。"),
|
|
@@ -258,7 +261,10 @@ export const DETECTOR_META: Record<string, DetectorMeta> = {
|
|
|
258
261
|
label: t("Ran the check after the last edit", "最後一次修改後有跑檢查"),
|
|
259
262
|
meaning: t("After its final change, the agent ran the check it named and the check passed.", "最後一次修改後,代理人有跑它說好的檢查,而且通過。"),
|
|
260
263
|
goodDirection: "higher",
|
|
261
|
-
howComputed: t(
|
|
264
|
+
howComputed: t(
|
|
265
|
+
"Passes when, after the last edit, every Anchor command passed (in bash or a monitor), the agent recorded passing evidence, or a test, build, lint or type-check run passed; a failing Anchor run fails it. Edits to Markdown or text after the check do not count as edits. Sessions with no edit, only prose edits, or an Anchor that is not a command and no run do not count.",
|
|
266
|
+
"最後一次修改後,Anchor 每個指令都通過(bash 或 monitor),或代理人記下通過的證據,或有測試、建置、lint、型別檢查通過,即通過;Anchor 指令失敗則不通過。檢查之後才改的 Markdown 或文字檔不算修改。沒改檔、只改文字,或 Anchor 不是指令又沒有執行的不算。",
|
|
267
|
+
),
|
|
262
268
|
example: {
|
|
263
269
|
pass: t("Edits a file, then runs `npm test`, which exits 0.", "改完檔案後執行 `npm test`,結束碼 0。"),
|
|
264
270
|
fail: t("Runs `npm test`, edits one more file, and stops.", "跑完 `npm test` 又改了一個檔案就結束。"),
|