pi-evals 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +23 -4
- package/dist/findings.js +4 -0
- package/dist/index.js +9 -4
- package/dist/labels-query.js +35 -0
- package/dist/labels.js +211 -0
- package/dist/live-labels.js +128 -0
- package/dist/model.js +9 -43
- package/dist/observer.js +8 -2
- package/dist/ops.js +2 -1
- package/dist/query.js +5 -1
- package/dist/render.js +1 -0
- package/dist/report/concepts.js +16 -2
- package/dist/report/sections.js +18 -3
- package/dist/report/work.js +2 -14
- package/dist/work/query.js +8 -16
- package/dist/work/track.js +10 -4
- package/dist/work/wording.js +27 -0
- package/docs/design.md +19 -1
- package/docs/schema.md +22 -4
- package/package.json +4 -2
- package/skills/analyzing-evals/SKILL.md +3 -1
- package/src/findings.ts +3 -0
- package/src/index.ts +8 -4
- package/src/labels-query.ts +36 -0
- package/src/labels.ts +248 -0
- package/src/live-labels.ts +140 -0
- package/src/model.ts +11 -47
- package/src/observer.ts +13 -3
- package/src/ops.ts +2 -1
- package/src/query.ts +4 -1
- package/src/render.ts +1 -0
- package/src/report/concepts.ts +20 -2
- package/src/report/sections.ts +42 -9
- package/src/report/work.ts +3 -14
- package/src/work/query.ts +9 -14
- package/src/work/track.ts +11 -2
- package/src/work/wording.ts +26 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
- `/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.
|
|
6
|
+
- 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.
|
|
7
|
+
- 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.
|
|
8
|
+
- `evals_query` has a `labels` view, and `findings` adds a line when three or more corrections share a rule and failure type.
|
|
9
|
+
- Labels show up at the next report or query, with no extract needed.
|
|
10
|
+
|
|
11
|
+
## 0.4.1
|
|
12
|
+
|
|
13
|
+
- 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.
|
|
14
|
+
|
|
3
15
|
## 0.4.0
|
|
4
16
|
|
|
5
17
|
- The report has a 「工作」 section: every todo item with its cost (subagents exact, main agent split evenly among items in progress at the same time), minutes in progress, how it closed (reviewer approval, a landed car, a wrap, evidence) and where it stalled, by what woke the main agent. A comparison of like with like says whether one model, role or anchorloop version costs less per item and per 100 changed lines, or that there are too few items to tell. Open items show where they stopped, on whom they wait, and for how long. Two concept cards explain cost attribution and fair comparison with this report's numbers.
|
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/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
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { agentLabel, appendLabel, cleanNote, FAILURE_TYPES, itemOnBranch, RULES, ruleLabel, undoLast, VERDICT_META, VERDICTS } from "./labels.js";
|
|
3
|
+
import { context } from "./ops.js";
|
|
4
|
+
import { projectKey } from "./project.js";
|
|
5
|
+
const VERDICT_WORDS = new Map(VERDICTS.flatMap((v) => [[v, v], [VERDICT_META[v].zh, v]]));
|
|
6
|
+
const USAGE = `pi-evals 用法:/evals label(一步步選)、/evals label <規則> pass|fail|unclear [說明],或 /evals label <你的話>(交給代理人整理成標記);規則:${RULES.join("、")};/evals label undo 撤銷這段工作上一筆當下標記。`;
|
|
7
|
+
/** The turn that formats the user's words: the instruction to the agent, with the words last and verbatim. */
|
|
8
|
+
export function promptFor(words) {
|
|
9
|
+
return [
|
|
10
|
+
"[/evals label] Below, in the user's own words, is the user's verdict on how this session's work followed the process rules.",
|
|
11
|
+
`Record it with evals_label, once per rule the words judge: on_behalf "user", rule (one of ${RULES.join(", ")}), label as the user judged it (pass, fail or unclear), and type when it is a fail.`,
|
|
12
|
+
"Record only what the user said, add no judgement of your own, then confirm in one line, in plain words and the user's language, what you recorded.",
|
|
13
|
+
"",
|
|
14
|
+
`User's words: ${words}`,
|
|
15
|
+
].join("\n");
|
|
16
|
+
}
|
|
17
|
+
export function liveLabels(pi, options) {
|
|
18
|
+
const { env, now, observed } = options;
|
|
19
|
+
/** The user's words waiting for their turn to start, and the turn that may speak for the user. */
|
|
20
|
+
let waiting;
|
|
21
|
+
let speaking;
|
|
22
|
+
const textOf = (content) => typeof content === "string" ? content : Array.isArray(content) ? content.map((p) => (p && typeof p === "object" && typeof p.text === "string" ? p.text : "")).join("") : "";
|
|
23
|
+
const start = (text) => {
|
|
24
|
+
if (waiting && text === waiting.prompt) {
|
|
25
|
+
speaking = { ...waiting };
|
|
26
|
+
waiting = undefined;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
pi.on("before_agent_start", (event) => start(event.prompt));
|
|
30
|
+
// A prompt queued behind a running turn starts its own run without before_agent_start: its user message opens it.
|
|
31
|
+
pi.on("message_end", (event) => {
|
|
32
|
+
const message = event.message;
|
|
33
|
+
if (message?.role !== "user")
|
|
34
|
+
return;
|
|
35
|
+
const text = textOf(message.content);
|
|
36
|
+
// Another message from the user in the same run is not part of the words the agent is formatting.
|
|
37
|
+
if (speaking && text !== speaking.prompt)
|
|
38
|
+
speaking = undefined;
|
|
39
|
+
start(text);
|
|
40
|
+
});
|
|
41
|
+
pi.on("agent_end", () => {
|
|
42
|
+
speaking = undefined;
|
|
43
|
+
});
|
|
44
|
+
pi.on("session_start", () => {
|
|
45
|
+
waiting = speaking = undefined;
|
|
46
|
+
});
|
|
47
|
+
const where = (ctx) => {
|
|
48
|
+
const c = context(env);
|
|
49
|
+
const session = ctx.sessionManager.getSessionId();
|
|
50
|
+
let branch;
|
|
51
|
+
try {
|
|
52
|
+
branch = ctx.sessionManager.getBranch?.();
|
|
53
|
+
}
|
|
54
|
+
catch { }
|
|
55
|
+
return { file: c.layout.labels, session, item: itemOnBranch(branch, session), project: projectKey(ctx.cwd, c.home), at: new Date(now()).toISOString() };
|
|
56
|
+
};
|
|
57
|
+
async function command(words, ctx) {
|
|
58
|
+
const say = (text, level = "info") => ctx.ui.notify(text, level);
|
|
59
|
+
const w = where(ctx);
|
|
60
|
+
if (words[0] === "undo") {
|
|
61
|
+
const last = undoLast(w.file, w.session, w.at);
|
|
62
|
+
say(last ? `pi-evals:已撤銷這段工作上一筆當下標記「${ruleLabel(last.evaluation_name, "zh")}」${VERDICT_META[last.label].zh}。` : "pi-evals:這段工作沒有可撤銷的當下標記。");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
let rule;
|
|
66
|
+
let verdict;
|
|
67
|
+
let note;
|
|
68
|
+
if (words.length) {
|
|
69
|
+
rule = RULES.find((r) => r === words[0]);
|
|
70
|
+
verdict = VERDICT_WORDS.get(words[1] ?? "");
|
|
71
|
+
note = words.slice(2).join(" ");
|
|
72
|
+
if (!rule || !verdict) {
|
|
73
|
+
const text = cleanNote(words.join(" "));
|
|
74
|
+
waiting = { session: w.session, prompt: promptFor(text), note: text };
|
|
75
|
+
pi.sendUserMessage(waiting.prompt, ctx.isIdle() ? undefined : { deliverAs: "followUp" });
|
|
76
|
+
return say(`pi-evals:已把你的話交給代理人,請它整理成標記${ctx.isIdle() ? "" : "(等目前的工作告一段落)"};它會回報記了什麼,不對就用 /evals label undo 撤銷。`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
if (!ctx.hasUI)
|
|
81
|
+
return say(USAGE, "warning");
|
|
82
|
+
const cancelled = () => say("pi-evals:已取消,沒有記下標記。");
|
|
83
|
+
const names = RULES.map((r) => ruleLabel(r, "zh"));
|
|
84
|
+
const picked = await ctx.ui.select("要標記哪一條規則?", names);
|
|
85
|
+
rule = RULES[names.indexOf(picked ?? "")];
|
|
86
|
+
if (!rule)
|
|
87
|
+
return cancelled();
|
|
88
|
+
const verdicts = VERDICTS.map((v) => VERDICT_META[v].zh);
|
|
89
|
+
verdict = VERDICTS[verdicts.indexOf((await ctx.ui.select(`這段工作有照做「${ruleLabel(rule, "zh")}」嗎?`, verdicts)) ?? "")];
|
|
90
|
+
if (!verdict)
|
|
91
|
+
return cancelled();
|
|
92
|
+
const typed = await ctx.ui.input("補充說明(用你自己的話,可留空,直接按 Enter)", "");
|
|
93
|
+
if (typed === undefined)
|
|
94
|
+
return cancelled();
|
|
95
|
+
note = typed;
|
|
96
|
+
}
|
|
97
|
+
const row = { session_id: w.session, evaluation_name: rule, label: verdict, at: w.at, annotator: "human", source: "live", item: w.item, project: w.project, note: cleanNote(note) };
|
|
98
|
+
appendLabel(w.file, row);
|
|
99
|
+
say(`pi-evals:已記下「${ruleLabel(rule, "zh")}」${VERDICT_META[verdict].zh}${row.item ? `,進行中的待辦 ${row.item}` : ""}${row.note ? ",附說明" : ""};/evals label undo 可撤銷。`);
|
|
100
|
+
}
|
|
101
|
+
pi.registerTool({
|
|
102
|
+
name: "evals_label",
|
|
103
|
+
label: "Evals Label",
|
|
104
|
+
description: "Log a user's correction of how you worked: rule broken (or other), type of slip; on_behalf user only in a /evals label turn.",
|
|
105
|
+
promptSnippet: "When the user corrects how you worked (skipped a check, wrong order, ignored a rule), log it once",
|
|
106
|
+
parameters: Type.Object({
|
|
107
|
+
rule: Type.Unsafe({ type: "string", enum: [...RULES] }),
|
|
108
|
+
label: Type.Optional(Type.Unsafe({ type: "string", enum: [...VERDICTS] })),
|
|
109
|
+
type: Type.Optional(Type.Unsafe({ type: "string", enum: [...FAILURE_TYPES] })),
|
|
110
|
+
on_behalf: Type.Optional(Type.Unsafe({ type: "string", enum: ["user"] })),
|
|
111
|
+
}, { additionalProperties: false }),
|
|
112
|
+
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
113
|
+
const session = ctx.sessionManager.getSessionId();
|
|
114
|
+
const voice = speaking?.session === session ? speaking : undefined;
|
|
115
|
+
const { rule, label, type, onBehalf } = agentLabel(params, !!voice);
|
|
116
|
+
const w = where(ctx);
|
|
117
|
+
if (onBehalf) {
|
|
118
|
+
// The user's judgement, the agent only formatted it: the note is the user's words, never the agent's.
|
|
119
|
+
appendLabel(w.file, { session_id: w.session, evaluation_name: rule, label, at: w.at, annotator: "human", source: "live-prompt", type, item: w.item, project: w.project, note: voice?.note });
|
|
120
|
+
return { content: [{ type: "text", text: `logged the user's label: ${rule} ${label}${type ? ` (${type})` : ""}` }], details: { rule, label, type, onBehalf } };
|
|
121
|
+
}
|
|
122
|
+
const skills = observed.skills();
|
|
123
|
+
appendLabel(w.file, { session_id: w.session, evaluation_name: rule, label: "fail", at: w.at, annotator: "agent", source: "correction", type, item: w.item, project: w.project, skills: skills.length ? skills : undefined });
|
|
124
|
+
return { content: [{ type: "text", text: `logged correction: ${rule}${type ? ` (${type})` : ""}` }], details: { rule, label, type, onBehalf } };
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
return { command };
|
|
128
|
+
}
|
package/dist/model.js
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
* The ReportModel: every number the report can show, each with its n and window, plus the plain-language
|
|
3
3
|
* metadata to explain it. The renderer reads only this; `evals_query` reads parts of it.
|
|
4
4
|
*/
|
|
5
|
-
import { existsSync
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
6
|
import { ASK_BUCKETS, emptyDay, mergeDay } from "./aggregate.js";
|
|
7
|
+
import { versionAt } from "./changes.js";
|
|
7
8
|
import { DETECTORS, ERA_START } from "./detectors.js";
|
|
8
9
|
import { CHANGE_KIND_META, CLOSE_KIND_META, DETECTOR_META, METRICS, NOTICE_META, STALL_KIND_META } from "./meta.js";
|
|
9
10
|
import { staticOwner } from "./owners.js";
|
|
10
11
|
import { weeklyRises } from "./trends.js";
|
|
11
|
-
import {
|
|
12
|
+
import { labelsModel } from "./labels.js";
|
|
13
|
+
import { ANCHORLOOP } from "./work/join.js";
|
|
12
14
|
import { workModel } from "./work/model.js";
|
|
13
15
|
export const SMALL_SAMPLE = 20;
|
|
14
16
|
/** Data older than this (hours) is reported as stale. */
|
|
@@ -153,46 +155,6 @@ export function impactFromRows(rows, change, all, windowDays, range, ownerOf) {
|
|
|
153
155
|
confounders: kinds,
|
|
154
156
|
};
|
|
155
157
|
}
|
|
156
|
-
function labelsJoin(labelsFile, evalsFile, sessionIds) {
|
|
157
|
-
if (!existsSync(labelsFile))
|
|
158
|
-
return { present: false, n: 0, unclear: 0, agreement: [] };
|
|
159
|
-
const codeLabels = existsSync(evalsFile) ? JSON.parse(readFileSync(evalsFile, "utf8")) : {};
|
|
160
|
-
const rows = readFileSync(labelsFile, "utf8")
|
|
161
|
-
.split("\n")
|
|
162
|
-
.filter(Boolean)
|
|
163
|
-
.flatMap((line) => {
|
|
164
|
-
try {
|
|
165
|
-
return [JSON.parse(line)];
|
|
166
|
-
}
|
|
167
|
-
catch {
|
|
168
|
-
return [];
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
const by = new Map();
|
|
172
|
-
let n = 0;
|
|
173
|
-
let unclear = 0;
|
|
174
|
-
for (const row of rows) {
|
|
175
|
-
if (sessionIds && !sessionIds.has(traceId(row.session_id, "labels")))
|
|
176
|
-
continue;
|
|
177
|
-
n++;
|
|
178
|
-
const t = by.get(row.evaluation_name) ?? { n: 0, agree: 0, unclear: 0 };
|
|
179
|
-
// "Cannot tell" is the reader's honest answer, not a disagreement: count it apart from the agreement rate.
|
|
180
|
-
if (row.label === "unclear") {
|
|
181
|
-
unclear += 1;
|
|
182
|
-
t.unclear += 1;
|
|
183
|
-
by.set(row.evaluation_name, t);
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
const code = codeLabels[row.session_id]?.[row.evaluation_name];
|
|
187
|
-
if (!code || code === "na")
|
|
188
|
-
continue;
|
|
189
|
-
t.n += 1;
|
|
190
|
-
if (code === row.label)
|
|
191
|
-
t.agree += 1;
|
|
192
|
-
by.set(row.evaluation_name, t);
|
|
193
|
-
}
|
|
194
|
-
return { present: true, n, unclear, agreement: [...by].map(([detector, t]) => ({ detector, n: t.n, agree: t.agree, rate: rate(t.agree, t.n), unclear: t.unclear })) };
|
|
195
|
-
}
|
|
196
158
|
export function buildModel(options) {
|
|
197
159
|
const { index, filter } = options;
|
|
198
160
|
const now = options.now ?? new Date();
|
|
@@ -225,6 +187,7 @@ export function buildModel(options) {
|
|
|
225
187
|
const scoped = Boolean(filter.since || filter.until || filter.project);
|
|
226
188
|
const hasSessionIds = selected.every(r => r.id !== undefined);
|
|
227
189
|
const labelIds = scoped && existsSync(options.labelsFile) ? new Set(selected.flatMap(r => r.id ? [r.id] : [])) : undefined;
|
|
190
|
+
const indexedIds = labelIds && new Set(options.rows.flatMap(r => r.id ? [r.id] : []));
|
|
228
191
|
const calls = Object.values(total.tools).reduce((s, t) => s + t.calls, 0);
|
|
229
192
|
const errors = Object.values(total.tools).reduce((s, t) => s + t.errors, 0);
|
|
230
193
|
const tokens = total.usage.input + total.usage.output + total.usage.cacheRead + total.usage.cacheWrite;
|
|
@@ -331,7 +294,10 @@ export function buildModel(options) {
|
|
|
331
294
|
changes: options.comparisons?.filter(c => inRange(c.at)) ?? sortedChanges
|
|
332
295
|
.filter((c) => inRange(c.at))
|
|
333
296
|
.map((c) => ({ ...c, impact: index.range.start && c.at > index.range.start ? impactFromRows(projectRows, c, sortedChanges, options.windowDays, index.range, owner) : null })),
|
|
334
|
-
labels: {
|
|
297
|
+
labels: {
|
|
298
|
+
...labelsModel(options.labelsFile, options.sessionEvalsFile, { ...filter, until: options.openEnd ? undefined : filter.until, selected: labelIds, indexed: indexedIds }, (at) => versionAt(sortedChanges, ANCHORLOOP, at)),
|
|
299
|
+
needsIndex: !!labelIds && !hasSessionIds,
|
|
300
|
+
},
|
|
335
301
|
coverage: options.coverage ?? null,
|
|
336
302
|
work: workModel(options.work, filter),
|
|
337
303
|
};
|