traceyard 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +234 -2
- package/lib/cli/bin/traceyard.mjs +4 -0
- package/lib/cli/package.json +5 -0
- package/lib/cli/src/compact.mjs +73 -0
- package/lib/cli/src/errors.mjs +9 -0
- package/lib/cli/src/evidence.mjs +235 -0
- package/lib/cli/src/git.mjs +249 -0
- package/lib/cli/src/github.mjs +139 -0
- package/lib/cli/src/main.mjs +915 -0
- package/lib/cli/src/mcp.mjs +317 -0
- package/lib/cli/src/receipt.mjs +172 -0
- package/lib/cli/src/run.mjs +461 -0
- package/lib/cli/src/verdicts.mjs +254 -0
- package/lib/cli/src/version.mjs +5 -0
- package/lib/core/src/agent-result.mjs +185 -0
- package/lib/core/src/ci-link.mjs +130 -0
- package/lib/core/src/discovery.mjs +105 -0
- package/lib/core/src/evidence.mjs +118 -0
- package/lib/core/src/failure-summary.mjs +39 -0
- package/lib/core/src/index.mjs +70 -0
- package/lib/core/src/package-manager.mjs +97 -0
- package/lib/core/src/pytest-runner.py +68 -0
- package/lib/core/src/pytest.mjs +118 -0
- package/lib/core/src/repository-index.mjs +310 -0
- package/lib/core/src/runners.mjs +103 -0
- package/lib/core/src/source-flow.mjs +135 -0
- package/lib/core/src/test-evidence.mjs +326 -0
- package/lib/core/src/test-inputs.mjs +97 -0
- package/lib/core/src/test-report.mjs +64 -0
- package/lib/core/src/worktree.mjs +95 -0
- package/package.json +45 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Praise Omosanya Oluwafisayo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,235 @@
|
|
|
1
|
-
#
|
|
1
|
+
# TraceYard CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Prove a failing test is fixed on your own machine. No TraceYard account or server is required. Test execution is local; dependency installation, optional Git fetching, and the initial package bootstrap can use the network when requested.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
traceyard repro src/cart.test.ts --at 3f2c9e1 # fails at the commit CI tested
|
|
7
|
+
traceyard check # run it against your edits, as often as you like
|
|
8
|
+
git commit -am "Fix cart rounding"
|
|
9
|
+
traceyard verify # failed before, passes now, test untouched
|
|
10
|
+
traceyard guard # rerun the test; exit 0 if still fixed at HEAD
|
|
11
|
+
traceyard receipt # Markdown you can paste into the PR
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Coding agents get the same commands as MCP tools with `traceyard mcp`. See [Coding agents](#coding-agents-mcp).
|
|
15
|
+
|
|
16
|
+
Released use is `npx traceyard@0.1.0` (or `npx traceyard` when you intentionally want the current latest). From a checkout, after `npm ci` and with Node.js 22.12.0 or newer, use `node packages/cli/bin/traceyard.mjs` for development.
|
|
17
|
+
|
|
18
|
+
## Commands
|
|
19
|
+
|
|
20
|
+
### `traceyard repro [test] [--at <sha> | --from <actions-url>]`
|
|
21
|
+
|
|
22
|
+
Runs the test at an exact commit in a throwaway `git worktree`. Your working tree, index and stash are never touched. `--at` defaults to `HEAD`.
|
|
23
|
+
|
|
24
|
+
`--from` takes a GitHub Actions run or job link. Traceyard reads the job log, finds the commit `actions/checkout` checked out, and picks the failing test file if the log names exactly one. It uses `GITHUB_TOKEN` or `GH_TOKEN` if set, then an authenticated `gh` CLI. Public repositories work without either. If the tested commit isn't in your clone (for example a pull request merge commit), add `--fetch`.
|
|
25
|
+
|
|
26
|
+
Traceyard remembers the test and commit, so `check` and `verify` can run without arguments afterwards.
|
|
27
|
+
|
|
28
|
+
With `--from`, test paths in a job log are relative to the folder the runner started in. Traceyard looks for the file at the tested commit, so `tests/test_cart.py` can resolve to `services/api/tests/test_cart.py`. If more than one file could be meant, or a failing file can't be found, it stops and asks you for the path.
|
|
29
|
+
|
|
30
|
+
### `traceyard check [test]`
|
|
31
|
+
|
|
32
|
+
Runs the test in your working tree, including uncommitted edits. This is the fast loop for each attempt at a fix. It never writes a receipt, because uncommitted code can't be pinned to a commit.
|
|
33
|
+
|
|
34
|
+
### `traceyard verify [test] [--before <sha>] [--after <sha>]`
|
|
35
|
+
|
|
36
|
+
Runs the test at the failing commit (`--before`, default: the last reproduced commit) and at the fix commit (`--after`, default `HEAD`). It compares the files changed between them. The verdict is `FIXED` only when all of these are true:
|
|
37
|
+
|
|
38
|
+
1. The test failed at `--before`.
|
|
39
|
+
2. The same test file passed at `--after`, with at least one passing test and no extra skips.
|
|
40
|
+
3. No tests, fixtures, snapshots, mocks, setup files or test runner config changed between the two commits. A change to the test script, the `jest` key in `package.json`, or a config file the script names counts as a runner config change. See [execution trust](https://github.com/fysaio/traceyard/blob/main/docs/EXECUTION_TRUST.md#test-inputs).
|
|
41
|
+
|
|
42
|
+
Each verify writes a receipt to `.traceyard/receipts/` as JSON and Markdown.
|
|
43
|
+
|
|
44
|
+
### `traceyard guard [receipt] [--before <sha>]`
|
|
45
|
+
|
|
46
|
+
A check for scripts, hooks and agents. It takes the newest receipt (or the one you name), and if that receipt is intact, says `FIXED` and its fix commit is exactly `HEAD`, it runs the verification again: the receipt's test at its failing commit and at `HEAD`, ignoring cached results, followed by the same rules `verify` uses. It passes (`FIXED`, exit 0) only when that fresh run is `FIXED`. The receipt is never proof by itself, because anyone who can edit the file can also recompute its digest. A guard therefore takes about as long as a `verify`.
|
|
47
|
+
|
|
48
|
+
If there is no receipt, commits were added after it, or the rerun does not fix the test, the verdict is `UNVERIFIED` (exit 1). An edited receipt, a `NEEDS_REVIEW` receipt or changed test inputs give `NEEDS_REVIEW` (exit 2). A test that cannot run gives `BLOCKED` (exit 3). Uncommitted changes add a warning, because only `HEAD` is checked.
|
|
49
|
+
|
|
50
|
+
The receipt's failing commit must be on `HEAD`'s first-parent line (the branch's own commits), otherwise the answer is `NEEDS_REVIEW`. That happens after a rebase, when the failing commit arrived through a merge, or when the failure was reproduced on a pull request merge commit. Check which commit really failed and pass it as `--before <sha>`, which replaces the receipt's value. The MCP `guard` tool has no such override.
|
|
51
|
+
|
|
52
|
+
A pass covers one test. It says nothing about the rest of the suite or whether the change is safe to merge. The receipt still chooses the test and, without `--before`, which earlier commit counts as failing. Someone who can write commits can break the code in one and restore it in the next, or arrange the history so a made-up commit sits on that line, so test changes made before the failing commit are not seen. A reviewer should check both, and a hook that knows the failing commit should pass `--before`. The rerun happens on your machine, with your installed packages and tools, so it is not protection against someone who controls that environment. Use CI for that.
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# .git/hooks/pre-push
|
|
56
|
+
traceyard guard || exit 1
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### `traceyard explain [evidence] [--failure <n>]`
|
|
60
|
+
|
|
61
|
+
Explains one failure from a recorded run. The default is the last failing run's first failure. You get the failure message with terminal codes and dependency stack frames removed, the `file:line` it points to, and 13 lines of source around that line at the run's commit, so an agent doesn't have to open the file.
|
|
62
|
+
|
|
63
|
+
### `traceyard inspect [evidence] [--offset <n>] [--limit <n>]`
|
|
64
|
+
|
|
65
|
+
Without an ID, `inspect` lists the 8 most recent runs and the 5 most recent receipts. With an evidence ID, it returns one slice of that run's full test log, 3,000 characters by default and at most 4,000. Follow `evidence.nextOffset` to read the next slice. With a receipt ID, it behaves like `receipt`.
|
|
66
|
+
|
|
67
|
+
### `traceyard receipt [id]`
|
|
68
|
+
|
|
69
|
+
Prints the newest receipt (or the one with that id) as Markdown. With `--json`, it returns the receipt body. Each receipt carries a SHA-256 digest of its contents. If the file was edited, `receipt` reports `intact: false` and the verdict `INCONCLUSIVE`.
|
|
70
|
+
|
|
71
|
+
Receipts have trust level `local`: they record what ran on this machine. Signed CI receipts come with the GitHub Action in Phase 3.
|
|
72
|
+
|
|
73
|
+
## Options
|
|
74
|
+
|
|
75
|
+
| Option | Effect |
|
|
76
|
+
| ----------------- | ------------------------------------------------------------------------ |
|
|
77
|
+
| `--case <name>` | Pytest case to run, such as `TestCart::test_total`. |
|
|
78
|
+
| `--json` | Print exactly one JSON object on stdout. Progress messages are silenced. |
|
|
79
|
+
| `--log` | Include the last 4,000 characters of test output. |
|
|
80
|
+
| `--fetch` | Let git fetch a commit that isn't in this clone. |
|
|
81
|
+
| `--install` | `check` only: install missing dependencies in your working tree. |
|
|
82
|
+
| `--fresh` | Ignore the cached result for the same commit and test. |
|
|
83
|
+
| `--timeout <sec>` | Time limit for one test run. Default 180. |
|
|
84
|
+
| `--repo <dir>` | Repository to use. Default: the current directory. |
|
|
85
|
+
| `--failure <n>` | `explain` only: which failure to explain. Default 1. |
|
|
86
|
+
| `--offset <n>` | `inspect` only: where the log slice starts. Default 0. |
|
|
87
|
+
| `--limit <n>` | `inspect` only: slice length in characters, 200 to 4,000. Default 3,000. |
|
|
88
|
+
|
|
89
|
+
## Exit codes
|
|
90
|
+
|
|
91
|
+
| Code | Verdicts | Meaning |
|
|
92
|
+
| ---- | ------------------------------------------------ | ------------------------------------------ |
|
|
93
|
+
| 0 | `REPRODUCED`, `PASSED`, `FIXED`, `AVAILABLE` | The command got the answer it was for. |
|
|
94
|
+
| 1 | `FAILING`, `STILL_FAILING`, `UNVERIFIED` | The test fails, or the fix isn't proven. |
|
|
95
|
+
| 2 | `NOT_REPRODUCED`, `NEEDS_REVIEW`, `INCONCLUSIVE` | A person needs to look before trusting it. |
|
|
96
|
+
| 3 | `BLOCKED` | The test could not run here. |
|
|
97
|
+
| 64 | `ERROR` | The command line was wrong. |
|
|
98
|
+
| 70 | | A bug in Traceyard. Please report it. |
|
|
99
|
+
|
|
100
|
+
## JSON output
|
|
101
|
+
|
|
102
|
+
With `--json`, every supported command prints exactly one JSON object on stdout; without it, commands print human-readable output. Progress is sent to stderr or suppressed as appropriate in JSON mode. The schema is `cliResultSchema` in [`shared/contracts/cli.ts`](https://github.com/fysaio/traceyard/blob/main/docs/../shared/contracts/cli.ts), and contract tests check every command against it. Fields are only added within `schemaVersion: 1`.
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
traceyard verify --json
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"schemaVersion": 1,
|
|
111
|
+
"command": "verify",
|
|
112
|
+
"verdict": "FIXED",
|
|
113
|
+
"exitCode": 0,
|
|
114
|
+
"summary": "src/sum.test.js failed at c2b9e3e081cb and passes at 48c7902bf4c5, with no test files changed.",
|
|
115
|
+
"next": "Open a pull request and attach the receipt.",
|
|
116
|
+
"test": { "path": "src/sum.test.js", "case": null },
|
|
117
|
+
"runs": [
|
|
118
|
+
{
|
|
119
|
+
"role": "baseline",
|
|
120
|
+
"commit": "c2b9e3e081cb88e2a02f39960433d6b625abf56c",
|
|
121
|
+
"workingTree": false,
|
|
122
|
+
"status": "FAILED",
|
|
123
|
+
"counts": { "passed": 1, "failed": 1, "skipped": 0 },
|
|
124
|
+
"failures": [
|
|
125
|
+
{
|
|
126
|
+
"file": "src/sum.test.js",
|
|
127
|
+
"name": "adds numbers",
|
|
128
|
+
"message": "AssertionError: expected -1 to be 3 // Object.is equality\n at src/sum.test.js:3:44"
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
"truncated": false,
|
|
132
|
+
"durationMs": 737,
|
|
133
|
+
"cached": true,
|
|
134
|
+
"dependencies": "linked",
|
|
135
|
+
"evidenceId": "ev_c2b9e3e081cb_3fd09b30eb84",
|
|
136
|
+
"message": "1 passed, 1 failed, 0 skipped."
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"role": "candidate",
|
|
140
|
+
"commit": "48c7902bf4c59e0320d0749bcf4553a9bd1c9327",
|
|
141
|
+
"status": "SUCCEEDED",
|
|
142
|
+
"...": "..."
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
"changedTests": [],
|
|
146
|
+
"receipt": {
|
|
147
|
+
"id": "rcpt_20261120084918982_d3a80a",
|
|
148
|
+
"path": ".traceyard/receipts/rcpt_20261120084918982_d3a80a.json",
|
|
149
|
+
"markdownPath": ".traceyard/receipts/rcpt_20261120084918982_d3a80a.md"
|
|
150
|
+
},
|
|
151
|
+
"warnings": []
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
- `next` is one sentence telling a person or agent what to do next.
|
|
156
|
+
- Output is bounded for agents: up to 5 failures, 600 characters each, with stack frames from `node_modules` removed. Raw output only appears with `--log`. A full result stays well under 1,500 tokens.
|
|
157
|
+
- Every run that executed has an `evidenceId`. The full log stays on disk; read it with `inspect <evidenceId>` in bounded slices. Terminal colours, progress bars, repeated lines and absolute paths are removed first.
|
|
158
|
+
- `repro`, `check` and `verify` also return `evidenceEnvelope`, the versioned evidence contract in [`shared/contracts/evidence.ts`](https://github.com/fysaio/traceyard/blob/main/docs/../shared/contracts/evidence.ts). It keeps the execution `state` (`COMPLETED`, `FAILED`, `BLOCKED`, `STALE`, ...) separate from the `claim` made about it (`FOCUSED_PASS`, `FAILED`, `INCONCLUSIVE`, ...), and records the exact revision (`commit`, or a `worktreeFingerprint` for `check`), input, policy and environment fingerprints, one entry per rule in `checks`, the `limitations`, and `next`. The claim is always derived from the state and checks, never set by hand.
|
|
159
|
+
- CLI evidence is always `source: "LOCAL_PROVISIONAL"` and `scope: "FOCUSED"`: one selected test on this machine. `FOCUSED_PASS` is not proof that the whole suite passes or that a change is safe to merge.
|
|
160
|
+
- `verify` reaches `FOCUSED_PASS` only for a `FIXED` verdict. Its checks are `reproduces-before`, `passes-after`, `distinct-commits`, `no-new-skips` and `test-inputs-unchanged`, so an `INCONCLUSIVE` claim names the rule that failed.
|
|
161
|
+
- `check` fingerprints the working tree before and after the run. If a tracked file, or an untracked file that existed before, changes while the test runs, the state is `STALE`, the claim is `INCONCLUSIVE` and the verdict is `INCONCLUSIVE` (exit code 2). New untracked files, such as caches a test runner writes, don't count.
|
|
162
|
+
- Receipts store the envelope inside their digest, which catches accidental edits but is not a signature. `guard` reruns the test and also treats a `FIXED` receipt whose envelope doesn't claim `FOCUSED_PASS` for the same fix commit as `NEEDS_REVIEW`. Receipts written before the envelope existed are still accepted.
|
|
163
|
+
- `dependencies` says how packages were made available:
|
|
164
|
+
- `existing`: already installed.
|
|
165
|
+
- `linked`: the commit has the same lockfile as your clone, so your `node_modules` was linked in.
|
|
166
|
+
- `cached`: a previous run installed this exact lockfile, and that copy was reused.
|
|
167
|
+
- `installed`: installed with lifecycle scripts off. For single-package projects the install goes into the dependency cache, so the next commit with the same lockfile reuses it.
|
|
168
|
+
- `none`: the project needs no packages.
|
|
169
|
+
|
|
170
|
+
## Where things are stored
|
|
171
|
+
|
|
172
|
+
Everything lives in `.traceyard/` at the repository root. That folder contains its own `.gitignore`, so it never shows up in `git status`.
|
|
173
|
+
|
|
174
|
+
- `runs/`: one file per run, named by evidence ID. A commit's result never changes, so `repro` and `verify` reuse it; `--fresh` reruns. Working-tree runs from `check` are kept too (the newest 20), so `explain` and `inspect` can read them.
|
|
175
|
+
- `receipts/`: verification receipts.
|
|
176
|
+
- `last-repro.json`: the test and commit that `check` and `verify` default to.
|
|
177
|
+
- `last-evidence.json`: the run `explain` defaults to: the last failing one.
|
|
178
|
+
|
|
179
|
+
Installed dependencies are cached per user, outside the repository: `~/.cache/traceyard` on Linux, `~/Library/Caches/traceyard` on macOS and `%LOCALAPPDATA%\traceyard\Cache` on Windows. Set `TRACEYARD_CACHE_DIR` to move it. The 5 most recently used dependency sets are kept. Workspaces and `file:` or `link:` dependencies install inside the throwaway checkout instead, because they need the rest of the repository.
|
|
180
|
+
|
|
181
|
+
## Supported projects
|
|
182
|
+
|
|
183
|
+
- **Vitest and Jest** through a `test` (or `test:<folder>`) script in the nearest `package.json`. npm, pnpm, Yarn and Bun are detected from `packageManager` or the lockfile, including monorepos.
|
|
184
|
+
- **Pytest** files named `test_*.py` or `*_test.py`, with a `requirements.txt` or `requirements-test.txt` beside them. Traceyard uses `TRACEYARD_PYTHON`, then an active virtualenv, then `.venv` or `venv` in the repository, then `python3` on `PATH`. The interpreter needs pytest installed.
|
|
185
|
+
|
|
186
|
+
## Coding agents (MCP)
|
|
187
|
+
|
|
188
|
+
`traceyard mcp` serves six local tools over stdio to any MCP client. They run on your machine with no account. Hosted MCP is a different server with three tools (`investigate`, `inspect`, and `verify`) and requires OAuth plus project authorization; see [Connect a coding agent](https://github.com/fysaio/traceyard/blob/main/docs/MCP.md). The local tools return a bounded result envelope; they are not interchangeable with the hosted tool schemas.
|
|
189
|
+
|
|
190
|
+
| Tool | Same as | Use |
|
|
191
|
+
| ----------- | ------------------- | --------------------------------------------------------------------------------------- |
|
|
192
|
+
| `reproduce` | `traceyard repro` | Rerun the failing test at the exact commit, or at the commit a GitHub Actions job used. |
|
|
193
|
+
| `check` | `traceyard check` | Run it against the working tree after each fix attempt. |
|
|
194
|
+
| `verify` | `traceyard verify` | Prove the committed fix and write a receipt. |
|
|
195
|
+
| `guard` | `traceyard guard` | Before claiming "fixed": reruns the receipt's test; `FIXED` covers that test only. |
|
|
196
|
+
| `explain` | `traceyard explain` | The first failure, the line it points to, and the source around it. |
|
|
197
|
+
| `inspect` | `traceyard inspect` | Recent runs and receipts, a run's full log in slices, or a receipt's Markdown. |
|
|
198
|
+
|
|
199
|
+
Each tool takes an optional `repo` (absolute path). It defaults to the directory the server started in, or to `--repo`.
|
|
200
|
+
|
|
201
|
+
**Claude Code**
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
claude mcp add traceyard -- npx -y traceyard mcp
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Cursor** (`.cursor/mcp.json`) and other clients that use `mcpServers`:
|
|
208
|
+
|
|
209
|
+
```json
|
|
210
|
+
{ "mcpServers": { "traceyard": { "command": "npx", "args": ["-y", "traceyard", "mcp"] } } }
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**VS Code with GitHub Copilot** (`.vscode/mcp.json`):
|
|
214
|
+
|
|
215
|
+
```json
|
|
216
|
+
{
|
|
217
|
+
"servers": {
|
|
218
|
+
"traceyard": { "type": "stdio", "command": "npx", "args": ["-y", "traceyard", "mcp"] }
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
**Codex** (`~/.codex/config.toml`):
|
|
224
|
+
|
|
225
|
+
```toml
|
|
226
|
+
[mcp_servers.traceyard]
|
|
227
|
+
command = "npx"
|
|
228
|
+
args = ["-y", "traceyard", "mcp"]
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
For checkout development, replace `npx -y traceyard` with `node /path/to/traceyard/packages/cli/bin/traceyard.mjs` after running `npm ci` with Node.js 22.12.0 or newer.
|
|
232
|
+
|
|
233
|
+
### Token budget
|
|
234
|
+
|
|
235
|
+
Every tool response is under 1,500 tokens. The tests check this on each call, and `node scripts/bench-cli.mjs` records it in [`docs/benchmarks/cli-agent.json`](https://github.com/fysaio/traceyard/blob/main/docs/benchmarks/cli-agent.json). On the benchmark repository (10 Vitest cases, 7 failing), the full loop costs about 2,400 tokens across eight calls: reproduce, reproduce again, explain, two inspects, check, verify and guard. The largest are `verify` and `guard`, at about 450 tokens each, because `guard` reruns both commits. A repeated `reproduce` at the same commit returns in about 70 ms from the cache.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Output shaping for people and agents. Everything an agent reads passes
|
|
2
|
+
// through here, so it stays small and free of terminal noise.
|
|
3
|
+
|
|
4
|
+
// CSI sequences (colours, cursor moves) and OSC sequences (hyperlinks, titles).
|
|
5
|
+
/* eslint-disable no-control-regex */
|
|
6
|
+
const ANSI =
|
|
7
|
+
/\u001b\[[0-?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b[@-Z\\-_]/g;
|
|
8
|
+
/* eslint-enable no-control-regex */
|
|
9
|
+
const WORKTREE = /(?:file:\/\/)?[^\s'"()]*traceyard-worktree-[^/\\]+[/\\]checkout[/\\]/g;
|
|
10
|
+
|
|
11
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
12
|
+
|
|
13
|
+
/** Make paths repository-relative: throwaway checkouts and, when given, the clone itself. */
|
|
14
|
+
export function relativePaths(text, root) {
|
|
15
|
+
let out = text.replace(WORKTREE, "");
|
|
16
|
+
if (root) {
|
|
17
|
+
const forward = root.split("\\").join("/");
|
|
18
|
+
for (const prefix of new Set([root, forward]))
|
|
19
|
+
out = out.replace(new RegExp(`(?:file:///?)?${escapeRegExp(prefix)}[/\\\\]`, "g"), "");
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Terminal output as plain text: no ANSI codes, carriage-return progress bars
|
|
26
|
+
* collapsed to their final state, repeated lines and runs of blank lines
|
|
27
|
+
* folded into one.
|
|
28
|
+
*/
|
|
29
|
+
export function cleanOutput(text, root) {
|
|
30
|
+
const lines = relativePaths(String(text ?? "").replace(ANSI, ""), root)
|
|
31
|
+
.replace(/\r\n/g, "\n")
|
|
32
|
+
.split("\n")
|
|
33
|
+
.map((line) => (line.includes("\r") ? (line.split("\r").findLast((p) => p) ?? "") : line))
|
|
34
|
+
.map((line) => line.trimEnd());
|
|
35
|
+
const kept = [];
|
|
36
|
+
let repeats = 0;
|
|
37
|
+
for (const line of lines) {
|
|
38
|
+
const previous = kept.at(-1);
|
|
39
|
+
if (previous !== undefined && line === previous) {
|
|
40
|
+
if (line) repeats++;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (repeats)
|
|
44
|
+
kept.push(` (previous line repeated ${repeats} more time${repeats > 1 ? "s" : ""})`);
|
|
45
|
+
repeats = 0;
|
|
46
|
+
kept.push(line);
|
|
47
|
+
}
|
|
48
|
+
if (repeats)
|
|
49
|
+
kept.push(` (previous line repeated ${repeats} more time${repeats > 1 ? "s" : ""})`);
|
|
50
|
+
while (kept.length && !kept[0]) kept.shift();
|
|
51
|
+
while (kept.length && !kept.at(-1)) kept.pop();
|
|
52
|
+
return kept.join("\n");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Shorten a failure message: clean it, drop stack frames inside node_modules
|
|
57
|
+
* and Node internals, and keep only the first frame in the project.
|
|
58
|
+
*/
|
|
59
|
+
export function compactFailure(message, root) {
|
|
60
|
+
const kept = [];
|
|
61
|
+
let frames = 0;
|
|
62
|
+
for (const line of cleanOutput(message, root).split("\n")) {
|
|
63
|
+
if (/^\s+at\s/.test(line)) {
|
|
64
|
+
if (/node_modules|node:internal|<anonymous>|\(native\)/.test(line) || frames >= 1) continue;
|
|
65
|
+
frames++;
|
|
66
|
+
}
|
|
67
|
+
kept.push(line);
|
|
68
|
+
}
|
|
69
|
+
return kept.join("\n");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Rough token count used for budgets and benchmarks: about four characters per token. */
|
|
73
|
+
export const estimateTokens = (text) => Math.ceil(String(text).length / 4);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The command line was wrong. Exit code 64. */
|
|
2
|
+
export class UsageError extends Error {
|
|
3
|
+
name = "UsageError";
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** The input was right but the test could not run here. Verdict BLOCKED, exit code 3. */
|
|
7
|
+
export class BlockedError extends Error {
|
|
8
|
+
name = "BlockedError";
|
|
9
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// Map local CLI runs onto the versioned evidence envelope
|
|
2
|
+
// (shared/contracts/evidence.ts). Everything the CLI produces is
|
|
3
|
+
// LOCAL_PROVISIONAL and FOCUSED: one selected test on this machine, never a
|
|
4
|
+
// required-check, full-suite or merge-safety claim.
|
|
5
|
+
|
|
6
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
7
|
+
import { buildEvidenceEnvelope, fingerprint } from "../../core/src/evidence.mjs";
|
|
8
|
+
import { VERSION } from "./version.mjs";
|
|
9
|
+
|
|
10
|
+
const SOURCE = "LOCAL_PROVISIONAL";
|
|
11
|
+
const SCOPE = "FOCUSED";
|
|
12
|
+
|
|
13
|
+
export const LOCAL_LIMITATION =
|
|
14
|
+
"Local provisional evidence from this machine, not a hosted attestation.";
|
|
15
|
+
const focusedLimitation = (test) =>
|
|
16
|
+
`Covers only ${label(test)}; it says nothing about other tests or whether the change is safe to merge.`;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* True for the two limitations every CLI envelope carries. They restate
|
|
20
|
+
* `source: LOCAL_PROVISIONAL` and `scope: FOCUSED`, so compact agent
|
|
21
|
+
* responses may leave them out and keep only the run-specific ones.
|
|
22
|
+
*/
|
|
23
|
+
export const isStandardLimitation = (text) =>
|
|
24
|
+
text === LOCAL_LIMITATION || /^Covers only .+; it says nothing about other tests/.test(text);
|
|
25
|
+
|
|
26
|
+
const label = (test) => (test.case ? `${test.path}::${test.case}` : test.path);
|
|
27
|
+
|
|
28
|
+
/** The built-in verdict rules. Changes when the rules (or the CLI) change. */
|
|
29
|
+
export const policyFingerprint = () =>
|
|
30
|
+
fingerprint({ policy: "traceyard-builtin-focused", version: 1, tool: VERSION });
|
|
31
|
+
|
|
32
|
+
function environmentFingerprint(runs) {
|
|
33
|
+
return fingerprint({
|
|
34
|
+
node: process.version,
|
|
35
|
+
platform: process.platform,
|
|
36
|
+
arch: process.arch,
|
|
37
|
+
tool: VERSION,
|
|
38
|
+
runners: runs.map((run) => run?.runner?.script ?? null),
|
|
39
|
+
dependencies: runs.map((run) => run?.dependencies ?? null),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const newRequestId = () => "req_" + randomBytes(8).toString("hex");
|
|
44
|
+
|
|
45
|
+
/** Stable, non-reversible ID for a repository without a GitHub remote. */
|
|
46
|
+
export const repositoryId = (github, root) =>
|
|
47
|
+
github
|
|
48
|
+
? "github:" + github
|
|
49
|
+
: "local:" + createHash("sha256").update(root).digest("hex").slice(0, 16);
|
|
50
|
+
|
|
51
|
+
/** A selected test's outcome as one check. A run with no passing test checked nothing. */
|
|
52
|
+
function testStatus(run) {
|
|
53
|
+
if (!run) return "NOT_RUN";
|
|
54
|
+
if (run.status === "BLOCKED") return "BLOCKED";
|
|
55
|
+
if (run.status === "FAILED") return "FAILED";
|
|
56
|
+
return run.counts.passed > 0 ? "PASSED" : "SKIPPED";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function runState(run) {
|
|
60
|
+
if (run.status === "BLOCKED") return "BLOCKED";
|
|
61
|
+
if (run.status === "FAILED") return "FAILED";
|
|
62
|
+
return "COMPLETED";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function runLimitations(run, role) {
|
|
66
|
+
const notes = [];
|
|
67
|
+
if (run.status === "BLOCKED") notes.push(`The ${role} run was blocked: ${run.message}`);
|
|
68
|
+
else if (!run.counts.passed && run.status !== "FAILED")
|
|
69
|
+
notes.push(`The ${role} run had no passing test, so nothing was checked.`);
|
|
70
|
+
if (run.cached)
|
|
71
|
+
notes.push(
|
|
72
|
+
`The ${role} result was reused from an earlier run of the same commit and test${run.recordedAt ? ` (${run.recordedAt})` : ""}.`,
|
|
73
|
+
);
|
|
74
|
+
if (run.truncated) notes.push(`The ${role} failure list was truncated.`);
|
|
75
|
+
return notes;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const evidenceIdFor = (...runs) =>
|
|
79
|
+
runs.find((run) => run?.evidenceId)?.evidenceId ?? "ev_blocked_" + randomBytes(6).toString("hex");
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Envelope for `repro` (a commit) or `check` (the working tree).
|
|
83
|
+
* `worktree` is `{ fingerprint, stale, complete }` for check: if the tree
|
|
84
|
+
* changed while the test ran, the result is STALE rather than a pass or a failure.
|
|
85
|
+
*/
|
|
86
|
+
export function singleRunEnvelope({
|
|
87
|
+
command,
|
|
88
|
+
run,
|
|
89
|
+
test,
|
|
90
|
+
repository,
|
|
91
|
+
requestId,
|
|
92
|
+
worktree = null,
|
|
93
|
+
next,
|
|
94
|
+
startedAt,
|
|
95
|
+
completedAt,
|
|
96
|
+
}) {
|
|
97
|
+
const checks = [{ id: `test:${label(test)}`, status: testStatus(run), required: false }];
|
|
98
|
+
const limitations = [LOCAL_LIMITATION, focusedLimitation(test), ...runLimitations(run, command)];
|
|
99
|
+
let state = runState(run);
|
|
100
|
+
if (worktree) {
|
|
101
|
+
if (worktree.stale) {
|
|
102
|
+
state = "STALE";
|
|
103
|
+
limitations.push("The working tree changed while the test ran, so this result is stale.");
|
|
104
|
+
}
|
|
105
|
+
if (!worktree.complete)
|
|
106
|
+
limitations.push(
|
|
107
|
+
"The working-tree fingerprint does not cover every untracked file, so some edits may go undetected.",
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
const evidenceId = evidenceIdFor(run);
|
|
111
|
+
return buildEvidenceEnvelope({
|
|
112
|
+
evidenceId,
|
|
113
|
+
runId: run.evidenceId ?? evidenceId,
|
|
114
|
+
requestId,
|
|
115
|
+
repositoryId: repository,
|
|
116
|
+
source: SOURCE,
|
|
117
|
+
scope: SCOPE,
|
|
118
|
+
state,
|
|
119
|
+
revision: {
|
|
120
|
+
commit: run.commit ?? null,
|
|
121
|
+
worktreeFingerprint: worktree ? worktree.fingerprint : null,
|
|
122
|
+
inputFingerprint: fingerprint({
|
|
123
|
+
command,
|
|
124
|
+
test: { path: test.path, case: test.case ?? null },
|
|
125
|
+
commit: run.commit ?? null,
|
|
126
|
+
worktree: worktree ? worktree.fingerprint : null,
|
|
127
|
+
}),
|
|
128
|
+
policyFingerprint: policyFingerprint(),
|
|
129
|
+
environmentFingerprint: environmentFingerprint([run]),
|
|
130
|
+
},
|
|
131
|
+
checks,
|
|
132
|
+
limitations,
|
|
133
|
+
next,
|
|
134
|
+
startedAt,
|
|
135
|
+
completedAt,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Envelope for `verify`. Each rule the verdict depends on is its own check,
|
|
141
|
+
* so a FIXED verdict is the only way to reach FOCUSED_PASS: the failure
|
|
142
|
+
* reproduced before, the same test passes after, the commits differ, no new
|
|
143
|
+
* skips, and no test inputs changed.
|
|
144
|
+
*/
|
|
145
|
+
export function verifyEnvelope({
|
|
146
|
+
baseline,
|
|
147
|
+
candidate,
|
|
148
|
+
test,
|
|
149
|
+
changedTests,
|
|
150
|
+
repository,
|
|
151
|
+
requestId,
|
|
152
|
+
next,
|
|
153
|
+
startedAt,
|
|
154
|
+
completedAt,
|
|
155
|
+
}) {
|
|
156
|
+
const reproduced =
|
|
157
|
+
baseline.status === "BLOCKED"
|
|
158
|
+
? "BLOCKED"
|
|
159
|
+
: baseline.status === "FAILED" && baseline.counts.failed > 0
|
|
160
|
+
? "PASSED"
|
|
161
|
+
: "FAILED";
|
|
162
|
+
const ran = Boolean(candidate) && reproduced === "PASSED";
|
|
163
|
+
const checks = [
|
|
164
|
+
{ id: `reproduces-before:${label(test)}`, status: reproduced, required: false },
|
|
165
|
+
{
|
|
166
|
+
id: `passes-after:${label(test)}`,
|
|
167
|
+
status: ran ? testStatus(candidate) : "NOT_RUN",
|
|
168
|
+
required: false,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
id: "distinct-commits",
|
|
172
|
+
status: !ran ? "NOT_RUN" : baseline.commit !== candidate.commit ? "PASSED" : "FAILED",
|
|
173
|
+
required: false,
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
id: "no-new-skips",
|
|
177
|
+
status: !ran
|
|
178
|
+
? "NOT_RUN"
|
|
179
|
+
: candidate.counts.skipped > baseline.counts.skipped
|
|
180
|
+
? "FAILED"
|
|
181
|
+
: "PASSED",
|
|
182
|
+
required: false,
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
id: "test-inputs-unchanged",
|
|
186
|
+
status: !ran ? "NOT_RUN" : changedTests.length ? "FAILED" : "PASSED",
|
|
187
|
+
required: false,
|
|
188
|
+
},
|
|
189
|
+
];
|
|
190
|
+
const limitations = [
|
|
191
|
+
LOCAL_LIMITATION,
|
|
192
|
+
focusedLimitation(test),
|
|
193
|
+
...runLimitations(baseline, "baseline"),
|
|
194
|
+
...(candidate ? runLimitations(candidate, "candidate") : []),
|
|
195
|
+
];
|
|
196
|
+
if (reproduced === "FAILED")
|
|
197
|
+
limitations.push("The test did not fail at the baseline commit, so no fix can be shown.");
|
|
198
|
+
if (ran && changedTests.length)
|
|
199
|
+
limitations.push(
|
|
200
|
+
`Test inputs changed between the commits: ${changedTests.slice(0, 5).join(", ")}${changedTests.length > 5 ? ", ..." : ""}.`,
|
|
201
|
+
);
|
|
202
|
+
let state = "COMPLETED";
|
|
203
|
+
if (baseline.status === "BLOCKED" || candidate?.status === "BLOCKED") state = "BLOCKED";
|
|
204
|
+
// Same commit on both sides proves nothing either way, even if the test fails.
|
|
205
|
+
else if (ran && candidate.status === "FAILED" && baseline.commit !== candidate.commit)
|
|
206
|
+
state = "FAILED";
|
|
207
|
+
const evidenceId = evidenceIdFor(candidate, baseline);
|
|
208
|
+
return buildEvidenceEnvelope({
|
|
209
|
+
evidenceId,
|
|
210
|
+
runId: (candidate ?? baseline).evidenceId ?? evidenceId,
|
|
211
|
+
requestId,
|
|
212
|
+
repositoryId: repository,
|
|
213
|
+
source: SOURCE,
|
|
214
|
+
scope: SCOPE,
|
|
215
|
+
state,
|
|
216
|
+
revision: {
|
|
217
|
+
commit: (candidate ?? baseline).commit ?? null,
|
|
218
|
+
worktreeFingerprint: null,
|
|
219
|
+
inputFingerprint: fingerprint({
|
|
220
|
+
command: "verify",
|
|
221
|
+
test: { path: test.path, case: test.case ?? null },
|
|
222
|
+
baseline: baseline.commit ?? null,
|
|
223
|
+
candidate: candidate?.commit ?? null,
|
|
224
|
+
changedTests: [...changedTests].sort(),
|
|
225
|
+
}),
|
|
226
|
+
policyFingerprint: policyFingerprint(),
|
|
227
|
+
environmentFingerprint: environmentFingerprint([baseline, candidate]),
|
|
228
|
+
},
|
|
229
|
+
checks,
|
|
230
|
+
limitations,
|
|
231
|
+
next,
|
|
232
|
+
startedAt,
|
|
233
|
+
completedAt,
|
|
234
|
+
});
|
|
235
|
+
}
|