pi-evals 0.2.0 → 0.4.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 +15 -0
- package/README.md +23 -9
- package/dist/build.js +14 -4
- package/dist/cli.js +2 -2
- package/dist/coverage.js +8 -1
- package/dist/extract/run.js +1 -1
- package/dist/extract/session.js +43 -3
- package/dist/findings.js +54 -0
- package/dist/index.js +14 -7
- package/dist/meta.js +43 -1
- package/dist/model.js +35 -14
- package/dist/ops.js +53 -22
- package/dist/paths.js +3 -0
- package/dist/query.js +36 -13
- package/dist/ranges.js +14 -0
- package/dist/render.js +15 -5
- package/dist/report/concepts.js +23 -1
- package/dist/report/findings.js +12 -1
- package/dist/report/sections.js +7 -5
- package/dist/report/strip.js +42 -0
- package/dist/report/style.js +14 -1
- package/dist/report/timeline.js +5 -14
- package/dist/report/week.js +21 -13
- package/dist/report/work.js +59 -0
- package/dist/schema.js +16 -1
- package/dist/trends.js +58 -0
- package/dist/work/join.js +429 -0
- package/dist/work/model.js +145 -0
- package/dist/work/query.js +59 -0
- package/dist/work/sb.js +131 -0
- package/dist/work/track.js +323 -0
- package/docs/design.md +15 -0
- package/docs/schema.md +8 -2
- package/package.json +5 -2
- package/scripts/change-impact.mjs +18 -0
- package/scripts/package-errors.mjs +10 -0
- package/scripts/query-lib.mjs +36 -0
- package/scripts/skill-days.mjs +9 -0
- package/skills/analyzing-evals/SKILL.md +23 -0
- package/src/aggregate.ts +14 -2
- package/src/build.ts +13 -4
- package/src/cli.ts +2 -2
- package/src/coverage.ts +8 -1
- package/src/extract/run.ts +1 -1
- package/src/extract/session.ts +36 -2
- package/src/findings.ts +52 -0
- package/src/index.ts +14 -9
- package/src/meta.ts +45 -1
- package/src/model.ts +40 -15
- package/src/ops.ts +50 -22
- package/src/paths.ts +7 -0
- package/src/query.ts +32 -13
- package/src/ranges.ts +15 -0
- package/src/render.ts +15 -5
- package/src/report/concepts.ts +30 -1
- package/src/report/findings.ts +19 -1
- package/src/report/sections.ts +9 -9
- package/src/report/strip.ts +40 -0
- package/src/report/style.ts +14 -1
- package/src/report/timeline.ts +6 -22
- package/src/report/week.ts +21 -17
- package/src/report/work.ts +87 -0
- package/src/schema.ts +16 -1
- package/src/trends.ts +61 -0
- package/src/work/join.ts +476 -0
- package/src/work/model.ts +179 -0
- package/src/work/query.ts +53 -0
- package/src/work/sb.ts +158 -0
- package/src/work/track.ts +397 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
- 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.
|
|
6
|
+
- Back-fill rebuilds work items from `todo/v1` snapshots, never merging tasks across a `clear` or a `/tree` branch, and writes `pi.workitem` and `pi.stall` records. It reads todo `uid`, `origin` and evidence `ref`, the review thread's `item` and `closed`, and the sb ledger when they exist, and joins by names otherwise.
|
|
7
|
+
- A work item's title (its todo subject, at most 80 characters) is the only source text pi-evals stores.
|
|
8
|
+
- `evals_query` has an `items` view, and `findings` adds a line when a like-with-like difference or a long wait stands out.
|
|
9
|
+
- A label of `unclear` is left out of the agreement rate and counted on its own (「看不出來」).
|
|
10
|
+
- Re-extracts every session once (extractor version 4).
|
|
11
|
+
|
|
12
|
+
## 0.3.0
|
|
13
|
+
|
|
14
|
+
- Open the report on the last 30 days and switch to 14 days, 90 days or all time without scripts. For other dates use `--since` or `--days`.
|
|
15
|
+
- Ask `/evals findings` or use the `findings` tool view for the headline, its limits, and which numbers to read next. Tool views now default to 30 days.
|
|
16
|
+
- The `analyzing-evals` skill includes three small queries for the details of a change, daily sessions using one skill, and a package’s daily errors.
|
|
17
|
+
|
|
3
18
|
## 0.2.0
|
|
4
19
|
|
|
5
20
|
- The report opens on two architecture changes, with a workload chart and a comparison you can open for every entry in the timeline. Each comparison shows what was counted and what limits the conclusion.
|
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ Agents can read the same numbers through one tool, `evals_query`.
|
|
|
13
13
|
- **Subagents**: launches by role and model, and their cost by role.
|
|
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
|
+
- **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.
|
|
16
17
|
- **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.
|
|
17
18
|
|
|
18
19
|
## Privacy
|
|
@@ -20,7 +21,8 @@ Agents can read the same numbers through one tool, `evals_query`.
|
|
|
20
21
|
Records hold derived facts only: names (tools, skills, packages, models, roles, project keys), counts, durations, exit codes, outcomes, and token and cost numbers.
|
|
21
22
|
They never hold transcript text, tool arguments, file contents, commands, questions, or answers.
|
|
22
23
|
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`.
|
|
23
|
-
|
|
24
|
+
The one exception is a work item's title: its todo subject, cut to one line of at most 80 characters.
|
|
25
|
+
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.
|
|
24
26
|
|
|
25
27
|
Everything stays on your machine, under `$XDG_STATE_HOME/pi-evals` (default `~/.local/state/pi-evals`).
|
|
26
28
|
Session files are only read, never written.
|
|
@@ -40,7 +42,8 @@ The observer loads in every session, subagents included.
|
|
|
40
42
|
| --- | --- |
|
|
41
43
|
| `/evals` or `/evals status` | Record counts, the last extract, index coverage of old sessions, and the report path. |
|
|
42
44
|
| `/evals extract [--workers N]` | Back-fills changed sessions in a background process, with two workers by default to leave memory for pi. Progress shows in the footer. |
|
|
43
|
-
| `/evals
|
|
45
|
+
| `/evals findings [--since YYYY-MM-DD] [--project <key>]` | Shows the report’s headline, what limits it, and where to look next. |
|
|
46
|
+
| `/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. |
|
|
44
47
|
| `/evals mark <note>` | Adds a note to the change timeline, e.g. `/evals mark workers moved to gpt-6.2-astra`. |
|
|
45
48
|
|
|
46
49
|
The same operations run from a shell, where extraction defaults to one fewer worker than available CPUs (at least one, at most eight).
|
|
@@ -48,7 +51,7 @@ On either surface, `--workers 0` reads the files sequentially without worker thr
|
|
|
48
51
|
|
|
49
52
|
```sh
|
|
50
53
|
pi-evals extract [--root <dir>]... [--workers <n>] [--json]
|
|
51
|
-
pi-evals report [--out <dir>] [--since YYYY-MM-DD] [--project <key>] [--lang zh|en]
|
|
54
|
+
pi-evals report [--out <dir>] [--since YYYY-MM-DD | --days N] [--project <key>] [--lang zh|en]
|
|
52
55
|
pi-evals status
|
|
53
56
|
pi-evals query <view> [--since YYYY-MM-DD] [--project <key>]
|
|
54
57
|
pi-evals mark <note>
|
|
@@ -56,23 +59,32 @@ pi-evals mark <note>
|
|
|
56
59
|
|
|
57
60
|
### The `evals_query` tool
|
|
58
61
|
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
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`.
|
|
64
|
+
The result is plain text under 2 KB, covering the latest 30 UTC dates through the last extract unless you give `since`.
|
|
65
|
+
`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
|
+
It also counts offered skills with no loads in the selected period and checks whether all old files are indexed.
|
|
67
|
+
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.
|
|
61
68
|
The tool never starts an extract.
|
|
62
69
|
|
|
63
70
|
## The report
|
|
64
71
|
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
Open `report.html` for the last 30 UTC dates, including the day of the last extract.
|
|
73
|
+
The links at the top switch to 14 days, 90 days or all time; each opens another offline page in the same directory, with no scripts or external assets.
|
|
74
|
+
Each page has a matching `model*.json` with the numbers it shows.
|
|
75
|
+
`--since` or `--days` writes `report-custom.html` and `model-custom.json` without replacing the preset pages.
|
|
67
76
|
Every number in the model carries a plain-language label, what it means, which direction is better, and how it is computed, in English and Traditional Chinese.
|
|
68
77
|
### Reading the report
|
|
69
78
|
|
|
79
|
+
The strip below the date switch counts the changes by kind; its labeled marks open the highlighted comparisons.
|
|
70
80
|
Start with the sentence above the timeline: it says what changed in the numbers; the next line tells you what limits the comparison.
|
|
71
81
|
Open a card to see which sessions started before and after the change.
|
|
72
82
|
Read the count beside each rate: a check that applies to 48 sessions can say nothing about the other 116 sessions in a group of 164.
|
|
73
83
|
If the window is short, or other changes landed in the same period, do not credit a difference to the new version alone.
|
|
74
84
|
|
|
75
|
-
The sidebar shows workload for the
|
|
85
|
+
The sidebar shows workload for the selected dates, with markers on days you changed the setup.
|
|
86
|
+
A change appears on the timeline by its own date; its before-and-after comparison can reach beyond the selected dates.
|
|
87
|
+
The cleanup check always considers **all** old files, so selecting two weeks cannot hide an unindexed file from last year.
|
|
76
88
|
The date disclosures keep the rest of the timeline available without putting hundreds of cards on the first screen.
|
|
77
89
|
Use the section links for usage, process checks, cost and cleanup coverage, or read the [five concepts with a worked example](docs/learn.zh-TW.md).
|
|
78
90
|
|
|
@@ -106,8 +118,10 @@ Use the section links for usage, process checks, cost and cleanup coverage, or r
|
|
|
106
118
|
| `index/days.json` | Aggregates by day and project. |
|
|
107
119
|
| `index/sessions.json` | A few numbers per session with its start time, for splitting sessions at a change's time. |
|
|
108
120
|
| `index/session-evals.json` | Process check results per session, for joining your labels. |
|
|
121
|
+
| `index/items.json`, `index/workitems.jsonl` | Work items joined across sessions, and their `pi.workitem` and `pi.stall` records. |
|
|
122
|
+
| `index/lines.json` | Cached `git diff --numstat` line counts between evidence commits. |
|
|
109
123
|
| `changes.jsonl`, `marks.jsonl` | The change timeline and your notes. |
|
|
110
|
-
| `labels.jsonl` | Your labels, when you add them (a later phase): `{ "session_id", "evaluation_name", "label": "pass" \| "fail" }` per line. The report then shows how often you and the automatic checks agree. |
|
|
124
|
+
| `labels.jsonl` | Your labels, when you add them (a later phase): `{ "session_id", "evaluation_name", "label": "pass" \| "fail" \| "unclear" }` per line. The report then shows how often you and the automatic checks agree; `unclear` labels are counted apart. |
|
|
111
125
|
| `reports/report.html`, `reports/model.json` | The report. |
|
|
112
126
|
|
|
113
127
|
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/build.js
CHANGED
|
@@ -9,9 +9,10 @@ import { dirname, join } from "node:path";
|
|
|
9
9
|
import { addLabel, bucketOf, bump, emptyDay, mergeDay, rowOf } from "./aggregate.js";
|
|
10
10
|
import { buildChanges, versionAt, writeChanges } from "./changes.js";
|
|
11
11
|
import { dayOf } from "./paths.js";
|
|
12
|
-
import { NAMES } from "./schema.js";
|
|
12
|
+
import { NAMES, traceId } from "./schema.js";
|
|
13
13
|
import { liveFiles, readRecords } from "./store.js";
|
|
14
|
-
|
|
14
|
+
import { ANCHORLOOP, joinWork, Lines, sbDirOf, writeWork } from "./work/join.js";
|
|
15
|
+
export const ANCHORLOOP_PACKAGES = ANCHORLOOP;
|
|
15
16
|
function atomicWrite(file, text) {
|
|
16
17
|
mkdirSync(dirname(file), { recursive: true });
|
|
17
18
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
@@ -198,7 +199,8 @@ export function buildIndex(options) {
|
|
|
198
199
|
if (Object.keys(labels).length)
|
|
199
200
|
sessionEvals[s.sessionId] = labels;
|
|
200
201
|
add(s.project, days);
|
|
201
|
-
rows.push(rowOf(s.start, s.project, s.kind === "subagent", s.cost, days, s.evals))
|
|
202
|
+
rows.push({ ...rowOf(s.start, s.project, s.kind === "subagent", s.cost, days, s.evals), id: traceId(s.sessionId, "labels"),
|
|
203
|
+
linked: s.kind === "subagent" ? Boolean(s.parentId || (s.logicalId && links.has(s.logicalId))) : undefined });
|
|
202
204
|
}
|
|
203
205
|
let liveOnly = 0;
|
|
204
206
|
for (const [id, records] of bySession) {
|
|
@@ -207,7 +209,7 @@ export function buildIndex(options) {
|
|
|
207
209
|
liveOnly += 1;
|
|
208
210
|
const summary = liveSummary(records);
|
|
209
211
|
add(summary.project, summary.days);
|
|
210
|
-
rows.push(rowOf(summary.start, summary.project, records.some((r) => r.name === NAMES.session && r.attrs["pi.session.kind"] === "subagent"), 0, summary.days));
|
|
212
|
+
rows.push({ ...rowOf(summary.start, summary.project, records.some((r) => r.name === NAMES.session && r.attrs["pi.session.kind"] === "subagent"), 0, summary.days), id: traceId(id, "labels"), linked: false });
|
|
211
213
|
}
|
|
212
214
|
const owners = {};
|
|
213
215
|
for (const rec of [...snapshots].sort((a, b) => a.ts.localeCompare(b.ts))) {
|
|
@@ -248,6 +250,14 @@ export function buildIndex(options) {
|
|
|
248
250
|
atomicWrite(layout.days, JSON.stringify(index));
|
|
249
251
|
atomicWrite(layout.sessionRows, JSON.stringify(rows));
|
|
250
252
|
atomicWrite(layout.sessionEvals, JSON.stringify(sessionEvals));
|
|
253
|
+
const now = options.now?.() ?? new Date();
|
|
254
|
+
try {
|
|
255
|
+
const work = joinWork({ summaries, changes, sbDir: sbDirOf(options.agentDir), repos: options.settings.changeRepos, lines: new Lines(layout.lines, now), now });
|
|
256
|
+
writeWork(layout, work);
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
errors.push(`work items: ${error instanceof Error ? error.message : String(error)}`);
|
|
260
|
+
}
|
|
251
261
|
return { index, changes, errors };
|
|
252
262
|
}
|
|
253
263
|
export function loadRows(layout) {
|
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import { context, mark, runExtract, runReport, statusText } from "./ops.js";
|
|
|
4
4
|
import { query, VIEWS } from "./query.js";
|
|
5
5
|
const USAGE = `usage:
|
|
6
6
|
pi-evals extract [--root <dir>]... [--workers <n>] [--json]
|
|
7
|
-
pi-evals report [--out <dir>] [--since YYYY-MM-DD] [--project <key>] [--lang zh|en]
|
|
7
|
+
pi-evals report [--out <dir>] [--since YYYY-MM-DD | --days N] [--project <key>] [--lang zh|en]
|
|
8
8
|
pi-evals status
|
|
9
9
|
pi-evals query <${VIEWS.join("|")}> [--since YYYY-MM-DD] [--project <key>]
|
|
10
10
|
pi-evals mark <note>`;
|
|
@@ -50,7 +50,7 @@ async function main(argv) {
|
|
|
50
50
|
}
|
|
51
51
|
if (cmd === "report") {
|
|
52
52
|
const lang = flag(args, "--lang") === "en" ? "en" : "zh";
|
|
53
|
-
const out = runReport({ outDir: flag(args, "--out"), filter: { since: flag(args, "--since"), project: flag(args, "--project") }, lang });
|
|
53
|
+
const out = runReport({ outDir: flag(args, "--out"), filter: { since: flag(args, "--since"), days: args.includes("--days") ? Number(flag(args, "--days")) : undefined, project: flag(args, "--project") }, lang });
|
|
54
54
|
if (!out) {
|
|
55
55
|
console.error("nothing extracted yet: run pi-evals extract");
|
|
56
56
|
return 1;
|
package/dist/coverage.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { listSessionFiles } from "./extract/run.js";
|
|
2
|
-
export function coverage(roots, checkpoint, cutDays, now = Date.now()) {
|
|
2
|
+
export function coverage(roots, checkpoint, cutDays, now = Date.now(), activity) {
|
|
3
3
|
const cutoff = now - cutDays * 86_400_000;
|
|
4
4
|
const files = listSessionFiles(roots);
|
|
5
5
|
const result = {
|
|
@@ -19,6 +19,13 @@ export function coverage(roots, checkpoint, cutDays, now = Date.now()) {
|
|
|
19
19
|
const fresh = !!known && known.size === f.size && known.mtimeMs === f.mtimeMs;
|
|
20
20
|
if (fresh)
|
|
21
21
|
result.all.indexedFiles += 1;
|
|
22
|
+
if (activity) {
|
|
23
|
+
const day = new Date(f.mtimeMs).toISOString().slice(0, 10), row = activity.get(day) ?? { files: 0, indexed: 0 };
|
|
24
|
+
row.files++;
|
|
25
|
+
if (fresh)
|
|
26
|
+
row.indexed++;
|
|
27
|
+
activity.set(day, row);
|
|
28
|
+
}
|
|
22
29
|
if (f.mtimeMs >= cutoff)
|
|
23
30
|
continue;
|
|
24
31
|
result.old.files += 1;
|
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 = 4;
|
|
11
11
|
export function loadCheckpoint(file) {
|
|
12
12
|
if (!existsSync(file))
|
|
13
13
|
return { v: 1, extractor: EXTRACTOR_VERSION, files: {}, catalogs: {} };
|
package/dist/extract/session.js
CHANGED
|
@@ -10,9 +10,14 @@ import { dayOf } from "../paths.js";
|
|
|
10
10
|
import { projectKey } from "../project.js";
|
|
11
11
|
import { NAMES, record, safeName, spanId, traceId } from "../schema.js";
|
|
12
12
|
import { skillFromPath, skillsFromBlocks, skillsFromCatalog, skillsFromCommand } from "../skills.js";
|
|
13
|
+
import { WorkTracker } from "../work/track.js";
|
|
13
14
|
const UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
14
15
|
const CHILD_FILE = new RegExp(`_(${UUID})-[0-9a-f]{8}-[0-9a-f]{8}-[0-9a-f]{4}\\.jsonl$`);
|
|
15
16
|
const BRIEF_PARENT = new RegExp(`/artifacts/(${UUID})/context/`);
|
|
17
|
+
/** The subagent name in a brief path `…/context/<name>-<YYYY-MM-DDTHH-MM-SS>.md`. */
|
|
18
|
+
const BRIEF_NAME = new RegExp(`/artifacts/${UUID}/context/([A-Za-z0-9_.-]+?)-\\d{4}-\\d{2}-\\d{2}T[0-9-]+\\.md`);
|
|
19
|
+
/** Question tools: the main waits on a person while one runs. */
|
|
20
|
+
const HUMAN_WAIT = new Set(["ask_user_question", "ask_user", "secret_drop"]);
|
|
16
21
|
const ASK_TOOLS = new Set(["ask_user_question", "ask_user"]);
|
|
17
22
|
const obj = (v) => (v && typeof v === "object" ? v : {});
|
|
18
23
|
const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : 0);
|
|
@@ -48,6 +53,9 @@ export class SessionReader {
|
|
|
48
53
|
notices = {};
|
|
49
54
|
firstUser = true;
|
|
50
55
|
model;
|
|
56
|
+
childName;
|
|
57
|
+
cwd;
|
|
58
|
+
work = new WorkTracker();
|
|
51
59
|
logicalId;
|
|
52
60
|
home;
|
|
53
61
|
emit;
|
|
@@ -86,6 +94,7 @@ export class SessionReader {
|
|
|
86
94
|
if (!this.start && ts)
|
|
87
95
|
this.start = ts;
|
|
88
96
|
const kind = this.tracker.feed(entry);
|
|
97
|
+
this.work.entry(entry, ts);
|
|
89
98
|
if (type === "model_change") {
|
|
90
99
|
this.model = safeName(`${str(entry.provider) ?? "?"}/${str(entry.modelId) ?? "?"}`);
|
|
91
100
|
}
|
|
@@ -113,6 +122,9 @@ export class SessionReader {
|
|
|
113
122
|
this.sessionId = safeName(str(entry.id) ?? "");
|
|
114
123
|
this.start = str(entry.timestamp) ?? this.start;
|
|
115
124
|
this.project = safeName(projectKey(str(entry.cwd), this.home));
|
|
125
|
+
const cwd = str(entry.cwd);
|
|
126
|
+
if (cwd && safeName(cwd) === cwd)
|
|
127
|
+
this.cwd = cwd;
|
|
116
128
|
}
|
|
117
129
|
system(message) {
|
|
118
130
|
const sections = obj(message.sections);
|
|
@@ -124,9 +136,13 @@ export class SessionReader {
|
|
|
124
136
|
const text = textOf(message.content);
|
|
125
137
|
if (this.firstUser) {
|
|
126
138
|
this.firstUser = false;
|
|
127
|
-
const
|
|
139
|
+
const head = text.slice(0, 2000);
|
|
140
|
+
const parent = head.match(BRIEF_PARENT)?.[1];
|
|
128
141
|
if (parent && this.logicalId)
|
|
129
142
|
this.parentId = parent;
|
|
143
|
+
const name = head.match(BRIEF_NAME)?.[1];
|
|
144
|
+
if (name && this.logicalId)
|
|
145
|
+
this.childName = safeName(name);
|
|
130
146
|
}
|
|
131
147
|
const anchor = str(entry.id) ?? ts;
|
|
132
148
|
this.closeTrace();
|
|
@@ -179,6 +195,7 @@ export class SessionReader {
|
|
|
179
195
|
day.usage.calls += 1;
|
|
180
196
|
bump(day.models, model);
|
|
181
197
|
this.cost += u.cost;
|
|
198
|
+
this.work.assistant(ts, u.cost, message.stopReason);
|
|
182
199
|
this.tokens += num(usage.totalTokens) || u.input + u.output + u.cacheRead + u.cacheWrite;
|
|
183
200
|
if (this.traceUsage) {
|
|
184
201
|
this.traceUsage.input += u.input;
|
|
@@ -261,9 +278,23 @@ export class SessionReader {
|
|
|
261
278
|
attrs["gen_ai.request.model"] = model;
|
|
262
279
|
attrs["pi.subagent.logical_id"] = child;
|
|
263
280
|
bump(day.subagents, `${role}|${model}`);
|
|
264
|
-
if (child)
|
|
265
|
-
|
|
281
|
+
if (child) {
|
|
282
|
+
const name = str(details.name) ? safeName(details.name) : undefined;
|
|
283
|
+
const item = str(details.item) ? safeName(details.item) : undefined;
|
|
284
|
+
this.spawned.push({ id: child, role, model, name });
|
|
285
|
+
this.work.launch({ id: child, name, role, model, item, at: ts });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (!isError && call && HUMAN_WAIT.has(name))
|
|
289
|
+
this.work.wait(call.ts, ts, "human");
|
|
290
|
+
if (!isError && name === "subagent_resume" && str(details.name))
|
|
291
|
+
this.work.child(ts, String(details.name), "resume");
|
|
292
|
+
if (!isError && name === "boss_pair" && str(details.thread)) {
|
|
293
|
+
const opt = (v) => (str(v) ? safeName(v) : undefined);
|
|
294
|
+
this.work.pair({ thread: safeName(details.thread), worker: opt(details.worker), reviewer: opt(details.reviewer), item: opt(details.item), at: ts });
|
|
266
295
|
}
|
|
296
|
+
if (!isError && name === "boss_wrap")
|
|
297
|
+
this.work.wrap(ts, details.wrapped === true);
|
|
267
298
|
if (call?.monitor && !isError) {
|
|
268
299
|
const monitorId = textOf(message.content).concat(" ", str(details.summary) ?? "").match(/Monitor #(\d+)/)?.[1];
|
|
269
300
|
day.monitors.started += 1;
|
|
@@ -306,6 +337,9 @@ export class SessionReader {
|
|
|
306
337
|
for (const skill of skillsFromBlocks(textOf(entry.content)))
|
|
307
338
|
this.skillLoad(skill, "declared", ts);
|
|
308
339
|
}
|
|
340
|
+
else if (type === "subagent_result" && str(obj(entry.details).name)) {
|
|
341
|
+
this.work.child(ts, String(obj(entry.details).name), "result");
|
|
342
|
+
}
|
|
309
343
|
else if (kind) {
|
|
310
344
|
bump(this.notices, kind);
|
|
311
345
|
bump(this.day(ts).notices, kind);
|
|
@@ -417,6 +451,9 @@ export class SessionReader {
|
|
|
417
451
|
kind: this.logicalId ? "subagent" : "interactive",
|
|
418
452
|
logicalId: this.logicalId,
|
|
419
453
|
parentId: this.parentId,
|
|
454
|
+
model: this.model,
|
|
455
|
+
childName: this.childName,
|
|
456
|
+
cwd: this.cwd,
|
|
420
457
|
spawned: this.spawned,
|
|
421
458
|
cost: this.cost,
|
|
422
459
|
tokens: this.tokens,
|
|
@@ -425,6 +462,9 @@ export class SessionReader {
|
|
|
425
462
|
notices: this.notices,
|
|
426
463
|
days: this.days,
|
|
427
464
|
};
|
|
465
|
+
const work = this.work.finish(this.sessionId, !!this.logicalId);
|
|
466
|
+
if (work)
|
|
467
|
+
summary.work = work;
|
|
428
468
|
return { summary, catalog: this.catalog };
|
|
429
469
|
}
|
|
430
470
|
}
|
package/dist/findings.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { overview, readings, value, verdict } from "./report/findings.js";
|
|
3
|
+
import { words } from "./report/format.js";
|
|
4
|
+
import { safeName } from "./schema.js";
|
|
5
|
+
import { trendPair } from "./trends.js";
|
|
6
|
+
import { itemsFinding } from "./work/query.js";
|
|
7
|
+
export const scriptsDir = fileURLToPath(new URL("../scripts", import.meta.url));
|
|
8
|
+
/** Shorten only identifiers, never a verdict or its drill-down pointer. */
|
|
9
|
+
function name(s) {
|
|
10
|
+
const chars = Array.from(safeName(s));
|
|
11
|
+
if (Buffer.byteLength(chars.join("")) <= 72)
|
|
12
|
+
return chars.join("");
|
|
13
|
+
while (Buffer.byteLength(chars.join("")) > 69)
|
|
14
|
+
chars.pop();
|
|
15
|
+
return chars.join("") + "…";
|
|
16
|
+
}
|
|
17
|
+
export function findings(m) {
|
|
18
|
+
const { headline, trust, highlighted } = overview(m, "en"), L = words("en");
|
|
19
|
+
const lines = [
|
|
20
|
+
`${m.window.since ?? "?"}..${m.window.until ?? "?"} UTC${m.window.project ? ` · ${name(m.window.project)}` : ""} · ${m.freshness.stale ? "STALE: " : ""}last extract ${m.freshness.lastExtract ?? "never"} → coverage`,
|
|
21
|
+
`Scripts: ${scriptsDir}`, `${headline} → changes`, `${trust} → changes`,
|
|
22
|
+
];
|
|
23
|
+
const extras = [];
|
|
24
|
+
for (const c of highlighted) {
|
|
25
|
+
const id = c.package ? `${name(c.package)} ${name(c.to ?? "unknown")}` : c.kind;
|
|
26
|
+
const rs = readings(c, m, "en"), r = rs.find(row => row.before?.value != null && row.after?.value != null);
|
|
27
|
+
const metric = r ? `${r.label} ${value(r, "before")} → ${value(r, "after")}; ` : "";
|
|
28
|
+
const prefix = `${c.at} ${id}: `;
|
|
29
|
+
extras.push({ line: lines.length, prefix, metric });
|
|
30
|
+
lines.push(`${prefix}${verdict(c, rs, L)} → changes`);
|
|
31
|
+
}
|
|
32
|
+
const unseen = m.skills.neverLoaded.length;
|
|
33
|
+
lines.push(`${unseen}/${m.skills.offered} offered skills never loaded in range → skills`);
|
|
34
|
+
const cov = m.coverage;
|
|
35
|
+
const gate = !cov ? "not measured" : !cov.old.files ? "no old files" : cov.notIndexed.files || cov.notIndexed.bytes
|
|
36
|
+
? `blocked: ${cov.notIndexed.files}/${cov.old.files} old files not indexed` : `all ${cov.old.files} old files indexed`;
|
|
37
|
+
lines.push(`Cleanup (all projects/dates): ${gate} → coverage`);
|
|
38
|
+
const work = itemsFinding(m.work);
|
|
39
|
+
if (work)
|
|
40
|
+
lines.push(work);
|
|
41
|
+
const w = m.weekly;
|
|
42
|
+
if (!w)
|
|
43
|
+
lines.push("Need two weeks in range for error trends → packages / monitors");
|
|
44
|
+
else {
|
|
45
|
+
const p = w.packages[0];
|
|
46
|
+
lines.push(`${w.start}..${w.end} UTC, earlier week vs later: ${p ? `${p.name === "unknown" ? "tools with no known package" : name(p.name)} errors/calls ${trendPair(p)}` : "no package rise flagged"} → packages`);
|
|
47
|
+
lines.push(`Same weeks: ${w.monitors ? `failed/finished jobs ${trendPair(w.monitors)}` : "no job error rise flagged"} → monitors`);
|
|
48
|
+
}
|
|
49
|
+
for (const { line, prefix, metric } of extras) {
|
|
50
|
+
if (Buffer.byteLength(lines.join("\n") + metric) <= 1499)
|
|
51
|
+
lines[line] = prefix + metric + lines[line].slice(prefix.length);
|
|
52
|
+
}
|
|
53
|
+
return lines.join("\n");
|
|
54
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ 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
|
+
import { scriptsDir } from "./findings.js";
|
|
8
9
|
import { observe } from "./observer.js";
|
|
9
10
|
import { context, mark, reportPath, runReport, statusText } from "./ops.js";
|
|
10
11
|
import { query, VIEWS } from "./query.js";
|
|
@@ -17,12 +18,14 @@ export function cliPath() {
|
|
|
17
18
|
const found = candidates.find((p) => existsSync(p));
|
|
18
19
|
return found ? { cmd: process.execPath, args: [found] } : undefined;
|
|
19
20
|
}
|
|
20
|
-
const SUBCOMMANDS = ["status", "extract", "report", "mark"];
|
|
21
|
+
const SUBCOMMANDS = ["status", "findings", "extract", "report", "mark"];
|
|
21
22
|
function parseFlags(args) {
|
|
22
23
|
const out = { rest: [] };
|
|
23
24
|
for (let i = 0; i < args.length; i++) {
|
|
24
25
|
if (args[i] === "--since")
|
|
25
26
|
out.since = args[++i];
|
|
27
|
+
else if (args[i] === "--days")
|
|
28
|
+
out.days = Number(args[++i]);
|
|
26
29
|
else if (args[i] === "--project")
|
|
27
30
|
out.project = args[++i];
|
|
28
31
|
else
|
|
@@ -95,7 +98,7 @@ export function createEvals(options = {}) {
|
|
|
95
98
|
});
|
|
96
99
|
};
|
|
97
100
|
pi.registerCommand("evals", {
|
|
98
|
-
description: "Usage and process records: /evals [status|extract|report|mark <note>]",
|
|
101
|
+
description: "Usage and process records: /evals [status|findings|extract|report|mark <note>]",
|
|
99
102
|
getArgumentCompletions: (prefix) => {
|
|
100
103
|
const items = SUBCOMMANDS.filter((s) => s.startsWith(prefix)).map((s) => ({ value: s, label: s }));
|
|
101
104
|
return items.length ? items : null;
|
|
@@ -106,6 +109,10 @@ export function createEvals(options = {}) {
|
|
|
106
109
|
if (sub === "status") {
|
|
107
110
|
ctx.ui.notify(statusText(env), "info");
|
|
108
111
|
}
|
|
112
|
+
else if (sub === "findings") {
|
|
113
|
+
const flags = parseFlags(words.slice(1));
|
|
114
|
+
ctx.ui.notify(query("findings", { env, ...flags }), "info");
|
|
115
|
+
}
|
|
109
116
|
else if (sub === "extract") {
|
|
110
117
|
if (running) {
|
|
111
118
|
ctx.ui.notify("pi-evals: an extract is already running.", "warning");
|
|
@@ -123,7 +130,7 @@ export function createEvals(options = {}) {
|
|
|
123
130
|
}
|
|
124
131
|
else if (sub === "report") {
|
|
125
132
|
const flags = parseFlags(words.slice(1));
|
|
126
|
-
const out = runReport({ env, filter:
|
|
133
|
+
const out = runReport({ env, filter: flags });
|
|
127
134
|
ctx.ui.notify(out ? `pi-evals report: ${out.html}\nmodel: ${out.json}` : "pi-evals: nothing extracted yet; run /evals extract first.", out ? "info" : "warning");
|
|
128
135
|
}
|
|
129
136
|
else if (sub === "mark") {
|
|
@@ -143,11 +150,11 @@ export function createEvals(options = {}) {
|
|
|
143
150
|
pi.registerTool({
|
|
144
151
|
name: "evals_query",
|
|
145
152
|
label: "Evals Query",
|
|
146
|
-
description: "
|
|
147
|
-
promptSnippet: "
|
|
153
|
+
description: "Start with findings for agent activity and changes; use one detail view for counts, cost or coverage.",
|
|
154
|
+
promptSnippet: "Analyze agent activity: query findings first, then one detail view",
|
|
148
155
|
parameters: Type.Object({
|
|
149
156
|
view: Type.Unsafe({ type: "string", enum: [...VIEWS], description: "Which summary" }),
|
|
150
|
-
since: Type.Optional(Type.String({ description: "YYYY-MM-DD; default
|
|
157
|
+
since: Type.Optional(Type.String({ description: "YYYY-MM-DD; default last 30 UTC dates through extraction" })),
|
|
151
158
|
project: Type.Optional(Type.String({ description: "Project key, e.g. a repo name" })),
|
|
152
159
|
}),
|
|
153
160
|
async execute(_id, params) {
|
|
@@ -157,7 +164,7 @@ export function createEvals(options = {}) {
|
|
|
157
164
|
if (params.since && !/^\d{4}-\d{2}-\d{2}$/.test(params.since))
|
|
158
165
|
throw new Error("since must be YYYY-MM-DD.");
|
|
159
166
|
const text = query(view, { since: params.since, project: params.project, env });
|
|
160
|
-
return { content: [{ type: "text", text }], details: { view, report: reportPath(env) } };
|
|
167
|
+
return { content: [{ type: "text", text }], details: { view, scriptsDir, report: reportPath(env) } };
|
|
161
168
|
},
|
|
162
169
|
});
|
|
163
170
|
};
|
package/dist/meta.js
CHANGED
|
@@ -142,7 +142,7 @@ export const METRICS = {
|
|
|
142
142
|
label: t("Your verdict matches the automatic check", "你的判斷與自動檢查一致"),
|
|
143
143
|
meaning: t("How far the automatic check can be trusted: it is the share of sessions you labelled where you and it gave the same verdict.", "自動檢查有多可信:在你標記過的工作階段中,你和它判斷相同的比例。"),
|
|
144
144
|
goodDirection: "higher",
|
|
145
|
-
howComputed: t("Sessions where your label equals the check's label, divided by sessions you labelled for that check.", "
|
|
145
|
+
howComputed: t("Sessions where your label equals the check's label, divided by sessions you labelled pass or fail for that check; labels marked unclear are counted apart.", "你的標記與檢查結果相同的工作階段數,除以你為該檢查標成通過或未通過的工作階段數;標成「看不出來」的另外計數。"),
|
|
146
146
|
},
|
|
147
147
|
coverage: {
|
|
148
148
|
label: t("Old sessions already indexed", "已建索引的舊工作階段"),
|
|
@@ -174,6 +174,48 @@ export const METRICS = {
|
|
|
174
174
|
goodDirection: "none",
|
|
175
175
|
howComputed: t("Set when the window before starts before the first session or the window after ends after the last extract; the days with data on each side are shown.", "變更前的期間早於第一個工作階段、或變更後的期間晚於上次抽取時標記;並列出兩邊各有資料的天數。"),
|
|
176
176
|
},
|
|
177
|
+
item_cost: {
|
|
178
|
+
label: t("Cost of a work item", "一項工作的花費"),
|
|
179
|
+
meaning: t("What one todo item cost from start to close: the subagents that worked on it plus its share of the main agent.", "一項待辦從開始到收尾花了多少:做它的子代理,加上主代理分給它的部分。"),
|
|
180
|
+
goodDirection: "lower",
|
|
181
|
+
howComputed: t("Child cost is exact (every reply of each joined subagent session added up); main cost is the main's replies while the item was in progress, each split evenly among the items in progress at that moment.", "子代理費用是精確的(每個對到的子代理工作階段,每次回覆的費用加總);主代理費用取這項工作進行中時主代理的每次回覆,平均分給當下所有進行中的工作。"),
|
|
182
|
+
},
|
|
183
|
+
item_minutes: {
|
|
184
|
+
label: t("Minutes in progress", "進行中的分鐘數"),
|
|
185
|
+
meaning: t("How long the item was marked in progress; queue time before it started is not counted.", "這項工作標成「進行中」的時間;開始前排隊等待的時間不算。"),
|
|
186
|
+
goodDirection: "none",
|
|
187
|
+
howComputed: t("From each switch to in_progress to the next switch away from it, added up.", "每次切到「進行中」到下一次離開它的時間,加總。"),
|
|
188
|
+
},
|
|
189
|
+
item_stall: {
|
|
190
|
+
label: t("Stall time", "停頓時間"),
|
|
191
|
+
meaning: t("Time inside an item's window when the main agent sat idle for two minutes or more, by what woke it.", "工作進行中,主代理閒著超過兩分鐘的時間,依叫醒它的是誰分類。"),
|
|
192
|
+
goodDirection: "lower",
|
|
193
|
+
howComputed: t("A stall starts when the main ends a turn (or asks you a question) and ends at the next prompt, peer message, subagent result, timer or job ending; gaps under two minutes are left out.", "主代理結束一輪(或開始問你問題)時開始,下一個提示、其他工作階段的訊息、子代理結果、排程或背景工作結束時結束;少於兩分鐘不算。"),
|
|
194
|
+
},
|
|
195
|
+
item_per_100_lines: {
|
|
196
|
+
label: t("Cost per 100 changed lines", "每百行改動的花費"),
|
|
197
|
+
meaning: t("Cost scaled by the size of the change, so a big item and a small one can be compared.", "把花費除以改動大小,大工作和小工作才比得起來。"),
|
|
198
|
+
goodDirection: "lower",
|
|
199
|
+
howComputed: t("Item cost divided by added plus deleted lines (git) from the previous item's last evidence commit to this item's last, times 100; only items whose evidence names commits.", "工作花費除以從上一項工作最後的證據提交到這項最後的證據提交之間,git 增刪的行數,再乘 100;只算證據有記提交的工作。"),
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
export const CLOSE_KIND_META = {
|
|
203
|
+
review_done: t("Reviewer approved", "審查通過"),
|
|
204
|
+
landed: t("Car landed", "車已進站(合併)"),
|
|
205
|
+
wrap: t("Closed at a wrap", "收工時結束"),
|
|
206
|
+
evidence: t("Done with evidence", "附證據完成"),
|
|
207
|
+
unproven: t("Marked done, no evidence", "標完成,沒附證據"),
|
|
208
|
+
deleted: t("Deleted", "刪除"),
|
|
209
|
+
open: t("Still open", "還開著"),
|
|
210
|
+
};
|
|
211
|
+
export const STALL_KIND_META = {
|
|
212
|
+
human: t("waiting for you", "等你"),
|
|
213
|
+
peer: t("waiting for another session", "等其他工作階段"),
|
|
214
|
+
child: t("waiting for a subagent", "等子代理"),
|
|
215
|
+
timer: t("waiting for a timer", "等排程喚醒"),
|
|
216
|
+
ci: t("waiting for a background job", "等背景工作"),
|
|
217
|
+
device: t("waiting for another device", "等其他裝置"),
|
|
218
|
+
working: t("still working (never stopped)", "還在做(沒停下來)"),
|
|
177
219
|
};
|
|
178
220
|
export const DETECTOR_META = {
|
|
179
221
|
anchor_before_first_edit: {
|
package/dist/model.js
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
import { existsSync, readFileSync } from "node:fs";
|
|
6
6
|
import { ASK_BUCKETS, emptyDay, mergeDay } from "./aggregate.js";
|
|
7
7
|
import { DETECTORS, ERA_START } from "./detectors.js";
|
|
8
|
-
import { CHANGE_KIND_META, DETECTOR_META, METRICS, NOTICE_META } from "./meta.js";
|
|
8
|
+
import { CHANGE_KIND_META, CLOSE_KIND_META, DETECTOR_META, METRICS, NOTICE_META, STALL_KIND_META } from "./meta.js";
|
|
9
9
|
import { staticOwner } from "./owners.js";
|
|
10
|
-
import {
|
|
10
|
+
import { weeklyRises } from "./trends.js";
|
|
11
|
+
import { traceId } from "./schema.js";
|
|
12
|
+
import { workModel } from "./work/model.js";
|
|
11
13
|
export const SMALL_SAMPLE = 20;
|
|
12
14
|
/** Data older than this (hours) is reported as stale. */
|
|
13
15
|
export const STALE_HOURS = 24;
|
|
@@ -151,9 +153,9 @@ export function impactFromRows(rows, change, all, windowDays, range, ownerOf) {
|
|
|
151
153
|
confounders: kinds,
|
|
152
154
|
};
|
|
153
155
|
}
|
|
154
|
-
function labelsJoin(labelsFile, evalsFile) {
|
|
156
|
+
function labelsJoin(labelsFile, evalsFile, sessionIds) {
|
|
155
157
|
if (!existsSync(labelsFile))
|
|
156
|
-
return { present: false, n: 0, agreement: [] };
|
|
158
|
+
return { present: false, n: 0, unclear: 0, agreement: [] };
|
|
157
159
|
const codeLabels = existsSync(evalsFile) ? JSON.parse(readFileSync(evalsFile, "utf8")) : {};
|
|
158
160
|
const rows = readFileSync(labelsFile, "utf8")
|
|
159
161
|
.split("\n")
|
|
@@ -167,17 +169,29 @@ function labelsJoin(labelsFile, evalsFile) {
|
|
|
167
169
|
}
|
|
168
170
|
});
|
|
169
171
|
const by = new Map();
|
|
172
|
+
let n = 0;
|
|
173
|
+
let unclear = 0;
|
|
170
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
|
+
}
|
|
171
186
|
const code = codeLabels[row.session_id]?.[row.evaluation_name];
|
|
172
187
|
if (!code || code === "na")
|
|
173
188
|
continue;
|
|
174
|
-
const t = by.get(row.evaluation_name) ?? { n: 0, agree: 0 };
|
|
175
189
|
t.n += 1;
|
|
176
190
|
if (code === row.label)
|
|
177
191
|
t.agree += 1;
|
|
178
192
|
by.set(row.evaluation_name, t);
|
|
179
193
|
}
|
|
180
|
-
return { present: true, n
|
|
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 })) };
|
|
181
195
|
}
|
|
182
196
|
export function buildModel(options) {
|
|
183
197
|
const { index, filter } = options;
|
|
@@ -206,6 +220,11 @@ export function buildModel(options) {
|
|
|
206
220
|
const byProject = [...projectSkills.values()].sort((a, b) => b.loads - a.loads);
|
|
207
221
|
const projectRows = filter.project ? options.rows.filter((r) => r.p === filter.project) : options.rows;
|
|
208
222
|
const owner = (tool) => ownerFor(index, tool);
|
|
223
|
+
const inRange = (at) => (!filter.since || at.slice(0, 10) >= filter.since) && (!filter.until || at.slice(0, 10) <= filter.until);
|
|
224
|
+
const selected = projectRows.filter(r => inRange(r.s)), children = selected.filter(r => r.k);
|
|
225
|
+
const scoped = Boolean(filter.since || filter.until || filter.project);
|
|
226
|
+
const hasSessionIds = selected.every(r => r.id !== undefined);
|
|
227
|
+
const labelIds = scoped && existsSync(options.labelsFile) ? new Set(selected.flatMap(r => r.id ? [r.id] : [])) : undefined;
|
|
209
228
|
const calls = Object.values(total.tools).reduce((s, t) => s + t.calls, 0);
|
|
210
229
|
const errors = Object.values(total.tools).reduce((s, t) => s + t.errors, 0);
|
|
211
230
|
const tokens = total.usage.input + total.usage.output + total.usage.cacheRead + total.usage.cacheWrite;
|
|
@@ -219,13 +238,14 @@ export function buildModel(options) {
|
|
|
219
238
|
versions.set(name, list);
|
|
220
239
|
}
|
|
221
240
|
const sortedChanges = [...options.changes].sort((a, b) => a.at.localeCompare(b.at));
|
|
222
|
-
const
|
|
241
|
+
const earliest = [days[0], sortedChanges.find(c => inRange(c.at))?.at.slice(0, 10)].filter(Boolean).sort()[0];
|
|
223
242
|
return {
|
|
224
243
|
v: 1,
|
|
225
244
|
generated: now.toISOString(),
|
|
226
|
-
|
|
245
|
+
weekly: weeklyRises(index, filter.since ?? earliest, filter.project),
|
|
246
|
+
window: { since: filter.since ?? earliest ?? null, until: filter.until ?? days.at(-1) ?? null, days: days.length, project: filter.project ?? null },
|
|
227
247
|
freshness: { lastExtract: lastExtract ?? null, built: index.built, stale: ageHours > STALE_HOURS, ageHours: Number.isFinite(ageHours) ? round(ageHours, 1) : null },
|
|
228
|
-
meta: { metrics: METRICS, detectors: DETECTOR_META, notices: NOTICE_META, changeKinds: CHANGE_KIND_META },
|
|
248
|
+
meta: { metrics: METRICS, detectors: DETECTOR_META, notices: NOTICE_META, changeKinds: CHANGE_KIND_META, closeKinds: CLOSE_KIND_META, stallKinds: STALL_KIND_META },
|
|
229
249
|
totals: {
|
|
230
250
|
sessions: total.sessions,
|
|
231
251
|
subagentSessions: total.subagentSessions,
|
|
@@ -281,8 +301,8 @@ export function buildModel(options) {
|
|
|
281
301
|
costByRole: Object.entries(total.subagentCost)
|
|
282
302
|
.map(([role, cost]) => ({ role, cost: round(cost, 2) }))
|
|
283
303
|
.sort((a, b) => b.cost - a.cost),
|
|
284
|
-
linked: index.sessions.linked,
|
|
285
|
-
subagentTotal: index.sessions.subagent,
|
|
304
|
+
linked: scoped ? (children.every(r => r.linked !== undefined) ? children.filter(r => r.linked).length : null) : index.sessions.linked,
|
|
305
|
+
subagentTotal: scoped ? children.length : index.sessions.subagent,
|
|
286
306
|
},
|
|
287
307
|
process: {
|
|
288
308
|
eraStart: ERA_START,
|
|
@@ -308,10 +328,11 @@ export function buildModel(options) {
|
|
|
308
328
|
.slice(0, 25)
|
|
309
329
|
.map(({ name, cost, sessions }) => ({ skill: name, cost, sessions })),
|
|
310
330
|
},
|
|
311
|
-
changes: sortedChanges
|
|
312
|
-
.filter((c) => (
|
|
331
|
+
changes: options.comparisons?.filter(c => inRange(c.at)) ?? sortedChanges
|
|
332
|
+
.filter((c) => inRange(c.at))
|
|
313
333
|
.map((c) => ({ ...c, impact: index.range.start && c.at > index.range.start ? impactFromRows(projectRows, c, sortedChanges, options.windowDays, index.range, owner) : null })),
|
|
314
|
-
labels: labelsJoin(options.labelsFile, options.sessionEvalsFile),
|
|
334
|
+
labels: { ...labelsJoin(options.labelsFile, options.sessionEvalsFile, labelIds), needsIndex: !!labelIds && !hasSessionIds },
|
|
315
335
|
coverage: options.coverage ?? null,
|
|
336
|
+
work: workModel(options.work, filter),
|
|
316
337
|
};
|
|
317
338
|
}
|