@tangle-network/traces 0.23.1 → 1.0.0

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.
Files changed (74) hide show
  1. package/README.md +61 -1078
  2. package/dist/analyst-model-call-JVUOYZ5V.js +20 -0
  3. package/dist/ask-XLS3VANY.js +39 -0
  4. package/dist/check-YF6ZHPGG.js +322 -0
  5. package/dist/chunk-3I4PJ5Q7.js +25 -0
  6. package/dist/chunk-3T62R7ON.js +5695 -0
  7. package/dist/chunk-4VKPN432.js +138 -0
  8. package/dist/chunk-6CLC7DKP.js +492 -0
  9. package/dist/chunk-7CBV5RJ2.js +535 -0
  10. package/dist/chunk-B62DOFGI.js +273 -0
  11. package/dist/chunk-CL3OQOWX.js +407 -0
  12. package/dist/chunk-DLGAKCQJ.js +782 -0
  13. package/dist/chunk-DU534HAX.js +263 -0
  14. package/dist/chunk-GLUDGUGJ.js +232 -0
  15. package/dist/chunk-J2PM5SVN.js +503 -0
  16. package/dist/chunk-M3W6TZHQ.js +381 -0
  17. package/dist/chunk-NH7HCDLB.js +759 -0
  18. package/dist/chunk-NZ5Y7UEL.js +1217 -0
  19. package/dist/chunk-O52XK7OB.js +19 -0
  20. package/dist/chunk-PYH3PL3N.js +62 -0
  21. package/dist/chunk-RZL5GAWH.js +60 -0
  22. package/dist/chunk-TR6O4S4T.js +208 -0
  23. package/dist/chunk-TW43MR5D.js +259 -0
  24. package/dist/chunk-TYLFUX42.js +228 -0
  25. package/dist/chunk-UOLRCQHC.js +120 -0
  26. package/dist/chunk-UVE5ANVV.js +3921 -0
  27. package/dist/chunk-V2OCGX57.js +53 -0
  28. package/dist/cli.js +2086 -2050
  29. package/dist/diff-ZZ6KYBPP.js +16 -0
  30. package/dist/improvement-OJQ6365E.js +25 -0
  31. package/dist/index.d.ts +1235 -4357
  32. package/dist/index.js +53 -1204
  33. package/dist/live-Y64AJ6MA.js +14 -0
  34. package/dist/mcp-ZPGTJQYQ.js +85 -0
  35. package/dist/report-JAMXRTCW.js +338 -0
  36. package/dist/run-watch-PLWTIRSV.js +649 -0
  37. package/dist/supervisor-report-RMPLLBGZ.js +29 -0
  38. package/dist/supervisor-run-context-WO6VOTGV.js +30 -0
  39. package/dist/upload-R6NMKSGQ.js +20 -0
  40. package/dist/verify-safe-C5ZXZOZ2.js +8 -0
  41. package/docs/analyze.md +76 -0
  42. package/docs/ask.md +88 -0
  43. package/docs/bundle.md +40 -0
  44. package/docs/check.md +77 -0
  45. package/docs/convert.md +44 -0
  46. package/docs/develop.md +32 -0
  47. package/docs/diff.md +38 -0
  48. package/docs/facts.md +114 -0
  49. package/docs/mcp.md +36 -0
  50. package/docs/migrate-1.0.md +33 -0
  51. package/docs/parsers.md +66 -0
  52. package/docs/release-1.0.0.md +147 -0
  53. package/docs/sdk.md +77 -0
  54. package/docs/select.md +70 -0
  55. package/docs/skills.md +46 -0
  56. package/docs/upload.md +47 -0
  57. package/docs/watch-jsonl.v1.example.jsonl +5 -0
  58. package/docs/watch.md +66 -0
  59. package/examples/README.md +9 -0
  60. package/examples/custom-analyst.ts +65 -74
  61. package/install.sh +22 -2
  62. package/package.json +8 -7
  63. package/skills/inspect-agent-traces/SKILL.md +47 -110
  64. package/dist/chunk-7DVZCCZI.js +0 -20983
  65. package/docs/replay-verify.md +0 -123
  66. package/docs/stream-findings.svg +0 -39
  67. package/docs/trace-analysts.md +0 -643
  68. package/examples/custom-backend.ts +0 -21
  69. package/examples/external-engines.ts +0 -62
  70. package/examples/improvement-config.mjs +0 -63
  71. package/examples/observe-and-alert.ts +0 -19
  72. package/examples/register-harness.ts +0 -26
  73. package/skills/build-trace-analyst/SKILL.md +0 -76
  74. package/skills/build-trace-analyst/agents/openai.yaml +0 -4
