@progen-labs/spectra 0.6.0 → 0.7.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/README.md CHANGED
@@ -1,355 +1,216 @@
1
- # @progen-labs/spectra
1
+ <h1 align="center">Spectra</h1>
2
2
 
3
- **Find out which file, which function and which component makes your frontend slow — automatically.**
3
+ <p align="center">
4
+ <b>Make your web app faster. Ask your AI agent, or run one command.</b>
5
+ <br>
6
+ <sub>React · Next.js · Vue · Angular · Svelte · any web frontend &nbsp;|&nbsp; Claude Code · Cursor · Copilot · Codex · Gemini · VS Code · CI</sub>
7
+ </p>
4
8
 
5
- Spectra is a CLI and dashboard that profiles a frontend build through the Chrome DevTools Protocol
6
- (tracing + CPU sampling) plus a small in-page probe for component re-renders and Web Vitals. Run one
7
- command and it starts your dev server, auto-discovers the actionable elements on the page, drives a set
8
- of **golden-path journeys**, records each one, and reports a ranked list of culprits — each with the
9
- exact function, file and line, the evidence, and a suggested fix.
9
+ <p align="center">
10
+ <a href="https://www.npmjs.com/package/@progen-labs/spectra"><img alt="npm version" src="https://img.shields.io/npm/v/@progen-labs/spectra?style=flat-square&color=0a84ff&label=npm"></a>
11
+ <a href="https://github.com/progen-labs/spectra/actions/workflows/checks.yml"><img alt="tests" src="https://img.shields.io/github/check-runs/progen-labs/spectra/main?nameFilter=Tests%20%28Node%2022%2C%20ubuntu-latest%29&style=flat-square&label=tests"></a>
12
+ <a href="https://www.npmjs.com/package/@progen-labs/spectra"><img alt="Downloads" src="https://img.shields.io/npm/dm/@progen-labs/spectra?style=flat-square&color=0a84ff"></a>
13
+ <a href="LICENSE"><img alt="MIT license" src="https://img.shields.io/npm/l/@progen-labs/spectra?style=flat-square&color=0a84ff"></a>
14
+ </p>
10
15
 
