@tangle-network/agent-eval 2.0.11 → 2.0.13
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 +31 -0
- package/dist/adapters/http.d.ts +2 -2
- package/dist/{agent-profile-_JzxgLDM.d.ts → agent-profile-8S2LfCvs.d.ts} +4 -4
- package/dist/{agent-profile-_JzxgLDM.d.ts.map → agent-profile-8S2LfCvs.d.ts.map} +1 -1
- package/dist/analyst/index.d.ts +324 -74
- package/dist/analyst/index.d.ts.map +1 -1
- package/dist/analyst/index.js +11 -161
- package/dist/analyst/index.js.map +1 -1
- package/dist/app-grade/index.d.ts +2 -2
- package/dist/app-grade/index.js +3 -3
- package/dist/{benchmark-command-CGQXNFj7.js → benchmark-command-C7ObyGm9.js} +945 -13
- package/dist/benchmark-command-C7ObyGm9.js.map +1 -0
- package/dist/benchmarks/index.d.ts +4 -4
- package/dist/benchmarks/index.js +3 -3
- package/dist/campaign/index.d.ts +6 -6
- package/dist/campaign/index.js +10 -10
- package/dist/{campaign-eus7YRs2.js → campaign-CaO2k8Jb.js} +11 -11
- package/dist/{campaign-eus7YRs2.js.map → campaign-CaO2k8Jb.js.map} +1 -1
- package/dist/{campaign-evidence-KM5GTsHG.js → campaign-evidence-71uzJMVY.js} +2 -2
- package/dist/{campaign-evidence-KM5GTsHG.js.map → campaign-evidence-71uzJMVY.js.map} +1 -1
- package/dist/{campaign-evidence-BOcX4w0r.d.ts → campaign-evidence-DcTgo4ze.d.ts} +2 -2
- package/dist/{campaign-evidence-BOcX4w0r.d.ts.map → campaign-evidence-DcTgo4ze.d.ts.map} +1 -1
- package/dist/{chat-client-Oyot5tyo.js → chat-client-TkNgQDLj.js} +2 -2
- package/dist/{chat-client-Oyot5tyo.js.map → chat-client-TkNgQDLj.js.map} +1 -1
- package/dist/{chat-json-call-DTmv2uNY.js → chat-json-call-gu3deRID.js} +2 -2
- package/dist/{chat-json-call-DTmv2uNY.js.map → chat-json-call-gu3deRID.js.map} +1 -1
- package/dist/cli.js +1371 -11
- package/dist/cli.js.map +1 -1
- package/dist/{client-DUMIaMob.d.ts → client-3sR4_h5q.d.ts} +2 -2
- package/dist/{client-DUMIaMob.d.ts.map → client-3sR4_h5q.d.ts.map} +1 -1
- package/dist/code-agent-jsonl-aPWZG3vr.js +104 -0
- package/dist/code-agent-jsonl-aPWZG3vr.js.map +1 -0
- package/dist/{completion-verifier-CCPG2Yc0.js → completion-verifier-BvPqg9Gp.js} +4 -4
- package/dist/{completion-verifier-CCPG2Yc0.js.map → completion-verifier-BvPqg9Gp.js.map} +1 -1
- package/dist/contract/index.d.ts +9 -9
- package/dist/contract/index.js +16 -112
- package/dist/contract/index.js.map +1 -1
- package/dist/{cost-ledger-C5CCidPm.js → cost-ledger-ni6f77QJ.js} +106 -50
- package/dist/cost-ledger-ni6f77QJ.js.map +1 -0
- package/dist/{decision-point-CfqtnGop.js → decision-point-CjC56Enj.js} +2 -2
- package/dist/{decision-point-CfqtnGop.js.map → decision-point-CjC56Enj.js.map} +1 -1
- package/dist/{default-registry-Rs5uzlfJ.js → default-registry-C5iSuS8e.js} +5 -5
- package/dist/{default-registry-Rs5uzlfJ.js.map → default-registry-C5iSuS8e.js.map} +1 -1
- package/dist/{default-registry-X8McMoUV.d.ts → default-registry-CVklg2e-.d.ts} +2 -2
- package/dist/{default-registry-X8McMoUV.d.ts.map → default-registry-CVklg2e-.d.ts.map} +1 -1
- package/dist/{define-agent-eval-D8ntOXqV.js → define-agent-eval-BLHr0_IP.js} +4 -4
- package/dist/{define-agent-eval-D8ntOXqV.js.map → define-agent-eval-BLHr0_IP.js.map} +1 -1
- package/dist/{define-agent-eval-DH5-xi-F.d.ts → define-agent-eval-DZ7wWMHC.d.ts} +5 -5
- package/dist/{define-agent-eval-DH5-xi-F.d.ts.map → define-agent-eval-DZ7wWMHC.d.ts.map} +1 -1
- package/dist/{dspy-rlm-engine-ChE1PUM5.js → dspy-rlm-engine-CR5MSL2k.js} +6 -5
- package/dist/{dspy-rlm-engine-ChE1PUM5.js.map → dspy-rlm-engine-CR5MSL2k.js.map} +1 -1
- package/dist/{evaluation-CjZH6gW0.d.ts → evaluation-D50Dzyce.d.ts} +2 -2
- package/dist/{evaluation-CjZH6gW0.d.ts.map → evaluation-D50Dzyce.d.ts.map} +1 -1
- package/dist/{evaluation-BAisv8ZR.js → evaluation-DqfNMaKr.js} +2 -2
- package/dist/{evaluation-BAisv8ZR.js.map → evaluation-DqfNMaKr.js.map} +1 -1
- package/dist/evaluation.d.ts +1 -1
- package/dist/evaluation.js +1 -1
- package/dist/experiment/index.d.ts +2 -2
- package/dist/experiment/index.js +1 -1
- package/dist/{external-optimizer-contracts-BFV8lnhl.js → external-optimizer-contracts-vrye9kti.js} +2 -2
- package/dist/{external-optimizer-contracts-BFV8lnhl.js.map → external-optimizer-contracts-vrye9kti.js.map} +1 -1
- package/dist/{external-optimizer-process-B6emPodQ.js → external-optimizer-process-DkOMkeHW.js} +3 -3
- package/dist/{external-optimizer-process-B6emPodQ.js.map → external-optimizer-process-DkOMkeHW.js.map} +1 -1
- package/dist/{external-optimizer-subprocess-_O06eDVA.js → external-optimizer-subprocess-CFIiwHSE.js} +3 -3
- package/dist/{external-optimizer-subprocess-_O06eDVA.js.map → external-optimizer-subprocess-CFIiwHSE.js.map} +1 -1
- package/dist/{finding-scope-B_As3F_v.js → finding-scope-BVQVcjz7.js} +2 -2
- package/dist/{finding-scope-B_As3F_v.js.map → finding-scope-BVQVcjz7.js.map} +1 -1
- package/dist/{findings-store-CvYUzQBR.js → findings-store-Drnjid7m.js} +5 -5
- package/dist/{findings-store-CvYUzQBR.js.map → findings-store-Drnjid7m.js.map} +1 -1
- package/dist/fuzz.js +1 -1
- package/dist/hosted/index.d.ts +2 -2
- package/dist/hosted/index.js +1 -1
- package/dist/{index-BmWw8zN6.d.ts → index-Bam453Y5.d.ts} +8 -8
- package/dist/{index-BmWw8zN6.d.ts.map → index-Bam453Y5.d.ts.map} +1 -1
- package/dist/{index-Cn9gB5Ca.d.ts → index-CYrvUGQl.d.ts} +206 -30
- package/dist/index-CYrvUGQl.d.ts.map +1 -0
- package/dist/{index-aRalB_Ma.d.ts → index-CxciVDt0.d.ts} +2 -2
- package/dist/{index-aRalB_Ma.d.ts.map → index-CxciVDt0.d.ts.map} +1 -1
- package/dist/{index-CCOaNmh2.d.ts → index-D1ghgNRI.d.ts} +3 -3
- package/dist/{index-CCOaNmh2.d.ts.map → index-D1ghgNRI.d.ts.map} +1 -1
- package/dist/index.d.ts +14 -14
- package/dist/index.js +471 -22
- package/dist/index.js.map +1 -1
- package/dist/{judge-gate-CpD3wmcf.js → judge-gate-WgYqQ9LA.js} +2 -2
- package/dist/{judge-gate-CpD3wmcf.js.map → judge-gate-WgYqQ9LA.js.map} +1 -1
- package/dist/{kind-factory-B-xCxG7p.js → kind-factory-C8MJpMTV.js} +2 -2
- package/dist/{kind-factory-B-xCxG7p.js.map → kind-factory-C8MJpMTV.js.map} +1 -1
- package/dist/{llm-client-Dk8lBnMh.js → llm-client-D4B1qR_1.js} +2 -2
- package/dist/{llm-client-Dk8lBnMh.js.map → llm-client-D4B1qR_1.js.map} +1 -1
- package/dist/{llm-judge-DYmEdo3M.js → llm-judge-ChGnwj4s.js} +4 -4
- package/dist/{llm-judge-DYmEdo3M.js.map → llm-judge-ChGnwj4s.js.map} +1 -1
- package/dist/{matrix-BDl7hoBr.d.ts → matrix-CAeyP9m-.d.ts} +2 -2
- package/dist/{matrix-BDl7hoBr.d.ts.map → matrix-CAeyP9m-.d.ts.map} +1 -1
- package/dist/meta-eval/index.js +2 -2
- package/dist/metrics-C6pXdupw.js +9 -0
- package/dist/metrics-C6pXdupw.js.map +1 -0
- package/dist/multishot/golden/index.d.ts +1 -1
- package/dist/multishot/index.d.ts +6 -6
- package/dist/multishot/index.js +8 -7
- package/dist/multishot/index.js.map +1 -1
- package/dist/openapi.json +1 -1
- package/dist/{optimization-method-4JlbMxd2.js → optimization-method-D2uCSc2j.js} +9 -9
- package/dist/{optimization-method-4JlbMxd2.js.map → optimization-method-D2uCSc2j.js.map} +1 -1
- package/dist/{proposal-findings-CfRFCFXS.js → proposal-findings-BCd4KjLy.js} +2 -2
- package/dist/{proposal-findings-CfRFCFXS.js.map → proposal-findings-BCd4KjLy.js.map} +1 -1
- package/dist/rl.d.ts +1 -1
- package/dist/rollout/index.d.ts +2 -2
- package/dist/rollout/index.js +1 -1
- package/dist/{rollout--rSr43Pd.js → rollout-CbHMVoDr.js} +2 -2
- package/dist/{rollout--rSr43Pd.js.map → rollout-CbHMVoDr.js.map} +1 -1
- package/dist/{run-improvement-loop-BeHu5D9Z.d.ts → run-improvement-loop-C9z817z_.d.ts} +7 -7
- package/dist/{run-improvement-loop-BeHu5D9Z.d.ts.map → run-improvement-loop-C9z817z_.d.ts.map} +1 -1
- package/dist/search/index.d.ts +3 -3
- package/dist/search/index.js +2 -2
- package/dist/{search-kernel-mZc79S6N.js → search-kernel-B1TEQ9pa.js} +2 -2
- package/dist/{search-kernel-mZc79S6N.js.map → search-kernel-B1TEQ9pa.js.map} +1 -1
- package/dist/{search-kernel-CJZ-ZSV1.d.ts → search-kernel-CZmj8gJW.d.ts} +3 -3
- package/dist/{search-kernel-CJZ-ZSV1.d.ts.map → search-kernel-CZmj8gJW.d.ts.map} +1 -1
- package/dist/{search-ledger-C7t68cmy.js → search-ledger-EjLGVZ4X.js} +25 -5
- package/dist/search-ledger-EjLGVZ4X.js.map +1 -0
- package/dist/{search-ledger-types-BhZE848w.d.ts → search-ledger-types-D4FsvPP9.d.ts} +8 -2
- package/dist/search-ledger-types-D4FsvPP9.d.ts.map +1 -0
- package/dist/{search-shipper-CmDW9dU6.js → search-shipper-DtSnRfOJ.js} +2 -2
- package/dist/{search-shipper-CmDW9dU6.js.map → search-shipper-DtSnRfOJ.js.map} +1 -1
- package/dist/{search-summary-CCgP2qXz.js → search-summary-C5fewoUi.js} +2 -2
- package/dist/{search-summary-CCgP2qXz.js.map → search-summary-C5fewoUi.js.map} +1 -1
- package/dist/{self-improve-C_Bcdmv8.js → self-improve-CQM7hIL_.js} +5 -5
- package/dist/{self-improve-C_Bcdmv8.js.map → self-improve-CQM7hIL_.js.map} +1 -1
- package/dist/{self-improve-B1fsNejr.d.ts → self-improve-Eo-EAWL8.d.ts} +7 -7
- package/dist/{self-improve-B1fsNejr.d.ts.map → self-improve-Eo-EAWL8.d.ts.map} +1 -1
- package/dist/{server-aZFmRucn.js → server-B-7vXS9T.js} +4 -4
- package/dist/{server-aZFmRucn.js.map → server-B-7vXS9T.js.map} +1 -1
- package/dist/{skillopt-optimization-method-DHk1K757.js → skillopt-optimization-method-DQ4urRij.js} +9 -9
- package/dist/{skillopt-optimization-method-DHk1K757.js.map → skillopt-optimization-method-DQ4urRij.js.map} +1 -1
- package/dist/{store-otlp-CdeW7NWq.js → store-otlp-DL30pdXE.js} +2 -2
- package/dist/{store-otlp-CdeW7NWq.js.map → store-otlp-DL30pdXE.js.map} +1 -1
- package/dist/{store-tool-spans-M3WxeRrG.d.ts → store-tool-spans-BD5Z304_.d.ts} +2 -2
- package/dist/{store-tool-spans-M3WxeRrG.d.ts.map → store-tool-spans-BD5Z304_.d.ts.map} +1 -1
- package/dist/{store-tool-spans-CVX-jfkk.js → store-tool-spans-DRdpbrnb.js} +3 -3
- package/dist/{store-tool-spans-CVX-jfkk.js.map → store-tool-spans-DRdpbrnb.js.map} +1 -1
- package/dist/{systemone-4PadCE4C.d.ts → systemone-D7FQ7n00.d.ts} +3 -3
- package/dist/{systemone-4PadCE4C.d.ts.map → systemone-D7FQ7n00.d.ts.map} +1 -1
- package/dist/systemone.d.ts +2 -2
- package/dist/systemone.js +2 -2
- package/dist/traces.d.ts +1 -1
- package/dist/traces.js +3 -3
- package/dist/{tree-CiIe-f3f.js → tree-CljLPWVm.js} +3 -3
- package/dist/{tree-CiIe-f3f.js.map → tree-CljLPWVm.js.map} +1 -1
- package/dist/{types-D5XtEH9Q.d.ts → types-BtWzceBY.d.ts} +17 -2
- package/dist/types-BtWzceBY.d.ts.map +1 -0
- package/dist/{types-Bte3EsFQ.d.ts → types-XxFZ2IAT.d.ts} +2 -2
- package/dist/{types-Bte3EsFQ.d.ts.map → types-XxFZ2IAT.d.ts.map} +1 -1
- package/dist/wire/index.js +1 -1
- package/docs/feature-guide.md +2 -0
- package/docs/public-api.md +16 -10
- package/docs/search-ledger.md +1 -1
- package/docs/skill-eval.md +110 -0
- package/package.json +4 -2
- package/dist/benchmark-command-CGQXNFj7.js.map +0 -1
- package/dist/cost-ledger-C5CCidPm.js.map +0 -1
- package/dist/index-Cn9gB5Ca.d.ts.map +0 -1
- package/dist/search-ledger-C7t68cmy.js.map +0 -1
- package/dist/search-ledger-types-BhZE848w.d.ts.map +0 -1
- package/dist/types-D5XtEH9Q.d.ts.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,21 +1,272 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { c as errorMessage } from "./errors-DeEEV9Vx.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
2
|
+
import { c as errorMessage, s as ValidationError } from "./errors-DeEEV9Vx.js";
|
|
3
|
+
import { l as costForTokenPricing } from "./cost-ledger-ni6f77QJ.js";
|
|
4
|
+
import { i as replaySearchLedgerText } from "./search-ledger-EjLGVZ4X.js";
|
|
5
|
+
import { o as operatorYield, s as INSUFFICIENT_FROM } from "./search-kernel-B1TEQ9pa.js";
|
|
6
|
+
import { t as renderSearchSummary } from "./search-summary-C5fewoUi.js";
|
|
7
|
+
import { l as SEARCH_LEDGER_BATCH_MAX_BYTES, m as SearchRunKindSchema, r as shipSearchLedger, s as hostedTenantFromEnv, t as SearchShipConflictError } from "./search-shipper-DtSnRfOJ.js";
|
|
8
|
+
import { n as createChatClient } from "./chat-client-TkNgQDLj.js";
|
|
8
9
|
import { a as privacyHit, f as appendRolloutLines, n as runRolloutReleaseCli, r as PRIVACY_RULE_NAMES, u as gateReceiptRolloutLines } from "./hf-dataset-B0s2ZAhQ.js";
|
|
9
10
|
import { i as harnessSessionRolloutLines, n as harnessSessionRefs } from "./harness-session-lines-CTh1-uOb.js";
|
|
10
|
-
import { t as runAnalystBenchmarkCommand } from "./benchmark-command-
|
|
11
|
-
import { i as buildOpenApi, l as handleVersion, o as runRpcBatch, r as startServerAsync, s as runRpcOnce } from "./server-
|
|
12
|
-
import { b as editCreditText, f as landscape, g as surfaceTextEdits, l as metaSearch, m as formatLandscape, n as taskMatrix, o as skillManifold, r as formatSkillManifold, s as renderMetaSearchText, t as tree, v as front, y as editCredit } from "./tree-
|
|
11
|
+
import { B as renderSkillUsageTable, H as claudeCodeSkillSessions, L as afterInvocation, R as buildSkillUsageReport, V as codexSkillSessions, W as readSkillFile, t as runAnalystBenchmarkCommand, z as instant } from "./benchmark-command-C7ObyGm9.js";
|
|
12
|
+
import { i as buildOpenApi, l as handleVersion, o as runRpcBatch, r as startServerAsync, s as runRpcOnce } from "./server-B-7vXS9T.js";
|
|
13
|
+
import { b as editCreditText, f as landscape, g as surfaceTextEdits, l as metaSearch, m as formatLandscape, n as taskMatrix, o as skillManifold, r as formatSkillManifold, s as renderMetaSearchText, t as tree, v as front, y as editCredit } from "./tree-CljLPWVm.js";
|
|
13
14
|
import { a as analyzeSupervisorRun, i as renderSupervisorRunMarkdown, r as renderSupervisorRunHeadline, t as runtimeRunRolloutLines } from "./runtime-rollouts-CE0MbQPq.js";
|
|
14
15
|
import { createHash } from "node:crypto";
|
|
15
16
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
16
17
|
import { dirname, join, resolve } from "node:path";
|
|
17
|
-
import { fileURLToPath } from "node:url";
|
|
18
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
18
19
|
import { appendFile, open, readFile, rm, stat } from "node:fs/promises";
|
|
20
|
+
// src/skill-usage/change-ledger.ts
|
|
21
|
+
/**
|
|
22
|
+
* The change ledger: one row per commit or pull request a session made, written
|
|
23
|
+
* by the session's own harness at the moment the call returned, and the reader
|
|
24
|
+
* that joins those rows to recorded sessions.
|
|
25
|
+
*
|
|
26
|
+
* A transcript names a pull request only when its output prints the URL, and
|
|
27
|
+
* names no commit. The ledger is the harness's own record: each row carries the
|
|
28
|
+
* tool call's id, so a change belongs to the typed turn whose span holds the
|
|
29
|
+
* call, and the session's own commits and merges are counted, not guessed from
|
|
30
|
+
* output text.
|
|
31
|
+
*
|
|
32
|
+
* Row format (JSON lines, `v` 1; a writer adds no other field the reader needs):
|
|
33
|
+
*
|
|
34
|
+
* | Field | Meaning |
|
|
35
|
+
* |---|---|
|
|
36
|
+
* | `at` | ISO time the call returned |
|
|
37
|
+
* | `harness` | the harness that wrote it, as the session reader names it (`claude-code`) |
|
|
38
|
+
* | `sessionId`, `agentId` | the session; inside a subagent, the subagent's id too (the id its own transcript carries) |
|
|
39
|
+
* | `toolUseId` | the id of the tool call that made the change; null when the harness gave none |
|
|
40
|
+
* | `action` | `commit`, `pr-create`, `pr-merge`, `observed`, or, from a writer that sees whole turns, `turn` and `push` |
|
|
41
|
+
* | `remote` | the repository as `owner/repo` (or `host/path`); null when the writer could not find it |
|
|
42
|
+
* | `sha`, `pr` | the commit or the pull request number; null when the call did not name it |
|
|
43
|
+
*
|
|
44
|
+
* `observed` is written once per session or subagent, at its first call. It says
|
|
45
|
+
* the writer was running, which is the only thing that lets "no change rows"
|
|
46
|
+
* mean "no change". A session with no row of any action is unknown, never none.
|
|
47
|
+
*
|
|
48
|
+
* A writer outside the harness, such as a gateway that runs the harness for a
|
|
49
|
+
* caller (CLI Bridge), sees turns, not tool calls, and adds fields to its rows:
|
|
50
|
+
*
|
|
51
|
+
* | Field | Meaning |
|
|
52
|
+
* |---|---|
|
|
53
|
+
* | `sessionId` | the gateway's session id |
|
|
54
|
+
* | `nativeSessionId` | the harness's own session id, the id its transcript carries; rows are keyed by it when present |
|
|
55
|
+
* | `turnId`, `runId` | the gateway's turn and run |
|
|
56
|
+
* | `turnStartedAt` | ISO time the turn began; with `at`, the window the change was made in |
|
|
57
|
+
* | `incomplete` | on a `turn` row: why that turn's change rows may not be all of its changes (a checkout shared with another running turn, an unread pull request list); null when they are |
|
|
58
|
+
* | `headBefore`, `head` | on a `turn` row: the working repository's HEAD when the turn began and when it ended |
|
|
59
|
+
* | `branch` | on a `push` row: the remote branch the turn pushed |
|
|
60
|
+
*
|
|
61
|
+
* Such a row has no `toolUseId`. The change belongs to the last tool call of the
|
|
62
|
+
* session record whose time lies in [`turnStartedAt`, `at`], so a record with no
|
|
63
|
+
* times, or none in the window, leaves the change unplaced. A `turn` row with a
|
|
64
|
+
* non-null `incomplete` makes the session's changes unknown, with a gap that says why.
|
|
65
|
+
*
|
|
66
|
+
* A row's `toolUseId` is the id the harness's hook saw. Where the session record
|
|
67
|
+
* holds the call under that id, or names it in `callAliases`, the change belongs
|
|
68
|
+
* to the turn that made the call. A row that matches neither makes the whole
|
|
69
|
+
* session unknown, with a gap that says so: the change happened, and which turn
|
|
70
|
+
* made it cannot be said, so no turn may be called change-free.
|
|
71
|
+
*/
|
|
72
|
+
const CHANGE_LEDGER_ACTIONS = [
|
|
73
|
+
"observed",
|
|
74
|
+
"commit",
|
|
75
|
+
"pr-create",
|
|
76
|
+
"pr-merge",
|
|
77
|
+
"turn",
|
|
78
|
+
"push"
|
|
79
|
+
];
|
|
80
|
+
const key = (harness, id) => `${harness}\u0000${id}`;
|
|
81
|
+
function parseRow(line) {
|
|
82
|
+
let value;
|
|
83
|
+
try {
|
|
84
|
+
value = JSON.parse(line);
|
|
85
|
+
} catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if (typeof value !== "object" || value === null) return null;
|
|
89
|
+
const row = value;
|
|
90
|
+
const text = (field) => {
|
|
91
|
+
const raw = row[field];
|
|
92
|
+
return typeof raw === "string" && raw !== "" ? raw : null;
|
|
93
|
+
};
|
|
94
|
+
const optional = (field) => {
|
|
95
|
+
const raw = row[field];
|
|
96
|
+
if (raw === null || raw === void 0) return null;
|
|
97
|
+
return typeof raw === "string" && raw !== "" ? raw : void 0;
|
|
98
|
+
};
|
|
99
|
+
const action = row.action;
|
|
100
|
+
const toolUseId = optional("toolUseId");
|
|
101
|
+
const agentId = optional("agentId");
|
|
102
|
+
const remote = optional("remote");
|
|
103
|
+
const sha = optional("sha");
|
|
104
|
+
const nativeSessionId = optional("nativeSessionId");
|
|
105
|
+
const turnStartedAt = optional("turnStartedAt");
|
|
106
|
+
const incomplete = optional("incomplete");
|
|
107
|
+
const pr = row.pr ?? null;
|
|
108
|
+
const at = text("at");
|
|
109
|
+
const harness = text("harness");
|
|
110
|
+
const sessionId = text("sessionId");
|
|
111
|
+
if (row.v !== 1 || at === null || harness === null || sessionId === null || !CHANGE_LEDGER_ACTIONS.includes(action) || toolUseId === void 0 || agentId === void 0 || remote === void 0 || sha === void 0 || nativeSessionId === void 0 || turnStartedAt === void 0 || incomplete === void 0 || pr !== null && !(typeof pr === "number" && Number.isInteger(pr) && pr > 0)) return null;
|
|
112
|
+
return {
|
|
113
|
+
v: 1,
|
|
114
|
+
at,
|
|
115
|
+
harness,
|
|
116
|
+
sessionId,
|
|
117
|
+
agentId,
|
|
118
|
+
toolUseId,
|
|
119
|
+
action,
|
|
120
|
+
remote,
|
|
121
|
+
sha,
|
|
122
|
+
pr,
|
|
123
|
+
nativeSessionId,
|
|
124
|
+
turnStartedAt,
|
|
125
|
+
incomplete
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/** The reference the registry's outcome source names a change by: `owner/repo#123` or `owner/repo@<sha>`. */
|
|
129
|
+
function refOf(row) {
|
|
130
|
+
if (row.remote === null) return null;
|
|
131
|
+
if (row.action === "commit") return row.sha === null ? null : `${row.remote}@${row.sha}`;
|
|
132
|
+
if (row.action === "pr-create" || row.action === "pr-merge") return row.pr === null ? null : `${row.remote}#${row.pr}`;
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
/** Read ledger text. A line that is not a row is counted, not skipped silently, and no row is guessed from it. */
|
|
136
|
+
function parseChangeLedger(text) {
|
|
137
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
138
|
+
let rows = 0;
|
|
139
|
+
let malformed = 0;
|
|
140
|
+
for (const line of text.split("\n")) {
|
|
141
|
+
if (line.trim() === "") continue;
|
|
142
|
+
const row = parseRow(line);
|
|
143
|
+
if (row === null) {
|
|
144
|
+
malformed += 1;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
rows += 1;
|
|
148
|
+
const id = key(row.harness, row.agentId ?? row.nativeSessionId ?? row.sessionId);
|
|
149
|
+
let session = sessions.get(id);
|
|
150
|
+
if (session === void 0) {
|
|
151
|
+
session = {
|
|
152
|
+
observed: false,
|
|
153
|
+
changes: [],
|
|
154
|
+
unnamed: 0,
|
|
155
|
+
timed: [],
|
|
156
|
+
incomplete: /* @__PURE__ */ new Map()
|
|
157
|
+
};
|
|
158
|
+
sessions.set(id, session);
|
|
159
|
+
}
|
|
160
|
+
if (row.action === "observed" || row.action === "push") {
|
|
161
|
+
session.observed = true;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (row.action === "turn") {
|
|
165
|
+
session.observed = true;
|
|
166
|
+
if (row.incomplete) session.incomplete.set(row.incomplete, (session.incomplete.get(row.incomplete) ?? 0) + 1);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
session.observed = true;
|
|
170
|
+
const ref = refOf(row);
|
|
171
|
+
if (ref === null) session.unnamed += 1;
|
|
172
|
+
else if (row.toolUseId === null && row.turnStartedAt) session.timed.push({
|
|
173
|
+
ref,
|
|
174
|
+
from: row.turnStartedAt,
|
|
175
|
+
to: row.at
|
|
176
|
+
});
|
|
177
|
+
else session.changes.push({
|
|
178
|
+
ref,
|
|
179
|
+
callId: row.toolUseId ?? "",
|
|
180
|
+
at: row.at
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
sessions,
|
|
185
|
+
rows,
|
|
186
|
+
malformed
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/** Read one or more ledger files as one ledger. A file that cannot be read throws: a missing ledger is not an empty one. */
|
|
190
|
+
async function readChangeLedger(paths) {
|
|
191
|
+
const texts = [];
|
|
192
|
+
for (const path of paths) try {
|
|
193
|
+
texts.push(await readFile(path, "utf8"));
|
|
194
|
+
} catch (error) {
|
|
195
|
+
throw new ValidationError(`readChangeLedger: cannot read ${path}: ${errorMessage(error)}`);
|
|
196
|
+
}
|
|
197
|
+
return parseChangeLedger(texts.join("\n"));
|
|
198
|
+
}
|
|
199
|
+
/** The last tool call or skill call of the record whose time lies in [from, to]; null when there is none. */
|
|
200
|
+
function callInWindow(record, from, to) {
|
|
201
|
+
const start = Date.parse(from);
|
|
202
|
+
const end = Date.parse(to);
|
|
203
|
+
if (!Number.isFinite(start) || !Number.isFinite(end)) return null;
|
|
204
|
+
let found = null;
|
|
205
|
+
for (const event of record.events) {
|
|
206
|
+
if (event.kind === "model" || event.at === null) continue;
|
|
207
|
+
const at = Date.parse(event.at);
|
|
208
|
+
if (at >= start && at <= end) found = event.kind === "tool" ? event.id : event.callId;
|
|
209
|
+
}
|
|
210
|
+
return found;
|
|
211
|
+
}
|
|
212
|
+
function joinRead(read, ledger) {
|
|
213
|
+
if (!read.succeeded) return read;
|
|
214
|
+
const { value } = read;
|
|
215
|
+
const held = ledger.sessions.get(key(value.harness, value.sessionId));
|
|
216
|
+
const seen = /* @__PURE__ */ new Set();
|
|
217
|
+
const changes = [];
|
|
218
|
+
const aliases = value.callAliases ?? {};
|
|
219
|
+
const placeable = new Set(value.events.flatMap((event) => event.kind === "tool" ? [event.id] : event.kind === "skill" ? [event.callId] : []));
|
|
220
|
+
let unplaced = 0;
|
|
221
|
+
const timed = [];
|
|
222
|
+
for (const change of held?.timed ?? []) {
|
|
223
|
+
const callId = callInWindow(value, change.from, change.to);
|
|
224
|
+
if (callId === null) unplaced += 1;
|
|
225
|
+
else timed.push({
|
|
226
|
+
ref: change.ref,
|
|
227
|
+
callId,
|
|
228
|
+
at: change.to
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
for (const row of [
|
|
232
|
+
...value.changes ?? [],
|
|
233
|
+
...held?.changes ?? [],
|
|
234
|
+
...timed
|
|
235
|
+
]) {
|
|
236
|
+
const change = Object.hasOwn(aliases, row.callId) ? {
|
|
237
|
+
...row,
|
|
238
|
+
callId: aliases[row.callId]
|
|
239
|
+
} : row;
|
|
240
|
+
if (!placeable.has(change.callId)) unplaced += 1;
|
|
241
|
+
const id = `${change.ref}\u0000${change.callId}`;
|
|
242
|
+
if (seen.has(id)) continue;
|
|
243
|
+
seen.add(id);
|
|
244
|
+
changes.push(change);
|
|
245
|
+
}
|
|
246
|
+
const gaps = [...value.gaps];
|
|
247
|
+
if (held !== void 0 && held.unnamed > 0) gaps.push(`${held.unnamed} changes the change ledger recorded could not be named (no repository, or no commit or pull request number)`);
|
|
248
|
+
if (unplaced > 0) gaps.push(`${unplaced} changes name a tool call this session record does not hold, so the turn that made them is unknown and no turn is reported as having made none`);
|
|
249
|
+
const { changes: _transcriptChanges, ...rest } = value;
|
|
250
|
+
const incomplete = [...held?.incomplete ?? []];
|
|
251
|
+
if (incomplete.length > 0) gaps.push(`the change ledger's writer said some turns' changes may be incomplete (${incomplete.map(([why, n]) => `${why}: ${n}`).join(", ")}), so the session's changes are unknown`);
|
|
252
|
+
const known = unplaced === 0 && incomplete.length === 0 && (held?.observed === true || changes.length > 0);
|
|
253
|
+
return {
|
|
254
|
+
...read,
|
|
255
|
+
value: {
|
|
256
|
+
...rest,
|
|
257
|
+
gaps,
|
|
258
|
+
...known ? { changes } : {}
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* The sessions of `source` with their changes taken from the ledger as well as
|
|
264
|
+
* from the transcript. A session the ledger never observed keeps only the
|
|
265
|
+
* changes its transcript shows, and has none recorded when it shows none.
|
|
266
|
+
*/
|
|
267
|
+
async function* withChangeLedger(source, ledger) {
|
|
268
|
+
for await (const read of source) yield joinRead(read, ledger);
|
|
269
|
+
}
|
|
19
270
|
// src/cli-config.ts
|
|
20
271
|
/**
|
|
21
272
|
* Provider configuration for the `agent-eval` binary.
|
|
@@ -84,6 +335,1098 @@ function nonEmpty(value) {
|
|
|
84
335
|
const trimmed = value?.trim();
|
|
85
336
|
return trimmed ? trimmed : void 0;
|
|
86
337
|
}
|
|
338
|
+
// src/skill-usage/command.ts
|
|
339
|
+
/**
|
|
340
|
+
* `agent-eval skill-usage <sessions-dir>` reads a directory of Claude Code
|
|
341
|
+
* transcripts (or, with `--harness codex`, Codex rollouts) and prints the
|
|
342
|
+
* skill-usage report.
|
|
343
|
+
*
|
|
344
|
+
* By default the JSON report goes to stdout and the short table to stderr, so
|
|
345
|
+
* `> report.json` keeps the report while the table stays on the terminal.
|
|
346
|
+
*
|
|
347
|
+
* `--pricing <file>` names a JSON object of per-million rates by model id, for a
|
|
348
|
+
* model the cost ledger has no rate for or prices too coarsely (its table has no
|
|
349
|
+
* cache-read rate).
|
|
350
|
+
*
|
|
351
|
+
* Exit codes follow the other self-parsing subcommands: 2 for a usage error, 1
|
|
352
|
+
* when the directory cannot be read, 0 after the report was written.
|
|
353
|
+
*/
|
|
354
|
+
const FORMATS$2 = [
|
|
355
|
+
"both",
|
|
356
|
+
"json",
|
|
357
|
+
"table"
|
|
358
|
+
];
|
|
359
|
+
const USAGE$2 = "usage: agent-eval skill-usage <sessions-dir> [--harness claude-code|codex] [--since <7d|36h|90m|ISO time>] [--format both|json|table] [--limit <rows>] [--pricing <rates.json>]";
|
|
360
|
+
const PROCESS_IO$2 = {
|
|
361
|
+
stdout: (text) => {
|
|
362
|
+
process.stdout.write(text);
|
|
363
|
+
},
|
|
364
|
+
stderr: (text) => {
|
|
365
|
+
process.stderr.write(text);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
/** The harnesses whose session stores the commands read. */
|
|
369
|
+
const SESSION_HARNESSES = ["claude-code", "codex"];
|
|
370
|
+
/** The sessions under a harness's store: Claude Code's projects directory, or Codex's sessions directory. */
|
|
371
|
+
function harnessSkillSessions(harness, directory, options) {
|
|
372
|
+
return harness === "codex" ? codexSkillSessions(directory, options) : claudeCodeSkillSessions(directory, options);
|
|
373
|
+
}
|
|
374
|
+
/** The value of `--harness`, checked. */
|
|
375
|
+
function parseHarness(raw) {
|
|
376
|
+
if (!SESSION_HARNESSES.includes(raw)) throw new Error(`--harness expects one of ${SESSION_HARNESSES.join("|")}, got ${JSON.stringify(raw)}`);
|
|
377
|
+
return raw;
|
|
378
|
+
}
|
|
379
|
+
const DURATION = /^(\d+(?:\.\d+)?)([dhm])$/;
|
|
380
|
+
const UNIT_MS = {
|
|
381
|
+
d: 864e5,
|
|
382
|
+
h: 36e5,
|
|
383
|
+
m: 6e4
|
|
384
|
+
};
|
|
385
|
+
/** `7d`, `36h` or `90m` back from `nowMs`, or an ISO instant. */
|
|
386
|
+
function parseSince(raw, nowMs) {
|
|
387
|
+
const duration = DURATION.exec(raw);
|
|
388
|
+
if (duration !== null) return nowMs - Number(duration[1]) * UNIT_MS[duration[2]];
|
|
389
|
+
const at = Date.parse(raw);
|
|
390
|
+
if (!Number.isFinite(at)) throw new Error(`--since expects a duration such as 7d or an ISO time, got ${JSON.stringify(raw)}`);
|
|
391
|
+
return at;
|
|
392
|
+
}
|
|
393
|
+
function parseArgs$3(argv) {
|
|
394
|
+
const args = {
|
|
395
|
+
directory: "",
|
|
396
|
+
harness: "claude-code",
|
|
397
|
+
since: null,
|
|
398
|
+
format: "both",
|
|
399
|
+
limit: 30,
|
|
400
|
+
pricing: null
|
|
401
|
+
};
|
|
402
|
+
const value = (flag, index) => {
|
|
403
|
+
const raw = argv[index];
|
|
404
|
+
if (raw === void 0) throw new Error(`${flag} expects a value`);
|
|
405
|
+
return raw;
|
|
406
|
+
};
|
|
407
|
+
for (let i = 0; i < argv.length; i++) {
|
|
408
|
+
const arg = argv[i];
|
|
409
|
+
if (arg === "--harness") args.harness = parseHarness(value(arg, ++i));
|
|
410
|
+
else if (arg === "--since") args.since = value(arg, ++i);
|
|
411
|
+
else if (arg === "--format") {
|
|
412
|
+
const raw = value(arg, ++i);
|
|
413
|
+
if (!FORMATS$2.includes(raw)) throw new Error(`--format expects one of ${FORMATS$2.join("|")}, got ${JSON.stringify(raw)}`);
|
|
414
|
+
args.format = raw;
|
|
415
|
+
} else if (arg === "--limit") {
|
|
416
|
+
const raw = Number(value(arg, ++i));
|
|
417
|
+
if (!Number.isInteger(raw) || raw < 1) throw new Error("--limit expects a positive integer");
|
|
418
|
+
args.limit = raw;
|
|
419
|
+
} else if (arg === "--pricing") args.pricing = value(arg, ++i);
|
|
420
|
+
else if (arg.startsWith("--")) throw new Error(`unknown flag "${arg}"`);
|
|
421
|
+
else if (args.directory === "") args.directory = arg;
|
|
422
|
+
else throw new Error(`unexpected argument "${arg}"`);
|
|
423
|
+
}
|
|
424
|
+
if (args.directory === "") throw new Error("a transcripts directory is required");
|
|
425
|
+
return args;
|
|
426
|
+
}
|
|
427
|
+
const RATE_FIELDS = [
|
|
428
|
+
"inputUsdPerMillion",
|
|
429
|
+
"cachedInputUsdPerMillion",
|
|
430
|
+
"cacheWriteUsdPerMillion",
|
|
431
|
+
"outputUsdPerMillion"
|
|
432
|
+
];
|
|
433
|
+
/** A rates file: `{ "<model id>": { inputUsdPerMillion, outputUsdPerMillion, ... } }`. */
|
|
434
|
+
function readPricingFile(path) {
|
|
435
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
436
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error(`--pricing ${path}: expected a JSON object of rates by model id`);
|
|
437
|
+
const rates = /* @__PURE__ */ new Map();
|
|
438
|
+
for (const [model, value] of Object.entries(parsed)) {
|
|
439
|
+
const fields = typeof value === "object" && value !== null ? value : {};
|
|
440
|
+
for (const field of RATE_FIELDS) {
|
|
441
|
+
const rate = fields[field];
|
|
442
|
+
if (typeof rate !== "number" && (field === "inputUsdPerMillion" || field === "outputUsdPerMillion" || rate !== void 0)) throw new Error(`--pricing ${path}: ${JSON.stringify(model)}.${field} must be a number`);
|
|
443
|
+
}
|
|
444
|
+
const pricing = fields;
|
|
445
|
+
costForTokenPricing(pricing, {
|
|
446
|
+
inputTokens: 0,
|
|
447
|
+
outputTokens: 0
|
|
448
|
+
});
|
|
449
|
+
rates.set(model, pricing);
|
|
450
|
+
}
|
|
451
|
+
return rates;
|
|
452
|
+
}
|
|
453
|
+
async function runSkillUsageCommand(argv, io = PROCESS_IO$2) {
|
|
454
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
455
|
+
io.stdout(`${USAGE$2}\n`);
|
|
456
|
+
return 0;
|
|
457
|
+
}
|
|
458
|
+
let args;
|
|
459
|
+
let sinceMs;
|
|
460
|
+
let rates;
|
|
461
|
+
try {
|
|
462
|
+
args = parseArgs$3(argv);
|
|
463
|
+
rates = args.pricing === null ? void 0 : readPricingFile(resolve(args.pricing));
|
|
464
|
+
sinceMs = args.since === null ? void 0 : parseSince(args.since, (io.now ?? Date.now)());
|
|
465
|
+
} catch (error) {
|
|
466
|
+
io.stderr(`${errorMessage(error)}\n${USAGE$2}\n`);
|
|
467
|
+
return 2;
|
|
468
|
+
}
|
|
469
|
+
try {
|
|
470
|
+
const report = await buildSkillUsageReport(harnessSkillSessions(args.harness, resolve(args.directory), sinceMs === void 0 ? {} : { sinceMs }), {
|
|
471
|
+
...sinceMs === void 0 ? {} : { sinceMs },
|
|
472
|
+
...rates === void 0 ? {} : { pricing: (model) => rates?.get(model) },
|
|
473
|
+
readSkillFile
|
|
474
|
+
});
|
|
475
|
+
const table = renderSkillUsageTable(report, args.limit);
|
|
476
|
+
if (args.format === "table") io.stdout(table);
|
|
477
|
+
else {
|
|
478
|
+
io.stdout(`${JSON.stringify(report, null, 2)}\n`);
|
|
479
|
+
if (args.format === "both") io.stderr(table);
|
|
480
|
+
}
|
|
481
|
+
return 0;
|
|
482
|
+
} catch (error) {
|
|
483
|
+
io.stderr(`agent-eval skill-usage: ${errorMessage(error)}\n`);
|
|
484
|
+
return 1;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
// src/intent-record/derive.ts
|
|
488
|
+
/**
|
|
489
|
+
* Intent records from recorded sessions.
|
|
490
|
+
*
|
|
491
|
+
* A session's typed turns are cut into intents. A turn that a labeler calls a
|
|
492
|
+
* correction or a re-ask attaches to the intent already open; any other turn
|
|
493
|
+
* opens a new one and closes the open one. A turn nobody labeled opens a new
|
|
494
|
+
* intent, and the intent it closes then cannot say how many corrections it
|
|
495
|
+
* drew. The span of an intent runs from its opening turn to the turn that
|
|
496
|
+
* closes it, or to the session's end, and its cost and procedures are those of
|
|
497
|
+
* the events in that span.
|
|
498
|
+
*/
|
|
499
|
+
const sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
500
|
+
function isCorrection(label) {
|
|
501
|
+
if (label === null) return null;
|
|
502
|
+
if (label.kind === "correction") return true;
|
|
503
|
+
return label.correction;
|
|
504
|
+
}
|
|
505
|
+
function cost(session, thread, options) {
|
|
506
|
+
const after = afterInvocation(session, thread.startEvent - 1, thread.startAt, options, {
|
|
507
|
+
eventIndex: thread.endEvent,
|
|
508
|
+
at: thread.endAt
|
|
509
|
+
});
|
|
510
|
+
return {
|
|
511
|
+
tokens: after.modelCalls > 0 && after.modelCallsWithoutUsage === 0 ? after.tokens.total : null,
|
|
512
|
+
usd: after.pricedModelCalls > 0 && after.unpricedModelCalls === 0 ? after.costUsd : null,
|
|
513
|
+
wallMs: after.wallMs,
|
|
514
|
+
modelCalls: after.modelCalls
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
function refsInSpan(session, from, to) {
|
|
518
|
+
if (session.changes === void 0) return void 0;
|
|
519
|
+
const position = /* @__PURE__ */ new Map();
|
|
520
|
+
session.events.forEach((event, index) => {
|
|
521
|
+
if (event.kind === "tool") position.set(event.id, index);
|
|
522
|
+
else if (event.kind === "skill") position.set(event.callId, index);
|
|
523
|
+
});
|
|
524
|
+
const refs = /* @__PURE__ */ new Set();
|
|
525
|
+
for (const change of session.changes) {
|
|
526
|
+
const index = position.get(change.callId);
|
|
527
|
+
if (index !== void 0 && index >= from && index < to) refs.add(change.ref);
|
|
528
|
+
}
|
|
529
|
+
return [...refs].sort();
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Cut one session's typed turns into intents. Returns none when the reader
|
|
533
|
+
* records no typed turns, and the caller counts that session apart.
|
|
534
|
+
*/
|
|
535
|
+
async function deriveSessionIntents(session, labeler, options, ignore) {
|
|
536
|
+
if (session.turns === void 0) return null;
|
|
537
|
+
const threads = [];
|
|
538
|
+
let open = null;
|
|
539
|
+
let previousText = null;
|
|
540
|
+
const close = (thread, by, at, event) => {
|
|
541
|
+
thread.closedBy = by;
|
|
542
|
+
thread.endAt = at;
|
|
543
|
+
thread.endEvent = event;
|
|
544
|
+
};
|
|
545
|
+
for (const [index, turn] of session.turns.entries()) {
|
|
546
|
+
if (options.sinceMs !== void 0) {
|
|
547
|
+
const at = instant(turn.at);
|
|
548
|
+
if (at === null || at < options.sinceMs) continue;
|
|
549
|
+
}
|
|
550
|
+
const context = {
|
|
551
|
+
harness: session.harness,
|
|
552
|
+
sessionId: session.sessionId,
|
|
553
|
+
index,
|
|
554
|
+
at: turn.at,
|
|
555
|
+
text: turn.text,
|
|
556
|
+
previousText
|
|
557
|
+
};
|
|
558
|
+
if (ignore?.(context) === true) continue;
|
|
559
|
+
const label = labeler === void 0 ? null : await labeler(context);
|
|
560
|
+
previousText = turn.text;
|
|
561
|
+
const correction = isCorrection(label);
|
|
562
|
+
const reask = label === null ? null : label.reask;
|
|
563
|
+
const attaches = open !== null && (correction === true || reask === true);
|
|
564
|
+
if (open !== null) {
|
|
565
|
+
if (correction === null) open.correctionsKnown = false;
|
|
566
|
+
else if (correction) open.corrections += 1;
|
|
567
|
+
if (reask === null) open.reasksKnown = false;
|
|
568
|
+
else if (reask) open.reasks += 1;
|
|
569
|
+
}
|
|
570
|
+
if (attaches && open !== null) {
|
|
571
|
+
open.userTurns += 1;
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
if (open !== null) close(open, "next-intent", turn.at, turn.eventIndex);
|
|
575
|
+
open = {
|
|
576
|
+
openedAtIndex: index,
|
|
577
|
+
startEvent: turn.eventIndex,
|
|
578
|
+
startAt: turn.at,
|
|
579
|
+
promptSha256: sha256(turn.text),
|
|
580
|
+
promptChars: turn.text.length,
|
|
581
|
+
turnId: turn.id,
|
|
582
|
+
label,
|
|
583
|
+
userTurns: 1,
|
|
584
|
+
corrections: 0,
|
|
585
|
+
reasks: 0,
|
|
586
|
+
correctionsKnown: true,
|
|
587
|
+
reasksKnown: true,
|
|
588
|
+
endEvent: session.events.length,
|
|
589
|
+
endAt: session.endedAt,
|
|
590
|
+
closedBy: "session-end"
|
|
591
|
+
};
|
|
592
|
+
threads.push(open);
|
|
593
|
+
}
|
|
594
|
+
return threads.map((thread) => {
|
|
595
|
+
return {
|
|
596
|
+
record: {
|
|
597
|
+
intentId: sha256(`${session.harness}\u0000${session.sessionId}\u0000${thread.turnId}`),
|
|
598
|
+
harness: session.harness,
|
|
599
|
+
sessionId: session.sessionId,
|
|
600
|
+
at: thread.startAt,
|
|
601
|
+
prompt: {
|
|
602
|
+
sha256: thread.promptSha256,
|
|
603
|
+
chars: thread.promptChars
|
|
604
|
+
},
|
|
605
|
+
label: thread.label === null ? null : {
|
|
606
|
+
source: thread.label.source,
|
|
607
|
+
kind: thread.label.kind,
|
|
608
|
+
done: thread.label.done
|
|
609
|
+
},
|
|
610
|
+
cost: cost(session, thread, options),
|
|
611
|
+
end: {
|
|
612
|
+
userTurns: thread.userTurns,
|
|
613
|
+
corrections: thread.correctionsKnown ? thread.corrections : null,
|
|
614
|
+
reasks: thread.reasksKnown ? thread.reasks : null,
|
|
615
|
+
closedBy: thread.closedBy
|
|
616
|
+
}
|
|
617
|
+
},
|
|
618
|
+
span: {
|
|
619
|
+
from: thread.startEvent,
|
|
620
|
+
to: thread.endEvent
|
|
621
|
+
},
|
|
622
|
+
window: {
|
|
623
|
+
from: thread.startAt,
|
|
624
|
+
to: thread.closedBy === "next-intent" ? thread.endAt : null
|
|
625
|
+
},
|
|
626
|
+
changeRefs: refsInSpan(session, thread.startEvent, thread.endEvent)
|
|
627
|
+
};
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
/** Whether a change reading says the change reached its done line: merged and not fixed within the window. */
|
|
631
|
+
function changesReachedDone(changes) {
|
|
632
|
+
if (changes.status !== "joined" || changes.outcomes.length === 0) return {
|
|
633
|
+
reachedDone: null,
|
|
634
|
+
abandoned: null
|
|
635
|
+
};
|
|
636
|
+
const outcomes = changes.outcomes;
|
|
637
|
+
const unmerged = outcomes.some((outcome) => outcome.merged === false);
|
|
638
|
+
const fixed = outcomes.some((outcome) => outcome.merged === true && outcome.hotfixed === true);
|
|
639
|
+
const clean = outcomes.every((outcome) => outcome.merged === true && outcome.hotfixed === false);
|
|
640
|
+
return {
|
|
641
|
+
reachedDone: unmerged || fixed ? false : clean ? true : null,
|
|
642
|
+
abandoned: unmerged ? true : outcomes.every((o) => o.merged === true) ? false : null
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
// src/intent-record/contract.ts
|
|
646
|
+
const INTENT_KINDS = [
|
|
647
|
+
"task",
|
|
648
|
+
"problem",
|
|
649
|
+
"project",
|
|
650
|
+
"information",
|
|
651
|
+
"correction"
|
|
652
|
+
];
|
|
653
|
+
// src/intent-record/report.ts
|
|
654
|
+
const NOTES$1 = [
|
|
655
|
+
"Intents are cut from typed turns: a turn a labeler calls a correction or a re-ask attaches to the open intent, and any other turn, labeled or not, opens a new one. Without labels every turn is its own intent and no intent knows its corrections.",
|
|
656
|
+
"An intent joins the changes whose tool call lies in its span, in its own session only. Work and changes in subagents count toward the procedures that served it, by time, and not toward its cost or changes.",
|
|
657
|
+
"reachedDone comes from the outcome of the intent’s changes when they have one, else is true when the person moved on to another intent, else unknown. A session that ends says nothing."
|
|
658
|
+
];
|
|
659
|
+
function joinChanges(refs, outcomes) {
|
|
660
|
+
if (refs === void 0) return { status: "not-recorded" };
|
|
661
|
+
if (refs.length === 0) return { status: "none" };
|
|
662
|
+
return {
|
|
663
|
+
status: "joined",
|
|
664
|
+
refs,
|
|
665
|
+
outcomes: refs.flatMap((ref) => {
|
|
666
|
+
const reading = outcomes.byRef.get(ref);
|
|
667
|
+
return reading === void 0 ? [] : [reading];
|
|
668
|
+
})
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
function buildIntentReport(sessions, outcomes) {
|
|
672
|
+
const byId = new Map(sessions.map((session) => [session.sessionId, session]));
|
|
673
|
+
const inherited = /* @__PURE__ */ new Map();
|
|
674
|
+
for (const session of sessions) for (let parent = session.parentSessionId, hops = 0; parent !== null && hops < 64; parent = byId.get(parent)?.parentSessionId ?? null, hops++) for (const draft of byId.get(parent)?.drafts ?? []) {
|
|
675
|
+
const from = instant(draft.window.from);
|
|
676
|
+
const to = instant(draft.window.to);
|
|
677
|
+
if (from === null) continue;
|
|
678
|
+
for (const invocation of session.invocations) {
|
|
679
|
+
const at = instant(invocation.at);
|
|
680
|
+
if (at === null || at < from || to !== null && at >= to) continue;
|
|
681
|
+
const keys = inherited.get(draft) ?? /* @__PURE__ */ new Set();
|
|
682
|
+
keys.add(invocation.key);
|
|
683
|
+
inherited.set(draft, keys);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
const intents = [];
|
|
687
|
+
let sessionsWithTurns = 0;
|
|
688
|
+
let sessionsWithoutTurns = 0;
|
|
689
|
+
for (const session of sessions) {
|
|
690
|
+
if (session.drafts === null) {
|
|
691
|
+
sessionsWithoutTurns += 1;
|
|
692
|
+
continue;
|
|
693
|
+
}
|
|
694
|
+
sessionsWithTurns += 1;
|
|
695
|
+
for (const draft of session.drafts) {
|
|
696
|
+
const keys = new Set(inherited.get(draft));
|
|
697
|
+
for (const invocation of session.invocations) if (invocation.index >= draft.span.from && invocation.index < draft.span.to) keys.add(invocation.key);
|
|
698
|
+
const changes = joinChanges(draft.changeRefs, outcomes);
|
|
699
|
+
const fromChanges = changesReachedDone(changes);
|
|
700
|
+
const movedOn = draft.record.end.closedBy === "next-intent";
|
|
701
|
+
const evidence = fromChanges.reachedDone !== null ? "change-outcome" : movedOn ? "moved-on" : "none";
|
|
702
|
+
intents.push({
|
|
703
|
+
...draft.record,
|
|
704
|
+
procedures: [...keys].sort(),
|
|
705
|
+
end: {
|
|
706
|
+
...draft.record.end,
|
|
707
|
+
reachedDone: fromChanges.reachedDone ?? (movedOn ? true : null),
|
|
708
|
+
abandoned: fromChanges.abandoned,
|
|
709
|
+
evidence
|
|
710
|
+
},
|
|
711
|
+
changes
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
const kinds = [...INTENT_KINDS, null];
|
|
716
|
+
const share = (part, whole) => whole === 0 ? null : part / whole;
|
|
717
|
+
const known = (record) => record.end.reachedDone !== null;
|
|
718
|
+
return {
|
|
719
|
+
intents,
|
|
720
|
+
summary: {
|
|
721
|
+
intents: intents.length,
|
|
722
|
+
sessionsWithTurns,
|
|
723
|
+
sessionsWithoutTurns,
|
|
724
|
+
labeled: intents.filter((record) => record.label !== null).length,
|
|
725
|
+
knownEnd: intents.filter(known).length,
|
|
726
|
+
knownEndShare: share(intents.filter(known).length, intents.length),
|
|
727
|
+
byKind: kinds.map((kind) => {
|
|
728
|
+
const of = intents.filter((record) => (record.label?.kind ?? null) === kind);
|
|
729
|
+
return {
|
|
730
|
+
kind,
|
|
731
|
+
intents: of.length,
|
|
732
|
+
knownEnd: of.filter(known).length,
|
|
733
|
+
knownEndShare: share(of.filter(known).length, of.length),
|
|
734
|
+
knownCorrections: of.filter((record) => record.end.corrections !== null).length,
|
|
735
|
+
joinedToChange: of.filter((record) => record.changes.status === "joined").length,
|
|
736
|
+
withChangeOutcome: of.filter((record) => record.changes.status === "joined" && record.changes.outcomes.length > 0).length
|
|
737
|
+
};
|
|
738
|
+
})
|
|
739
|
+
},
|
|
740
|
+
notes: [...NOTES$1]
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Index outcomes by change reference. An outcome judged over another window
|
|
745
|
+
* keeps `merged` and `gateGreenFirstTry` and loses `hotfixed`: a 3-day and a
|
|
746
|
+
* 14-day "no fix" are different claims, and the registry has one definition.
|
|
747
|
+
* Two outcomes for one reference must agree; a reference given twice with
|
|
748
|
+
* different readings throws.
|
|
749
|
+
*/
|
|
750
|
+
function indexChangeOutcomes(outcomes) {
|
|
751
|
+
const byRef = /* @__PURE__ */ new Map();
|
|
752
|
+
let otherWindow = 0;
|
|
753
|
+
let duplicates = 0;
|
|
754
|
+
for (const outcome of outcomes) {
|
|
755
|
+
if (typeof outcome.ref !== "string" || outcome.ref === "") throw new ValidationError("a change outcome needs a non-empty ref");
|
|
756
|
+
const sameWindow = outcome.hotfixWindowDays === 7;
|
|
757
|
+
if (!sameWindow) otherWindow += 1;
|
|
758
|
+
const reading = {
|
|
759
|
+
ref: outcome.ref,
|
|
760
|
+
merged: outcome.merged,
|
|
761
|
+
gateGreenFirstTry: outcome.gateGreenFirstTry,
|
|
762
|
+
hotfixed: sameWindow ? outcome.hotfixed : null
|
|
763
|
+
};
|
|
764
|
+
const known = byRef.get(outcome.ref);
|
|
765
|
+
if (known !== void 0) {
|
|
766
|
+
duplicates += 1;
|
|
767
|
+
if (JSON.stringify(known) !== JSON.stringify(reading)) throw new ValidationError(`change ${outcome.ref} has two different outcomes`);
|
|
768
|
+
continue;
|
|
769
|
+
}
|
|
770
|
+
byRef.set(outcome.ref, reading);
|
|
771
|
+
}
|
|
772
|
+
return {
|
|
773
|
+
byRef,
|
|
774
|
+
otherWindow,
|
|
775
|
+
duplicates
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* The changes an invocation produced: those of its session, and of every
|
|
780
|
+
* session that spawned it, since a subagent's work belongs to the change its
|
|
781
|
+
* parent shipped. A session absent from `sessions` ends the walk, and a cycle
|
|
782
|
+
* in the parent links is cut where it repeats.
|
|
783
|
+
*/
|
|
784
|
+
function joinInvocationToChanges(sessionId, sessions, outcomes) {
|
|
785
|
+
const refs = /* @__PURE__ */ new Set();
|
|
786
|
+
let recorded = false;
|
|
787
|
+
const visited = /* @__PURE__ */ new Set();
|
|
788
|
+
for (let current = sessionId; current !== null && !visited.has(current); current = sessions.get(current)?.parentSessionId ?? null) {
|
|
789
|
+
visited.add(current);
|
|
790
|
+
const session = sessions.get(current);
|
|
791
|
+
if (session?.refs === void 0) continue;
|
|
792
|
+
recorded = true;
|
|
793
|
+
for (const ref of session.refs) refs.add(ref);
|
|
794
|
+
}
|
|
795
|
+
if (!recorded) return { status: "not-recorded" };
|
|
796
|
+
if (refs.size === 0) return { status: "none" };
|
|
797
|
+
const sorted = [...refs].sort();
|
|
798
|
+
return {
|
|
799
|
+
status: "joined",
|
|
800
|
+
refs: sorted,
|
|
801
|
+
outcomes: sorted.flatMap((ref) => {
|
|
802
|
+
const reading = outcomes.byRef.get(ref);
|
|
803
|
+
return reading === void 0 ? [] : [reading];
|
|
804
|
+
})
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
// src/procedure-registry/registry.ts
|
|
808
|
+
const NOTES = [
|
|
809
|
+
"Session executions measure from the invocation to the end of its session, as `skill-usage` does, so a session that invokes several procedures counts its later work under each and the totals overlap across versions.",
|
|
810
|
+
"Search-cell and session measures are different quantities (a cell is one task, a session is open-ended) and are never added together.",
|
|
811
|
+
"An invocation joins the changes of its own session and of the sessions that spawned it. It joins every change the session produced, before and after the invocation."
|
|
812
|
+
];
|
|
813
|
+
function normalizeDigest(value) {
|
|
814
|
+
const hex = value.startsWith("sha256:") ? value.slice(7) : value;
|
|
815
|
+
if (!/^[0-9a-f]{64}$/.test(hex)) throw new ValidationError(`a procedure digest is a sha256, got ${JSON.stringify(value)}`);
|
|
816
|
+
return `sha256:${hex}`;
|
|
817
|
+
}
|
|
818
|
+
function compareText(a, b) {
|
|
819
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
820
|
+
}
|
|
821
|
+
function emptyMeasure() {
|
|
822
|
+
return {
|
|
823
|
+
sum: 0,
|
|
824
|
+
measured: 0,
|
|
825
|
+
unmeasured: 0
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
function addMeasure(total, value) {
|
|
829
|
+
if (value === null) total.unmeasured += 1;
|
|
830
|
+
else {
|
|
831
|
+
total.sum += value;
|
|
832
|
+
total.measured += 1;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
function emptyCounts() {
|
|
836
|
+
return {
|
|
837
|
+
yes: 0,
|
|
838
|
+
no: 0,
|
|
839
|
+
unknown: 0
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
function count(counts, value) {
|
|
843
|
+
if (value === null) counts.unknown += 1;
|
|
844
|
+
else if (value) counts.yes += 1;
|
|
845
|
+
else counts.no += 1;
|
|
846
|
+
}
|
|
847
|
+
/** The caller's reading of one change field, across the readings of every outcome the change has. */
|
|
848
|
+
function pick(readings, field) {
|
|
849
|
+
return readings === void 0 ? null : readings[field];
|
|
850
|
+
}
|
|
851
|
+
function summarizeChanges(executions, index) {
|
|
852
|
+
const changes = {
|
|
853
|
+
invocations: executions.length,
|
|
854
|
+
joined: 0,
|
|
855
|
+
none: 0,
|
|
856
|
+
notRecorded: 0,
|
|
857
|
+
distinctChanges: 0,
|
|
858
|
+
withOutcome: 0,
|
|
859
|
+
merged: emptyCounts(),
|
|
860
|
+
gateGreenFirstTry: emptyCounts(),
|
|
861
|
+
hotfixed: emptyCounts()
|
|
862
|
+
};
|
|
863
|
+
const refs = /* @__PURE__ */ new Set();
|
|
864
|
+
for (const execution of executions) {
|
|
865
|
+
const joined = execution.changes;
|
|
866
|
+
if (joined.status === "joined") {
|
|
867
|
+
changes.joined += 1;
|
|
868
|
+
for (const ref of joined.refs) refs.add(ref);
|
|
869
|
+
} else if (joined.status === "none") changes.none += 1;
|
|
870
|
+
else changes.notRecorded += 1;
|
|
871
|
+
}
|
|
872
|
+
changes.distinctChanges = refs.size;
|
|
873
|
+
for (const ref of [...refs].sort(compareText)) {
|
|
874
|
+
const reading = index.byRef.get(ref);
|
|
875
|
+
if (reading !== void 0) changes.withOutcome += 1;
|
|
876
|
+
count(changes.merged, pick(reading, "merged"));
|
|
877
|
+
count(changes.gateGreenFirstTry, pick(reading, "gateGreenFirstTry"));
|
|
878
|
+
count(changes.hotfixed, pick(reading, "hotfixed"));
|
|
879
|
+
}
|
|
880
|
+
return changes;
|
|
881
|
+
}
|
|
882
|
+
var Registry = class {
|
|
883
|
+
builders = /* @__PURE__ */ new Map();
|
|
884
|
+
builder(key) {
|
|
885
|
+
let builder = this.builders.get(key);
|
|
886
|
+
if (builder === void 0) {
|
|
887
|
+
builder = {
|
|
888
|
+
key,
|
|
889
|
+
digest: key.startsWith("sha256:") ? key : null,
|
|
890
|
+
names: /* @__PURE__ */ new Set(),
|
|
891
|
+
kind: null,
|
|
892
|
+
parents: /* @__PURE__ */ new Set(),
|
|
893
|
+
edges: [],
|
|
894
|
+
searches: [],
|
|
895
|
+
decisions: [],
|
|
896
|
+
executions: []
|
|
897
|
+
};
|
|
898
|
+
this.builders.set(key, builder);
|
|
899
|
+
}
|
|
900
|
+
return builder;
|
|
901
|
+
}
|
|
902
|
+
all() {
|
|
903
|
+
return [...this.builders.values()];
|
|
904
|
+
}
|
|
905
|
+
};
|
|
906
|
+
const nodeKey = (searchId, nodeId) => `${searchId}\u0000${nodeId}`;
|
|
907
|
+
function addSearch(registry, search, keys, options) {
|
|
908
|
+
const subject = search.header?.subject ?? "";
|
|
909
|
+
const closed = search.closed !== null;
|
|
910
|
+
const claim = search.closed?.claim ?? null;
|
|
911
|
+
const rootNodeId = search.rootNodeId;
|
|
912
|
+
for (const node of search.nodes()) {
|
|
913
|
+
const key = keys.get(nodeKey(search.searchId, node.nodeId));
|
|
914
|
+
const identity = options.procedureOfNode?.(node, search) ?? null;
|
|
915
|
+
const builder = registry.builder(key);
|
|
916
|
+
if (identity?.kind !== void 0) builder.kind = identity.kind;
|
|
917
|
+
if (identity?.name !== void 0) builder.names.add(identity.name);
|
|
918
|
+
const latest = node.decisions.at(-1);
|
|
919
|
+
builder.searches.push({
|
|
920
|
+
searchId: search.searchId,
|
|
921
|
+
nodeId: node.nodeId,
|
|
922
|
+
subject,
|
|
923
|
+
closed,
|
|
924
|
+
status: latest === void 0 ? null : latest.decision.status
|
|
925
|
+
});
|
|
926
|
+
const resolve = (ref) => {
|
|
927
|
+
const parentKey = keys.get(nodeKey(ref.searchId, ref.nodeId));
|
|
928
|
+
return parentKey?.startsWith("sha256:") ? parentKey : null;
|
|
929
|
+
};
|
|
930
|
+
for (const parent of node.parents) {
|
|
931
|
+
const digest = resolve(parent);
|
|
932
|
+
if (digest !== null) builder.parents.add(digest);
|
|
933
|
+
}
|
|
934
|
+
node.edgeIds.forEach((edgeId, position) => {
|
|
935
|
+
const edge = search.edge(edgeId);
|
|
936
|
+
if (edge === void 0) return;
|
|
937
|
+
builder.edges.push({
|
|
938
|
+
searchId: search.searchId,
|
|
939
|
+
edgeId,
|
|
940
|
+
operator: edge.operator,
|
|
941
|
+
attribution: edge.attribution,
|
|
942
|
+
proposer: edge.proposer === null ? null : {
|
|
943
|
+
kind: edge.proposer.kind,
|
|
944
|
+
name: edge.proposer.name
|
|
945
|
+
},
|
|
946
|
+
parents: edge.parents.map((parent) => ({
|
|
947
|
+
searchId: parent.searchId,
|
|
948
|
+
nodeId: parent.nodeId,
|
|
949
|
+
digest: resolve(parent)
|
|
950
|
+
})),
|
|
951
|
+
reproposal: position > 0
|
|
952
|
+
});
|
|
953
|
+
});
|
|
954
|
+
node.decisions.forEach((record, position) => {
|
|
955
|
+
builder.decisions.push({
|
|
956
|
+
searchId: search.searchId,
|
|
957
|
+
nodeId: node.nodeId,
|
|
958
|
+
source: "node-decided",
|
|
959
|
+
status: record.decision.status,
|
|
960
|
+
rung: record.decision.status === "advanced" ? record.decision.rung : null,
|
|
961
|
+
rule: record.rule,
|
|
962
|
+
reason: record.reason,
|
|
963
|
+
current: position === node.decisions.length - 1
|
|
964
|
+
});
|
|
965
|
+
});
|
|
966
|
+
for (const cell of search.cells({ nodeId: node.nodeId })) {
|
|
967
|
+
if (cell.attempts === 0) continue;
|
|
968
|
+
const onSeat = cell.subscriptionAttempts === cell.attempts;
|
|
969
|
+
builder.executions.push({
|
|
970
|
+
source: "search-cell",
|
|
971
|
+
searchId: search.searchId,
|
|
972
|
+
nodeId: node.nodeId,
|
|
973
|
+
cellId: cell.cellId,
|
|
974
|
+
split: cell.split,
|
|
975
|
+
stage: cell.stage,
|
|
976
|
+
outcome: cell.outcome,
|
|
977
|
+
score: cell.score,
|
|
978
|
+
tokens: cell.tokensKnown ? cell.tokens.inputTokens + cell.tokens.outputTokens + cell.tokens.cachedTokens : null,
|
|
979
|
+
usd: cell.costKnown && !onSeat ? cell.spentUsd : null,
|
|
980
|
+
costBasis: !cell.costKnown ? "unknown" : onSeat ? "subscription" : "measured",
|
|
981
|
+
wallMs: cell.wallKnown ? cell.wallMs : null
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
if (claim !== null) {
|
|
986
|
+
const nodeId = claim.selected ?? rootNodeId;
|
|
987
|
+
const key = nodeId === null ? void 0 : keys.get(nodeKey(search.searchId, nodeId));
|
|
988
|
+
if (nodeId !== null && key !== void 0) registry.builder(key).decisions.push({
|
|
989
|
+
searchId: search.searchId,
|
|
990
|
+
nodeId,
|
|
991
|
+
source: "claim",
|
|
992
|
+
status: claim.decision,
|
|
993
|
+
rung: null,
|
|
994
|
+
rule: claim.rule.uri,
|
|
995
|
+
reason: claim.reason,
|
|
996
|
+
current: true
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Build the registry from search ledgers, recorded sessions and the outcomes of
|
|
1002
|
+
* the changes those sessions produced. Any of the three may be absent.
|
|
1003
|
+
*
|
|
1004
|
+
* An invocation is counted once per call id across the whole source, and with
|
|
1005
|
+
* `sinceMs` only invocations at or after it count, exactly as `skill-usage`
|
|
1006
|
+
* counts them; an undated invocation cannot be placed in the window and is
|
|
1007
|
+
* left out. Versions are ordered by executions, most first, then by key.
|
|
1008
|
+
*/
|
|
1009
|
+
async function buildProcedureRegistry(input, options = {}) {
|
|
1010
|
+
if (options.sinceMs !== void 0 && !Number.isFinite(options.sinceMs)) throw new ValidationError(`buildProcedureRegistry: sinceMs must be finite, got ${options.sinceMs}`);
|
|
1011
|
+
const outcomes = indexChangeOutcomes(input.outcomes ?? []);
|
|
1012
|
+
const registry = new Registry();
|
|
1013
|
+
const searches = [...input.searches ?? []];
|
|
1014
|
+
const keys = /* @__PURE__ */ new Map();
|
|
1015
|
+
for (const search of searches) for (const node of search.nodes()) {
|
|
1016
|
+
const identity = options.procedureOfNode?.(node, search) ?? null;
|
|
1017
|
+
keys.set(nodeKey(search.searchId, node.nodeId), normalizeDigest(identity?.digest ?? node.artifactDigest));
|
|
1018
|
+
}
|
|
1019
|
+
for (const search of searches) addSearch(registry, search, keys, options);
|
|
1020
|
+
const sessionChanges = /* @__PURE__ */ new Map();
|
|
1021
|
+
const pending = [];
|
|
1022
|
+
const unreadable = [];
|
|
1023
|
+
const seenCalls = /* @__PURE__ */ new Set();
|
|
1024
|
+
const sessions = {
|
|
1025
|
+
read: 0,
|
|
1026
|
+
unreadable: 0,
|
|
1027
|
+
withInvocation: 0
|
|
1028
|
+
};
|
|
1029
|
+
const intentSessions = [];
|
|
1030
|
+
const versionDigest = (event) => {
|
|
1031
|
+
if (event.version !== null) return event.version.bodySha256;
|
|
1032
|
+
if (event.skillFile === null || options.readSkillFile === void 0) return null;
|
|
1033
|
+
const file = options.readSkillFile(event.skillFile);
|
|
1034
|
+
return file.succeeded ? file.bodySha256 : null;
|
|
1035
|
+
};
|
|
1036
|
+
for await (const read of input.sessions ?? []) {
|
|
1037
|
+
if (!read.succeeded) {
|
|
1038
|
+
sessions.unreadable += 1;
|
|
1039
|
+
unreadable.push({
|
|
1040
|
+
source: read.source,
|
|
1041
|
+
error: read.error
|
|
1042
|
+
});
|
|
1043
|
+
continue;
|
|
1044
|
+
}
|
|
1045
|
+
const session = read.value;
|
|
1046
|
+
sessions.read += 1;
|
|
1047
|
+
sessionChanges.set(session.sessionId, {
|
|
1048
|
+
parentSessionId: session.parentSessionId,
|
|
1049
|
+
refs: session.changes?.map((change) => change.ref)
|
|
1050
|
+
});
|
|
1051
|
+
let counted = false;
|
|
1052
|
+
const placed = [];
|
|
1053
|
+
session.events.forEach((event, position) => {
|
|
1054
|
+
if (event.kind !== "skill") return;
|
|
1055
|
+
if (seenCalls.has(event.callId)) return;
|
|
1056
|
+
seenCalls.add(event.callId);
|
|
1057
|
+
if (options.sinceMs !== void 0) {
|
|
1058
|
+
const at = instant(event.at);
|
|
1059
|
+
if (at === null || at < options.sinceMs) return;
|
|
1060
|
+
}
|
|
1061
|
+
counted = true;
|
|
1062
|
+
const hex = versionDigest(event);
|
|
1063
|
+
const key = hex === null ? `unversioned:${event.skill}` : normalizeDigest(hex);
|
|
1064
|
+
const builder = registry.builder(key);
|
|
1065
|
+
builder.names.add(event.skill);
|
|
1066
|
+
builder.kind ??= options.kindOfSkill?.(event.skill) ?? "skill";
|
|
1067
|
+
placed.push({
|
|
1068
|
+
index: position,
|
|
1069
|
+
at: event.at,
|
|
1070
|
+
key
|
|
1071
|
+
});
|
|
1072
|
+
const after = afterInvocation(session, position, event.at, options);
|
|
1073
|
+
pending.push({
|
|
1074
|
+
builderKey: key,
|
|
1075
|
+
sessionId: session.sessionId,
|
|
1076
|
+
harness: session.harness,
|
|
1077
|
+
event,
|
|
1078
|
+
measures: {
|
|
1079
|
+
tokens: after.modelCalls > 0 && after.modelCallsWithoutUsage === 0 ? after.tokens.total : null,
|
|
1080
|
+
usd: after.pricedModelCalls > 0 && after.unpricedModelCalls === 0 ? after.costUsd : null,
|
|
1081
|
+
wallMs: after.wallMs
|
|
1082
|
+
}
|
|
1083
|
+
});
|
|
1084
|
+
});
|
|
1085
|
+
if (counted) sessions.withInvocation += 1;
|
|
1086
|
+
if (options.intents !== void 0) intentSessions.push({
|
|
1087
|
+
sessionId: session.sessionId,
|
|
1088
|
+
parentSessionId: session.parentSessionId,
|
|
1089
|
+
drafts: await deriveSessionIntents(session, options.intents.labeler, options, options.intents.ignore),
|
|
1090
|
+
invocations: placed
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
const joins = {
|
|
1094
|
+
joined: 0,
|
|
1095
|
+
none: 0,
|
|
1096
|
+
notRecorded: 0,
|
|
1097
|
+
withOutcome: 0
|
|
1098
|
+
};
|
|
1099
|
+
const joinedRefs = /* @__PURE__ */ new Set();
|
|
1100
|
+
for (const invocation of pending) {
|
|
1101
|
+
const { event } = invocation;
|
|
1102
|
+
const changes = joinInvocationToChanges(invocation.sessionId, sessionChanges, outcomes);
|
|
1103
|
+
if (changes.status === "joined") {
|
|
1104
|
+
joins.joined += 1;
|
|
1105
|
+
for (const ref of changes.refs) joinedRefs.add(ref);
|
|
1106
|
+
if (changes.outcomes.length > 0) joins.withOutcome += 1;
|
|
1107
|
+
} else if (changes.status === "none") joins.none += 1;
|
|
1108
|
+
else joins.notRecorded += 1;
|
|
1109
|
+
registry.builder(invocation.builderKey).executions.push({
|
|
1110
|
+
source: "session",
|
|
1111
|
+
harness: invocation.harness,
|
|
1112
|
+
sessionId: invocation.sessionId,
|
|
1113
|
+
callId: event.callId,
|
|
1114
|
+
skill: event.skill,
|
|
1115
|
+
invoker: event.invoker,
|
|
1116
|
+
at: event.at,
|
|
1117
|
+
failed: event.failed,
|
|
1118
|
+
...invocation.measures,
|
|
1119
|
+
changes
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
const versions = registry.all().map((builder) => {
|
|
1123
|
+
const cells = {
|
|
1124
|
+
count: 0,
|
|
1125
|
+
passed: 0,
|
|
1126
|
+
failed: 0,
|
|
1127
|
+
errored: 0,
|
|
1128
|
+
subscription: 0,
|
|
1129
|
+
tokens: emptyMeasure(),
|
|
1130
|
+
usd: emptyMeasure(),
|
|
1131
|
+
wallMs: emptyMeasure()
|
|
1132
|
+
};
|
|
1133
|
+
const sessionRuns = {
|
|
1134
|
+
invocations: 0,
|
|
1135
|
+
tokens: emptyMeasure(),
|
|
1136
|
+
usd: emptyMeasure(),
|
|
1137
|
+
wallMs: emptyMeasure()
|
|
1138
|
+
};
|
|
1139
|
+
const runs = [];
|
|
1140
|
+
for (const execution of builder.executions) if (execution.source === "search-cell") {
|
|
1141
|
+
cells.count += 1;
|
|
1142
|
+
if (execution.outcome === "passed") cells.passed += 1;
|
|
1143
|
+
else if (execution.outcome === "failed") cells.failed += 1;
|
|
1144
|
+
else if (execution.outcome === "errored") cells.errored += 1;
|
|
1145
|
+
addMeasure(cells.tokens, execution.tokens);
|
|
1146
|
+
if (execution.costBasis === "subscription") cells.subscription += 1;
|
|
1147
|
+
else addMeasure(cells.usd, execution.usd);
|
|
1148
|
+
addMeasure(cells.wallMs, execution.wallMs);
|
|
1149
|
+
} else {
|
|
1150
|
+
sessionRuns.invocations += 1;
|
|
1151
|
+
addMeasure(sessionRuns.tokens, execution.tokens);
|
|
1152
|
+
addMeasure(sessionRuns.usd, execution.usd);
|
|
1153
|
+
addMeasure(sessionRuns.wallMs, execution.wallMs);
|
|
1154
|
+
runs.push(execution);
|
|
1155
|
+
}
|
|
1156
|
+
return {
|
|
1157
|
+
key: builder.key,
|
|
1158
|
+
digest: builder.digest,
|
|
1159
|
+
names: [...builder.names].sort(compareText),
|
|
1160
|
+
kind: builder.kind,
|
|
1161
|
+
parents: [...builder.parents].sort(compareText),
|
|
1162
|
+
edges: builder.edges,
|
|
1163
|
+
searches: builder.searches,
|
|
1164
|
+
decisions: builder.decisions,
|
|
1165
|
+
cells,
|
|
1166
|
+
sessions: {
|
|
1167
|
+
...sessionRuns,
|
|
1168
|
+
changes: summarizeChanges(runs, outcomes)
|
|
1169
|
+
},
|
|
1170
|
+
executions: builder.executions
|
|
1171
|
+
};
|
|
1172
|
+
});
|
|
1173
|
+
versions.sort((a, b) => {
|
|
1174
|
+
const left = a.cells.count + a.sessions.invocations;
|
|
1175
|
+
const right = b.cells.count + b.sessions.invocations;
|
|
1176
|
+
return left !== right ? right - left : compareText(a.key, b.key);
|
|
1177
|
+
});
|
|
1178
|
+
const share = (part) => pending.length === 0 ? null : part / pending.length;
|
|
1179
|
+
return {
|
|
1180
|
+
searches: {
|
|
1181
|
+
read: searches.length,
|
|
1182
|
+
closed: searches.filter((s) => s.closed !== null).length
|
|
1183
|
+
},
|
|
1184
|
+
sessions,
|
|
1185
|
+
invocations: pending.length,
|
|
1186
|
+
changeJoin: {
|
|
1187
|
+
hotfixWindowDays: 7,
|
|
1188
|
+
invocations: pending.length,
|
|
1189
|
+
...joins,
|
|
1190
|
+
joinedShare: share(joins.joined),
|
|
1191
|
+
withOutcomeShare: share(joins.withOutcome),
|
|
1192
|
+
distinctChanges: joinedRefs.size,
|
|
1193
|
+
outcomesSupplied: outcomes.byRef.size,
|
|
1194
|
+
outcomesInWrongWindow: outcomes.otherWindow
|
|
1195
|
+
},
|
|
1196
|
+
versions,
|
|
1197
|
+
intents: options.intents === void 0 ? null : buildIntentReport(intentSessions, outcomes),
|
|
1198
|
+
unreadable,
|
|
1199
|
+
notes: [...NOTES]
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
// src/procedure-registry/render.ts
|
|
1203
|
+
function percent(share) {
|
|
1204
|
+
return share === null ? "n/a" : `${(share * 100).toFixed(1)}%`;
|
|
1205
|
+
}
|
|
1206
|
+
/** A measure's sum, with how many executions did not report it. */
|
|
1207
|
+
function measure(total, digits = 0) {
|
|
1208
|
+
if (total.measured === 0) return total.unmeasured === 0 ? "-" : "unknown";
|
|
1209
|
+
const text = total.sum.toFixed(digits);
|
|
1210
|
+
return total.unmeasured === 0 ? text : `${text}+${total.unmeasured}?`;
|
|
1211
|
+
}
|
|
1212
|
+
function digest(version) {
|
|
1213
|
+
return version.digest === null ? "(no version)" : version.digest.slice(7, 19);
|
|
1214
|
+
}
|
|
1215
|
+
function decided(version) {
|
|
1216
|
+
const latest = version.decisions.filter((decision) => decision.current);
|
|
1217
|
+
return latest.length === 0 ? "-" : [...new Set(latest.map((d) => d.status))].join(",");
|
|
1218
|
+
}
|
|
1219
|
+
function renderProcedureRegistryTable(registry, limit = 30) {
|
|
1220
|
+
const join = registry.changeJoin;
|
|
1221
|
+
const lines = [
|
|
1222
|
+
`${registry.versions.length} procedure versions; ${registry.invocations} invocations in ${registry.sessions.read} sessions (${registry.sessions.unreadable} unreadable); ${registry.searches.read} searches`,
|
|
1223
|
+
`joined to a change: ${join.joined} of ${join.invocations} invocations (${percent(join.joinedShare)}); none ${join.none}, not recorded ${join.notRecorded}`,
|
|
1224
|
+
`with an outcome for a change: ${join.withOutcome} (${percent(join.withOutcomeShare)}); ${join.distinctChanges} distinct changes, ${join.outcomesSupplied} outcomes supplied (hot-fix window ${join.hotfixWindowDays} days)`,
|
|
1225
|
+
`cells on a subscription seat (a known basis with no dollar figure): ${registry.versions.reduce((n, v) => n + v.cells.subscription, 0)}`,
|
|
1226
|
+
"",
|
|
1227
|
+
"version kind names cells runs chg-joined merged y/n/? hotfix y/n/? tokens(runs) decided"
|
|
1228
|
+
];
|
|
1229
|
+
for (const version of registry.versions.slice(0, limit)) {
|
|
1230
|
+
const changes = version.sessions.changes;
|
|
1231
|
+
const counts = (c) => `${c.yes}/${c.no}/${c.unknown}`;
|
|
1232
|
+
lines.push([
|
|
1233
|
+
digest(version).padEnd(13),
|
|
1234
|
+
(version.kind ?? "unclassified").padEnd(11),
|
|
1235
|
+
version.names.join(",").slice(0, 30).padEnd(30),
|
|
1236
|
+
String(version.cells.count).padStart(5),
|
|
1237
|
+
String(version.sessions.invocations).padStart(5),
|
|
1238
|
+
String(changes.joined).padStart(10),
|
|
1239
|
+
counts(changes.merged).padStart(13),
|
|
1240
|
+
counts(changes.hotfixed).padStart(13),
|
|
1241
|
+
measure(version.sessions.tokens).padStart(13),
|
|
1242
|
+
decided(version)
|
|
1243
|
+
].join(" "));
|
|
1244
|
+
}
|
|
1245
|
+
if (registry.versions.length > limit) lines.push(`... ${registry.versions.length - limit} more versions in the JSON`);
|
|
1246
|
+
const intents = registry.intents;
|
|
1247
|
+
if (intents !== null) {
|
|
1248
|
+
const summary = intents.summary;
|
|
1249
|
+
lines.push("", `${summary.intents} intents in ${summary.sessionsWithTurns} sessions (${summary.sessionsWithoutTurns} record no typed turns); ${summary.labeled} labeled; known end ${summary.knownEnd} (${percent(summary.knownEndShare)})`, "kind intents known-end share corrections-known joined-to-change with-outcome");
|
|
1250
|
+
for (const row of summary.byKind) {
|
|
1251
|
+
if (row.intents === 0) continue;
|
|
1252
|
+
lines.push([
|
|
1253
|
+
(row.kind ?? "unlabeled").padEnd(12),
|
|
1254
|
+
String(row.intents).padStart(8),
|
|
1255
|
+
String(row.knownEnd).padStart(10),
|
|
1256
|
+
percent(row.knownEndShare).padStart(7),
|
|
1257
|
+
String(row.knownCorrections).padStart(18),
|
|
1258
|
+
String(row.joinedToChange).padStart(17),
|
|
1259
|
+
String(row.withChangeOutcome).padStart(13)
|
|
1260
|
+
].join(" "));
|
|
1261
|
+
}
|
|
1262
|
+
for (const note of intents.notes) lines.push("", `note: ${note}`);
|
|
1263
|
+
}
|
|
1264
|
+
for (const note of registry.notes) lines.push("", `note: ${note}`);
|
|
1265
|
+
return `${lines.join("\n")}\n`;
|
|
1266
|
+
}
|
|
1267
|
+
// src/procedure-registry/command.ts
|
|
1268
|
+
/**
|
|
1269
|
+
* `agent-eval procedure-registry <sessions-dir>` prints the procedure registry
|
|
1270
|
+
* for a directory of Claude Code transcripts (or, with `--harness codex`, Codex
|
|
1271
|
+
* rollouts) and any number of search ledgers.
|
|
1272
|
+
*
|
|
1273
|
+
* `--change-ledger <file>` (repeatable) names a change ledger, the harness's own
|
|
1274
|
+
* record of each commit and pull request a session made (see
|
|
1275
|
+
* `src/skill-usage/change-ledger.ts`). A session the ledger observed has exactly
|
|
1276
|
+
* the changes it lists; a session it never saw has only what its transcript
|
|
1277
|
+
* shows, and none recorded when the transcript shows none.
|
|
1278
|
+
*
|
|
1279
|
+
* `--outcomes <file>` names a JSON array of {@link ChangeOutcome}: what the
|
|
1280
|
+
* caller knows of each change the sessions produced. Without it every change is
|
|
1281
|
+
* joined and none has an outcome. The JSON registry goes to stdout and the
|
|
1282
|
+
* short table to stderr, as `skill-usage` does.
|
|
1283
|
+
*
|
|
1284
|
+
* Exit codes: 2 for a usage error, 1 when a directory or ledger cannot be
|
|
1285
|
+
* read, 0 after the registry was written.
|
|
1286
|
+
*/
|
|
1287
|
+
const FORMATS$1 = [
|
|
1288
|
+
"both",
|
|
1289
|
+
"json",
|
|
1290
|
+
"table"
|
|
1291
|
+
];
|
|
1292
|
+
const USAGE$1 = "usage: agent-eval procedure-registry <sessions-dir> [--harness claude-code|codex] [--ledger <search-ledger.jsonl>]... [--since <7d|36h|90m|ISO time>] [--outcomes <changes.json>] [--change-ledger <changes.jsonl>]... [--intents [<labeler.mjs>]] [--format both|json|table] [--limit <rows>] [--pricing <rates.json>]";
|
|
1293
|
+
const PROCESS_IO$1 = {
|
|
1294
|
+
stdout: (text) => {
|
|
1295
|
+
process.stdout.write(text);
|
|
1296
|
+
},
|
|
1297
|
+
stderr: (text) => {
|
|
1298
|
+
process.stderr.write(text);
|
|
1299
|
+
}
|
|
1300
|
+
};
|
|
1301
|
+
function parseArgs$2(argv) {
|
|
1302
|
+
const args = {
|
|
1303
|
+
directory: "",
|
|
1304
|
+
harness: "claude-code",
|
|
1305
|
+
ledgers: [],
|
|
1306
|
+
since: null,
|
|
1307
|
+
outcomes: null,
|
|
1308
|
+
changeLedgers: [],
|
|
1309
|
+
intents: null,
|
|
1310
|
+
format: "both",
|
|
1311
|
+
limit: 30,
|
|
1312
|
+
pricing: null
|
|
1313
|
+
};
|
|
1314
|
+
const value = (flag, index) => {
|
|
1315
|
+
const raw = argv[index];
|
|
1316
|
+
if (raw === void 0) throw new Error(`${flag} expects a value`);
|
|
1317
|
+
return raw;
|
|
1318
|
+
};
|
|
1319
|
+
for (let i = 0; i < argv.length; i++) {
|
|
1320
|
+
const arg = argv[i];
|
|
1321
|
+
if (arg === "--harness") args.harness = parseHarness(value(arg, ++i));
|
|
1322
|
+
else if (arg === "--ledger") args.ledgers.push(value(arg, ++i));
|
|
1323
|
+
else if (arg === "--since") args.since = value(arg, ++i);
|
|
1324
|
+
else if (arg === "--outcomes") args.outcomes = value(arg, ++i);
|
|
1325
|
+
else if (arg === "--change-ledger") args.changeLedgers.push(value(arg, ++i));
|
|
1326
|
+
else if (arg === "--intents") {
|
|
1327
|
+
const next = argv[i + 1];
|
|
1328
|
+
const labeler = next !== void 0 && !next.startsWith("--") ? next : null;
|
|
1329
|
+
if (labeler !== null) i += 1;
|
|
1330
|
+
args.intents = { labeler };
|
|
1331
|
+
} else if (arg === "--pricing") args.pricing = value(arg, ++i);
|
|
1332
|
+
else if (arg === "--format") {
|
|
1333
|
+
const raw = value(arg, ++i);
|
|
1334
|
+
if (!FORMATS$1.includes(raw)) throw new Error(`--format expects one of ${FORMATS$1.join("|")}, got ${JSON.stringify(raw)}`);
|
|
1335
|
+
args.format = raw;
|
|
1336
|
+
} else if (arg === "--limit") {
|
|
1337
|
+
const raw = Number(value(arg, ++i));
|
|
1338
|
+
if (!Number.isInteger(raw) || raw < 1) throw new Error("--limit expects a positive integer");
|
|
1339
|
+
args.limit = raw;
|
|
1340
|
+
} else if (arg.startsWith("--")) throw new Error(`unknown flag "${arg}"`);
|
|
1341
|
+
else if (args.directory === "") args.directory = arg;
|
|
1342
|
+
else throw new Error(`unexpected argument "${arg}"`);
|
|
1343
|
+
}
|
|
1344
|
+
if (args.directory === "") throw new Error("a sessions directory is required");
|
|
1345
|
+
return args;
|
|
1346
|
+
}
|
|
1347
|
+
/** An outcomes file: a JSON array of change outcomes; each field is checked, so a typo is not read as unknown. */
|
|
1348
|
+
function readOutcomes(path) {
|
|
1349
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
1350
|
+
if (!Array.isArray(parsed)) throw new Error(`--outcomes ${path}: expected a JSON array`);
|
|
1351
|
+
const tri = (item, field, index) => {
|
|
1352
|
+
const raw = item[field];
|
|
1353
|
+
if (raw === null || typeof raw === "boolean") return raw;
|
|
1354
|
+
throw new Error(`--outcomes ${path}: entry ${index} ${field} must be true, false or null`);
|
|
1355
|
+
};
|
|
1356
|
+
return parsed.map((entry, index) => {
|
|
1357
|
+
const item = typeof entry === "object" && entry !== null ? entry : {};
|
|
1358
|
+
if (typeof item.ref !== "string" || item.ref === "") throw new Error(`--outcomes ${path}: entry ${index} needs a ref`);
|
|
1359
|
+
if (typeof item.hotfixWindowDays !== "number") throw new Error(`--outcomes ${path}: entry ${index} needs hotfixWindowDays`);
|
|
1360
|
+
return {
|
|
1361
|
+
ref: item.ref,
|
|
1362
|
+
merged: tri(item, "merged", index),
|
|
1363
|
+
gateGreenFirstTry: tri(item, "gateGreenFirstTry", index),
|
|
1364
|
+
hotfixed: tri(item, "hotfixed", index),
|
|
1365
|
+
hotfixWindowDays: item.hotfixWindowDays
|
|
1366
|
+
};
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
/** A labeler module: its default export is an {@link IntentLabeler}. It lives with the caller, where the labels and the words they read do. */
|
|
1370
|
+
async function loadLabeler(path) {
|
|
1371
|
+
const loaded = await import(pathToFileURL(resolve(path)).href);
|
|
1372
|
+
if (typeof loaded.default !== "function") throw new Error(`--intents ${path}: the module must export a labeler function as its default`);
|
|
1373
|
+
return {
|
|
1374
|
+
labeler: loaded.default,
|
|
1375
|
+
...typeof loaded.ignore === "function" ? { ignore: loaded.ignore } : {}
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
async function readLedger(path) {
|
|
1379
|
+
const text = await readFile(path, "utf8");
|
|
1380
|
+
const first = JSON.parse(text.slice(0, Math.max(0, text.indexOf("\n"))));
|
|
1381
|
+
if (typeof first.searchId !== "string") throw new Error(`${path} line 1 names no searchId`);
|
|
1382
|
+
return replaySearchLedgerText(text, first.searchId, path);
|
|
1383
|
+
}
|
|
1384
|
+
async function runProcedureRegistryCommand(argv, io = PROCESS_IO$1) {
|
|
1385
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
1386
|
+
io.stdout(`${USAGE$1}\n`);
|
|
1387
|
+
return 0;
|
|
1388
|
+
}
|
|
1389
|
+
let args;
|
|
1390
|
+
let sinceMs;
|
|
1391
|
+
let rates;
|
|
1392
|
+
let outcomes = [];
|
|
1393
|
+
try {
|
|
1394
|
+
args = parseArgs$2(argv);
|
|
1395
|
+
rates = args.pricing === null ? void 0 : readPricingFile(resolve(args.pricing));
|
|
1396
|
+
sinceMs = args.since === null ? void 0 : parseSince(args.since, (io.now ?? Date.now)());
|
|
1397
|
+
if (args.outcomes !== null) outcomes = readOutcomes(resolve(args.outcomes));
|
|
1398
|
+
} catch (error) {
|
|
1399
|
+
io.stderr(`${errorMessage(error)}\n${USAGE$1}\n`);
|
|
1400
|
+
return 2;
|
|
1401
|
+
}
|
|
1402
|
+
try {
|
|
1403
|
+
const labeler = args.intents?.labeler == null ? void 0 : await loadLabeler(args.intents.labeler);
|
|
1404
|
+
const searches = await Promise.all(args.ledgers.map((path) => readLedger(resolve(path))));
|
|
1405
|
+
const changeLedger = args.changeLedgers.length === 0 ? void 0 : await readChangeLedger(args.changeLedgers.map((path) => resolve(path)));
|
|
1406
|
+
if (changeLedger !== void 0 && changeLedger.malformed > 0) io.stderr(`change ledger: ${changeLedger.malformed} lines are not rows and were not read\n`);
|
|
1407
|
+
const transcripts = harnessSkillSessions(args.harness, resolve(args.directory), sinceMs === void 0 ? {} : { sinceMs });
|
|
1408
|
+
const registry = await buildProcedureRegistry({
|
|
1409
|
+
searches,
|
|
1410
|
+
sessions: changeLedger === void 0 ? transcripts : withChangeLedger(transcripts, changeLedger),
|
|
1411
|
+
outcomes
|
|
1412
|
+
}, {
|
|
1413
|
+
...sinceMs === void 0 ? {} : { sinceMs },
|
|
1414
|
+
...rates === void 0 ? {} : { pricing: (model) => rates?.get(model) },
|
|
1415
|
+
readSkillFile,
|
|
1416
|
+
...args.intents === null ? {} : { intents: { ...labeler } }
|
|
1417
|
+
});
|
|
1418
|
+
const table = renderProcedureRegistryTable(registry, args.limit);
|
|
1419
|
+
if (args.format === "table") io.stdout(table);
|
|
1420
|
+
else {
|
|
1421
|
+
io.stdout(`${JSON.stringify(registry, null, 2)}\n`);
|
|
1422
|
+
if (args.format === "both") io.stderr(table);
|
|
1423
|
+
}
|
|
1424
|
+
return 0;
|
|
1425
|
+
} catch (error) {
|
|
1426
|
+
io.stderr(`agent-eval procedure-registry: ${errorMessage(error)}\n`);
|
|
1427
|
+
return 1;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
87
1430
|
// src/search-command.ts
|
|
88
1431
|
/**
|
|
89
1432
|
* `agent-eval search <subcommand>`: work with a search ledger from a terminal.
|
|
@@ -707,6 +2050,8 @@ async function runSupervisorRunCommand(argv, io = PROCESS_IO) {
|
|
|
707
2050
|
* agent-eval supervisor-run report <runDir> [--format headline|markdown|json]
|
|
708
2051
|
* agent-eval search ship <search-ledger.jsonl> --run-kind optimization|eval
|
|
709
2052
|
* agent-eval search show <search-ledger.jsonl>
|
|
2053
|
+
* agent-eval skill-usage <transcripts-dir> [--since 7d]
|
|
2054
|
+
* agent-eval procedure-registry <sessions-dir> [--ledger <path>]... [--since 30d] [--outcomes <file>] [--change-ledger <file>]...
|
|
710
2055
|
* agent-eval openapi [--out path] # write OpenAPI spec
|
|
711
2056
|
* agent-eval version
|
|
712
2057
|
*
|
|
@@ -777,6 +2122,19 @@ Commands:
|
|
|
777
2122
|
search show <search-ledger.jsonl>
|
|
778
2123
|
Verify a search ledger and print its summary: leading nodes, recently
|
|
779
2124
|
discarded nodes and recent proposals, the same text a proposer reads.
|
|
2125
|
+
skill-usage <transcripts-dir> [--since <7d|36h|90m|ISO time>] [--format both|json|table] [--limit <rows>] [--pricing <rates.json>]
|
|
2126
|
+
Read a directory of Claude Code transcripts and report each skill and
|
|
2127
|
+
version: invocations by agent, user and harness, sessions, and the tool
|
|
2128
|
+
calls, tool errors, tokens, wall time and cost after its first invocation.
|
|
2129
|
+
The JSON report goes to stdout and the table to stderr.
|
|
2130
|
+
procedure-registry <sessions-dir> [--ledger <search-ledger.jsonl>]... [--since <7d|36h|90m|ISO time>] [--outcomes <changes.json>] [--change-ledger <changes.jsonl>]... [--intents [<labeler.mjs>]] [--format both|json|table] [--limit <rows>] [--pricing <rates.json>]
|
|
2131
|
+
Join search ledgers and recorded Claude Code sessions on the version digest:
|
|
2132
|
+
per procedure version, its lineage, every execution, tokens, cost and wall
|
|
2133
|
+
time, the outcome of the changes its sessions produced, and the decisions
|
|
2134
|
+
taken on it. With --intents, also each typed turn's intent: the versions
|
|
2135
|
+
that served it, its cost and how it ended; the labeler module's default
|
|
2136
|
+
export labels turns, and without one no turn has a kind or a correction.
|
|
2137
|
+
The JSON registry goes to stdout and the table to stderr.
|
|
780
2138
|
version
|
|
781
2139
|
Print server + wire-protocol version JSON.
|
|
782
2140
|
|
|
@@ -843,6 +2201,8 @@ async function main() {
|
|
|
843
2201
|
case "rollout-release": return await runRolloutReleaseCli(process.argv.slice(3));
|
|
844
2202
|
case "analyst-benchmark": return await runAnalystBenchmarkCommand(process.argv.slice(3));
|
|
845
2203
|
case "supervisor-run": return await runSupervisorRunCommand(process.argv.slice(3));
|
|
2204
|
+
case "skill-usage": return await runSkillUsageCommand(process.argv.slice(3));
|
|
2205
|
+
case "procedure-registry": return await runProcedureRegistryCommand(process.argv.slice(3));
|
|
846
2206
|
case "version":
|
|
847
2207
|
process.stdout.write(`${JSON.stringify(handleVersion(), null, 2)}\n`);
|
|
848
2208
|
return 0;
|
|
@@ -877,7 +2237,7 @@ const FLAGS_BY_COMMAND = {
|
|
|
877
2237
|
"": /* @__PURE__ */ new Set()
|
|
878
2238
|
};
|
|
879
2239
|
function assertKnownFlags(command, flags) {
|
|
880
|
-
if (command === "rollout-release" || command === "analyst-benchmark" || command === "supervisor-run" || command === "search") return;
|
|
2240
|
+
if (command === "rollout-release" || command === "analyst-benchmark" || command === "supervisor-run" || command === "skill-usage" || command === "procedure-registry" || command === "search") return;
|
|
881
2241
|
const allowed = FLAGS_BY_COMMAND[command];
|
|
882
2242
|
if (!allowed) return;
|
|
883
2243
|
const unknown = Object.keys(flags).filter((flag) => !allowed.has(flag));
|