@tangle-network/agent-eval 0.120.0 → 0.120.2
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 +12 -0
- package/package.json +1 -1
- package/dist/analyst/index.d.ts +0 -3111
- package/dist/analyst/index.js +0 -403
- package/dist/analyst/index.js.map +0 -1
- package/dist/authenticity/index.d.ts +0 -161
- package/dist/authenticity/index.js +0 -215
- package/dist/authenticity/index.js.map +0 -1
- package/dist/belief-state/index.d.ts +0 -1301
- package/dist/belief-state/index.js +0 -2152
- package/dist/belief-state/index.js.map +0 -1
- package/dist/benchmarks/index.d.ts +0 -974
- package/dist/benchmarks/index.js +0 -60
- package/dist/benchmarks/index.js.map +0 -1
- package/dist/builder-eval/index.d.ts +0 -695
- package/dist/builder-eval/index.js +0 -366
- package/dist/builder-eval/index.js.map +0 -1
- package/dist/campaign/index.d.ts +0 -7454
- package/dist/campaign/index.js +0 -272
- package/dist/campaign/index.js.map +0 -1
- package/dist/chunk-32BZXMSO.js +0 -3878
- package/dist/chunk-32BZXMSO.js.map +0 -1
- package/dist/chunk-3A246TSA.js +0 -998
- package/dist/chunk-3A246TSA.js.map +0 -1
- package/dist/chunk-3RF76KTD.js +0 -84
- package/dist/chunk-3RF76KTD.js.map +0 -1
- package/dist/chunk-3YYRZDON.js +0 -45
- package/dist/chunk-3YYRZDON.js.map +0 -1
- package/dist/chunk-4I2E3LLO.js +0 -1030
- package/dist/chunk-4I2E3LLO.js.map +0 -1
- package/dist/chunk-ARU2PZFM.js +0 -312
- package/dist/chunk-ARU2PZFM.js.map +0 -1
- package/dist/chunk-BOD4O7OF.js +0 -40
- package/dist/chunk-BOD4O7OF.js.map +0 -1
- package/dist/chunk-DPZAEKA6.js +0 -880
- package/dist/chunk-DPZAEKA6.js.map +0 -1
- package/dist/chunk-DTJ6QUQB.js +0 -131
- package/dist/chunk-DTJ6QUQB.js.map +0 -1
- package/dist/chunk-GGE4NNQT.js +0 -65
- package/dist/chunk-GGE4NNQT.js.map +0 -1
- package/dist/chunk-H5UD2323.js +0 -286
- package/dist/chunk-H5UD2323.js.map +0 -1
- package/dist/chunk-HHWE3POT.js +0 -94
- package/dist/chunk-HHWE3POT.js.map +0 -1
- package/dist/chunk-HKUCJ437.js +0 -787
- package/dist/chunk-HKUCJ437.js.map +0 -1
- package/dist/chunk-JHCHEVET.js +0 -274
- package/dist/chunk-JHCHEVET.js.map +0 -1
- package/dist/chunk-JHOJHHU7.js +0 -867
- package/dist/chunk-JHOJHHU7.js.map +0 -1
- package/dist/chunk-JM2SKQMS.js +0 -750
- package/dist/chunk-JM2SKQMS.js.map +0 -1
- package/dist/chunk-JN2FCO5W.js +0 -7958
- package/dist/chunk-JN2FCO5W.js.map +0 -1
- package/dist/chunk-K4DBDHLK.js +0 -158
- package/dist/chunk-K4DBDHLK.js.map +0 -1
- package/dist/chunk-K6N6XJJX.js +0 -306
- package/dist/chunk-K6N6XJJX.js.map +0 -1
- package/dist/chunk-MA6HLL3S.js +0 -65
- package/dist/chunk-MA6HLL3S.js.map +0 -1
- package/dist/chunk-MAZ26DC7.js +0 -99
- package/dist/chunk-MAZ26DC7.js.map +0 -1
- package/dist/chunk-MOXWMGPC.js +0 -577
- package/dist/chunk-MOXWMGPC.js.map +0 -1
- package/dist/chunk-NJC7U437.js +0 -626
- package/dist/chunk-NJC7U437.js.map +0 -1
- package/dist/chunk-NPCTHQIO.js +0 -91
- package/dist/chunk-NPCTHQIO.js.map +0 -1
- package/dist/chunk-ONWEPEDO.js +0 -57
- package/dist/chunk-ONWEPEDO.js.map +0 -1
- package/dist/chunk-OYZAPX5G.js +0 -1526
- package/dist/chunk-OYZAPX5G.js.map +0 -1
- package/dist/chunk-PC4UYEBM.js +0 -166
- package/dist/chunk-PC4UYEBM.js.map +0 -1
- package/dist/chunk-PICTDURQ.js +0 -766
- package/dist/chunk-PICTDURQ.js.map +0 -1
- package/dist/chunk-PJQFMIOX.js +0 -1182
- package/dist/chunk-PJQFMIOX.js.map +0 -1
- package/dist/chunk-PXD6ZFNY.js +0 -1107
- package/dist/chunk-PXD6ZFNY.js.map +0 -1
- package/dist/chunk-PXE2VKMX.js +0 -140
- package/dist/chunk-PXE2VKMX.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/chunk-QBRSJK47.js +0 -622
- package/dist/chunk-QBRSJK47.js.map +0 -1
- package/dist/chunk-QWMPPZ3X.js +0 -550
- package/dist/chunk-QWMPPZ3X.js.map +0 -1
- package/dist/chunk-S3UZOQ5Y.js +0 -328
- package/dist/chunk-S3UZOQ5Y.js.map +0 -1
- package/dist/chunk-S5TT5R3L.js +0 -2668
- package/dist/chunk-S5TT5R3L.js.map +0 -1
- package/dist/chunk-T4SQEITX.js +0 -95
- package/dist/chunk-T4SQEITX.js.map +0 -1
- package/dist/chunk-TT4KNT67.js +0 -124
- package/dist/chunk-TT4KNT67.js.map +0 -1
- package/dist/chunk-U5CHZ5M3.js +0 -357
- package/dist/chunk-U5CHZ5M3.js.map +0 -1
- package/dist/chunk-ULOKLHIQ.js +0 -1937
- package/dist/chunk-ULOKLHIQ.js.map +0 -1
- package/dist/chunk-VI2UW6B6.js +0 -162
- package/dist/chunk-VI2UW6B6.js.map +0 -1
- package/dist/chunk-VQMK5FMP.js +0 -247
- package/dist/chunk-VQMK5FMP.js.map +0 -1
- package/dist/chunk-VSMTAMNK.js +0 -53
- package/dist/chunk-VSMTAMNK.js.map +0 -1
- package/dist/chunk-VZSRQ272.js +0 -149
- package/dist/chunk-VZSRQ272.js.map +0 -1
- package/dist/chunk-WW2A73HW.js +0 -159
- package/dist/chunk-WW2A73HW.js.map +0 -1
- package/dist/chunk-X4UCIOTZ.js +0 -136
- package/dist/chunk-X4UCIOTZ.js.map +0 -1
- package/dist/chunk-XDIRG3TO.js +0 -1266
- package/dist/chunk-XDIRG3TO.js.map +0 -1
- package/dist/chunk-XJYR7XFV.js +0 -317
- package/dist/chunk-XJYR7XFV.js.map +0 -1
- package/dist/chunk-ZET2UAYW.js +0 -89
- package/dist/chunk-ZET2UAYW.js.map +0 -1
- package/dist/chunk-ZZUXHH3R.js +0 -99
- package/dist/chunk-ZZUXHH3R.js.map +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -112
- package/dist/cli.js.map +0 -1
- package/dist/contract/index.d.ts +0 -4969
- package/dist/contract/index.js +0 -1653
- package/dist/contract/index.js.map +0 -1
- package/dist/control.d.ts +0 -1013
- package/dist/control.js +0 -34
- package/dist/control.js.map +0 -1
- package/dist/fuzz.d.ts +0 -759
- package/dist/fuzz.js +0 -714
- package/dist/fuzz.js.map +0 -1
- package/dist/hosted/index.d.ts +0 -730
- package/dist/hosted/index.js +0 -14
- package/dist/hosted/index.js.map +0 -1
- package/dist/index.d.ts +0 -16780
- package/dist/index.js +0 -12168
- package/dist/index.js.map +0 -1
- package/dist/matrix/index.d.ts +0 -155
- package/dist/matrix/index.js +0 -8
- package/dist/matrix/index.js.map +0 -1
- package/dist/meta-eval/index.d.ts +0 -1030
- package/dist/meta-eval/index.js +0 -417
- package/dist/meta-eval/index.js.map +0 -1
- package/dist/multishot/index.d.ts +0 -579
- package/dist/multishot/index.js +0 -589
- package/dist/multishot/index.js.map +0 -1
- package/dist/openapi.json +0 -992
- package/dist/pipelines/index.d.ts +0 -567
- package/dist/pipelines/index.js +0 -515
- package/dist/pipelines/index.js.map +0 -1
- package/dist/reporting.d.ts +0 -1277
- package/dist/reporting.js +0 -48
- package/dist/reporting.js.map +0 -1
- package/dist/rl.d.ts +0 -4092
- package/dist/rl.js +0 -1724
- package/dist/rl.js.map +0 -1
- package/dist/run-campaign-HNFPJET4.js +0 -14
- package/dist/run-campaign-HNFPJET4.js.map +0 -1
- package/dist/storyboard/index.d.ts +0 -279
- package/dist/storyboard/index.js +0 -767
- package/dist/storyboard/index.js.map +0 -1
- package/dist/trace-attributes.d.ts +0 -52
- package/dist/trace-attributes.js +0 -62
- package/dist/trace-attributes.js.map +0 -1
- package/dist/traces.d.ts +0 -2343
- package/dist/traces.js +0 -249
- package/dist/traces.js.map +0 -1
- package/dist/wire/index.d.ts +0 -1252
- package/dist/wire/index.js +0 -81
- package/dist/wire/index.js.map +0 -1
package/dist/chunk-HKUCJ437.js
DELETED
|
@@ -1,787 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
estimateCost,
|
|
3
|
-
isModelPriced
|
|
4
|
-
} from "./chunk-VI2UW6B6.js";
|
|
5
|
-
import {
|
|
6
|
-
extractUsage
|
|
7
|
-
} from "./chunk-PXE2VKMX.js";
|
|
8
|
-
|
|
9
|
-
// src/contract/intake/code-agent-session.ts
|
|
10
|
-
import { createHash } from "crypto";
|
|
11
|
-
function parseCodeAgentJsonl(jsonl) {
|
|
12
|
-
const entries = [];
|
|
13
|
-
let malformedLines = 0;
|
|
14
|
-
for (const line of jsonl.split("\n")) {
|
|
15
|
-
const trimmed = line.trim();
|
|
16
|
-
if (!trimmed) continue;
|
|
17
|
-
try {
|
|
18
|
-
entries.push(JSON.parse(trimmed));
|
|
19
|
-
} catch {
|
|
20
|
-
malformedLines += 1;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return { entries, malformedLines };
|
|
24
|
-
}
|
|
25
|
-
function fromCodexSession(options) {
|
|
26
|
-
return fromCodeAgentSession("codex", options);
|
|
27
|
-
}
|
|
28
|
-
function fromClaudeCodeSession(options) {
|
|
29
|
-
return fromCodeAgentSession("claude-code", options);
|
|
30
|
-
}
|
|
31
|
-
function fromOpenCodeSession(options) {
|
|
32
|
-
return fromCodeAgentSession("opencode", options);
|
|
33
|
-
}
|
|
34
|
-
function fromKimiCodeSession(options) {
|
|
35
|
-
return fromCodeAgentSession("kimi-code", options);
|
|
36
|
-
}
|
|
37
|
-
function fromPiSession(options) {
|
|
38
|
-
return fromCodeAgentSession("pi", options);
|
|
39
|
-
}
|
|
40
|
-
var fromPigraphSession = fromPiSession;
|
|
41
|
-
function fromCodeAgentSession(source, options) {
|
|
42
|
-
const entries = options.entries.filter(isRecord);
|
|
43
|
-
if (entries.length === 0) {
|
|
44
|
-
return {
|
|
45
|
-
runs: [],
|
|
46
|
-
diagnostics: [
|
|
47
|
-
{
|
|
48
|
-
source,
|
|
49
|
-
sessionId: fallbackSessionId(source, options.sourcePath),
|
|
50
|
-
sourcePath: options.sourcePath,
|
|
51
|
-
entries: 0,
|
|
52
|
-
malformedLines: options.malformedLines ?? 0,
|
|
53
|
-
inferredScore: true,
|
|
54
|
-
hasExplicitTerminalSignal: false,
|
|
55
|
-
hasQualityLabel: false,
|
|
56
|
-
hasTokenUsage: false,
|
|
57
|
-
hasCost: false,
|
|
58
|
-
costKind: "uncaptured",
|
|
59
|
-
warnings: ["no parseable session entries"]
|
|
60
|
-
}
|
|
61
|
-
],
|
|
62
|
-
metrics: []
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
const metrics = metricsFor(source, entries);
|
|
66
|
-
const sessionId = sessionIdFromEntries(source, entries) ?? fallbackSessionId(source, options.sourcePath);
|
|
67
|
-
const model = withSnapshot(options.model ?? modelFromEntries(source, entries) ?? source);
|
|
68
|
-
const tokenUsage = {
|
|
69
|
-
input: metrics.inputTokens,
|
|
70
|
-
output: metrics.outputTokens,
|
|
71
|
-
...metrics.reasoningTokens > 0 ? { reasoning: metrics.reasoningTokens } : {},
|
|
72
|
-
...metrics.cachedTokens > 0 ? { cached: metrics.cachedTokens } : {},
|
|
73
|
-
...metrics.cacheWriteTokens > 0 ? { cacheWrite: metrics.cacheWriteTokens } : {}
|
|
74
|
-
};
|
|
75
|
-
const { costUsd, costProvenance } = resolveSessionCost(options.costProvenance, metrics, model);
|
|
76
|
-
const score = clamp01(options.score ?? metrics.processScore);
|
|
77
|
-
const promptHash = options.promptHash ?? hashString(`prompt:${source}:${firstUserText(entries) ?? ""}`);
|
|
78
|
-
const configHash = options.configHash ?? hashJson({
|
|
79
|
-
source,
|
|
80
|
-
model,
|
|
81
|
-
sourcePath: options.sourcePath,
|
|
82
|
-
cwd: cwdFromEntries(entries),
|
|
83
|
-
entryCount: entries.length
|
|
84
|
-
});
|
|
85
|
-
const explicitTerminal = hasExplicitTerminalSignal(source, metrics);
|
|
86
|
-
const warnings = diagnosticsFor(metrics, {
|
|
87
|
-
model,
|
|
88
|
-
explicitTerminal,
|
|
89
|
-
malformedLines: options.malformedLines ?? 0,
|
|
90
|
-
scoreOverridden: options.score !== void 0,
|
|
91
|
-
costKind: costProvenance.kind
|
|
92
|
-
});
|
|
93
|
-
const run = {
|
|
94
|
-
runId: `${source}:${sessionId}`,
|
|
95
|
-
experimentId: options.experimentId ?? `${source}-local-sessions`,
|
|
96
|
-
candidateId: options.candidateId ?? model,
|
|
97
|
-
seed: options.seed ?? stableSeed(sessionId),
|
|
98
|
-
model,
|
|
99
|
-
promptHash,
|
|
100
|
-
configHash,
|
|
101
|
-
commitSha: options.commitSha ?? "local-session",
|
|
102
|
-
wallMs: metrics.wallMs,
|
|
103
|
-
costUsd,
|
|
104
|
-
costProvenance,
|
|
105
|
-
tokenUsage,
|
|
106
|
-
outcome: {
|
|
107
|
-
holdoutScore: score,
|
|
108
|
-
raw: {
|
|
109
|
-
entries: metrics.entries,
|
|
110
|
-
user_messages: metrics.userMessages,
|
|
111
|
-
assistant_messages: metrics.assistantMessages,
|
|
112
|
-
reasoning_items: metrics.reasoningItems,
|
|
113
|
-
tool_calls: metrics.toolCalls,
|
|
114
|
-
tool_outputs: metrics.toolOutputs,
|
|
115
|
-
tool_errors: metrics.toolErrors,
|
|
116
|
-
patch_attempts: metrics.patchAttempts,
|
|
117
|
-
patch_successes: metrics.patchSuccesses,
|
|
118
|
-
patch_failures: metrics.patchFailures,
|
|
119
|
-
turns_started: metrics.turnsStarted,
|
|
120
|
-
turns_completed: metrics.turnsCompleted,
|
|
121
|
-
turns_aborted: metrics.turnsAborted,
|
|
122
|
-
context_compactions: metrics.contextCompactions,
|
|
123
|
-
pr_links: metrics.prLinks,
|
|
124
|
-
file_snapshots: metrics.fileSnapshots,
|
|
125
|
-
graph_nodes: metrics.graphNodes,
|
|
126
|
-
graph_edges: metrics.graphEdges,
|
|
127
|
-
action_candidates: metrics.actionCandidates,
|
|
128
|
-
verification_reports: metrics.verificationReports,
|
|
129
|
-
completion_decisions: metrics.completionDecisions,
|
|
130
|
-
reliability_rows: metrics.reliabilityRows,
|
|
131
|
-
reliability_lift: metrics.reliabilityLift,
|
|
132
|
-
input_tokens: metrics.inputTokens,
|
|
133
|
-
output_tokens: metrics.outputTokens,
|
|
134
|
-
reasoning_tokens: metrics.reasoningTokens,
|
|
135
|
-
cached_tokens: metrics.cachedTokens,
|
|
136
|
-
cache_write_tokens: metrics.cacheWriteTokens,
|
|
137
|
-
observed_cost_usd: metrics.observedCostUsd,
|
|
138
|
-
observed_cost_captured: metrics.observedCostCaptured ? 1 : 0,
|
|
139
|
-
estimated_cost_usd: costProvenance.kind === "estimated" ? costUsd : 0,
|
|
140
|
-
process_score: score,
|
|
141
|
-
inferred_score: options.score === void 0 ? 1 : 0,
|
|
142
|
-
explicit_terminal_signal: explicitTerminal ? 1 : 0,
|
|
143
|
-
quality_label_present: options.score !== void 0 ? 1 : 0,
|
|
144
|
-
cost_observed: costProvenance.kind === "observed" ? 1 : 0,
|
|
145
|
-
cost_estimated: costProvenance.kind === "estimated" ? 1 : 0,
|
|
146
|
-
cost_uncaptured: costProvenance.kind === "uncaptured" ? 1 : 0,
|
|
147
|
-
cost_unknown: costProvenance.kind === "uncaptured" ? 1 : 0
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
splitTag: options.splitTag ?? "holdout",
|
|
151
|
-
...options.scenarioId ? { scenarioId: options.scenarioId } : {},
|
|
152
|
-
...metrics.toolErrors > 0 || metrics.turnsAborted > 0 ? { failureMode: metrics.turnsAborted > 0 ? "turn_aborted" : "tool_error" } : {}
|
|
153
|
-
};
|
|
154
|
-
return {
|
|
155
|
-
runs: [run],
|
|
156
|
-
diagnostics: [
|
|
157
|
-
{
|
|
158
|
-
source,
|
|
159
|
-
sessionId,
|
|
160
|
-
sourcePath: options.sourcePath,
|
|
161
|
-
entries: entries.length,
|
|
162
|
-
malformedLines: options.malformedLines ?? 0,
|
|
163
|
-
inferredScore: options.score === void 0,
|
|
164
|
-
hasExplicitTerminalSignal: explicitTerminal,
|
|
165
|
-
hasQualityLabel: options.score !== void 0,
|
|
166
|
-
hasTokenUsage: metrics.inputTokens > 0 || metrics.outputTokens > 0 || metrics.reasoningTokens > 0 || metrics.cachedTokens > 0 || metrics.cacheWriteTokens > 0,
|
|
167
|
-
hasCost: costProvenance.kind !== "uncaptured",
|
|
168
|
-
costKind: costProvenance.kind,
|
|
169
|
-
warnings
|
|
170
|
-
}
|
|
171
|
-
],
|
|
172
|
-
metrics: [metrics]
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function metricsFor(source, entries) {
|
|
176
|
-
switch (source) {
|
|
177
|
-
case "codex":
|
|
178
|
-
return codexMetrics(entries);
|
|
179
|
-
case "claude-code":
|
|
180
|
-
return claudeCodeMetrics(entries);
|
|
181
|
-
case "opencode":
|
|
182
|
-
return openCodeMetrics(entries);
|
|
183
|
-
case "kimi-code":
|
|
184
|
-
return kimiCodeMetrics(entries);
|
|
185
|
-
case "pi":
|
|
186
|
-
return piMetrics(entries);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
function codexMetrics(entries) {
|
|
190
|
-
const metrics = emptyMetrics(entries.length);
|
|
191
|
-
const startedToolIds = /* @__PURE__ */ new Set();
|
|
192
|
-
let startedAt;
|
|
193
|
-
let completedAt;
|
|
194
|
-
for (const entry of entries) {
|
|
195
|
-
const payload = record(entry.payload) ?? {};
|
|
196
|
-
const entryType = stringField(entry, "type");
|
|
197
|
-
const payloadType = stringField(payload, "type");
|
|
198
|
-
const timestamp = timestampMs(entry.timestamp);
|
|
199
|
-
if (timestamp !== void 0) {
|
|
200
|
-
startedAt = startedAt === void 0 ? timestamp : Math.min(startedAt, timestamp);
|
|
201
|
-
completedAt = completedAt === void 0 ? timestamp : Math.max(completedAt, timestamp);
|
|
202
|
-
}
|
|
203
|
-
if (entryType === "turn.started") metrics.turnsStarted += 1;
|
|
204
|
-
if (entryType === "turn.completed") {
|
|
205
|
-
metrics.turnsCompleted += 1;
|
|
206
|
-
addCodexExecUsage(metrics, record(entry.usage));
|
|
207
|
-
}
|
|
208
|
-
if (entryType === "turn.failed") metrics.turnsAborted += 1;
|
|
209
|
-
if (entryType === "error") metrics.toolErrors += 1;
|
|
210
|
-
const item = record(entry.item);
|
|
211
|
-
if (item && (entryType === "item.started" || entryType === "item.completed")) {
|
|
212
|
-
addCodexExecItem(metrics, startedToolIds, entryType, item);
|
|
213
|
-
}
|
|
214
|
-
if (entryType === "response_item") {
|
|
215
|
-
if (payloadType === "function_call" || payloadType === "custom_tool_call")
|
|
216
|
-
metrics.toolCalls += 1;
|
|
217
|
-
if (payloadType === "function_call_output" || payloadType === "custom_tool_call_output")
|
|
218
|
-
metrics.toolOutputs += 1;
|
|
219
|
-
if (payloadType === "reasoning") metrics.reasoningItems += 1;
|
|
220
|
-
if (payloadType === "message" && stringField(payload, "role") === "assistant")
|
|
221
|
-
metrics.assistantMessages += 1;
|
|
222
|
-
}
|
|
223
|
-
if (entryType === "event_msg") {
|
|
224
|
-
if (payloadType === "user_message") metrics.userMessages += 1;
|
|
225
|
-
if (payloadType === "agent_message") metrics.assistantMessages += 1;
|
|
226
|
-
if (payloadType === "task_started") {
|
|
227
|
-
metrics.turnsStarted += 1;
|
|
228
|
-
const started = timestampMs(payload.started_at);
|
|
229
|
-
if (started !== void 0) {
|
|
230
|
-
startedAt = startedAt === void 0 ? started : Math.min(startedAt, started);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (payloadType === "task_complete") {
|
|
234
|
-
metrics.turnsCompleted += 1;
|
|
235
|
-
const completed = timestampMs(payload.completed_at);
|
|
236
|
-
if (completed !== void 0) {
|
|
237
|
-
completedAt = completedAt === void 0 ? completed : Math.max(completedAt, completed);
|
|
238
|
-
}
|
|
239
|
-
const duration = numberField(payload, "duration_ms");
|
|
240
|
-
if (duration !== void 0) metrics.wallMs = Math.max(metrics.wallMs, duration);
|
|
241
|
-
}
|
|
242
|
-
if (payloadType === "turn_aborted") {
|
|
243
|
-
metrics.turnsAborted += 1;
|
|
244
|
-
const completed = timestampMs(payload.completed_at);
|
|
245
|
-
if (completed !== void 0) {
|
|
246
|
-
completedAt = completedAt === void 0 ? completed : Math.max(completedAt, completed);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
if (payloadType === "context_compacted") metrics.contextCompactions += 1;
|
|
250
|
-
if (payloadType === "patch_apply_end") {
|
|
251
|
-
metrics.patchAttempts += 1;
|
|
252
|
-
if (payload.success === true) metrics.patchSuccesses += 1;
|
|
253
|
-
else {
|
|
254
|
-
metrics.patchFailures += 1;
|
|
255
|
-
metrics.toolErrors += 1;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
if (payloadType === "token_count")
|
|
259
|
-
setCodexCumulativeUsage(metrics, record(record(payload.info)?.total_token_usage));
|
|
260
|
-
const result = record(payload.result);
|
|
261
|
-
if (result && "Err" in result) metrics.toolErrors += 1;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
if (metrics.wallMs === 0 && startedAt !== void 0 && completedAt !== void 0) {
|
|
265
|
-
metrics.wallMs = Math.max(0, completedAt - startedAt);
|
|
266
|
-
}
|
|
267
|
-
metrics.processScore = codexProcessScore(metrics);
|
|
268
|
-
return metrics;
|
|
269
|
-
}
|
|
270
|
-
function addCodexExecItem(metrics, startedToolIds, eventType, item) {
|
|
271
|
-
const itemType = stringField(item, "type");
|
|
272
|
-
const itemId = stringField(item, "id");
|
|
273
|
-
const isTool = itemType === "command_execution" || itemType === "mcp_tool_call" || itemType === "collab_tool_call" || itemType === "web_search";
|
|
274
|
-
if (eventType === "item.started" && isTool) {
|
|
275
|
-
metrics.toolCalls += 1;
|
|
276
|
-
if (itemId) startedToolIds.add(itemId);
|
|
277
|
-
}
|
|
278
|
-
if (eventType === "item.completed" && isTool) {
|
|
279
|
-
if (!itemId || !startedToolIds.has(itemId)) metrics.toolCalls += 1;
|
|
280
|
-
metrics.toolOutputs += 1;
|
|
281
|
-
}
|
|
282
|
-
if (eventType !== "item.completed") return;
|
|
283
|
-
if (itemType === "agent_message" || itemType === "message") metrics.assistantMessages += 1;
|
|
284
|
-
if (itemType === "reasoning") metrics.reasoningItems += 1;
|
|
285
|
-
if (itemType === "file_change") {
|
|
286
|
-
metrics.patchAttempts += 1;
|
|
287
|
-
const status = stringField(item, "status");
|
|
288
|
-
if (status === "completed") metrics.patchSuccesses += 1;
|
|
289
|
-
if (status === "failed") {
|
|
290
|
-
metrics.patchFailures += 1;
|
|
291
|
-
metrics.toolErrors += 1;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
if (itemType === "error" || codexExecToolFailed(itemType, item)) metrics.toolErrors += 1;
|
|
295
|
-
}
|
|
296
|
-
function codexExecToolFailed(itemType, item) {
|
|
297
|
-
const status = stringField(item, "status");
|
|
298
|
-
if (itemType === "command_execution") {
|
|
299
|
-
const exitCode = numberField(item, "exit_code");
|
|
300
|
-
return status === "failed" || status === "declined" || exitCode !== void 0 && exitCode !== 0;
|
|
301
|
-
}
|
|
302
|
-
if (itemType === "mcp_tool_call") return status === "failed" || record(item.error) !== null;
|
|
303
|
-
return itemType === "collab_tool_call" && status === "failed";
|
|
304
|
-
}
|
|
305
|
-
function addCodexExecUsage(metrics, usage) {
|
|
306
|
-
const parsed = readUsage(usage);
|
|
307
|
-
metrics.inputTokens += parsed.input;
|
|
308
|
-
metrics.outputTokens += parsed.output;
|
|
309
|
-
metrics.reasoningTokens += parsed.reasoning;
|
|
310
|
-
metrics.cachedTokens += parsed.cached;
|
|
311
|
-
metrics.cacheWriteTokens += parsed.cacheWrite;
|
|
312
|
-
}
|
|
313
|
-
function setCodexCumulativeUsage(metrics, usage) {
|
|
314
|
-
const parsed = readUsage(usage);
|
|
315
|
-
metrics.inputTokens = Math.max(metrics.inputTokens, parsed.input);
|
|
316
|
-
metrics.outputTokens = Math.max(metrics.outputTokens, parsed.output);
|
|
317
|
-
metrics.reasoningTokens = Math.max(metrics.reasoningTokens, parsed.reasoning);
|
|
318
|
-
metrics.cachedTokens = Math.max(metrics.cachedTokens, parsed.cached);
|
|
319
|
-
metrics.cacheWriteTokens = Math.max(metrics.cacheWriteTokens, parsed.cacheWrite);
|
|
320
|
-
}
|
|
321
|
-
function claudeCodeMetrics(entries) {
|
|
322
|
-
const metrics = emptyMetrics(entries.length);
|
|
323
|
-
let startedAt;
|
|
324
|
-
let completedAt;
|
|
325
|
-
for (const entry of entries) {
|
|
326
|
-
const type = stringField(entry, "type");
|
|
327
|
-
const timestamp = timestampMs(entry.timestamp);
|
|
328
|
-
if (timestamp !== void 0) {
|
|
329
|
-
startedAt = startedAt === void 0 ? timestamp : Math.min(startedAt, timestamp);
|
|
330
|
-
completedAt = completedAt === void 0 ? timestamp : Math.max(completedAt, timestamp);
|
|
331
|
-
}
|
|
332
|
-
if (type === "user") metrics.userMessages += 1;
|
|
333
|
-
if (type === "assistant") metrics.assistantMessages += 1;
|
|
334
|
-
if (type === "pr-link") metrics.prLinks += 1;
|
|
335
|
-
if (type === "file-history-snapshot") metrics.fileSnapshots += 1;
|
|
336
|
-
const message = record(entry.message);
|
|
337
|
-
if (message) addUsage(metrics, record(message.usage));
|
|
338
|
-
const content = Array.isArray(message?.content) ? message.content : [];
|
|
339
|
-
for (const item of content) {
|
|
340
|
-
const part = record(item);
|
|
341
|
-
if (!part) continue;
|
|
342
|
-
const partType = stringField(part, "type");
|
|
343
|
-
if (partType === "thinking") metrics.reasoningItems += 1;
|
|
344
|
-
if (partType === "tool_use") metrics.toolCalls += 1;
|
|
345
|
-
if (partType === "tool_result") {
|
|
346
|
-
metrics.toolOutputs += 1;
|
|
347
|
-
if (part.is_error === true) metrics.toolErrors += 1;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
if (startedAt !== void 0 && completedAt !== void 0)
|
|
352
|
-
metrics.wallMs = Math.max(0, completedAt - startedAt);
|
|
353
|
-
metrics.processScore = claudeProcessScore(metrics);
|
|
354
|
-
return metrics;
|
|
355
|
-
}
|
|
356
|
-
function openCodeMetrics(entries) {
|
|
357
|
-
const metrics = emptyMetrics(entries.length);
|
|
358
|
-
const messageUsage = emptyTokenTotals();
|
|
359
|
-
const partUsage = emptyTokenTotals();
|
|
360
|
-
let messageCost = 0;
|
|
361
|
-
let partCost = 0;
|
|
362
|
-
let messageCostCaptured = false;
|
|
363
|
-
let partCostCaptured = false;
|
|
364
|
-
let startedAt;
|
|
365
|
-
let completedAt;
|
|
366
|
-
for (const entry of entries) {
|
|
367
|
-
const time = record(entry.time);
|
|
368
|
-
const created = timestampMs(time?.created);
|
|
369
|
-
const completed = timestampMs(time?.completed);
|
|
370
|
-
if (created !== void 0)
|
|
371
|
-
startedAt = startedAt === void 0 ? created : Math.min(startedAt, created);
|
|
372
|
-
if (completed !== void 0)
|
|
373
|
-
completedAt = completedAt === void 0 ? completed : Math.max(completedAt, completed);
|
|
374
|
-
const role = stringField(entry, "role");
|
|
375
|
-
if (role === "user") metrics.userMessages += 1;
|
|
376
|
-
if (role === "assistant") {
|
|
377
|
-
metrics.assistantMessages += 1;
|
|
378
|
-
const finish = stringField(entry, "finish");
|
|
379
|
-
if (finish === "stop") metrics.turnsCompleted += 1;
|
|
380
|
-
if (finish === "error") metrics.turnsAborted += 1;
|
|
381
|
-
}
|
|
382
|
-
const type = stringField(entry, "type");
|
|
383
|
-
if (type === "reasoning") metrics.reasoningItems += 1;
|
|
384
|
-
if (type === "tool") {
|
|
385
|
-
metrics.toolCalls += 1;
|
|
386
|
-
const status = stringField(record(entry.state) ?? {}, "status");
|
|
387
|
-
if (status === "completed") metrics.toolOutputs += 1;
|
|
388
|
-
if (status === "error") {
|
|
389
|
-
metrics.toolOutputs += 1;
|
|
390
|
-
metrics.toolErrors += 1;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
if (type === "patch") {
|
|
394
|
-
metrics.patchAttempts += 1;
|
|
395
|
-
metrics.patchSuccesses += 1;
|
|
396
|
-
}
|
|
397
|
-
const cost = numberField(entry, "cost");
|
|
398
|
-
if (record(entry.tokens) && role) {
|
|
399
|
-
addUsageTo(messageUsage, record(entry.tokens));
|
|
400
|
-
if (cost !== void 0) {
|
|
401
|
-
messageCost += cost;
|
|
402
|
-
messageCostCaptured = true;
|
|
403
|
-
}
|
|
404
|
-
} else if (record(entry.tokens)) {
|
|
405
|
-
addUsageTo(partUsage, record(entry.tokens));
|
|
406
|
-
if (cost !== void 0) {
|
|
407
|
-
partCost += cost;
|
|
408
|
-
partCostCaptured = true;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
const usage = hasTokenTotals(messageUsage) ? messageUsage : partUsage;
|
|
413
|
-
metrics.inputTokens = usage.input;
|
|
414
|
-
metrics.outputTokens = usage.output;
|
|
415
|
-
metrics.reasoningTokens = usage.reasoning;
|
|
416
|
-
metrics.cachedTokens = usage.cached;
|
|
417
|
-
metrics.cacheWriteTokens = usage.cacheWrite;
|
|
418
|
-
metrics.observedCostUsd = messageCostCaptured ? messageCost : partCost;
|
|
419
|
-
metrics.observedCostCaptured = messageCostCaptured || partCostCaptured;
|
|
420
|
-
if (metrics.wallMs === 0 && startedAt !== void 0 && completedAt !== void 0)
|
|
421
|
-
metrics.wallMs = Math.max(0, completedAt - startedAt);
|
|
422
|
-
metrics.processScore = terminalProcessScore(metrics);
|
|
423
|
-
return metrics;
|
|
424
|
-
}
|
|
425
|
-
function kimiCodeMetrics(entries) {
|
|
426
|
-
const metrics = emptyMetrics(entries.length);
|
|
427
|
-
let startedAt;
|
|
428
|
-
let completedAt;
|
|
429
|
-
for (const entry of entries) {
|
|
430
|
-
const timestamp = timestampMs(entry.timestamp);
|
|
431
|
-
if (timestamp !== void 0) {
|
|
432
|
-
startedAt = startedAt === void 0 ? timestamp : Math.min(startedAt, timestamp);
|
|
433
|
-
completedAt = completedAt === void 0 ? timestamp : Math.max(completedAt, timestamp);
|
|
434
|
-
}
|
|
435
|
-
const role = stringField(entry, "role");
|
|
436
|
-
if (role === "user") metrics.userMessages += 1;
|
|
437
|
-
if (role === "assistant") metrics.assistantMessages += 1;
|
|
438
|
-
if (role === "_usage") addUsage(metrics, entry);
|
|
439
|
-
const message = record(entry.message);
|
|
440
|
-
const messageType = message ? stringField(message, "type") : void 0;
|
|
441
|
-
const payload = record(message?.payload) ?? {};
|
|
442
|
-
if (messageType === "TurnBegin") {
|
|
443
|
-
metrics.userMessages += 1;
|
|
444
|
-
metrics.turnsStarted += 1;
|
|
445
|
-
}
|
|
446
|
-
if (messageType === "TurnEnd") metrics.turnsCompleted += 1;
|
|
447
|
-
if (messageType === "StepInterrupted") metrics.turnsAborted += 1;
|
|
448
|
-
if (messageType === "StepBegin") metrics.reasoningItems += 1;
|
|
449
|
-
if (messageType === "ContentPart") {
|
|
450
|
-
const payloadType = stringField(payload, "type");
|
|
451
|
-
if (payloadType === "think") metrics.reasoningItems += 1;
|
|
452
|
-
if (payloadType === "text") metrics.assistantMessages += 1;
|
|
453
|
-
}
|
|
454
|
-
if (messageType === "ToolCall") metrics.toolCalls += 1;
|
|
455
|
-
if (messageType === "ToolResult") {
|
|
456
|
-
metrics.toolOutputs += 1;
|
|
457
|
-
if (record(payload.return_value)?.is_error === true) metrics.toolErrors += 1;
|
|
458
|
-
}
|
|
459
|
-
if (messageType === "StatusUpdate") addUsage(metrics, record(payload.token_usage));
|
|
460
|
-
if (messageType === "Notification") {
|
|
461
|
-
const notification = record(payload.payload);
|
|
462
|
-
const exitCode = numberField(notification ?? {}, "exit_code");
|
|
463
|
-
if (notification?.timed_out === true || exitCode !== void 0 && exitCode !== 0) {
|
|
464
|
-
metrics.toolErrors += 1;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
if (startedAt !== void 0 && completedAt !== void 0)
|
|
469
|
-
metrics.wallMs = Math.max(0, completedAt - startedAt);
|
|
470
|
-
metrics.processScore = terminalProcessScore(metrics);
|
|
471
|
-
return metrics;
|
|
472
|
-
}
|
|
473
|
-
function piMetrics(entries) {
|
|
474
|
-
const metrics = emptyMetrics(entries.length);
|
|
475
|
-
let bestReliabilityScore;
|
|
476
|
-
for (const entry of entries) {
|
|
477
|
-
const nodes = Array.isArray(entry.nodes) ? entry.nodes : [];
|
|
478
|
-
const edges = Array.isArray(entry.edges) ? entry.edges : [];
|
|
479
|
-
metrics.graphNodes += nodes.length;
|
|
480
|
-
metrics.graphEdges += edges.length;
|
|
481
|
-
for (const node of nodes) {
|
|
482
|
-
const obj = record(node);
|
|
483
|
-
const ir = record(obj?.ir) ?? obj;
|
|
484
|
-
const kind = stringField(ir ?? {}, "kind");
|
|
485
|
-
if (kind === "ActionCandidate") metrics.actionCandidates += 1;
|
|
486
|
-
if (kind === "ToolInvocation") metrics.toolCalls += 1;
|
|
487
|
-
if (kind === "ToolResult") metrics.toolOutputs += 1;
|
|
488
|
-
if (kind === "VerificationReport") metrics.verificationReports += 1;
|
|
489
|
-
if (kind === "CompletionDecision") {
|
|
490
|
-
metrics.completionDecisions += 1;
|
|
491
|
-
metrics.turnsCompleted += 1;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
const averageReliability = numberField(entry, "averageNodeReliability");
|
|
495
|
-
if (averageReliability !== void 0)
|
|
496
|
-
bestReliabilityScore = maxOptional(bestReliabilityScore, averageReliability);
|
|
497
|
-
const pessimisticPath = numberField(entry, "pessimisticPathEstimate");
|
|
498
|
-
if (pessimisticPath !== void 0)
|
|
499
|
-
bestReliabilityScore = maxOptional(bestReliabilityScore, pessimisticPath);
|
|
500
|
-
const rows = Array.isArray(entry.rows) ? entry.rows : [];
|
|
501
|
-
metrics.reliabilityRows += rows.length;
|
|
502
|
-
for (const row of rows) {
|
|
503
|
-
const obj = record(row);
|
|
504
|
-
if (!obj) continue;
|
|
505
|
-
const lift = numberField(obj, "lift");
|
|
506
|
-
if (lift !== void 0) metrics.reliabilityLift = Math.max(metrics.reliabilityLift, lift);
|
|
507
|
-
const validated = numberField(obj, "validatedSuccessEstimate");
|
|
508
|
-
if (validated !== void 0)
|
|
509
|
-
bestReliabilityScore = maxOptional(bestReliabilityScore, validated);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
metrics.processScore = bestReliabilityScore !== void 0 ? clamp01(bestReliabilityScore) : metrics.completionDecisions > 0 ? 1 : 0;
|
|
513
|
-
return metrics;
|
|
514
|
-
}
|
|
515
|
-
function emptyMetrics(entries) {
|
|
516
|
-
return {
|
|
517
|
-
entries,
|
|
518
|
-
userMessages: 0,
|
|
519
|
-
assistantMessages: 0,
|
|
520
|
-
reasoningItems: 0,
|
|
521
|
-
toolCalls: 0,
|
|
522
|
-
toolOutputs: 0,
|
|
523
|
-
toolErrors: 0,
|
|
524
|
-
patchAttempts: 0,
|
|
525
|
-
patchSuccesses: 0,
|
|
526
|
-
patchFailures: 0,
|
|
527
|
-
turnsStarted: 0,
|
|
528
|
-
turnsCompleted: 0,
|
|
529
|
-
turnsAborted: 0,
|
|
530
|
-
contextCompactions: 0,
|
|
531
|
-
prLinks: 0,
|
|
532
|
-
fileSnapshots: 0,
|
|
533
|
-
graphNodes: 0,
|
|
534
|
-
graphEdges: 0,
|
|
535
|
-
actionCandidates: 0,
|
|
536
|
-
verificationReports: 0,
|
|
537
|
-
completionDecisions: 0,
|
|
538
|
-
reliabilityRows: 0,
|
|
539
|
-
reliabilityLift: 0,
|
|
540
|
-
inputTokens: 0,
|
|
541
|
-
outputTokens: 0,
|
|
542
|
-
reasoningTokens: 0,
|
|
543
|
-
cachedTokens: 0,
|
|
544
|
-
cacheWriteTokens: 0,
|
|
545
|
-
observedCostUsd: 0,
|
|
546
|
-
observedCostCaptured: false,
|
|
547
|
-
wallMs: 0,
|
|
548
|
-
processScore: 0
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
function codexProcessScore(metrics) {
|
|
552
|
-
const terminalTurns = metrics.turnsCompleted + metrics.turnsAborted;
|
|
553
|
-
const base = terminalTurns > 0 ? metrics.turnsCompleted / terminalTurns : metrics.assistantMessages > 0 ? 0.5 : 0;
|
|
554
|
-
return penalizeErrors(base, metrics);
|
|
555
|
-
}
|
|
556
|
-
function claudeProcessScore(metrics) {
|
|
557
|
-
const base = metrics.prLinks > 0 ? 1 : metrics.assistantMessages > 0 ? 0.75 : 0;
|
|
558
|
-
return penalizeErrors(base, metrics);
|
|
559
|
-
}
|
|
560
|
-
function terminalProcessScore(metrics) {
|
|
561
|
-
const terminalTurns = metrics.turnsCompleted + metrics.turnsAborted;
|
|
562
|
-
const base = terminalTurns > 0 ? metrics.turnsCompleted / terminalTurns : metrics.assistantMessages > 0 ? 0.75 : metrics.toolCalls > 0 ? 0.5 : 0;
|
|
563
|
-
return penalizeErrors(base, metrics);
|
|
564
|
-
}
|
|
565
|
-
function penalizeErrors(base, metrics) {
|
|
566
|
-
const operations = Math.max(1, metrics.toolCalls + metrics.patchAttempts);
|
|
567
|
-
const errorRate = Math.min(1, (metrics.toolErrors + metrics.patchFailures) / operations);
|
|
568
|
-
return clamp01(base * (1 - 0.5 * errorRate));
|
|
569
|
-
}
|
|
570
|
-
function emptyTokenTotals() {
|
|
571
|
-
return { input: 0, output: 0, reasoning: 0, cached: 0, cacheWrite: 0 };
|
|
572
|
-
}
|
|
573
|
-
function hasTokenTotals(usage) {
|
|
574
|
-
return usage.input > 0 || usage.output > 0 || usage.reasoning > 0 || usage.cached > 0 || usage.cacheWrite > 0;
|
|
575
|
-
}
|
|
576
|
-
function addUsage(metrics, usage) {
|
|
577
|
-
const parsed = readUsage(usage);
|
|
578
|
-
metrics.inputTokens += parsed.input;
|
|
579
|
-
metrics.outputTokens += parsed.output;
|
|
580
|
-
metrics.reasoningTokens += parsed.reasoning;
|
|
581
|
-
metrics.cachedTokens += parsed.cached;
|
|
582
|
-
metrics.cacheWriteTokens += parsed.cacheWrite;
|
|
583
|
-
}
|
|
584
|
-
function addUsageTo(totals, usage) {
|
|
585
|
-
const parsed = readUsage(usage);
|
|
586
|
-
totals.input += parsed.input;
|
|
587
|
-
totals.output += parsed.output;
|
|
588
|
-
totals.reasoning += parsed.reasoning;
|
|
589
|
-
totals.cached += parsed.cached;
|
|
590
|
-
totals.cacheWrite += parsed.cacheWrite;
|
|
591
|
-
}
|
|
592
|
-
function readUsage(usage) {
|
|
593
|
-
const parsed = extractUsage(usage);
|
|
594
|
-
return {
|
|
595
|
-
input: parsed?.input ?? 0,
|
|
596
|
-
output: parsed?.output ?? 0,
|
|
597
|
-
reasoning: parsed?.reasoning ?? 0,
|
|
598
|
-
cached: parsed?.cached ?? 0,
|
|
599
|
-
cacheWrite: parsed?.cacheWrite ?? 0
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
function resolveSessionCost(explicit, metrics, model) {
|
|
603
|
-
if (explicit) {
|
|
604
|
-
if (explicit.kind === "uncaptured") {
|
|
605
|
-
if (explicit.usd !== null) throw new Error("uncaptured cost must have usd: null");
|
|
606
|
-
return { costUsd: 0, costProvenance: explicit };
|
|
607
|
-
}
|
|
608
|
-
if (!Number.isFinite(explicit.usd) || explicit.usd < 0) {
|
|
609
|
-
throw new Error(`${explicit.kind} cost must be a finite, non-negative USD amount`);
|
|
610
|
-
}
|
|
611
|
-
return { costUsd: explicit.usd, costProvenance: explicit };
|
|
612
|
-
}
|
|
613
|
-
if (metrics.observedCostCaptured) {
|
|
614
|
-
const costProvenance = { kind: "observed", usd: metrics.observedCostUsd };
|
|
615
|
-
return { costUsd: metrics.observedCostUsd, costProvenance };
|
|
616
|
-
}
|
|
617
|
-
const hasUsage = metrics.inputTokens > 0 || metrics.outputTokens > 0;
|
|
618
|
-
if (hasUsage && isModelPriced(model)) {
|
|
619
|
-
const costUsd = estimateCost(metrics.inputTokens, metrics.outputTokens, model);
|
|
620
|
-
return { costUsd, costProvenance: { kind: "estimated", usd: costUsd } };
|
|
621
|
-
}
|
|
622
|
-
return { costUsd: 0, costProvenance: { kind: "uncaptured", usd: null } };
|
|
623
|
-
}
|
|
624
|
-
function diagnosticsFor(metrics, options) {
|
|
625
|
-
const warnings = [];
|
|
626
|
-
if (!options.scoreOverridden) warnings.push("outcome score is inferred from process telemetry");
|
|
627
|
-
if (!options.explicitTerminal) warnings.push("no explicit terminal success/failure signal");
|
|
628
|
-
if (metrics.inputTokens === 0 && metrics.outputTokens === 0 && metrics.reasoningTokens === 0 && metrics.cachedTokens === 0 && metrics.cacheWriteTokens === 0) {
|
|
629
|
-
warnings.push("missing token usage");
|
|
630
|
-
}
|
|
631
|
-
if (options.costKind === "estimated")
|
|
632
|
-
warnings.push("USD cost estimated from token usage and model pricing");
|
|
633
|
-
if (options.costKind === "uncaptured") warnings.push("USD cost uncaptured");
|
|
634
|
-
if (options.costKind === "uncaptured" && !isModelPriced(options.model))
|
|
635
|
-
warnings.push("model pricing unknown");
|
|
636
|
-
if (options.malformedLines > 0)
|
|
637
|
-
warnings.push(`${options.malformedLines} malformed JSONL lines skipped`);
|
|
638
|
-
return warnings;
|
|
639
|
-
}
|
|
640
|
-
function hasExplicitTerminalSignal(source, metrics) {
|
|
641
|
-
if (source === "codex") return metrics.turnsCompleted + metrics.turnsAborted > 0;
|
|
642
|
-
if (source === "opencode" || source === "kimi-code")
|
|
643
|
-
return metrics.turnsCompleted + metrics.turnsAborted > 0;
|
|
644
|
-
if (source === "pi") return metrics.completionDecisions > 0 || metrics.reliabilityRows > 0;
|
|
645
|
-
return metrics.prLinks > 0 || metrics.toolErrors > 0;
|
|
646
|
-
}
|
|
647
|
-
function sessionIdFromEntries(source, entries) {
|
|
648
|
-
for (const entry of entries) {
|
|
649
|
-
if (source === "codex") {
|
|
650
|
-
const threadId = stringField(entry, "thread_id");
|
|
651
|
-
if (threadId) return threadId;
|
|
652
|
-
const payload2 = record(entry.payload);
|
|
653
|
-
const id = payload2 ? stringField(payload2, "id") : void 0;
|
|
654
|
-
if (id) return id;
|
|
655
|
-
}
|
|
656
|
-
const message = record(entry.message);
|
|
657
|
-
const payload = record(message?.payload);
|
|
658
|
-
const sessionId = stringField(entry, "sessionID") ?? stringField(entry, "sessionId") ?? stringField(entry, "session_id") ?? stringField(payload ?? {}, "session_id");
|
|
659
|
-
if (sessionId) return sessionId;
|
|
660
|
-
}
|
|
661
|
-
return void 0;
|
|
662
|
-
}
|
|
663
|
-
function modelFromEntries(source, entries) {
|
|
664
|
-
let providerModel;
|
|
665
|
-
for (const entry of entries) {
|
|
666
|
-
if (source === "codex") {
|
|
667
|
-
const payload = record(entry.payload);
|
|
668
|
-
const model2 = payload ? stringField(payload, "model") : void 0;
|
|
669
|
-
if (model2) return model2;
|
|
670
|
-
providerModel = providerModel ?? (payload ? stringField(payload, "model_provider") : void 0);
|
|
671
|
-
}
|
|
672
|
-
const openCodeModel = stringField(entry, "modelID");
|
|
673
|
-
if (openCodeModel) {
|
|
674
|
-
const provider = stringField(entry, "providerID");
|
|
675
|
-
return provider ? `${provider}/${openCodeModel}` : openCodeModel;
|
|
676
|
-
}
|
|
677
|
-
const modelObject = record(entry.model);
|
|
678
|
-
const nestedModel = stringField(modelObject ?? {}, "modelID");
|
|
679
|
-
if (nestedModel) {
|
|
680
|
-
const provider = stringField(modelObject ?? {}, "providerID");
|
|
681
|
-
return provider ? `${provider}/${nestedModel}` : nestedModel;
|
|
682
|
-
}
|
|
683
|
-
const message = record(entry.message);
|
|
684
|
-
const model = message ? stringField(message, "model") : void 0;
|
|
685
|
-
if (model) return model;
|
|
686
|
-
}
|
|
687
|
-
return providerModel;
|
|
688
|
-
}
|
|
689
|
-
function cwdFromEntries(entries) {
|
|
690
|
-
for (const entry of entries) {
|
|
691
|
-
const path = record(entry.path);
|
|
692
|
-
const cwd = stringField(entry, "cwd") ?? stringField(path ?? {}, "cwd") ?? stringField(path ?? {}, "root") ?? (record(entry.payload) ? stringField(record(entry.payload), "cwd") : void 0);
|
|
693
|
-
if (cwd) return cwd;
|
|
694
|
-
}
|
|
695
|
-
return void 0;
|
|
696
|
-
}
|
|
697
|
-
function firstUserText(entries) {
|
|
698
|
-
for (const entry of entries) {
|
|
699
|
-
const payload = record(entry.payload);
|
|
700
|
-
const payloadType = payload ? stringField(payload, "type") : void 0;
|
|
701
|
-
if (payloadType === "user_message") return stringField(payload, "message");
|
|
702
|
-
if (stringField(entry, "role") === "user") {
|
|
703
|
-
const content = entry.content;
|
|
704
|
-
if (typeof content === "string") return content;
|
|
705
|
-
}
|
|
706
|
-
const wirePayload = record(record(entry.message)?.payload);
|
|
707
|
-
const userInput = wirePayload ? stringField(wirePayload, "user_input") : void 0;
|
|
708
|
-
if (userInput) return userInput;
|
|
709
|
-
const message = record(entry.message);
|
|
710
|
-
if (message && stringField(message, "role") === "user") {
|
|
711
|
-
const content = message.content;
|
|
712
|
-
if (typeof content === "string") return content;
|
|
713
|
-
if (Array.isArray(content)) {
|
|
714
|
-
const text = content.map((part) => {
|
|
715
|
-
const obj = record(part);
|
|
716
|
-
return obj ? stringField(obj, "text") : void 0;
|
|
717
|
-
}).filter((part) => part !== void 0).join("\n");
|
|
718
|
-
if (text) return text;
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
return void 0;
|
|
723
|
-
}
|
|
724
|
-
function fallbackSessionId(source, sourcePath) {
|
|
725
|
-
return hashString(`${source}:${sourcePath ?? "unknown-session"}`).slice(
|
|
726
|
-
"sha256:".length,
|
|
727
|
-
"sha256:".length + 20
|
|
728
|
-
);
|
|
729
|
-
}
|
|
730
|
-
function withSnapshot(model) {
|
|
731
|
-
const trimmed = model.trim() || "unknown";
|
|
732
|
-
if (trimmed.includes("@") || /-\d{8}$/.test(trimmed) || /-\d{4}-\d{2}-\d{2}$/.test(trimmed)) {
|
|
733
|
-
return trimmed;
|
|
734
|
-
}
|
|
735
|
-
return `${trimmed}@observed-local`;
|
|
736
|
-
}
|
|
737
|
-
function hashJson(value) {
|
|
738
|
-
return hashString(JSON.stringify(value));
|
|
739
|
-
}
|
|
740
|
-
function hashString(value) {
|
|
741
|
-
return `sha256:${createHash("sha256").update(value).digest("hex")}`;
|
|
742
|
-
}
|
|
743
|
-
function stableSeed(value) {
|
|
744
|
-
return createHash("sha256").update(value).digest().readUInt32BE(0);
|
|
745
|
-
}
|
|
746
|
-
function maxOptional(current, next) {
|
|
747
|
-
return current === void 0 ? next : Math.max(current, next);
|
|
748
|
-
}
|
|
749
|
-
function clamp01(value) {
|
|
750
|
-
if (!Number.isFinite(value)) return 0;
|
|
751
|
-
return Math.max(0, Math.min(1, value));
|
|
752
|
-
}
|
|
753
|
-
function isRecord(value) {
|
|
754
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
755
|
-
}
|
|
756
|
-
function record(value) {
|
|
757
|
-
return isRecord(value) ? value : null;
|
|
758
|
-
}
|
|
759
|
-
function stringField(obj, key) {
|
|
760
|
-
const value = obj[key];
|
|
761
|
-
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
762
|
-
}
|
|
763
|
-
function numberField(obj, key) {
|
|
764
|
-
const value = obj[key];
|
|
765
|
-
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
766
|
-
}
|
|
767
|
-
function timestampMs(value) {
|
|
768
|
-
if (typeof value === "number" && Number.isFinite(value)) {
|
|
769
|
-
return value > 1e12 ? value : value * 1e3;
|
|
770
|
-
}
|
|
771
|
-
if (typeof value === "string" && value.length > 0) {
|
|
772
|
-
const parsed = Date.parse(value);
|
|
773
|
-
return Number.isFinite(parsed) ? parsed : void 0;
|
|
774
|
-
}
|
|
775
|
-
return void 0;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
export {
|
|
779
|
-
parseCodeAgentJsonl,
|
|
780
|
-
fromCodexSession,
|
|
781
|
-
fromClaudeCodeSession,
|
|
782
|
-
fromOpenCodeSession,
|
|
783
|
-
fromKimiCodeSession,
|
|
784
|
-
fromPiSession,
|
|
785
|
-
fromPigraphSession
|
|
786
|
-
};
|
|
787
|
-
//# sourceMappingURL=chunk-HKUCJ437.js.map
|