11
- Deep component-level attribution for **React, Next.js, Vue and Angular** (component names, render counts
12
- and per-component render/change-detection time; source files too, where the framework exposes them). For
13
- **Svelte and any other build**, a source-mapped generic profile still pinpoints the slow files and
14
- functions. The framework is detected in the page itself, so it is right wherever you start Spectra from.
15
- Apps behind a login work too: Spectra [signs in first](#behind-a-login), with every kind of login. A
16
- [Progen Labs](https://github.com/progen-labs) project — independent, open source, no telemetry, no account
17
- required.
16
+ <p align="center">
17
+ <a href="https://progen-labs.github.io/website/#spectra/docs/improve"><b>Documentation</b></a>
18
+ &nbsp;·&nbsp;
19
+ <a href="https://progen-labs.github.io/website/#spectra/demo"><b>2½-minute demo</b></a>
20
+ &nbsp;·&nbsp;
21
+ <a href="#get-started">Get started</a>
22
+ &nbsp;·&nbsp;
23
+ <a href="#measure-without-changing-anything">Measure only</a>
24
+ &nbsp;·&nbsp;
25
+ <a href="#project-health">Project health</a>
26
+ </p>
18
27
 
19
- **Watch the demo (2½ minutes):** [progen-labs.github.io/website/#spectra/demo](https://progen-labs.github.io/website/#spectra/demo).
28
+ Spectra runs your app in Chrome, measures it, and finds the problems in **your own code**: the exact file, function,
29
+ line and component, with a suggested fix. Then it has each problem fixed, measures the change, and keeps only what
30
+ measurably helped. It works with the AI coding agent you already use, or on its own. Everything runs on your
31
+ machine: no account, no telemetry, no uploads. A [Progen Labs](https://github.com/progen-labs) project, free and
32
+ open source.
20
33
 
21
- **Documentation:** the full guide, with annotated screenshots of every screen, is at
22
- [progen-labs.github.io/website](https://progen-labs.github.io/website/#spectra/docs/introduction).
34
+ ## Get started
23
35
 
24
- ## Install
36
+ **1. Install.** Node.js 22.12 or newer and a local Chrome, Chromium or Edge (Spectra drives the browser you have).
25
37
 
26
38
  ```bash
27
39
  npm install --save-dev @progen-labs/spectra
40
+ npx spectra
28
41
  ```
29
42
 
30
- Requirements: **Node 18+** and a local **Chrome / Chromium / Edge** (Spectra drives your installed
31
- browser; it does not download one). If it can't find Chrome, set `CHROME_PATH` to the executable.
32
-
33
- ## Quick start
43
+ `npx spectra` sets things up: it teaches your AI coding agent what Spectra does, in the file the agent reads for
44
+ your project (`AGENTS.md`, a Claude Code skill, Copilot instructions, a Cursor rule…). Nothing happens at install time.
34
45
 
35
- From the root of your project:
46
+ **2. Ask your agent.** In Claude Code, Cursor, GitHub Copilot, Codex, Gemini CLI, Windsurf or any other coding agent,
47
+ in plain words:
36
48
 
37
- ```bash
38
- npx spectra performance
39
- ```
49
+ > improve the performance
40
50
 
41
- With no `--url`, Spectra:
42
-
43
- 1. detects your framework and starts your dev server (`npm run dev`/`start`/`serve`),
44
- 2. records a baseline page load,
45
- 3. auto-discovers the actionable elements (links, buttons, inputs, forms),
46
- 4. synthesizes and runs **golden-path journeys** — safely (see below),
47
- 5. prints a performance matrix and saves a report per journey, then stops the server.
48
-
49
- ```
50
- # Golden path Result TBT LCP LongT Top finding
51
- — Initial page load PASS 0ms 128ms 0 [warning] main chunk served uncompressed
52
- 1 Click "Pricing" PASS 0ms — 0 [warning] Large DOM: 2,139 nodes
53
- 2 Click "Folders" PASS 0ms — 0 [critical] TreeNode re-rendered 1100× (96% wasted)
54
- ...
55
- Automation: 8/8 golden paths passed.
56
- ```
51
+ The agent runs Spectra's loop. Spectra measures the app and names the first problem: file, line, cost, suggested fix.
52
+ The agent makes that one change. Spectra runs your checks, measures again, and says **keep** or **undo**. Repeat.
53
+ Then the agent tells you what got faster, with the before → after numbers, and what it tried that didn't help.
57
54
 
58
- Then open the visual dashboard — ranked culprits, component re-renders, long tasks, the golden-path matrix,
59
- **PDF export** and **commit-to-commit compare**:
55
+ Or let Spectra do the whole thing unattended, with a coding agent installed on your machine:
60
56
 
61
57
  ```bash
62
- npx spectra dashboard --open
58
+ npx spectra improve
63
59
  ```
64
60
 
65
- ![The Spectra dashboard: the top culprit of a recording, burn() in src/heavy.js, with its time and a suggested fix](docs/dashboard.webp)
66
-
67
- A [tour of the dashboard](https://progen-labs.github.io/website/#spectra/docs/dashboard), with every part
68
- labelled, is in the docs.
69
-
70
- ## Commands
71
-
72
- ```
73
- spectra performance [options] Golden-path evaluation (default)
74
- spectra performance --quick One page-load profile (about 15 s)
75
- spectra compare <before> <after> Did it get faster? Noise-aware before/after
76
- spectra reports List saved reports
77
- spectra mcp [--project <dir>] MCP server for AI tools (stdio)
78
- spectra dashboard [--port N] [--open] Open the dashboard UI
79
- spectra fix [options] The AI fix harness (spectra fix --help)
80
- spectra agents [--remove] Teach your AI agents what Spectra does
81
- spectra --help Full option list
82
- spectra --version
83
- ```
61
+ It finds the agent (Claude Code, Codex, Gemini CLI, Copilot CLI, Cursor, OpenCode or Amp; `--agent` to choose),
62
+ works in a copy of your last commit, and puts the kept fixes on a branch, one commit each, with the measurements in
63
+ the commit messages. Your own files are never touched.
84
64
 
85
- **`performance` options**
65
+ **3. Review.** The changes are in your working tree (`git diff`) or on the branch (`git log -p HEAD..spectra/improve-…`).
66
+ Commit, or merge, and you're done.
86
67
 
87
- | Option | Description |
88
- | --- | --- |
89
- | `--url <page>` | Evaluate an already-running page; skips self-boot |
90
- | `--paths <n>` | Max golden paths to run (default 12) |
91
- | `--command "<cmd>"` | Override the dev-server command |
92
- | `--boot-timeout <s>` | How long to wait for the dev server (default 60) |
93
- | `--headed` | Show the browser window |
94
- | `--login-url <url>`, `--login-user <name>` | Sign in first: the login page and the username; the password comes from `SPECTRA_LOGIN_PASSWORD` (see [Behind a login](#behind-a-login)) |
95
- | `--login <method>` | `form`, `link`, `http`, `token` or `manual` (you sign in in the Chrome window); guessed when left out |
96
- | `--quick` | One page-load profile instead of the golden-path suite: the fast loop |
97
- | `--runs <n>` | Record n times and report the median (with `--quick` or `--mode`) |
98
- | `--mode live\|load` | Classic single-page profile instead of the golden-path suite |
99
- | `--json` | Print a machine-readable result on stdout (tables go to stderr) |
100
- | `--out <file>` | Also write that result to a file (an input for `compare`) |
101
- | `--config <file>` | Budgets and sign-in file (default: `spectra.config.json` in your project) |
102
-
103
- ## Behind a login
104
-
105
- Most production frontends sit behind a login, and the Chrome Spectra launches starts signed out. Tell
106
- Spectra how your app signs in and it signs in before it records, so the login never shows up in a
107
- measurement:
108
-
109
- | Method | For |
110
- | --- | --- |
111
- | **Login form** (`form`) | A username and password on your app's login page or its identity provider (OAuth, OpenID Connect, SAML): one or two steps, forms that render late, in iframes or web components, behind a "Sign in" button, with **authenticator codes** from a TOTP secret |
112
- | **I'll sign in myself** (`manual`) | SMS or email codes, push approvals, passkeys, CAPTCHAs: Chrome opens on the login page and Spectra waits for you |
113
- | **Browser prompt** (`http`) | HTTP Basic or Digest, common on staging servers |
114
- | **Token or cookie** (`token`) | A header (sent only to your app's origin), cookies or localStorage entries |
115
- | **Sign-in link** (`link`) | A URL that signs in by itself, such as a dev-only auto-login |
68
+ ## What a session looks like
116
69
 
117
- In the dashboard, turn on **My app needs a sign-in** under **Page to profile**. On the command line:
70
+ The guided loop on Spectra's React demo app. Each step is one short command, so any agent can drive it:
118
71
 
119
- ```bash
120
- SPECTRA_LOGIN_PASSWORD="$TEST_PASSWORD" npx spectra performance --login-url http://localhost:3000/login --login-user demo@example.com
121
- npx spectra performance --login manual --login-url https://staging.example.com/login
122
72
  ```
73
+ $ npx spectra improve next
74
+ spectra: measuring the baseline (3 page loads) …
75
+ Problem 1 of 5: Row is slow to render: 1442ms total, 0.2ms per render (7200×)
76
+ Where: src/Row.jsx:3
77
+ Cost: about 1.44 s, seen in 3 runs
78
+ Where the time went:
79
+ Row() in src/Row.jsx:3: 1.44 s (slow render)
80
+ Suggested fix: Move expensive calculations into useMemo, virtualise long lists, …
123
81
 
124
- Or once, for every command, the VS Code extension, the MCP server and `spectra fix`, in `spectra.config.json`:
82
+ Make ONE focused change in src/Row.jsx that removes or reduces this cost, keeping the behaviour exactly the same …
83
+ Then run: npx spectra improve check
125
84
 
126
- ```json
127
- { "signIn": { "method": "form", "url": "http://localhost:3000/login", "username": "demo@example.com" } }
128
- ```
129
-
130
- Secrets come only from the dashboard or the environment (`SPECTRA_LOGIN_PASSWORD`, `SPECTRA_LOGIN_TOTP_SECRET`,
131
- `SPECTRA_LOGIN_HEADER`, `SPECTRA_LOGIN_COOKIES`, `SPECTRA_LOGIN_STORAGE`). They stay in memory: never written
132
- to disk, a report, a log or an error message, and `spectra.config.json` refuses them. Spectra never solves
133
- CAPTCHAs. Use a test account where you can. See
134
- [Signing in](https://progen-labs.github.io/website/#spectra/docs/signing-in), with a short video.
85
+ $ npx spectra improve check # after the agent's change
86
+ spectra: running the checks (npm test) …
87
+ spectra: measuring the change …
88
+ ✓ Kept: JavaScript CPU time: 1.55 s → 162 ms (−90%)
89
+ also Row (src/Row.jsx) — render time: 1.44 s → 35.4 ms (−98%)
90
+ Checks passed: npm test.
91
+ Keep this change.
135
92
 
136
- ## Measure, change, verify
93
+ Problem 2 of 4: App rendered 60× (19/s)
94
+ Where: src/main.jsx:15
95
+ …
137
96
 
138
- Performance numbers are noisy, so Spectra never trusts a single recording when you ask it whether a change
139
- helped. Record a few runs before and after, then compare:
97
+ $ npx spectra improve check # after a change that did nothing
98
+ ✗ Undo this change: no measurable improvement: every change was within run-to-run noise.
99
+ Revert the files you changed for this problem (and only those), then continue.
140
100
 
141
- ```bash
142
- npx spectra performance --quick --runs 5 --out before.json
143
- # …make your change…
144
- npx spectra performance --quick --runs 5 --out after.json
145
- npx spectra compare before.json after.json
101
+ $ npx spectra improve report
102
+ Spectra improve — 1 of 2 problems fixed
103
+ ✓ fixed Row is slow to render … (src/Row.jsx:3): JavaScript CPU time: 1.55 s → 162 ms (−90%)
104
+ ✗ undone App rendered 60× (19/s) (src/main.jsx:15) — no measurable improvement
105
+ Overall, before → after: IMPROVED (confidence: medium)
106
+ ✓ JavaScript CPU time: 1.55 s → 162 ms (−90%)
107
+ ✓ Row (src/Row.jsx) — render time: 1.44 s → 35.4 ms (−98%)
146
108
  ```
147
109
 
148
- ```
149
- Spectra compare — IMPROVED (confidence: medium)
150
- ✓ JavaScript CPU time: 1.52 s → 92.1 ms (−94%)
151
- ✓ Row (src/Row.jsx) — render time: 1.44 s → 7.4 ms (−99%)
110
+ ## How it decides
152
111
 
153
- Findings: 3 resolved · 2 new · 10 still present
154
- resolved [critical] Row is slow to render: 1444ms total, 0.2ms per render (7200×)
155
- ```
112
+ Spectra makes every decision; the agent only edits.
156
113
 
157
- Each side is reduced to its median, and a difference only counts when it is larger than the run-to-run
158
- spread. A side can be a `--out` result file, a report id from `spectra reports`, a report file, or several
159
- ids joined by commas.
160
-
161
- ## Budgets and CI
162
-
163
- Put limits in `spectra.config.json` at your project root:
164
-
165
- ```json
166
- {
167
- "$schema": "./node_modules/@progen-labs/spectra/schema/config.schema.json",
168
- "budgets": { "tbtMs": 200, "lcpMs": 2500, "cls": 0.1, "criticalFindings": 0 }
169
- }
170
- ```
114
+ - **Measured, not guessed.** Three page loads before and after each change, reduced to medians. A change counts
115
+ only when it is bigger than the run-to-run noise, so a lucky run never decides.
116
+ - **Your checks first.** Your `test`, type-check and `build` scripts (or `--check "<cmd>"`) must pass after every
117
+ change. A faster page that breaks is undone.
118
+ - **Your code only.** Problems in `node_modules` are reported, not fixed. A new critical problem in your own code
119
+ undoes a change; a vendor chunk renamed between builds does not.
120
+ - **One change at a time, in order of cost.** A fix that also clears other problems skips them.
121
+ - **Unattended, in isolation.** A git worktree of your last commit with its own dev server; changes to
122
+ `package.json`, lockfiles, configuration, tests or CI, deletions, or more than 150 lines are refused; nothing is
123
+ pushed or merged.
171
124
 
172
- Every `spectra performance` run checks them: the median for `--quick`/`--mode`, every journey for the
173
- golden-path suite. Metrics a recording did not measure are skipped, never failed. Available budgets:
174
- `tbtMs`, `lcpMs`, `fcpMs`, `cls`, `inpMs`, `ttfbMs`, `longTaskCount`, `maxLongTaskMs`, `scriptingMs`,
175
- `forcedLayoutCount`, `domNodes`, `heapUsedMb`, `transferKb`, `criticalFindings`, `findingCount`.
125
+ The rules are Spectra's code, checked by a [test bench](https://progen-labs.github.io/website/#spectra/docs/harness-bench)
126
+ in CI: a real fix must be kept, a "faster" page that renders nothing must be caught, a cosmetic change must not count.
127
+ See [How improve decides](https://progen-labs.github.io/website/#spectra/docs/harness).
176
128
 
177
- Exit codes make it a CI gate:
129
+ ## What it works with
178
130
 
179
- | Code | Meaning |
131
+ | | |
180
132
  | --- | --- |
181
- | `0` | Done, and within budget |
182
- | `1` | Could not run (no Chrome, server down, bad config) |
183
- | `2` | Ran, but a budget was exceeded, or `compare --fail-on-regression` found a regression |
184
-
185
- ### GitHub Action
186
-
187
- The repository is also a GitHub Action. On every pull request it profiles the change and its base commit on the
188
- same runner, compares them beyond run-to-run noise, enforces your budgets, and writes the result to the job summary
189
- and (optionally) a PR comment:
190
-
191
- ```yaml
192
- name: Performance
193
- on: pull_request
194
- permissions:
195
- contents: read
196
- pull-requests: write # only for comment: true
197
- jobs:
198
- spectra:
199
- runs-on: ubuntu-latest
200
- steps:
201
- - uses: actions/checkout@v4
202
- - uses: actions/setup-node@v4
203
- with: { node-version: 22 }
204
- - run: npm ci
205
- - uses: progen-labs/spectra@v1
206
- with:
207
- compare-to-base: true
208
- fail-on-regression: true
209
- comment: true
210
- ```
211
-
212
- Inputs include `url`, `command`, `mode` (`quick` or `golden-paths`), `runs`, `config`, `fail-on-budget` and
213
- `working-directory`; outputs are `result-file`, `verdict`, `over-budget` and `summary-file`. Full reports are
214
- uploaded as an artifact. See the [Action guide](https://progen-labs.github.io/website/#spectra/docs/github-action).
215
-
216
- ## Machine-readable output
217
-
218
- `--json` prints a small, versioned result on stdout and sends every human-readable line to stderr, so it can
219
- be piped into `jq`, an editor or an AI agent. Each result has `schemaVersion` and a `kind` (`profile`,
220
- `evaluation`, `compare` or `reports`) and points at the full reports on disk rather than embedding them.
221
- Findings carry the file, line, cost in ms and a suggested fix. The format is described by a JSON Schema
222
- shipped with the package (`schema/result.schema.json`); additive changes keep `schemaVersion`, breaking
223
- changes bump it. Saved reports carry their own `schemaVersion` too.
224
-
225
- ## Use it from your AI assistant
226
-
227
- **Your agent already knows Spectra.** Installing it writes Spectra's knowledge doc (what it does, which command
228
- answers which request, how to read the results, how to prove a change helped) where your AI coding agent reads its
229
- project instructions. So you can ask in plain words, *"why is checkout slow?"*, *"did my change make it faster?"*,
230
- and the agent runs Spectra for you:
231
-
232
- | Agent | File |
233
- | --- | --- |
234
- | Codex, GitHub Copilot's coding agent, Cursor, Windsurf, Zed, Jules, Amp and any other agent that reads `AGENTS.md` | a Spectra block in `AGENTS.md` (always) |
235
- | Claude Code | `.claude/skills/spectra/SKILL.md`, and a short note in `CLAUDE.md` |
236
- | GitHub Copilot (VS Code, Visual Studio, JetBrains) | `.github/instructions/spectra.instructions.md` |
237
- | Cursor · Windsurf · Cline · Roo Code · Gemini CLI | `.cursor/rules/spectra.mdc` · `.windsurf/rules/spectra.md` · `.clinerules/spectra.md` · `.roo/rules/spectra.md` · `GEMINI.md` |
238
-
239
- Beyond `AGENTS.md`, it writes for the agents your project or machine uses, only between its own markers, so your
240
- own text is never touched. pnpm and Bun skip install steps until you allow them; run `npx spectra agents` instead
241
- (`--all`, `--only claude,copilot`, `--list`, `--print`). `npx spectra agents --remove` takes it all out, and
242
- `"agentDocs": false` in `spectra.config.json` (or `SPECTRA_AGENT_DOCS=0`) keeps it off. See
243
- [Any AI agent](https://progen-labs.github.io/website/#spectra/docs/agents).
244
-
245
- Spectra is an [MCP](https://modelcontextprotocol.io) server too, so an AI coding assistant can profile a page,
246
- fix what it finds, and prove each fix with before/after measurements.
133
+ | **Frameworks** | Component names, render counts and timings for **React, Next.js, Vue and Angular**; source-mapped files and functions for **Svelte, SolidJS and any other build**. Detected in the page itself. |
134
+ | **AI agents** | Any agent that reads `AGENTS.md` (Codex, Copilot's coding agent, Cursor, Windsurf, Zed, Jules, Amp…), plus Claude Code (a skill), GitHub Copilot (instructions), Cursor, Windsurf, Cline, Roo Code and Gemini CLI, each in its own file. MCP clients get the loop as tools (`improve_next`, `improve_check`, `improve_report`); there is a [Claude Code plugin](https://progen-labs.github.io/website/#spectra/docs/claude-code). |
135
+ | **Unattended** | Claude Code, Codex CLI, Gemini CLI, GitHub Copilot CLI, Cursor CLI, OpenCode, Amp, or any command of yours. |
136
+ | **Editors** | The [VS Code extension](https://marketplace.visualstudio.com/items?itemName=progen-labs.spectra-performance) shows each finding at its line and render counts above components. |
137
+ | **CI** | The [GitHub Action](https://progen-labs.github.io/website/#spectra/docs/github-action) profiles every pull request against its base commit and enforces your budgets. |
138
+ | **Apps behind a login** | Spectra [signs in first](https://progen-labs.github.io/website/#spectra/docs/signing-in): a login form (one or two steps, single sign-on, authenticator codes), you in the browser window, the browser prompt, a token or cookie, or a sign-in link. Secrets stay in memory. |
247
139
 
248
- **Claude Code**, with the plugin (adds an *improve-performance* skill and `/spectra:audit`):
249
-
250
- ```
251
- /plugin marketplace add progen-labs/spectra
252
- /plugin install spectra@progen-labs
253
- ```
254
-
255
- **Any MCP client** (Claude Code without the plugin, Claude Desktop, Cursor, VS Code, Windsurf…): run
256
- `npx -y @progen-labs/spectra mcp` as a stdio server (Spectra 0.3.0 or later). For example:
140
+ ## Measure without changing anything
257
141
 
258
142
  ```bash
259
- claude mcp add spectra -- npx -y @progen-labs/spectra mcp
143
+ npx spectra performance # starts your dev server, finds the page's buttons, links and
144
+ # forms, runs safe user journeys through them, reports each one
145
+ npx spectra performance --quick --runs 3 # one page, three loads, medians: the fast loop
146
+ npx spectra dashboard --open # the visual dashboard: culprits, page map, call trees, PDFs
260
147
  ```
261
148
 
262
- ```json
263
- { "mcpServers": { "spectra": { "command": "npx", "args": ["-y", "@progen-labs/spectra", "mcp", "--project", "/path/to/your/app"] } } }
264
149
  ```
265
-
266
- Tools: `profile_page`, `verify_change` (re-profile and compare against a baseline), `compare_profiles`,
267
- `run_golden_paths`, `list_reports` and `get_report`. The server profiles pages on this machine only (start it with
268
- `--allow-remote` to lift that), runs one browser at a time, and stops Chrome and any dev server it started when a
269
- call is cancelled. See the [MCP guide](https://progen-labs.github.io/website/#spectra/docs/mcp-server).
270
-
271
- ## The AI fix harness
272
-
273
- `spectra fix` hands the costliest findings in your own code to a coding agent, one at a time, and keeps a change only
274
- when your checks still pass and Spectra measures the page faster beyond run-to-run noise. Kept changes arrive as
275
- commits on a new branch, `spectra/fix-<time>`, for you to review; everything else is undone.
276
-
277
- ```bash
278
- npx spectra fix # Claude Code (signed in) fixes up to 3 findings
279
- npx spectra fix --check "npm run e2e" --max-fixes 5
280
- npx spectra fix --agent "./my-agent.sh" # any agent: instructions on stdin
150
+ # Golden path Result TBT LCP LongT Top finding
151
+ — Initial page load PASS 0ms 128ms 0 [warning] main chunk served uncompressed
152
+ 1 Click "Pricing" PASS 0ms — 0 [warning] Large DOM: 2,139 nodes
153
+ 2 Click "Folders" PASS 0ms — 0 [critical] TreeNode re-rendered 1100× (96% wasted)
154
+ Automation: 8/8 golden paths passed.
281
155
  ```
282
156
 
283
- The harness, not the agent, makes every decision:
284
-
285
- - **Isolation.** It works in a git worktree of your last commit, with its own dev server. Your working tree is never
286
- touched, and nothing is pushed or merged.
287
- - **Your checks first.** Your test, type-check and build scripts (or `--check`, which can test the running app at
288
- `$SPECTRA_FIX_URL`) must pass before any change and after each one. A faster page that breaks is undone.
289
- - **Scope rules.** A change may not touch `package.json`, lockfiles, configuration, tests or CI, delete files, or
290
- exceed 150 lines.
291
- - **Proof.** The change is kept only if `spectra compare` says *improved* with medium or high confidence and no new
292
- critical finding; with low confidence it measures again.
293
- - **A record.** Each kept commit carries its evidence; `.spectra/fix/<time>/report.md` summarises the session, and a
294
- history skips findings that failed before. A finding that an earlier kept fix already cleared is skipped too.
295
-
296
- By default the agent is Claude Code in headless mode, allowed only to read and edit files (no shell, no web, no MCP),
297
- with a spending cap per finding. A test bench (`npm run bench`) checks the harness's decisions in CI: a real fix is
298
- kept, a "faster" change that breaks the page is caught, a cosmetic change doesn't count, and an edit to
299
- `package.json` is refused. With Claude Code on the demo app, it kept two of three fixes and cut JavaScript CPU time
300
- from 1.51 s to 82.5 ms (−95%) for $0.44. See [the AI fix harness](https://progen-labs.github.io/website/#spectra/docs/harness).
301
-
302
- ## In VS Code
157
+ ![The Spectra dashboard: the top culprit of a recording, burn() in src/heavy.js, with its time and a suggested fix](docs/dashboard.webp)
303
158
 
304
- The Spectra extension (`vscode/`) puts results where you work: every finding in the **Problems panel** at the file
305
- and line responsible, **CodeLens** above the costliest components and functions
306
- (`⚡ Spectra: Row · 7,200 renders · 1.44 s rendering`), headline numbers in the **status bar**, **Verify against
307
- baseline** after a change, golden paths, and the dashboard inside the editor. Results that the CLI or an AI
308
- assistant writes to `.spectra/results` appear automatically, and on VS Code 1.101+ it offers Spectra's MCP server to
309
- agent mode. It runs your project's Spectra (0.2.0 or later) or `npx`.
159
+ Prove a change yourself with `npx spectra performance --quick --runs 5 --out before.json`, the same with `after.json`,
160
+ then `npx spectra compare before.json after.json`. Put limits in `spectra.config.json` and every run becomes a CI gate
161
+ (exit code 2 when over budget). `--json` prints a versioned result for scripts and editors. See
162
+ [Measure a page](https://progen-labs.github.io/website/#spectra/docs/cli-performance),
163
+ [Compare](https://progen-labs.github.io/website/#spectra/docs/compare),
164
+ [Budgets and CI](https://progen-labs.github.io/website/#spectra/docs/budgets) and
165
+ [JSON output](https://progen-labs.github.io/website/#spectra/docs/json-output).
310
166
 
311
- Install **Spectra — frontend performance** from the [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=progen-labs.spectra-performance), or from a terminal:
167
+ ## Commands
312
168
 
313
- ```bash
314
- code --install-extension progen-labs.spectra-performance
169
+ ```
170
+ spectra improve [options] Make the app faster, unattended (spectra improve --help)
171
+ spectra improve next|check|report|stop The same, step by step, for your AI agent or you
172
+ spectra performance [options] Measure only: golden-path journeys, or --quick
173
+ spectra compare <before> <after> Did it get faster? Beyond run-to-run noise
174
+ spectra reports List saved reports
175
+ spectra dashboard [--open] The dashboard UI
176
+ spectra mcp [--project <dir>] MCP server for AI tools (stdio)
177
+ spectra agents [--remove] Teach your AI agents what Spectra does
178
+ spectra --help Every option
315
179
  ```
316
180
 
317
- For Cursor, Windsurf or VSCodium (Open VSX), until it is listed there: `cd vscode && npx @vscode/vsce package
318
- --no-dependencies`, then install `spectra-performance-0.1.0.vsix` with **Extensions: Install from VSIX…**.
319
-
320
- See the [VS Code guide](https://progen-labs.github.io/website/#spectra/docs/vscode).
321
-
322
- ## Safe by default
323
-
324
- Auto-exploration never triggers destructive actions. Spectra detects controls that would mutate state —
325
- anything labelled delete / pay / checkout / log out, logout links, and `POST`/`PUT`/`DELETE` form submits —
326
- and **skips** them unless you explicitly allow them. Form fields are filled with synthetic values; GET
327
- searches and navigations are fair game. If a session expires and the app sends Spectra back to its login page,
328
- Spectra signs in again.
329
-
330
- ## Where results go
181
+ Everything Spectra does runs on your machine, in a separate Chrome profile, on a development build (production
182
+ builds hide component timings). Reports go to `.spectra/` in your project; keep it out of git. Automatic exploration
183
+ never clicks delete, pay or log out, and never submits a form that changes data.
331
184
 
332
- Reports are written to `.spectra/reports/` in your project (add it to `.gitignore`). Each golden path is a
333
- full report you can open in `spectra dashboard`, export to PDF, or compare against another commit.
185
+ ## Project health
334
186
 
335
- ## How it works
187
+ <p align="center">
188
+ <a href="https://github.com/progen-labs/spectra/actions/workflows/checks.yml"><img alt="tests" src="https://img.shields.io/github/check-runs/progen-labs/spectra/main?nameFilter=Tests%20%28Node%2022%2C%20ubuntu-latest%29&style=flat-square&label=tests"></a>
189
+ <a href="https://github.com/progen-labs/spectra/actions/workflows/checks.yml"><img alt="lint" src="https://img.shields.io/github/check-runs/progen-labs/spectra/main?nameFilter=Lint&style=flat-square&label=lint"></a>
190
+ <a href="https://github.com/progen-labs/spectra/actions/workflows/checks.yml"><img alt="npm audit" src="https://img.shields.io/github/check-runs/progen-labs/spectra/main?nameFilter=npm%20audit&style=flat-square&label=npm%20audit"></a>
191
+ <a href="https://github.com/progen-labs/spectra/actions/workflows/checks.yml"><img alt="snyk" src="https://img.shields.io/github/check-runs/progen-labs/spectra/main?nameFilter=Snyk&style=flat-square&label=snyk"></a>
192
+ <a href="https://socket.dev/npm/package/@progen-labs/spectra"><img alt="Socket" src="https://socket.dev/api/badge/npm/package/@progen-labs/spectra"></a>
193
+ <a href="https://github.com/progen-labs/spectra/actions/workflows/checks.yml"><img alt="size budget" src="https://img.shields.io/github/check-runs/progen-labs/spectra/main?nameFilter=Size%20budget&style=flat-square&label=size%20budget"></a>
194
+ <a href="https://scorecard.dev/viewer/?uri=github.com/progen-labs/spectra"><img alt="OpenSSF Scorecard" src="https://api.scorecard.dev/projects/github.com/progen-labs/spectra/badge?style=flat-square"></a>
195
+ <a href="https://www.npmjs.com/package/@progen-labs/spectra?activeTab=code"><img alt="unpacked size" src="https://img.shields.io/npm/unpacked-size/@progen-labs/spectra?style=flat-square&label=unpacked&color=0a84ff"></a>
196
+ </p>
336
197
 
337
- Spectra launches Chrome via `puppeteer-core`, records a CDP trace + CPU profile, and injects a probe that
338
- tracks component renders, slow interactions and Web Vitals. It maps sampled frames back to your source
339
- through source maps (and bundler markers as a fallback), then ranks the files, functions and components
340
- that cost the most main-thread time. See the
341
- [deep-dive docs](https://github.com/progen-labs/spectra/blob/main/DOCS.md) for how capture, correlation
342
- and report generation work.
198
+ Every pull request and push to `main` runs the same checks, and **spectra-bot** reports them in one comment on each
199
+ pull request: the tests on Node 22, 24 and 26 across Linux, macOS and Windows with a coverage floor, lint, `npm audit`
200
+ and Snyk, Socket's supply-chain score, size budgets, the links in the docs, the improve bench, the GitHub Action on the
201
+ demo app, CodeQL and the OpenSSF Scorecard. Every action is pinned to a commit, and CI installs from the committed
202
+ lockfile. Releases carry a changelog, the package, its SBOM and signed build attestations. See
203
+ [CONTRIBUTING.md](CONTRIBUTING.md), [CHANGELOG.md](CHANGELOG.md) and, for security issues, [SECURITY.md](SECURITY.md).
343
204
 
344
205
  ## Documentation
345
206
 
346
- - **[The guide](https://progen-labs.github.io/website/#spectra/docs/introduction)**: every feature, with
347
- annotated screenshots. Start with
348
- [Quick start](https://progen-labs.github.io/website/#spectra/docs/quick-start),
349
- [Compare before and after](https://progen-labs.github.io/website/#spectra/docs/compare),
207
+ - **[The guide](https://progen-labs.github.io/website/#spectra/docs/improve)**: start with
208
+ [Improve the performance](https://progen-labs.github.io/website/#spectra/docs/improve) and
209
+ [Your AI agent](https://progen-labs.github.io/website/#spectra/docs/agents); then
210
+ [Measure a page](https://progen-labs.github.io/website/#spectra/docs/cli-performance),
350
211
  [Budgets and CI](https://progen-labs.github.io/website/#spectra/docs/budgets),
351
- [JSON output](https://progen-labs.github.io/website/#spectra/docs/json-output),
352
- [Claude Code](https://progen-labs.github.io/website/#spectra/docs/claude-code), the
212
+ [MCP server](https://progen-labs.github.io/website/#spectra/docs/mcp-server),
213
+ [How improve decides](https://progen-labs.github.io/website/#spectra/docs/harness), the
353
214
  [Findings reference](https://progen-labs.github.io/website/#spectra/docs/findings) and
354
215
  [Troubleshooting](https://progen-labs.github.io/website/#spectra/docs/troubleshooting).
355
216
  - **[DOCS.md](DOCS.md)**: the in-repo manual, the technical deep dive, and how to contribute.