@tangle-network/traces 0.8.13 → 0.8.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -12,218 +12,39 @@ import {
12
12
  haloAnalyzer,
13
13
  inspectSessionIndex,
14
14
  knownHarnesses,
15
+ loadTracesConfig,
16
+ mergeTracesConfig,
15
17
  parseSession,
16
18
  parseSince,
17
19
  planUpload,
18
20
  readSessionIndexFile,
21
+ renderAdoption,
19
22
  renderInspectionReport,
23
+ renderPipelines,
24
+ renderReactions,
25
+ renderReport,
20
26
  resolveAdapter,
21
27
  runExternalAnalyzers,
22
28
  runPipelines,
29
+ runTraceImprovementLoop,
30
+ runTraceInvestigation,
31
+ saveReport,
23
32
  selectAdapters,
24
33
  serializePolicyEvidence,
25
34
  serializeSessionIndex,
26
35
  serializeSpans,
36
+ summarizeDeterministicSignals,
27
37
  watchSessions,
28
38
  writeInspectionReportFile,
29
39
  writeOtlpFile,
30
40
  writePolicyEvidenceFile,
31
41
  writeSessionIndexFile,
32
42
  writeTraceEvidenceExportFile
33
- } from "./chunk-PRRWLKSI.js";
43
+ } from "./chunk-EOQY2RIK.js";
34
44
 
35
45
  // src/cli.ts
36
46
  import { readFileSync } from "fs";
37
47
  import { readFile, stat, writeFile } from "fs/promises";
