pi-evals 0.4.1 → 0.5.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 +15 -0
- package/README.md +23 -4
- package/dist/detectors.js +106 -24
- package/dist/extract/run.js +1 -1
- package/dist/findings.js +4 -0
- package/dist/index.js +9 -4
- package/dist/labels-query.js +35 -0
- package/dist/labels.js +211 -0
- package/dist/live-labels.js +128 -0
- package/dist/meta.js +2 -2
- package/dist/model.js +9 -43
- package/dist/observer.js +8 -2
- package/dist/ops.js +2 -1
- package/dist/query.js +5 -1
- package/dist/render.js +1 -0
- package/dist/report/concepts.js +14 -0
- package/dist/report/sections.js +18 -3
- package/dist/work/track.js +10 -4
- package/docs/design.md +21 -3
- package/docs/schema.md +24 -6
- package/package.json +4 -2
- package/skills/analyzing-evals/SKILL.md +3 -1
- package/src/detectors.ts +110 -26
- package/src/extract/run.ts +1 -1
- package/src/findings.ts +3 -0
- package/src/index.ts +8 -4
- package/src/labels-query.ts +36 -0
- package/src/labels.ts +248 -0
- package/src/live-labels.ts +140 -0
- package/src/meta.ts +8 -2
- package/src/model.ts +11 -47
- package/src/observer.ts +13 -3
- package/src/ops.ts +2 -1
- package/src/query.ts +4 -1
- package/src/render.ts +1 -0
- package/src/report/concepts.ts +18 -0
- package/src/report/sections.ts +42 -9
- package/src/work/track.ts +11 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.1
|
|
4
|
+
|
|
5
|
+
- 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`.
|
|
6
|
+
- 「最後一次修改後有跑檢查」 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`.
|
|
7
|
+
- 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.
|
|
8
|
+
- Re-extracts every session once (extractor version 5).
|
|
9
|
+
|
|
10
|
+
## 0.5.0
|
|
11
|
+
|
|
12
|
+
- `/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.
|
|
13
|
+
- A new tool, `evals_label`, lets an agent log a correction when you correct how it worked, by rule and failure type (`no_check_stated`, `no_check_run`, `skipped_rule`, `wrong_order`, `unverified_claim`, `ignored_instruction`, `other`). It accepts names only and adds about 690 bytes of tool text. It can write your label on your behalf only during a turn that `/evals label <your words>` started.
|
|
14
|
+
- The report's labels section counts labels given after the fact (事後標) and in the moment (當下標) apart, with code agreement for each; agent corrections never count toward agreement. A new 「被糾正」 section counts corrections by rule, failure type, skill loaded and anchorloop version, and says when there are too few to read. A concept card, 「當下標記 vs 事後標記」, explains the difference with this report's numbers.
|
|
15
|
+
- `evals_query` has a `labels` view, and `findings` adds a line when three or more corrections share a rule and failure type.
|
|
16
|
+
- Labels show up at the next report or query, with no extract needed.
|
|
17
|
+
|
|
3
18
|
## 0.4.1
|
|
4
19
|
|
|
5
20
|
- Work comparisons in `items`, `findings`, and the HTML report now give separate costs per item and per 100 changed lines, with the number of items behind each comparison. When the measures disagree, the report explains why neither group is necessarily cheaper overall.
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Records of how [pi](https://github.com/earendil-works/pi) agents use skills, packages, ask-user, monitors and subagents, and whether their work follows the anchorloop process rules.
|
|
4
4
|
It reads past session files once, keeps a small observer running for what those files do not hold, and builds a static HTML report.
|
|
5
|
-
Agents can read the same numbers through one tool, `evals_query`.
|
|
5
|
+
Agents can read the same numbers through one tool, `evals_query`, and log a correction you gave them with another, `evals_label`.
|
|
6
6
|
|
|
7
7
|
## What it records
|
|
8
8
|
|
|
@@ -14,6 +14,7 @@ Agents can read the same numbers through one tool, `evals_query`.
|
|
|
14
14
|
- **Process**: four checks of the anchorloop rules per session, for sessions started after anchorloop 3.0.0 was pinned (2026-11-23T10:51:07Z); see [docs/design.md](docs/design.md#process-detectors).
|
|
15
15
|
- **Cost**: model cost and tokens, and the cost of the sessions that loaded each skill.
|
|
16
16
|
- **Work items**: each todo task from the moment it is switched to in progress until it is done or deleted: what it cost (subagents exactly, the main agent as an even share), where it closed (reviewer approval, a landed car, a wrap, evidence), where it stalled and on whom, and whether one way of working is cheaper than another of the same kind.
|
|
17
|
+
- **Your labels and corrections**: your verdict on a process rule, given in the moment with `/evals label` or after the fact, and the corrections an agent logs when you correct how it worked.
|
|
17
18
|
- **Your changes**: package pins, model routing, rules, skills and agent roles from the git history of your setup repositories, version changes seen live, and notes you add with `/evals mark`, each with the same numbers in the days before and after.
|
|
18
19
|
|
|
19
20
|
## Privacy
|
|
@@ -21,7 +22,8 @@ Agents can read the same numbers through one tool, `evals_query`.
|
|
|
21
22
|
Records hold derived facts only: names (tools, skills, packages, models, roles, project keys), counts, durations, exit codes, outcomes, and token and cost numbers.
|
|
22
23
|
They never hold transcript text, tool arguments, file contents, commands, questions, or answers.
|
|
23
24
|
Every string written to a record must look like a name (no spaces, no line breaks, at most 160 characters), or it is stored as `redacted`.
|
|
24
|
-
|
|
25
|
+
There are two exceptions: a work item's title (its todo subject, cut to one line of at most 80 characters), and the note you add to your own label with `/evals label` (one line, at most 500 characters, never shown in the report or a query result).
|
|
26
|
+
An agent's correction holds names only: the tool refuses any other text.
|
|
25
27
|
A test plants a secret in every text field of a session and checks that it reaches no output file and no query result outside a title field.
|
|
26
28
|
|
|
27
29
|
Everything stays on your machine, under `$XDG_STATE_HOME/pi-evals` (default `~/.local/state/pi-evals`).
|
|
@@ -45,6 +47,13 @@ The observer loads in every session, subagents included.
|
|
|
45
47
|
| `/evals findings [--since YYYY-MM-DD] [--project <key>]` | Shows the report’s headline, what limits it, and where to look next. |
|
|
46
48
|
| `/evals report [--since YYYY-MM-DD \| --days N] [--project <key>]` | Builds the linked date ranges, or one custom report when a start date or day count is given. |
|
|
47
49
|
| `/evals mark <note>` | Adds a note to the change timeline, e.g. `/evals mark workers moved to gpt-6.2-astra`. |
|
|
50
|
+
| `/evals label` | Labels the current session while the work is in front of you: pick a rule (or 「其他」), then 照做, 沒照做 or 看不出來, then an optional note in your own words. |
|
|
51
|
+
| `/evals label <rule> pass\|fail\|unclear [note]` | The same in one line; `<rule>` is a check name (`anchor_before_first_edit`, `check_after_last_edit`, `todo_evidence`, `close_guard_quiet`) or `other`. |
|
|
52
|
+
| `/evals label <your words>` | Anything else, e.g. `/evals label 剛剛沒先跑測試就說完成`: the agent turns your words into labels with `evals_label` and says in one line what it recorded. The verdict is yours and your words are kept as the note. |
|
|
53
|
+
| `/evals label undo` | Withdraws the current session's last label given in the moment. |
|
|
54
|
+
|
|
55
|
+
A label records the session, the time, and the key of the todo item in progress, if any (its `uid`, else `<session>#<id>`, as work items are keyed).
|
|
56
|
+
It reaches the report and `evals_query` at their next read, without an extract.
|
|
48
57
|
|
|
49
58
|
The same operations run from a shell, where extraction defaults to one fewer worker than available CPUs (at least one, at most eight).
|
|
50
59
|
On either surface, `--workers 0` reads the files sequentially without worker threads:
|
|
@@ -60,12 +69,22 @@ pi-evals mark <note>
|
|
|
60
69
|
### The `evals_query` tool
|
|
61
70
|
|
|
62
71
|
Start with `findings` (under 1,500 bytes), then follow one pointer if you need the counts.
|
|
63
|
-
An agent calls `evals_query` with a `view` (`findings`, `items`, `skills`, `packages`, `ask_user`, `monitors`, `subagents`, `process`, `cost`, `changes`, `coverage`) and optional `since` and `project`.
|
|
72
|
+
An agent calls `evals_query` with a `view` (`findings`, `items`, `labels`, `skills`, `packages`, `ask_user`, `monitors`, `subagents`, `process`, `cost`, `changes`, `coverage`) and optional `since` and `project`.
|
|
64
73
|
The result is plain text under 2 KB, covering the latest 30 UTC dates through the last extract unless you give `since`.
|
|
65
74
|
`findings` flags the biggest package error-rate rise and a rise in jobs ending in error when the later of two complete weeks is at least five percentage points higher, with at least 20 calls or endings in **each** week.
|
|
66
75
|
It also counts offered skills with no loads in the selected period and checks whether all old files are indexed.
|
|
67
76
|
The [analysis skill](skills/analyzing-evals/SKILL.md) includes three read-only commands for a change’s full comparison, a skill’s daily session counts, and a package’s daily errors.
|
|
68
77
|
The tool never starts an extract.
|
|
78
|
+
`labels` gives your labels by when they were given, how often the code checks agree with them, and the corrections agents logged; `findings` adds a line when three or more corrections share a rule and failure type.
|
|
79
|
+
|
|
80
|
+
### The `evals_label` tool
|
|
81
|
+
|
|
82
|
+
When you correct how an agent worked (it skipped a check, worked in the wrong order, ignored a rule), it calls `evals_label` once with `rule` (a check name or `other`) and an optional `type`: `no_check_stated`, `no_check_run`, `skipped_rule`, `wrong_order`, `unverified_claim`, `ignored_instruction` or `other`.
|
|
83
|
+
The row also keeps the session, the time, the item in progress, and the skills the session had loaded.
|
|
84
|
+
The count covers corrections the agent logged, not all its mistakes.
|
|
85
|
+
During a turn started by `/evals label <your words>`, the agent passes `on_behalf: "user"` and your verdict (`label`: `pass`, `fail` or `unclear`); that row is your label, not a correction.
|
|
86
|
+
At any other time `on_behalf` is refused, and the agent's own label can only be a fail.
|
|
87
|
+
The tool adds about 690 bytes of tool text to each session.
|
|
69
88
|
|
|
70
89
|
## The report
|
|
71
90
|
|
|
@@ -121,7 +140,7 @@ Use the section links for usage, process checks, cost and cleanup coverage, or r
|
|
|
121
140
|
| `index/items.json`, `index/workitems.jsonl` | Work items joined across sessions, and their `pi.workitem` and `pi.stall` records. |
|
|
122
141
|
| `index/lines.json` | Cached `git diff --numstat` line counts between evidence commits. |
|
|
123
142
|
| `changes.jsonl`, `marks.jsonl` | The change timeline and your notes. |
|
|
124
|
-
| `labels.jsonl` | Your labels
|
|
143
|
+
| `labels.jsonl` | Your labels and agents' corrections, appended one per line ([docs/schema.md](docs/schema.md#labels)). The report shows how often you and the automatic checks agree, split by labels given after the fact and in the moment; `unclear` labels are counted apart. Its 「被糾正」 section counts the corrections by rule, failure type, skill loaded and anchorloop version. |
|
|
125
144
|
| `reports/report.html`, `reports/model.json` | The report. |
|
|
126
145
|
|
|
127
146
|
The record format is in [docs/schema.md](docs/schema.md); the decisions behind it are in [docs/design.md](docs/design.md).
|
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/findings.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { correctionsFinding } from "./labels-query.js";
|
|
2
3
|
import { overview, readings, value, verdict } from "./report/findings.js";
|
|
3
4
|
import { words } from "./report/format.js";
|
|
4
5
|
import { safeName } from "./schema.js";
|
|
@@ -38,6 +39,9 @@ export function findings(m) {
|
|
|
38
39
|
const work = itemsFinding(m.work);
|
|
39
40
|
if (work)
|
|
40
41
|
lines.push(work);
|
|
42
|
+
const corrected = correctionsFinding(m);
|
|
43
|
+
if (corrected)
|
|
44
|
+
lines.push(corrected);
|
|
41
45
|
const w = m.weekly;
|
|
42
46
|
if (!w)
|
|
43
47
|
lines.push("Need two weeks in range for error trends → packages / monitors");
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* pi-evals: the live observer, the `/evals` command (status, extract, report, mark), and the `evals_query`
|
|
2
|
+
* pi-evals: the live observer, the `/evals` command (status, extract, report, mark, label), and the `evals_query` and `evals_label` tools.
|
|
3
3
|
*/
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { Type } from "typebox";
|
|
8
8
|
import { scriptsDir } from "./findings.js";
|
|
9
|
+
import { liveLabels } from "./live-labels.js";
|
|
9
10
|
import { observe } from "./observer.js";
|
|
10
11
|
import { context, mark, reportPath, runReport, statusText } from "./ops.js";
|
|
11
12
|
import { query, VIEWS } from "./query.js";
|
|
@@ -18,7 +19,7 @@ export function cliPath() {
|
|
|
18
19
|
const found = candidates.find((p) => existsSync(p));
|
|
19
20
|
return found ? { cmd: process.execPath, args: [found] } : undefined;
|
|
20
21
|
}
|
|
21
|
-
const SUBCOMMANDS = ["status", "findings", "extract", "report", "mark"];
|
|
22
|
+
const SUBCOMMANDS = ["status", "findings", "extract", "report", "mark", "label"];
|
|
22
23
|
function parseFlags(args) {
|
|
23
24
|
const out = { rest: [] };
|
|
24
25
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -38,7 +39,8 @@ export function createEvals(options = {}) {
|
|
|
38
39
|
const spawnFn = options.spawnExtract ?? spawn;
|
|
39
40
|
return function evals(pi) {
|
|
40
41
|
const ctx0 = context(env);
|
|
41
|
-
observe(pi, { layout: ctx0.layout, home: ctx0.home, now: options.now });
|
|
42
|
+
const observed = observe(pi, { layout: ctx0.layout, home: ctx0.home, now: options.now });
|
|
43
|
+
const labels = liveLabels(pi, { env, now: options.now ?? Date.now, observed });
|
|
42
44
|
let settingsWarned = false;
|
|
43
45
|
pi.on("session_start", (_event, ctx) => {
|
|
44
46
|
if (settingsWarned || !ctx0.settings.error)
|
|
@@ -98,7 +100,7 @@ export function createEvals(options = {}) {
|
|
|
98
100
|
});
|
|
99
101
|
};
|
|
100
102
|
pi.registerCommand("evals", {
|
|
101
|
-
description: "Usage and process records: /evals [status|findings|extract|report|mark <note
|
|
103
|
+
description: "Usage and process records: /evals [status|findings|extract|report|mark <note>|label]",
|
|
102
104
|
getArgumentCompletions: (prefix) => {
|
|
103
105
|
const items = SUBCOMMANDS.filter((s) => s.startsWith(prefix)).map((s) => ({ value: s, label: s }));
|
|
104
106
|
return items.length ? items : null;
|
|
@@ -142,6 +144,9 @@ export function createEvals(options = {}) {
|
|
|
142
144
|
const change = mark(text, env);
|
|
143
145
|
ctx.ui.notify(`pi-evals: marked ${change.at}: ${text}`, "info");
|
|
144
146
|
}
|
|
147
|
+
else if (sub === "label") {
|
|
148
|
+
await labels.command(words.slice(1), ctx);
|
|
149
|
+
}
|
|
145
150
|
else {
|
|
146
151
|
ctx.ui.notify(`Unknown subcommand "${sub}". Use: ${SUBCOMMANDS.join(", ")}.`, "warning");
|
|
147
152
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** The `labels` view of `evals_query` and its line in `findings`: names and numbers, never a note. */
|
|
2
|
+
import { SMALL_SAMPLE } from "./model.js";
|
|
3
|
+
/** Corrections of one rule and failure type that make a findings line. */
|
|
4
|
+
export const CLUSTER = 3;
|
|
5
|
+
const list = (rows, name, limit = 6) => rows.slice(0, limit).map((r) => `${name(r)} ${r.n}`).join(", ") || "none";
|
|
6
|
+
const ratio = (c) => `${c.agree}/${c.n}`;
|
|
7
|
+
export function labelsView(m) {
|
|
8
|
+
const l = m.labels;
|
|
9
|
+
if (l.needsIndex)
|
|
10
|
+
return ["labels in this range need an index with session ids: the user can run /evals extract"];
|
|
11
|
+
const c = l.corrections;
|
|
12
|
+
const out = [
|
|
13
|
+
"human labels = your verdicts on a rule; after the fact (batch) or in the moment (/evals label)",
|
|
14
|
+
`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}`,
|
|
15
|
+
"code vs human, agreed/compared (after the fact; in the moment):",
|
|
16
|
+
];
|
|
17
|
+
for (const a of l.agreement)
|
|
18
|
+
out.push(`${a.detector}: ${ratio(a)} (${ratio(a.bySource.batch)}; ${ratio(a.bySource.live)})`);
|
|
19
|
+
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` : ""}`);
|
|
20
|
+
if (c.n) {
|
|
21
|
+
out.push(`by rule: ${list(c.byRule, (r) => r.rule)}`);
|
|
22
|
+
out.push(`by type: ${list(c.byType, (r) => r.type)}`);
|
|
23
|
+
out.push(`by rule/type: ${list(c.byRuleType, (r) => `${r.rule}/${r.type}`, 4)}`);
|
|
24
|
+
out.push(`by skill loaded (one correction counts for each): ${list(c.bySkill, (r) => r.skill || "(none)")}`);
|
|
25
|
+
out.push(`by anchorloop version: ${list(c.byVersion, (r) => r.version)}`);
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
/** A findings line when corrections of one rule and type recur. */
|
|
30
|
+
export function correctionsFinding(m) {
|
|
31
|
+
const c = m.labels.corrections, top = c.byRuleType[0];
|
|
32
|
+
if (!top || top.n < CLUSTER)
|
|
33
|
+
return undefined;
|
|
34
|
+
return `Corrections logged: ${top.n} of ${c.n} are ${top.rule}/${top.type} (agent-logged, not all mistakes) → labels`;
|
|
35
|
+
}
|
package/dist/labels.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Labels (`labels.jsonl`, append-only): human verdicts on the process checks, given after the fact (`batch`, rows
|
|
3
|
+
* without a source) or in the moment (`live`, `/evals label`), and the corrections an agent logs when the user
|
|
4
|
+
* corrects how it worked (`correction`, the `evals_label` tool). Only a human note is free text; agent rows hold names.
|
|
5
|
+
*/
|
|
6
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
7
|
+
import { dirname } from "node:path";
|
|
8
|
+
import { DETECTORS } from "./detectors.js";
|
|
9
|
+
import { DETECTOR_META } from "./meta.js";
|
|
10
|
+
import { safeName, traceId } from "./schema.js";
|
|
11
|
+
import { liveItemKey } from "./work/track.js";
|
|
12
|
+
export const RULES = [...DETECTORS, "other"];
|
|
13
|
+
export const VERDICTS = ["pass", "fail", "unclear"];
|
|
14
|
+
export const FAILURE_TYPES = ["no_check_stated", "no_check_run", "skipped_rule", "wrong_order", "unverified_claim", "ignored_instruction", "other"];
|
|
15
|
+
export const NOTE_MAX = 500;
|
|
16
|
+
const t = (en, zh) => ({ en, zh });
|
|
17
|
+
export const RULE_OTHER = t("Other", "其他");
|
|
18
|
+
export const VERDICT_META = { pass: t("Followed", "照做"), fail: t("Not followed", "沒照做"), unclear: t("Cannot tell", "看不出來") };
|
|
19
|
+
export const FAILURE_TYPE_META = {
|
|
20
|
+
no_check_stated: t("Did not say how to check", "沒先說怎麼驗證"),
|
|
21
|
+
no_check_run: t("Did not run the check", "沒跑檢查"),
|
|
22
|
+
skipped_rule: t("Skipped a rule", "跳過規則"),
|
|
23
|
+
wrong_order: t("Wrong order", "順序錯了"),
|
|
24
|
+
unverified_claim: t("Said done without proof", "沒驗證就說做好了"),
|
|
25
|
+
ignored_instruction: t("Ignored your instruction", "沒照你的指示"),
|
|
26
|
+
other: t("Other", "其他"),
|
|
27
|
+
};
|
|
28
|
+
export const ruleLabel = (rule, lang) => (rule === "other" ? RULE_OTHER[lang] : (DETECTOR_META[rule]?.label[lang] ?? rule));
|
|
29
|
+
/** A human label given in the moment: typed, or formatted by the agent from the user's words. */
|
|
30
|
+
export const givenLive = (row) => row.source === "live" || row.source === "live-prompt";
|
|
31
|
+
const isLive = (row) => givenLive(row) && row.annotator === "human" && !row.undo;
|
|
32
|
+
function parse(file) {
|
|
33
|
+
if (!existsSync(file))
|
|
34
|
+
return [];
|
|
35
|
+
return readFileSync(file, "utf8")
|
|
36
|
+
.split("\n")
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
.flatMap((line) => {
|
|
39
|
+
try {
|
|
40
|
+
const row = JSON.parse(line);
|
|
41
|
+
return row && typeof row.session_id === "string" ? [row] : [];
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/** Rows in effect, in file order. A withdrawal cancels its session's latest live row still in effect before it. */
|
|
49
|
+
export function readLabels(file) {
|
|
50
|
+
const rows = parse(file);
|
|
51
|
+
const gone = new Set();
|
|
52
|
+
const live = new Map();
|
|
53
|
+
rows.forEach((r, i) => {
|
|
54
|
+
if (r.undo) {
|
|
55
|
+
const last = live.get(r.session_id)?.pop();
|
|
56
|
+
if (last !== undefined)
|
|
57
|
+
gone.add(last);
|
|
58
|
+
gone.add(i);
|
|
59
|
+
}
|
|
60
|
+
else if (isLive(r))
|
|
61
|
+
live.set(r.session_id, [...(live.get(r.session_id) ?? []), i]);
|
|
62
|
+
});
|
|
63
|
+
return rows.filter((_, i) => !gone.has(i));
|
|
64
|
+
}
|
|
65
|
+
export function appendLabel(file, row) {
|
|
66
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
67
|
+
appendFileSync(file, `${JSON.stringify(row)}\n`);
|
|
68
|
+
}
|
|
69
|
+
/** Withdraws this session's last live label by appending a withdrawal; returns the withdrawn row. */
|
|
70
|
+
export function undoLast(file, session, at) {
|
|
71
|
+
const last = readLabels(file).filter((r) => r.session_id === session && isLive(r)).at(-1);
|
|
72
|
+
if (last)
|
|
73
|
+
appendLabel(file, { session_id: session, evaluation_name: last.evaluation_name, label: last.label, at, annotator: "human", source: "live", undo: last.at });
|
|
74
|
+
return last;
|
|
75
|
+
}
|
|
76
|
+
/** One line, at most NOTE_MAX characters; empty becomes none. */
|
|
77
|
+
export function cleanNote(text) {
|
|
78
|
+
const one = (text ?? "").replace(/\s+/g, " ").trim();
|
|
79
|
+
return one ? Array.from(one).slice(0, NOTE_MAX).join("") : undefined;
|
|
80
|
+
}
|
|
81
|
+
/** The work item in progress on the current branch: its 0.4.0 key (uid, else origin#id, else session#id). */
|
|
82
|
+
export function itemOnBranch(branch, session) {
|
|
83
|
+
if (!branch)
|
|
84
|
+
return undefined;
|
|
85
|
+
for (let i = branch.length - 1; i >= 0; i--) {
|
|
86
|
+
const e = branch[i];
|
|
87
|
+
if (e?.type !== "custom" || e.customType !== "todo/v1")
|
|
88
|
+
continue;
|
|
89
|
+
const tasks = e.data?.tasks;
|
|
90
|
+
if (Array.isArray(tasks))
|
|
91
|
+
return liveItemKey(tasks, session);
|
|
92
|
+
}
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* `evals_label` arguments: known names only, nothing else; throws on any other field or value. Without `on_behalf`
|
|
97
|
+
* the row is the agent's own correction, a fail; `on_behalf: "user"` is accepted only while `speaking` (a
|
|
98
|
+
* `/evals label <words>` turn of this session is running), and then needs the user's verdict.
|
|
99
|
+
*/
|
|
100
|
+
export function agentLabel(params, speaking) {
|
|
101
|
+
const p = (params && typeof params === "object" ? params : {});
|
|
102
|
+
const extra = Object.keys(p).filter((k) => !["rule", "label", "type", "on_behalf"].includes(k));
|
|
103
|
+
if (extra.length)
|
|
104
|
+
throw new Error(`evals_label takes only rule, label, type and on_behalf, not ${extra.map((k) => safeName(k)).join(", ")}.`);
|
|
105
|
+
if (!RULES.includes(p.rule))
|
|
106
|
+
throw new Error(`rule must be one of: ${RULES.join(", ")}.`);
|
|
107
|
+
if (p.type !== undefined && !FAILURE_TYPES.includes(p.type))
|
|
108
|
+
throw new Error(`type must be one of: ${FAILURE_TYPES.join(", ")}.`);
|
|
109
|
+
if (p.on_behalf !== undefined && p.on_behalf !== "user")
|
|
110
|
+
throw new Error('on_behalf can only be "user".');
|
|
111
|
+
const onBehalf = p.on_behalf === "user";
|
|
112
|
+
if (onBehalf && !speaking)
|
|
113
|
+
throw new Error('on_behalf "user" is valid only during a /evals label turn the user started in this session; log your own correction without it.');
|
|
114
|
+
if (onBehalf ? !VERDICTS.includes(p.label) : p.label !== undefined && p.label !== "fail") {
|
|
115
|
+
throw new Error(onBehalf ? "label must be the user's verdict: pass, fail or unclear." : "Your own correction is always a fail; a pass or unclear verdict is the user's, given through /evals label.");
|
|
116
|
+
}
|
|
117
|
+
const label = p.label ?? "fail";
|
|
118
|
+
if (p.type !== undefined && label !== "fail")
|
|
119
|
+
throw new Error("type names the kind of slip, so it goes only with a fail.");
|
|
120
|
+
return { rule: p.rule, label, type: p.type, onBehalf };
|
|
121
|
+
}
|
|
122
|
+
const rate = (num, den) => ({ value: den > 0 ? num / den : null, n: den });
|
|
123
|
+
const counted = (map) => [...map].sort((a, b) => b[1] - a[1] || String(a[0]).localeCompare(String(b[0])));
|
|
124
|
+
const bump = (map, key) => map.set(key, (map.get(key) ?? 0) + 1);
|
|
125
|
+
/**
|
|
126
|
+
* Human labels against the code checks (agreement, by when they were given), and the corrections agents logged.
|
|
127
|
+
* A session in the index belongs to the range by its start; a label whose session is not indexed yet (given in the
|
|
128
|
+
* moment, before an extract) belongs by its own time and project.
|
|
129
|
+
*/
|
|
130
|
+
export function labelsModel(labelsFile, evalsFile, scope, versionOf) {
|
|
131
|
+
const empty = { present: false, n: 0, unclear: 0, bySource: { batch: 0, live: 0 }, fromWords: 0, sessions: { batch: 0, live: 0 }, noCode: 0, other: 0, agreement: [], corrections: corrections([], versionOf) };
|
|
132
|
+
if (!existsSync(labelsFile))
|
|
133
|
+
return empty;
|
|
134
|
+
const code = existsSync(evalsFile) ? JSON.parse(readFileSync(evalsFile, "utf8")) : {};
|
|
135
|
+
const inDates = (at) => (!scope.since || at.slice(0, 10) >= scope.since) && (!scope.until || at.slice(0, 10) <= scope.until);
|
|
136
|
+
const inScope = (r) => {
|
|
137
|
+
if (!scope.selected)
|
|
138
|
+
return true;
|
|
139
|
+
const id = traceId(r.session_id, "labels");
|
|
140
|
+
if (scope.selected.has(id))
|
|
141
|
+
return true;
|
|
142
|
+
return r.source !== undefined && !scope.indexed?.has(id) && typeof r.at === "string" && inDates(r.at) && (!scope.project || r.project === scope.project);
|
|
143
|
+
};
|
|
144
|
+
const rows = readLabels(labelsFile).filter(inScope);
|
|
145
|
+
const human = rows.filter((r) => r.annotator !== "agent");
|
|
146
|
+
const by = new Map();
|
|
147
|
+
const sessions = { batch: new Set(), live: new Set() };
|
|
148
|
+
const out = { ...empty, present: true, n: human.length };
|
|
149
|
+
for (const row of human) {
|
|
150
|
+
const source = givenLive(row) ? "live" : "batch";
|
|
151
|
+
out.bySource[source] += 1;
|
|
152
|
+
if (row.source === "live-prompt")
|
|
153
|
+
out.fromWords += 1;
|
|
154
|
+
sessions[source].add(row.session_id);
|
|
155
|
+
if (row.evaluation_name === "other") {
|
|
156
|
+
out.other += 1;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const t = by.get(row.evaluation_name) ?? { unclear: 0, batch: { n: 0, agree: 0 }, live: { n: 0, agree: 0 } };
|
|
160
|
+
by.set(row.evaluation_name, t);
|
|
161
|
+
// "Cannot tell" is the reader's honest answer, not a disagreement: count it apart from the agreement rate.
|
|
162
|
+
if (row.label === "unclear") {
|
|
163
|
+
out.unclear += 1;
|
|
164
|
+
t.unclear += 1;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const verdict = code[row.session_id]?.[row.evaluation_name];
|
|
168
|
+
if (!verdict || verdict === "na") {
|
|
169
|
+
out.noCode += 1;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
t[source].n += 1;
|
|
173
|
+
if (verdict === row.label)
|
|
174
|
+
t[source].agree += 1;
|
|
175
|
+
}
|
|
176
|
+
out.sessions = { batch: sessions.batch.size, live: sessions.live.size };
|
|
177
|
+
out.agreement = [...by].map(([detector, t]) => {
|
|
178
|
+
const n = t.batch.n + t.live.n, agree = t.batch.agree + t.live.agree;
|
|
179
|
+
return { detector, n, agree, rate: rate(agree, n), unclear: t.unclear, bySource: { batch: { ...t.batch, rate: rate(t.batch.agree, t.batch.n) }, live: { ...t.live, rate: rate(t.live.agree, t.live.n) } } };
|
|
180
|
+
});
|
|
181
|
+
out.corrections = corrections(rows.filter((r) => r.annotator === "agent" && r.source === "correction"), versionOf);
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
/** The corrections agents logged, by rule, failure type, the skills loaded in the session, and anchorloop version. */
|
|
185
|
+
function corrections(rows, versionOf) {
|
|
186
|
+
const rule = new Map(), type = new Map(), pair = new Map();
|
|
187
|
+
const skill = new Map(), skillN = new Map(), version = new Map(), versionN = new Map();
|
|
188
|
+
for (const r of rows) {
|
|
189
|
+
const kind = r.type && FAILURE_TYPES.includes(r.type) ? r.type : "other";
|
|
190
|
+
bump(rule, r.evaluation_name);
|
|
191
|
+
bump(type, kind);
|
|
192
|
+
bump(pair, `${r.evaluation_name}|${kind}`);
|
|
193
|
+
for (const s of r.skills?.length ? r.skills : [""]) {
|
|
194
|
+
bump(skillN, s);
|
|
195
|
+
skill.set(s, (skill.get(s) ?? new Set()).add(r.session_id));
|
|
196
|
+
}
|
|
197
|
+
const v = versionOf(r.at) ?? "unknown";
|
|
198
|
+
bump(versionN, v);
|
|
199
|
+
version.set(v, (version.get(v) ?? new Set()).add(r.session_id));
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
n: rows.length,
|
|
203
|
+
sessions: new Set(rows.map((r) => r.session_id)).size,
|
|
204
|
+
byRule: counted(rule).map(([name, n]) => ({ rule: name, n })),
|
|
205
|
+
byType: counted(type).map(([name, n]) => ({ type: name, n })),
|
|
206
|
+
byRuleType: counted(pair).map(([key, n]) => ({ rule: key.split("|")[0], type: key.split("|")[1], n })),
|
|
207
|
+
/** `skill` "" = no skill loaded before the correction. */
|
|
208
|
+
bySkill: counted(skillN).map(([name, n]) => ({ skill: name, n, sessions: skill.get(name)?.size ?? 0 })),
|
|
209
|
+
byVersion: counted(versionN).map(([name, n]) => ({ version: name, n, sessions: version.get(name)?.size ?? 0 })),
|
|
210
|
+
};
|
|
211
|
+
}
|