@tangle-network/traces 0.9.12 → 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 +58 -17
- package/dist/{chunk-YDUN3M5J.js → chunk-H47X6QWV.js} +3907 -798
- package/dist/cli.js +126 -65
- package/dist/index.d.ts +319 -24
- 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,7 +96,13 @@ 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
|
|
|
@@ -99,6 +110,8 @@ Every adapter captures the full conversation: the **user's prompt** and the **as
|
|
|
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
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
|
|
@@ -122,13 +135,16 @@ traces upload --since 24h # upload last day to the Inte
|
|
|
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 |
|
|
125
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` |
|
|
126
142
|
| `--cwd <dir>` | Filter by working directory |
|
|
127
143
|
| `--since <t>` | `upload`: window, `30m`/`2h`/`7d` or ISO (default 24h); `analyze`: ISO cutoff |
|
|
128
144
|
| `--out <path>` | Write the report to a file |
|
|
129
145
|
| `--dir <path>` | `improve`: write the full artifact pack to this directory |
|
|
130
146
|
| `--otlp <path>` | OTLP artifact path (also evidence provenance / dry-run upload preview) |
|
|
131
|
-
| `--format <kind>` | `export
|
|
147
|
+
| `--format <kind>` | File `analyze`, `export`, or `stream`: `auto`, `policy-evidence`, `sandbox-events`, `openinference`, `intelligence-spans`, or `chat-trajectory` |
|
|
132
148
|
| `--llm` / `--budget <usd>` | Enable agentic analysts (needs `OPENAI_API_KEY`) / cap their spend |
|
|
133
149
|
| `--config <path>` | `analyze` / `investigate` / `improve` / `stream`: load BYO analysts, live analysts, and external analyzers |
|
|
134
150
|
| `--interval <s>` / `--window <m>` | `watch` / live `stream`: poll seconds (default 5) / active-session window minutes (default 30) |
|
|
@@ -218,6 +234,7 @@ The config can export:
|
|
|
218
234
|
- `liveAnalysts`: deterministic online analysts that implement the `TraceLiveAnalyst` contract for `traces stream`
|
|
219
235
|
- `registry`: a prebuilt `AnalystRegistry`
|
|
220
236
|
- `externalAnalyzers`: HALO or any command/model adapter that reads the OTLP artifact
|
|
237
|
+
|
|
221
238
|
Traces does not pretend that an action is a measured candidate.
|
|
222
239
|
Use `agent-eval` to propose and compare candidate changes, `agent-runtime` to package an approved improvement, and `agent-interface` to represent profile edits.
|
|
223
240
|
|
|
@@ -251,7 +268,21 @@ traces evidence --all --since 24h --out policy-evidence.jsonl --otlp spans.otlp.
|
|
|
251
268
|
```
|
|
252
269
|
|
|
253
270
|
`--last` follows recent file activity and may select a child session in multi-agent work.
|
|
254
|
-
Use `--harness codex --current` for the invoking Codex
|
|
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.
|
|
255
286
|
For a reproducible report, run `traces list` first and pass its session ID with `--session`.
|
|
256
287
|
Ephemeral `codex exec --json` output has no discovery location, so select its file with `--harness codex-exec --session <path>`.
|
|
257
288
|
The adapter rejects empty, incomplete, or other JSONL formats instead of emitting zero-valued session evidence.
|
|
@@ -259,7 +290,7 @@ The adapter rejects empty, incomplete, or other JSONL formats instead of emittin
|
|
|
259
290
|
Each JSONL row is one session:
|
|
260
291
|
|
|
261
292
|
- session provenance: harness, session id, cwd, path, mtime
|
|
262
|
-
- 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
|
|
263
294
|
- repo labels: `tangle.subject.key`, `git.repository`, branch, commit
|
|
264
295
|
- behavior metrics: span counts, LLM turns, tool calls, errored tool calls, tokens, models, tool histogram
|
|
265
296
|
- mining signals: stuck loops and tool error rate
|
|
@@ -274,6 +305,7 @@ If you already have compact evidence or event captures on disk, convert them to
|
|
|
274
305
|
```bash
|
|
275
306
|
traces export policy-evidence.jsonl --out spans.openinference.jsonl
|
|
276
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
|
|
277
309
|
halo spans.openinference.jsonl --prompt "Analyze this trace slice" --max-turns 1
|
|
278
310
|
```
|
|
279
311
|
|
|
@@ -282,6 +314,7 @@ halo spans.openinference.jsonl --prompt "Analyze this trace slice" --max-turns 1
|
|
|
282
314
|
- compact `traces.policy_evidence.session` JSONL from `traces evidence`
|
|
283
315
|
- JSON arrays with `start`, `raw`, `result`, `done`, and `error` events
|
|
284
316
|
- existing OpenInference JSONL, rewritten through the local redaction path
|
|
317
|
+
- chat message arrays and objects with a `messages` array
|
|
285
318
|
|
|
286
319
|
Run `traces export --help` for the full command reference.
|
|
287
320
|
|
|
@@ -309,19 +342,24 @@ It does **not** catch free-form PII such as names, postal addresses, or phone nu
|
|
|
309
342
|
|
|
310
343
|
Always `--dry-run` first to see exactly what would be sent.
|
|
311
344
|
|
|
312
|
-
##
|
|
313
|
-
|
|
314
|
-
`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
|
|
315
346
|
|
|
316
|
-
|
|
347
|
+
Use the local checks by default.
|
|
348
|
+
Add a model-backed engine only when the question needs semantic judgment or behavior discovery.
|
|
317
349
|
|
|
318
350
|
```bash
|
|
319
|
-
traces analyze --last 1
|
|
351
|
+
traces analyze --last 1
|
|
352
|
+
traces analyze --last 1 --llm --budget 0.50
|
|
320
353
|
traces analyze --last 1 --analyzer halo --analyzer-prompt "find token waste"
|
|
321
|
-
traces analyze --
|
|
354
|
+
traces analyze --all --last 20 --analyzer hodoscope
|
|
355
|
+
traces analyze --last 1 --analyzer my-installed-command
|
|
322
356
|
```
|
|
323
357
|
|
|
324
|
-
|
|
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.
|
|
325
363
|
|
|
326
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:
|
|
327
365
|
|
|
@@ -330,7 +368,8 @@ Our OTLP artifact is **canonical OpenInference** (top-level `kind`, `resource`,
|
|
|
330
368
|
traces upload --since 24h --dry-run --redactor "my-pii-scrubber"
|
|
331
369
|
```
|
|
332
370
|
|
|
333
|
-
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).
|
|
334
373
|
|
|
335
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.
|
|
336
375
|
|
|
@@ -368,6 +407,8 @@ The CLI is a thin consumer of these exports.
|
|
|
368
407
|
| `inspectSessionIndex` | `(TraceSessionIndex) → TraceInspectionReport` | rank improvement findings from an index without rescanning sessions |
|
|
369
408
|
| `buildPolicyEvidenceRecord` | `(ref, spans, opts?) → PolicyEvidenceRecord` | summarize one session for downstream policy mining |
|
|
370
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 |
|
|
371
412
|
| `exportTraceEvidenceFile` | `(path, opts?) → { format, spans, redactionCount }` | convert compact evidence/events/OpenInference files to redacted OpenInference spans |
|
|
372
413
|
| `scanSessions` | `(ScanOptions) → AsyncIterable<ScannedSession>` | the shared locate→parse iterator |
|
|
373
414
|
| `collectSessions` | `(CollectOptions) → SessionBatch[]` | redacted per-session batches for your own pipeline |
|
|
@@ -375,7 +416,7 @@ The CLI is a thin consumer of these exports.
|
|
|
375
416
|
| `planUpload` / `executeUpload` | `(…, { backend? }) → …` | redact + dedup + send to any sink |
|
|
376
417
|
| `selectAdapters` / `listAdapters` / `resolveAdapter` | adapter selection + the harness registry |
|
|
377
418
|
| `HarnessTraceAdapter` | interface (`locate` + `parse`) | implement to add a harness |
|
|
378
|
-
| `ExternalAnalyzer` / `Redactor` | `haloAnalyzer` / `commandAnalyzer` / `commandRedactor` | drive engines/models you install
|
|
419
|
+
| `ExternalAnalyzer` / `Redactor` | `haloAnalyzer` / `hodoscopeAnalyzer` / `commandAnalyzer` / `commandRedactor` | drive engines/models you install |
|
|
379
420
|
|
|
380
421
|
```ts
|
|
381
422
|
import { watchSessions, streamSessions, analyzeSpans, AnalystRegistry, makeFinding } from '@tangle-network/traces'
|
|
@@ -409,7 +450,7 @@ Runnable, in [`examples/`](./examples):
|
|
|
409
450
|
| [`improvement-config.mjs`](./examples/improvement-config.mjs) | plug in BYO analysts for `traces stream` / `traces improve` |
|
|
410
451
|
| [`custom-backend.ts`](./examples/custom-backend.ts) | redact + dedup + upload to your own sink |
|
|
411
452
|
| [`register-harness.ts`](./examples/register-harness.ts) | add a new harness by implementing `HarnessTraceAdapter` |
|
|
412
|
-
| [`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 |
|
|
413
454
|
|
|
414
455
|
## Develop
|
|
415
456
|
|