@tangle-network/agent-eval 2.0.12 → 2.0.14

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.
Files changed (120) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/adapters/http.d.ts +2 -2
  3. package/dist/{agent-profile-C0FBdYa6.d.ts → agent-profile-Iiiqim4k.d.ts} +5 -5
  4. package/dist/{agent-profile-C0FBdYa6.d.ts.map → agent-profile-Iiiqim4k.d.ts.map} +1 -1
  5. package/dist/analyst/index.d.ts +109 -11
  6. package/dist/analyst/index.d.ts.map +1 -1
  7. package/dist/analyst/index.js +2 -2
  8. package/dist/{analyze-runs-Izz_ZeWg.d.ts → analyze-runs-ByEuSMUT.d.ts} +2 -2
  9. package/dist/{analyze-runs-Izz_ZeWg.d.ts.map → analyze-runs-ByEuSMUT.d.ts.map} +1 -1
  10. package/dist/app-grade/index.d.ts +3 -3
  11. package/dist/{benchmark-command-Be5O6A2v.js → benchmark-command-BizGxhuU.js} +427 -29
  12. package/dist/{benchmark-command-Be5O6A2v.js.map → benchmark-command-BizGxhuU.js.map} +1 -1
  13. package/dist/benchmarks/index.d.ts +4 -4
  14. package/dist/benchmarks/index.js +2 -2
  15. package/dist/campaign/index.d.ts +7 -7
  16. package/dist/campaign/index.js +7 -7
  17. package/dist/{campaign-CE08mvQO.js → campaign-CaO2k8Jb.js} +7 -7
  18. package/dist/{campaign-CE08mvQO.js.map → campaign-CaO2k8Jb.js.map} +1 -1
  19. package/dist/{campaign-evidence-DRvr7lZU.d.ts → campaign-evidence-p9QJoA1P.d.ts} +3 -3
  20. package/dist/{campaign-evidence-DRvr7lZU.d.ts.map → campaign-evidence-p9QJoA1P.d.ts.map} +1 -1
  21. package/dist/cli.js +366 -24
  22. package/dist/cli.js.map +1 -1
  23. package/dist/{client-DUMIaMob.d.ts → client-3sR4_h5q.d.ts} +2 -2
  24. package/dist/{client-DUMIaMob.d.ts.map → client-3sR4_h5q.d.ts.map} +1 -1
  25. package/dist/contract/index.d.ts +11 -11
  26. package/dist/contract/index.js +5 -5
  27. package/dist/{default-registry-DFRlBniE.d.ts → default-registry-DpTVhIO5.d.ts} +6 -6
  28. package/dist/{default-registry-DFRlBniE.d.ts.map → default-registry-DpTVhIO5.d.ts.map} +1 -1
  29. package/dist/{define-agent-eval-BHn6t-DC.js → define-agent-eval-BLHr0_IP.js} +3 -3
  30. package/dist/{define-agent-eval-BHn6t-DC.js.map → define-agent-eval-BLHr0_IP.js.map} +1 -1
  31. package/dist/{define-agent-eval-n63vmQMR.d.ts → define-agent-eval-D__7N3BM.d.ts} +5 -5
  32. package/dist/{define-agent-eval-n63vmQMR.d.ts.map → define-agent-eval-D__7N3BM.d.ts.map} +1 -1
  33. package/dist/diagnosis/index.d.ts +2 -2
  34. package/dist/{evaluation-VbjqORBn.d.ts → evaluation-DVNNvOz5.d.ts} +4 -4
  35. package/dist/{evaluation-VbjqORBn.d.ts.map → evaluation-DVNNvOz5.d.ts.map} +1 -1
  36. package/dist/evaluation.d.ts +1 -1
  37. package/dist/{exact-types-BIHqYBYf.d.ts → exact-types-QwxMWchv.d.ts} +2 -2
  38. package/dist/{exact-types-BIHqYBYf.d.ts.map → exact-types-QwxMWchv.d.ts.map} +1 -1
  39. package/dist/experiment/index.d.ts +2 -2
  40. package/dist/{feedback-trajectory-CoQPmSJV.d.ts → feedback-trajectory-BkWAgoY0.d.ts} +3 -3
  41. package/dist/{feedback-trajectory-CoQPmSJV.d.ts.map → feedback-trajectory-BkWAgoY0.d.ts.map} +1 -1
  42. package/dist/hosted/index.d.ts +2 -2
  43. package/dist/hosted/index.js +1 -1
  44. package/dist/{index-CbzPtg7O.d.ts → index-B5FH3fgu.d.ts} +18 -18
  45. package/dist/{index-CbzPtg7O.d.ts.map → index-B5FH3fgu.d.ts.map} +1 -1
  46. package/dist/{index-BEXEYURJ.d.ts → index-DXEhnNrn.d.ts} +10 -10
  47. package/dist/{index-BEXEYURJ.d.ts.map → index-DXEhnNrn.d.ts.map} +1 -1
  48. package/dist/{index-Dt3zWlRa.d.ts → index-DkL184ja.d.ts} +5 -5
  49. package/dist/{index-Dt3zWlRa.d.ts.map → index-DkL184ja.d.ts.map} +1 -1
  50. package/dist/{index-rrPT3Pw0.d.ts → index-h7nEEV3T.d.ts} +2 -2
  51. package/dist/{index-rrPT3Pw0.d.ts.map → index-h7nEEV3T.d.ts.map} +1 -1
  52. package/dist/index.d.ts +18 -18
  53. package/dist/index.js +4 -4
  54. package/dist/{llm-judge-CgF3ZM3R.js → llm-judge-ChGnwj4s.js} +2 -2
  55. package/dist/{llm-judge-CgF3ZM3R.js.map → llm-judge-ChGnwj4s.js.map} +1 -1
  56. package/dist/{matrix-B95YsrV7.d.ts → matrix-kxgHmj2-.d.ts} +2 -2
  57. package/dist/{matrix-B95YsrV7.d.ts.map → matrix-kxgHmj2-.d.ts.map} +1 -1
  58. package/dist/multishot/golden/index.d.ts +1 -1
  59. package/dist/multishot/index.d.ts +7 -7
  60. package/dist/multishot/index.js +2 -2
  61. package/dist/openapi.json +1 -1
  62. package/dist/{optimization-method-1xzXK-B6.js → optimization-method-D2uCSc2j.js} +4 -4
  63. package/dist/{optimization-method-1xzXK-B6.js.map → optimization-method-D2uCSc2j.js.map} +1 -1
  64. package/dist/{prime-protocol-BRMk6dGI.d.ts → prime-protocol-46WvqIIt.d.ts} +2 -2
  65. package/dist/{prime-protocol-BRMk6dGI.d.ts.map → prime-protocol-46WvqIIt.d.ts.map} +1 -1
  66. package/dist/{registry-BeInzotS.d.ts → registry-Bh1M9hrf.d.ts} +3 -3
  67. package/dist/{registry-BeInzotS.d.ts.map → registry-Bh1M9hrf.d.ts.map} +1 -1
  68. package/dist/rl.d.ts +3 -3
  69. package/dist/rollout/index.d.ts +2 -2
  70. package/dist/{run-improvement-loop-BPhkYKV2.d.ts → run-improvement-loop-FsLfRyJm.d.ts} +8 -8
  71. package/dist/{run-improvement-loop-BPhkYKV2.d.ts.map → run-improvement-loop-FsLfRyJm.d.ts.map} +1 -1
  72. package/dist/search/index.d.ts +3 -3
  73. package/dist/search/index.js +2 -2
  74. package/dist/{search-kernel-BkkDo75N.js → search-kernel-B1TEQ9pa.js} +2 -2
  75. package/dist/{search-kernel-BkkDo75N.js.map → search-kernel-B1TEQ9pa.js.map} +1 -1
  76. package/dist/{search-kernel-CDSEWa2X.d.ts → search-kernel-BSYkfEg5.d.ts} +3 -3
  77. package/dist/{search-kernel-CDSEWa2X.d.ts.map → search-kernel-BSYkfEg5.d.ts.map} +1 -1
  78. package/dist/{search-ledger-sormHFLS.js → search-ledger-EjLGVZ4X.js} +9 -5
  79. package/dist/search-ledger-EjLGVZ4X.js.map +1 -0
  80. package/dist/{search-ledger-types-BhZE848w.d.ts → search-ledger-types-D4FsvPP9.d.ts} +8 -2
  81. package/dist/search-ledger-types-D4FsvPP9.d.ts.map +1 -0
  82. package/dist/{search-shipper-BJ2Bkx2q.js → search-shipper-DtSnRfOJ.js} +2 -2
  83. package/dist/{search-shipper-BJ2Bkx2q.js.map → search-shipper-DtSnRfOJ.js.map} +1 -1
  84. package/dist/{search-summary-DMckFUNY.js → search-summary-C5fewoUi.js} +2 -2
  85. package/dist/{search-summary-DMckFUNY.js.map → search-summary-C5fewoUi.js.map} +1 -1
  86. package/dist/{self-improve-D0TtJz4e.d.ts → self-improve-Bf3b6rS9.d.ts} +8 -8
  87. package/dist/{self-improve-D0TtJz4e.d.ts.map → self-improve-Bf3b6rS9.d.ts.map} +1 -1
  88. package/dist/{self-improve-CMrPmjYE.js → self-improve-CQM7hIL_.js} +3 -3
  89. package/dist/{self-improve-CMrPmjYE.js.map → self-improve-CQM7hIL_.js.map} +1 -1
  90. package/dist/{skillopt-optimization-method-D-BPMi8J.js → skillopt-optimization-method-DQ4urRij.js} +3 -3
  91. package/dist/{skillopt-optimization-method-D-BPMi8J.js.map → skillopt-optimization-method-DQ4urRij.js.map} +1 -1
  92. package/dist/{store-tool-spans-M3WxeRrG.d.ts → store-tool-spans-_hFLpBfi.d.ts} +4 -4
  93. package/dist/{store-tool-spans-M3WxeRrG.d.ts.map → store-tool-spans-_hFLpBfi.d.ts.map} +1 -1
  94. package/dist/{systemone-C26IFS-a.d.ts → systemone-CE0Rj-BQ.d.ts} +6 -6
  95. package/dist/{systemone-C26IFS-a.d.ts.map → systemone-CE0Rj-BQ.d.ts.map} +1 -1
  96. package/dist/{systemone-review-DpAXWDkL.d.ts → systemone-review-CRJ-Zdfo.d.ts} +3 -3
  97. package/dist/{systemone-review-DpAXWDkL.d.ts.map → systemone-review-CRJ-Zdfo.d.ts.map} +1 -1
  98. package/dist/systemone.d.ts +3 -3
  99. package/dist/{tool-groups-SlnoQNyT.d.ts → tool-groups-BHX9G_oE.d.ts} +2 -2
  100. package/dist/tool-groups-BHX9G_oE.d.ts.map +1 -0
  101. package/dist/{trace-questions-ybyF0B6N.d.ts → trace-questions-DfaIVysB.d.ts} +2 -2
  102. package/dist/{trace-questions-ybyF0B6N.d.ts.map → trace-questions-DfaIVysB.d.ts.map} +1 -1
  103. package/dist/trace-repair/index.d.ts +1 -1
  104. package/dist/traces.d.ts +2 -2
  105. package/dist/{tree-BX9ykHi3.js → tree-CljLPWVm.js} +3 -3
  106. package/dist/{tree-BX9ykHi3.js.map → tree-CljLPWVm.js.map} +1 -1
  107. package/dist/{types-CBT-XcX5.d.ts → types-BBht9lpj.d.ts} +5 -3
  108. package/dist/types-BBht9lpj.d.ts.map +1 -0
  109. package/dist/{types-CYPV2dlR.d.ts → types-CEiYR2xs.d.ts} +2 -2
  110. package/dist/{types-CYPV2dlR.d.ts.map → types-CEiYR2xs.d.ts.map} +1 -1
  111. package/dist/{types-B1W3v8dT.d.ts → types-CjrzKsOK.d.ts} +8 -8
  112. package/dist/{types-B1W3v8dT.d.ts.map → types-CjrzKsOK.d.ts.map} +1 -1
  113. package/dist/wire/index.d.ts +1 -1
  114. package/docs/search-ledger.md +1 -1
  115. package/docs/skill-eval.md +12 -3
  116. package/package.json +1 -1
  117. package/dist/search-ledger-sormHFLS.js.map +0 -1
  118. package/dist/search-ledger-types-BhZE848w.d.ts.map +0 -1
  119. package/dist/tool-groups-SlnoQNyT.d.ts.map +0 -1
  120. package/dist/types-CBT-XcX5.d.ts.map +0 -1
