agent-inspect 6.7.3 → 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 +15 -0
- package/package.json +1 -1
- package/packages/cli/dist/{chunk-EMYDJREA.mjs → chunk-FVEQ7JFF.mjs} +227 -201
- package/packages/cli/dist/chunk-FVEQ7JFF.mjs.map +1 -0
- package/packages/cli/dist/index.cjs +247 -209
- package/packages/cli/dist/index.cjs.map +1 -1
- package/packages/cli/dist/index.mjs +16 -5
- package/packages/cli/dist/index.mjs.map +1 -1
- package/packages/cli/dist/{src-IPJNFV37.mjs → src-I5NA7BLK.mjs} +3 -3
- package/packages/cli/dist/{src-IPJNFV37.mjs.map → src-I5NA7BLK.mjs.map} +1 -1
- package/packages/core/dist/advanced.cjs +225 -199
- package/packages/core/dist/advanced.cjs.map +1 -1
- package/packages/core/dist/advanced.mjs +26 -241
- package/packages/core/dist/advanced.mjs.map +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-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/exporters.cjs +136 -129
- package/packages/core/dist/exporters.cjs.map +1 -1
- package/packages/core/dist/exporters.mjs +1 -1
- package/packages/core/dist/logs.cjs +13 -2
- package/packages/core/dist/logs.cjs.map +1 -1
- package/packages/core/dist/logs.mjs +2 -2
- 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-EMYDJREA.mjs.map +0 -1
- package/packages/core/dist/chunk-3USJVBLA.mjs.map +0 -1
- package/packages/core/dist/chunk-E5F2LQCX.mjs.map +0 -1
|
@@ -2225,6 +2225,210 @@ var init_trace_filter = __esm({
|
|
|
2225
2225
|
}
|
|
2226
2226
|
});
|
|
2227
2227
|
|
|
2228
|
+
// packages/core/src/stats.ts
|
|
2229
|
+
function percentile(sorted, p) {
|
|
2230
|
+
if (sorted.length === 0) return void 0;
|
|
2231
|
+
const idx = Math.min(
|
|
2232
|
+
sorted.length - 1,
|
|
2233
|
+
Math.max(0, Math.ceil(p / 100 * sorted.length) - 1)
|
|
2234
|
+
);
|
|
2235
|
+
return sorted[idx];
|
|
2236
|
+
}
|
|
2237
|
+
async function readRunStartedMetadata(filePath) {
|
|
2238
|
+
try {
|
|
2239
|
+
const events = await readTraceEventsFromFile(filePath);
|
|
2240
|
+
for (const event of events) {
|
|
2241
|
+
if (event.event !== "run_started") continue;
|
|
2242
|
+
const rs = event;
|
|
2243
|
+
if (rs.metadata && typeof rs.metadata === "object") {
|
|
2244
|
+
return rs.metadata;
|
|
2245
|
+
}
|
|
2246
|
+
return void 0;
|
|
2247
|
+
}
|
|
2248
|
+
} catch {
|
|
2249
|
+
}
|
|
2250
|
+
return void 0;
|
|
2251
|
+
}
|
|
2252
|
+
function metaMatchesCorrelation(metadata, correlationId, groupId) {
|
|
2253
|
+
if (correlationId) {
|
|
2254
|
+
const v = metadata?.correlationId;
|
|
2255
|
+
if (typeof v !== "string" || v !== correlationId) return false;
|
|
2256
|
+
}
|
|
2257
|
+
if (groupId) {
|
|
2258
|
+
const v = metadata?.groupId;
|
|
2259
|
+
if (typeof v !== "string" || v !== groupId) return false;
|
|
2260
|
+
}
|
|
2261
|
+
return true;
|
|
2262
|
+
}
|
|
2263
|
+
async function buildTraceStats(metas, options) {
|
|
2264
|
+
let filtered = filterTraces(metas, { since: options.since });
|
|
2265
|
+
if (options.correlationId || options.groupId) {
|
|
2266
|
+
const next = [];
|
|
2267
|
+
for (const m of filtered) {
|
|
2268
|
+
const md = await readRunStartedMetadata(m.filePath);
|
|
2269
|
+
if (metaMatchesCorrelation(md, options.correlationId, options.groupId)) {
|
|
2270
|
+
next.push(m);
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
filtered = next;
|
|
2274
|
+
}
|
|
2275
|
+
let successCount = 0;
|
|
2276
|
+
let errorCount = 0;
|
|
2277
|
+
let runningCount = 0;
|
|
2278
|
+
let unknownCount = 0;
|
|
2279
|
+
const durations = [];
|
|
2280
|
+
let totalSteps = 0;
|
|
2281
|
+
let totalLlmSteps = 0;
|
|
2282
|
+
let totalToolSteps = 0;
|
|
2283
|
+
let totalErrorSteps = 0;
|
|
2284
|
+
const slowestRuns = [];
|
|
2285
|
+
const slowestSteps = [];
|
|
2286
|
+
for (const m of filtered) {
|
|
2287
|
+
if (m.status === "success") successCount += 1;
|
|
2288
|
+
else if (m.status === "error") errorCount += 1;
|
|
2289
|
+
else if (m.status === "running") runningCount += 1;
|
|
2290
|
+
else unknownCount += 1;
|
|
2291
|
+
if (typeof m.durationMs === "number" && Number.isFinite(m.durationMs) && m.durationMs >= 0) {
|
|
2292
|
+
durations.push(m.durationMs);
|
|
2293
|
+
slowestRuns.push({
|
|
2294
|
+
runId: m.runId,
|
|
2295
|
+
name: m.name,
|
|
2296
|
+
durationMs: m.durationMs,
|
|
2297
|
+
status: m.status
|
|
2298
|
+
});
|
|
2299
|
+
}
|
|
2300
|
+
try {
|
|
2301
|
+
const events = await readTraceEventsFromFile(m.filePath);
|
|
2302
|
+
if (events.length === 0) continue;
|
|
2303
|
+
const summary = buildRunSummary(events);
|
|
2304
|
+
totalSteps += summary.totalSteps;
|
|
2305
|
+
totalLlmSteps += summary.llmSteps;
|
|
2306
|
+
totalToolSteps += summary.toolSteps;
|
|
2307
|
+
totalErrorSteps += summary.errorSteps;
|
|
2308
|
+
const steps = collectCompletedSteps(events, m.runId);
|
|
2309
|
+
for (const s of steps) {
|
|
2310
|
+
slowestSteps.push(s);
|
|
2311
|
+
}
|
|
2312
|
+
} catch {
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
slowestRuns.sort((a, b) => (b.durationMs ?? 0) - (a.durationMs ?? 0));
|
|
2316
|
+
slowestSteps.sort((a, b) => b.durationMs - a.durationMs);
|
|
2317
|
+
const runLimit = options.slowRunLimit ?? 5;
|
|
2318
|
+
const stepLimit = options.slowStepLimit ?? 5;
|
|
2319
|
+
const sortedDur = [...durations].sort((a, b) => a - b);
|
|
2320
|
+
const totalRuns = filtered.length;
|
|
2321
|
+
const errorRate = totalRuns > 0 ? errorCount / totalRuns : 0;
|
|
2322
|
+
const sumDur = durations.reduce((a, b) => a + b, 0);
|
|
2323
|
+
return {
|
|
2324
|
+
traceDir: options.traceDir,
|
|
2325
|
+
...options.since ? { since: options.since } : {},
|
|
2326
|
+
...options.correlationId ? { correlationId: options.correlationId } : {},
|
|
2327
|
+
...options.groupId ? { groupId: options.groupId } : {},
|
|
2328
|
+
totalRuns,
|
|
2329
|
+
successCount,
|
|
2330
|
+
errorCount,
|
|
2331
|
+
runningCount,
|
|
2332
|
+
unknownCount,
|
|
2333
|
+
errorRate,
|
|
2334
|
+
duration: {
|
|
2335
|
+
...sortedDur.length > 0 ? {
|
|
2336
|
+
minMs: sortedDur[0],
|
|
2337
|
+
maxMs: sortedDur[sortedDur.length - 1],
|
|
2338
|
+
avgMs: sumDur / sortedDur.length,
|
|
2339
|
+
p50Ms: percentile(sortedDur, 50),
|
|
2340
|
+
p95Ms: percentile(sortedDur, 95)
|
|
2341
|
+
} : {}
|
|
2342
|
+
},
|
|
2343
|
+
totalSteps,
|
|
2344
|
+
avgStepsPerRun: totalRuns > 0 ? totalSteps / totalRuns : 0,
|
|
2345
|
+
totalLlmSteps,
|
|
2346
|
+
totalToolSteps,
|
|
2347
|
+
totalErrorSteps,
|
|
2348
|
+
slowestRuns: slowestRuns.slice(0, runLimit),
|
|
2349
|
+
slowestSteps: slowestSteps.slice(0, stepLimit)
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
function collectCompletedSteps(events, runId) {
|
|
2353
|
+
const started = /* @__PURE__ */ new Map();
|
|
2354
|
+
const out = [];
|
|
2355
|
+
for (const e of events) {
|
|
2356
|
+
if (e.event === "step_started") {
|
|
2357
|
+
const s = e;
|
|
2358
|
+
started.set(s.stepId, { name: s.name, type: s.type });
|
|
2359
|
+
}
|
|
2360
|
+
if (e.event === "step_completed") {
|
|
2361
|
+
const c = e;
|
|
2362
|
+
if (c.status !== "success" && c.status !== "error") continue;
|
|
2363
|
+
if (typeof c.durationMs !== "number" || !Number.isFinite(c.durationMs)) {
|
|
2364
|
+
continue;
|
|
2365
|
+
}
|
|
2366
|
+
const meta2 = started.get(c.stepId);
|
|
2367
|
+
out.push({
|
|
2368
|
+
runId,
|
|
2369
|
+
stepName: meta2?.name ?? c.stepId,
|
|
2370
|
+
stepType: meta2?.type ?? "logic",
|
|
2371
|
+
durationMs: c.durationMs
|
|
2372
|
+
});
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
return out;
|
|
2376
|
+
}
|
|
2377
|
+
function formatStepLabel(stepType, stepName) {
|
|
2378
|
+
return stepName.startsWith(`${stepType}:`) ? stepName : `${stepType}:${stepName}`;
|
|
2379
|
+
}
|
|
2380
|
+
function renderTraceStats(stats) {
|
|
2381
|
+
const lines = [];
|
|
2382
|
+
lines.push("Trace stats (local)");
|
|
2383
|
+
lines.push(`Directory: ${stats.traceDir}`);
|
|
2384
|
+
if (stats.since) lines.push(`Since: ${stats.since}`);
|
|
2385
|
+
if (stats.correlationId) lines.push(`Correlation ID: ${stats.correlationId}`);
|
|
2386
|
+
if (stats.groupId) lines.push(`Group ID: ${stats.groupId}`);
|
|
2387
|
+
lines.push("");
|
|
2388
|
+
lines.push(`Runs: ${stats.totalRuns}`);
|
|
2389
|
+
lines.push(
|
|
2390
|
+
` success: ${stats.successCount} error: ${stats.errorCount} running: ${stats.runningCount} unknown: ${stats.unknownCount}`
|
|
2391
|
+
);
|
|
2392
|
+
lines.push(`Error rate: ${(stats.errorRate * 100).toFixed(1)}%`);
|
|
2393
|
+
if (stats.duration.avgMs !== void 0) {
|
|
2394
|
+
lines.push(
|
|
2395
|
+
`Duration: min ${formatDuration2(stats.duration.minMs ?? 0)} | avg ${formatDuration2(stats.duration.avgMs)} | p50 ${formatDuration2(stats.duration.p50Ms ?? 0)} | p95 ${formatDuration2(stats.duration.p95Ms ?? 0)} | max ${formatDuration2(stats.duration.maxMs ?? 0)}`
|
|
2396
|
+
);
|
|
2397
|
+
}
|
|
2398
|
+
lines.push("");
|
|
2399
|
+
lines.push(`Steps: ${stats.totalSteps} (avg ${stats.avgStepsPerRun.toFixed(1)} per run)`);
|
|
2400
|
+
lines.push(
|
|
2401
|
+
` LLM: ${stats.totalLlmSteps} tool: ${stats.totalToolSteps} errors: ${stats.totalErrorSteps}`
|
|
2402
|
+
);
|
|
2403
|
+
if (stats.slowestRuns.length > 0) {
|
|
2404
|
+
lines.push("");
|
|
2405
|
+
lines.push("Slowest runs:");
|
|
2406
|
+
for (const r of stats.slowestRuns) {
|
|
2407
|
+
lines.push(
|
|
2408
|
+
` ${r.runId} | ${r.name ?? "-"} | ${formatDuration2(r.durationMs ?? 0)} | ${r.status}`
|
|
2409
|
+
);
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
if (stats.slowestSteps.length > 0) {
|
|
2413
|
+
lines.push("");
|
|
2414
|
+
lines.push("Slowest steps:");
|
|
2415
|
+
for (const s of stats.slowestSteps) {
|
|
2416
|
+
lines.push(
|
|
2417
|
+
` ${s.runId} | ${formatStepLabel(s.stepType, s.stepName)} | ${formatDuration2(s.durationMs)}`
|
|
2418
|
+
);
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
return lines.join("\n");
|
|
2422
|
+
}
|
|
2423
|
+
var init_stats = __esm({
|
|
2424
|
+
"packages/core/src/stats.ts"() {
|
|
2425
|
+
init_trace_metadata();
|
|
2426
|
+
init_trace_filter();
|
|
2427
|
+
init_storage();
|
|
2428
|
+
init_utils();
|
|
2429
|
+
}
|
|
2430
|
+
});
|
|
2431
|
+
|
|
2228
2432
|
// packages/core/src/timeline.ts
|
|
2229
2433
|
function finite(n) {
|
|
2230
2434
|
return typeof n === "number" && Number.isFinite(n);
|
|
@@ -2382,7 +2586,7 @@ function renderTimeline(timeline, options = {}) {
|
|
|
2382
2586
|
const dur = e.durationMs !== void 0 ? formatDuration2(e.durationMs) : "-";
|
|
2383
2587
|
const err = e.isError ? " error" : "";
|
|
2384
2588
|
const off = formatDuration2(e.offsetMs);
|
|
2385
|
-
let line = `${prefix}+${off} ${typeTag
|
|
2589
|
+
let line = `${prefix}+${off} ${formatStepLabel(typeTag, e.name)} (${dur})${err}`;
|
|
2386
2590
|
if (e.streaming?.chunkCount !== void 0) {
|
|
2387
2591
|
line += ` chunks=${e.streaming.chunkCount}`;
|
|
2388
2592
|
}
|
|
@@ -2395,6 +2599,7 @@ function renderTimeline(timeline, options = {}) {
|
|
|
2395
2599
|
}
|
|
2396
2600
|
var init_timeline = __esm({
|
|
2397
2601
|
"packages/core/src/timeline.ts"() {
|
|
2602
|
+
init_stats();
|
|
2398
2603
|
init_utils();
|
|
2399
2604
|
}
|
|
2400
2605
|
});
|
|
@@ -2545,6 +2750,12 @@ var init_what = __esm({
|
|
|
2545
2750
|
});
|
|
2546
2751
|
|
|
2547
2752
|
// packages/core/src/explain.ts
|
|
2753
|
+
function toDisplayStatus(status) {
|
|
2754
|
+
if (status === "ok") return "success";
|
|
2755
|
+
if (status === "error") return "error";
|
|
2756
|
+
if (status === "running") return "running";
|
|
2757
|
+
return "unknown";
|
|
2758
|
+
}
|
|
2548
2759
|
function flatten(nodes, out = []) {
|
|
2549
2760
|
for (const node of nodes) {
|
|
2550
2761
|
out.push({ node, index: out.length + 1 });
|
|
@@ -2602,7 +2813,7 @@ function buildFacts(run, redactor) {
|
|
|
2602
2813
|
const facts = [
|
|
2603
2814
|
fact("run.id", "Run id", run.runId, redactor),
|
|
2604
2815
|
fact("run.name", "Run name", run.name ?? run.runId, redactor),
|
|
2605
|
-
fact("run.status", "Run status", run.status
|
|
2816
|
+
fact("run.status", "Run status", toDisplayStatus(run.status), redactor),
|
|
2606
2817
|
fact("run.totalEvents", "Total events", run.metadata.totalEvents, redactor),
|
|
2607
2818
|
fact("run.stepCount", "Top-level step count", run.children.length, redactor),
|
|
2608
2819
|
fact("run.nodeCount", "Total node count", nodes.length, redactor),
|
|
@@ -2678,7 +2889,7 @@ function buildLocalExplanation(run, options = {}) {
|
|
|
2678
2889
|
mode,
|
|
2679
2890
|
runId: String(redactValue(redactor, "runId", run.runId)),
|
|
2680
2891
|
...run.name !== void 0 ? { name: String(redactValue(redactor, "name", run.name)) } : {},
|
|
2681
|
-
...run.status !== void 0 ? { status: run.status } : {},
|
|
2892
|
+
...run.status !== void 0 ? { status: toDisplayStatus(run.status) } : {},
|
|
2682
2893
|
redactionProfile,
|
|
2683
2894
|
facts,
|
|
2684
2895
|
inferences: mode === "dry-run" ? [] : buildInferences(run, facts),
|
|
@@ -2695,207 +2906,6 @@ var init_explain = __esm({
|
|
|
2695
2906
|
}
|
|
2696
2907
|
});
|
|
2697
2908
|
|
|
2698
|
-
// packages/core/src/stats.ts
|
|
2699
|
-
function percentile(sorted, p) {
|
|
2700
|
-
if (sorted.length === 0) return void 0;
|
|
2701
|
-
const idx = Math.min(
|
|
2702
|
-
sorted.length - 1,
|
|
2703
|
-
Math.max(0, Math.ceil(p / 100 * sorted.length) - 1)
|
|
2704
|
-
);
|
|
2705
|
-
return sorted[idx];
|
|
2706
|
-
}
|
|
2707
|
-
async function readRunStartedMetadata(filePath) {
|
|
2708
|
-
try {
|
|
2709
|
-
const events = await readTraceEventsFromFile(filePath);
|
|
2710
|
-
for (const event of events) {
|
|
2711
|
-
if (event.event !== "run_started") continue;
|
|
2712
|
-
const rs = event;
|
|
2713
|
-
if (rs.metadata && typeof rs.metadata === "object") {
|
|
2714
|
-
return rs.metadata;
|
|
2715
|
-
}
|
|
2716
|
-
return void 0;
|
|
2717
|
-
}
|
|
2718
|
-
} catch {
|
|
2719
|
-
}
|
|
2720
|
-
return void 0;
|
|
2721
|
-
}
|
|
2722
|
-
function metaMatchesCorrelation(metadata, correlationId, groupId) {
|
|
2723
|
-
if (correlationId) {
|
|
2724
|
-
const v = metadata?.correlationId;
|
|
2725
|
-
if (typeof v !== "string" || v !== correlationId) return false;
|
|
2726
|
-
}
|
|
2727
|
-
if (groupId) {
|
|
2728
|
-
const v = metadata?.groupId;
|
|
2729
|
-
if (typeof v !== "string" || v !== groupId) return false;
|
|
2730
|
-
}
|
|
2731
|
-
return true;
|
|
2732
|
-
}
|
|
2733
|
-
async function buildTraceStats(metas, options) {
|
|
2734
|
-
let filtered = filterTraces(metas, { since: options.since });
|
|
2735
|
-
if (options.correlationId || options.groupId) {
|
|
2736
|
-
const next = [];
|
|
2737
|
-
for (const m of filtered) {
|
|
2738
|
-
const md = await readRunStartedMetadata(m.filePath);
|
|
2739
|
-
if (metaMatchesCorrelation(md, options.correlationId, options.groupId)) {
|
|
2740
|
-
next.push(m);
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
filtered = next;
|
|
2744
|
-
}
|
|
2745
|
-
let successCount = 0;
|
|
2746
|
-
let errorCount = 0;
|
|
2747
|
-
let runningCount = 0;
|
|
2748
|
-
let unknownCount = 0;
|
|
2749
|
-
const durations = [];
|
|
2750
|
-
let totalSteps = 0;
|
|
2751
|
-
let totalLlmSteps = 0;
|
|
2752
|
-
let totalToolSteps = 0;
|
|
2753
|
-
let totalErrorSteps = 0;
|
|
2754
|
-
const slowestRuns = [];
|
|
2755
|
-
const slowestSteps = [];
|
|
2756
|
-
for (const m of filtered) {
|
|
2757
|
-
if (m.status === "success") successCount += 1;
|
|
2758
|
-
else if (m.status === "error") errorCount += 1;
|
|
2759
|
-
else if (m.status === "running") runningCount += 1;
|
|
2760
|
-
else unknownCount += 1;
|
|
2761
|
-
if (typeof m.durationMs === "number" && Number.isFinite(m.durationMs) && m.durationMs >= 0) {
|
|
2762
|
-
durations.push(m.durationMs);
|
|
2763
|
-
slowestRuns.push({
|
|
2764
|
-
runId: m.runId,
|
|
2765
|
-
name: m.name,
|
|
2766
|
-
durationMs: m.durationMs,
|
|
2767
|
-
status: m.status
|
|
2768
|
-
});
|
|
2769
|
-
}
|
|
2770
|
-
try {
|
|
2771
|
-
const events = await readTraceEventsFromFile(m.filePath);
|
|
2772
|
-
if (events.length === 0) continue;
|
|
2773
|
-
const summary = buildRunSummary(events);
|
|
2774
|
-
totalSteps += summary.totalSteps;
|
|
2775
|
-
totalLlmSteps += summary.llmSteps;
|
|
2776
|
-
totalToolSteps += summary.toolSteps;
|
|
2777
|
-
totalErrorSteps += summary.errorSteps;
|
|
2778
|
-
const steps = collectCompletedSteps(events, m.runId);
|
|
2779
|
-
for (const s of steps) {
|
|
2780
|
-
slowestSteps.push(s);
|
|
2781
|
-
}
|
|
2782
|
-
} catch {
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
slowestRuns.sort((a, b) => (b.durationMs ?? 0) - (a.durationMs ?? 0));
|
|
2786
|
-
slowestSteps.sort((a, b) => b.durationMs - a.durationMs);
|
|
2787
|
-
const runLimit = options.slowRunLimit ?? 5;
|
|
2788
|
-
const stepLimit = options.slowStepLimit ?? 5;
|
|
2789
|
-
const sortedDur = [...durations].sort((a, b) => a - b);
|
|
2790
|
-
const totalRuns = filtered.length;
|
|
2791
|
-
const errorRate = totalRuns > 0 ? errorCount / totalRuns : 0;
|
|
2792
|
-
const sumDur = durations.reduce((a, b) => a + b, 0);
|
|
2793
|
-
return {
|
|
2794
|
-
traceDir: options.traceDir,
|
|
2795
|
-
...options.since ? { since: options.since } : {},
|
|
2796
|
-
...options.correlationId ? { correlationId: options.correlationId } : {},
|
|
2797
|
-
...options.groupId ? { groupId: options.groupId } : {},
|
|
2798
|
-
totalRuns,
|
|
2799
|
-
successCount,
|
|
2800
|
-
errorCount,
|
|
2801
|
-
runningCount,
|
|
2802
|
-
unknownCount,
|
|
2803
|
-
errorRate,
|
|
2804
|
-
duration: {
|
|
2805
|
-
...sortedDur.length > 0 ? {
|
|
2806
|
-
minMs: sortedDur[0],
|
|
2807
|
-
maxMs: sortedDur[sortedDur.length - 1],
|
|
2808
|
-
avgMs: sumDur / sortedDur.length,
|
|
2809
|
-
p50Ms: percentile(sortedDur, 50),
|
|
2810
|
-
p95Ms: percentile(sortedDur, 95)
|
|
2811
|
-
} : {}
|
|
2812
|
-
},
|
|
2813
|
-
totalSteps,
|
|
2814
|
-
avgStepsPerRun: totalRuns > 0 ? totalSteps / totalRuns : 0,
|
|
2815
|
-
totalLlmSteps,
|
|
2816
|
-
totalToolSteps,
|
|
2817
|
-
totalErrorSteps,
|
|
2818
|
-
slowestRuns: slowestRuns.slice(0, runLimit),
|
|
2819
|
-
slowestSteps: slowestSteps.slice(0, stepLimit)
|
|
2820
|
-
};
|
|
2821
|
-
}
|
|
2822
|
-
function collectCompletedSteps(events, runId) {
|
|
2823
|
-
const started = /* @__PURE__ */ new Map();
|
|
2824
|
-
const out = [];
|
|
2825
|
-
for (const e of events) {
|
|
2826
|
-
if (e.event === "step_started") {
|
|
2827
|
-
const s = e;
|
|
2828
|
-
started.set(s.stepId, { name: s.name, type: s.type });
|
|
2829
|
-
}
|
|
2830
|
-
if (e.event === "step_completed") {
|
|
2831
|
-
const c = e;
|
|
2832
|
-
if (c.status !== "success" && c.status !== "error") continue;
|
|
2833
|
-
if (typeof c.durationMs !== "number" || !Number.isFinite(c.durationMs)) {
|
|
2834
|
-
continue;
|
|
2835
|
-
}
|
|
2836
|
-
const meta2 = started.get(c.stepId);
|
|
2837
|
-
out.push({
|
|
2838
|
-
runId,
|
|
2839
|
-
stepName: meta2?.name ?? c.stepId,
|
|
2840
|
-
stepType: meta2?.type ?? "logic",
|
|
2841
|
-
durationMs: c.durationMs
|
|
2842
|
-
});
|
|
2843
|
-
}
|
|
2844
|
-
}
|
|
2845
|
-
return out;
|
|
2846
|
-
}
|
|
2847
|
-
function renderTraceStats(stats) {
|
|
2848
|
-
const lines = [];
|
|
2849
|
-
lines.push("Trace stats (local)");
|
|
2850
|
-
lines.push(`Directory: ${stats.traceDir}`);
|
|
2851
|
-
if (stats.since) lines.push(`Since: ${stats.since}`);
|
|
2852
|
-
if (stats.correlationId) lines.push(`Correlation ID: ${stats.correlationId}`);
|
|
2853
|
-
if (stats.groupId) lines.push(`Group ID: ${stats.groupId}`);
|
|
2854
|
-
lines.push("");
|
|
2855
|
-
lines.push(`Runs: ${stats.totalRuns}`);
|
|
2856
|
-
lines.push(
|
|
2857
|
-
` success: ${stats.successCount} error: ${stats.errorCount} running: ${stats.runningCount} unknown: ${stats.unknownCount}`
|
|
2858
|
-
);
|
|
2859
|
-
lines.push(`Error rate: ${(stats.errorRate * 100).toFixed(1)}%`);
|
|
2860
|
-
if (stats.duration.avgMs !== void 0) {
|
|
2861
|
-
lines.push(
|
|
2862
|
-
`Duration: min ${formatDuration2(stats.duration.minMs ?? 0)} | avg ${formatDuration2(stats.duration.avgMs)} | p50 ${formatDuration2(stats.duration.p50Ms ?? 0)} | p95 ${formatDuration2(stats.duration.p95Ms ?? 0)} | max ${formatDuration2(stats.duration.maxMs ?? 0)}`
|
|
2863
|
-
);
|
|
2864
|
-
}
|
|
2865
|
-
lines.push("");
|
|
2866
|
-
lines.push(`Steps: ${stats.totalSteps} (avg ${stats.avgStepsPerRun.toFixed(1)} per run)`);
|
|
2867
|
-
lines.push(
|
|
2868
|
-
` LLM: ${stats.totalLlmSteps} tool: ${stats.totalToolSteps} errors: ${stats.totalErrorSteps}`
|
|
2869
|
-
);
|
|
2870
|
-
if (stats.slowestRuns.length > 0) {
|
|
2871
|
-
lines.push("");
|
|
2872
|
-
lines.push("Slowest runs:");
|
|
2873
|
-
for (const r of stats.slowestRuns) {
|
|
2874
|
-
lines.push(
|
|
2875
|
-
` ${r.runId} | ${r.name ?? "-"} | ${formatDuration2(r.durationMs ?? 0)} | ${r.status}`
|
|
2876
|
-
);
|
|
2877
|
-
}
|
|
2878
|
-
}
|
|
2879
|
-
if (stats.slowestSteps.length > 0) {
|
|
2880
|
-
lines.push("");
|
|
2881
|
-
lines.push("Slowest steps:");
|
|
2882
|
-
for (const s of stats.slowestSteps) {
|
|
2883
|
-
lines.push(
|
|
2884
|
-
` ${s.runId} | ${s.stepType}:${s.stepName} | ${formatDuration2(s.durationMs)}`
|
|
2885
|
-
);
|
|
2886
|
-
}
|
|
2887
|
-
}
|
|
2888
|
-
return lines.join("\n");
|
|
2889
|
-
}
|
|
2890
|
-
var init_stats = __esm({
|
|
2891
|
-
"packages/core/src/stats.ts"() {
|
|
2892
|
-
init_trace_metadata();
|
|
2893
|
-
init_trace_filter();
|
|
2894
|
-
init_storage();
|
|
2895
|
-
init_utils();
|
|
2896
|
-
}
|
|
2897
|
-
});
|
|
2898
|
-
|
|
2899
2909
|
// packages/core/src/search.ts
|
|
2900
2910
|
function parseDurationFilter(expr) {
|
|
2901
2911
|
const raw = expr.trim();
|
|
@@ -2962,6 +2972,12 @@ async function searchTraces(metas, options) {
|
|
|
2962
2972
|
...sessionLabel ? { sessionId: sessionLabel } : {}
|
|
2963
2973
|
});
|
|
2964
2974
|
}
|
|
2975
|
+
results.sort((a, b) => {
|
|
2976
|
+
const ta = a.timestamp ?? 0;
|
|
2977
|
+
const tb = b.timestamp ?? 0;
|
|
2978
|
+
if (ta !== tb) return tb - ta;
|
|
2979
|
+
return a.runId.localeCompare(b.runId);
|
|
2980
|
+
});
|
|
2965
2981
|
return results.slice(0, limit);
|
|
2966
2982
|
}
|
|
2967
2983
|
for (const m of filtered) {
|
|
@@ -3009,7 +3025,7 @@ async function searchTraces(metas, options) {
|
|
|
3009
3025
|
results.sort((a, b) => {
|
|
3010
3026
|
const ta = a.timestamp ?? 0;
|
|
3011
3027
|
const tb = b.timestamp ?? 0;
|
|
3012
|
-
if (ta !== tb) return
|
|
3028
|
+
if (ta !== tb) return tb - ta;
|
|
3013
3029
|
const runCmp = a.runId.localeCompare(b.runId);
|
|
3014
3030
|
if (runCmp !== 0) return runCmp;
|
|
3015
3031
|
return (a.stepName ?? "").localeCompare(b.stepName ?? "");
|
|
@@ -6213,13 +6229,24 @@ function inc(map, key) {
|
|
|
6213
6229
|
map[key] = (map[key] ?? 0) + 1;
|
|
6214
6230
|
}
|
|
6215
6231
|
function computeRunStatus(events) {
|
|
6232
|
+
let runTerminal;
|
|
6233
|
+
let sawRunEvent = false;
|
|
6234
|
+
for (const e of events) {
|
|
6235
|
+
if (e.kind !== "RUN") continue;
|
|
6236
|
+
sawRunEvent = true;
|
|
6237
|
+
if (e.status === "ok" || e.status === "error") {
|
|
6238
|
+
runTerminal = e.status;
|
|
6239
|
+
}
|
|
6240
|
+
}
|
|
6241
|
+
if (sawRunEvent) {
|
|
6242
|
+
return runTerminal ?? "running";
|
|
6243
|
+
}
|
|
6216
6244
|
let hasRunning = false;
|
|
6217
6245
|
for (const e of events) {
|
|
6218
6246
|
if (e.status === "error") return "error";
|
|
6219
6247
|
if (e.status === "running") hasRunning = true;
|
|
6220
6248
|
}
|
|
6221
|
-
|
|
6222
|
-
return "ok";
|
|
6249
|
+
return hasRunning ? "running" : "ok";
|
|
6223
6250
|
}
|
|
6224
6251
|
var TreeBuilder;
|
|
6225
6252
|
var init_tree_builder = __esm({
|
|
@@ -10804,7 +10831,7 @@ var init_src = __esm({
|
|
|
10804
10831
|
});
|
|
10805
10832
|
|
|
10806
10833
|
// package.json
|
|
10807
|
-
var version = "6.7.
|
|
10834
|
+
var version = "6.7.4";
|
|
10808
10835
|
|
|
10809
10836
|
// packages/cli/src/list.ts
|
|
10810
10837
|
init_advanced();
|
|
@@ -16902,9 +16929,20 @@ function buildRules(config, options) {
|
|
|
16902
16929
|
...asStringArray2(checks2.select) ?? [],
|
|
16903
16930
|
...options.rule ?? []
|
|
16904
16931
|
];
|
|
16932
|
+
if (select.length === 0) {
|
|
16933
|
+
const auto = new Set(DEFAULT_SELECT);
|
|
16934
|
+
for (const rule of rules) {
|
|
16935
|
+
if (rule.id !== "run.status") auto.add(rule.id);
|
|
16936
|
+
}
|
|
16937
|
+
return {
|
|
16938
|
+
rules,
|
|
16939
|
+
select: [...auto],
|
|
16940
|
+
diagnostics
|
|
16941
|
+
};
|
|
16942
|
+
}
|
|
16905
16943
|
return {
|
|
16906
16944
|
rules,
|
|
16907
|
-
select
|
|
16945
|
+
select,
|
|
16908
16946
|
diagnostics
|
|
16909
16947
|
};
|
|
16910
16948
|
}
|