pi-evals 0.0.0-stage → 0.2.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 +21 -0
- package/LICENSE +21 -0
- package/README.md +116 -2
- package/dist/aggregate.js +113 -0
- package/dist/build.js +260 -0
- package/dist/changes.js +170 -0
- package/dist/cli.js +86 -0
- package/dist/coverage.js +34 -0
- package/dist/detectors.js +154 -0
- package/dist/extract/file.js +42 -0
- package/dist/extract/run.js +149 -0
- package/dist/extract/session.js +430 -0
- package/dist/extract/worker.js +12 -0
- package/dist/index.js +165 -0
- package/dist/meta.js +233 -0
- package/dist/model.js +317 -0
- package/dist/observer.js +240 -0
- package/dist/ops.js +93 -0
- package/dist/owners.js +97 -0
- package/dist/paths.js +76 -0
- package/dist/project.js +43 -0
- package/dist/query.js +92 -0
- package/dist/render.js +31 -0
- package/dist/report/concepts.js +37 -0
- package/dist/report/findings.js +73 -0
- package/dist/report/format.js +16 -0
- package/dist/report/sections.js +61 -0
- package/dist/report/style.js +77 -0
- package/dist/report/timeline.js +91 -0
- package/dist/report/week.js +36 -0
- package/dist/schema.js +65 -0
- package/dist/skills.js +41 -0
- package/dist/store.js +51 -0
- package/docs/design.md +106 -0
- package/docs/learn.zh-TW.md +33 -0
- package/docs/schema.md +68 -0
- package/package.json +56 -4
- package/src/aggregate.ts +204 -0
- package/src/build.ts +257 -0
- package/src/changes.ts +178 -0
- package/src/cli.ts +89 -0
- package/src/coverage.ts +44 -0
- package/src/detectors.ts +182 -0
- package/src/extract/file.ts +46 -0
- package/src/extract/run.ts +198 -0
- package/src/extract/session.ts +430 -0
- package/src/extract/worker.ts +12 -0
- package/src/index.ts +160 -0
- package/src/meta.ts +259 -0
- package/src/model.ts +346 -0
- package/src/observer.ts +255 -0
- package/src/ops.ts +110 -0
- package/src/owners.ts +92 -0
- package/src/paths.ts +108 -0
- package/src/project.ts +43 -0
- package/src/query.ts +85 -0
- package/src/render.ts +63 -0
- package/src/report/concepts.ts +94 -0
- package/src/report/findings.ts +84 -0
- package/src/report/format.ts +24 -0
- package/src/report/sections.ts +188 -0
- package/src/report/style.ts +77 -0
- package/src/report/timeline.ts +143 -0
- package/src/report/week.ts +55 -0
- package/src/schema.ts +84 -0
- package/src/skills.ts +46 -0
- package/src/store.ts +49 -0
package/docs/design.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Design
|
|
2
|
+
|
|
3
|
+
pi-evals 0.1.0 is phase 1 of an evals effort for one person's pi setup: record how skills and packages are used and whether the work follows the anchorloop process, from past sessions and from now on, and show it in a report.
|
|
4
|
+
This file records the decisions and the words they came from.
|
|
5
|
+
The evidence came from four research notes written before the build (in the maintainer's agent-root repository, `scratch/evals/`): `instrumentation.md` (which pi seams carry which facts), `inventory.md` (anchorloop, pi-session-doctor and the session format on disk), `literature.md` (papers, OSS and the OTel conventions), and `research.md` (vendor guidance on agent and skill evals).
|
|
6
|
+
|
|
7
|
+
## What the owner asked for
|
|
8
|
+
|
|
9
|
+
The request, 2026-11-25: 「我想要強化一下 ai evals(上網看看最佳實踐),這可以把 session doctor 移除,或是把 session doctor 升級成 evals 工具,包括可以從資料產出視圖」 (strengthen AI evals following best practice; remove pi-session-doctor or upgrade it into an evals tool, with views produced from the data).
|
|
10
|
+
|
|
11
|
+
Decisions on 2026-11-26, binding for this package:
|
|
12
|
+
|
|
13
|
+
| Words | Decision |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| 「新套件 pi-evals,移除 session doctor」 | A new package. pi-session-doctor profiles event-loop stalls and never reads transcripts (inventory §5), so nothing of it carries over; its removal happens in the setup repository, not here. |
|
|
16
|
+
| 「回頭抽取+小觀察器」 | A read-only back-fill over the session files, plus a small live observer only for what those files lack. |
|
|
17
|
+
| 「自己產出靜態網頁」 | Our own static HTML report, not a hosted or self-hosted trace server. |
|
|
18
|
+
| 「可能會需要重新撰寫我們自己的 ask user … or monitor 如果他們沒有提供能記錄蹤跡的接口」 | No rewrite. The ask-user tool's results already hold the questions' count, cancel flag and wait time, and its `rpiv:ask-user:*` events show where an answer came from; pi-loop-monitor emits `monitor:started/finished/done/error` on `pi.events` with everything a record needs (instrumentation §2, §5). The observer listens; both packages stay untouched. |
|
|
19
|
+
| 「用 pi command 操作,這樣 agent 也可以自己去看」 | `/evals` (status, extract, report, mark) is the main surface, and one tool, `evals_query`, lets an agent read bounded summaries. The CLI is a thin wrapper over the same functions. |
|
|
20
|
+
| 「報表的設計會很重要,要注重人類可讀性,最好是可以記錄我做出的架構調整所造成的影響」 | A change timeline (pins, model routing, rules, skills, agent roles, live version changes, manual marks) with the same numbers before and after each change. The data (ReportModel, `model.json`) is separate from the renderer; this release ships a plain renderer, and the designed one will replace it after a mockup round. |
|
|
21
|
+
| 「先索引,穩定後再開清理」 | No cleanup code. `/evals status` and `evals_query coverage` report how many session files older than the cut (default 60 days without changes) the index fully covers, by count and bytes: the gate before a retention tool may delete them. Extra session roots (a future trash dir) are a setting. |
|
|
22
|
+
| 「記得我對 evals 是門外漢,你的報表和標記網頁要讓我有辦法看懂」 | Every metric and detector in the ReportModel carries a label, one sentence of meaning, the better direction, one sentence on how it is computed, and for detectors a pass and a fail example, in English and Traditional Chinese. No unexplained statistics terms in what the reader sees. |
|
|
23
|
+
|
|
24
|
+
Later phases, not built here, each with a seam left open: human labels (phase 2; `labels.jsonl` is joined if present), with-and-without-skill A/B runs (phase 3), and session cleanup through a retention tool once the index covers old sessions (phase 4; `extraRoots` reads its trash dir).
|
|
25
|
+
|
|
26
|
+
## Decisions
|
|
27
|
+
|
|
28
|
+
### One record shape, OTel names
|
|
29
|
+
|
|
30
|
+
OpenTelemetry's GenAI conventions already name the facts asked for: `execute_tool` spans with an agent-skills refinement (`gen_ai.skill.name`, `gen_ai.skill.resource.name`), `invoke_agent`, usage tokens, and the `gen_ai.evaluation.result` event (literature §2).
|
|
31
|
+
pi-evals uses those names, `pi.*` for pi facts, `anchorloop.*` for process facts, and `eval.annotator_kind` / `eval.scope` from OpenInference's annotation model, since OTel has no evaluation scope yet.
|
|
32
|
+
The session is an attribute (`session.id`), not a span, as pi-otel argues; a trace is one user prompt (literature §2, §4).
|
|
33
|
+
Skill use is counted from tool calls and expansions, never from text mentions: cc-skill-usage measured a 212-fold overcount from grepping names (literature §2).
|
|
34
|
+
A shell command counts as a skill load only when the whole command prints one `SKILL.md`; on the real corpus a looser rule counted 6,560 "loads" that were mostly searches and edits of skill files, against 21 under the strict rule.
|
|
35
|
+
|
|
36
|
+
### Privacy by construction
|
|
37
|
+
|
|
38
|
+
Sessions hold customer and ticket content and secrets (inventory, Gotchas; research §6).
|
|
39
|
+
Records hold derived facts only, and the guard is in the record builder: every string attribute must look like a name or it becomes `redacted`.
|
|
40
|
+
The summary keys (tool, skill, model and role names) pass the same check, because a model can choose a tool name or a path freely.
|
|
41
|
+
The privacy test was written first and failed on exactly that: a secret placed in a read path and a tool name reached `days.json` and the report through the summary keys while the records stayed clean.
|
|
42
|
+
|
|
43
|
+
### Back-fill
|
|
44
|
+
|
|
45
|
+
The session files hold almost everything (instrumentation §5): tool calls with `durationMs` (from October on; older calls use the time between call and result), the ask-user results in both the current and the retired `pi-ask-user` shapes, the skill catalog pi offered (the system message's `skills` section), monitor endings delivered as `pi-loop-monitor` messages, and close-guard notices.
|
|
46
|
+
Extraction streams each file line by line on a pool of worker threads and writes one record file per session file atomically.
|
|
47
|
+
It is incremental by path, size and modification time, so a later extract reads only active sessions; an extractor version in the checkpoint forces a full re-read when extraction changes.
|
|
48
|
+
A subagent session is linked to its parent three ways: the parent's `subagent` result (`details.id`, the child's logical id), `~/.pi/agent/dispatch-ledger/<parent>.json`, and the artifacts path in the child's brief.
|
|
49
|
+
Live records and back-fill meet by session id: back-fill counts win, and live adds monitor lifecycles and answer sources.
|
|
50
|
+
|
|
51
|
+
### Live observer
|
|
52
|
+
|
|
53
|
+
It registers handlers and nothing heavy: one tool-owner snapshot per session from `pi.getAllTools()` sourceInfo, the nearest `package.json` for name and version (instrumentation §1: "do not infer ownership from names"), a record per `tool_execution_end` (which also fires for blocked, aborted and invalid calls), skill loads from reads, `/skill:` input and declared-skills messages, `monitor:*` events, and `rpiv:ask-user:answer` to tag remote answers.
|
|
54
|
+
It appends to the state dir, never to the session file, and a failed write warns once per session and is otherwise ignored.
|
|
55
|
+
|
|
56
|
+
### Process detectors
|
|
57
|
+
|
|
58
|
+
Four session-scoped checks, each a `gen_ai.evaluation.result` with `annotator_kind` CODE.
|
|
59
|
+
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).
|
|
60
|
+
|
|
61
|
+
- `anchor_before_first_edit`: an `Anchor:` line or todo anchor appears before the first successful `write` or `edit`. An anchor stated only in a subagent's brief is still a fail, named `anchor_only_in_brief`, so the report can tell the two apart.
|
|
62
|
+
- `check_after_last_edit`: every command of the anchor has a passing run after the last change.
|
|
63
|
+
- `todo_evidence`: completed tasks in the final todo list carry evidence; the value is the share that do.
|
|
64
|
+
- `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).
|
|
65
|
+
|
|
66
|
+
Only sessions that started after anchorloop 3.0.0 reached this setup are judged: the pin commit in weihung-basic-agent, 2026-11-23T10:51:07Z. Older sessions are out of scope rather than failing (inventory, Gotchas), and they are left out of the "not applicable" counts.
|
|
67
|
+
Like the guard, an edit made through bash is not seen as a change.
|
|
68
|
+
These are process checks on observable events, which suits a process skill whose path is the product (research §1); they say how often the rules were followed, not whether the work was right.
|
|
69
|
+
A session's anchorloop version is the newest pin in the change timeline at or before the session's start, so a pin at 16:46 splits that day's sessions at 16:46.
|
|
70
|
+
|
|
71
|
+
### Change impact
|
|
72
|
+
|
|
73
|
+
Each change gets the same handful of numbers for the sessions that started in the 7 days (by default) before the change's time and in the 7 days from it, with the session count on each side.
|
|
74
|
+
The split is by start time, not calendar day: an earlier version split by day and credited a pin's effect to the 588 sessions of that day that ran before the pin.
|
|
75
|
+
Three flags go with each comparison: a side with fewer than 20 sessions is too small to read; a window that reaches before the first session or past the last extract is incomplete, with the days that have data on each side; and other commits inside the windows are counted once each, by the kinds they changed.
|
|
76
|
+
The flags are shown, not hidden: these comparisons hint at an effect and prove none (research §1 on noise: single runs vary by several points).
|
|
77
|
+
With this setup's pace of change almost every comparison has other commits nearby, so the kinds matter more than the count.
|
|
78
|
+
|
|
79
|
+
### Report
|
|
80
|
+
|
|
81
|
+
The ReportModel holds every number with its n and window, and the plain-language metadata; the renderer reads only it.
|
|
82
|
+
The HTML has no scripts, no network and no external assets, uses inline SVG, and follows the system's light or dark setting.
|
|
83
|
+
It renders in Traditional Chinese by default (`--lang en` for English).
|
|
84
|
+
|
|
85
|
+
Version 0.2.0 uses the timeline and comparison layouts selected on 2026-11-26.
|
|
86
|
+
The renderer makes the following editorial choices from the model, without consulting transcripts or fetching data:
|
|
87
|
+
|
|
88
|
+
- A pin or routing change qualifies for the front page even without a comparison; another change qualifies only if both windows have at least 20 sessions.
|
|
89
|
+
- The headline gives priority to a change to the process rules themselves: an anchorloop pin within seven days of the latest change with at least 20 applicable sessions on both sides of the anchor check. Otherwise take the newest qualifying comparison with enough sessions, then the newest qualifying change. With no candidate, report why there is nothing to compare.
|
|
90
|
+
- Show the lead and at most one earlier change from a different commit. Prefer a small sample with records on both sides (to show why the numbers might mislead), then a pin or routing change with a complete window, then the next eligible change. Order the cards by time. Keep every other entry in its UTC day’s disclosure, with a direct link to its detail; no truncation.
|
|
91
|
+
- For an anchorloop pin with two comparable readings of the anchor check, compare the two process rates. Otherwise use the package error rate when available on both sides, or the overall tool error rate, alongside cost per session. Rates use their own denominators, not the total session count. A missing value is a dash, not zero.
|
|
92
|
+
- The headline names the first comparable reading and whether it rose, fell or held steady at the displayed precision. A short window, small sample or overlapping change qualifies that observation. The verdict lists every applicable caveat, including a displayed reading based on fewer than 20 applicable observations on either side. Only a complete, unconfounded comparison with enough observations and a visible difference says there was an observable change. Even that is not a causal claim.
|
|
93
|
+
- The workload chart covers the last seven complete UTC dates in the report period (or fewer if the filter starts later), not seven nonempty days. Each marker means at least one change that day. Session and tool totals in the other sections still cover the selected report period.
|
|
94
|
+
- Each detail uses the model’s actual window and session counts. Dates with records may exceed seven in a seven-day window that starts mid-day. The ruler shows the last extract only when it falls inside the after window, and its segments are not to scale.
|
|
95
|
+
|
|
96
|
+
### Storage choices
|
|
97
|
+
|
|
98
|
+
JSON lines and JSON files, no database: the index is rebuilt from per-session summaries in about a second, and the reader needs no service (research §4: everything reduces to files plus one static page).
|
|
99
|
+
Back-filled records take about 0.7 GB for the 23.8 GB corpus; the per-day aggregates the report and the tool read take about 1.5 MB.
|
|
100
|
+
|
|
101
|
+
## Measured on the maintainer's corpus (2026-11-26)
|
|
102
|
+
|
|
103
|
+
- 21,526 session files, 23.8 GB, read in 21 to 84 seconds with seven workers (285 to 1,130 MB/s over four runs, depending on the disk cache and machine load), peak memory 3.0 to 3.2 GB; with one worker, 129 seconds (185 MB/s) and 1.0 GB. `--workers` caps both. A later extract reads only the files that changed: 23 files in under 2 seconds.
|
|
104
|
+
- 1.40 million records: 1.14 million tool calls, 80,000 detector results, 29,000 prompts, 11,000 skill loads, 7,300 monitor endings.
|
|
105
|
+
- Cross-checks against the raw files: ask-user calls 5,101 by both counts; `SKILL.md` reads on 2026-11-24, 570 raw against 568 counted (the two missing reads failed); one session's 73 tool calls, 73 in its summary and 73 records.
|
|
106
|
+
- Sixty random text samples from transcripts (messages, thinking, tool arguments) appear in no file under the state dir.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# 怎麼讀一次調整的結果
|
|
2
|
+
|
|
3
|
+
2026 年 11 月 25 日更新 pi-anchorloop 後,動手前先說好驗證方法的比例從 20.3% 降到 12.5%。
|
|
4
|
+
但報表產生時,新版才用了八個多小時。
|
|
5
|
+
以下數字取自當時的報表;下次抽取後,調整後的那一組還會變。
|
|
6
|
+
|
|
7
|
+
## 紀錄:當時做了什麼
|
|
8
|
+
|
|
9
|
+
代理人讀了一份技能說明,就留下一筆載入紀錄。
|
|
10
|
+
11 月 19 日至 25 日共計有 2,619 次技能載入;知道載入了幾次,不必知道對話裡說了什麼。
|
|
11
|
+
|
|
12
|
+
## 指標:用同一個算法數紀錄
|
|
13
|
+
|
|
14
|
+
同一週,按開始時間計算,共有 5,246 段工作。
|
|
15
|
+
工作段數是工作量的指標:一段工作載入三次技能,仍只有一段工作。
|
|
16
|
+
工作段數變多,不等於工作品質更好。
|
|
17
|
+
|
|
18
|
+
## 程式檢查:查得到先後,查不到方法好壞
|
|
19
|
+
|
|
20
|
+
調整後,有 6 段工作在改檔前就說好怎麼驗證,通過了這條檢查。
|
|
21
|
+
程式查的是「先說方法,再改檔」的順序;就算順序正確,那個方法也可能驗不到要修的問題。
|
|
22
|
+
|
|
23
|
+
## 前後比較與樣本數:哪幾段工作算進去了
|
|
24
|
+
|
|
25
|
+
以更新時間 16:46 UTC 為界,前面有 5,171 段工作,後面有 164 段。
|
|
26
|
+
後面這組只有 48 段適用「動手前先說好怎麼驗證」,所以 6 段通過是 6 / 48,也就是 12.5%,不是 6 / 164。
|
|
27
|
+
看另一條規則時,適用的工作不同,樣本數也會不同。
|
|
28
|
+
|
|
29
|
+
## 同期多個調整:原因還不能指給某個版本
|
|
30
|
+
|
|
31
|
+
同一段比較期間還有 76 筆別的調整。
|
|
32
|
+
如果規則和模型分派都改過,前後即使有差異,也不能只歸給套件更新。
|
|
33
|
+
等七天的資料收齊,可以重看比例;資料收齊本身不會排除其他調整的影響。
|
package/docs/schema.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Record schema, version 1
|
|
2
|
+
|
|
3
|
+
Live records (`events/<YYYY-MM-DD>.jsonl`) and back-filled records (`index/records/<YYYY-MM>/<key>.jsonl`) share one shape: one JSON object per line.
|
|
4
|
+
Names follow the [OpenTelemetry GenAI semantic conventions](https://github.com/open-telemetry/semantic-conventions-genai) where they define one (status: Development); `pi.*` names pi facts, `anchorloop.*` names process facts, and `eval.*` names evaluation metadata that OTel does not define yet.
|
|
5
|
+
The envelope is shaped so a replay to an OTLP backend needs no renaming.
|
|
6
|
+
|
|
7
|
+
## Envelope
|
|
8
|
+
|
|
9
|
+
| Field | Type | Meaning |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `schema_version` | number | `1`. Additive changes keep the version; a removed or renamed field raises it. |
|
|
12
|
+
| `name` | string | Span or event name, from the table below. |
|
|
13
|
+
| `kind` | `"span"` \| `"event"` | A span has a duration; an event is a point in time. |
|
|
14
|
+
| `ts` | ISO 8601 UTC | Start of a span, or the time of an event. |
|
|
15
|
+
| `end_ts`, `duration_ms` | ISO, number | End and length of a span, when known. |
|
|
16
|
+
| `trace_id` | 32 hex | One trace per user prompt: everything from one prompt to the next. Stable across re-extraction. |
|
|
17
|
+
| `span_id` | 16 hex | Stable id derived from the session id and the entry or tool call id. |
|
|
18
|
+
| `source` | `"backfill"` \| `"live"` | Which reader wrote it. |
|
|
19
|
+
| `attrs` | object | Attributes. Strings must look like names (letters, digits, `_@./:+#=\|-`, at most 160 characters); anything else is stored as `redacted`. |
|
|
20
|
+
|
|
21
|
+
Every record carries `session.id` (the pi session id from the session header) and `pi.project` (a short project key: the repository name for `~/projects/<repo>/…` and for Herdr worktrees, else the first path segment).
|
|
22
|
+
|
|
23
|
+
## Records
|
|
24
|
+
|
|
25
|
+
| Name | Kind | Attributes |
|
|
26
|
+
| --- | --- | --- |
|
|
27
|
+
| `pi.session` | event | `pi.session.kind` (`interactive` \| `subagent`), `pi.subagent.logical_id`, `pi.session.parent_id`, `gen_ai.request.model` (last model), `pi.tool_calls`, `pi.usage.cost_usd`. Back-fill writes it when a session file ends (`ts` start, `end_ts` last entry); live writes it at session start. |
|
|
28
|
+
| `invoke_agent` | span | One per user prompt (the trace root). `gen_ai.operation.name` = `invoke_agent`, `gen_ai.agent.name` = `pi`, `pi.prompt.origin` (`user` \| `skill_command` \| `extension`), and in back-fill `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.usage.cache_read.input_tokens`, `gen_ai.usage.cache_write.input_tokens`, `pi.usage.cost_usd`, `pi.tool_calls` for the whole prompt. |
|
|
29
|
+
| `execute_tool` | span | One per finished tool call, including failed, blocked and aborted calls. `gen_ai.operation.name` = `execute_tool`, `gen_ai.tool.name`, `gen_ai.tool.call.id`, `error.type` (`tool_error` when the result is an error), `pi.duration.source` (`measured` \| `timestamps` \| `not_run`), `pi.tool.exit_code` (bash). Live adds `pi.tool.owner` and `pi.tool.owner_version` from `pi.getAllTools()` sourceInfo, and `pi.tool.parent_call` for nested calls. A read of a skill file adds `gen_ai.skill.name` and, for files other than `SKILL.md`, `gen_ai.skill.resource.name` (the OTel agent-skills refinement applied to pi's `read`). Ask-user calls add `pi.ask_user.questions`, `pi.ask_user.cancelled`, `pi.ask_user.source` (`terminal` \| `remote` \| `none` live; `unknown` in back-fill). Subagent launches add `gen_ai.agent.name` (role), `gen_ai.request.model`, `pi.subagent.logical_id`. |
|
|
30
|
+
| `pi.skill.load` | event | `gen_ai.skill.name`, `pi.skill.trigger` (`read` \| `slash` \| `declared` \| `bash`), `gen_ai.tool.call.id` when a tool call loaded it. Count skill use from these records only; the skill attributes on `execute_tool` describe the same read. |
|
|
31
|
+
| `pi.monitor` | span | `pi.monitor.id` (per session), `pi.monitor.status` (`completed` \| `error` \| `stopped` \| …), `pi.monitor.exit_code`, `pi.monitor.output_lines`, `pi.monitor.reported_status` (live). Back-fill sees only the endings pi-loop-monitor delivered to the session (about half); live sees every `monitor:*` event. |
|
|
32
|
+
| `anchorloop.close_guard.notice` | event | `anchorloop.notice.kind`: `no_anchor`, `no_passing_run`, `evidence_handoff`, `other`. |
|
|
33
|
+
| `gen_ai.evaluation.result` | event | One per process detector per session. `gen_ai.evaluation.name`, `gen_ai.evaluation.score.label` (`pass` \| `fail` \| `na`), `gen_ai.evaluation.score.value` (1, 0, or a share), `gen_ai.evaluation.explanation` (a fixed reason code), `eval.annotator_kind` = `CODE`, `eval.scope` = `session`, `eval.detector.version`. |
|
|
34
|
+
| `pi.compaction` | event | A compaction entry in the session. |
|
|
35
|
+
| `pi.tools.snapshot` | event | Live, once per session at the first prompt: `pi.tools`, a sorted list of `tool=owner@version`. |
|
|
36
|
+
| `pi.skills.available` | event | Live, once per session: `pi.skills`, the names of the skills pi offered. |
|
|
37
|
+
|
|
38
|
+
### Process detectors
|
|
39
|
+
|
|
40
|
+
| `gen_ai.evaluation.name` | `pass` | `fail` explanations | `na` explanations |
|
|
41
|
+
| --- | --- | --- | --- |
|
|
42
|
+
| `anchor_before_first_edit` | `anchor_first` | `change_before_anchor`, `anchor_only_in_brief` | `no_edit` |
|
|
43
|
+
| `check_after_last_edit` | `anchor_green` | `no_passing_run_after_change` | `no_edit`, `no_anchor`, `anchor_without_command` |
|
|
44
|
+
| `todo_evidence` | `all_evidenced` | `completed_without_evidence` (value = share with evidence) | `no_completed_task` |
|
|
45
|
+
| `close_guard_quiet` | `no_notice` | the commonest notice kind | `no_edit` |
|
|
46
|
+
|
|
47
|
+
Sessions that started before 2026-11-23T10:51:07Z (the anchorloop 3.0.0 pin) get `na` with `out_of_scope_pre_3.0` for all four.
|
|
48
|
+
|
|
49
|
+
## Labels (for a later phase)
|
|
50
|
+
|
|
51
|
+
`labels.jsonl` in the state dir, one human verdict per line:
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{ "session_id": "01a2…", "evaluation_name": "anchor_before_first_edit", "label": "fail", "at": "2026-12-01T09:00:00Z", "note": "optional" }
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The report joins these with `index/session-evals.json` (the code labels per session) and shows how often they agree.
|
|
58
|
+
|
|
59
|
+
## Change timeline
|
|
60
|
+
|
|
61
|
+
`changes.jsonl`, rebuilt by every extract, one change per line:
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{ "at": "2026-11-25T08:12:00.000Z", "kind": "pin", "subject": "commit subject", "package": "pi-anchorloop", "from": "3.2.0", "to": "3.3.0", "sha": "7614445…", "repo": "weihung-basic-agent", "source": "git" }
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`kind` is `pin`, `model-routing`, `rule`, `skill`, `agent-role`, or `manual`; `source` is `git`, `live` (a version change between two live tool snapshots) or `mark` (`/evals mark`).
|
|
68
|
+
Unlike records, `subject` is free text: a commit subject or your own note.
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-evals",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
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
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "wayne930242",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/wayne930242/pi-evals.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/wayne930242/pi-evals#readme",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"pi-package",
|
|
15
|
+
"pi",
|
|
16
|
+
"pi-coding-agent",
|
|
17
|
+
"extension",
|
|
18
|
+
"evals",
|
|
19
|
+
"telemetry",
|
|
20
|
+
"skills",
|
|
21
|
+
"opentelemetry"
|
|
22
|
+
],
|
|
23
|
+
"bin": {
|
|
24
|
+
"pi-evals": "dist/cli.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"src",
|
|
28
|
+
"dist",
|
|
29
|
+
"docs",
|
|
30
|
+
"README.md",
|
|
31
|
+
"CHANGELOG.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"pi": {
|
|
35
|
+
"extensions": [
|
|
36
|
+
"./src/index.ts"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.build.json",
|
|
41
|
+
"check": "tsc --noEmit",
|
|
42
|
+
"test": "npm run build && node --test --test-force-exit tests/*.test.ts",
|
|
43
|
+
"prepack": "npm run build"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=22.18"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
50
|
+
"typebox": "*"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@earendil-works/pi-coding-agent": "1.6.1",
|
|
54
|
+
"@types/node": "26.6.10",
|
|
55
|
+
"typebox": "1.4.7",
|
|
56
|
+
"typescript": "7.0.2"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/aggregate.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/** Additive per-day aggregates. A session summary holds one per UTC day; the index sums them by day and project. */
|
|
2
|
+
import type { DetectorName, NoticeKind } from "./detectors.ts";
|
|
3
|
+
import type { Label } from "./schema.ts";
|
|
4
|
+
|
|
5
|
+
export interface ToolAgg {
|
|
6
|
+
calls: number;
|
|
7
|
+
errors: number;
|
|
8
|
+
durSum: number;
|
|
9
|
+
durN: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Upper bounds (ms) of the ask-user wait buckets; the last bucket is open. */
|
|
13
|
+
export const ASK_BUCKETS = [10_000, 30_000, 60_000, 300_000, 1_800_000];
|
|
14
|
+
|
|
15
|
+
export interface DayAgg {
|
|
16
|
+
sessions: number;
|
|
17
|
+
subagentSessions: number;
|
|
18
|
+
prompts: number;
|
|
19
|
+
tools: Record<string, ToolAgg>;
|
|
20
|
+
skills: Record<string, number>;
|
|
21
|
+
skillTriggers: Record<string, number>;
|
|
22
|
+
/** Sessions (by start day) that loaded the skill, and their total cost. */
|
|
23
|
+
skillSessions: Record<string, number>;
|
|
24
|
+
skillCost: Record<string, number>;
|
|
25
|
+
ask: { calls: number; cancelled: number; errors: number; durSum: number; durN: number; buckets: number[]; sources: Record<string, number> };
|
|
26
|
+
monitors: { started: number; finished: number; statuses: Record<string, number>; durSum: number; durN: number };
|
|
27
|
+
/** Subagent launches by `role|model`. */
|
|
28
|
+
subagents: Record<string, number>;
|
|
29
|
+
/** Cost and sessions of subagent sessions by the role their parent gave them (filled when the index links them). */
|
|
30
|
+
subagentCost: Record<string, number>;
|
|
31
|
+
usage: { input: number; output: number; cacheRead: number; cacheWrite: number; cost: number; calls: number };
|
|
32
|
+
models: Record<string, number>;
|
|
33
|
+
detectors: Record<string, { pass: number; fail: number; na: number }>;
|
|
34
|
+
/** Detector results by anchorloop version: `detector|version` (filled by the index). */
|
|
35
|
+
detectorVersions: Record<string, { pass: number; fail: number; na: number }>;
|
|
36
|
+
notices: Record<string, number>;
|
|
37
|
+
compactions: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function emptyDay(): DayAgg {
|
|
41
|
+
return {
|
|
42
|
+
sessions: 0,
|
|
43
|
+
subagentSessions: 0,
|
|
44
|
+
prompts: 0,
|
|
45
|
+
tools: {},
|
|
46
|
+
skills: {},
|
|
47
|
+
skillTriggers: {},
|
|
48
|
+
skillSessions: {},
|
|
49
|
+
skillCost: {},
|
|
50
|
+
ask: { calls: 0, cancelled: 0, errors: 0, durSum: 0, durN: 0, buckets: ASK_BUCKETS.map(() => 0).concat(0), sources: {} },
|
|
51
|
+
monitors: { started: 0, finished: 0, statuses: {}, durSum: 0, durN: 0 },
|
|
52
|
+
subagents: {},
|
|
53
|
+
subagentCost: {},
|
|
54
|
+
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, calls: 0 },
|
|
55
|
+
models: {},
|
|
56
|
+
detectors: {},
|
|
57
|
+
detectorVersions: {},
|
|
58
|
+
notices: {},
|
|
59
|
+
compactions: 0,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const bump = (map: Record<string, number>, key: string, by = 1) => {
|
|
64
|
+
map[key] = (map[key] ?? 0) + by;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export function bucketOf(ms: number): number {
|
|
68
|
+
const i = ASK_BUCKETS.findIndex((limit) => ms < limit);
|
|
69
|
+
return i < 0 ? ASK_BUCKETS.length : i;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function addCounts(into: Record<string, number>, from: Record<string, number>) {
|
|
73
|
+
for (const [k, v] of Object.entries(from)) bump(into, k, v);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function addLabels(into: Record<string, { pass: number; fail: number; na: number }>, from: Record<string, { pass: number; fail: number; na: number }>) {
|
|
77
|
+
for (const [k, v] of Object.entries(from)) {
|
|
78
|
+
const t = (into[k] ??= { pass: 0, fail: 0, na: 0 });
|
|
79
|
+
t.pass += v.pass;
|
|
80
|
+
t.fail += v.fail;
|
|
81
|
+
t.na += v.na;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function addLabel(into: Record<string, { pass: number; fail: number; na: number }>, key: string, label: Label) {
|
|
86
|
+
const t = (into[key] ??= { pass: 0, fail: 0, na: 0 });
|
|
87
|
+
t[label] += 1;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Adds `from` into `into` and returns `into`. */
|
|
91
|
+
export function mergeDay(into: DayAgg, from: DayAgg): DayAgg {
|
|
92
|
+
into.sessions += from.sessions;
|
|
93
|
+
into.subagentSessions += from.subagentSessions;
|
|
94
|
+
into.prompts += from.prompts;
|
|
95
|
+
for (const [name, t] of Object.entries(from.tools)) {
|
|
96
|
+
const a = (into.tools[name] ??= { calls: 0, errors: 0, durSum: 0, durN: 0 });
|
|
97
|
+
a.calls += t.calls;
|
|
98
|
+
a.errors += t.errors;
|
|
99
|
+
a.durSum += t.durSum;
|
|
100
|
+
a.durN += t.durN;
|
|
101
|
+
}
|
|
102
|
+
addCounts(into.skills, from.skills);
|
|
103
|
+
addCounts(into.skillTriggers, from.skillTriggers);
|
|
104
|
+
addCounts(into.skillSessions, from.skillSessions);
|
|
105
|
+
addCounts(into.skillCost, from.skillCost);
|
|
106
|
+
mergeAsk(into.ask, from.ask);
|
|
107
|
+
mergeMonitors(into.monitors, from.monitors);
|
|
108
|
+
addCounts(into.subagents, from.subagents);
|
|
109
|
+
addCounts(into.subagentCost, from.subagentCost);
|
|
110
|
+
for (const key of Object.keys(into.usage) as (keyof DayAgg["usage"])[]) into.usage[key] += from.usage[key];
|
|
111
|
+
addCounts(into.models, from.models);
|
|
112
|
+
addLabels(into.detectors, from.detectors);
|
|
113
|
+
addLabels(into.detectorVersions, from.detectorVersions);
|
|
114
|
+
addCounts(into.notices, from.notices);
|
|
115
|
+
into.compactions += from.compactions;
|
|
116
|
+
return into;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function mergeAsk(into: DayAgg["ask"], from: DayAgg["ask"]) {
|
|
120
|
+
into.calls += from.calls;
|
|
121
|
+
into.cancelled += from.cancelled;
|
|
122
|
+
into.errors += from.errors;
|
|
123
|
+
into.durSum += from.durSum;
|
|
124
|
+
into.durN += from.durN;
|
|
125
|
+
from.buckets.forEach((v, i) => (into.buckets[i] = (into.buckets[i] ?? 0) + v));
|
|
126
|
+
addCounts(into.sources, from.sources);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function mergeMonitors(into: DayAgg["monitors"], from: DayAgg["monitors"]) {
|
|
130
|
+
into.started += from.started;
|
|
131
|
+
into.finished += from.finished;
|
|
132
|
+
into.durSum += from.durSum;
|
|
133
|
+
into.durN += from.durN;
|
|
134
|
+
addCounts(into.statuses, from.statuses);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** One session's derived facts: per-day aggregates plus the session-level fields the index joins on. */
|
|
138
|
+
export interface SessionSummary {
|
|
139
|
+
v: 1;
|
|
140
|
+
sessionId: string;
|
|
141
|
+
project: string;
|
|
142
|
+
start: string;
|
|
143
|
+
end: string;
|
|
144
|
+
kind: "interactive" | "subagent";
|
|
145
|
+
/** Logical id of a subagent session (the first uuid of its file name). */
|
|
146
|
+
logicalId?: string;
|
|
147
|
+
/** Parent session id, when the brief's artifact path or a dispatch ledger names it. */
|
|
148
|
+
parentId?: string;
|
|
149
|
+
/** Logical ids of the subagents this session launched, with the role and model it asked for. */
|
|
150
|
+
spawned: { id: string; role: string; model: string }[];
|
|
151
|
+
cost: number;
|
|
152
|
+
tokens: number;
|
|
153
|
+
toolCalls: number;
|
|
154
|
+
/** Session-level detector results (`na` outside the anchorloop 3.x era). */
|
|
155
|
+
evals: Partial<Record<DetectorName, { label: Label; value?: number; explanation: string }>>;
|
|
156
|
+
notices: Partial<Record<NoticeKind, number>>;
|
|
157
|
+
/** Hash of the skill catalog pi offered this session (names in the index's catalog table). */
|
|
158
|
+
catalog?: string;
|
|
159
|
+
days: Record<string, DayAgg>;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* One session in a few numbers, keyed to its start time: what the before/after comparison of a change and the
|
|
164
|
+
* version split read, so a change at 16:00 splits a day's sessions at 16:00 rather than at midnight.
|
|
165
|
+
*/
|
|
166
|
+
export interface SessionRow {
|
|
167
|
+
/** Start, ISO. */
|
|
168
|
+
s: string;
|
|
169
|
+
p: string;
|
|
170
|
+
/** 1 for a subagent session. */
|
|
171
|
+
k: 0 | 1;
|
|
172
|
+
/** Model cost, USD. */
|
|
173
|
+
c: number;
|
|
174
|
+
/** Tool → [calls, errors]. */
|
|
175
|
+
t: Record<string, [number, number]>;
|
|
176
|
+
/** Ask-user calls and dismissals. */
|
|
177
|
+
ac: number;
|
|
178
|
+
ax: number;
|
|
179
|
+
/** Skill loads and close-guard notices. */
|
|
180
|
+
sl: number;
|
|
181
|
+
nt: number;
|
|
182
|
+
/** Detector → 1 pass, 0 fail (in scope and applicable only). */
|
|
183
|
+
ev: Record<string, 0 | 1>;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function rowOf(start: string, project: string, subagent: boolean, cost: number, days: Record<string, DayAgg>, evals: Record<string, { label: Label } | undefined> = {}): SessionRow {
|
|
187
|
+
const row: SessionRow = { s: start, p: project, k: subagent ? 1 : 0, c: Math.round(cost * 1e4) / 1e4, t: {}, ac: 0, ax: 0, sl: 0, nt: 0, ev: {} };
|
|
188
|
+
for (const day of Object.values(days)) {
|
|
189
|
+
for (const [tool, t] of Object.entries(day.tools)) {
|
|
190
|
+
const cell = (row.t[tool] ??= [0, 0]);
|
|
191
|
+
cell[0] += t.calls;
|
|
192
|
+
cell[1] += t.errors;
|
|
193
|
+
}
|
|
194
|
+
row.ac += day.ask.calls;
|
|
195
|
+
row.ax += day.ask.cancelled;
|
|
196
|
+
row.sl += Object.values(day.skills).reduce((s, v) => s + v, 0);
|
|
197
|
+
row.nt += Object.values(day.notices).reduce((s, v) => s + v, 0);
|
|
198
|
+
}
|
|
199
|
+
for (const [name, result] of Object.entries(evals)) {
|
|
200
|
+
if (result?.label === "pass") row.ev[name] = 1;
|
|
201
|
+
else if (result?.label === "fail") row.ev[name] = 0;
|
|
202
|
+
}
|
|
203
|
+
return row;
|
|
204
|
+
}
|