@@ -30,21 +30,290 @@ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "nod
30
30
  import { arch, platform } from "node:os";
31
31
  import { pathToFileURL } from "node:url";
32
32
  import { link, lstat, mkdir, open, readFile, readdir, realpath, stat, unlink } from "node:fs/promises";
33
- import { readSessionInput } from "@tangle-network/harness-sessions";
33
+ import { codexRefForFile, readSessionInput } from "@tangle-network/harness-sessions";
34
34
  import { TextDecoder as TextDecoder$1 } from "node:util";
35
35
  import { performance } from "node:perf_hooks";
36
36
  import { linearSumAssignment } from "linear-sum-assignment";
37
+ // src/skill-usage/change-ledger.ts
38
+ /**
39
+ * The change ledger: one row per commit or pull request a session made, written
40
+ * by the session's own harness at the moment the call returned, and the reader
41
+ * that joins those rows to recorded sessions.
42
+ *
43
+ * A transcript names a pull request only when its output prints the URL, and
44
+ * names no commit. The ledger is the harness's own record: each row carries the
45
+ * tool call's id, so a change belongs to the typed turn whose span holds the
46
+ * call, and the session's own commits and merges are counted, not guessed from
47
+ * output text.
48
+ *
49
+ * Row format (JSON lines, `v` 1; a writer adds no other field the reader needs):
50
+ *
51
+ * | Field | Meaning |
52
+ * |---|---|
53
+ * | `at` | ISO time the call returned |
54
+ * | `harness` | the harness that wrote it, as the session reader names it (`claude-code`) |
55
+ * | `sessionId`, `agentId` | the session; inside a subagent, the subagent's id too (the id its own transcript carries) |
56
+ * | `toolUseId` | the id of the tool call that made the change; null when the harness gave none |
57
+ * | `action` | `commit`, `pr-create`, `pr-merge`, `observed`, or, from a writer that sees whole turns, `turn` and `push` |
58
+ * | `remote` | the repository as `owner/repo` (or `host/path`); null when the writer could not find it |
59
+ * | `sha`, `pr` | the commit or the pull request number; null when the call did not name it |
60
+ *
61
+ * `observed` is written once per session or subagent, at its first call. It says
62
+ * the writer was running, which is the only thing that lets "no change rows"
63
+ * mean "no change". A session with no row of any action is unknown, never none.
64
+ *
65
+ * A writer outside the harness, such as a gateway that runs the harness for a
66
+ * caller (CLI Bridge), sees turns, not tool calls, and adds fields to its rows:
67
+ *
68
+ * | Field | Meaning |
69
+ * |---|---|
70
+ * | `sessionId` | the gateway's session id |
71
+ * | `nativeSessionId` | the harness's own session id, the id its transcript carries; rows are keyed by it when present |
72
+ * | `turnId`, `runId` | the gateway's turn and run |
73
+ * | `turnStartedAt` | ISO time the turn began; with `at`, the window the change was made in |
74
+ * | `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 |
75
+ * | `headBefore`, `head` | on a `turn` row: the working repository's HEAD when the turn began and when it ended |
76
+ * | `branch` | on a `push` row: the remote branch the turn pushed |
77
+ *
78
+ * Such a row has no `toolUseId`. The change belongs to the last tool call of the
79
+ * session record whose time lies in [`turnStartedAt`, `at`], so a record with no
80
+ * times, or none in the window, leaves the change unplaced. A `turn` row with a
81
+ * non-null `incomplete` makes the session's changes unknown, with a gap that says why.
82
+ *
83
+ * A row's `toolUseId` is the id the harness's hook saw. Where the session record
84
+ * holds the call under that id, or names it in `callAliases`, the change belongs
85
+ * to the turn that made the call. A row that matches neither makes the whole
86
+ * session unknown, with a gap that says so: the change happened, and which turn
87
+ * made it cannot be said, so no turn may be called change-free.
88
+ */
89
+ const CHANGE_LEDGER_ACTIONS = [
90
+ "observed",
91
+ "commit",
92
+ "pr-create",
93
+ "pr-merge",
94
+ "turn",
95
+ "push"
96
+ ];
97
+ const key = (harness, id) => `${harness}\u0000${id}`;
98
+ function parseRow(line) {
99
+ let value;
100
+ try {
101
+ value = JSON.parse(line);
102
+ } catch {
103
+ return null;
104
+ }
105
+ if (typeof value !== "object" || value === null) return null;
106
+ const row = value;
107
+ const text = (field) => {
108
+ const raw = row[field];
109
+ return typeof raw === "string" && raw !== "" ? raw : null;
110
+ };
111
+ const optional = (field) => {
112
+ const raw = row[field];
113
+ if (raw === null || raw === void 0) return null;
114
+ return typeof raw === "string" && raw !== "" ? raw : void 0;
115
+ };
116
+ const action = row.action;
117
+ const toolUseId = optional("toolUseId");
118
+ const agentId = optional("agentId");
119
+ const remote = optional("remote");
120
+ const sha = optional("sha");
121
+ const nativeSessionId = optional("nativeSessionId");
122
+ const turnStartedAt = optional("turnStartedAt");
123
+ const incomplete = optional("incomplete");
124
+ const pr = row.pr ?? null;
125
+ const at = text("at");
126
+ const harness = text("harness");
127
+ const sessionId = text("sessionId");
128
+ 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;
129
+ return {
130
+ v: 1,
131
+ at,
132
+ harness,
133
+ sessionId,
134
+ agentId,
135
+ toolUseId,
136
+ action,
137
+ remote,
138
+ sha,
139
+ pr,
140
+ nativeSessionId,
141
+ turnStartedAt,
142
+ incomplete
143
+ };
144
+ }
145
+ /** The reference the registry's outcome source names a change by: `owner/repo#123` or `owner/repo@<sha>`. */
146
+ function refOf(row) {
147
+ if (row.remote === null) return null;
148
+ if (row.action === "commit") return row.sha === null ? null : `${row.remote}@${row.sha}`;
149
+ if (row.action === "pr-create" || row.action === "pr-merge") return row.pr === null ? null : `${row.remote}#${row.pr}`;
150
+ return null;
151
+ }
152
+ /** Read ledger text. A line that is not a row is counted, not skipped silently, and no row is guessed from it. */
153
+ function parseChangeLedger(text) {
154
+ const sessions = /* @__PURE__ */ new Map();
155
+ let rows = 0;
156
+ let malformed = 0;
157
+ for (const line of text.split("\n")) {
158
+ if (line.trim() === "") continue;
159
+ const row = parseRow(line);
160
+ if (row === null) {
161
+ malformed += 1;
162
+ continue;
163
+ }
164
+ rows += 1;
165
+ const id = key(row.harness, row.agentId ?? row.nativeSessionId ?? row.sessionId);
166
+ let session = sessions.get(id);
167
+ if (session === void 0) {
168
+ session = {
169
+ observed: false,
170
+ changes: [],
171
+ unnamed: 0,
172
+ timed: [],
173
+ incomplete: /* @__PURE__ */ new Map()
174
+ };
175
+ sessions.set(id, session);
176
+ }
177
+ if (row.action === "observed" || row.action === "push") {
178
+ session.observed = true;
179
+ continue;
180
+ }
181
+ if (row.action === "turn") {
182
+ session.observed = true;
183
+ if (row.incomplete) session.incomplete.set(row.incomplete, (session.incomplete.get(row.incomplete) ?? 0) + 1);
184
+ continue;
185
+ }
186
+ session.observed = true;
187
+ const ref = refOf(row);
188
+ if (ref === null) session.unnamed += 1;
189
+ else if (row.toolUseId === null && row.turnStartedAt) session.timed.push({
190
+ ref,
191
+ from: row.turnStartedAt,
192
+ to: row.at
193
+ });
194
+ else session.changes.push({
195
+ ref,
196
+ callId: row.toolUseId ?? "",
197
+ at: row.at
198
+ });
199
+ }
200
+ return {
201
+ sessions,
202
+ rows,
203
+ malformed
204
+ };
205
+ }
206
+ /** Read one or more ledger files as one ledger. A file that cannot be read throws: a missing ledger is not an empty one. */
207
+ async function readChangeLedger(paths) {
208
+ const texts = [];
209
+ for (const path of paths) try {
210
+ texts.push(await readFile(path, "utf8"));
211
+ } catch (error) {
212
+ throw new ValidationError(`readChangeLedger: cannot read ${path}: ${errorMessage(error)}`);
213
+ }
214
+ return parseChangeLedger(texts.join("\n"));
215
+ }
216
+ /** The last tool call or skill call of the record whose time lies in [from, to]; null when there is none. */
217
+ function callInWindow(record, from, to) {
218
+ const start = Date.parse(from);
219
+ const end = Date.parse(to);
220
+ if (!Number.isFinite(start) || !Number.isFinite(end)) return null;
221
+ let found = null;
222
+ for (const event of record.events) {
223
+ if (event.kind === "model" || event.at === null) continue;
224
+ const at = Date.parse(event.at);
225
+ if (at >= start && at <= end) found = event.kind === "tool" ? event.id : event.callId;
226
+ }
227
+ return found;
228
+ }
229
+ function joinRead(read, ledger) {
230
+ if (!read.succeeded) return read;
231
+ const { value } = read;
232
+ const held = ledger.sessions.get(key(value.harness, value.sessionId));
233
+ const seen = /* @__PURE__ */ new Set();
234
+ const changes = [];
235
+ const aliases = value.callAliases ?? {};
236
+ const placeable = new Set(value.events.flatMap((event) => event.kind === "tool" ? [event.id] : event.kind === "skill" ? [event.callId] : []));
237
+ let unplaced = 0;
238
+ const timed = [];
239
+ for (const change of held?.timed ?? []) {
240
+ const callId = callInWindow(value, change.from, change.to);
241
+ if (callId === null) unplaced += 1;
242
+ else timed.push({
243
+ ref: change.ref,
244
+ callId,
245
+ at: change.to
246
+ });
247
+ }
248
+ for (const row of [
249
+ ...value.changes ?? [],
250
+ ...held?.changes ?? [],
251
+ ...timed
252
+ ]) {
253
+ const change = Object.hasOwn(aliases, row.callId) ? {
254
+ ...row,
255
+ callId: aliases[row.callId]
256
+ } : row;
257
+ if (!placeable.has(change.callId)) unplaced += 1;
258
+ const id = `${change.ref}\u0000${change.callId}`;
259
+ if (seen.has(id)) continue;
260
+ seen.add(id);
261
+ changes.push(change);
262
+ }
263
+ const gaps = [...value.gaps];
264
+ 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)`);
265
+ 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`);
266
+ const { changes: _transcriptChanges, ...rest } = value;
267
+ const incomplete = [...held?.incomplete ?? []];
268
+ 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`);
269
+ const known = unplaced === 0 && incomplete.length === 0 && (held?.observed === true || changes.length > 0);
270
+ return {
271
+ ...read,
272
+ value: {
273
+ ...rest,
274
+ gaps,
275
+ ...known ? { changes } : {}
276
+ }
277
+ };
278
+ }
279
+ /**
280
+ * The sessions of `source` with their changes taken from the ledger as well as
281
+ * from the transcript. A session the ledger never observed keeps only the
282
+ * changes its transcript shows, and has none recorded when it shows none.
283
+ */
284
+ async function* withChangeLedger(source, ledger) {
285
+ for await (const read of source) yield joinRead(read, ledger);
286
+ }
37
287
  // src/skill-usage/change-refs.ts
38
- const SHELL_TOOLS = /* @__PURE__ */ new Set(["Bash"]);
288
+ /** Claude Code's shell tool, and Codex's: `exec_command`, `shell`, and `exec`, the code-mode tool whose JavaScript runs the shell. */
289
+ const SHELL_TOOLS = /* @__PURE__ */ new Set([
290
+ "Bash",
291
+ "exec_command",
292
+ "shell",
293
+ "shell_command",
294
+ "exec"
295
+ ]);
39
296
  /** `gh pr create`, or a wrapper named `gh-<identity>`, including its flags up to the subcommand. */
40
297
  const PR_COMMAND = /\bgh(?:-[\w-]+)?\s+(?:-\S+\s+\S+\s+)*pr\s+(create|merge)\b/g;
41
298
  const PULL_URL = /https:\/\/github\.com\/([\w.-]+\/[\w.-]+)\/pull\/(\d+)/g;
42
299
  const MERGE_ARGS = /\bpr\s+merge\s+(?:(?:https:\/\/github\.com\/([\w.-]+\/[\w.-]+)\/pull\/)?(\d+))/;
43
300
  const REPO_FLAG = /(?:-R|--repo)[\s=]+([\w.-]+\/[\w.-]+)/;
301
+ /**
302
+ * The shell text of a call: the `command` or `cmd` of its input (a string, or an
303
+ * argv joined), or, for Codex's `exec`, the JavaScript, which holds the commands.
304
+ */
305
+ function shellCommandText(call) {
306
+ if (!SHELL_TOOLS.has(call.name)) return null;
307
+ if (typeof call.input === "string") return call.name === "exec" ? call.input : null;
308
+ const input = record$1(call.input);
309
+ const command = input?.command ?? input?.cmd;
310
+ if (typeof command === "string") return command;
311
+ if (Array.isArray(command) && command.every((part) => typeof part === "string")) return command.join(" ");
312
+ return null;
313
+ }
44
314
  function githubPullRequestRefs(call) {
45
- if (!SHELL_TOOLS.has(call.name)) return [];
46
- const command = record$1(call.input)?.command;
47
- if (typeof command !== "string") return [];
315
+ const command = shellCommandText(call);
316
+ if (command === null) return [];
48
317
  const kinds = /* @__PURE__ */ new Set();
49
318
  for (const match of command.matchAll(PR_COMMAND)) kinds.add(match[1]);
50
319
  if (kinds.size === 0) return [];
@@ -106,7 +375,7 @@ function costUsage(usage) {
106
375
  ...usage.cacheWrite === null ? {} : { cacheWriteTokens: usage.cacheWrite }
107
376
  };
108
377
  }
109
- function invocation(fields, loaded) {
378
+ function invocation(fields, loaded, skillFile = null) {
110
379
  return {
111
380
  kind: "skill",
112
381
  ...fields,
@@ -114,7 +383,7 @@ function invocation(fields, loaded) {
114
383
  bodySha256: skillBodySha256(loaded.body),
115
384
  source: "session"
116
385
  },
117
- skillFile: loaded?.skillFile ?? null
386
+ skillFile: loaded?.skillFile ?? skillFile
118
387
  };
119
388
  }
120
389
  /**
@@ -133,6 +402,7 @@ function skillSessionFromHarnessSession(session, markers = {}) {
133
402
  const placedToolCalls = /* @__PURE__ */ new Set();
134
403
  const events = [];
135
404
  const changes = [];
405
+ const turns = [];
136
406
  const placeModelCall = (id) => {
137
407
  const call = modelCalls.get(id);
138
408
  if (call === void 0 || placedModelCalls.has(id)) return;
@@ -174,7 +444,7 @@ function skillSessionFromHarnessSession(session, markers = {}) {
174
444
  invoker: "agent",
175
445
  at: call.startedAt,
176
446
  failed
177
- }, markers.loadedByCallId?.get(id)));
447
+ }, markers.loadedByCallId?.get(id), markers.skillFileOfToolCall?.(call) ?? null));
178
448
  };
179
449
  for (const message of session.messages) {
180
450
  if (message.inherited === true) continue;
@@ -183,6 +453,15 @@ function skillSessionFromHarnessSession(session, markers = {}) {
183
453
  for (const part of message.parts) if (part.type === "tool-call") placeToolCall(part.toolCallId);
184
454
  continue;
185
455
  }
456
+ if (message.role === "user" && message.actor === "human") {
457
+ const text = message.parts.flatMap((part) => part.type === "text" ? [part.text] : []).join("\n").trim();
458
+ if (text !== "") turns.push({
459
+ id: message.id,
460
+ at: message.at,
461
+ eventIndex: events.length,
462
+ text
463
+ });
464
+ }
186
465
  const marker = markers.invocationsByMessageId?.get(message.id);
187
466
  if (marker !== void 0) events.push(invocation({
188
467
  callId: message.id,
@@ -205,9 +484,29 @@ function skillSessionFromHarnessSession(session, markers = {}) {
205
484
  endedAt: session.endedAt,
206
485
  events,
207
486
  ...markers.changesOfToolCall === void 0 ? {} : { changes },
487
+ ...markers.callAliases === void 0 || Object.keys(markers.callAliases).length === 0 ? {} : { callAliases: markers.callAliases },
488
+ turns,
208
489
  gaps
209
490
  };
210
491
  }
492
+ // src/skill-usage/transcript-walk.ts
493
+ /** Finding the session files under a harness's store: one walk, shared by every reader. */
494
+ async function walkTranscripts(directory, walk, wanted = (name) => name.endsWith(".jsonl")) {
495
+ const entries = await readdir(directory, { withFileTypes: true });
496
+ entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
497
+ for (const entry of entries) {
498
+ const path = join(directory, entry.name);
499
+ if (entry.isDirectory()) try {
500
+ await walkTranscripts(path, walk, wanted);
501
+ } catch (error) {
502
+ walk.unreadable.push({
503
+ source: path,
504
+ error: errorMessage(error)
505
+ });
506
+ }
507
+ else if ((entry.isFile() || entry.isSymbolicLink()) && wanted(entry.name)) walk.files.push(path);
508
+ }
509
+ }
211
510
  // src/skill-usage/claude-code.ts
212
511
  /**
213
512
  * Claude Code transcripts as skill session records.
@@ -389,22 +688,6 @@ function skillSession(records, identity) {
389
688
  ...skillMarkers(records, identity.parentSessionId !== null)
390
689
  });
391
690
  }
392
- async function walkTranscripts(directory, walk) {
393
- const entries = await readdir(directory, { withFileTypes: true });
394
- entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
395
- for (const entry of entries) {
396
- const path = join(directory, entry.name);
397
- if (entry.isDirectory()) try {
398
- await walkTranscripts(path, walk);
399
- } catch (error) {
400
- walk.unreadable.push({
401
- source: path,
402
- error: errorMessage(error)
403
- });
404
- }
405
- else if ((entry.isFile() || entry.isSymbolicLink()) && entry.name.endsWith(".jsonl")) walk.files.push(path);
406
- }
407
- }
408
691
  /**
409
692
  * Every transcript under a Claude Code projects directory, one read per file:
410
693
  * top-level sessions and each subagent's own file. A file or folder that cannot
@@ -443,6 +726,120 @@ async function* claudeCodeSkillSessions(directory, options = {}) {
443
726
  };
444
727
  }
445
728
  }
729
+ // src/skill-usage/codex.ts
730
+ /**
731
+ * Codex rollouts as skill session records.
732
+ *
733
+ * `@tangle-network/harness-sessions` owns what a rollout's tool calls, model
734
+ * calls, typed turns and usage are. This module adds what the rollout says about
735
+ * skills and changes:
736
+ *
737
+ * | Fact | Record |
738
+ * |---|---|
739
+ * | a skill invocation | a shell call that reads a `skills/<name>/SKILL.md` file with a viewer (`cat`, `sed`, `head`, `nl`...); Codex has no skill tool, so the read is the invocation |
740
+ * | the skill's version | none from the session: the read is often partial (`head -70`), so the report reads the skill file as it is now and says so |
741
+ * | a change | a pull request a shell call opened or merged, as for Claude Code; the change ledger adds commits |
742
+ *
743
+ * Inside Codex's code-mode `exec` tool a script runs shell commands, and the
744
+ * hook that wrote a change ledger row saw the command's own id (`exec-<uuid>`),
745
+ * not the id of the `exec` call. The rollout records that id on the command's
746
+ * completion event, between the call and its output, so it names the call when
747
+ * exactly one `exec` call is open. With none or several open it names none, and
748
+ * the session says how many ids it could not place.
749
+ */
750
+ /** A viewer reading a skill file: `cat path`, `sed -n '1,80p' path`, `head -70 path`. */
751
+ const SKILL_READ = /\b(?:cat|head|tail|sed|nl|bat|less|more|awk)\b[^\n;&|]*?(?:^|[\s'"=])((?:[\w~.$/-]*\/)?skills\/([\w.-]+)\/SKILL\.md)\b/;
752
+ /** The skill a shell call reads, and the file it reads it from. */
753
+ function skillRead(call) {
754
+ const command = shellCommandText(call);
755
+ if (command === null) return null;
756
+ const match = SKILL_READ.exec(command);
757
+ if (match === null) return null;
758
+ return {
759
+ skill: match[2],
760
+ file: match[1]
761
+ };
762
+ }
763
+ /** The ids hooks name nested commands by, mapped to the `exec` call that ran them. */
764
+ function execCallAliases(records) {
765
+ const aliases = {};
766
+ const open = /* @__PURE__ */ new Set();
767
+ let unplaced = 0;
768
+ for (const value of records) {
769
+ const entry = record$1(value);
770
+ const payload = record$1(entry?.payload);
771
+ if (entry === null || payload === null) continue;
772
+ if (entry.type === "response_item") {
773
+ const callId = stringField(payload, "call_id");
774
+ if (callId === void 0) continue;
775
+ if (payload.type === "custom_tool_call" && payload.name === "exec") open.add(callId);
776
+ else if (payload.type === "custom_tool_call_output") open.delete(callId);
777
+ } else if (entry.type === "event_msg" && payload.type === "item_completed") {
778
+ const item = record$1(payload.item);
779
+ if (item === null || item.type !== "CommandExecution") continue;
780
+ const id = stringField(item, "id");
781
+ if (id === void 0 || !id.startsWith("exec-")) continue;
782
+ const [only] = open;
783
+ if (open.size === 1 && only !== void 0) aliases[id] = only;
784
+ else unplaced += 1;
785
+ }
786
+ }
787
+ return {
788
+ aliases,
789
+ unplaced
790
+ };
791
+ }
792
+ /** One rollout's parsed lines as a skill session record. */
793
+ function rolloutSession(records, path) {
794
+ const session = readSessionInput("codex", { records }, codexRefForFile(path));
795
+ const { aliases, unplaced } = execCallAliases(records);
796
+ const value = skillSessionFromHarnessSession(session, {
797
+ skillOfToolCall: (call) => skillRead(call)?.skill ?? null,
798
+ skillFileOfToolCall: (call) => skillRead(call)?.file ?? null,
799
+ changesOfToolCall: githubPullRequestRefs,
800
+ callAliases: aliases
801
+ });
802
+ if (unplaced > 0) value.gaps.push(`${unplaced} commands run inside code-mode scripts name no single script, so a change ledger row for them cannot be placed`);
803
+ return value;
804
+ }
805
+ /**
806
+ * Every rollout under a Codex sessions directory (`~/.codex/sessions`, or one
807
+ * account's), one read per file: top-level threads and each subagent's own. A
808
+ * file or folder that cannot be read is a failed read with its reason. Throws
809
+ * when the directory itself cannot be read.
810
+ */
811
+ async function* codexSkillSessions(directory, options = {}) {
812
+ const walk = {
813
+ files: [],
814
+ unreadable: []
815
+ };
816
+ try {
817
+ await walkTranscripts(directory, walk, (name) => name.startsWith("rollout-") && name.endsWith(".jsonl"));
818
+ } catch (error) {
819
+ throw new ValidationError(`codexSkillSessions: cannot read ${directory}: ${errorMessage(error)}`);
820
+ }
821
+ for (const failure of walk.unreadable) yield {
822
+ succeeded: false,
823
+ ...failure
824
+ };
825
+ for (const path of walk.files) try {
826
+ if (options.sinceMs !== void 0 && (await stat(path)).mtimeMs < options.sinceMs) continue;
827
+ const parsed = await parseCodeAgentJsonlFile(path);
828
+ const value = rolloutSession(parsed.entries, path);
829
+ if (parsed.malformedLines > 0) value.gaps.push(`${parsed.malformedLines} lines are not JSON`);
830
+ yield {
831
+ succeeded: true,
832
+ source: path,
833
+ value
834
+ };
835
+ } catch (error) {
836
+ yield {
837
+ succeeded: false,
838
+ source: path,
839
+ error: errorMessage(error)
840
+ };
841
+ }
842
+ }
446
843
  // src/skill-usage/report.ts
447
844
  const OVERLAP_NOTE = "A session that invokes several skills counts its later work under each of them, so the after-invocation columns overlap across rows and do not add up.";
448
845
  const PRICING_NOTE = "costUsd prices each model call with the cost ledger: the rates the caller gave for that model, else the ledger model table. Cache reads and writes are priced only at a rate the table names for that model; a call with cache tokens on a model without one, or a model with no row, is counted as not priced and stays out of the total.";
@@ -478,7 +875,7 @@ function modelCallCost(model, usage, pricing) {
478
875
  return priced.costUnknown ? null : priced.costUsd;
479
876
  }
480
877
  /** What one session did after position `from`, to its end. */
481
- function afterInvocation(session, from, startedAt, options) {
878
+ function afterInvocation(session, from, startedAt, options, until = null) {
482
879
  const after = {
483
880
  toolCalls: 0,
484
881
  toolErrors: 0,
@@ -491,7 +888,8 @@ function afterInvocation(session, from, startedAt, options) {
491
888
  pricedModelCalls: 0,
492
889
  unpricedModelCalls: 0
493
890
  };
494
- for (let index = from + 1; index < session.events.length; index++) {
891
+ const stop = until === null ? session.events.length : Math.min(until.eventIndex, session.events.length);
892
+ for (let index = from + 1; index < stop; index++) {
495
893
  const event = session.events[index];
496
894
  if (event.kind === "tool") {
497
895
  after.toolCalls += 1;
@@ -513,7 +911,7 @@ function afterInvocation(session, from, startedAt, options) {
513
911
  }
514
912
  }
515
913
  const start = instant(startedAt);
516
- const end = instant(session.endedAt);
914
+ const end = instant(until === null ? session.endedAt : until.at);
517
915
  if (start !== null && end !== null && end >= start) after.wallMs = end - start;
518
916
  return after;
519
917
  }
@@ -7646,6 +8044,6 @@ function printSuccessSummary(artifact, paths) {
7646
8044
  function shellQuote(value) {
7647
8045
  return /^[a-zA-Z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replaceAll("'", "'\\''")}'`;
