@tangle-network/traces 0.8.18 → 0.8.20
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/README.md +64 -30
- package/dist/{chunk-G3OBZSWY.js → chunk-FCTZLWP7.js} +234 -180
- package/dist/cli.js +51 -24
- package/dist/index.d.ts +172 -135
- package/dist/index.js +5 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
writePolicyEvidenceFile,
|
|
44
44
|
writeSessionIndexFile,
|
|
45
45
|
writeTraceEvidenceExportFile
|
|
46
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-FCTZLWP7.js";
|
|
47
47
|
|
|
48
48
|
// src/cli.ts
|
|
49
49
|
import { readFileSync } from "fs";
|
|
@@ -119,6 +119,9 @@ function parseArgs(argv) {
|
|
|
119
119
|
case "--config":
|
|
120
120
|
a.config = next();
|
|
121
121
|
break;
|
|
122
|
+
case "--mode":
|
|
123
|
+
a.mode = next();
|
|
124
|
+
break;
|
|
122
125
|
case "--metadata":
|
|
123
126
|
a.metadata = next();
|
|
124
127
|
break;
|
|
@@ -212,7 +215,7 @@ async function buildAxService() {
|
|
|
212
215
|
const apiKey = process.env.OPENAI_API_KEY;
|
|
213
216
|
if (!apiKey) {
|
|
214
217
|
throw new Error(
|
|
215
|
-
"--llm needs OPENAI_API_KEY
|
|
218
|
+
"--llm needs OPENAI_API_KEY: an OpenAI key, or a router/gateway key with OPENAI_BASE_URL set to an OpenAI-compatible endpoint (e.g. the Tangle router). Deterministic analysis needs no key."
|
|
216
219
|
);
|
|
217
220
|
}
|
|
218
221
|
const apiURL = process.env.OPENAI_BASE_URL || void 0;
|
|
@@ -223,7 +226,7 @@ async function cmdList(args) {
|
|
|
223
226
|
const groups = await discover({ ...args, last: args.last || 20 });
|
|
224
227
|
for (const { adapter, refs } of groups) {
|
|
225
228
|
console.log(`
|
|
226
|
-
${adapter.harness}
|
|
229
|
+
${adapter.harness}: ${refs.length} session(s)`);
|
|
227
230
|
for (const r of refs) {
|
|
228
231
|
console.log(` ${new Date(r.mtimeMs).toISOString()} ${r.sessionId} ${r.cwd ?? ""}`);
|
|
229
232
|
}
|
|
@@ -513,16 +516,32 @@ function formatLiveFinding(finding) {
|
|
|
513
516
|
const where = `[${finding.session.harness}] ${finding.session.sessionId.slice(0, 8)}`;
|
|
514
517
|
const cwd = finding.session.cwd ? ` \xB7 ${finding.session.cwd}` : "";
|
|
515
518
|
return [
|
|
516
|
-
`${ts} ${finding.severity.toUpperCase()} ${where}
|
|
519
|
+
`${ts} ${finding.severity.toUpperCase()} ${where}: ${finding.title}${cwd}`,
|
|
517
520
|
` evidence: ${summarizeFindingEvidence(finding)}`,
|
|
518
521
|
` action: ${finding.action}`,
|
|
519
522
|
` check: ${finding.check}`
|
|
520
523
|
].join("\n");
|
|
521
524
|
}
|
|
522
|
-
|
|
525
|
+
function streamMode(raw) {
|
|
526
|
+
if (raw === void 0) return "visualizer";
|
|
527
|
+
if (raw === "visualizer" || raw === "findings" || raw === "agent") return raw;
|
|
528
|
+
throw new Error(`unknown stream mode "${raw}" (expected visualizer, findings, or agent)`);
|
|
529
|
+
}
|
|
530
|
+
function streamPreset(args) {
|
|
531
|
+
const mode = streamMode(args.mode);
|
|
532
|
+
return {
|
|
533
|
+
mode,
|
|
534
|
+
includeSpans: !args.noSpans && mode === "visualizer",
|
|
535
|
+
includeFindings: !args.noFindings,
|
|
536
|
+
includeBatches: true,
|
|
537
|
+
includeReports: mode === "agent"
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
async function streamExplicitSession(args, extraAnalysts) {
|
|
523
541
|
if (!args.session) throw new Error("streamExplicitSession needs --session");
|
|
524
542
|
const adapter = resolveAdapter(args.harness);
|
|
525
543
|
if (!adapter) throw new Error(`unknown harness "${args.harness}"`);
|
|
544
|
+
const preset = streamPreset(args);
|
|
526
545
|
const st = await stat(args.session);
|
|
527
546
|
const ref = {
|
|
528
547
|
harness: adapter.harness,
|
|
@@ -534,13 +553,16 @@ async function streamExplicitSession(args) {
|
|
|
534
553
|
const spans = await parseSession(adapter, ref);
|
|
535
554
|
for (const event of traceStreamEventsFromSpans(spans, {
|
|
536
555
|
ref,
|
|
537
|
-
includeSpans:
|
|
538
|
-
includeFindings:
|
|
556
|
+
includeSpans: preset.includeSpans,
|
|
557
|
+
includeFindings: preset.includeFindings,
|
|
558
|
+
extraAnalysts
|
|
539
559
|
})) {
|
|
540
560
|
process.stdout.write(serializeTraceStreamEvent(event));
|
|
541
561
|
}
|
|
542
562
|
}
|
|
543
563
|
async function cmdStream(args) {
|
|
564
|
+
const config = await loadTracesConfig(args.config);
|
|
565
|
+
const preset = streamPreset(args);
|
|
544
566
|
if (args.input) {
|
|
545
567
|
const { spans, harness } = await collectImportedSpans(args);
|
|
546
568
|
const ref = {
|
|
@@ -552,15 +574,16 @@ async function cmdStream(args) {
|
|
|
552
574
|
};
|
|
553
575
|
for (const event of traceStreamEventsFromSpans(spans, {
|
|
554
576
|
ref,
|
|
555
|
-
includeSpans:
|
|
556
|
-
includeFindings:
|
|
577
|
+
includeSpans: preset.includeSpans,
|
|
578
|
+
includeFindings: preset.includeFindings,
|
|
579
|
+
extraAnalysts: config?.liveAnalysts
|
|
557
580
|
})) {
|
|
558
581
|
process.stdout.write(serializeTraceStreamEvent(event));
|
|
559
582
|
}
|
|
560
583
|
return;
|
|
561
584
|
}
|
|
562
585
|
if (args.session) {
|
|
563
|
-
await streamExplicitSession(args);
|
|
586
|
+
await streamExplicitSession(args, config?.liveAnalysts);
|
|
564
587
|
return;
|
|
565
588
|
}
|
|
566
589
|
const all = args.all || !args.harnessExplicit && !args.cwd;
|
|
@@ -568,7 +591,7 @@ async function cmdStream(args) {
|
|
|
568
591
|
process.once("SIGINT", () => controller.abort());
|
|
569
592
|
if (!args.replay) {
|
|
570
593
|
process.stderr.write(
|
|
571
|
-
`traces stream
|
|
594
|
+
`traces stream: ${preset.mode} JSONL feed for ${all ? "all harnesses" : args.harness}, last ${args.window}m, every ${args.interval}s. Ctrl-C to stop.
|
|
572
595
|
`
|
|
573
596
|
);
|
|
574
597
|
}
|
|
@@ -580,8 +603,11 @@ async function cmdStream(args) {
|
|
|
580
603
|
windowMs: args.window * 6e4,
|
|
581
604
|
intervalMs: args.interval * 1e3,
|
|
582
605
|
once: args.replay,
|
|
583
|
-
includeSpans:
|
|
584
|
-
includeFindings:
|
|
606
|
+
includeSpans: preset.includeSpans,
|
|
607
|
+
includeFindings: preset.includeFindings,
|
|
608
|
+
includeBatches: preset.includeBatches,
|
|
609
|
+
includeReports: preset.includeReports,
|
|
610
|
+
extraAnalysts: config?.liveAnalysts,
|
|
585
611
|
signal: controller.signal,
|
|
586
612
|
onEvent: (event) => {
|
|
587
613
|
process.stdout.write(serializeTraceStreamEvent(event));
|
|
@@ -598,7 +624,7 @@ async function cmdWatch(args) {
|
|
|
598
624
|
const controller = new AbortController();
|
|
599
625
|
process.once("SIGINT", () => controller.abort());
|
|
600
626
|
process.stderr.write(
|
|
601
|
-
`traces watch
|
|
627
|
+
`traces watch: observing ${all ? "all harnesses" : args.harness}, sessions active in the last ${args.window}m, every ${args.interval}s. Loop + semantic live findings; read-only; Ctrl-C to stop.
|
|
602
628
|
`
|
|
603
629
|
);
|
|
604
630
|
await watchSessions({
|
|
@@ -612,7 +638,7 @@ async function cmdWatch(args) {
|
|
|
612
638
|
onLoop: (l) => {
|
|
613
639
|
const ts = (/* @__PURE__ */ new Date()).toISOString().slice(11, 19);
|
|
614
640
|
process.stdout.write(
|
|
615
|
-
`${ts} LOOP [${l.harness}] ${l.sessionId.slice(0, 8)}
|
|
641
|
+
`${ts} LOOP [${l.harness}] ${l.sessionId.slice(0, 8)}: \`${l.toolName}\` repeated \xD7${l.occurrences} with identical args (${(l.windowMs / 1e3).toFixed(0)}s)${l.cwd ? ` \xB7 ${l.cwd}` : ""}
|
|
616
642
|
`
|
|
617
643
|
);
|
|
618
644
|
},
|
|
@@ -660,7 +686,7 @@ Window: since ${new Date(sinceMs).toISOString()}
|
|
|
660
686
|
}
|
|
661
687
|
if (args.dryRun) {
|
|
662
688
|
const res2 = await executeUpload(plan, { dryRun: true, otlpOut: args.otlp, stripContent: args.noContent, redactor });
|
|
663
|
-
console.log(`dry run
|
|
689
|
+
console.log(`dry run: ${newItems.length} session(s), ${totalRedactions} redaction(s). Redacted OTLP -> ${res2.otlpPath}`);
|
|
664
690
|
console.log("No upload performed. Set TANGLE_INGEST_URL / TANGLE_INGEST_API_KEY / TANGLE_TENANT_ID and drop --dry-run to send.");
|
|
665
691
|
return;
|
|
666
692
|
}
|
|
@@ -678,7 +704,7 @@ Window: since ${new Date(sinceMs).toISOString()}
|
|
|
678
704
|
);
|
|
679
705
|
}
|
|
680
706
|
function usageExport() {
|
|
681
|
-
console.log(`traces export
|
|
707
|
+
console.log(`traces export: convert trace evidence files to OpenInference JSONL
|
|
682
708
|
|
|
683
709
|
Usage:
|
|
684
710
|
traces export <input.jsonl|input.json> --out <spans.jsonl> [--format auto]
|
|
@@ -688,7 +714,7 @@ Usage:
|
|
|
688
714
|
|
|
689
715
|
Input formats:
|
|
690
716
|
policy-evidence Compact JSONL rows from \`traces evidence --out policy-evidence.jsonl\`
|
|
691
|
-
sandbox-events
|
|
717
|
+
sandbox-events JSON arrays with start/raw/result/done/error events
|
|
692
718
|
openinference Existing OpenInference JSONL; rewrites through traces redaction
|
|
693
719
|
intelligence-spans JSONL rows exported from Tangle Intelligence trace spans
|
|
694
720
|
auto Detect the format from the file contents (default)
|
|
@@ -706,7 +732,7 @@ Safety:
|
|
|
706
732
|
--metadata must be a JSON object; --attr key=value is repeatable and overrides matching metadata keys.`);
|
|
707
733
|
}
|
|
708
734
|
function usage() {
|
|
709
|
-
console.log(`traces
|
|
735
|
+
console.log(`traces: analyze, observe & upload coding-agent sessions
|
|
710
736
|
|
|
711
737
|
Commands:
|
|
712
738
|
list List discovered sessions
|
|
@@ -728,27 +754,28 @@ Options:
|
|
|
728
754
|
--last <n> Most-recent N sessions
|
|
729
755
|
--session <path> Analyze/stream one explicit harness session file
|
|
730
756
|
--cwd <dir> Filter sessions by working directory
|
|
731
|
-
--since <t> upload: window
|
|
757
|
+
--since <t> upload: window, 30m / 2h / 7d or an ISO date (default 24h); analyze: ISO cutoff
|
|
732
758
|
--out <path> Write report to a file
|
|
733
759
|
--dir <path> improve: write artifacts to this directory
|
|
734
760
|
--otlp <path> OTLP artifact path (also evidence provenance / dry-run upload preview)
|
|
735
761
|
--format <kind> analyze/export file: auto | policy-evidence | sandbox-events | openinference | intelligence-spans
|
|
736
762
|
--metadata <json> analyze/export file: attach JSON object fields as span attributes
|
|
737
763
|
--attr <k=v> analyze/export file: attach one span attribute (repeatable)
|
|
764
|
+
--mode <kind> stream: visualizer | findings | agent (default visualizer)
|
|
738
765
|
--replay, --once stream: scan once and exit (default for positional input / --session)
|
|
739
766
|
--no-spans stream: omit per-span pulse events
|
|
740
767
|
--no-findings stream: omit semantic live-finding events
|
|
741
768
|
--llm Enable agentic RLM analysts (needs OPENAI_API_KEY / OPENAI_BASE_URL)
|
|
742
769
|
--model <id> --llm model id (e.g. a router model like glm-5.2); default is agent-eval's
|
|
743
|
-
--config <path> investigate/improve: JS config with analysts, external analyzers, or proposal adapter
|
|
770
|
+
--config <path> investigate/improve/stream: JS config with analysts, liveAnalysts, external analyzers, or proposal adapter
|
|
744
771
|
--budget <usd> USD cap for agentic analysts
|
|
745
772
|
--analyzer <cmd> analyze: also run an external engine over the OTLP (repeatable; "halo" or any command)
|
|
746
773
|
--analyzer-prompt <p> analyze: prompt passed to external analyzers (default: diagnose)
|
|
747
|
-
--interval <s> watch: poll interval seconds (default 5)
|
|
748
|
-
--window <m> watch: only sessions active in the last N minutes (default 30)
|
|
774
|
+
--interval <s> watch/stream: poll interval seconds (default 5)
|
|
775
|
+
--window <m> watch/stream: only sessions active in the last N minutes (default 30)
|
|
749
776
|
--min-loop <n> Min identical repeated calls to flag a loop (default 3)
|
|
750
777
|
--dry-run upload: redact + dedup + preview, write OTLP, but do NOT send
|
|
751
|
-
--no-content upload: strip prompt/response text
|
|
778
|
+
--no-content upload: strip prompt/response text; send metadata only
|
|
752
779
|
--redactor <cmd> upload: external PII scrubber (JSON array stdin\u2192stdout) after the regex pass
|
|
753
780
|
--yes, -y upload: skip the confirmation prompt
|
|
754
781
|
--version, -v Print the installed traces version
|
package/dist/index.d.ts
CHANGED
|
@@ -1106,9 +1106,175 @@ declare function commandRedactor(spec: {
|
|
|
1106
1106
|
timeoutMs?: number;
|
|
1107
1107
|
}): Redactor;
|
|
1108
1108
|
|
|
1109
|
+
type TraceLiveSeverity = 'info' | 'low' | 'medium' | 'high';
|
|
1110
|
+
interface TraceLiveEvidence {
|
|
1111
|
+
readonly kind: 'metric' | 'span' | 'pattern';
|
|
1112
|
+
readonly label: string;
|
|
1113
|
+
readonly value: string;
|
|
1114
|
+
readonly spanIds?: readonly string[];
|
|
1115
|
+
}
|
|
1116
|
+
interface TraceLiveFinding {
|
|
1117
|
+
readonly schemaVersion: 1;
|
|
1118
|
+
readonly kind: 'traces.live_finding';
|
|
1119
|
+
readonly id: string;
|
|
1120
|
+
readonly ruleId: string;
|
|
1121
|
+
readonly fingerprint: string;
|
|
1122
|
+
readonly severity: TraceLiveSeverity;
|
|
1123
|
+
readonly title: string;
|
|
1124
|
+
readonly claim: string;
|
|
1125
|
+
readonly action: string;
|
|
1126
|
+
readonly check: string;
|
|
1127
|
+
readonly evidence: readonly TraceLiveEvidence[];
|
|
1128
|
+
readonly session: TraceStreamSession;
|
|
1129
|
+
readonly observedAt: string;
|
|
1130
|
+
}
|
|
1131
|
+
interface TraceStreamSession {
|
|
1132
|
+
readonly harness: string;
|
|
1133
|
+
readonly sessionId: string;
|
|
1134
|
+
readonly cwd: string | null;
|
|
1135
|
+
readonly path?: string;
|
|
1136
|
+
}
|
|
1137
|
+
type TraceLiveActionKind = 'tool' | 'read' | 'edit' | 'verify' | 'claim' | 'other';
|
|
1138
|
+
interface TraceLiveAction {
|
|
1139
|
+
readonly kind: TraceLiveActionKind;
|
|
1140
|
+
readonly spanId: string;
|
|
1141
|
+
readonly span: OtlpSpan;
|
|
1142
|
+
readonly toolName?: string;
|
|
1143
|
+
readonly signature: string;
|
|
1144
|
+
readonly errored: boolean;
|
|
1145
|
+
}
|
|
1146
|
+
interface TraceLiveLoop {
|
|
1147
|
+
readonly harness: string;
|
|
1148
|
+
readonly sessionId: string;
|
|
1149
|
+
readonly cwd: string | null;
|
|
1150
|
+
readonly toolName: string;
|
|
1151
|
+
readonly argHash: string;
|
|
1152
|
+
readonly occurrences: number;
|
|
1153
|
+
readonly windowMs: number;
|
|
1154
|
+
}
|
|
1155
|
+
interface TraceLiveAnalysisContext {
|
|
1156
|
+
readonly spans: readonly OtlpSpan[];
|
|
1157
|
+
readonly actions: readonly TraceLiveAction[];
|
|
1158
|
+
readonly tools: readonly OtlpSpan[];
|
|
1159
|
+
readonly erroredTools: readonly OtlpSpan[];
|
|
1160
|
+
readonly verificationActions: readonly TraceLiveAction[];
|
|
1161
|
+
readonly changeActions: readonly TraceLiveAction[];
|
|
1162
|
+
readonly session: TraceStreamSession;
|
|
1163
|
+
readonly generatedAt: string;
|
|
1164
|
+
readonly newSpanCount: number;
|
|
1165
|
+
}
|
|
1166
|
+
interface TraceLiveAnalyst {
|
|
1167
|
+
readonly id: string;
|
|
1168
|
+
analyze(context: TraceLiveAnalysisContext): readonly TraceLiveFinding[];
|
|
1169
|
+
}
|
|
1170
|
+
interface TraceLiveBatch {
|
|
1171
|
+
readonly schemaVersion: 1;
|
|
1172
|
+
readonly kind: 'traces.live_batch';
|
|
1173
|
+
readonly generatedAt: string;
|
|
1174
|
+
readonly session: TraceStreamSession;
|
|
1175
|
+
readonly spanCount: number;
|
|
1176
|
+
readonly newSpanCount: number;
|
|
1177
|
+
readonly toolCallCount: number;
|
|
1178
|
+
readonly erroredToolCallCount: number;
|
|
1179
|
+
readonly verificationCallCount: number;
|
|
1180
|
+
readonly changeCallCount: number;
|
|
1181
|
+
readonly actionCounts: Readonly<Record<TraceLiveActionKind, number>>;
|
|
1182
|
+
readonly findingCount: number;
|
|
1183
|
+
readonly findings: readonly TraceLiveFinding[];
|
|
1184
|
+
}
|
|
1185
|
+
type TraceStreamEvent = {
|
|
1186
|
+
readonly schemaVersion: 1;
|
|
1187
|
+
readonly kind: 'traces.stream.session';
|
|
1188
|
+
readonly event: 'session';
|
|
1189
|
+
readonly generatedAt: string;
|
|
1190
|
+
readonly session: TraceStreamSession;
|
|
1191
|
+
readonly spanCount: number;
|
|
1192
|
+
readonly startedAt: string | null;
|
|
1193
|
+
readonly endedAt: string | null;
|
|
1194
|
+
} | {
|
|
1195
|
+
readonly schemaVersion: 1;
|
|
1196
|
+
readonly kind: 'traces.stream.span';
|
|
1197
|
+
readonly event: 'span';
|
|
1198
|
+
readonly generatedAt: string;
|
|
1199
|
+
readonly session: TraceStreamSession;
|
|
1200
|
+
readonly span: OtlpSpan;
|
|
1201
|
+
} | {
|
|
1202
|
+
readonly schemaVersion: 1;
|
|
1203
|
+
readonly kind: 'traces.stream.batch';
|
|
1204
|
+
readonly event: 'analysis_batch';
|
|
1205
|
+
readonly generatedAt: string;
|
|
1206
|
+
readonly ref?: SessionRef;
|
|
1207
|
+
readonly batch: TraceLiveBatch;
|
|
1208
|
+
} | {
|
|
1209
|
+
readonly schemaVersion: 1;
|
|
1210
|
+
readonly kind: 'traces.stream.report';
|
|
1211
|
+
readonly event: 'report';
|
|
1212
|
+
readonly generatedAt: string;
|
|
1213
|
+
readonly session: TraceStreamSession;
|
|
1214
|
+
readonly ref: SessionRef;
|
|
1215
|
+
readonly report: PipelineReport;
|
|
1216
|
+
readonly loops: readonly TraceLiveLoop[];
|
|
1217
|
+
} | {
|
|
1218
|
+
readonly schemaVersion: 1;
|
|
1219
|
+
readonly kind: 'traces.stream.finding';
|
|
1220
|
+
readonly event: 'finding';
|
|
1221
|
+
readonly generatedAt: string;
|
|
1222
|
+
readonly finding: TraceLiveFinding;
|
|
1223
|
+
} | {
|
|
1224
|
+
readonly schemaVersion: 1;
|
|
1225
|
+
readonly kind: 'traces.stream.tick';
|
|
1226
|
+
readonly event: 'tick';
|
|
1227
|
+
readonly generatedAt: string;
|
|
1228
|
+
readonly sessions: number;
|
|
1229
|
+
readonly newSpans: number;
|
|
1230
|
+
readonly findings: number;
|
|
1231
|
+
};
|
|
1232
|
+
interface LiveBatchOptions {
|
|
1233
|
+
readonly generatedAt?: string;
|
|
1234
|
+
readonly session?: Partial<TraceStreamSession>;
|
|
1235
|
+
readonly newSpanCount?: number;
|
|
1236
|
+
/** Replaces the built-in deterministic live analysts. */
|
|
1237
|
+
readonly analysts?: readonly TraceLiveAnalyst[];
|
|
1238
|
+
/** Adds custom live analysts after the built-ins. */
|
|
1239
|
+
readonly extraAnalysts?: readonly TraceLiveAnalyst[];
|
|
1240
|
+
}
|
|
1241
|
+
interface TraceStreamReplayOptions extends LiveBatchOptions {
|
|
1242
|
+
readonly ref?: SessionRef;
|
|
1243
|
+
readonly includeSpans?: boolean;
|
|
1244
|
+
readonly includeFindings?: boolean;
|
|
1245
|
+
}
|
|
1246
|
+
interface TraceStreamOptions extends ScanOptions {
|
|
1247
|
+
/** Observe sessions active within this window. Default 30 min. */
|
|
1248
|
+
readonly windowMs?: number;
|
|
1249
|
+
/** Poll interval. Default 5s. */
|
|
1250
|
+
readonly intervalMs?: number;
|
|
1251
|
+
/** Stop after one scan, useful for replay or tests. */
|
|
1252
|
+
readonly once?: boolean;
|
|
1253
|
+
/** Emit one JSON event per new span. Default true. */
|
|
1254
|
+
readonly includeSpans?: boolean;
|
|
1255
|
+
/** Emit live semantic findings. Default true. */
|
|
1256
|
+
readonly includeFindings?: boolean;
|
|
1257
|
+
/** Emit session and analysis-batch events. Default true. */
|
|
1258
|
+
readonly includeBatches?: boolean;
|
|
1259
|
+
/** Emit deterministic pipeline report events. Default false. */
|
|
1260
|
+
readonly includeReports?: boolean;
|
|
1261
|
+
/** Minimum repeated identical calls for report loop detection. Default 3. */
|
|
1262
|
+
readonly minLoopOccurrences?: number;
|
|
1263
|
+
/** Adds custom live analysts after the built-ins. */
|
|
1264
|
+
readonly extraAnalysts?: readonly TraceLiveAnalyst[];
|
|
1265
|
+
readonly onEvent: (event: TraceStreamEvent) => void | Promise<void>;
|
|
1266
|
+
}
|
|
1267
|
+
declare function classifyLiveActions(spans: readonly OtlpSpan[]): TraceLiveAction[];
|
|
1268
|
+
declare const defaultTraceLiveAnalysts: readonly TraceLiveAnalyst[];
|
|
1269
|
+
declare function analyzeLiveBatch(spans: readonly OtlpSpan[], opts?: LiveBatchOptions): TraceLiveBatch;
|
|
1270
|
+
declare function traceStreamEventsFromSpans(spans: readonly OtlpSpan[], opts?: TraceStreamReplayOptions): TraceStreamEvent[];
|
|
1271
|
+
declare function serializeTraceStreamEvent(event: TraceStreamEvent): string;
|
|
1272
|
+
declare function streamSessions(opts: TraceStreamOptions): Promise<void>;
|
|
1273
|
+
|
|
1109
1274
|
interface TracesConfig {
|
|
1110
1275
|
readonly registry?: AnalystRegistry;
|
|
1111
1276
|
readonly analysts?: readonly Analyst[];
|
|
1277
|
+
readonly liveAnalysts?: readonly TraceLiveAnalyst[];
|
|
1112
1278
|
readonly externalAnalyzers?: readonly ExternalAnalyzer[];
|
|
1113
1279
|
readonly improvementAdapter?: ImprovementAdapter;
|
|
1114
1280
|
}
|
|
@@ -1276,139 +1442,15 @@ declare function writeTraceImprovementArtifacts(result: Pick<TraceImprovementRes
|
|
|
1276
1442
|
declare function runTraceImprovementLoop(opts: TraceImprovementOptions): Promise<TraceImprovementResult>;
|
|
1277
1443
|
declare function saveReport(path: string, report: string): Promise<void>;
|
|
1278
1444
|
|
|
1279
|
-
type TraceLiveSeverity = 'info' | 'low' | 'medium' | 'high';
|
|
1280
|
-
interface TraceLiveEvidence {
|
|
1281
|
-
readonly kind: 'metric' | 'span' | 'pattern';
|
|
1282
|
-
readonly label: string;
|
|
1283
|
-
readonly value: string;
|
|
1284
|
-
readonly spanIds?: readonly string[];
|
|
1285
|
-
}
|
|
1286
|
-
interface TraceLiveFinding {
|
|
1287
|
-
readonly schemaVersion: 1;
|
|
1288
|
-
readonly kind: 'traces.live_finding';
|
|
1289
|
-
readonly id: string;
|
|
1290
|
-
readonly ruleId: string;
|
|
1291
|
-
readonly fingerprint: string;
|
|
1292
|
-
readonly severity: TraceLiveSeverity;
|
|
1293
|
-
readonly title: string;
|
|
1294
|
-
readonly claim: string;
|
|
1295
|
-
readonly action: string;
|
|
1296
|
-
readonly check: string;
|
|
1297
|
-
readonly evidence: readonly TraceLiveEvidence[];
|
|
1298
|
-
readonly session: TraceStreamSession;
|
|
1299
|
-
readonly observedAt: string;
|
|
1300
|
-
}
|
|
1301
|
-
interface TraceStreamSession {
|
|
1302
|
-
readonly harness: string;
|
|
1303
|
-
readonly sessionId: string;
|
|
1304
|
-
readonly cwd: string | null;
|
|
1305
|
-
readonly path?: string;
|
|
1306
|
-
}
|
|
1307
|
-
interface TraceLiveBatch {
|
|
1308
|
-
readonly schemaVersion: 1;
|
|
1309
|
-
readonly kind: 'traces.live_batch';
|
|
1310
|
-
readonly generatedAt: string;
|
|
1311
|
-
readonly session: TraceStreamSession;
|
|
1312
|
-
readonly spanCount: number;
|
|
1313
|
-
readonly newSpanCount: number;
|
|
1314
|
-
readonly toolCallCount: number;
|
|
1315
|
-
readonly erroredToolCallCount: number;
|
|
1316
|
-
readonly verificationCallCount: number;
|
|
1317
|
-
readonly changeCallCount: number;
|
|
1318
|
-
readonly findingCount: number;
|
|
1319
|
-
readonly findings: readonly TraceLiveFinding[];
|
|
1320
|
-
}
|
|
1321
|
-
type TraceStreamEvent = {
|
|
1322
|
-
readonly schemaVersion: 1;
|
|
1323
|
-
readonly kind: 'traces.stream.session';
|
|
1324
|
-
readonly event: 'session';
|
|
1325
|
-
readonly generatedAt: string;
|
|
1326
|
-
readonly session: TraceStreamSession;
|
|
1327
|
-
readonly spanCount: number;
|
|
1328
|
-
readonly startedAt: string | null;
|
|
1329
|
-
readonly endedAt: string | null;
|
|
1330
|
-
} | {
|
|
1331
|
-
readonly schemaVersion: 1;
|
|
1332
|
-
readonly kind: 'traces.stream.span';
|
|
1333
|
-
readonly event: 'span';
|
|
1334
|
-
readonly generatedAt: string;
|
|
1335
|
-
readonly session: TraceStreamSession;
|
|
1336
|
-
readonly span: OtlpSpan;
|
|
1337
|
-
} | {
|
|
1338
|
-
readonly schemaVersion: 1;
|
|
1339
|
-
readonly kind: 'traces.stream.batch';
|
|
1340
|
-
readonly event: 'analysis_batch';
|
|
1341
|
-
readonly generatedAt: string;
|
|
1342
|
-
readonly batch: TraceLiveBatch;
|
|
1343
|
-
} | {
|
|
1344
|
-
readonly schemaVersion: 1;
|
|
1345
|
-
readonly kind: 'traces.stream.finding';
|
|
1346
|
-
readonly event: 'finding';
|
|
1347
|
-
readonly generatedAt: string;
|
|
1348
|
-
readonly finding: TraceLiveFinding;
|
|
1349
|
-
} | {
|
|
1350
|
-
readonly schemaVersion: 1;
|
|
1351
|
-
readonly kind: 'traces.stream.tick';
|
|
1352
|
-
readonly event: 'tick';
|
|
1353
|
-
readonly generatedAt: string;
|
|
1354
|
-
readonly sessions: number;
|
|
1355
|
-
readonly newSpans: number;
|
|
1356
|
-
readonly findings: number;
|
|
1357
|
-
};
|
|
1358
|
-
interface LiveBatchOptions {
|
|
1359
|
-
readonly generatedAt?: string;
|
|
1360
|
-
readonly session?: Partial<TraceStreamSession>;
|
|
1361
|
-
readonly newSpanCount?: number;
|
|
1362
|
-
}
|
|
1363
|
-
interface TraceStreamReplayOptions extends LiveBatchOptions {
|
|
1364
|
-
readonly ref?: SessionRef;
|
|
1365
|
-
readonly includeSpans?: boolean;
|
|
1366
|
-
readonly includeFindings?: boolean;
|
|
1367
|
-
}
|
|
1368
|
-
interface TraceStreamOptions extends ScanOptions {
|
|
1369
|
-
/** Observe sessions active within this window. Default 30 min. */
|
|
1370
|
-
readonly windowMs?: number;
|
|
1371
|
-
/** Poll interval. Default 5s. */
|
|
1372
|
-
readonly intervalMs?: number;
|
|
1373
|
-
/** Stop after one scan, useful for replay or tests. */
|
|
1374
|
-
readonly once?: boolean;
|
|
1375
|
-
/** Emit one JSON event per new span. Default true. */
|
|
1376
|
-
readonly includeSpans?: boolean;
|
|
1377
|
-
/** Emit live semantic findings. Default true. */
|
|
1378
|
-
readonly includeFindings?: boolean;
|
|
1379
|
-
/** Emit session and analysis-batch events. Default true. */
|
|
1380
|
-
readonly includeBatches?: boolean;
|
|
1381
|
-
readonly onEvent: (event: TraceStreamEvent) => void | Promise<void>;
|
|
1382
|
-
}
|
|
1383
|
-
declare function analyzeLiveBatch(spans: readonly OtlpSpan[], opts?: LiveBatchOptions): TraceLiveBatch;
|
|
1384
|
-
declare function traceStreamEventsFromSpans(spans: readonly OtlpSpan[], opts?: TraceStreamReplayOptions): TraceStreamEvent[];
|
|
1385
|
-
declare function serializeTraceStreamEvent(event: TraceStreamEvent): string;
|
|
1386
|
-
declare function streamSessions(opts: TraceStreamOptions): Promise<void>;
|
|
1387
|
-
|
|
1388
1445
|
/**
|
|
1389
|
-
* Live trace observer —
|
|
1446
|
+
* Live trace observer — compatibility wrapper behind `traces watch`.
|
|
1390
1447
|
*
|
|
1391
|
-
* `
|
|
1392
|
-
*
|
|
1393
|
-
*
|
|
1394
|
-
* grows (`onLoop`). It's read-only (never touches the agent or its harness) and
|
|
1395
|
-
* cancellable via an `AbortSignal`, so a third party can subscribe to the live
|
|
1396
|
-
* findings stream and feed it into any system — a dashboard, an alerter, a
|
|
1397
|
-
* steering layer, or another agent — without shelling out to the CLI.
|
|
1448
|
+
* `streamSessions` is the single live scanner. `watchSessions` keeps the
|
|
1449
|
+
* callback-oriented SDK surface for existing users while consuming stream
|
|
1450
|
+
* events instead of running a second polling loop.
|
|
1398
1451
|
*/
|
|
1399
1452
|
|
|
1400
|
-
|
|
1401
|
-
interface ObservedLoop {
|
|
1402
|
-
harness: string;
|
|
1403
|
-
sessionId: string;
|
|
1404
|
-
cwd: string | null;
|
|
1405
|
-
toolName: string;
|
|
1406
|
-
argHash: string;
|
|
1407
|
-
/** Identical repeated calls observed so far. */
|
|
1408
|
-
occurrences: number;
|
|
1409
|
-
/** Milliseconds between the first and last call in the loop. */
|
|
1410
|
-
windowMs: number;
|
|
1411
|
-
}
|
|
1453
|
+
type ObservedLoop = TraceLiveLoop;
|
|
1412
1454
|
interface ObserverOptions {
|
|
1413
1455
|
/** Harness ids/aliases to observe. Omit (or pass `all: true`) → every harness. */
|
|
1414
1456
|
harnesses?: string[];
|
|
@@ -1443,11 +1485,6 @@ interface ObserverOptions {
|
|
|
1443
1485
|
sessions: number;
|
|
1444
1486
|
}) => void;
|
|
1445
1487
|
}
|
|
1446
|
-
/**
|
|
1447
|
-
* Observe active sessions until `opts.signal` aborts. Returns a promise that
|
|
1448
|
-
* resolves on abort. Errors in a single session are routed to `onError` and
|
|
1449
|
-
* never stop the loop.
|
|
1450
|
-
*/
|
|
1451
1488
|
declare function watchSessions(opts: ObserverOptions): Promise<void>;
|
|
1452
1489
|
|
|
1453
1490
|
/**
|
|
@@ -1602,4 +1639,4 @@ interface ExecuteOptions {
|
|
|
1602
1639
|
/** Send the NEW items (or, on dryRun, write the redacted OTLP that would send). */
|
|
1603
1640
|
declare function executeUpload(plan: UploadPlan, opts?: ExecuteOptions): Promise<UploadResult>;
|
|
1604
1641
|
|
|
1605
|
-
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 LiveBatchOptions, 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 TraceLiveBatch, type TraceLiveEvidence, type TraceLiveFinding, type TraceLiveSeverity, type TraceRecommendation, type TraceReplayProof, type TraceSessionIndex, type TraceSessionIndexRow, type TraceStoreInvestigationOptions, type TraceStoreInvestigationResult, type TraceStreamEvent, type TraceStreamOptions, type TraceStreamReplayOptions, type TraceStreamSession, type TracesConfig, type TriggerPair, type UploadBackend, type UploadItem, type UploadPlan, type UploadRecord, type UploadResult, type UploadState, type UserPromptInput, alreadyUploaded, analyzeAdoption, analyzeLiveBatch, 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, serializeTraceStreamEvent, sessionHash, span, stampRepoAttrs, streamSessions, textIsSynthetic, toOpenInferenceSpan, toRuntimeStore, toTraceSpanEvents, traceStreamEventsFromSpans, uploadKey, userPromptSpan, watchSessions, writeInspectionReportFile, writeOtlpFile, writePolicyEvidenceFile, writeSessionIndexFile, writeTraceEvidenceExportFile, writeTraceImprovementArtifacts };
|
|
1642
|
+
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 LiveBatchOptions, 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 TraceLiveAction, type TraceLiveActionKind, type TraceLiveAnalysisContext, type TraceLiveAnalyst, type TraceLiveBatch, type TraceLiveEvidence, type TraceLiveFinding, type TraceLiveLoop, type TraceLiveSeverity, type TraceRecommendation, type TraceReplayProof, type TraceSessionIndex, type TraceSessionIndexRow, type TraceStoreInvestigationOptions, type TraceStoreInvestigationResult, type TraceStreamEvent, type TraceStreamOptions, type TraceStreamReplayOptions, type TraceStreamSession, type TracesConfig, type TriggerPair, type UploadBackend, type UploadItem, type UploadPlan, type UploadRecord, type UploadResult, type UploadState, type UserPromptInput, alreadyUploaded, analyzeAdoption, analyzeLiveBatch, analyzeReactions, analyzeSpans, applyRedactor, buildPolicyEvidenceRecord, buildSessionIndex, buildSessionIndexFromRows, buildTraceFindingPacket, capText, classifyLiveActions, classifyReaction, claudeActor, codexActor, collectPolicyEvidence, collectSessionIndex, collectSessions, commandAnalyzer, commandRedactor, countSkillRunsJsonl, defaultTraceLiveAnalysts, 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, serializeTraceStreamEvent, sessionHash, span, stampRepoAttrs, streamSessions, textIsSynthetic, toOpenInferenceSpan, toRuntimeStore, toTraceSpanEvents, traceStreamEventsFromSpans, uploadKey, userPromptSpan, watchSessions, writeInspectionReportFile, writeOtlpFile, writePolicyEvidenceFile, writeSessionIndexFile, writeTraceEvidenceExportFile, writeTraceImprovementArtifacts };
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
buildSessionIndexFromRows,
|
|
30
30
|
buildTraceFindingPacket,
|
|
31
31
|
capText,
|
|
32
|
+
classifyLiveActions,
|
|
32
33
|
classifyReaction,
|
|
33
34
|
claudeActor,
|
|
34
35
|
codexActor,
|
|
@@ -37,6 +38,7 @@ import {
|
|
|
37
38
|
commandAnalyzer,
|
|
38
39
|
commandRedactor,
|
|
39
40
|
countSkillRunsJsonl,
|
|
41
|
+
defaultTraceLiveAnalysts,
|
|
40
42
|
executeUpload,
|
|
41
43
|
exportTraceEvidenceFile,
|
|
42
44
|
exportTraceEvidenceRows,
|
|
@@ -93,7 +95,7 @@ import {
|
|
|
93
95
|
writeSessionIndexFile,
|
|
94
96
|
writeTraceEvidenceExportFile,
|
|
95
97
|
writeTraceImprovementArtifacts
|
|
96
|
-
} from "./chunk-
|
|
98
|
+
} from "./chunk-FCTZLWP7.js";
|
|
97
99
|
|
|
98
100
|
// src/collect.ts
|
|
99
101
|
async function collectSessions(opts = {}) {
|
|
@@ -151,6 +153,7 @@ export {
|
|
|
151
153
|
buildSessionIndexFromRows,
|
|
152
154
|
buildTraceFindingPacket,
|
|
153
155
|
capText,
|
|
156
|
+
classifyLiveActions,
|
|
154
157
|
classifyReaction,
|
|
155
158
|
claudeActor,
|
|
156
159
|
codexActor,
|
|
@@ -161,6 +164,7 @@ export {
|
|
|
161
164
|
commandRedactor,
|
|
162
165
|
countSkillRunsJsonl,
|
|
163
166
|
createHostedClient,
|
|
167
|
+
defaultTraceLiveAnalysts,
|
|
164
168
|
executeUpload,
|
|
165
169
|
exportTraceEvidenceFile,
|
|
166
170
|
exportTraceEvidenceRows,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/traces",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.20",
|
|
4
4
|
"description": "Point it at your coding-agent session traces (Claude Code, Codex, OpenCode, Gemini, Pi, …) and get failure-mode + efficiency findings. CLI + SDK over the @tangle-network/agent-eval analyst suite — observe live sessions, run your own analysts, redact, and upload to the Tangle Intelligence Platform.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|