@@ -1,123 +0,0 @@
1
- # replay-verify — executed proofs for trajectory findings
2
-
3
- An analyst finding today is a cited claim: "step 37 is where the run went wrong."
4
- `traces replay-verify` upgrades that claim to an executed proof: it replays the trajectory prefix inside a real sandbox on the trajectory's own docker image, then runs two counterfactual arms at the error-critical step k:
5
-
6
- - **Arm A** re-executes the recorded step k and checks the recorded failure reproduces — same returncode plus a stable output substring (the failure signature).
7
- - **Arm B** executes a corrected step k and checks the failure vanishes (exit 0 and the signature absent).
8
-
9
- Each arm gets a fresh sandbox with its own prefix replay, so arm B is never contaminated by arm A's side effects.
10
- Under the hood each arm is an agent-eval `runCounterfactual` meta-run (`layer='meta'`, `parentRunId` = the ingested trajectory run), with the `SandboxCounterfactualRunner` from `@tangle-network/agent-eval/trajectory-replay` supplying the `executeFrom` callback that scaffold leaves to consumers.
11
- The replay engine is agent-eval's; traces supplies only the Tangle Sandbox execution backend and the CLI (`src/replay.ts`).
12
-
13
- ## Usage
14
-
15
- ```sh
16
- traces replay-verify \
17
- --steps normalized/<traj_id>/steps.json \
18
- --image <docker_config.base_image> \
19
- --at 37 \
20
- --cwd /home \
21
- --fix-command "sed -i '145d' /home/zstd/programs/zstdcli.c && make -C /home/zstd zstd -j2 V=1" \
22
- --signature 'undeclared (first use in this function)' \
23
- --out ./replay-out \
24
- --base-url http://127.0.0.1:4097 --api-key-env SANDBOX_API_KEY
25
- ```
26
-
27
- Outputs `replay-verdict.json` (machine-readable: prefix divergences, both arms, timings, run ids) and `report.md` (human-readable with real stdout/stderr excerpts).
28
- `traces replay-verify --help` lists every flag.
29
-
30
- ## Execution semantics
31
-
32
- Every step runs the way mini-SWE ran it: a fresh `/bin/sh` subshell from a fixed workdir.
33
- The action is base64-piped into `sh` after `cd`-ing to `--cwd`, so arbitrary quoting in recorded actions survives, and the reported exit code is the action's own.
34
-
35
- Prefix divergences (recorded returncode ≠ replayed exit) are recorded per step, never abort the replay, and are surfaced in the verdict.
36
- A high divergence rate is a finding about replayability, not a failure of the tool.
37
-
38
- ## Honest limits
39
-
40
- - **Only SWE-style trajectories are replayable.** The docker image comes from the raw trajectory's `info.docker_config.base_image`; terminal-bench-style tasks that need external compose peers (databases, services) cannot be replayed with a single image.
41
- - **Commands never run as root.** The sandbox platform pins every customer command to the configured non-root subprocess identity (uid 1000 by default) — a deliberate security invariant with no override. Trajectories recorded as root (mini-SWE's default) will hit permission errors on root-owned trees. Fix by deriving a replay image that chowns the working tree to the sandbox uid:
42
-
43
- ```dockerfile
44
- FROM mswebench/facebook_m_zstd:pr-1733
45
- RUN chown -R 1000:1000 /home
46
- ```
47
-
48
- This preserves the recorded failure semantics for build/edit workflows (they depend on writability, not on uid 0). The verdict records the image actually used.
49
- - **Copy-on-write forks are firecracker-only.** `box.branch()` could replay the prefix once and fork at k; on the docker driver each arm replays the prefix in its own fresh sandbox instead. Wall-time cost is one extra prefix replay per arm.
50
- - **Environment drift shows up as divergence.** The sandbox mounts a workspace at `/home/agent` and injects platform env; recorded observations that depend on exact `ls` output or env contents can differ while returncodes still match. Only returncodes drive the divergence count.
51
- - **The failure signature is derived, not assumed.** Default: the first recorded-output line containing "error". Compiler quote glyphs vary with locale, so prefer an explicit `--signature` with an ASCII-stable substring.
52
-
53
- ## Batch mode — replayability and fix-flip rates
54
-
55
- `traces replay-verify-batch` runs the proof at corpus scale over gold-labeled CodeTraceBench corpora and measures two headline numbers nobody had before:
56
-
57
- - **Replayability rate** — fraction of replayable cases where the prefix replays with ≤10% returncode divergence AND arm A reproduces the recorded returncode at the gold step k (k = the first gold incorrect step from `incorrect_stages[].incorrect_step_ids` that is a real mid-trajectory action; see the submit-step rule below).
58
- - **Fix-flip rate** — fraction of arm-B-executed cases where a generated corrected command made the failure vanish.
59
-
60
- ```sh
61
- traces replay-verify-batch \
62
- --corpus dev-32=<labels.json>::<prepared-dir> \
63
- --corpus holdout-1=<labels.json>::<prepared-dir> \
64
- --out ./replay-batch-out \
65
- --fix generate --max-fix-cases 30 --seed 17 \
66
- --base-url http://127.0.0.1:4097 --api-key-env SANDBOX_API_KEY \
67
- --fix-api-key-env ZAI_GLM_API_KEY
68
- ```
69
-
70
- A corpus is a gold label file plus a prepared directory (`normalized/<traj_id>/steps.json` + `extracted/<traj_id>/swe_raw/**`). Replayable = the raw trajectory carries `info.docker_config.base_image` AND the labels mark ≥1 gold incorrect step that is a real mid-trajectory action. The batch:
71
-
72
- - reports the true replayable count and a per-reason exclusion table (`--enumerate-only` prints both without touching a sandbox);
73
- - **skips submit-command golds when choosing k.** A gold step whose action is the agent's end-of-run submit (`COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT`) marks a bad submit *decision*, not a failed command — there is no executable failure to reproduce, so it is never a counterfactual target. k advances to the first non-submit gold; a case whose golds are all submit steps is excluded as `gold-only-submit-step`. The report carries a per-corpus table of both counts (this matters most for split3, whose gold labels concentrate on the submit decision);
74
- - derives the working directory from the recorded run config (`info.config.environment.cwd`), falling back to `docker_config.cwd`, then to the first `pwd` observation;
75
- - builds and caches a uid-1000 derived image per (base image, cwd) pair — `ctb-replay:<hash>-uid1000` — because the sandbox platform pins commands to a non-root identity;
76
- - runs every case serially (image pulls contend on disk and registry bandwidth) and records pull/build failures as report rows, never silent skips;
77
- - uses the recorded per-step timeout (`info.config.environment.timeout`) unless `--step-timeout` overrides it.
78
-
79
- Fix generation (`--fix generate`) runs ONE chat completion per arm-A-reproduced case against an OpenAI-compatible endpoint (default: glm-5.2 on z.ai). The prompt carries the gold step's action and observation, ±3 surrounding steps, and the task statement; the reply must be a single corrected shell command. Cases beyond `--max-fix-cases` are excluded by a seeded random sample and marked `sampled-out` in the report. Arm B replays the prefix in its own fresh sandbox and executes the corrected command; `failureVanished` = exit 0 with the failure signature absent.
80
-
81
- ### Iterative fix loop (`--fix loop`)
82
-
83
- `--fix loop` (agent-eval `runFixLoop`) replaces the single shot with an execution-feedback loop of up to `--fix-attempts` attempts (default 3) per case:
84
-
85
- - Attempt 1 is byte-identical to the one-shot prompt, so the report's `fixFlipAttempt1` stays directly comparable to `--fix generate`.
86
- - When an arm fails (nonzero exit or the failure signature persists) or the model call itself fails, the next prompt carries every prior command with its REAL executed stdout/stderr (clipped tails), never a paraphrase.
87
- - Retries may answer with a short script — at most 5 commands in one fenced block — executed as ONE `/bin/sh` unit; a longer script is rejected as a failed attempt and the rejection feeds the next prompt.
88
- - Every attempt runs in its own fresh sandbox with the same replayed prefix. A used sandbox is never mutated mid-arm, so a flip always proves the corrected step against the recorded prefix state, not against debris from an earlier attempt. Wall-time cost is one extra prefix replay per attempt.
89
-
90
- The report adds `fixFlipAttempt1` (flips at attempt 1 over cases whose attempt 1 executed), `flipsByAttempt`, the full per-attempt trail on each case row (`fix.attempts`), and one `armB-attempt<N>-result.json` per executed attempt (`armB-result.json` keeps the last executed attempt — the flipped one when the loop flips).
91
-
92
- Honest-reporting notes baked into the report:
93
-
94
- - A gold step whose recorded observation carries **no returncode** can never satisfy "arm A reproduces the recorded returncode": it counts against the replayability rate and the per-case table says why.
95
- - A gold step recorded with **returncode 0** (the labeled mistake succeeded — a wrong-direction action, not a crash) reproduces trivially; for such cases `failureVanished` is vacuous, so read the headline's separate fix-flip rate on the recorded-rc≠0 subset.
96
-
97
- Outputs: `batch-report.json`, `batch-report.md` (headline + exclusion + pull-failure + per-case tables), `cases.jsonl` (incremental, crash-safe), and one directory per case with the full `replay-verify` artifacts plus `armB-result.json`.
98
-
99
- ## Analyst wire — finding in, executed proof out
100
-
101
- `replayVerifyFinding` (from `@tangle-network/agent-eval/trajectory-replay`, re-exported by this package) is the entry point the analyst product calls:
102
-
103
- ```ts
104
- import { replayVerifyFinding, sandboxReplayBackend } from '@tangle-network/traces'
105
-
106
- const { invocation, fixCommand, verdict } = await replayVerifyFinding(
107
- { trajId: 'miniswe-…-zstd-1733-786102c1', subject: 'incorrect-steps-37-37-unescaped-consequence-39' },
108
- { corpora, out: './proof', fixCaller, backendFactory: (image) => sandboxReplayBackend({ image, apiKey, baseUrl }) },
109
- )
110
- ```
111
-
112
- The subject grammar is the analyst benchmark's `incorrect-steps-<first>-<last>-<escaped|unescaped>-consequence-<step>`; `--at` is the finding's **first** incorrect step (the finding's claim, which may differ from the gold label). The wire resolves the trajectory across the given corpora, generates the arm-B fix through the same one-call generator (or accepts a pre-supplied `fixCommand`), and returns the full `ReplayVerdict`. It throws with a precise reason when the finding cannot be replayed (malformed subject, unknown trajectory, non-SWE case, step out of range) — the product surfaces that reason instead of a proof.
113
-
114
- ## Product surface — verified findings
115
-
116
- `traces verify-findings` (and `traces analyze --verify-findings`) runs this proof per recorded analyst finding and annotates each with `reproduced | fix-flipped | divergent | not-replayable` plus a receipt directory.
117
- Unlike the wire above it accepts the shapes analysts actually emit (`incorrect-step-<n>` subjects, `metadata.block_first_step`, `trace://` evidence refs) and never throws on a finding-shaped dead end — the dead end becomes the finding's honest `not-replayable` receipt.
118
- See [Verified findings](./trace-analysts.md#verified-findings-executed-replay).
119
-
120
- ## Orchestrator prerequisites
121
-
122
- replay-verify talks to a sandbox API (`--base-url`); in local development that is the sandbox SDK adapter in front of an orchestrator running the docker driver.
123
- Arbitrary docker images need the platform control runtime (node injected from a mounted Nix profile) because sidecar-less images rarely ship node: the orchestrator needs `NIX_PROFILE_PATH` set, and this CLI passes the `SIDECAR_PLATFORM_CONTROL_RUNTIME` container-env marker on create (the production sandbox API derives the same marker from `agent: false`).
@@ -1,39 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" role="img" viewBox="0 0 1100 540">
2
- <title>traces stream findings mode terminal capture</title>
3
- <desc>A terminal preview of traces stream findings mode showing session, batch, and finding JSONL rows.</desc>
4
- <rect width="1100" height="540" fill="#f6f7f9"/>
5
- <rect x="50" y="44" width="1000" height="452" rx="8" fill="#111827"/>
6
- <rect x="50" y="44" width="1000" height="42" rx="8" fill="#202938"/>
7
- <circle cx="78" cy="65" r="7" fill="#ff5f57"/>
8
- <circle cx="100" cy="65" r="7" fill="#febc2e"/>
9
- <circle cx="122" cy="65" r="7" fill="#28c840"/>
10
- <text x="550" y="70" text-anchor="middle" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="14" fill="#cbd5e1">traces stream --mode findings</text>
11
-
12
- <text x="78" y="124" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="18" fill="#8bd5ff">$ traces stream spans.openinference.jsonl --format openinference --mode findings</text>
13
-
14
- <g font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="16">
15
- <text x="78" y="174" fill="#e5e7eb">{&quot;event&quot;:&quot;session&quot;,</text>
16
- <text x="313" y="174" fill="#a7f3d0">&quot;spanCount&quot;:5,</text>
17
- <text x="458" y="174" fill="#e5e7eb">&quot;sessionId&quot;:&quot;spans.openinference.jsonl&quot;}</text>
18
-
19
- <text x="78" y="224" fill="#e5e7eb">{&quot;event&quot;:&quot;analysis_batch&quot;,</text>
20
- <text x="352" y="224" fill="#a7f3d0">&quot;findingCount&quot;:3,</text>
21
- <text x="536" y="224" fill="#fcd34d">&quot;toolCallCount&quot;:3,</text>
22
- <text x="732" y="224" fill="#fca5a5">&quot;erroredToolCallCount&quot;:3}</text>
23
-
24
- <text x="78" y="274" fill="#e5e7eb">{&quot;event&quot;:&quot;finding&quot;, &quot;finding&quot;:{</text>
25
- <text x="407" y="274" fill="#fca5a5">&quot;severity&quot;:&quot;high&quot;,</text>
26
- <text x="608" y="274" fill="#c4b5fd">&quot;ruleId&quot;:&quot;same-failing-command&quot;}}</text>
27
- <text x="102" y="304" fill="#94a3b8">action: Stop rerunning it; inspect the first failure before another retry.</text>
28
-
29
- <text x="78" y="354" fill="#e5e7eb">{&quot;event&quot;:&quot;finding&quot;, &quot;finding&quot;:{</text>
30
- <text x="407" y="354" fill="#fca5a5">&quot;severity&quot;:&quot;high&quot;,</text>
31
- <text x="608" y="354" fill="#c4b5fd">&quot;ruleId&quot;:&quot;verification-without-change&quot;}}</text>
32
- <text x="102" y="384" fill="#94a3b8">evidence: 3 verification calls since the last detected code/config change.</text>
33
-
34
- <text x="78" y="434" fill="#e5e7eb">{&quot;event&quot;:&quot;finding&quot;, &quot;finding&quot;:{</text>
35
- <text x="407" y="434" fill="#fcd34d">&quot;severity&quot;:&quot;medium&quot;,</text>
36
- <text x="627" y="434" fill="#c4b5fd">&quot;ruleId&quot;:&quot;completion-claim-without-verification&quot;}}</text>
37
- <text x="102" y="464" fill="#94a3b8">check: a later test/build/typecheck/lint/smoke command should appear.</text>
38
- </g>
39
- </svg>