7648
8046
  }
7649
- export { agentRxBenchmarkCase as A, renderSkillUsageTable as B, ANALYST_BENCHMARK_COST_LEDGER_FILE as C, AGENT_RX_UPSTREAM_REVISION as D, ANALYST_BENCHMARK_OBSERVATIONS_FILE as E, runAnalystBenchmark as F, skillSessionFromHarnessSession as H, traceStoreEvidenceResolver as I, afterInvocation as L, normalizeAgentRxCategory as M, externalId as N, codeTraceBenchCase as O, positiveStep as P, buildSkillUsageReport as R, ANALYST_BENCHMARK_IMPLEMENTATION_FILES as S, ANALYST_BENCHMARK_MANIFEST_FILE as T, readSkillFile as U, claudeCodeSkillSessions as V, readAnalystBenchmarkArtifact as _, runInlineAnalystDefinition as a, ANALYST_BENCHMARK_EVIDENCE_DEPENDENCY_LOCK_SHA256 as b, publicRlmAnalystDefinition as c, publicDirectAnalystDefinition as d, runChunkedAnalystDefinition as f, expandCodeTraceFailureBlocks as g, analystDefinitionProtocolSha256 as h, primeCodeTraceAnalystDefinition as i, agentRxPredictionsToFindings as j, codeTracerPredictionsToFindings as k, runReplVariableAnalystDefinition as l, analystDefinitionAsymmetries as m, createPrimeBenchmarkRunner as n, loadPublicBenchmarkRows as o, AnalystExpressivenessError as p, primeAnalystProtocolSha256 as r, createPublicBenchmarkRlmRunner as s, runAnalystBenchmarkCommand as t, createPublicBenchmarkDirectRunner as u, CODE_TRACE_BENCH_ANALYST_PROMPT as v, ANALYST_BENCHMARK_LOCAL_RECEIPT_FILE as w, ANALYST_BENCHMARK_EVIDENCE_IMPLEMENTATION_SHA256 as x, publicBenchmarkProtocolSha256 as y, instant as z };
8047
+ export { agentRxBenchmarkCase as A, renderSkillUsageTable as B, ANALYST_BENCHMARK_COST_LEDGER_FILE as C, AGENT_RX_UPSTREAM_REVISION as D, ANALYST_BENCHMARK_OBSERVATIONS_FILE as E, runAnalystBenchmark as F, CHANGE_LEDGER_ACTIONS as G, claudeCodeSkillSessions as H, traceStoreEvidenceResolver as I, withChangeLedger as J, parseChangeLedger as K, afterInvocation as L, normalizeAgentRxCategory as M, externalId as N, codeTraceBenchCase as O, positiveStep as P, buildSkillUsageReport as R, ANALYST_BENCHMARK_IMPLEMENTATION_FILES as S, ANALYST_BENCHMARK_MANIFEST_FILE as T, skillSessionFromHarnessSession as U, codexSkillSessions as V, readSkillFile as W, readAnalystBenchmarkArtifact as _, runInlineAnalystDefinition as a, ANALYST_BENCHMARK_EVIDENCE_DEPENDENCY_LOCK_SHA256 as b, publicRlmAnalystDefinition as c, publicDirectAnalystDefinition as d, runChunkedAnalystDefinition as f, expandCodeTraceFailureBlocks as g, analystDefinitionProtocolSha256 as h, primeCodeTraceAnalystDefinition as i, agentRxPredictionsToFindings as j, codeTracerPredictionsToFindings as k, runReplVariableAnalystDefinition as l, analystDefinitionAsymmetries as m, createPrimeBenchmarkRunner as n, loadPublicBenchmarkRows as o, AnalystExpressivenessError as p, readChangeLedger as q, primeAnalystProtocolSha256 as r, createPublicBenchmarkRlmRunner as s, runAnalystBenchmarkCommand as t, createPublicBenchmarkDirectRunner as u, CODE_TRACE_BENCH_ANALYST_PROMPT as v, ANALYST_BENCHMARK_LOCAL_RECEIPT_FILE as w, ANALYST_BENCHMARK_EVIDENCE_IMPLEMENTATION_SHA256 as x, publicBenchmarkProtocolSha256 as y, instant as z };
7650
8048
 
7651
- //# sourceMappingURL=benchmark-command-Be5O6A2v.js.map
8049
+ //# sourceMappingURL=benchmark-command-BizGxhuU.js.map