@tangle-network/agent-eval 2.0.11 → 2.0.12
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 +16 -0
- package/dist/adapters/http.d.ts +2 -2
- package/dist/{agent-profile-_JzxgLDM.d.ts → agent-profile-C0FBdYa6.d.ts} +3 -3
- package/dist/{agent-profile-_JzxgLDM.d.ts.map → agent-profile-C0FBdYa6.d.ts.map} +1 -1
- package/dist/analyst/index.d.ts +292 -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-Be5O6A2v.js} +797 -13
- package/dist/benchmark-command-Be5O6A2v.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 +5 -5
- package/dist/campaign/index.js +10 -10
- package/dist/{campaign-eus7YRs2.js → campaign-CE08mvQO.js} +11 -11
- package/dist/{campaign-eus7YRs2.js.map → campaign-CE08mvQO.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-DRvr7lZU.d.ts} +2 -2
- package/dist/{campaign-evidence-BOcX4w0r.d.ts.map → campaign-evidence-DRvr7lZU.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 +778 -10
- package/dist/cli.js.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 +8 -8
- 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-DFRlBniE.d.ts} +2 -2
- package/dist/{default-registry-X8McMoUV.d.ts.map → default-registry-DFRlBniE.d.ts.map} +1 -1
- package/dist/{define-agent-eval-D8ntOXqV.js → define-agent-eval-BHn6t-DC.js} +4 -4
- package/dist/{define-agent-eval-D8ntOXqV.js.map → define-agent-eval-BHn6t-DC.js.map} +1 -1
- package/dist/{define-agent-eval-DH5-xi-F.d.ts → define-agent-eval-n63vmQMR.d.ts} +4 -4
- package/dist/{define-agent-eval-DH5-xi-F.d.ts.map → define-agent-eval-n63vmQMR.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-BAisv8ZR.js → evaluation-DqfNMaKr.js} +2 -2
- package/dist/{evaluation-BAisv8ZR.js.map → evaluation-DqfNMaKr.js.map} +1 -1
- package/dist/{evaluation-CjZH6gW0.d.ts → evaluation-VbjqORBn.d.ts} +2 -2
- package/dist/{evaluation-CjZH6gW0.d.ts.map → evaluation-VbjqORBn.d.ts.map} +1 -1
- package/dist/evaluation.d.ts +1 -1
- package/dist/evaluation.js +1 -1
- package/dist/experiment/index.d.ts +1 -1
- 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.js +1 -1
- package/dist/{index-BmWw8zN6.d.ts → index-BEXEYURJ.d.ts} +7 -7
- package/dist/{index-BmWw8zN6.d.ts.map → index-BEXEYURJ.d.ts.map} +1 -1
- package/dist/{index-Cn9gB5Ca.d.ts → index-CbzPtg7O.d.ts} +205 -29
- package/dist/index-CbzPtg7O.d.ts.map +1 -0
- package/dist/{index-CCOaNmh2.d.ts → index-Dt3zWlRa.d.ts} +3 -3
- package/dist/{index-CCOaNmh2.d.ts.map → index-Dt3zWlRa.d.ts.map} +1 -1
- package/dist/{index-aRalB_Ma.d.ts → index-rrPT3Pw0.d.ts} +2 -2
- package/dist/{index-aRalB_Ma.d.ts.map → index-rrPT3Pw0.d.ts.map} +1 -1
- package/dist/index.d.ts +13 -13
- 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-CgF3ZM3R.js} +4 -4
- package/dist/{llm-judge-DYmEdo3M.js.map → llm-judge-CgF3ZM3R.js.map} +1 -1
- package/dist/{matrix-BDl7hoBr.d.ts → matrix-B95YsrV7.d.ts} +2 -2
- package/dist/{matrix-BDl7hoBr.d.ts.map → matrix-B95YsrV7.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-1xzXK-B6.js} +9 -9
- package/dist/{optimization-method-4JlbMxd2.js.map → optimization-method-1xzXK-B6.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-BPhkYKV2.d.ts} +5 -5
- package/dist/{run-improvement-loop-BeHu5D9Z.d.ts.map → run-improvement-loop-BPhkYKV2.d.ts.map} +1 -1
- package/dist/search/index.d.ts +2 -2
- package/dist/search/index.js +2 -2
- package/dist/{search-kernel-mZc79S6N.js → search-kernel-BkkDo75N.js} +2 -2
- package/dist/{search-kernel-mZc79S6N.js.map → search-kernel-BkkDo75N.js.map} +1 -1
- package/dist/{search-kernel-CJZ-ZSV1.d.ts → search-kernel-CDSEWa2X.d.ts} +2 -2
- package/dist/{search-kernel-CJZ-ZSV1.d.ts.map → search-kernel-CDSEWa2X.d.ts.map} +1 -1
- package/dist/{search-ledger-C7t68cmy.js → search-ledger-sormHFLS.js} +17 -1
- package/dist/search-ledger-sormHFLS.js.map +1 -0
- package/dist/{search-shipper-CmDW9dU6.js → search-shipper-BJ2Bkx2q.js} +2 -2
- package/dist/{search-shipper-CmDW9dU6.js.map → search-shipper-BJ2Bkx2q.js.map} +1 -1
- package/dist/{search-summary-CCgP2qXz.js → search-summary-DMckFUNY.js} +2 -2
- package/dist/{search-summary-CCgP2qXz.js.map → search-summary-DMckFUNY.js.map} +1 -1
- package/dist/{self-improve-C_Bcdmv8.js → self-improve-CMrPmjYE.js} +5 -5
- package/dist/{self-improve-C_Bcdmv8.js.map → self-improve-CMrPmjYE.js.map} +1 -1
- package/dist/{self-improve-B1fsNejr.d.ts → self-improve-D0TtJz4e.d.ts} +5 -5
- package/dist/{self-improve-B1fsNejr.d.ts.map → self-improve-D0TtJz4e.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-D-BPMi8J.js} +9 -9
- package/dist/{skillopt-optimization-method-DHk1K757.js.map → skillopt-optimization-method-D-BPMi8J.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-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-C26IFS-a.d.ts} +3 -3
- package/dist/{systemone-4PadCE4C.d.ts.map → systemone-C26IFS-a.d.ts.map} +1 -1
- package/dist/systemone.d.ts +2 -2
- package/dist/systemone.js +2 -2
- package/dist/traces.js +3 -3
- package/dist/{tree-CiIe-f3f.js → tree-BX9ykHi3.js} +3 -3
- package/dist/{tree-CiIe-f3f.js.map → tree-BX9ykHi3.js.map} +1 -1
- package/dist/{types-D5XtEH9Q.d.ts → types-CBT-XcX5.d.ts} +14 -1
- package/dist/types-CBT-XcX5.d.ts.map +1 -0
- package/dist/{types-Bte3EsFQ.d.ts → types-CYPV2dlR.d.ts} +2 -2
- package/dist/{types-Bte3EsFQ.d.ts.map → types-CYPV2dlR.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/skill-eval.md +103 -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/types-D5XtEH9Q.d.ts.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
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-sormHFLS.js";
|
|
5
|
+
import { o as operatorYield, s as INSUFFICIENT_FROM } from "./search-kernel-BkkDo75N.js";
|
|
6
|
+
import { t as renderSearchSummary } from "./search-summary-DMckFUNY.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-BJ2Bkx2q.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, L as afterInvocation, R as buildSkillUsageReport, U as readSkillFile, V as claudeCodeSkillSessions, t as runAnalystBenchmarkCommand, z as instant } from "./benchmark-command-Be5O6A2v.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-BX9ykHi3.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";
|
|
@@ -84,6 +85,759 @@ function nonEmpty(value) {
|
|
|
84
85
|
const trimmed = value?.trim();
|
|
85
86
|
return trimmed ? trimmed : void 0;
|
|
86
87
|
}
|
|
88
|
+
// src/skill-usage/command.ts
|
|
89
|
+
/**
|
|
90
|
+
* `agent-eval skill-usage <transcripts-dir>` reads a directory of Claude Code
|
|
91
|
+
* transcripts and prints the skill-usage report.
|
|
92
|
+
*
|
|
93
|
+
* By default the JSON report goes to stdout and the short table to stderr, so
|
|
94
|
+
* `> report.json` keeps the report while the table stays on the terminal.
|
|
95
|
+
*
|
|
96
|
+
* `--pricing <file>` names a JSON object of per-million rates by model id, for a
|
|
97
|
+
* model the cost ledger has no rate for or prices too coarsely (its table has no
|
|
98
|
+
* cache-read rate).
|
|
99
|
+
*
|
|
100
|
+
* Exit codes follow the other self-parsing subcommands: 2 for a usage error, 1
|
|
101
|
+
* when the directory cannot be read, 0 after the report was written.
|
|
102
|
+
*/
|
|
103
|
+
const FORMATS$2 = [
|
|
104
|
+
"both",
|
|
105
|
+
"json",
|
|
106
|
+
"table"
|
|
107
|
+
];
|
|
108
|
+
const USAGE$2 = "usage: agent-eval skill-usage <transcripts-dir> [--since <7d|36h|90m|ISO time>] [--format both|json|table] [--limit <rows>] [--pricing <rates.json>]";
|
|
109
|
+
const PROCESS_IO$2 = {
|
|
110
|
+
stdout: (text) => {
|
|
111
|
+
process.stdout.write(text);
|
|
112
|
+
},
|
|
113
|
+
stderr: (text) => {
|
|
114
|
+
process.stderr.write(text);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const DURATION = /^(\d+(?:\.\d+)?)([dhm])$/;
|
|
118
|
+
const UNIT_MS = {
|
|
119
|
+
d: 864e5,
|
|
120
|
+
h: 36e5,
|
|
121
|
+
m: 6e4
|
|
122
|
+
};
|
|
123
|
+
/** `7d`, `36h` or `90m` back from `nowMs`, or an ISO instant. */
|
|
124
|
+
function parseSince(raw, nowMs) {
|
|
125
|
+
const duration = DURATION.exec(raw);
|
|
126
|
+
if (duration !== null) return nowMs - Number(duration[1]) * UNIT_MS[duration[2]];
|
|
127
|
+
const at = Date.parse(raw);
|
|
128
|
+
if (!Number.isFinite(at)) throw new Error(`--since expects a duration such as 7d or an ISO time, got ${JSON.stringify(raw)}`);
|
|
129
|
+
return at;
|
|
130
|
+
}
|
|
131
|
+
function parseArgs$3(argv) {
|
|
132
|
+
const args = {
|
|
133
|
+
directory: "",
|
|
134
|
+
since: null,
|
|
135
|
+
format: "both",
|
|
136
|
+
limit: 30,
|
|
137
|
+
pricing: null
|
|
138
|
+
};
|
|
139
|
+
const value = (flag, index) => {
|
|
140
|
+
const raw = argv[index];
|
|
141
|
+
if (raw === void 0) throw new Error(`${flag} expects a value`);
|
|
142
|
+
return raw;
|
|
143
|
+
};
|
|
144
|
+
for (let i = 0; i < argv.length; i++) {
|
|
145
|
+
const arg = argv[i];
|
|
146
|
+
if (arg === "--since") args.since = value(arg, ++i);
|
|
147
|
+
else if (arg === "--format") {
|
|
148
|
+
const raw = value(arg, ++i);
|
|
149
|
+
if (!FORMATS$2.includes(raw)) throw new Error(`--format expects one of ${FORMATS$2.join("|")}, got ${JSON.stringify(raw)}`);
|
|
150
|
+
args.format = raw;
|
|
151
|
+
} else if (arg === "--limit") {
|
|
152
|
+
const raw = Number(value(arg, ++i));
|
|
153
|
+
if (!Number.isInteger(raw) || raw < 1) throw new Error("--limit expects a positive integer");
|
|
154
|
+
args.limit = raw;
|
|
155
|
+
} else if (arg === "--pricing") args.pricing = value(arg, ++i);
|
|
156
|
+
else if (arg.startsWith("--")) throw new Error(`unknown flag "${arg}"`);
|
|
157
|
+
else if (args.directory === "") args.directory = arg;
|
|
158
|
+
else throw new Error(`unexpected argument "${arg}"`);
|
|
159
|
+
}
|
|
160
|
+
if (args.directory === "") throw new Error("a transcripts directory is required");
|
|
161
|
+
return args;
|
|
162
|
+
}
|
|
163
|
+
const RATE_FIELDS = [
|
|
164
|
+
"inputUsdPerMillion",
|
|
165
|
+
"cachedInputUsdPerMillion",
|
|
166
|
+
"cacheWriteUsdPerMillion",
|
|
167
|
+
"outputUsdPerMillion"
|
|
168
|
+
];
|
|
169
|
+
/** A rates file: `{ "<model id>": { inputUsdPerMillion, outputUsdPerMillion, ... } }`. */
|
|
170
|
+
function readPricingFile(path) {
|
|
171
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
172
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error(`--pricing ${path}: expected a JSON object of rates by model id`);
|
|
173
|
+
const rates = /* @__PURE__ */ new Map();
|
|
174
|
+
for (const [model, value] of Object.entries(parsed)) {
|
|
175
|
+
const fields = typeof value === "object" && value !== null ? value : {};
|
|
176
|
+
for (const field of RATE_FIELDS) {
|
|
177
|
+
const rate = fields[field];
|
|
178
|
+
if (typeof rate !== "number" && (field === "inputUsdPerMillion" || field === "outputUsdPerMillion" || rate !== void 0)) throw new Error(`--pricing ${path}: ${JSON.stringify(model)}.${field} must be a number`);
|
|
179
|
+
}
|
|
180
|
+
const pricing = fields;
|
|
181
|
+
costForTokenPricing(pricing, {
|
|
182
|
+
inputTokens: 0,
|
|
183
|
+
outputTokens: 0
|
|
184
|
+
});
|
|
185
|
+
rates.set(model, pricing);
|
|
186
|
+
}
|
|
187
|
+
return rates;
|
|
188
|
+
}
|
|
189
|
+
async function runSkillUsageCommand(argv, io = PROCESS_IO$2) {
|
|
190
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
191
|
+
io.stdout(`${USAGE$2}\n`);
|
|
192
|
+
return 0;
|
|
193
|
+
}
|
|
194
|
+
let args;
|
|
195
|
+
let sinceMs;
|
|
196
|
+
let rates;
|
|
197
|
+
try {
|
|
198
|
+
args = parseArgs$3(argv);
|
|
199
|
+
rates = args.pricing === null ? void 0 : readPricingFile(resolve(args.pricing));
|
|
200
|
+
sinceMs = args.since === null ? void 0 : parseSince(args.since, (io.now ?? Date.now)());
|
|
201
|
+
} catch (error) {
|
|
202
|
+
io.stderr(`${errorMessage(error)}\n${USAGE$2}\n`);
|
|
203
|
+
return 2;
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
const report = await buildSkillUsageReport(claudeCodeSkillSessions(resolve(args.directory), sinceMs === void 0 ? {} : { sinceMs }), {
|
|
207
|
+
...sinceMs === void 0 ? {} : { sinceMs },
|
|
208
|
+
...rates === void 0 ? {} : { pricing: (model) => rates?.get(model) },
|
|
209
|
+
readSkillFile
|
|
210
|
+
});
|
|
211
|
+
const table = renderSkillUsageTable(report, args.limit);
|
|
212
|
+
if (args.format === "table") io.stdout(table);
|
|
213
|
+
else {
|
|
214
|
+
io.stdout(`${JSON.stringify(report, null, 2)}\n`);
|
|
215
|
+
if (args.format === "both") io.stderr(table);
|
|
216
|
+
}
|
|
217
|
+
return 0;
|
|
218
|
+
} catch (error) {
|
|
219
|
+
io.stderr(`agent-eval skill-usage: ${errorMessage(error)}\n`);
|
|
220
|
+
return 1;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Index outcomes by change reference. An outcome judged over another window
|
|
225
|
+
* keeps `merged` and `gateGreenFirstTry` and loses `hotfixed`: a 3-day and a
|
|
226
|
+
* 14-day "no fix" are different claims, and the registry has one definition.
|
|
227
|
+
* Two outcomes for one reference must agree; a reference given twice with
|
|
228
|
+
* different readings throws.
|
|
229
|
+
*/
|
|
230
|
+
function indexChangeOutcomes(outcomes) {
|
|
231
|
+
const byRef = /* @__PURE__ */ new Map();
|
|
232
|
+
let otherWindow = 0;
|
|
233
|
+
let duplicates = 0;
|
|
234
|
+
for (const outcome of outcomes) {
|
|
235
|
+
if (typeof outcome.ref !== "string" || outcome.ref === "") throw new ValidationError("a change outcome needs a non-empty ref");
|
|
236
|
+
const sameWindow = outcome.hotfixWindowDays === 7;
|
|
237
|
+
if (!sameWindow) otherWindow += 1;
|
|
238
|
+
const reading = {
|
|
239
|
+
ref: outcome.ref,
|
|
240
|
+
merged: outcome.merged,
|
|
241
|
+
gateGreenFirstTry: outcome.gateGreenFirstTry,
|
|
242
|
+
hotfixed: sameWindow ? outcome.hotfixed : null
|
|
243
|
+
};
|
|
244
|
+
const known = byRef.get(outcome.ref);
|
|
245
|
+
if (known !== void 0) {
|
|
246
|
+
duplicates += 1;
|
|
247
|
+
if (JSON.stringify(known) !== JSON.stringify(reading)) throw new ValidationError(`change ${outcome.ref} has two different outcomes`);
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
byRef.set(outcome.ref, reading);
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
byRef,
|
|
254
|
+
otherWindow,
|
|
255
|
+
duplicates
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* The changes an invocation produced: those of its session, and of every
|
|
260
|
+
* session that spawned it, since a subagent's work belongs to the change its
|
|
261
|
+
* parent shipped. A session absent from `sessions` ends the walk, and a cycle
|
|
262
|
+
* in the parent links is cut where it repeats.
|
|
263
|
+
*/
|
|
264
|
+
function joinInvocationToChanges(sessionId, sessions, outcomes) {
|
|
265
|
+
const refs = /* @__PURE__ */ new Set();
|
|
266
|
+
let recorded = false;
|
|
267
|
+
const visited = /* @__PURE__ */ new Set();
|
|
268
|
+
for (let current = sessionId; current !== null && !visited.has(current); current = sessions.get(current)?.parentSessionId ?? null) {
|
|
269
|
+
visited.add(current);
|
|
270
|
+
const session = sessions.get(current);
|
|
271
|
+
if (session?.refs === void 0) continue;
|
|
272
|
+
recorded = true;
|
|
273
|
+
for (const ref of session.refs) refs.add(ref);
|
|
274
|
+
}
|
|
275
|
+
if (!recorded) return { status: "not-recorded" };
|
|
276
|
+
if (refs.size === 0) return { status: "none" };
|
|
277
|
+
const sorted = [...refs].sort();
|
|
278
|
+
return {
|
|
279
|
+
status: "joined",
|
|
280
|
+
refs: sorted,
|
|
281
|
+
outcomes: sorted.flatMap((ref) => {
|
|
282
|
+
const reading = outcomes.byRef.get(ref);
|
|
283
|
+
return reading === void 0 ? [] : [reading];
|
|
284
|
+
})
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
// src/procedure-registry/registry.ts
|
|
288
|
+
const NOTES = [
|
|
289
|
+
"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.",
|
|
290
|
+
"Search-cell and session measures are different quantities (a cell is one task, a session is open-ended) and are never added together.",
|
|
291
|
+
"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."
|
|
292
|
+
];
|
|
293
|
+
function normalizeDigest(value) {
|
|
294
|
+
const hex = value.startsWith("sha256:") ? value.slice(7) : value;
|
|
295
|
+
if (!/^[0-9a-f]{64}$/.test(hex)) throw new ValidationError(`a procedure digest is a sha256, got ${JSON.stringify(value)}`);
|
|
296
|
+
return `sha256:${hex}`;
|
|
297
|
+
}
|
|
298
|
+
function compareText(a, b) {
|
|
299
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
300
|
+
}
|
|
301
|
+
function emptyMeasure() {
|
|
302
|
+
return {
|
|
303
|
+
sum: 0,
|
|
304
|
+
measured: 0,
|
|
305
|
+
unmeasured: 0
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
function addMeasure(total, value) {
|
|
309
|
+
if (value === null) total.unmeasured += 1;
|
|
310
|
+
else {
|
|
311
|
+
total.sum += value;
|
|
312
|
+
total.measured += 1;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function emptyCounts() {
|
|
316
|
+
return {
|
|
317
|
+
yes: 0,
|
|
318
|
+
no: 0,
|
|
319
|
+
unknown: 0
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function count(counts, value) {
|
|
323
|
+
if (value === null) counts.unknown += 1;
|
|
324
|
+
else if (value) counts.yes += 1;
|
|
325
|
+
else counts.no += 1;
|
|
326
|
+
}
|
|
327
|
+
/** The caller's reading of one change field, across the readings of every outcome the change has. */
|
|
328
|
+
function pick(readings, field) {
|
|
329
|
+
return readings === void 0 ? null : readings[field];
|
|
330
|
+
}
|
|
331
|
+
function summarizeChanges(executions, index) {
|
|
332
|
+
const changes = {
|
|
333
|
+
invocations: executions.length,
|
|
334
|
+
joined: 0,
|
|
335
|
+
none: 0,
|
|
336
|
+
notRecorded: 0,
|
|
337
|
+
distinctChanges: 0,
|
|
338
|
+
withOutcome: 0,
|
|
339
|
+
merged: emptyCounts(),
|
|
340
|
+
gateGreenFirstTry: emptyCounts(),
|
|
341
|
+
hotfixed: emptyCounts()
|
|
342
|
+
};
|
|
343
|
+
const refs = /* @__PURE__ */ new Set();
|
|
344
|
+
for (const execution of executions) {
|
|
345
|
+
const joined = execution.changes;
|
|
346
|
+
if (joined.status === "joined") {
|
|
347
|
+
changes.joined += 1;
|
|
348
|
+
for (const ref of joined.refs) refs.add(ref);
|
|
349
|
+
} else if (joined.status === "none") changes.none += 1;
|
|
350
|
+
else changes.notRecorded += 1;
|
|
351
|
+
}
|
|
352
|
+
changes.distinctChanges = refs.size;
|
|
353
|
+
for (const ref of [...refs].sort(compareText)) {
|
|
354
|
+
const reading = index.byRef.get(ref);
|
|
355
|
+
if (reading !== void 0) changes.withOutcome += 1;
|
|
356
|
+
count(changes.merged, pick(reading, "merged"));
|
|
357
|
+
count(changes.gateGreenFirstTry, pick(reading, "gateGreenFirstTry"));
|
|
358
|
+
count(changes.hotfixed, pick(reading, "hotfixed"));
|
|
359
|
+
}
|
|
360
|
+
return changes;
|
|
361
|
+
}
|
|
362
|
+
var Registry = class {
|
|
363
|
+
builders = /* @__PURE__ */ new Map();
|
|
364
|
+
builder(key) {
|
|
365
|
+
let builder = this.builders.get(key);
|
|
366
|
+
if (builder === void 0) {
|
|
367
|
+
builder = {
|
|
368
|
+
key,
|
|
369
|
+
digest: key.startsWith("sha256:") ? key : null,
|
|
370
|
+
names: /* @__PURE__ */ new Set(),
|
|
371
|
+
kind: null,
|
|
372
|
+
parents: /* @__PURE__ */ new Set(),
|
|
373
|
+
edges: [],
|
|
374
|
+
searches: [],
|
|
375
|
+
decisions: [],
|
|
376
|
+
executions: []
|
|
377
|
+
};
|
|
378
|
+
this.builders.set(key, builder);
|
|
379
|
+
}
|
|
380
|
+
return builder;
|
|
381
|
+
}
|
|
382
|
+
all() {
|
|
383
|
+
return [...this.builders.values()];
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
const nodeKey = (searchId, nodeId) => `${searchId}\u0000${nodeId}`;
|
|
387
|
+
function addSearch(registry, search, keys, options) {
|
|
388
|
+
const subject = search.header?.subject ?? "";
|
|
389
|
+
const closed = search.closed !== null;
|
|
390
|
+
const claim = search.closed?.claim ?? null;
|
|
391
|
+
const rootNodeId = search.rootNodeId;
|
|
392
|
+
for (const node of search.nodes()) {
|
|
393
|
+
const key = keys.get(nodeKey(search.searchId, node.nodeId));
|
|
394
|
+
const identity = options.procedureOfNode?.(node, search) ?? null;
|
|
395
|
+
const builder = registry.builder(key);
|
|
396
|
+
if (identity?.kind !== void 0) builder.kind = identity.kind;
|
|
397
|
+
if (identity?.name !== void 0) builder.names.add(identity.name);
|
|
398
|
+
const latest = node.decisions.at(-1);
|
|
399
|
+
builder.searches.push({
|
|
400
|
+
searchId: search.searchId,
|
|
401
|
+
nodeId: node.nodeId,
|
|
402
|
+
subject,
|
|
403
|
+
closed,
|
|
404
|
+
status: latest === void 0 ? null : latest.decision.status
|
|
405
|
+
});
|
|
406
|
+
const resolve = (ref) => {
|
|
407
|
+
const parentKey = keys.get(nodeKey(ref.searchId, ref.nodeId));
|
|
408
|
+
return parentKey?.startsWith("sha256:") ? parentKey : null;
|
|
409
|
+
};
|
|
410
|
+
for (const parent of node.parents) {
|
|
411
|
+
const digest = resolve(parent);
|
|
412
|
+
if (digest !== null) builder.parents.add(digest);
|
|
413
|
+
}
|
|
414
|
+
node.edgeIds.forEach((edgeId, position) => {
|
|
415
|
+
const edge = search.edge(edgeId);
|
|
416
|
+
if (edge === void 0) return;
|
|
417
|
+
builder.edges.push({
|
|
418
|
+
searchId: search.searchId,
|
|
419
|
+
edgeId,
|
|
420
|
+
operator: edge.operator,
|
|
421
|
+
attribution: edge.attribution,
|
|
422
|
+
proposer: edge.proposer === null ? null : {
|
|
423
|
+
kind: edge.proposer.kind,
|
|
424
|
+
name: edge.proposer.name
|
|
425
|
+
},
|
|
426
|
+
parents: edge.parents.map((parent) => ({
|
|
427
|
+
searchId: parent.searchId,
|
|
428
|
+
nodeId: parent.nodeId,
|
|
429
|
+
digest: resolve(parent)
|
|
430
|
+
})),
|
|
431
|
+
reproposal: position > 0
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
node.decisions.forEach((record, position) => {
|
|
435
|
+
builder.decisions.push({
|
|
436
|
+
searchId: search.searchId,
|
|
437
|
+
nodeId: node.nodeId,
|
|
438
|
+
source: "node-decided",
|
|
439
|
+
status: record.decision.status,
|
|
440
|
+
rung: record.decision.status === "advanced" ? record.decision.rung : null,
|
|
441
|
+
rule: record.rule,
|
|
442
|
+
reason: record.reason,
|
|
443
|
+
current: position === node.decisions.length - 1
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
for (const cell of search.cells({ nodeId: node.nodeId })) {
|
|
447
|
+
if (cell.attempts === 0) continue;
|
|
448
|
+
builder.executions.push({
|
|
449
|
+
source: "search-cell",
|
|
450
|
+
searchId: search.searchId,
|
|
451
|
+
nodeId: node.nodeId,
|
|
452
|
+
cellId: cell.cellId,
|
|
453
|
+
split: cell.split,
|
|
454
|
+
stage: cell.stage,
|
|
455
|
+
outcome: cell.outcome,
|
|
456
|
+
score: cell.score,
|
|
457
|
+
tokens: cell.tokensKnown ? cell.tokens.inputTokens + cell.tokens.outputTokens + cell.tokens.cachedTokens : null,
|
|
458
|
+
usd: cell.costKnown ? cell.spentUsd : null,
|
|
459
|
+
wallMs: cell.wallKnown ? cell.wallMs : null
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (claim !== null) {
|
|
464
|
+
const nodeId = claim.selected ?? rootNodeId;
|
|
465
|
+
const key = nodeId === null ? void 0 : keys.get(nodeKey(search.searchId, nodeId));
|
|
466
|
+
if (nodeId !== null && key !== void 0) registry.builder(key).decisions.push({
|
|
467
|
+
searchId: search.searchId,
|
|
468
|
+
nodeId,
|
|
469
|
+
source: "claim",
|
|
470
|
+
status: claim.decision,
|
|
471
|
+
rung: null,
|
|
472
|
+
rule: claim.rule.uri,
|
|
473
|
+
reason: claim.reason,
|
|
474
|
+
current: true
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Build the registry from search ledgers, recorded sessions and the outcomes of
|
|
480
|
+
* the changes those sessions produced. Any of the three may be absent.
|
|
481
|
+
*
|
|
482
|
+
* An invocation is counted once per call id across the whole source, and with
|
|
483
|
+
* `sinceMs` only invocations at or after it count, exactly as `skill-usage`
|
|
484
|
+
* counts them; an undated invocation cannot be placed in the window and is
|
|
485
|
+
* left out. Versions are ordered by executions, most first, then by key.
|
|
486
|
+
*/
|
|
487
|
+
async function buildProcedureRegistry(input, options = {}) {
|
|
488
|
+
if (options.sinceMs !== void 0 && !Number.isFinite(options.sinceMs)) throw new ValidationError(`buildProcedureRegistry: sinceMs must be finite, got ${options.sinceMs}`);
|
|
489
|
+
const outcomes = indexChangeOutcomes(input.outcomes ?? []);
|
|
490
|
+
const registry = new Registry();
|
|
491
|
+
const searches = [...input.searches ?? []];
|
|
492
|
+
const keys = /* @__PURE__ */ new Map();
|
|
493
|
+
for (const search of searches) for (const node of search.nodes()) {
|
|
494
|
+
const identity = options.procedureOfNode?.(node, search) ?? null;
|
|
495
|
+
keys.set(nodeKey(search.searchId, node.nodeId), normalizeDigest(identity?.digest ?? node.artifactDigest));
|
|
496
|
+
}
|
|
497
|
+
for (const search of searches) addSearch(registry, search, keys, options);
|
|
498
|
+
const sessionChanges = /* @__PURE__ */ new Map();
|
|
499
|
+
const pending = [];
|
|
500
|
+
const unreadable = [];
|
|
501
|
+
const seenCalls = /* @__PURE__ */ new Set();
|
|
502
|
+
const sessions = {
|
|
503
|
+
read: 0,
|
|
504
|
+
unreadable: 0,
|
|
505
|
+
withInvocation: 0
|
|
506
|
+
};
|
|
507
|
+
const versionDigest = (event) => {
|
|
508
|
+
if (event.version !== null) return event.version.bodySha256;
|
|
509
|
+
if (event.skillFile === null || options.readSkillFile === void 0) return null;
|
|
510
|
+
const file = options.readSkillFile(event.skillFile);
|
|
511
|
+
return file.succeeded ? file.bodySha256 : null;
|
|
512
|
+
};
|
|
513
|
+
for await (const read of input.sessions ?? []) {
|
|
514
|
+
if (!read.succeeded) {
|
|
515
|
+
sessions.unreadable += 1;
|
|
516
|
+
unreadable.push({
|
|
517
|
+
source: read.source,
|
|
518
|
+
error: read.error
|
|
519
|
+
});
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
const session = read.value;
|
|
523
|
+
sessions.read += 1;
|
|
524
|
+
sessionChanges.set(session.sessionId, {
|
|
525
|
+
parentSessionId: session.parentSessionId,
|
|
526
|
+
refs: session.changes?.map((change) => change.ref)
|
|
527
|
+
});
|
|
528
|
+
let counted = false;
|
|
529
|
+
session.events.forEach((event, position) => {
|
|
530
|
+
if (event.kind !== "skill") return;
|
|
531
|
+
if (seenCalls.has(event.callId)) return;
|
|
532
|
+
seenCalls.add(event.callId);
|
|
533
|
+
if (options.sinceMs !== void 0) {
|
|
534
|
+
const at = instant(event.at);
|
|
535
|
+
if (at === null || at < options.sinceMs) return;
|
|
536
|
+
}
|
|
537
|
+
counted = true;
|
|
538
|
+
const hex = versionDigest(event);
|
|
539
|
+
const key = hex === null ? `unversioned:${event.skill}` : normalizeDigest(hex);
|
|
540
|
+
const builder = registry.builder(key);
|
|
541
|
+
builder.names.add(event.skill);
|
|
542
|
+
builder.kind ??= options.kindOfSkill?.(event.skill) ?? "skill";
|
|
543
|
+
const after = afterInvocation(session, position, event.at, options);
|
|
544
|
+
pending.push({
|
|
545
|
+
builderKey: key,
|
|
546
|
+
sessionId: session.sessionId,
|
|
547
|
+
harness: session.harness,
|
|
548
|
+
event,
|
|
549
|
+
measures: {
|
|
550
|
+
tokens: after.modelCalls > 0 && after.modelCallsWithoutUsage === 0 ? after.tokens.total : null,
|
|
551
|
+
usd: after.pricedModelCalls > 0 && after.unpricedModelCalls === 0 ? after.costUsd : null,
|
|
552
|
+
wallMs: after.wallMs
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
if (counted) sessions.withInvocation += 1;
|
|
557
|
+
}
|
|
558
|
+
const joins = {
|
|
559
|
+
joined: 0,
|
|
560
|
+
none: 0,
|
|
561
|
+
notRecorded: 0,
|
|
562
|
+
withOutcome: 0
|
|
563
|
+
};
|
|
564
|
+
const joinedRefs = /* @__PURE__ */ new Set();
|
|
565
|
+
for (const invocation of pending) {
|
|
566
|
+
const { event } = invocation;
|
|
567
|
+
const changes = joinInvocationToChanges(invocation.sessionId, sessionChanges, outcomes);
|
|
568
|
+
if (changes.status === "joined") {
|
|
569
|
+
joins.joined += 1;
|
|
570
|
+
for (const ref of changes.refs) joinedRefs.add(ref);
|
|
571
|
+
if (changes.outcomes.length > 0) joins.withOutcome += 1;
|
|
572
|
+
} else if (changes.status === "none") joins.none += 1;
|
|
573
|
+
else joins.notRecorded += 1;
|
|
574
|
+
registry.builder(invocation.builderKey).executions.push({
|
|
575
|
+
source: "session",
|
|
576
|
+
harness: invocation.harness,
|
|
577
|
+
sessionId: invocation.sessionId,
|
|
578
|
+
callId: event.callId,
|
|
579
|
+
skill: event.skill,
|
|
580
|
+
invoker: event.invoker,
|
|
581
|
+
at: event.at,
|
|
582
|
+
failed: event.failed,
|
|
583
|
+
...invocation.measures,
|
|
584
|
+
changes
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
const versions = registry.all().map((builder) => {
|
|
588
|
+
const cells = {
|
|
589
|
+
count: 0,
|
|
590
|
+
passed: 0,
|
|
591
|
+
failed: 0,
|
|
592
|
+
errored: 0,
|
|
593
|
+
tokens: emptyMeasure(),
|
|
594
|
+
usd: emptyMeasure(),
|
|
595
|
+
wallMs: emptyMeasure()
|
|
596
|
+
};
|
|
597
|
+
const sessionRuns = {
|
|
598
|
+
invocations: 0,
|
|
599
|
+
tokens: emptyMeasure(),
|
|
600
|
+
usd: emptyMeasure(),
|
|
601
|
+
wallMs: emptyMeasure()
|
|
602
|
+
};
|
|
603
|
+
const runs = [];
|
|
604
|
+
for (const execution of builder.executions) if (execution.source === "search-cell") {
|
|
605
|
+
cells.count += 1;
|
|
606
|
+
if (execution.outcome === "passed") cells.passed += 1;
|
|
607
|
+
else if (execution.outcome === "failed") cells.failed += 1;
|
|
608
|
+
else if (execution.outcome === "errored") cells.errored += 1;
|
|
609
|
+
addMeasure(cells.tokens, execution.tokens);
|
|
610
|
+
addMeasure(cells.usd, execution.usd);
|
|
611
|
+
addMeasure(cells.wallMs, execution.wallMs);
|
|
612
|
+
} else {
|
|
613
|
+
sessionRuns.invocations += 1;
|
|
614
|
+
addMeasure(sessionRuns.tokens, execution.tokens);
|
|
615
|
+
addMeasure(sessionRuns.usd, execution.usd);
|
|
616
|
+
addMeasure(sessionRuns.wallMs, execution.wallMs);
|
|
617
|
+
runs.push(execution);
|
|
618
|
+
}
|
|
619
|
+
return {
|
|
620
|
+
key: builder.key,
|
|
621
|
+
digest: builder.digest,
|
|
622
|
+
names: [...builder.names].sort(compareText),
|
|
623
|
+
kind: builder.kind,
|
|
624
|
+
parents: [...builder.parents].sort(compareText),
|
|
625
|
+
edges: builder.edges,
|
|
626
|
+
searches: builder.searches,
|
|
627
|
+
decisions: builder.decisions,
|
|
628
|
+
cells,
|
|
629
|
+
sessions: {
|
|
630
|
+
...sessionRuns,
|
|
631
|
+
changes: summarizeChanges(runs, outcomes)
|
|
632
|
+
},
|
|
633
|
+
executions: builder.executions
|
|
634
|
+
};
|
|
635
|
+
});
|
|
636
|
+
versions.sort((a, b) => {
|
|
637
|
+
const left = a.cells.count + a.sessions.invocations;
|
|
638
|
+
const right = b.cells.count + b.sessions.invocations;
|
|
639
|
+
return left !== right ? right - left : compareText(a.key, b.key);
|
|
640
|
+
});
|
|
641
|
+
const share = (part) => pending.length === 0 ? null : part / pending.length;
|
|
642
|
+
return {
|
|
643
|
+
searches: {
|
|
644
|
+
read: searches.length,
|
|
645
|
+
closed: searches.filter((s) => s.closed !== null).length
|
|
646
|
+
},
|
|
647
|
+
sessions,
|
|
648
|
+
invocations: pending.length,
|
|
649
|
+
changeJoin: {
|
|
650
|
+
hotfixWindowDays: 7,
|
|
651
|
+
invocations: pending.length,
|
|
652
|
+
...joins,
|
|
653
|
+
joinedShare: share(joins.joined),
|
|
654
|
+
withOutcomeShare: share(joins.withOutcome),
|
|
655
|
+
distinctChanges: joinedRefs.size,
|
|
656
|
+
outcomesSupplied: outcomes.byRef.size,
|
|
657
|
+
outcomesInWrongWindow: outcomes.otherWindow
|
|
658
|
+
},
|
|
659
|
+
versions,
|
|
660
|
+
unreadable,
|
|
661
|
+
notes: [...NOTES]
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
// src/procedure-registry/render.ts
|
|
665
|
+
function percent(share) {
|
|
666
|
+
return share === null ? "n/a" : `${(share * 100).toFixed(1)}%`;
|
|
667
|
+
}
|
|
668
|
+
/** A measure's sum, with how many executions did not report it. */
|
|
669
|
+
function measure(total, digits = 0) {
|
|
670
|
+
if (total.measured === 0) return total.unmeasured === 0 ? "-" : "unknown";
|
|
671
|
+
const text = total.sum.toFixed(digits);
|
|
672
|
+
return total.unmeasured === 0 ? text : `${text}+${total.unmeasured}?`;
|
|
673
|
+
}
|
|
674
|
+
function digest(version) {
|
|
675
|
+
return version.digest === null ? "(no version)" : version.digest.slice(7, 19);
|
|
676
|
+
}
|
|
677
|
+
function decided(version) {
|
|
678
|
+
const latest = version.decisions.filter((decision) => decision.current);
|
|
679
|
+
return latest.length === 0 ? "-" : [...new Set(latest.map((d) => d.status))].join(",");
|
|
680
|
+
}
|
|
681
|
+
function renderProcedureRegistryTable(registry, limit = 30) {
|
|
682
|
+
const join = registry.changeJoin;
|
|
683
|
+
const lines = [
|
|
684
|
+
`${registry.versions.length} procedure versions; ${registry.invocations} invocations in ${registry.sessions.read} sessions (${registry.sessions.unreadable} unreadable); ${registry.searches.read} searches`,
|
|
685
|
+
`joined to a change: ${join.joined} of ${join.invocations} invocations (${percent(join.joinedShare)}); none ${join.none}, not recorded ${join.notRecorded}`,
|
|
686
|
+
`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)`,
|
|
687
|
+
"",
|
|
688
|
+
"version kind names cells runs chg-joined merged y/n/? hotfix y/n/? tokens(runs) decided"
|
|
689
|
+
];
|
|
690
|
+
for (const version of registry.versions.slice(0, limit)) {
|
|
691
|
+
const changes = version.sessions.changes;
|
|
692
|
+
const counts = (c) => `${c.yes}/${c.no}/${c.unknown}`;
|
|
693
|
+
lines.push([
|
|
694
|
+
digest(version).padEnd(13),
|
|
695
|
+
(version.kind ?? "unclassified").padEnd(11),
|
|
696
|
+
version.names.join(",").slice(0, 30).padEnd(30),
|
|
697
|
+
String(version.cells.count).padStart(5),
|
|
698
|
+
String(version.sessions.invocations).padStart(5),
|
|
699
|
+
String(changes.joined).padStart(10),
|
|
700
|
+
counts(changes.merged).padStart(13),
|
|
701
|
+
counts(changes.hotfixed).padStart(13),
|
|
702
|
+
measure(version.sessions.tokens).padStart(13),
|
|
703
|
+
decided(version)
|
|
704
|
+
].join(" "));
|
|
705
|
+
}
|
|
706
|
+
if (registry.versions.length > limit) lines.push(`... ${registry.versions.length - limit} more versions in the JSON`);
|
|
707
|
+
for (const note of registry.notes) lines.push("", `note: ${note}`);
|
|
708
|
+
return `${lines.join("\n")}\n`;
|
|
709
|
+
}
|
|
710
|
+
// src/procedure-registry/command.ts
|
|
711
|
+
/**
|
|
712
|
+
* `agent-eval procedure-registry <sessions-dir>` prints the procedure registry
|
|
713
|
+
* for a directory of Claude Code transcripts and any number of search ledgers.
|
|
714
|
+
*
|
|
715
|
+
* `--outcomes <file>` names a JSON array of {@link ChangeOutcome}: what the
|
|
716
|
+
* caller knows of each change the sessions produced. Without it every change is
|
|
717
|
+
* joined and none has an outcome. The JSON registry goes to stdout and the
|
|
718
|
+
* short table to stderr, as `skill-usage` does.
|
|
719
|
+
*
|
|
720
|
+
* Exit codes: 2 for a usage error, 1 when a directory or ledger cannot be
|
|
721
|
+
* read, 0 after the registry was written.
|
|
722
|
+
*/
|
|
723
|
+
const FORMATS$1 = [
|
|
724
|
+
"both",
|
|
725
|
+
"json",
|
|
726
|
+
"table"
|
|
727
|
+
];
|
|
728
|
+
const USAGE$1 = "usage: agent-eval procedure-registry <sessions-dir> [--ledger <search-ledger.jsonl>]... [--since <7d|36h|90m|ISO time>] [--outcomes <changes.json>] [--format both|json|table] [--limit <rows>] [--pricing <rates.json>]";
|
|
729
|
+
const PROCESS_IO$1 = {
|
|
730
|
+
stdout: (text) => {
|
|
731
|
+
process.stdout.write(text);
|
|
732
|
+
},
|
|
733
|
+
stderr: (text) => {
|
|
734
|
+
process.stderr.write(text);
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
function parseArgs$2(argv) {
|
|
738
|
+
const args = {
|
|
739
|
+
directory: "",
|
|
740
|
+
ledgers: [],
|
|
741
|
+
since: null,
|
|
742
|
+
outcomes: null,
|
|
743
|
+
format: "both",
|
|
744
|
+
limit: 30,
|
|
745
|
+
pricing: null
|
|
746
|
+
};
|
|
747
|
+
const value = (flag, index) => {
|
|
748
|
+
const raw = argv[index];
|
|
749
|
+
if (raw === void 0) throw new Error(`${flag} expects a value`);
|
|
750
|
+
return raw;
|
|
751
|
+
};
|
|
752
|
+
for (let i = 0; i < argv.length; i++) {
|
|
753
|
+
const arg = argv[i];
|
|
754
|
+
if (arg === "--ledger") args.ledgers.push(value(arg, ++i));
|
|
755
|
+
else if (arg === "--since") args.since = value(arg, ++i);
|
|
756
|
+
else if (arg === "--outcomes") args.outcomes = value(arg, ++i);
|
|
757
|
+
else if (arg === "--pricing") args.pricing = value(arg, ++i);
|
|
758
|
+
else if (arg === "--format") {
|
|
759
|
+
const raw = value(arg, ++i);
|
|
760
|
+
if (!FORMATS$1.includes(raw)) throw new Error(`--format expects one of ${FORMATS$1.join("|")}, got ${JSON.stringify(raw)}`);
|
|
761
|
+
args.format = raw;
|
|
762
|
+
} else if (arg === "--limit") {
|
|
763
|
+
const raw = Number(value(arg, ++i));
|
|
764
|
+
if (!Number.isInteger(raw) || raw < 1) throw new Error("--limit expects a positive integer");
|
|
765
|
+
args.limit = raw;
|
|
766
|
+
} else if (arg.startsWith("--")) throw new Error(`unknown flag "${arg}"`);
|
|
767
|
+
else if (args.directory === "") args.directory = arg;
|
|
768
|
+
else throw new Error(`unexpected argument "${arg}"`);
|
|
769
|
+
}
|
|
770
|
+
if (args.directory === "") throw new Error("a sessions directory is required");
|
|
771
|
+
return args;
|
|
772
|
+
}
|
|
773
|
+
/** An outcomes file: a JSON array of change outcomes; each field is checked, so a typo is not read as unknown. */
|
|
774
|
+
function readOutcomes(path) {
|
|
775
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
776
|
+
if (!Array.isArray(parsed)) throw new Error(`--outcomes ${path}: expected a JSON array`);
|
|
777
|
+
const tri = (item, field, index) => {
|
|
778
|
+
const raw = item[field];
|
|
779
|
+
if (raw === null || typeof raw === "boolean") return raw;
|
|
780
|
+
throw new Error(`--outcomes ${path}: entry ${index} ${field} must be true, false or null`);
|
|
781
|
+
};
|
|
782
|
+
return parsed.map((entry, index) => {
|
|
783
|
+
const item = typeof entry === "object" && entry !== null ? entry : {};
|
|
784
|
+
if (typeof item.ref !== "string" || item.ref === "") throw new Error(`--outcomes ${path}: entry ${index} needs a ref`);
|
|
785
|
+
if (typeof item.hotfixWindowDays !== "number") throw new Error(`--outcomes ${path}: entry ${index} needs hotfixWindowDays`);
|
|
786
|
+
return {
|
|
787
|
+
ref: item.ref,
|
|
788
|
+
merged: tri(item, "merged", index),
|
|
789
|
+
gateGreenFirstTry: tri(item, "gateGreenFirstTry", index),
|
|
790
|
+
hotfixed: tri(item, "hotfixed", index),
|
|
791
|
+
hotfixWindowDays: item.hotfixWindowDays
|
|
792
|
+
};
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
async function readLedger(path) {
|
|
796
|
+
const text = await readFile(path, "utf8");
|
|
797
|
+
const first = JSON.parse(text.slice(0, Math.max(0, text.indexOf("\n"))));
|
|
798
|
+
if (typeof first.searchId !== "string") throw new Error(`${path} line 1 names no searchId`);
|
|
799
|
+
return replaySearchLedgerText(text, first.searchId, path);
|
|
800
|
+
}
|
|
801
|
+
async function runProcedureRegistryCommand(argv, io = PROCESS_IO$1) {
|
|
802
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
803
|
+
io.stdout(`${USAGE$1}\n`);
|
|
804
|
+
return 0;
|
|
805
|
+
}
|
|
806
|
+
let args;
|
|
807
|
+
let sinceMs;
|
|
808
|
+
let rates;
|
|
809
|
+
let outcomes = [];
|
|
810
|
+
try {
|
|
811
|
+
args = parseArgs$2(argv);
|
|
812
|
+
rates = args.pricing === null ? void 0 : readPricingFile(resolve(args.pricing));
|
|
813
|
+
sinceMs = args.since === null ? void 0 : parseSince(args.since, (io.now ?? Date.now)());
|
|
814
|
+
if (args.outcomes !== null) outcomes = readOutcomes(resolve(args.outcomes));
|
|
815
|
+
} catch (error) {
|
|
816
|
+
io.stderr(`${errorMessage(error)}\n${USAGE$1}\n`);
|
|
817
|
+
return 2;
|
|
818
|
+
}
|
|
819
|
+
try {
|
|
820
|
+
const registry = await buildProcedureRegistry({
|
|
821
|
+
searches: await Promise.all(args.ledgers.map((path) => readLedger(resolve(path)))),
|
|
822
|
+
sessions: claudeCodeSkillSessions(resolve(args.directory), sinceMs === void 0 ? {} : { sinceMs }),
|
|
823
|
+
outcomes
|
|
824
|
+
}, {
|
|
825
|
+
...sinceMs === void 0 ? {} : { sinceMs },
|
|
826
|
+
...rates === void 0 ? {} : { pricing: (model) => rates?.get(model) },
|
|
827
|
+
readSkillFile
|
|
828
|
+
});
|
|
829
|
+
const table = renderProcedureRegistryTable(registry, args.limit);
|
|
830
|
+
if (args.format === "table") io.stdout(table);
|
|
831
|
+
else {
|
|
832
|
+
io.stdout(`${JSON.stringify(registry, null, 2)}\n`);
|
|
833
|
+
if (args.format === "both") io.stderr(table);
|
|
834
|
+
}
|
|
835
|
+
return 0;
|
|
836
|
+
} catch (error) {
|
|
837
|
+
io.stderr(`agent-eval procedure-registry: ${errorMessage(error)}\n`);
|
|
838
|
+
return 1;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
87
841
|
// src/search-command.ts
|
|
88
842
|
/**
|
|
89
843
|
* `agent-eval search <subcommand>`: work with a search ledger from a terminal.
|
|
@@ -707,6 +1461,8 @@ async function runSupervisorRunCommand(argv, io = PROCESS_IO) {
|
|
|
707
1461
|
* agent-eval supervisor-run report <runDir> [--format headline|markdown|json]
|
|
708
1462
|
* agent-eval search ship <search-ledger.jsonl> --run-kind optimization|eval
|
|
709
1463
|
* agent-eval search show <search-ledger.jsonl>
|
|
1464
|
+
* agent-eval skill-usage <transcripts-dir> [--since 7d]
|
|
1465
|
+
* agent-eval procedure-registry <sessions-dir> [--ledger <path>]... [--since 30d] [--outcomes <file>]
|
|
710
1466
|
* agent-eval openapi [--out path] # write OpenAPI spec
|
|
711
1467
|
* agent-eval version
|
|
712
1468
|
*
|
|
@@ -777,6 +1533,16 @@ Commands:
|
|
|
777
1533
|
search show <search-ledger.jsonl>
|
|
778
1534
|
Verify a search ledger and print its summary: leading nodes, recently
|
|
779
1535
|
discarded nodes and recent proposals, the same text a proposer reads.
|
|
1536
|
+
skill-usage <transcripts-dir> [--since <7d|36h|90m|ISO time>] [--format both|json|table] [--limit <rows>] [--pricing <rates.json>]
|
|
1537
|
+
Read a directory of Claude Code transcripts and report each skill and
|
|
1538
|
+
version: invocations by agent, user and harness, sessions, and the tool
|
|
1539
|
+
calls, tool errors, tokens, wall time and cost after its first invocation.
|
|
1540
|
+
The JSON report goes to stdout and the table to stderr.
|
|
1541
|
+
procedure-registry <sessions-dir> [--ledger <search-ledger.jsonl>]... [--since <7d|36h|90m|ISO time>] [--outcomes <changes.json>] [--format both|json|table] [--limit <rows>] [--pricing <rates.json>]
|
|
1542
|
+
Join search ledgers and recorded Claude Code sessions on the version digest:
|
|
1543
|
+
per procedure version, its lineage, every execution, tokens, cost and wall
|
|
1544
|
+
time, the outcome of the changes its sessions produced, and the decisions
|
|
1545
|
+
taken on it. The JSON registry goes to stdout and the table to stderr.
|
|
780
1546
|
version
|
|
781
1547
|
Print server + wire-protocol version JSON.
|
|
782
1548
|
|
|
@@ -843,6 +1609,8 @@ async function main() {
|
|
|
843
1609
|
case "rollout-release": return await runRolloutReleaseCli(process.argv.slice(3));
|
|
844
1610
|
case "analyst-benchmark": return await runAnalystBenchmarkCommand(process.argv.slice(3));
|
|
845
1611
|
case "supervisor-run": return await runSupervisorRunCommand(process.argv.slice(3));
|
|
1612
|
+
case "skill-usage": return await runSkillUsageCommand(process.argv.slice(3));
|
|
1613
|
+
case "procedure-registry": return await runProcedureRegistryCommand(process.argv.slice(3));
|
|
846
1614
|
case "version":
|
|
847
1615
|
process.stdout.write(`${JSON.stringify(handleVersion(), null, 2)}\n`);
|
|
848
1616
|
return 0;
|
|
@@ -877,7 +1645,7 @@ const FLAGS_BY_COMMAND = {
|
|
|
877
1645
|
"": /* @__PURE__ */ new Set()
|
|
878
1646
|
};
|
|
879
1647
|
function assertKnownFlags(command, flags) {
|
|
880
|
-
if (command === "rollout-release" || command === "analyst-benchmark" || command === "supervisor-run" || command === "search") return;
|
|
1648
|
+
if (command === "rollout-release" || command === "analyst-benchmark" || command === "supervisor-run" || command === "skill-usage" || command === "procedure-registry" || command === "search") return;
|
|
881
1649
|
const allowed = FLAGS_BY_COMMAND[command];
|
|
882
1650
|
if (!allowed) return;
|
|
883
1651
|
const unknown = Object.keys(flags).filter((flag) => !allowed.has(flag));
|