@tangle-network/traces 0.1.0 → 0.2.1

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 CHANGED
@@ -1,28 +1,44 @@
1
1
  # traces
2
2
 
3
- Point it at your coding-agent session traces and get **failure-mode + efficiency findings** — without instrumenting anything. It reads the logs your harness already writes to disk.
3
+ Analyze your coding-agent session logs for failure modes — stuck loops, token bloat, dropped self-verification — with zero instrumentation. It reads the logs your harness (Claude Code, Codex, OpenCode, …) already writes to disk.
4
4
 
5
- Built for the recurring problem: agents loop, re-send their whole history, stop verifying their own work, and get stuck. `traces` surfaces that from the trace, deterministically.
5
+ `traces` is a CLI and an SDK: run it ad-hoc, or build on it.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm i -g @tangle-network/traces # the `traces` CLI
11
+ npx @tangle-network/traces analyze # or run without installing
12
+ npm i @tangle-network/traces # or use it as a library
13
+ ```
14
+
15
+ ## Quick start
6
16
 
7
17
  ```bash
8
- npx @tangle-network/traces analyze --harness claude-code --last 1
18
+ traces analyze --harness claude-code --last 1
9
19
  ```
10
20
 
11
- ## What it does
21
+ ```
22
+ # Trace report — claude-code · 1 session · 2,429 spans
23
+
24
+ ## Stuck loops
25
+ - `bash` ×7 with identical args in 48s (same git status retried, no state change)
26
+
27
+ ## Tool use
28
+ - 1,204 tool calls · duplicate-call 22% · retry 6% · error 8%
29
+ ```
12
30
 
13
- 1. Reads a harness's native session log (no OpenTelemetry setup required).
14
- 2. Normalizes it to OTLP-JSONL — the shape the [`@tangle-network/agent-eval`](https://www.npmjs.com/package/@tangle-network/agent-eval) analyst suite *and* [HALO](https://github.com/context-labs/halo) consume.
15
- 3. Runs the analysts and writes a markdown report.
31
+ The deterministic pass (stuck loops, token growth, tool monoculture, missing self-verification) needs no API key and costs nothing. Add `--llm` for the agentic analysts (failure-mode / knowledge-gap / knowledge-poisoning / improvement); they call OpenAI and respect `--budget`.
16
32
 
17
- The deterministic pass (token-growth, output-decay, tool-monoculture, missing self-verification) needs **no API key and costs nothing**. Add `--llm` for the agentic RLM analysts (failure-mode / knowledge-gap / knowledge-poisoning / improvement).
33
+ The written OTLP-JSONL artifact also feeds [HALO](https://github.com/context-labs/halo) (`halo spans.jsonl -p "diagnose"`) — analysis is never locked to one engine.
18
34
 
19
35
  ## Supported harnesses
20
36
 
21
- Covers the coding-agent CLIs in the agent-dev-container nix profile. "Verified" = parser exercised against real on-disk sessions; "fixture" = parser exercised against a schema-accurate fixture (no local sessions to test); see the test suite.
37
+ "Verified" = tested against real sessions; "fixture" = tested against schema-accurate fixtures (no real sessions available).
22
38
 
23
39
  | Harness (aliases) | Reads from | Status |
24
40
  |---|---|---|
25
- | `claude-code` (`claudish`, `openclaw`, `nanoclaw`) | `~/.claude/projects/<cwd>/*.jsonl` (+ subagent sidechains) | verified |
41
+ | `claude-code` (`claude`, `claudish`, `openclaw`, `nanoclaw`) | `~/.claude/projects/<cwd>/*.jsonl` (+ subagent sidechains) | verified |
26
42
  | `codex` (`codex-acp`) | `~/.codex/sessions/**/rollout-*.jsonl` | verified |
27
43
  | `opencode` | `~/.local/share/opencode/storage/` | verified |
28
44
  | `gemini` (`gemini-cli`) | `~/.gemini/tmp/<hash>/chats/session-*.json` | verified |
@@ -31,36 +47,68 @@ Covers the coding-agent CLIs in the agent-dev-container nix profile. "Verified"
31
47
  | `qwen` (`qwen-code`) | `~/.qwen/projects/<cwd>/chats/*.jsonl` | fixture |
32
48
  | `amp` | `~/.local/share/amp/threads/T-*.json` | fixture |
33
49
  | `github-copilot` (`copilot`) | `~/.copilot/session-state/<id>/events.jsonl` | fixture |
34
- | `forge` (`forgecode`) | `/dump` JSON exports (live `~/.forge/.forge.db` SQLite is a follow-up) | fixture |
50
+ | `forge` (`forgecode`) | `/dump` JSON exports | fixture |
35
51
 
36
- Notes: Factory's token totals live in the `.settings.json` sidecar (no per-turn usage). Forge's primary store is SQLite; v1 reads its dependency-free `/dump` exports. ACP-only bridges (`claude-agent-acp`) may not persist a local transcript at all.
37
-
38
- Adding a harness is one file implementing `HarnessTraceAdapter` (`locate` + `parse`) in `src/adapters/`.
52
+ Factory stores token totals in `.settings.json`, not per turn. Forge reads `/dump` JSON exports (live SQLite is a follow-up). ACP-only bridges may not persist a local transcript.
39
53
 
40
54
  ## Commands
41
55
 
42
56
  ```bash
43
- traces list --harness claude-code --last 20 # discover sessions
44
- traces analyze --harness codex --last 1 # $0 deterministic report
57
+ traces list --harness claude-code --last 20 # discover sessions
58
+ traces analyze --harness codex --last 1 # $0 deterministic report
45
59
  traces analyze --all --since 2026-06-18 --out report.md
46
- traces convert --harness claude-code --last 1 --otlp spans.jsonl # OTLP only → HALO
47
- traces analyze --harness claude-code --last 1 --llm # +agentic (needs OPENAI_API_KEY)
60
+ traces convert --harness claude-code --last 1 --otlp spans.jsonl # OTLP only
61
+ traces watch --all # live observer; notify on stuck loops
62
+ traces upload --since 1h --dry-run # redact + dedup + preview, no network
63
+ traces upload --since 24h # upload last day to the Intelligence Platform
48
64
  ```
49
65
 
50
- ### Options
51
-
52
66
  | Flag | Meaning |
53
67
  |---|---|
54
68
  | `--harness <id>` | Harness or alias (default: `claude-code`) |
55
- | `--all` | Sweep every known harness |
69
+ | `--all` | Every known harness |
56
70
  | `--last <n>` | Most-recent N sessions |
57
- | `--session <path>` | Analyze one explicit session file |
58
- | `--cwd <dir>` | Filter sessions by working directory |
59
- | `--since <iso>` | Only sessions modified since this time |
60
- | `--out <path>` | Write report to a file |
61
- | `--otlp <path>` | OTLP artifact path |
62
- | `--llm` | Enable agentic RLM analysts (needs `OPENAI_API_KEY`) |
63
- | `--budget <usd>` | USD cap for agentic analysts |
71
+ | `--session <path>` | One explicit session file |
72
+ | `--cwd <dir>` | Filter by working directory |
73
+ | `--since <t>` | `upload`: window — `30m`/`2h`/`7d` or ISO (default 24h); `analyze`: ISO cutoff |
74
+ | `--out <path>` | Write the report to a file |
75
+ | `--otlp <path>` | OTLP artifact path (also the dry-run upload preview) |
76
+ | `--llm` / `--budget <usd>` | Enable agentic analysts (needs `OPENAI_API_KEY`) / cap their spend |
77
+ | `--interval <s>` / `--window <m>` | `watch`: poll seconds (default 5) / active-session window minutes (default 30) |
78
+ | `--min-loop <n>` | Identical repeated calls before flagging a loop (default 3) |
79
+ | `--dry-run` / `--yes` | `upload`: preview without sending / skip the confirm prompt |
80
+
81
+ `upload` redacts PII/secrets locally before anything leaves the machine, dedups against already-uploaded sessions, and tags each with metadata (harness, cwd, git branch, host). It needs `TANGLE_INGEST_URL` (or `TANGLE_ORCHESTRATOR_URL`), `TANGLE_INGEST_API_KEY` (or `TANGLE_API_KEY`), and `TANGLE_TENANT_ID`; without them, `--dry-run` still works.
82
+
83
+ ## Use as a library
84
+
85
+ The CLI is a thin consumer of these exports. Full runnable examples in [`examples/`](./examples).
86
+
87
+ | Export | Signature | Use |
88
+ |---|---|---|
89
+ | `analyzeSpans` | `(spans, { registry?, ai?, budgetUsd? }) → AnalyzeResult` | run analysts — built-in, or **your own** via `registry` |
90
+ | `watchSessions` | `(ObserverOptions) → Promise<void>` | live observer; `onLoop` / `onReport` / `signal` / `adapters` |
91
+ | `collectSessions` | `(CollectOptions) → SessionBatch[]` | redacted per-session batches for your own pipeline |
92
+ | `redactSpans` | `(spans, rules?) → { spans, report }` | PII/secret redaction (`TRACES_REDACTION_RULES`) |
93
+ | `planUpload` / `executeUpload` | `(…, { backend? }) → …` | redact + dedup + send to any sink |
94
+ | `listAdapters` / `resolveAdapter` | `() → […]` / `(id) → adapter` | the harness registry |
95
+ | `HarnessTraceAdapter` | interface (`locate` + `parse`) | implement to add a harness |
96
+
97
+ ```ts
98
+ import { watchSessions, analyzeSpans, AnalystRegistry, makeFinding } from '@tangle-network/traces'
99
+
100
+ // Observe live sessions, feed findings anywhere (read-only, cancellable):
101
+ const c = new AbortController()
102
+ await watchSessions({ all: true, signal: c.signal, onLoop: (l) => alert(l.toolName, l.occurrences) })
103
+
104
+ // Run your own analyst instead of the built-ins:
105
+ const registry = new AnalystRegistry()
106
+ registry.register({ id: 'mine', description: '…', inputKind: 'trace-store', cost: { kind: 'deterministic' }, version: '1.0.0',
107
+ async analyze() { return [makeFinding({ analyst_id: 'mine', area: 'custom', claim: '…', severity: 'info', evidence_refs: [], confidence: 0.9 })] } })
108
+ await analyzeSpans(spans, { registry })
109
+ ```
110
+
111
+ Add a new harness: implement `HarnessTraceAdapter` and pass it via `adapters: [...]` to `watchSessions`/`collectSessions`, or drop a file in `src/adapters/`. See [`examples/register-harness.ts`](./examples/register-harness.ts).
64
112
 
65
113
  ## Develop
66
114
 
@@ -69,5 +117,5 @@ pnpm install
69
117
  pnpm dev analyze --harness claude-code --last 1 # run from source via tsx
70
118
  pnpm test
71
119
  pnpm typecheck
72
- pnpm build # → dist/cli.js (the published bin)
120
+ pnpm build # → dist/index.js (SDK) + dist/cli.js (bin) + .d.ts
73
121
  ```