agent-inspect 6.7.2 → 6.7.4
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 +21 -0
- package/README.md +1 -1
- package/docs/EXPORTS.md +9 -0
- package/docs/PERFORMANCE.md +18 -0
- package/docs/STANDARDS.md +4 -0
- package/package.json +2 -2
- package/packages/cli/dist/{chunk-M6PC5KUT.mjs → chunk-FVEQ7JFF.mjs} +251 -209
- package/packages/cli/dist/chunk-FVEQ7JFF.mjs.map +1 -0
- package/packages/cli/dist/index.cjs +292 -229
- package/packages/cli/dist/index.cjs.map +1 -1
- package/packages/cli/dist/index.mjs +35 -15
- package/packages/cli/dist/index.mjs.map +1 -1
- package/packages/cli/dist/{src-27LC2BB3.mjs → src-I5NA7BLK.mjs} +3 -3
- package/packages/cli/dist/{src-27LC2BB3.mjs.map → src-I5NA7BLK.mjs.map} +1 -1
- package/packages/core/dist/advanced.cjs +249 -207
- package/packages/core/dist/advanced.cjs.map +1 -1
- package/packages/core/dist/advanced.mjs +51 -250
- package/packages/core/dist/advanced.mjs.map +1 -1
- package/packages/core/dist/checks.cjs +56 -4
- package/packages/core/dist/checks.cjs.map +1 -1
- package/packages/core/dist/checks.mjs +1 -1
- package/packages/core/dist/{chunk-X2FLDF7M.mjs → chunk-CTA6XNDP.mjs} +3 -3
- package/packages/core/dist/{chunk-X2FLDF7M.mjs.map → chunk-CTA6XNDP.mjs.map} +1 -1
- package/packages/core/dist/{chunk-EWHN6NA4.mjs → chunk-EQVXDGGU.mjs} +58 -6
- package/packages/core/dist/chunk-EQVXDGGU.mjs.map +1 -0
- package/packages/core/dist/{chunk-3USJVBLA.mjs → chunk-KDDU2R5P.mjs} +236 -5
- package/packages/core/dist/chunk-KDDU2R5P.mjs.map +1 -0
- package/packages/core/dist/{chunk-E5F2LQCX.mjs → chunk-T5MASTIW.mjs} +15 -4
- package/packages/core/dist/chunk-T5MASTIW.mjs.map +1 -0
- package/packages/core/dist/{chunk-KNYL56KZ.mjs → chunk-UOPVGCOB.mjs} +3 -3
- package/packages/core/dist/{chunk-KNYL56KZ.mjs.map → chunk-UOPVGCOB.mjs.map} +1 -1
- package/packages/core/dist/diff.cjs +4 -0
- package/packages/core/dist/diff.cjs.map +1 -1
- package/packages/core/dist/diff.mjs +4 -0
- package/packages/core/dist/diff.mjs.map +1 -1
- package/packages/core/dist/exporters.cjs +145 -133
- package/packages/core/dist/exporters.cjs.map +1 -1
- package/packages/core/dist/exporters.d.cts +3 -2
- package/packages/core/dist/exporters.d.ts +3 -2
- package/packages/core/dist/exporters.mjs +10 -5
- package/packages/core/dist/exporters.mjs.map +1 -1
- package/packages/core/dist/logs.cjs +16 -4
- package/packages/core/dist/logs.cjs.map +1 -1
- package/packages/core/dist/logs.mjs +5 -4
- package/packages/core/dist/logs.mjs.map +1 -1
- package/packages/core/dist/persisted.cjs +13 -2
- package/packages/core/dist/persisted.cjs.map +1 -1
- package/packages/core/dist/persisted.mjs +3 -3
- package/packages/core/dist/readers.cjs +13 -2
- package/packages/core/dist/readers.cjs.map +1 -1
- package/packages/core/dist/readers.mjs +3 -3
- package/packages/cli/dist/chunk-M6PC5KUT.mjs.map +0 -1
- package/packages/core/dist/chunk-3USJVBLA.mjs.map +0 -1
- package/packages/core/dist/chunk-E5F2LQCX.mjs.map +0 -1
- package/packages/core/dist/chunk-EWHN6NA4.mjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { runTraceChecks, createRunStatusRule, createToolUsageRule, createRunDurationRule, createLlmUsageRule, createObservedOutcomeRule } from './chunk-
|
|
1
|
+
import { runTraceChecks, createRunStatusRule, createToolUsageRule, createRunDurationRule, createLlmUsageRule, createObservedOutcomeRule } from './chunk-EQVXDGGU.mjs';
|
|
2
2
|
export { MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, TERMINAL_INDENT, TraceDirectory, createInspector, createInspectorRuntime, formatTerminalName, getCurrentContext, getCurrentCorrelationMetadata, getCurrentDepth, getCurrentRunId, getCurrentRunName, getCurrentStepId, getIndent, getParentStepId, getTraceDirFromContext, getTraceSafetyFromContext, hasActiveContext, isAgentInspectEnabled, isSilentContext, maybeInspectRun, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, renderErrorLine, renderRunSummary, renderStepLine, resolveTraceDir, runWithContext, runWithStepContext } from './chunk-ZWA5RWMV.mjs';
|
|
3
|
-
import {
|
|
4
|
-
export { buildRunSummary, buildRunTimeline, buildRunWhatSummary, extractMetadata, renderRunWhat, renderTimeline } from './chunk-
|
|
3
|
+
import { filterTraces, extractMetadata, buildRunSummary } from './chunk-KDDU2R5P.mjs';
|
|
4
|
+
export { buildRunSummary, buildRunTimeline, buildRunWhatSummary, buildTraceStats, extractMetadata, filterTraces, renderRunWhat, renderTimeline, renderTraceStats } from './chunk-KDDU2R5P.mjs';
|
|
5
5
|
import { parseObservationFilter, extractOutcomesFromTraceEvents, extractOutcomesFromPersistedEvents } from './chunk-VFO76UH3.mjs';
|
|
6
6
|
export { extractOutcomesFromPersistedEvents, extractOutcomesFromTraceEvents } from './chunk-VFO76UH3.mjs';
|
|
7
7
|
import './chunk-BT7CATSD.mjs';
|
|
@@ -9,11 +9,11 @@ import { escapeHtml } from './chunk-CAWPF22J.mjs';
|
|
|
9
9
|
import { resolveRedactionProfile, readTraceEventsFromFile } from './chunk-ULCGIRTC.mjs';
|
|
10
10
|
export { DEFAULT_MAX_EVENT_BYTES, DEFAULT_MAX_METADATA_VALUE_LENGTH, DEFAULT_MAX_PREVIEW_LENGTH, getRunIdFromTraceFileName, initializeTraceFile, listTraceFiles, prepareMetadataForDisk, prepareTraceEventForDisk, readTraceEvents, readTraceFile, resolveRedactionProfile, resolveTraceSafetyOptions, serializeEvent, validateEvent, writeTraceEvent } from './chunk-ULCGIRTC.mjs';
|
|
11
11
|
import { Redactor } from './chunk-VU6O5QAH.mjs';
|
|
12
|
-
import { openTrace } from './chunk-
|
|
13
|
-
import './chunk-
|
|
12
|
+
import { openTrace } from './chunk-CTA6XNDP.mjs';
|
|
13
|
+
import './chunk-UOPVGCOB.mjs';
|
|
14
14
|
import './chunk-S4YWKV4G.mjs';
|
|
15
|
-
import './chunk-
|
|
16
|
-
import { parseDuration,
|
|
15
|
+
import './chunk-T5MASTIW.mjs';
|
|
16
|
+
import { parseDuration, isTraceEvent, getTraceFilePath } from './chunk-WRE4CNPF.mjs';
|
|
17
17
|
export { DEFAULT_TRACE_DIR_NAME, FALLBACK_TRACE_DIR, MAX_NAME_LENGTH, RUNS_DIR_NAME, createRunId, createStepId, ensureTraceDir, formatDuration, formatError, formatTimestamp, getDefaultTraceDir, getTraceFilePath, isStepStatus, isStepType, isTraceEvent, parseDuration, parseTraceJsonl, truncateName, unknownTraceFormatMessage, warn } from './chunk-WRE4CNPF.mjs';
|
|
18
18
|
import './chunk-P366CCL2.mjs';
|
|
19
19
|
import './chunk-7TGZLWEE.mjs';
|
|
@@ -23,41 +23,13 @@ import path from 'path';
|
|
|
23
23
|
import { access, readFile } from 'fs/promises';
|
|
24
24
|
import { pathToFileURL } from 'url';
|
|
25
25
|
|
|
26
|
-
// packages/core/src/trace-filter.ts
|
|
27
|
-
function toLower(s) {
|
|
28
|
-
return typeof s === "string" ? s.toLowerCase() : "";
|
|
29
|
-
}
|
|
30
|
-
function filterTraces(traces, options) {
|
|
31
|
-
const input = [...traces];
|
|
32
|
-
let out = input.filter((t) => {
|
|
33
|
-
if (options.status && t.status !== options.status) return false;
|
|
34
|
-
if (options.name) {
|
|
35
|
-
const q = options.name.toLowerCase();
|
|
36
|
-
const hay = `${toLower(t.name)} ${toLower(t.runId)}`;
|
|
37
|
-
if (!hay.includes(q)) return false;
|
|
38
|
-
}
|
|
39
|
-
if (options.since) {
|
|
40
|
-
const windowMs = parseDuration(options.since);
|
|
41
|
-
const cutoff = Date.now() - windowMs;
|
|
42
|
-
const started = typeof t.startedAt === "number" ? t.startedAt : void 0;
|
|
43
|
-
const basis = started ?? t.createdAt.getTime();
|
|
44
|
-
if (!Number.isFinite(basis) || basis < cutoff) return false;
|
|
45
|
-
}
|
|
46
|
-
return true;
|
|
47
|
-
});
|
|
48
|
-
out.sort((a, b) => {
|
|
49
|
-
const aTime = (typeof a.startedAt === "number" ? a.startedAt : void 0) ?? a.createdAt.getTime();
|
|
50
|
-
const bTime = (typeof b.startedAt === "number" ? b.startedAt : void 0) ?? b.createdAt.getTime();
|
|
51
|
-
return bTime - aTime;
|
|
52
|
-
});
|
|
53
|
-
if (typeof options.limit === "number" && Number.isFinite(options.limit)) {
|
|
54
|
-
const n = Math.max(0, Math.floor(options.limit));
|
|
55
|
-
out = out.slice(0, n);
|
|
56
|
-
}
|
|
57
|
-
return out;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
26
|
// packages/core/src/explain.ts
|
|
27
|
+
function toDisplayStatus(status) {
|
|
28
|
+
if (status === "ok") return "success";
|
|
29
|
+
if (status === "error") return "error";
|
|
30
|
+
if (status === "running") return "running";
|
|
31
|
+
return "unknown";
|
|
32
|
+
}
|
|
61
33
|
function flatten(nodes, out = []) {
|
|
62
34
|
for (const node of nodes) {
|
|
63
35
|
out.push({ node, index: out.length + 1 });
|
|
@@ -115,7 +87,7 @@ function buildFacts(run, redactor) {
|
|
|
115
87
|
const facts = [
|
|
116
88
|
fact("run.id", "Run id", run.runId, redactor),
|
|
117
89
|
fact("run.name", "Run name", run.name ?? run.runId, redactor),
|
|
118
|
-
fact("run.status", "Run status", run.status
|
|
90
|
+
fact("run.status", "Run status", toDisplayStatus(run.status), redactor),
|
|
119
91
|
fact("run.totalEvents", "Total events", run.metadata.totalEvents, redactor),
|
|
120
92
|
fact("run.stepCount", "Top-level step count", run.children.length, redactor),
|
|
121
93
|
fact("run.nodeCount", "Total node count", nodes.length, redactor),
|
|
@@ -191,7 +163,7 @@ function buildLocalExplanation(run, options = {}) {
|
|
|
191
163
|
mode,
|
|
192
164
|
runId: String(redactValue(redactor, "runId", run.runId)),
|
|
193
165
|
...run.name !== void 0 ? { name: String(redactValue(redactor, "name", run.name)) } : {},
|
|
194
|
-
...run.status !== void 0 ? { status: run.status } : {},
|
|
166
|
+
...run.status !== void 0 ? { status: toDisplayStatus(run.status) } : {},
|
|
195
167
|
redactionProfile,
|
|
196
168
|
facts,
|
|
197
169
|
inferences: mode === "dry-run" ? [] : buildInferences(run, facts),
|
|
@@ -202,199 +174,6 @@ function buildLocalExplanation(run, options = {}) {
|
|
|
202
174
|
};
|
|
203
175
|
}
|
|
204
176
|
|
|
205
|
-
// packages/core/src/stats.ts
|
|
206
|
-
function percentile(sorted, p) {
|
|
207
|
-
if (sorted.length === 0) return void 0;
|
|
208
|
-
const idx = Math.min(
|
|
209
|
-
sorted.length - 1,
|
|
210
|
-
Math.max(0, Math.ceil(p / 100 * sorted.length) - 1)
|
|
211
|
-
);
|
|
212
|
-
return sorted[idx];
|
|
213
|
-
}
|
|
214
|
-
async function readRunStartedMetadata(filePath) {
|
|
215
|
-
try {
|
|
216
|
-
const events = await readTraceEventsFromFile(filePath);
|
|
217
|
-
for (const event of events) {
|
|
218
|
-
if (event.event !== "run_started") continue;
|
|
219
|
-
const rs = event;
|
|
220
|
-
if (rs.metadata && typeof rs.metadata === "object") {
|
|
221
|
-
return rs.metadata;
|
|
222
|
-
}
|
|
223
|
-
return void 0;
|
|
224
|
-
}
|
|
225
|
-
} catch {
|
|
226
|
-
}
|
|
227
|
-
return void 0;
|
|
228
|
-
}
|
|
229
|
-
function metaMatchesCorrelation(metadata, correlationId, groupId) {
|
|
230
|
-
if (correlationId) {
|
|
231
|
-
const v = metadata?.correlationId;
|
|
232
|
-
if (typeof v !== "string" || v !== correlationId) return false;
|
|
233
|
-
}
|
|
234
|
-
if (groupId) {
|
|
235
|
-
const v = metadata?.groupId;
|
|
236
|
-
if (typeof v !== "string" || v !== groupId) return false;
|
|
237
|
-
}
|
|
238
|
-
return true;
|
|
239
|
-
}
|
|
240
|
-
async function buildTraceStats(metas, options) {
|
|
241
|
-
let filtered = filterTraces(metas, { since: options.since });
|
|
242
|
-
if (options.correlationId || options.groupId) {
|
|
243
|
-
const next = [];
|
|
244
|
-
for (const m of filtered) {
|
|
245
|
-
const md = await readRunStartedMetadata(m.filePath);
|
|
246
|
-
if (metaMatchesCorrelation(md, options.correlationId, options.groupId)) {
|
|
247
|
-
next.push(m);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
filtered = next;
|
|
251
|
-
}
|
|
252
|
-
let successCount = 0;
|
|
253
|
-
let errorCount = 0;
|
|
254
|
-
let runningCount = 0;
|
|
255
|
-
let unknownCount = 0;
|
|
256
|
-
const durations = [];
|
|
257
|
-
let totalSteps = 0;
|
|
258
|
-
let totalLlmSteps = 0;
|
|
259
|
-
let totalToolSteps = 0;
|
|
260
|
-
let totalErrorSteps = 0;
|
|
261
|
-
const slowestRuns = [];
|
|
262
|
-
const slowestSteps = [];
|
|
263
|
-
for (const m of filtered) {
|
|
264
|
-
if (m.status === "success") successCount += 1;
|
|
265
|
-
else if (m.status === "error") errorCount += 1;
|
|
266
|
-
else if (m.status === "running") runningCount += 1;
|
|
267
|
-
else unknownCount += 1;
|
|
268
|
-
if (typeof m.durationMs === "number" && Number.isFinite(m.durationMs) && m.durationMs >= 0) {
|
|
269
|
-
durations.push(m.durationMs);
|
|
270
|
-
slowestRuns.push({
|
|
271
|
-
runId: m.runId,
|
|
272
|
-
name: m.name,
|
|
273
|
-
durationMs: m.durationMs,
|
|
274
|
-
status: m.status
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
try {
|
|
278
|
-
const events = await readTraceEventsFromFile(m.filePath);
|
|
279
|
-
if (events.length === 0) continue;
|
|
280
|
-
const summary = buildRunSummary(events);
|
|
281
|
-
totalSteps += summary.totalSteps;
|
|
282
|
-
totalLlmSteps += summary.llmSteps;
|
|
283
|
-
totalToolSteps += summary.toolSteps;
|
|
284
|
-
totalErrorSteps += summary.errorSteps;
|
|
285
|
-
const steps = collectCompletedSteps(events, m.runId);
|
|
286
|
-
for (const s of steps) {
|
|
287
|
-
slowestSteps.push(s);
|
|
288
|
-
}
|
|
289
|
-
} catch {
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
slowestRuns.sort((a, b) => (b.durationMs ?? 0) - (a.durationMs ?? 0));
|
|
293
|
-
slowestSteps.sort((a, b) => b.durationMs - a.durationMs);
|
|
294
|
-
const runLimit = options.slowRunLimit ?? 5;
|
|
295
|
-
const stepLimit = options.slowStepLimit ?? 5;
|
|
296
|
-
const sortedDur = [...durations].sort((a, b) => a - b);
|
|
297
|
-
const totalRuns = filtered.length;
|
|
298
|
-
const errorRate = totalRuns > 0 ? errorCount / totalRuns : 0;
|
|
299
|
-
const sumDur = durations.reduce((a, b) => a + b, 0);
|
|
300
|
-
return {
|
|
301
|
-
traceDir: options.traceDir,
|
|
302
|
-
...options.since ? { since: options.since } : {},
|
|
303
|
-
...options.correlationId ? { correlationId: options.correlationId } : {},
|
|
304
|
-
...options.groupId ? { groupId: options.groupId } : {},
|
|
305
|
-
totalRuns,
|
|
306
|
-
successCount,
|
|
307
|
-
errorCount,
|
|
308
|
-
runningCount,
|
|
309
|
-
unknownCount,
|
|
310
|
-
errorRate,
|
|
311
|
-
duration: {
|
|
312
|
-
...sortedDur.length > 0 ? {
|
|
313
|
-
minMs: sortedDur[0],
|
|
314
|
-
maxMs: sortedDur[sortedDur.length - 1],
|
|
315
|
-
avgMs: sumDur / sortedDur.length,
|
|
316
|
-
p50Ms: percentile(sortedDur, 50),
|
|
317
|
-
p95Ms: percentile(sortedDur, 95)
|
|
318
|
-
} : {}
|
|
319
|
-
},
|
|
320
|
-
totalSteps,
|
|
321
|
-
avgStepsPerRun: totalRuns > 0 ? totalSteps / totalRuns : 0,
|
|
322
|
-
totalLlmSteps,
|
|
323
|
-
totalToolSteps,
|
|
324
|
-
totalErrorSteps,
|
|
325
|
-
slowestRuns: slowestRuns.slice(0, runLimit),
|
|
326
|
-
slowestSteps: slowestSteps.slice(0, stepLimit)
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
function collectCompletedSteps(events, runId) {
|
|
330
|
-
const started = /* @__PURE__ */ new Map();
|
|
331
|
-
const out = [];
|
|
332
|
-
for (const e of events) {
|
|
333
|
-
if (e.event === "step_started") {
|
|
334
|
-
const s = e;
|
|
335
|
-
started.set(s.stepId, { name: s.name, type: s.type });
|
|
336
|
-
}
|
|
337
|
-
if (e.event === "step_completed") {
|
|
338
|
-
const c = e;
|
|
339
|
-
if (c.status !== "success" && c.status !== "error") continue;
|
|
340
|
-
if (typeof c.durationMs !== "number" || !Number.isFinite(c.durationMs)) {
|
|
341
|
-
continue;
|
|
342
|
-
}
|
|
343
|
-
const meta = started.get(c.stepId);
|
|
344
|
-
out.push({
|
|
345
|
-
runId,
|
|
346
|
-
stepName: meta?.name ?? c.stepId,
|
|
347
|
-
stepType: meta?.type ?? "logic",
|
|
348
|
-
durationMs: c.durationMs
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return out;
|
|
353
|
-
}
|
|
354
|
-
function renderTraceStats(stats) {
|
|
355
|
-
const lines = [];
|
|
356
|
-
lines.push("Trace stats (local)");
|
|
357
|
-
lines.push(`Directory: ${stats.traceDir}`);
|
|
358
|
-
if (stats.since) lines.push(`Since: ${stats.since}`);
|
|
359
|
-
if (stats.correlationId) lines.push(`Correlation ID: ${stats.correlationId}`);
|
|
360
|
-
if (stats.groupId) lines.push(`Group ID: ${stats.groupId}`);
|
|
361
|
-
lines.push("");
|
|
362
|
-
lines.push(`Runs: ${stats.totalRuns}`);
|
|
363
|
-
lines.push(
|
|
364
|
-
` success: ${stats.successCount} error: ${stats.errorCount} running: ${stats.runningCount} unknown: ${stats.unknownCount}`
|
|
365
|
-
);
|
|
366
|
-
lines.push(`Error rate: ${(stats.errorRate * 100).toFixed(1)}%`);
|
|
367
|
-
if (stats.duration.avgMs !== void 0) {
|
|
368
|
-
lines.push(
|
|
369
|
-
`Duration: min ${formatDuration(stats.duration.minMs ?? 0)} | avg ${formatDuration(stats.duration.avgMs)} | p50 ${formatDuration(stats.duration.p50Ms ?? 0)} | p95 ${formatDuration(stats.duration.p95Ms ?? 0)} | max ${formatDuration(stats.duration.maxMs ?? 0)}`
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
lines.push("");
|
|
373
|
-
lines.push(`Steps: ${stats.totalSteps} (avg ${stats.avgStepsPerRun.toFixed(1)} per run)`);
|
|
374
|
-
lines.push(
|
|
375
|
-
` LLM: ${stats.totalLlmSteps} tool: ${stats.totalToolSteps} errors: ${stats.totalErrorSteps}`
|
|
376
|
-
);
|
|
377
|
-
if (stats.slowestRuns.length > 0) {
|
|
378
|
-
lines.push("");
|
|
379
|
-
lines.push("Slowest runs:");
|
|
380
|
-
for (const r of stats.slowestRuns) {
|
|
381
|
-
lines.push(
|
|
382
|
-
` ${r.runId} | ${r.name ?? "-"} | ${formatDuration(r.durationMs ?? 0)} | ${r.status}`
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
if (stats.slowestSteps.length > 0) {
|
|
387
|
-
lines.push("");
|
|
388
|
-
lines.push("Slowest steps:");
|
|
389
|
-
for (const s of stats.slowestSteps) {
|
|
390
|
-
lines.push(
|
|
391
|
-
` ${s.runId} | ${s.stepType}:${s.stepName} | ${formatDuration(s.durationMs)}`
|
|
392
|
-
);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
return lines.join("\n");
|
|
396
|
-
}
|
|
397
|
-
|
|
398
177
|
// packages/core/src/search.ts
|
|
399
178
|
function parseDurationFilter(expr) {
|
|
400
179
|
const raw = expr.trim();
|
|
@@ -461,6 +240,12 @@ async function searchTraces(metas, options) {
|
|
|
461
240
|
...sessionLabel ? { sessionId: sessionLabel } : {}
|
|
462
241
|
});
|
|
463
242
|
}
|
|
243
|
+
results.sort((a, b) => {
|
|
244
|
+
const ta = a.timestamp ?? 0;
|
|
245
|
+
const tb = b.timestamp ?? 0;
|
|
246
|
+
if (ta !== tb) return tb - ta;
|
|
247
|
+
return a.runId.localeCompare(b.runId);
|
|
248
|
+
});
|
|
464
249
|
return results.slice(0, limit);
|
|
465
250
|
}
|
|
466
251
|
for (const m of filtered) {
|
|
@@ -508,7 +293,7 @@ async function searchTraces(metas, options) {
|
|
|
508
293
|
results.sort((a, b) => {
|
|
509
294
|
const ta = a.timestamp ?? 0;
|
|
510
295
|
const tb = b.timestamp ?? 0;
|
|
511
|
-
if (ta !== tb) return
|
|
296
|
+
if (ta !== tb) return tb - ta;
|
|
512
297
|
const runCmp = a.runId.localeCompare(b.runId);
|
|
513
298
|
if (runCmp !== 0) return runCmp;
|
|
514
299
|
return (a.stepName ?? "").localeCompare(b.stepName ?? "");
|
|
@@ -2417,7 +2202,9 @@ function compareCohortAggregates(groups, options) {
|
|
|
2417
2202
|
metric,
|
|
2418
2203
|
"Average duration (ms)",
|
|
2419
2204
|
baselineAgg?.avgDurationMs,
|
|
2420
|
-
candidateAgg?.avgDurationMs
|
|
2205
|
+
candidateAgg?.avgDurationMs,
|
|
2206
|
+
true,
|
|
2207
|
+
tolerance
|
|
2421
2208
|
);
|
|
2422
2209
|
if (item) comparisons.push(item);
|
|
2423
2210
|
break;
|
|
@@ -2427,7 +2214,9 @@ function compareCohortAggregates(groups, options) {
|
|
|
2427
2214
|
metric,
|
|
2428
2215
|
"Average LLM calls",
|
|
2429
2216
|
baselineAgg?.avgLlmCallCount,
|
|
2430
|
-
candidateAgg?.avgLlmCallCount
|
|
2217
|
+
candidateAgg?.avgLlmCallCount,
|
|
2218
|
+
true,
|
|
2219
|
+
tolerance
|
|
2431
2220
|
);
|
|
2432
2221
|
if (item) comparisons.push(item);
|
|
2433
2222
|
break;
|
|
@@ -2437,7 +2226,9 @@ function compareCohortAggregates(groups, options) {
|
|
|
2437
2226
|
metric,
|
|
2438
2227
|
"Average token usage",
|
|
2439
2228
|
baselineAgg?.avgTokenUsage,
|
|
2440
|
-
candidateAgg?.avgTokenUsage
|
|
2229
|
+
candidateAgg?.avgTokenUsage,
|
|
2230
|
+
true,
|
|
2231
|
+
tolerance
|
|
2441
2232
|
);
|
|
2442
2233
|
if (item) comparisons.push(item);
|
|
2443
2234
|
break;
|
|
@@ -2447,7 +2238,9 @@ function compareCohortAggregates(groups, options) {
|
|
|
2447
2238
|
metric,
|
|
2448
2239
|
"Average retries",
|
|
2449
2240
|
baselineAgg?.avgRetryCount,
|
|
2450
|
-
candidateAgg?.avgRetryCount
|
|
2241
|
+
candidateAgg?.avgRetryCount,
|
|
2242
|
+
true,
|
|
2243
|
+
tolerance
|
|
2451
2244
|
);
|
|
2452
2245
|
if (item) comparisons.push(item);
|
|
2453
2246
|
break;
|
|
@@ -2457,7 +2250,9 @@ function compareCohortAggregates(groups, options) {
|
|
|
2457
2250
|
metric,
|
|
2458
2251
|
"Observation failure rate",
|
|
2459
2252
|
baselineAgg?.observationFailureRate,
|
|
2460
|
-
candidateAgg?.observationFailureRate
|
|
2253
|
+
candidateAgg?.observationFailureRate,
|
|
2254
|
+
true,
|
|
2255
|
+
tolerance
|
|
2461
2256
|
);
|
|
2462
2257
|
if (item) comparisons.push(item);
|
|
2463
2258
|
break;
|
|
@@ -2493,7 +2288,9 @@ function compareCohortAggregates(groups, options) {
|
|
|
2493
2288
|
metric,
|
|
2494
2289
|
"Guardrail failures",
|
|
2495
2290
|
baselineAgg?.avgGuardrailFailures,
|
|
2496
|
-
candidateAgg?.avgGuardrailFailures
|
|
2291
|
+
candidateAgg?.avgGuardrailFailures,
|
|
2292
|
+
true,
|
|
2293
|
+
tolerance
|
|
2497
2294
|
);
|
|
2498
2295
|
if (item) comparisons.push(item);
|
|
2499
2296
|
break;
|
|
@@ -2503,7 +2300,9 @@ function compareCohortAggregates(groups, options) {
|
|
|
2503
2300
|
metric,
|
|
2504
2301
|
"Circuit violations",
|
|
2505
2302
|
baselineAgg?.avgCircuitViolations,
|
|
2506
|
-
candidateAgg?.avgCircuitViolations
|
|
2303
|
+
candidateAgg?.avgCircuitViolations,
|
|
2304
|
+
true,
|
|
2305
|
+
tolerance
|
|
2507
2306
|
);
|
|
2508
2307
|
if (item) comparisons.push(item);
|
|
2509
2308
|
break;
|
|
@@ -2513,7 +2312,9 @@ function compareCohortAggregates(groups, options) {
|
|
|
2513
2312
|
metric,
|
|
2514
2313
|
"Redaction warnings",
|
|
2515
2314
|
baselineAgg?.avgRedactionWarnings,
|
|
2516
|
-
candidateAgg?.avgRedactionWarnings
|
|
2315
|
+
candidateAgg?.avgRedactionWarnings,
|
|
2316
|
+
true,
|
|
2317
|
+
tolerance
|
|
2517
2318
|
);
|
|
2518
2319
|
if (item) comparisons.push(item);
|
|
2519
2320
|
break;
|
|
@@ -2633,7 +2434,7 @@ async function computeCohortRunMetrics(input) {
|
|
|
2633
2434
|
toolOrdering: tools.ordering
|
|
2634
2435
|
};
|
|
2635
2436
|
}
|
|
2636
|
-
function
|
|
2437
|
+
function percentile(values, p) {
|
|
2637
2438
|
if (values.length === 0) return void 0;
|
|
2638
2439
|
const sorted = [...values].sort((a, b) => a - b);
|
|
2639
2440
|
const idx = Math.min(
|
|
@@ -2687,7 +2488,7 @@ function aggregateCohortMetrics(runs, groupKey, cohortLabel) {
|
|
|
2687
2488
|
runCount: runs.length,
|
|
2688
2489
|
errorRate: runs.length > 0 ? errors / runs.length : 0,
|
|
2689
2490
|
avgDurationMs: durations.length > 0 ? durations.reduce((sum, value) => sum + value, 0) / durations.length : void 0,
|
|
2690
|
-
p95DurationMs:
|
|
2491
|
+
p95DurationMs: percentile(durations, 95),
|
|
2691
2492
|
avgLlmCallCount: runs.length > 0 ? runs.reduce((sum, run) => sum + run.llmCallCount, 0) / runs.length : 0,
|
|
2692
2493
|
avgTokenUsage: tokenValues.length > 0 ? tokenValues.reduce((sum, value) => sum + value, 0) / tokenValues.length : void 0,
|
|
2693
2494
|
avgRetryCount: runs.length > 0 ? runs.reduce((sum, run) => sum + run.retryCount, 0) / runs.length : 0,
|
|
@@ -2913,7 +2714,7 @@ function parseGateNumber(value, label, options = {}) {
|
|
|
2913
2714
|
}
|
|
2914
2715
|
|
|
2915
2716
|
// packages/core/src/gate/evaluate.ts
|
|
2916
|
-
function
|
|
2717
|
+
function percentile2(values, p) {
|
|
2917
2718
|
if (values.length === 0) return void 0;
|
|
2918
2719
|
const sorted = [...values].sort((a, b) => a - b);
|
|
2919
2720
|
const idx = Math.min(
|
|
@@ -2985,7 +2786,7 @@ async function evaluateGateThresholds(runs, options) {
|
|
|
2985
2786
|
}
|
|
2986
2787
|
if (options.maxP95DurationMs !== void 0) {
|
|
2987
2788
|
const durations = runMetrics.map((run) => run.durationMs).filter((value) => typeof value === "number");
|
|
2988
|
-
const actual =
|
|
2789
|
+
const actual = percentile2(durations, 95);
|
|
2989
2790
|
const ok = actual !== void 0 && actual <= options.maxP95DurationMs;
|
|
2990
2791
|
checks.push({
|
|
2991
2792
|
id: "maxP95Duration",
|
|
@@ -3297,6 +3098,6 @@ function renderGateReport(result, options = {}) {
|
|
|
3297
3098
|
return renderGateSummaryMarkdown(result);
|
|
3298
3099
|
}
|
|
3299
3100
|
|
|
3300
|
-
export { COHORT_METRIC_IDS, DEFAULT_SUITE_ARTIFACTS_DIR, DEFAULT_SUITE_CONFIG_NAMES, SESSION_WORKFLOW_KEYS, SUITE_TEMPLATE_IDS, aggregateBundleSafeStatus, aggregateSessionCheckResults, analyzeCohort, assertBundlePathContained, buildActivitySummary, buildBundleMetadata, buildBundleSummaryMarkdown, buildLocalExplanation, buildPlaceholderArtifact, buildSessionIndex,
|
|
3101
|
+
export { COHORT_METRIC_IDS, DEFAULT_SUITE_ARTIFACTS_DIR, DEFAULT_SUITE_CONFIG_NAMES, SESSION_WORKFLOW_KEYS, SUITE_TEMPLATE_IDS, aggregateBundleSafeStatus, aggregateSessionCheckResults, analyzeCohort, assertBundlePathContained, buildActivitySummary, buildBundleMetadata, buildBundleSummaryMarkdown, buildLocalExplanation, buildPlaceholderArtifact, buildSessionIndex, bundleFailsOnSafety, bundleRunAssetRelativePath, compareCohortAggregates, defaultBundleOutputPath, defaultSuiteConfigTemplate, deriveSessionStatus, enrichSessionRunRecord, enrichSessionSummary, extractSessionWorkflowMetadata, filterMetasBySessionScope, gateHasThresholds, getSuiteTemplate, groupSessionCohorts, isAgentInspectTrace, listSuiteTemplates, loadSessionRunRecords, loadSuiteConfig, loadTraceMetadataList, normalizeBundleOutputPath, normalizeSuiteConfig, parseCohortMetricList, parseDurationFilter, parseGateList, parseGateNumber, parseGroupBySpec, renderActivitySummaryHuman, renderCohortReport, renderCohortSummaryMarkdown, renderGateGithubStepSummary, renderGateJUnit, renderGateReport, renderGateSummaryMarkdown, renderSuiteReport, renderSuiteReportMarkdown, resolveBundleRunIds, resolveSuiteCaseTrace, resolveSuiteConfigPath, resolveSuiteTemplate, runGate, runSuite, sanitizeBundleRunId, searchTraces, sessionKeyForRun, toMetadataSafeStatus, traceMetasToSessionRunRecords, validateSuiteConfig };
|
|
3301
3102
|
//# sourceMappingURL=advanced.mjs.map
|
|
3302
3103
|
//# sourceMappingURL=advanced.mjs.map
|