@tangle-network/traces 0.9.11 → 0.9.13
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 +62 -19
- package/dist/{chunk-ELWOJS65.js → chunk-H47X6QWV.js} +4016 -750
- package/dist/cli.js +162 -68
- package/dist/index.d.ts +325 -30
- package/dist/index.js +23 -1
- package/docs/demo.gif +0 -0
- package/docs/trace-analysts.md +222 -0
- package/examples/custom-analyst.ts +179 -0
- package/examples/custom-backend.ts +21 -0
- package/examples/external-engines.ts +49 -0
- package/examples/improvement-config.mjs +63 -0
- package/examples/observe-and-alert.ts +19 -0
- package/examples/register-harness.ts +26 -0
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ It reads the transcripts your harness leaves on disk, reconstructs the run as sp
|
|
|
22
22
|
- [Session index](#session-index)
|
|
23
23
|
- [Policy-mining evidence](#policy-mining-evidence)
|
|
24
24
|
- [Upload to the Intelligence Platform](#upload-to-the-intelligence-platform)
|
|
25
|
-
- [
|
|
25
|
+
- [Trace analysts](#trace-analysts)
|
|
26
26
|
- [Library (SDK)](#library-sdk)
|
|
27
27
|
- [Examples](#examples)
|
|
28
28
|
- [Develop](#develop)
|
|
@@ -49,11 +49,16 @@ traces watch --all
|
|
|
49
49
|
traces stream --all --mode findings
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
The first command is shown in the demo above.
|
|
53
|
+
The **deterministic pass** checks stuck loops, token growth, output decay, missing self-verification, tool failures, and human corrections.
|
|
54
|
+
Each supported issue is returned as a finding with evidence, an action, confidence, and a validation plan.
|
|
55
|
+
It needs no API key and costs nothing.
|
|
53
56
|
|
|
54
57
|
Add `--llm` for the **agentic analysts**. `traces` first uses free local signals to choose the smallest useful set: a failure review always runs, while knowledge and edit reviews run only when failures, repeated calls, or corrective feedback support them. They call OpenAI and respect `--budget <usd>`.
|
|
55
58
|
|
|
56
|
-
Every run also writes a **canonical OpenInference JSONL artifact
|
|
59
|
+
Every run also writes a **canonical OpenInference JSONL artifact**.
|
|
60
|
+
Use it with [HALO](https://github.com/context-labs/halo), [Hodoscope](https://github.com/ManifoldRG/hodoscope), or any command that reads the file.
|
|
61
|
+
See [Trace analysts](#trace-analysts).
|
|
57
62
|
|
|
58
63
|
`traces improve` is the reviewable action path.
|
|
59
64
|
It writes one typed result, one report, flattened evidence rows, and the canonical OTLP trace.
|
|
@@ -91,14 +96,22 @@ The deterministic pass (free, no key) surfaces:
|
|
|
91
96
|
| `github-copilot` (`copilot`) | `~/.copilot/session-state/<id>/events.jsonl` | fixture |
|
|
92
97
|
| `forge` (`forgecode`) | `/dump` JSON exports | fixture |
|
|
93
98
|
|
|
94
|
-
Every adapter captures the
|
|
99
|
+
Every adapter captures the conversation stored in one session file: the **user's prompt** and the **assistant's response** text, plus tool calls/results and token usage.
|
|
100
|
+
Claude Code's nested subagent files are folded into the parent trace.
|
|
101
|
+
Codex stores each worker in a separate session file; add `--workflow` to resolve the connected coordinator and worker files.
|
|
102
|
+
`github-copilot` is the one exception: its log format carries no user prompt.
|
|
103
|
+
Factory stores token totals in `.settings.json`, not per turn.
|
|
104
|
+
Forge reads `/dump` JSON exports; live SQLite remains unsupported.
|
|
105
|
+
ACP-only bridges may not persist a local transcript.
|
|
95
106
|
|
|
96
107
|
## CLI reference
|
|
97
108
|
|
|
98
109
|
```bash
|
|
99
110
|
traces list --harness claude-code --last 20 # discover sessions
|
|
100
111
|
traces analyze --harness codex --session <id> # pin one ID printed by `list`
|
|
101
|
-
traces analyze --harness codex --
|
|
112
|
+
traces analyze --harness codex --current # this session, even when a child wrote later
|
|
113
|
+
traces analyze --harness codex --current --latest-turn --workflow # current turn plus workers
|
|
114
|
+
traces analyze --harness claude-code --session <path> --latest-turn # latest task plus its subagents
|
|
102
115
|
traces investigate --all --last 10 --out report.md # explicit investigation alias
|
|
103
116
|
traces improve --all --last 10 --dir .traces/improvement
|
|
104
117
|
traces analyze --all --since 2026-06-18 --out report.md
|
|
@@ -121,13 +134,17 @@ traces upload --since 24h # upload last day to the Inte
|
|
|
121
134
|
| `--harness <id>` | Harness or alias (default: `claude-code`) |
|
|
122
135
|
| `--all` | Every known harness |
|
|
123
136
|
| `--last <n>` | Most-recent N sessions |
|
|
124
|
-
| `--
|
|
137
|
+
| `--current` | Active Codex session from `CODEX_THREAD_ID` |
|
|
138
|
+
| `--latest-turn` | Limit a resumed Codex or Claude Code session to its latest task turn |
|
|
139
|
+
| `--session <id\|path>` | One listed session ID or explicit session file |
|
|
140
|
+
| `--workflow` | Expand selected files through stable parent and child session IDs |
|
|
141
|
+
| `--max-workflow-sessions <n>` | Stop workflow expansion before parsing more than `n` files; default `100` |
|
|
125
142
|
| `--cwd <dir>` | Filter by working directory |
|
|
126
143
|
| `--since <t>` | `upload`: window, `30m`/`2h`/`7d` or ISO (default 24h); `analyze`: ISO cutoff |
|
|
127
144
|
| `--out <path>` | Write the report to a file |
|
|
128
145
|
| `--dir <path>` | `improve`: write the full artifact pack to this directory |
|
|
129
146
|
| `--otlp <path>` | OTLP artifact path (also evidence provenance / dry-run upload preview) |
|
|
130
|
-
| `--format <kind>` | `export
|
|
147
|
+
| `--format <kind>` | File `analyze`, `export`, or `stream`: `auto`, `policy-evidence`, `sandbox-events`, `openinference`, `intelligence-spans`, or `chat-trajectory` |
|
|
131
148
|
| `--llm` / `--budget <usd>` | Enable agentic analysts (needs `OPENAI_API_KEY`) / cap their spend |
|
|
132
149
|
| `--config <path>` | `analyze` / `investigate` / `improve` / `stream`: load BYO analysts, live analysts, and external analyzers |
|
|
133
150
|
| `--interval <s>` / `--window <m>` | `watch` / live `stream`: poll seconds (default 5) / active-session window minutes (default 30) |
|
|
@@ -217,6 +234,7 @@ The config can export:
|
|
|
217
234
|
- `liveAnalysts`: deterministic online analysts that implement the `TraceLiveAnalyst` contract for `traces stream`
|
|
218
235
|
- `registry`: a prebuilt `AnalystRegistry`
|
|
219
236
|
- `externalAnalyzers`: HALO or any command/model adapter that reads the OTLP artifact
|
|
237
|
+
|
|
220
238
|
Traces does not pretend that an action is a measured candidate.
|
|
221
239
|
Use `agent-eval` to propose and compare candidate changes, `agent-runtime` to package an approved improvement, and `agent-interface` to represent profile edits.
|
|
222
240
|
|
|
@@ -249,7 +267,22 @@ It is intentionally read-only: it points to repeated-call loops, high tool-error
|
|
|
249
267
|
traces evidence --all --since 24h --out policy-evidence.jsonl --otlp spans.otlp.jsonl
|
|
250
268
|
```
|
|
251
269
|
|
|
252
|
-
`--last` follows recent file activity and
|
|
270
|
+
`--last` follows recent file activity and may select a child session in multi-agent work.
|
|
271
|
+
Use `--harness codex --current --latest-turn --workflow` for the invoking Codex turn plus its connected workers.
|
|
272
|
+
Omit `--latest-turn` when the full history of a resumed session is the intended unit.
|
|
273
|
+
Workflow expansion follows session IDs, never timestamps or worker names.
|
|
274
|
+
For a latest Codex child, it selects the last parent task that structurally spawned or targeted that child ID, then includes only workers referenced by that parent task.
|
|
275
|
+
This requires the parent log to record the child ID on a spawn, send, follow-up, or lifecycle event and to associate that event with a stable turn ID.
|
|
276
|
+
If either field is absent, the workflow is reported incomplete instead of widening to the parent's full history.
|
|
277
|
+
Missing files, duplicate IDs, contradictory parents, and cycles are reported explicitly.
|
|
278
|
+
Claude Code subagent files are already folded into their parent trace, so `--workflow` normally resolves one Claude session file.
|
|
279
|
+
With `--latest-turn`, ordinary Claude subagents are selected by their parent tool call ID.
|
|
280
|
+
Claude Workflow subagents are selected by the run ID and transcript directory returned by the parent `Workflow` call.
|
|
281
|
+
Each Workflow child attaches to the latest matching call that started before the child.
|
|
282
|
+
Task selection then keeps only children attached to calls in that task.
|
|
283
|
+
Returned directories from another resumed Claude session are included in parsing and source hashes.
|
|
284
|
+
Missing or conflicting Workflow identities stop the parse instead of widening the selected history.
|
|
285
|
+
Cross-harness parent/child trees are not inferred.
|
|
253
286
|
For a reproducible report, run `traces list` first and pass its session ID with `--session`.
|
|
254
287
|
Ephemeral `codex exec --json` output has no discovery location, so select its file with `--harness codex-exec --session <path>`.
|
|
255
288
|
The adapter rejects empty, incomplete, or other JSONL formats instead of emitting zero-valued session evidence.
|
|
@@ -257,7 +290,7 @@ The adapter rejects empty, incomplete, or other JSONL formats instead of emittin
|
|
|
257
290
|
Each JSONL row is one session:
|
|
258
291
|
|
|
259
292
|
- session provenance: harness, session id, cwd, path, mtime
|
|
260
|
-
- explicit-session source binding: `provenance.sourceSha256` over
|
|
293
|
+
- explicit-session source binding: `provenance.sourceSha256` over every adapter-declared input file, including Claude worker and metadata files
|
|
261
294
|
- repo labels: `tangle.subject.key`, `git.repository`, branch, commit
|
|
262
295
|
- behavior metrics: span counts, LLM turns, tool calls, errored tool calls, tokens, models, tool histogram
|
|
263
296
|
- mining signals: stuck loops and tool error rate
|
|
@@ -272,6 +305,7 @@ If you already have compact evidence or event captures on disk, convert them to
|
|
|
272
305
|
```bash
|
|
273
306
|
traces export policy-evidence.jsonl --out spans.openinference.jsonl
|
|
274
307
|
traces export sandbox-events.json --format sandbox-events --out spans.openinference.jsonl
|
|
308
|
+
traces export trajectory.json --format chat-trajectory --out spans.openinference.jsonl
|
|
275
309
|
halo spans.openinference.jsonl --prompt "Analyze this trace slice" --max-turns 1
|
|
276
310
|
```
|
|
277
311
|
|
|
@@ -280,6 +314,7 @@ halo spans.openinference.jsonl --prompt "Analyze this trace slice" --max-turns 1
|
|
|
280
314
|
- compact `traces.policy_evidence.session` JSONL from `traces evidence`
|
|
281
315
|
- JSON arrays with `start`, `raw`, `result`, `done`, and `error` events
|
|
282
316
|
- existing OpenInference JSONL, rewritten through the local redaction path
|
|
317
|
+
- chat message arrays and objects with a `messages` array
|
|
283
318
|
|
|
284
319
|
Run `traces export --help` for the full command reference.
|
|
285
320
|
|
|
@@ -307,19 +342,24 @@ It does **not** catch free-form PII such as names, postal addresses, or phone nu
|
|
|
307
342
|
|
|
308
343
|
Always `--dry-run` first to see exactly what would be sent.
|
|
309
344
|
|
|
310
|
-
##
|
|
311
|
-
|
|
312
|
-
`traces` hosts analysis engines and PII scrubbers it does **not** bundle. You install the tool; `traces` drives it over a thin command adapter. Same pattern for any future engine or model.
|
|
345
|
+
## Trace analysts
|
|
313
346
|
|
|
314
|
-
|
|
347
|
+
Use the local checks by default.
|
|
348
|
+
Add a model-backed engine only when the question needs semantic judgment or behavior discovery.
|
|
315
349
|
|
|
316
350
|
```bash
|
|
317
|
-
traces analyze --last 1
|
|
351
|
+
traces analyze --last 1
|
|
352
|
+
traces analyze --last 1 --llm --budget 0.50
|
|
318
353
|
traces analyze --last 1 --analyzer halo --analyzer-prompt "find token waste"
|
|
319
|
-
traces analyze --
|
|
354
|
+
traces analyze --all --last 20 --analyzer hodoscope
|
|
355
|
+
traces analyze --last 1 --analyzer my-installed-command
|
|
320
356
|
```
|
|
321
357
|
|
|
322
|
-
|
|
358
|
+
HALO returns a diagnosis report.
|
|
359
|
+
Hodoscope samples distinct behaviors and marks every sample `needs_review`.
|
|
360
|
+
An arbitrary command returns a raw report unless its SDK adapter explicitly parses a stricter output type.
|
|
361
|
+
|
|
362
|
+
Read [Trace analysts](./docs/trace-analysts.md) for the output contract, a minimal custom analyst, and labeled benchmark setup.
|
|
323
363
|
|
|
324
364
|
**Redactors** scrub prompt/response prose with an external PII model (catching names/addresses the regex pass can't), running *after* the built-in redaction:
|
|
325
365
|
|
|
@@ -328,7 +368,8 @@ Our OTLP artifact is **canonical OpenInference** (top-level `kind`, `resource`,
|
|
|
328
368
|
traces upload --since 24h --dry-run --redactor "my-pii-scrubber"
|
|
329
369
|
```
|
|
330
370
|
|
|
331
|
-
In the SDK these are the `ExternalAnalyzer` and `Redactor` interfaces (`haloAnalyzer`, `commandAnalyzer`, `commandRedactor`, `applyRedactor`, `runExternalAnalyzers`).
|
|
371
|
+
In the SDK these are the `ExternalAnalyzer` and `Redactor` interfaces (`haloAnalyzer`, `hodoscopeAnalyzer`, `commandAnalyzer`, `commandRedactor`, `applyRedactor`, `runExternalAnalyzers`).
|
|
372
|
+
See [`examples/external-engines.ts`](./examples/external-engines.ts).
|
|
332
373
|
|
|
333
374
|
> For the built-in agentic analysts (`--llm`), set `OPENAI_API_KEY`, or point at any OpenAI-compatible gateway with `OPENAI_BASE_URL` (e.g. an internal router) to use a non-OpenAI key.
|
|
334
375
|
|
|
@@ -366,6 +407,8 @@ The CLI is a thin consumer of these exports.
|
|
|
366
407
|
| `inspectSessionIndex` | `(TraceSessionIndex) → TraceInspectionReport` | rank improvement findings from an index without rescanning sessions |
|
|
367
408
|
| `buildPolicyEvidenceRecord` | `(ref, spans, opts?) → PolicyEvidenceRecord` | summarize one session for downstream policy mining |
|
|
368
409
|
| `collectPolicyEvidence` | `(ScanOptions) → PolicyEvidenceRecord[]` | scan harness sessions and emit policy-evidence rows |
|
|
410
|
+
| `collectSessionWorkflow` | `(adapter, seeds, opts?) → SessionWorkflow` | resolve a bounded parent/child session tree with explicit relationship issues |
|
|
411
|
+
| `collectSessionSelection` | `(groups, opts?) → SessionSelection` | parse, expand, and optionally byte-bind selected session groups |
|
|
369
412
|
| `exportTraceEvidenceFile` | `(path, opts?) → { format, spans, redactionCount }` | convert compact evidence/events/OpenInference files to redacted OpenInference spans |
|
|
370
413
|
| `scanSessions` | `(ScanOptions) → AsyncIterable<ScannedSession>` | the shared locate→parse iterator |
|
|
371
414
|
| `collectSessions` | `(CollectOptions) → SessionBatch[]` | redacted per-session batches for your own pipeline |
|
|
@@ -373,7 +416,7 @@ The CLI is a thin consumer of these exports.
|
|
|
373
416
|
| `planUpload` / `executeUpload` | `(…, { backend? }) → …` | redact + dedup + send to any sink |
|
|
374
417
|
| `selectAdapters` / `listAdapters` / `resolveAdapter` | adapter selection + the harness registry |
|
|
375
418
|
| `HarnessTraceAdapter` | interface (`locate` + `parse`) | implement to add a harness |
|
|
376
|
-
| `ExternalAnalyzer` / `Redactor` | `haloAnalyzer` / `commandAnalyzer` / `commandRedactor` | drive engines/models you install
|
|
419
|
+
| `ExternalAnalyzer` / `Redactor` | `haloAnalyzer` / `hodoscopeAnalyzer` / `commandAnalyzer` / `commandRedactor` | drive engines/models you install |
|
|
377
420
|
|
|
378
421
|
```ts
|
|
379
422
|
import { watchSessions, streamSessions, analyzeSpans, AnalystRegistry, makeFinding } from '@tangle-network/traces'
|
|
@@ -407,7 +450,7 @@ Runnable, in [`examples/`](./examples):
|
|
|
407
450
|
| [`improvement-config.mjs`](./examples/improvement-config.mjs) | plug in BYO analysts for `traces stream` / `traces improve` |
|
|
408
451
|
| [`custom-backend.ts`](./examples/custom-backend.ts) | redact + dedup + upload to your own sink |
|
|
409
452
|
| [`register-harness.ts`](./examples/register-harness.ts) | add a new harness by implementing `HarnessTraceAdapter` |
|
|
410
|
-
| [`external-engines.ts`](./examples/external-engines.ts) | drive HALO
|
|
453
|
+
| [`external-engines.ts`](./examples/external-engines.ts) | drive HALO, Hodoscope, and an external PII scrubber |
|
|
411
454
|
|
|
412
455
|
## Develop
|
|
413
456
|
|