38
-
39
- // src/report.ts
40
- var SEVERITY_RANK = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
41
- var SEVERITY_BADGE = {
42
- critical: "\u{1F534} CRITICAL",
43
- high: "\u{1F7E0} HIGH",
44
- medium: "\u{1F7E1} MEDIUM",
45
- low: "\u{1F535} LOW",
46
- info: "\u2139\uFE0F INFO"
47
- };
48
- function deterministicSummaryText(summary) {
49
- const parts = [];
50
- if (summary.stuckLoops > 0) parts.push(`${summary.stuckLoops} stuck loop(s)`);
51
- if (summary.reactionSignals > 0) parts.push(`${summary.reactionSignals} human reaction signal(s)`);
52
- if (summary.toolErrorRuns > 0) parts.push(`${summary.toolErrorRuns} tool-error run(s)`);
53
- if (parts.length === 0) return "0 deterministic signals";
54
- if (parts.length === 1) return parts[0];
55
- return `${parts.slice(0, -1).join(", ")} and ${parts[parts.length - 1]}`;
56
- }
57
- function plural(count, singular, pluralForm = `${singular}s`) {
58
- return count === 1 ? singular : pluralForm;
59
- }
60
- function summarizeDeterministicSignals(pipelines, reactions) {
61
- const stuckLoops = pipelines.stuckLoops.findings.length;
62
- const reactionSignals = Object.values(reactions.signals).reduce((total, count) => total + count, 0);
63
- const toolErrorRuns = pipelines.toolUse.filter((run) => run.errorRate > 0).length;
64
- return {
65
- stuckLoops,
66
- reactionSignals,
67
- toolErrorRuns,
68
- totalSignals: stuckLoops + reactionSignals + toolErrorRuns
69
- };
70
- }
71
- function renderReport(result, meta) {
72
- const lines = [];
73
- const findings = [...result.findings].sort(
74
- (a, b) => (SEVERITY_RANK[a.severity] ?? 9) - (SEVERITY_RANK[b.severity] ?? 9)
75
- );
76
- const deterministic = meta.deterministic ?? { stuckLoops: 0, reactionSignals: 0, toolErrorRuns: 0, totalSignals: 0 };
77
- const findingSummary = deterministic.totalSignals > 0 ? `${findings.length} analyst ${plural(findings.length, "finding")} + ${deterministic.totalSignals} deterministic ${plural(deterministic.totalSignals, "signal")}` : `${findings.length} ${plural(findings.length, "finding")}`;
78
- lines.push(`# Trace analysis \u2014 ${meta.harness}`);
79
- lines.push("");
80
- lines.push(
81
- `${meta.sessionCount} session(s), ${meta.spanCount} spans \u2192 **${findingSummary}** across ${result.per_analyst.length} analyst(s). Cost: $${result.total_cost_usd.toFixed(4)}.`
82
- );
83
- lines.push("");
84
- lines.push("| Analyst | Status | Findings | Latency |");
85
- lines.push("|---|---|---|---|");
86
- for (const s of result.per_analyst) {
87
- lines.push(`| \`${s.analyst_id}\` | ${s.status} | ${s.findings_count} | ${s.latency_ms}ms |`);
88
- }
89
- lines.push("");
90
- if (findings.length === 0 && deterministic.totalSignals === 0) {
91
- lines.push("_No findings \u2014 no behavioral inefficiencies or failure modes detected._");
92
- } else if (findings.length === 0) {
93
- lines.push(
94
- `_No analyst findings. Deterministic checks found ${deterministicSummaryText(deterministic)}; see sections below._`
95
- );
96
- } else {
97
- const byArea = /* @__PURE__ */ new Map();
98
- for (const f of findings) {
99
- const arr = byArea.get(f.area) ?? [];
100
- arr.push(f);
101
- byArea.set(f.area, arr);
102
- }
103
- for (const [area, arr] of byArea) {
104
- lines.push(`## ${area} (${arr.length})`);
105
- lines.push("");
106
- for (const f of arr) {
107
- lines.push(`### ${SEVERITY_BADGE[f.severity] ?? f.severity} \u2014 ${f.claim}`);
108
- lines.push("");
109
- if (f.subject) lines.push(`- **Subject:** \`${f.subject}\``);
110
- lines.push(`- **Confidence:** ${f.confidence}`);
111
- if (f.recommended_action) lines.push(`- **Fix:** ${f.recommended_action}`);
112
- for (const ev of f.evidence_refs.slice(0, 3)) {
113
- const excerpt = ev.excerpt ? ` \u2014 \`${ev.excerpt.slice(0, 200)}\`` : "";
114
- lines.push(`- **Evidence:** ${ev.kind} ${ev.uri}${excerpt}`);
115
- }
116
- lines.push("");
117
- }
118
- }
119
- }
120
- lines.push("---");
121
- lines.push(`OTLP artifact: \`${meta.otlpPath}\` \u2014 run external engines with \`traces analyze --analyzer halo\`.`);
122
- lines.push("");
123
- return lines.join("\n");
124
- }
125
- function renderPipelines(pr) {
126
- const lines = ["## loops & waste (deterministic)", ""];
127
- if (pr.stuckLoops.findings.length === 0) {
128
- lines.push("- **Stuck loops:** none (no tool called \u22653\xD7 with identical args).");
129
- } else {
130
- lines.push(`- **Stuck loops:** ${pr.stuckLoops.findings.length} (${(pr.stuckLoops.affectedRunRatio * 100).toFixed(0)}% of runs affected)`);
131
- for (const f of pr.stuckLoops.findings.sort((a, b) => b.occurrences - a.occurrences).slice(0, 10)) {
132
- lines.push(` - \u{1F501} \`${f.toolName}\` \xD7${f.occurrences} with identical args over ${(f.windowMs / 1e3).toFixed(1)}s`);
133
- }
134
- }
135
- for (const m of pr.toolUse) {
136
- if (m.totalCalls === 0) continue;
137
- lines.push(
138
- `- **Tool use** (${m.totalCalls} calls): ${(m.duplicateRate * 100).toFixed(0)}% duplicate, ${(m.retryRate * 100).toFixed(0)}% retry, ${(m.errorRate * 100).toFixed(0)}% error`
139
- );
140
- }
141
- lines.push("");
142
- return lines.join("\n");
143
- }
144
- var REACTION_BADGE = {
145
- correction: "correction",
146
- frustration: "frustration",
147
- jargon: "jargon-complaint",
148
- structure: "structure-complaint",
149
- praise: "praise"
150
- };
151
- function ratioStr(r) {
152
- if (r === null) return "n/a (no reaction signals)";
153
- if (!Number.isFinite(r)) return "\u221E (corrective with zero praise)";
154
- return `${r.toFixed(2)}:1`;
155
- }
156
- function oneLine(s, n) {
157
- const t = s.replace(/\s+/g, " ").trim();
158
- return t.length > n ? `${t.slice(0, n)}\u2026` : t;
159
- }
160
- function renderReactions(rr) {
161
- const lines = ["## user reactions (deterministic, human turns only)", ""];
162
- const total = Object.values(rr.signals).reduce((a, b) => a + b, 0);
163
- if (rr.humanReactionTurns === 0) {
164
- lines.push("- No human turns followed an assistant turn (nothing to classify).");
165
- lines.push("");
166
- return lines.join("\n");
167
- }
168
- lines.push(
169
- `- **Reaction turns:** ${rr.humanReactionTurns} human turn(s) followed an assistant turn; ${total} carried a reaction signal.`
170
- );
171
- lines.push(`- **Corrective-to-positive ratio:** ${ratioStr(rr.correctiveToPositiveRatio)}`);
172
- lines.push("");
173
- lines.push("| Signal | Count |");
174
- lines.push("|---|---|");
175
- for (const [k, v] of Object.entries(rr.signals)) {
176
- if (v > 0) lines.push(`| ${REACTION_BADGE[k] ?? k} | ${v} |`);
177
- }
178
- lines.push("");
179
- if (rr.triggerPairs.length > 0) {
180
- lines.push("### top trigger pairs (assistant prose \u2192 human reaction)");
181
- lines.push("");
182
- for (const p of rr.triggerPairs) {
183
- lines.push(`- **[${p.reactions.map((r) => REACTION_BADGE[r] ?? r).join(", ")}]**`);
184
- lines.push(` - assistant: \`${oneLine(p.assistant, 180)}\``);
185
- lines.push(` - human: \`${oneLine(p.human, 180)}\``);
186
- }
187
- lines.push("");
188
- }
189
- return lines.join("\n");
190
- }
191
- function renderAdoption(ar) {
192
- const lines = ["## skill & subagent adoption (deterministic)", ""];
193
- lines.push(
194
- `- **Skill penetration:** ${(ar.skillPenetration * 100).toFixed(0)}% (${ar.sessionsWithSkill}/${ar.sessionCount} session(s) invoked a skill explicitly)`
195
- );
196
- lines.push(
197
- `- **Explicit skill invocations:** ${ar.totalSkillInvocations} (Skill tool spans) \xB7 **Loop-dispatched runs:** ${ar.totalLoopDispatchedRuns} (from ${ar.skillRunFilesRead} \`.evolve/skill-runs.jsonl\` file(s))`
198
- );
199
- lines.push(
200
- `- **Subagent spawns:** ${ar.totalSubagentSpawns} across ${ar.sessionsWithSubagent} session(s)`
201
- );
202
- lines.push("");
203
- const skillRows = Object.entries(ar.skillInvocations).sort((a, b) => b[1] - a[1]);
204
- const loopRows = Object.entries(ar.loopDispatchedRuns).sort((a, b) => b[1] - a[1]);
205
- if (skillRows.length > 0 || loopRows.length > 0) {
206
- lines.push("| Skill | Explicit invocations | Loop-dispatched runs |");
207
- lines.push("|---|---|---|");
208
- const names = [.../* @__PURE__ */ new Set([...skillRows.map((r) => r[0]), ...loopRows.map((r) => r[0])])].sort(
209
- (a, b) => (ar.skillInvocations[b] ?? 0) + (ar.loopDispatchedRuns[b] ?? 0) - (ar.skillInvocations[a] ?? 0) - (ar.loopDispatchedRuns[a] ?? 0)
210
- );
211
- for (const n of names) {
212
- lines.push(`| \`${n}\` | ${ar.skillInvocations[n] ?? 0} | ${ar.loopDispatchedRuns[n] ?? 0} |`);
213
- }
214
- lines.push("");
215
- }
216
- const agentRows = Object.entries(ar.subagentSpawns).sort((a, b) => b[1] - a[1]);
217
- if (agentRows.length > 0) {
218
- lines.push("| Subagent | Spawns |");
219
- lines.push("|---|---|");
220
- for (const [n, c] of agentRows) lines.push(`| \`${n}\` | ${c} |`);
221
- lines.push("");
222
- }
223
- return lines.join("\n");
224
- }
225
-
226
- // src/cli.ts
227
48
  function packageVersion() {
228
49
  const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
229
50
  if (typeof pkg.version !== "string" || !pkg.version) throw new Error("package.json is missing version");
@@ -273,6 +94,9 @@ function parseArgs(argv) {
273
94
  case "--out":
274
95
  a.out = next();
275
96
  break;
97
+ case "--dir":
98
+ a.dir = next();
99
+ break;
276
100
  case "--otlp":
277
101
  a.otlp = next();
278
102
  break;
@@ -285,6 +109,9 @@ function parseArgs(argv) {
285
109
  case "--model":
286
110
  a.model = next();
287
111
  break;
112
+ case "--config":
113
+ a.config = next();
114
+ break;
288
115
  case "--metadata":
289
116
  a.metadata = next();
290
117
  break;
@@ -561,9 +388,7 @@ ${renderPipelines(pipelines)}
561
388
  ${renderReactions(reactions)}
562
389
  ${renderAdoption(adoption)}`;
563
390
  if (args.analyzers.length > 0 && otlpPath) {
564
- const engines = args.analyzers.map(
565
- (spec) => spec === "halo" ? haloAnalyzer({ defaultPrompt: args.analyzerPrompt, model: args.model }) : commandAnalyzer({ name: spec, command: spec, args: (p, prompt) => prompt ? [p, prompt] : [p] })
566
- );
391
+ const engines = externalAnalyzersFromArgs(args);
567
392
  const results = await runExternalAnalyzers(otlpPath, engines, { prompt: args.analyzerPrompt });
568
393
  for (const r of results) {
569
394
  report += `
@@ -580,6 +405,68 @@ ${r.ok ? r.output || "(no output)" : `failed: ${r.error}`}`;
580
405
  console.log(report);
581
406
  }
582
407
  }
408
+ function externalAnalyzersFromArgs(args) {
409
+ return args.analyzers.map(
410
+ (spec) => spec === "halo" ? haloAnalyzer({ defaultPrompt: args.analyzerPrompt, model: args.model }) : commandAnalyzer({ name: spec, command: spec, args: (p, prompt) => prompt ? [p, prompt] : [p] })
411
+ );
412
+ }
413
+ async function cmdInvestigate(args) {
414
+ const { spans, harness, sessionCount, cwds } = await collectSpans(args);
415
+ if (spans.length === 0) throw new Error("no spans found for the given selection");
416
+ const config = await loadTracesConfig(args.config);
417
+ const ai = args.llm ? await buildAxService() : void 0;
418
+ const result = await runTraceInvestigation(mergeTracesConfig({
419
+ spans,
420
+ harness,
421
+ sessionCount,
422
+ cwds,
423
+ minLoopOccurrences: args.minLoop,
424
+ ai,
425
+ model: args.model,
426
+ budgetUsd: args.budget,
427
+ otlpOutPath: args.otlp,
428
+ externalAnalyzers: externalAnalyzersFromArgs(args),
429
+ analyzerPrompt: args.analyzerPrompt,
430
+ log: (msg) => process.stderr.write(`${msg}
431
+ `)
432
+ }, config));
433
+ if (args.out) {
434
+ await saveReport(args.out, result.report);
435
+ console.log(`investigation report \u2192 ${args.out} (${result.findings.length} findings, ${result.recommendations.length} recommendations, OTLP: ${result.otlpPath})`);
436
+ } else {
437
+ console.log(result.report);
438
+ }
439
+ }
440
+ async function cmdImprove(args) {
441
+ const { spans, harness, sessionCount, cwds } = await collectSpans(args);
442
+ if (spans.length === 0) throw new Error("no spans found for the given selection");
443
+ const config = await loadTracesConfig(args.config);
444
+ const ai = args.llm ? await buildAxService() : void 0;
445
+ const result = await runTraceImprovementLoop({
446
+ ...mergeTracesConfig({
447
+ spans,
448
+ harness,
449
+ sessionCount,
450
+ cwds,
451
+ minLoopOccurrences: args.minLoop,
452
+ ai,
453
+ model: args.model,
454
+ budgetUsd: args.budget,
455
+ otlpOutPath: args.otlp,
456
+ externalAnalyzers: externalAnalyzersFromArgs(args),
457
+ analyzerPrompt: args.analyzerPrompt,
458
+ log: (msg) => process.stderr.write(`${msg}
459
+ `)
460
+ }, config),
461
+ adapter: config?.improvementAdapter,
462
+ outDir: args.dir ?? args.out
463
+ });
464
+ const dir = result.artifacts?.directory;
465
+ if (!dir) throw new Error("improve did not produce an artifact directory");
466
+ console.log(
467
+ `improvement artifacts \u2192 ${dir} (${result.findings.length} findings, ${result.recommendations.length} recommendations, ${result.proposals.length} proposal(s), OTLP: ${result.otlpPath})`
468
+ );
469
+ }
583
470
  async function cmdWatch(args) {
584
471
  const all = args.all || !args.harnessExplicit && !args.cwd;
585
472
  const controller = new AbortController();
@@ -692,6 +579,8 @@ function usage() {
692
579
  Commands:
693
580
  list List discovered sessions
694
581
  analyze Run analyst suite + loop/waste pipelines, write a markdown report
582
+ investigate Run typed investigation flow, including BYO config + recommendations
583
+ improve Write a full improvement artifact directory for review/apply/rerun
695
584
  convert Emit OTLP-JSONL only (HALO: use analyze --analyzer halo)
696
585
  index Emit a reusable session index JSON for later investigation
697
586
  inspect Read a session index and print ranked improvement findings
@@ -708,12 +597,14 @@ Options:
708
597
  --cwd <dir> Filter sessions by working directory
709
598
  --since <t> upload: window \u2014 30m / 2h / 7d or an ISO date (default 24h); analyze: ISO cutoff
710
599
  --out <path> Write report to a file
600
+ --dir <path> improve: write artifacts to this directory
711
601
  --otlp <path> OTLP artifact path (also evidence provenance / dry-run upload preview)
712
602
  --format <kind> export: auto | policy-evidence | sandbox-events | openinference
713
603
  --metadata <json> export: attach JSON object fields as span attributes
714
604
  --attr <k=v> export: attach one span attribute (repeatable)
715
605
  --llm Enable agentic RLM analysts (needs OPENAI_API_KEY / OPENAI_BASE_URL)
716
606
  --model <id> --llm model id (e.g. a router model like glm-5.2); default is agent-eval's
607
+ --config <path> investigate/improve: JS config with analysts, external analyzers, or proposal adapter
717
608
  --budget <usd> USD cap for agentic analysts
718
609
  --analyzer <cmd> analyze: also run an external engine over the OTLP (repeatable; "halo" or any command)
719
610
  --analyzer-prompt <p> analyze: prompt passed to external analyzers (default: diagnose)
@@ -752,6 +643,12 @@ async function main() {
752
643
  case "analyze":
753
644
  await cmdAnalyze(args);
754
645
  break;
646
+ case "investigate":
647
+ await cmdInvestigate(args);
648
+ break;
649
+ case "improve":
650
+ await cmdImprove(args);
651
+ break;
755
652
  case "convert":
756
653
  await cmdConvert(args);
757
654
  break;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { ToolUseMetrics, InMemoryTraceStore } from '@tangle-network/agent-eval';
2
2
  import { StuckLoopReport } from '@tangle-network/agent-eval/pipelines';
3
3
  import { AxAIService } from '@ax-llm/ax';
4
- import { AnalystRegistry, buildDefaultAnalystRegistry, AnalystFinding } from '@tangle-network/agent-eval/analyst';
4
+ import { AnalystRegistry, buildDefaultAnalystRegistry, AnalystFinding, AnalystRunResult, Analyst } from '@tangle-network/agent-eval/analyst';
5
5
  export { Analyst, AnalystContext, AnalystFinding, AnalystRegistry, buildDefaultAnalystRegistry, makeFinding } from '@tangle-network/agent-eval/analyst';
6
- import { RedactionRule, RedactionReport } from '@tangle-network/agent-eval/traces';
6
+ import { TraceAnalysisStore, RedactionRule, RedactionReport } from '@tangle-network/agent-eval/traces';
7
7
  export { DEFAULT_REDACTION_RULES, RedactionReport, RedactionRule, redactString, redactValue } from '@tangle-network/agent-eval/traces';
8
8
  import { TraceSpanEvent } from '@tangle-network/agent-eval/hosted';
9
9
  export { HostedClient, createHostedClient, hostedClientFromEnv } from '@tangle-network/agent-eval/hosted';
@@ -1106,6 +1106,176 @@ declare function commandRedactor(spec: {
1106
1106
  timeoutMs?: number;
1107
1107
  }): Redactor;
1108
1108
 
1109
+ interface TracesConfig {
1110
+ readonly registry?: AnalystRegistry;
1111
+ readonly analysts?: readonly Analyst[];
1112
+ readonly externalAnalyzers?: readonly ExternalAnalyzer[];
1113
+ readonly improvementAdapter?: ImprovementAdapter;
1114
+ }
1115
+ interface TraceInvestigationOptions {
1116
+ readonly spans: readonly OtlpSpan[];
1117
+ readonly harness: string;
1118
+ readonly sessionCount: number;
1119
+ readonly cwds?: readonly string[];
1120
+ readonly minLoopOccurrences?: number;
1121
+ readonly ai?: AxAIService;
1122
+ readonly model?: string;
1123
+ readonly budgetUsd?: number;
1124
+ readonly registry?: AnalystRegistry;
1125
+ readonly externalAnalyzers?: readonly ExternalAnalyzer[];
1126
+ readonly analyzerPrompt?: string;
1127
+ readonly otlpOutPath?: string;
1128
+ readonly generatedAt?: string;
1129
+ readonly log?: (msg: string, fields?: Record<string, unknown>) => void;
1130
+ }
1131
+ interface TraceRecommendation {
1132
+ readonly schemaVersion: 1;
1133
+ readonly id: string;
1134
+ readonly severity: AnalystFinding['severity'];
1135
+ readonly title: string;
1136
+ readonly action: string;
1137
+ readonly rationale: string;
1138
+ readonly evidenceRefs: readonly AnalystFinding['evidence_refs'][number][];
1139
+ readonly findingIds: readonly string[];
1140
+ readonly validationPlan: string;
1141
+ readonly source: 'analyst' | 'deterministic' | 'external';
1142
+ }
1143
+ interface TraceClaim {
1144
+ readonly schemaVersion: 1;
1145
+ readonly id: string;
1146
+ readonly severity: AnalystFinding['severity'];
1147
+ readonly text: string;
1148
+ readonly area: string;
1149
+ readonly sourceFindingId: string;
1150
+ readonly evidenceRefs: readonly AnalystFinding['evidence_refs'][number][];
1151
+ readonly validationPlan?: string;
1152
+ }
1153
+ interface TraceEvidenceRow {
1154
+ readonly schemaVersion: 1;
1155
+ readonly kind: 'traces.improvement_evidence';
1156
+ readonly findingId: string;
1157
+ readonly severity: AnalystFinding['severity'];
1158
+ readonly area: string;
1159
+ readonly claim: string;
1160
+ readonly evidence: AnalystFinding['evidence_refs'][number];
1161
+ }
1162
+ interface ImprovementProposal {
1163
+ readonly id: string;
1164
+ readonly title: string;
1165
+ readonly description: string;
1166
+ readonly recommendationIds: readonly string[];
1167
+ readonly patch?: string;
1168
+ readonly validationCommand?: string;
1169
+ readonly evidenceRefs?: readonly AnalystFinding['evidence_refs'][number][];
1170
+ }
1171
+ interface ImprovementAdapterInput {
1172
+ readonly findings: readonly AnalystFinding[];
1173
+ readonly recommendations: readonly TraceRecommendation[];
1174
+ readonly claims: readonly TraceClaim[];
1175
+ readonly spans: readonly OtlpSpan[];
1176
+ readonly otlpPath: string;
1177
+ }
1178
+ interface ImprovementAdapter {
1179
+ propose(input: ImprovementAdapterInput): Promise<readonly ImprovementProposal[]>;
1180
+ }
1181
+ interface FindingStore {
1182
+ append(runId: string, findings: readonly AnalystFinding[]): Promise<void>;
1183
+ }
1184
+ interface RecommendationWriter {
1185
+ write(recommendations: readonly TraceRecommendation[]): Promise<void>;
1186
+ }
1187
+ interface TraceReplayProof {
1188
+ readonly schemaVersion: 1;
1189
+ readonly kind: 'traces.improvement_replay';
1190
+ readonly generatedAt: string;
1191
+ readonly status: 'proposal-only' | 'not-run';
1192
+ readonly candidateApplied: false;
1193
+ readonly baseline: {
1194
+ readonly spanCount: number;
1195
+ readonly findingCount: number;
1196
+ readonly recommendationCount: number;
1197
+ readonly stuckLoops: number;
1198
+ readonly reactionSignals: number;
1199
+ readonly toolErrorRuns: number;
1200
+ };
1201
+ readonly proposals: readonly ImprovementProposal[];
1202
+ readonly note: string;
1203
+ }
1204
+ interface TraceImprovementArtifacts {
1205
+ readonly directory: string;
1206
+ readonly findings: string;
1207
+ readonly recommendations: string;
1208
+ readonly evidence: string;
1209
+ readonly claims: string;
1210
+ readonly report: string;
1211
+ readonly replay: string;
1212
+ }
1213
+ interface TraceInvestigationResult {
1214
+ readonly schemaVersion: 1;
1215
+ readonly kind: 'traces.investigation';
1216
+ readonly generatedAt: string;
1217
+ readonly harness: string;
1218
+ readonly sessionCount: number;
1219
+ readonly spanCount: number;
1220
+ readonly otlpPath: string;
1221
+ readonly findings: readonly AnalystFinding[];
1222
+ readonly recommendations: readonly TraceRecommendation[];
1223
+ readonly claims: readonly TraceClaim[];
1224
+ readonly pipelines: PipelineReport;
1225
+ readonly reactions: ReactionReport;
1226
+ readonly adoption: AdoptionReport;
1227
+ readonly external: readonly ExternalAnalysisResult[];
1228
+ readonly report: string;
1229
+ }
1230
+ interface TraceFindingPacket {
1231
+ readonly schemaVersion: 1;
1232
+ readonly kind: 'traces.finding_packet';
1233
+ readonly generatedAt: string;
1234
+ readonly source: string;
1235
+ readonly findings: readonly AnalystFinding[];
1236
+ readonly recommendations: readonly TraceRecommendation[];
1237
+ readonly claims: readonly TraceClaim[];
1238
+ readonly report: string;
1239
+ }
1240
+ interface BuildTraceFindingPacketOptions {
1241
+ readonly findings: readonly AnalystFinding[];
1242
+ readonly generatedAt?: string;
1243
+ readonly source?: string;
1244
+ readonly title?: string;
1245
+ }
1246
+ interface TraceStoreInvestigationOptions {
1247
+ readonly traceStore: TraceAnalysisStore;
1248
+ readonly registry?: AnalystRegistry;
1249
+ readonly ai?: AxAIService;
1250
+ readonly model?: string;
1251
+ readonly budgetUsd?: number;
1252
+ readonly runId?: string;
1253
+ readonly generatedAt?: string;
1254
+ readonly log?: (msg: string, fields?: Record<string, unknown>) => void;
1255
+ }
1256
+ interface TraceStoreInvestigationResult extends Omit<TraceFindingPacket, 'kind'> {
1257
+ readonly kind: 'traces.store_investigation';
1258
+ readonly analystResult: AnalystRunResult;
1259
+ }
1260
+ interface TraceImprovementResult extends Omit<TraceInvestigationResult, 'kind'> {
1261
+ readonly kind: 'traces.improvement';
1262
+ readonly proposals: readonly ImprovementProposal[];
1263
+ readonly replay: TraceReplayProof;
1264
+ readonly artifacts?: TraceImprovementArtifacts;
1265
+ }
1266
+ interface TraceImprovementOptions extends TraceInvestigationOptions {
1267
+ readonly adapter?: ImprovementAdapter;
1268
+ readonly outDir?: string;
1269
+ }
1270
+ declare function buildTraceFindingPacket(opts: BuildTraceFindingPacketOptions): TraceFindingPacket;
1271
+ declare function loadTracesConfig(path?: string): Promise<TracesConfig | undefined>;
1272
+ declare function mergeTracesConfig(opts: TraceInvestigationOptions, config?: TracesConfig): TraceInvestigationOptions;
1273
+ declare function runTraceInvestigation(opts: TraceInvestigationOptions): Promise<TraceInvestigationResult>;
1274
+ declare function runTraceStoreInvestigation(opts: TraceStoreInvestigationOptions): Promise<TraceStoreInvestigationResult>;
1275
+ declare function writeTraceImprovementArtifacts(result: Pick<TraceImprovementResult, 'findings' | 'recommendations' | 'claims' | 'report' | 'replay'>, outDir?: string): Promise<TraceImprovementArtifacts>;
1276
+ declare function runTraceImprovementLoop(opts: TraceImprovementOptions): Promise<TraceImprovementResult>;
1277
+ declare function saveReport(path: string, report: string): Promise<void>;
1278
+
1109
1279
  /**
1110
1280
  * Live trace observer — the reusable, event-driven core behind `traces watch`.
1111
1281
  *
@@ -1319,4 +1489,4 @@ interface ExecuteOptions {
1319
1489
  /** Send the NEW items (or, on dryRun, write the redacted OTLP that would send). */
1320
1490
  declare function executeUpload(plan: UploadPlan, opts?: ExecuteOptions): Promise<UploadResult>;
1321
1491
 
1322
- export { ACTOR_ATTR, ATTR, type Actor, type AdoptionOptions, type AdoptionReport, AmpAdapter, type AnalyzeOptions, type AnalyzeResult, type BuildPolicyEvidenceOptions, type BuildSessionIndexOptions, CODING_REDACTION_RULES, CONTENT_CAP, CORRECTIVE_REACTIONS, ClaudeAdapter, CodexAdapter, type CollectOptions, type CollectPolicyEvidenceOptions, type CollectSessionIndexOptions, CopilotAdapter, DEFAULT_HARNESS, type ExecuteOptions, type ExternalAnalysisResult, type ExternalAnalyzer, FactoryAdapter, ForgeAdapter, GeminiAdapter, type HarnessTraceAdapter, INGEST_SOURCE_CLI, type InspectSessionIndexOptions, type LocateOptions, type ObservedLoop, type ObserverOptions, OpencodeAdapter, type OtlpSpan, type OtlpSpanKind, type OtlpStatusCode, PiAdapter, type PipelineOptions, type PipelineReport, type PlanOptions, type PolicyEvidenceLoopSummary, type PolicyEvidenceRecord, type PolicyEvidenceToolSummary, QwenAdapter, REACTIONS, type Reaction, type ReactionReport, type ReactionSessionReport, type Redactor, type RepoAttrs, type RepoResolution, type RepoResolutionSource, type RunResult, type RuntimeTrace, type ScanOptions, type ScannedSession, type SessionBatch, type SessionRef, type SpanInput, type SpanRedaction, TRACES_REDACTION_RULES, type TraceContextIndex, type TraceContextRoot, type TraceEvidenceExportOptions, type TraceEvidenceExportResult, type TraceEvidenceFormatOption, type TraceEvidenceInputFormat, type TraceIndexedFile, type TraceInspectionArea, type TraceInspectionFinding, type TraceInspectionReport, type TraceInspectionSeverity, type TraceSessionIndex, type TraceSessionIndexRow, type TriggerPair, type UploadBackend, type UploadItem, type UploadPlan, type UploadRecord, type UploadResult, type UploadState, type UserPromptInput, alreadyUploaded, analyzeAdoption, analyzeReactions, analyzeSpans, applyRedactor, buildPolicyEvidenceRecord, buildSessionIndex, buildSessionIndexFromRows, capText, classifyReaction, claudeActor, codexActor, collectPolicyEvidence, collectSessionIndex, collectSessions, commandAnalyzer, commandRedactor, countSkillRunsJsonl, executeUpload, exportTraceEvidenceFile, exportTraceEvidenceRows, exportTraceEvidenceText, haloAnalyzer, inspectSessionIndex, knownHarnesses, listAdapters, loadState, looksLikeAgentPrompt, normalizeRemote, parseIsoToEpochMs, parseSession, parseSince, planUpload, readSessionIndexFile, redactSpans, renderInspectionReport, resolveAdapter, resolveRepoAttrs, resolveSessionRepoAttrs, runCommand, runExternalAnalyzers, runPipelines, saveState, scanSessions, selectAdapters, serializeInspectionReport, serializePolicyEvidence, serializeSessionIndex, serializeSpans, sessionHash, span, stampRepoAttrs, textIsSynthetic, toOpenInferenceSpan, toRuntimeStore, toTraceSpanEvents, uploadKey, userPromptSpan, watchSessions, writeInspectionReportFile, writeOtlpFile, writePolicyEvidenceFile, writeSessionIndexFile, writeTraceEvidenceExportFile };
1492
+ export { ACTOR_ATTR, ATTR, type Actor, type AdoptionOptions, type AdoptionReport, AmpAdapter, type AnalyzeOptions, type AnalyzeResult, type BuildPolicyEvidenceOptions, type BuildSessionIndexOptions, type BuildTraceFindingPacketOptions, CODING_REDACTION_RULES, CONTENT_CAP, CORRECTIVE_REACTIONS, ClaudeAdapter, CodexAdapter, type CollectOptions, type CollectPolicyEvidenceOptions, type CollectSessionIndexOptions, CopilotAdapter, DEFAULT_HARNESS, type ExecuteOptions, type ExternalAnalysisResult, type ExternalAnalyzer, FactoryAdapter, type FindingStore, ForgeAdapter, GeminiAdapter, type HarnessTraceAdapter, INGEST_SOURCE_CLI, type ImprovementAdapter, type ImprovementAdapterInput, type ImprovementProposal, type InspectSessionIndexOptions, type LocateOptions, type ObservedLoop, type ObserverOptions, OpencodeAdapter, type OtlpSpan, type OtlpSpanKind, type OtlpStatusCode, PiAdapter, type PipelineOptions, type PipelineReport, type PlanOptions, type PolicyEvidenceLoopSummary, type PolicyEvidenceRecord, type PolicyEvidenceToolSummary, QwenAdapter, REACTIONS, type Reaction, type ReactionReport, type ReactionSessionReport, type RecommendationWriter, type Redactor, type RepoAttrs, type RepoResolution, type RepoResolutionSource, type RunResult, type RuntimeTrace, type ScanOptions, type ScannedSession, type SessionBatch, type SessionRef, type SpanInput, type SpanRedaction, TRACES_REDACTION_RULES, type TraceClaim, type TraceContextIndex, type TraceContextRoot, type TraceEvidenceExportOptions, type TraceEvidenceExportResult, type TraceEvidenceFormatOption, type TraceEvidenceInputFormat, type TraceEvidenceRow, type TraceFindingPacket, type TraceImprovementArtifacts, type TraceImprovementOptions, type TraceImprovementResult, type TraceIndexedFile, type TraceInspectionArea, type TraceInspectionFinding, type TraceInspectionReport, type TraceInspectionSeverity, type TraceInvestigationOptions, type TraceInvestigationResult, type TraceRecommendation, type TraceReplayProof, type TraceSessionIndex, type TraceSessionIndexRow, type TraceStoreInvestigationOptions, type TraceStoreInvestigationResult, type TracesConfig, type TriggerPair, type UploadBackend, type UploadItem, type UploadPlan, type UploadRecord, type UploadResult, type UploadState, type UserPromptInput, alreadyUploaded, analyzeAdoption, analyzeReactions, analyzeSpans, applyRedactor, buildPolicyEvidenceRecord, buildSessionIndex, buildSessionIndexFromRows, buildTraceFindingPacket, capText, classifyReaction, claudeActor, codexActor, collectPolicyEvidence, collectSessionIndex, collectSessions, commandAnalyzer, commandRedactor, countSkillRunsJsonl, executeUpload, exportTraceEvidenceFile, exportTraceEvidenceRows, exportTraceEvidenceText, haloAnalyzer, inspectSessionIndex, knownHarnesses, listAdapters, loadState, loadTracesConfig, looksLikeAgentPrompt, mergeTracesConfig, normalizeRemote, parseIsoToEpochMs, parseSession, parseSince, planUpload, readSessionIndexFile, redactSpans, renderInspectionReport, resolveAdapter, resolveRepoAttrs, resolveSessionRepoAttrs, runCommand, runExternalAnalyzers, runPipelines, runTraceImprovementLoop, runTraceInvestigation, runTraceStoreInvestigation, saveReport, saveState, scanSessions, selectAdapters, serializeInspectionReport, serializePolicyEvidence, serializeSessionIndex, serializeSpans, sessionHash, span, stampRepoAttrs, textIsSynthetic, toOpenInferenceSpan, toRuntimeStore, toTraceSpanEvents, uploadKey, userPromptSpan, watchSessions, writeInspectionReportFile, writeOtlpFile, writePolicyEvidenceFile, writeSessionIndexFile, writeTraceEvidenceExportFile, writeTraceImprovementArtifacts };
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ import {
26
26
  buildPolicyEvidenceRecord,
27
27
  buildSessionIndex,
28
28
  buildSessionIndexFromRows,
29
+ buildTraceFindingPacket,
29
30
  capText,
30
31
  classifyReaction,
31
32
  claudeActor,
@@ -44,7 +45,9 @@ import {
44
45
  knownHarnesses,
45
46
  listAdapters,
46
47
  loadState,
48
+ loadTracesConfig,
47
49
  looksLikeAgentPrompt,
50
+ mergeTracesConfig,
48
51
  normalizeRemote,
49
52
  parseIsoToEpochMs,
50
53
  parseSession,
@@ -59,6 +62,10 @@ import {
59
62
  runCommand,
60
63
  runExternalAnalyzers,
61
64
  runPipelines,
65
+ runTraceImprovementLoop,
66
+ runTraceInvestigation,
67
+ runTraceStoreInvestigation,
68
+ saveReport,
62
69
  saveState,
63
70
  scanSessions,
64
71
  selectAdapters,
@@ -80,8 +87,9 @@ import {
80
87
  writeOtlpFile,
81
88
  writePolicyEvidenceFile,
82
89
  writeSessionIndexFile,
83
- writeTraceEvidenceExportFile
84
- } from "./chunk-PRRWLKSI.js";
90
+ writeTraceEvidenceExportFile,
91
+ writeTraceImprovementArtifacts
92
+ } from "./chunk-EOQY2RIK.js";
85
93
 
86
94
  // src/collect.ts
87
95
  async function collectSessions(opts = {}) {
@@ -136,6 +144,7 @@ export {
136
144
  buildPolicyEvidenceRecord,
137
145
  buildSessionIndex,
138
146
  buildSessionIndexFromRows,
147
+ buildTraceFindingPacket,
139
148
  capText,
140
149
  classifyReaction,
141
150
  claudeActor,
@@ -157,8 +166,10 @@ export {
157
166
  knownHarnesses,
158
167
  listAdapters,
159
168
  loadState,
169
+ loadTracesConfig,
160
170
  looksLikeAgentPrompt,
161
171
  makeFinding,
172
+ mergeTracesConfig,
162
173
  normalizeRemote,
163
174
  parseIsoToEpochMs,
164
175
  parseSession,
@@ -175,6 +186,10 @@ export {
175
186
  runCommand,
176
187
  runExternalAnalyzers,
177
188
  runPipelines,
189
+ runTraceImprovementLoop,
190
+ runTraceInvestigation,
191
+ runTraceStoreInvestigation,
192
+ saveReport,
178
193
  saveState,
179
194
  scanSessions,
180
195
  selectAdapters,
@@ -196,5 +211,6 @@ export {
196
211
  writeOtlpFile,
197
212
  writePolicyEvidenceFile,
198
213
  writeSessionIndexFile,
199
- writeTraceEvidenceExportFile
214
+ writeTraceEvidenceExportFile,
215
+ writeTraceImprovementArtifacts
200
216
  };
package/install.sh CHANGED
File without changes