aztrx-cli 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,292 @@
1
+ # ⚡ Aztrx
2
+
3
+ > **Autonomous runtime stress-tester, deterministic bug minimizer, and self-healing engine for web applications.**
4
+
5
+ [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D18-green.svg?style=flat-square)](https://nodejs.org)
6
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](LICENSE)
7
+
8
+ Aztrx drives your web app like a hostile user — clicking, entering boundary data, and racing asynchronous UI states. When a runtime crash occurs (even one swallowed by a React Error Boundary), Aztrx intercepts it via the Chrome DevTools Protocol, maps it back to the exact source line, shrinks the interaction trace to the bare minimum with **ddmin**, and emits an executable, standalone **Playwright test** that proves the bug — not a log line.
9
+
10
+ ![aztrx demo](media/demo.gif)
11
+
12
+ ---
13
+
14
+ ## Why Aztrx
15
+
16
+ - **Sees swallowed errors.** Error Boundaries and `window.onerror` miss the errors your app *catches*. Aztrx reads the real throw-site stack off the `Error` object, so a crash you've never seen in your logs becomes a finding you can't ignore.
17
+ - **Proves, not reports.** Every crash/error finding ships with an executable `.spec.ts` and a flake-rate verdict — `[deterministic 5/5]`, `[flaky 3/5]`, or `[unreliable]`.
18
+ - **Heals, not just finds.** `--heal` generates a patch through an LLM, gates it (redaction + AST safety), compiles it, and replays it against the repro inside an isolated git worktree — the patch is verified before a human ever sees it.
19
+ - **Safe by default.** A deny-by-default network guard blocks off-origin calls, and a destructive-action deny-list refuses to click "delete", "pay", or "logout".
20
+
21
+ ---
22
+
23
+ ## Quickstart
24
+
25
+ Run against any running local dev server — no install, no repo clone:
26
+
27
+ ```bash
28
+ npx aztrx-cli run http://localhost:3000 # deterministic walk
29
+ npx aztrx-cli run http://localhost:3000 --fuzz # seeded chaos (replayable)
30
+ npx aztrx-cli run http://localhost:3000 --fuzz --repro # + minimize → compile → validate
31
+ ```
32
+
33
+ Install it globally once it's published:
34
+
35
+ ```bash
36
+ npm i -g aztrx-cli
37
+ aztrx-cli run http://localhost:3000 --repro
38
+ ```
39
+
40
+ > **Not on npm yet?** Install from source (contributors):
41
+ > ```bash
42
+ > git clone https://github.com/DanisChaparov/aztrx
43
+ > cd aztrx
44
+ > npm install
45
+ > npm run build
46
+ > npm link # puts `aztrx-cli` on your PATH
47
+ > ```
48
+
49
+ Aztrx drives Chromium through Playwright — the first run downloads the browser
50
+ automatically (`npx playwright install chromium` to force it).
51
+
52
+ ---
53
+
54
+ ## Features & Workflows
55
+
56
+ ### 1. Initialize configuration
57
+
58
+ Scaffold `aztrx.config.ts`, detect the framework + dev port, and seed `.aztrx/` into `.gitignore`:
59
+
60
+ ```bash
61
+ npx aztrx-cli init
62
+ ```
63
+
64
+ ### 2. Autonomous healing (`--heal`)
65
+
66
+ Locate the crash, hand the redacted context to an LLM, run a TypeScript check and Playwright validation inside an isolated worktree, and write a verified `.patch` file:
67
+
68
+ ```bash
69
+ export ANTHROPIC_API_KEY="your-api-key"
70
+ npx aztrx-cli run http://localhost:3000 --fuzz --repro --heal
71
+ ```
72
+
73
+ ### 3. Live studio dashboard
74
+
75
+ Inspect real-time telemetry events and triage findings in the built-in web UI:
76
+
77
+ ```bash
78
+ npx aztrx-cli studio
79
+ # → listening at http://localhost:7331
80
+ ```
81
+
82
+ ### 4. Cloud & CI ingest (`--upload`)
83
+
84
+ Stream sanitized, deduplicated crash fingerprints and metrics to your team's ingest server:
85
+
86
+ ```bash
87
+ npx aztrx-cli run http://localhost:3000 --upload --api-key <YOUR_API_KEY> --cloud-url http://localhost:8787
88
+ ```
89
+
90
+ ### 5. GitHub Action
91
+
92
+ Ship a runtime gate on every PR — see [Continuous Integration](#continuous-integration-github-action) below.
93
+
94
+ ---
95
+
96
+ ## CLI reference
97
+
98
+ | Flag | Description | Default |
99
+ | --- | --- | --- |
100
+ | `--fuzz` | Seeded chaos fuzzing instead of the deterministic walk | — |
101
+ | `--repro` | Minimize (ddmin) → emit Playwright spec → validate flake rate | — |
102
+ | `--heal` | Generate + verify an LLM patch (implies `--repro`) | — |
103
+ | `--upload` | Stream run findings to the cloud ingest backend | — |
104
+ | `--api-key <key>` | Auth key for `--upload` / `--share-data` | `$AZTRX_API_KEY` |
105
+ | `--cloud-url <url>` | Ingest server base URL | `https://api.aztrx.app` |
106
+ | `--max-actions <n>` | Max actions per pass | `100` |
107
+ | `--seed <n>` | PRNG seed for deterministic fuzz | `42` |
108
+ | `--repro-runs <n>` | Flake-rate replay iterations | `3` |
109
+ | `--heal-model <model>` | Fallback LLM tier | `claude-sonnet-5` |
110
+ | `--heal-fast-model <model>` | Fast/cheap first tier | `claude-haiku-4-5` |
111
+ | `--pr-comment [path]` | Write a GitHub PR markdown comment | `.aztrx/pr-comment.md` |
112
+ | `--telemetry` | Collect anonymized tuples locally (opt-in) | — |
113
+ | `--share-data` | Also upload the sanitized tuples (opt-in) | — |
114
+ | `--repo <path>` | Root path for sourcemap → source resolution | cwd |
115
+ | `--allow-host <host>` | Add a host to the network allow-list (repeatable) | — |
116
+ | `--auth <path>` / `--storage-state <path>` | Playwright storage-state for authenticated pages | — |
117
+ | `--fail-on` | Exit `1` if any crash/error finding is present | — |
118
+ | `--dry-run` | Log planned actions without executing them | — |
119
+ | `--crash-test` | Throw a deliberate error to verify capture | — |
120
+ | `--plain` / `--ui` | Force plain logs / force the live panel | — |
121
+
122
+ ---
123
+
124
+ ## Output artifacts
125
+
126
+ Every run writes self-contained artifacts inside `.aztrx/` (gitignored):
127
+
128
+ ```
129
+ .aztrx/
130
+ ├── report.html # zero-CDN interactive triage report
131
+ ├── repro/
132
+ │ └── 458f6bf71977.spec.ts # minimal, executable Playwright repro
133
+ ├── heal/
134
+ │ └── fix.patch # gated, compiler-checked fix
135
+ ├── events.jsonl # run log, streamed by `aztrx studio`
136
+ ├── telemetry/dataset.jsonl # opt-in anonymized tuple dataset
137
+ └── pr-comment.md # GitHub PR markdown (with --pr-comment)
138
+ ```
139
+
140
+ ---
141
+
142
+ ## Architecture
143
+
144
+ Aztrx is a decoupled, event-driven pipeline — modules talk only through an
145
+ `EventBus`; the orchestrator wires them together.
146
+
147
+ ```
148
+ [ CDP interceptor ] ──▶ [ action ring buffer ] ──▶ [ classifier (fingerprint) ]
149
+
150
+ [ verified .patch ] ◀── [ LLM healer ] ◀── [ ddmin minimizer ] ◀── [ sourcemap resolver ]
151
+
152
+ [ Playwright spec (.spec.ts) ] ──▶ [ flake-rate validator ]
153
+ ```
154
+
155
+ | Stage | Module | Role |
156
+ | --- | --- | --- |
157
+ | F1 | `interceptor.ts` | CDP interceptor — captures raw runtime errors and console/network events |
158
+ | F2 | `recorder.ts` | Ring buffer of the last 25 actions; selector cascade `data-testid → text → CSS path` |
159
+ | F3 | `classifier.ts` | Fingerprints + dedups findings, assigns severity; suppresses `.aztrx/baseline.json` (input) |
160
+ | F4 | `resolver.ts` | Maps minified frames to source files, lines, and snippets via sourcemaps |
161
+ | F5 | `fuzzer.ts` + `domWalker.ts` | Seeded chaos fuzzer; `domWalker` (F5-lite) discovers interactive elements |
162
+ | F6 | `networkGuard.ts` + `domWalker.ts` | Deny-by-default network policy + destructive-action deny-list |
163
+ | F7 | `minimizer.ts` | ddmin delta-debugging — eliminates irrelevant actions |
164
+ | F8 | `specCompiler.ts` | Emits standalone, clean Playwright `.spec.ts` repro |
165
+ | F9 | `validator.ts` | Multi-pass replays → `deterministic` / `flaky` / `unreliable` |
166
+ | F10 | `heal/` | Closed-loop healing — redact → generate → AST gate → sandbox → `tsc` → verify |
167
+ | F11 | `telemetry/` | Opt-in anonymized crash→repro→patch tuple collection (data flywheel) |
168
+ | F12 | `cloud/` | Opt-in cloud sync — streams sanitized findings to the ingest dashboard |
169
+
170
+ ---
171
+
172
+ ## Continuous Integration (GitHub Action)
173
+
174
+ Runtime gate on every PR. The action boots your dev server, runs
175
+ `aztrx-cli run --fail-on --repro --heal`, posts a markdown comment with the
176
+ deterministic repro + gated patch, and fails the check on a crash/error.
177
+
178
+ ```yaml
179
+ # .github/workflows/ci.yml — composite action, inline
180
+ on: pull_request
181
+ jobs:
182
+ aztrx:
183
+ runs-on: ubuntu-latest
184
+ permissions: { contents: read, pull-requests: write }
185
+ steps:
186
+ - uses: actions/checkout@v4
187
+ - uses: DanisChaparov/aztrx@main
188
+ with:
189
+ url: http://localhost:3000
190
+ start-command: npm run dev # optional — boot the app in the background
191
+ token: ${{ github.token }}
192
+ anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }} # optional — enables --heal
193
+ ```
194
+
195
+ Or as a reusable workflow:
196
+
197
+ ```yaml
198
+ on: pull_request
199
+ jobs:
200
+ aztrx:
201
+ uses: DanisChaparov/aztrx/.github/workflows/aztrx-pr.yml@main
202
+ with:
203
+ url: http://localhost:3000
204
+ start-command: npm run dev
205
+ secrets:
206
+ anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
207
+ ```
208
+
209
+ ---
210
+
211
+ ## Smart Cloud Router
212
+
213
+ `--heal` is backed by a two-tier router. The fast/cheap model
214
+ (`claude-haiku-4-5`) generates first; its patch is gated, compiled, and replayed
215
+ against the repro. If the bug still reproduces — or the patch fails a gate —
216
+ aztrx falls back to `claude-sonnet-5` and tries again. Most one-line fixes never
217
+ pay for the big model. Tiers are configurable via `AZTRX_FAST_MODEL` /
218
+ `AZTRX_MODEL` or `--heal-fast-model` / `--heal-model`.
219
+
220
+ ## Telemetry & privacy
221
+
222
+ Off by default and strictly opt-in. `--telemetry` collects the anonymized tuple
223
+ `[crash_fingerprint, min_repro_spec, verified_patch, framework_metadata,
224
+ model_tier_used]` locally (nothing leaves the machine); `--share-data` uploads it
225
+ to the telemetry endpoint. Every field passes a sanitizer that irreversibly
226
+ strips secrets, anonymizes URLs to `<host>`, and scrubs repo paths to `<repo>`.
227
+ Uploads are fire-and-forget, bounded by a 2s timeout, and never affect the exit
228
+ code.
229
+
230
+ ## Security invariants
231
+
232
+ - **Deny-by-default network** — only the target origin (plus explicit `--allow-host`) is reachable.
233
+ - **Destructive-action deny-list** — never clicks delete / pay / logout.
234
+ - **`.aztrx/` is gitignored** on `init` — repro specs and reports stay out of history.
235
+
236
+ ---
237
+
238
+ ## Open benchmark
239
+
240
+ The detector is scored against a 13-target corpus of **real Next.js App Router
241
+ apps** — one seeded runtime bug per app across the archetype matrix (null deref,
242
+ async race, JSON parse, stack overflow, Server Action, route transition, and more).
243
+
244
+ | metric | value |
245
+ | --- | --- |
246
+ | seeded bugs | 13 |
247
+ | detection recall | **100%** (13 / 13) |
248
+ | deterministic repros | **100%** (12 / 12) |
249
+ | repro not attempted | 1 (mount-time bug, no action history) |
250
+ | unseeded findings | 5 — two root causes (`/api/cart` → 500, Server Action → 500) |
251
+
252
+ ```bash
253
+ cd bench/frameworks
254
+ npm install # once — installs next/react for the target apps
255
+ npm run bench # detection
256
+ npm run bench:repro # detection + repro scoring
257
+ ```
258
+
259
+ Full per-case table and scoring notes live in
260
+ [`bench/frameworks/RESULTS.md`](bench/frameworks/RESULTS.md).
261
+
262
+ ---
263
+
264
+ ## Roadmap
265
+
266
+ - [x] Closed-loop healing — redact → generate → gate → sandbox → verify (F10)
267
+ - [ ] Open-source launch — npm publish, `npx aztrx-cli run`, hero screencast
268
+ - [x] Hardening — `--auth`/`--storage-state`, tsc compile fast-fail, React 19/Next.js 15 triage
269
+ - [x] Real-project benchmark — 13 Next.js App Router targets (100% recall, 100% deterministic repro)
270
+ - [x] B2B ($29/mo) — GitHub Action (`action.yml` + reusable workflow), PR bot markdown comment
271
+ - [x] B2B ($29/mo) — Smart Cloud Router (haiku fast-tier → verify → Sonnet fallback)
272
+ - [x] B2B ($29/mo) — Cloud dashboard (api.aztrx.app)
273
+ - [x] Data flywheel — opt-in anonymized patch-tuple collection (F11)
274
+
275
+ ## Contributing
276
+
277
+ ```bash
278
+ git clone https://github.com/DanisChaparov/aztrx
279
+ cd aztrx
280
+ npm install
281
+ npx playwright install chromium
282
+ npm run build
283
+
284
+ # smoke fixture (throws on the "Break me" button)
285
+ node fixtures/serve.mjs &
286
+ node dist/cli.js http://localhost:8901/crash.html --repo fixtures --repro
287
+ # → one ● crash mapped to crash.html:13:15, minimized to 1 step
288
+ ```
289
+
290
+ ## License
291
+
292
+ Apache-2.0 © DanisChaparov
package/dist/cli.js ADDED
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env node
2
+ import path from "path";
3
+ import pc from "picocolors";
4
+ import { program } from "commander";
5
+ import { run } from "./core/orchestrator.js";
6
+ import { EventBus } from "./core/eventBus.js";
7
+ import { renderTui } from "./ui/app.js";
8
+ import { initProject } from "./core/init.js";
9
+ import { startStudio } from "./core/studio.js";
10
+ import { writePrComment } from "./core/pr.js";
11
+ import { flushTelemetry } from "./core/telemetry/index.js";
12
+ import { flushCloud } from "./core/cloud/index.js";
13
+ function collect(value, prev) {
14
+ prev.push(value);
15
+ return prev;
16
+ }
17
+ program
18
+ .name("aztrx")
19
+ .description("Runtime stress-testing for web apps — detect bugs, prove them with a repro")
20
+ .option("--repo <path>", "project root to inspect/watch (default: cwd)", process.cwd());
21
+ program
22
+ .command("init")
23
+ .description("scaffold aztrx.config.ts and seed .aztrx/ into .gitignore")
24
+ .option("--url <url>", "dev server URL (default: auto-detect port)")
25
+ .option("--framework <name>", "framework override (auto-detected if omitted)")
26
+ .action(async (opts) => {
27
+ const res = await initProject({
28
+ repoRoot: path.resolve(program.opts().repo),
29
+ url: opts.url,
30
+ framework: opts.framework,
31
+ });
32
+ console.log(pc.green("✓") + ` aztrx.config.ts written (${pc.bold(res.framework)}, ${res.url})`);
33
+ if (res.gitignoreUpdated)
34
+ console.log(pc.green("✓") + " .aztrx/ added to .gitignore");
35
+ console.log("");
36
+ console.log(pc.dim(`Next: npx aztrx run ${res.url} --repo .`));
37
+ });
38
+ program
39
+ .command("studio")
40
+ .description("start the live studio dashboard on localhost:7331")
41
+ .option("--port <n>", "port to listen on", "7331")
42
+ .action((opts) => {
43
+ startStudio({ repoRoot: path.resolve(program.opts().repo), port: parseInt(opts.port, 10) });
44
+ });
45
+ program
46
+ .command("run", { isDefault: true })
47
+ .description("inspect a running app and prove its bugs with an executable repro")
48
+ .argument("<url>", "dev server to inspect, e.g. http://localhost:3000")
49
+ .option("--repo <path>", "project root to inspect/watch (default: cwd)")
50
+ .option("--max-actions <n>", "max actions per pass", "100")
51
+ .option("--dry-run", "report what would be clicked without clicking")
52
+ .option("--crash-test", "throw a deliberate error to verify capture")
53
+ .option("--fail-on", "exit 1 if any crash/error finding is present")
54
+ .option("--fuzz", "chaos fuzzing instead of the deterministic walk (F5)")
55
+ .option("--seed <n>", "RNG seed for fuzz", "42")
56
+ .option("--repro", "minimize + compile + validate each finding (F7-F9)")
57
+ .option("--repro-runs <n>", "replay iterations for the flake-rate gate", "3")
58
+ .option("--heal", "closed-loop healing for crash/error findings (implies --repro)")
59
+ .option("--heal-model <model>", "LLM model for healing — the fallback tier (default claude-sonnet-5)")
60
+ .option("--heal-fast-model <model>", "fast/cheap first tier for the smart router (default claude-haiku-4-5)")
61
+ .option("--pr-comment [path]", "write a GitHub PR markdown comment (default .aztrx/pr-comment.md)")
62
+ .option("--telemetry", "opt-in: collect anonymized crash→repro→patch tuples locally (.aztrx/telemetry)")
63
+ .option("--share-data", "opt-in: also upload the sanitized tuples to the telemetry endpoint")
64
+ .option("--upload", "opt-in: stream run results to the Aztrx cloud dashboard (needs --api-key)")
65
+ .option("--api-key <key>", "API key for --upload / --share-data (defaults to $AZTRX_API_KEY)")
66
+ .option("--cloud-url <url>", "override the cloud ingest base URL (default https://api.aztrx.app)")
67
+ .option("--allow-host <host>", "add a host to the network allow-list (repeatable)", collect, [])
68
+ .option("--storage-state <path>", "path to a Playwright storage-state JSON (cookies/localStorage) for authenticated pages")
69
+ .option("--auth <path>", "alias for --storage-state")
70
+ .option("--plain", "disable the live terminal UI, print plain logs (default when piped)")
71
+ .option("--ui", "force the live terminal UI even when stdout is not a TTY")
72
+ .action(async (url, opts) => {
73
+ const repoRoot = path.resolve(opts.repo ?? program.opts().repo);
74
+ const runOpts = {
75
+ url,
76
+ repoRoot,
77
+ maxActions: parseInt(opts.maxActions, 10),
78
+ dryRun: opts.dryRun,
79
+ crashTest: opts.crashTest,
80
+ fuzz: opts.fuzz,
81
+ repro: opts.repro || opts.heal,
82
+ seed: parseInt(opts.seed, 10),
83
+ allowHosts: opts.allowHost ?? [],
84
+ reproRuns: parseInt(opts.reproRuns, 10),
85
+ heal: opts.heal,
86
+ healModel: opts.healModel,
87
+ healFastModel: opts.healFastModel,
88
+ telemetry: opts.telemetry,
89
+ shareData: opts.shareData,
90
+ upload: opts.upload,
91
+ apiKey: opts.apiKey,
92
+ cloudUrl: opts.cloudUrl,
93
+ storageState: opts.storageState ?? opts.auth,
94
+ };
95
+ const failOn = Boolean(opts.failOn);
96
+ const useUi = !opts.plain && (process.stdout.isTTY === true || opts.ui === true);
97
+ let findings = [];
98
+ if (useUi) {
99
+ const bus = new EventBus();
100
+ const runPromise = run({ ...runOpts, bus, ui: true });
101
+ await renderTui({
102
+ bus,
103
+ done: runPromise,
104
+ targetUrl: url,
105
+ repoRoot,
106
+ mode: opts.fuzz ? `fuzz (seed ${opts.seed})` : opts.heal ? "repro → heal" : opts.repro ? "repro" : "deterministic walk",
107
+ });
108
+ try {
109
+ findings = await runPromise;
110
+ }
111
+ catch (e) {
112
+ console.error(pc.red("Aztrx run failed:"), e.message);
113
+ process.exit(1);
114
+ }
115
+ }
116
+ else {
117
+ findings = await run(runOpts);
118
+ }
119
+ if (opts.prComment) {
120
+ const prPath = typeof opts.prComment === "string"
121
+ ? opts.prComment
122
+ : path.join(repoRoot, ".aztrx", "pr-comment.md");
123
+ writePrComment(repoRoot, url, findings, prPath);
124
+ console.log(pc.dim(`PR comment: ${path.relative(repoRoot, prPath)}`));
125
+ }
126
+ // Drain any in-flight telemetry uploads (each bounded) before exit, so a
127
+ // pending `--share-data` dispatch isn't killed mid-flight. Never affects
128
+ // the exit code.
129
+ await flushTelemetry();
130
+ await flushCloud();
131
+ if (failOn && findings.some((f) => f.severity === "crash" || f.severity === "error")) {
132
+ process.exit(1);
133
+ }
134
+ process.exit(0);
135
+ });
136
+ program.parseAsync();