@progen-labs/spectra 0.5.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/CHANGELOG.md ADDED
@@ -0,0 +1,94 @@
1
+ # Changelog
2
+
3
+ Every release of Spectra, newest first. Versions follow [semantic versioning](https://semver.org); while Spectra is 0.x, a minor version can change behaviour. The same changelog is on the [website](https://progen-labs.github.io/website/#spectra/docs/changelog).
4
+
5
+ Update an existing install with `npm install --save-dev @progen-labs/spectra@latest`, and check yours with `npx spectra --version`.
6
+
7
+ ## 0.7.0 (25 October 2026)
8
+
9
+ **Ask your AI agent to "improve the performance", and Spectra does the rest.** Spectra's main command is now `spectra improve`: it measures the app, finds the problems in your own code, has each one fixed, measures the change, and keeps only what measurably helped. Everything else Spectra can do is still there, behind it.
10
+
11
+ - **`spectra improve`**, two ways with the same rules. **Guided**: `npx spectra improve next` measures and names the first problem (file, line, cost, suggested fix); the AI agent you are talking to, or you, makes that one change; `npx spectra improve check` runs your checks, measures again and says keep or undo, then names the next problem; `npx spectra improve report` sums it up. Any agent can drive it, with no extra tools. **Unattended**: `npx spectra improve` finds a coding agent on your machine (Claude Code, Codex, Gemini CLI, Copilot CLI, Cursor, OpenCode or Amp; `--agent` to choose) and does the whole loop in a copy of your last commit, with the kept fixes as commits on `spectra/improve-<time>`. `spectra fix` stays as the old name. Sessions live in `.spectra/improve/`. See [Improve the performance](https://progen-labs.github.io/website/#spectra/docs/improve).
12
+ - **The MCP server** has the same loop as tools: `improve_next`, `improve_check` and `improve_report`, next to the six it had. The Claude Code plugin's *improve-performance* skill uses them.
13
+ - **Your agent knows the loop.** The knowledge doc Spectra writes for AI agents, and `npx spectra` with no command, now lead with it.
14
+ - **A fairer keep rule.** A change is undone for a new critical finding only when the finding is in your own code: a vendor chunk the dev server renamed between measurements no longer undoes a good fix. In `spectra compare`, a chunk keeps its identity across content hashes and query strings (`react-dom-hmN8LOy-.js?v=1` and `react-dom-Zq1x_9ab.js?v=2` are the same resource).
15
+ - **Docs for the simple path first.** The README and the website lead with install, ask, review; the command reference, budgets, CI, MCP, the dashboard and the rest follow.
16
+
17
+ ## 0.6.1 (22 October 2026)
18
+
19
+ - **Node.js 22.12 or newer.** Spectra's Chrome driver, puppeteer-core, needs it, so `engines` in `package.json` now says so instead of Node 18, and every release is installed and run on it in CI. Node 20 reached its end of life in April 2026.
20
+ - **No install script.** Spectra's knowledge doc for AI agents is now written the first time Spectra runs in your project, instead of during `npm install`, so package managers and supply-chain scanners such as Socket have no install script to flag. It works the same with npm, pnpm, Yarn and Bun, once per version, and never comes back after `npx spectra agents --remove`. See [Any AI agent](https://progen-labs.github.io/website/#spectra/docs/agents).
21
+ - **A sign-in click that goes nowhere is retried.** On a busy page or a slow machine, the click on the sign-in button can be lost. When the form sent nothing at all, Spectra now presses Enter in the last field once, and if the form still sent nothing, the error says so and asks for the button's selector. See [Signing in](https://progen-labs.github.io/website/#spectra/docs/signing-in).
22
+ - **A change as big as the noise is noise.** A comparison now counts a change only when it is bigger than the spread between runs, as the docs always said. Before, a change exactly equal to it counted, so one long task in two of three runs could mark a change slower in `spectra compare`, the GitHub Action and `spectra fix`.
23
+ - **zod 4.6.7** in the lockfile (through puppeteer-core), for a high-severity advisory in 4.6.5. A fresh install already gets the fixed version.
24
+
25
+ ## 0.6.0 (22 October 2026)
26
+
27
+ **Your AI agent knows Spectra.** Installing Spectra now teaches your coding agent what it does: which command answers which request, how to read the results, how to prove a change made things faster, and the rules to follow. So you can ask in plain words ("why is checkout slow?", "did my change help?") and the agent runs Spectra for you. The knowledge doc goes into `AGENTS.md` (Codex, GitHub Copilot's coding agent, Cursor, Windsurf, Zed and others) and, for the agents your project or machine uses, a Claude Code skill, GitHub Copilot instructions, a Cursor rule, and Windsurf, Cline, Roo Code and Gemini CLI files. Your own text is never touched. `npx spectra agents` does it by hand (pnpm and Bun skip install steps until you allow them), and `--remove` takes it out. See [Any AI agent](https://progen-labs.github.io/website/#spectra/docs/agents).
28
+
29
+ ## 0.5.0 (22 October 2026)
30
+
31
+ Spectra signs in, and every label names your framework.
32
+
33
+ - **Signing in, every kind of login.** Most production frontends sit behind a login; now Spectra signs in before it profiles. A **login form** (one or two steps, forms that render late, in iframes or web components, behind a **Sign in** button, on your identity provider), with **authenticator codes** from a TOTP secret; **signing in yourself** in the Chrome window for SMS or email codes, passkeys and CAPTCHAs; the **browser's login prompt** (HTTP Basic or Digest); a **token, cookie or localStorage entry**; or a **sign-in link**. In the dashboard, turn on **My app needs a sign-in**; on the command line use `--login-url` and `--login-user` with `SPECTRA_LOGIN_PASSWORD`, or put the non-secret parts in `spectra.config.json` for every tool. Secrets stay in memory, are never written to disk, a report or a log, and the config file refuses them. See [Signing in](https://progen-labs.github.io/website/#spectra/docs/signing-in).
34
+ - **Framework-agnostic labels.** The dashboard, findings, comparisons and PDFs say **Components**, **Component render time** and the framework the page runs (React, Vue or Angular), instead of "React" everywhere.
35
+ - **The framework is detected in the page.** The probe is ready for React, Vue and Angular on every page, so an Angular or Vue app is profiled as itself even when Spectra starts from another folder, a monorepo root or an editor. Before, it took the framework from the `package.json` where Spectra started and fell back to React.
36
+ - **Page map for every app.** The page screenshot is now always taken, and Vue and Angular components are pinned on it, not only React ones.
37
+ - **Fixed**: a plain JavaScript page no longer gets a "No React renderer was seen" finding, and the dashboard's pill says **No component framework seen** without looking like an error.
38
+
39
+ ## 0.4.1 (17 October 2026)
40
+
41
+ - **`spectra fix` skips findings that are already fixed.** One fix often clears several findings. After each kept fix, a finding the new measurement no longer shows is listed as skipped ("already resolved by an earlier kept change") instead of being handed to the agent, which saves its time and cost. Found by the first [real-agent bench run](https://progen-labs.github.io/website/#spectra/docs/harness-bench), where one of three attempts went to a finding the first fix had cleared.
42
+
43
+ ## 0.4.0 (17 October 2026)
44
+
45
+ The [AI fix harness](https://progen-labs.github.io/website/#spectra/docs/harness). `spectra fix` hands the costliest findings in your own code to a coding agent (Claude Code by default, or any command), one at a time, in a git worktree of your last commit. A change is kept as a commit on a new branch only when it stays within scope, your checks pass (they can test the running app at `$SPECTRA_FIX_URL`) and Spectra measures it faster beyond run-to-run noise; otherwise it is undone. Each session leaves a Markdown report and a history, so failed findings aren't retried. A [test bench](https://progen-labs.github.io/website/#spectra/docs/harness-bench) checks the harness's decisions in CI. See [spectra fix](https://progen-labs.github.io/website/#spectra/docs/cli-fix) and [Checks and safety](https://progen-labs.github.io/website/#spectra/docs/harness-safety).
46
+
47
+ ## GitHub Action v1 (17 October 2026)
48
+
49
+ `uses: progen-labs/spectra@v1` profiles each pull request and its base commit on the same runner, compares them, enforces budgets, and reports in the job summary and an optional pull request comment. See [GitHub Action](https://progen-labs.github.io/website/#spectra/docs/github-action).
50
+
51
+ ## VS Code extension 0.1.0 (17 October 2026)
52
+
53
+ The first release of the [VS Code extension](https://progen-labs.github.io/website/#spectra/docs/vscode), on the [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=progen-labs.spectra-performance) as `progen-labs.spectra-performance`: findings in the Problems panel at the exact line, CodeLens above costly components and functions, headline numbers in the status bar, verify against a baseline, golden paths, the dashboard in the editor, results shared with the CLI and AI assistants, and Spectra's MCP server offered to agent mode.
54
+
55
+ ## 0.3.0 (17 October 2026)
56
+
57
+ Spectra works inside your AI assistant.
58
+
59
+ - **`spectra mcp`**: Spectra as an MCP server, with `profile_page`, `verify_change`, `compare_profiles`, `run_golden_paths`, `list_reports` and `get_report`. Local pages only by default; one browser at a time; progress notifications and cancellation. See [MCP server](https://progen-labs.github.io/website/#spectra/docs/mcp-server).
60
+ - **Claude Code plugin**: `/plugin marketplace add progen-labs/spectra`, then `/plugin install spectra@progen-labs`. Claude fixes performance problems one at a time and keeps a change only when Spectra measures an improvement; `/spectra:audit` reports without editing. See [Claude Code plugin](https://progen-labs.github.io/website/#spectra/docs/claude-code).
61
+ - **Cleaner stops**: stopping or cancelling a run now also closes Chrome and stops the dev server Spectra started.
62
+
63
+ ## 0.2.0 (17 October 2026)
64
+
65
+ Faster loops, honest comparisons and machine-readable output. Everything is additive: existing commands and options behave as before.
66
+
67
+ - **`--quick`**: a single page-load profile, the fast loop. See [Quick and repeated profiles](https://progen-labs.github.io/website/#spectra/docs/quick-profiles).
68
+ - **`--runs N`**: record several times and report medians, the spread and how many runs saw each finding.
69
+ - **`spectra compare`**: noise-aware before and after, from `--out` result files, report ids or report files. `--fail-on-regression` exits with code 2. See [Compare](https://progen-labs.github.io/website/#spectra/docs/compare).
70
+ - **`spectra reports`**: list saved reports. See [spectra reports](https://progen-labs.github.io/website/#spectra/docs/reports).
71
+ - **Budgets** in `spectra.config.json`, checked on every run, with exit codes for CI. See [Budgets and CI](https://progen-labs.github.io/website/#spectra/docs/budgets).
72
+ - **`--json` and `--out`**: a versioned result with published JSON Schemas. Saved reports carry a `schemaVersion`. See [JSON output](https://progen-labs.github.io/website/#spectra/docs/json-output).
73
+ - **A lighter install**: 29 packages and 33 MB instead of 73 packages and 54 MB, because the dashboard ships prebuilt.
74
+ - **Fixed**: relative `--scenario` paths now resolve against your directory. Zero times read "0 ms", and a single run's summary line no longer prints "nullms".
75
+ - **Dashboard fixes**: on laptop-sized windows the report tabs wrap instead of hiding **Compare commits** off the edge, and the Long tasks cards keep file names, functions and times inside the card.
76
+
77
+ ## 0.1.3 (11 October 2026)
78
+
79
+ - **Angular**: per-component change-detection counts and self time from Angular's development-mode profiler.
80
+
81
+ ## 0.1.2 (11 October 2026)
82
+
83
+ - Fixed every reported dependency vulnerability.
84
+
85
+ ## 0.1.1 (11 October 2026)
86
+
87
+ - **Vue**: deep component support through Vue's DevTools hook.
88
+ - **Next.js**: profiled through React.
89
+
90
+ ## 0.1.0 (11 October 2026)
91
+
92
+ - First release on npm as `@progen-labs/spectra`.
93
+ - `spectra performance`: self-boots your dev server, discovers actionable elements and runs the safe [golden-path suite](https://progen-labs.github.io/website/#spectra/docs/golden-paths).
94
+ - `spectra dashboard`: the full dashboard with no build step, including PDF export and commit comparison.
package/README.md CHANGED
@@ -1,335 +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
34
-
35
- From the root of your project:
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.
36
45
 
37
- ```bash
38
- npx spectra performance
39
- ```
40
-
41
- With no `--url`, Spectra:
46
+ **2. Ask your agent.** In Claude Code, Cursor, GitHub Copilot, Codex, Gemini CLI, Windsurf or any other coding agent,
47
+ in plain words:
42
48
 
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.
49
+ > improve the performance
48
50
 
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
63
- ```
64
-
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 --help Full option list
80
- spectra --version
58
+ npx spectra improve
81
59
  ```
82
60
 
83
- **`performance` options**
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
- | Option | Description |
86
- | --- | --- |
87
- | `--url <page>` | Evaluate an already-running page; skips self-boot |
88
- | `--paths <n>` | Max golden paths to run (default 12) |
89
- | `--command "<cmd>"` | Override the dev-server command |
90
- | `--boot-timeout <s>` | How long to wait for the dev server (default 60) |
91
- | `--headed` | Show the browser window |
92
- | `--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)) |
93
- | `--login <method>` | `form`, `link`, `http`, `token` or `manual` (you sign in in the Chrome window); guessed when left out |
94
- | `--quick` | One page-load profile instead of the golden-path suite: the fast loop |
95
- | `--runs <n>` | Record n times and report the median (with `--quick` or `--mode`) |
96
- | `--mode live\|load` | Classic single-page profile instead of the golden-path suite |
97
- | `--json` | Print a machine-readable result on stdout (tables go to stderr) |
98
- | `--out <file>` | Also write that result to a file (an input for `compare`) |
99
- | `--config <file>` | Budgets and sign-in file (default: `spectra.config.json` in your project) |
100
-
101
- ## Behind a login
102
-
103
- Most production frontends sit behind a login, and the Chrome Spectra launches starts signed out. Tell
104
- Spectra how your app signs in and it signs in before it records, so the login never shows up in a
105
- measurement:
106
-
107
- | Method | For |
108
- | --- | --- |
109
- | **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 |
110
- | **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 |
111
- | **Browser prompt** (`http`) | HTTP Basic or Digest, common on staging servers |
112
- | **Token or cookie** (`token`) | A header (sent only to your app's origin), cookies or localStorage entries |
113
- | **Sign-in link** (`link`) | A URL that signs in by itself, such as a dev-only auto-login |
114
-
115
- In the dashboard, turn on **My app needs a sign-in** under **Page to profile**. On the command line:
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.
116
67
 
117
- ```bash
118
- SPECTRA_LOGIN_PASSWORD="$TEST_PASSWORD" npx spectra performance --login-url http://localhost:3000/login --login-user demo@example.com
119
- npx spectra performance --login manual --login-url https://staging.example.com/login
120
- ```
68
+ ## What a session looks like
121
69
 
122
- Or once, for every command, the VS Code extension, the MCP server and `spectra fix`, in `spectra.config.json`:
70
+ The guided loop on Spectra's React demo app. Each step is one short command, so any agent can drive it:
123
71
 
124
- ```json
125
- { "signIn": { "method": "form", "url": "http://localhost:3000/login", "username": "demo@example.com" } }
126
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, …
127
81
 
128
- Secrets come only from the dashboard or the environment (`SPECTRA_LOGIN_PASSWORD`, `SPECTRA_LOGIN_TOTP_SECRET`,
129
- `SPECTRA_LOGIN_HEADER`, `SPECTRA_LOGIN_COOKIES`, `SPECTRA_LOGIN_STORAGE`). They stay in memory: never written
130
- to disk, a report, a log or an error message, and `spectra.config.json` refuses them. Spectra never solves
131
- CAPTCHAs. Use a test account where you can. See
132
- [Signing in](https://progen-labs.github.io/website/#spectra/docs/signing-in), with a short video.
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
133
84
 
134
- ## Measure, change, verify
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
- Performance numbers are noisy, so Spectra never trusts a single recording when you ask it whether a change
137
- helped. Record a few runs before and after, then compare:
93
+ Problem 2 of 4: App rendered 60× (19/s)
94
+ Where: src/main.jsx:15
95
+ …
138
96
 
139
- ```bash
140
- npx spectra performance --quick --runs 5 --out before.json
141
- # …make your change…
142
- npx spectra performance --quick --runs 5 --out after.json
143
- npx spectra compare before.json after.json
144
- ```
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.
145
100
 
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
- Spectra compare — IMPROVED (confidence: medium)
148
- ✓ JavaScript CPU time: 1.52 s → 92.1 ms (−94%)
149
- ✓ Row (src/Row.jsx) — render time: 1.44 s → 7.4 ms (−99%)
150
109
 
151
- Findings: 3 resolved · 2 new · 10 still present
152
- resolved [critical] Row is slow to render: 1444ms total, 0.2ms per render (7200×)
153
- ```
110
+ ## How it decides
154
111
 
155
- Each side is reduced to its median, and a difference only counts when it is larger than the run-to-run
156
- spread. A side can be a `--out` result file, a report id from `spectra reports`, a report file, or several
157
- ids joined by commas.
112
+ Spectra makes every decision; the agent only edits.
158
113
 
159
- ## Budgets and CI
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.
160
124
 
161
- Put limits in `spectra.config.json` at your project root:
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).
162
128
 
163
- ```json
164
- {
165
- "$schema": "./node_modules/@progen-labs/spectra/schema/config.schema.json",
166
- "budgets": { "tbtMs": 200, "lcpMs": 2500, "cls": 0.1, "criticalFindings": 0 }
167
- }
168
- ```
129
+ ## What it works with
169
130
 
170
- Every `spectra performance` run checks them: the median for `--quick`/`--mode`, every journey for the
171
- golden-path suite. Metrics a recording did not measure are skipped, never failed. Available budgets:
172
- `tbtMs`, `lcpMs`, `fcpMs`, `cls`, `inpMs`, `ttfbMs`, `longTaskCount`, `maxLongTaskMs`, `scriptingMs`,
173
- `forcedLayoutCount`, `domNodes`, `heapUsedMb`, `transferKb`, `criticalFindings`, `findingCount`.
174
-
175
- Exit codes make it a CI gate:
176
-
177
- | Code | Meaning |
131
+ | | |
178
132
  | --- | --- |
179
- | `0` | Done, and within budget |
180
- | `1` | Could not run (no Chrome, server down, bad config) |
181
- | `2` | Ran, but a budget was exceeded, or `compare --fail-on-regression` found a regression |
182
-
183
- ### GitHub Action
184
-
185
- The repository is also a GitHub Action. On every pull request it profiles the change and its base commit on the
186
- same runner, compares them beyond run-to-run noise, enforces your budgets, and writes the result to the job summary
187
- and (optionally) a PR comment:
188
-
189
- ```yaml
190
- name: Performance
191
- on: pull_request
192
- permissions:
193
- contents: read
194
- pull-requests: write # only for comment: true
195
- jobs:
196
- spectra:
197
- runs-on: ubuntu-latest
198
- steps:
199
- - uses: actions/checkout@v4
200
- - uses: actions/setup-node@v4
201
- with: { node-version: 22 }
202
- - run: npm ci
203
- - uses: progen-labs/spectra@v1
204
- with:
205
- compare-to-base: true
206
- fail-on-regression: true
207
- comment: true
208
- ```
209
-
210
- Inputs include `url`, `command`, `mode` (`quick` or `golden-paths`), `runs`, `config`, `fail-on-budget` and
211
- `working-directory`; outputs are `result-file`, `verdict`, `over-budget` and `summary-file`. Full reports are
212
- uploaded as an artifact. See the [Action guide](https://progen-labs.github.io/website/#spectra/docs/github-action).
213
-
214
- ## Machine-readable output
215
-
216
- `--json` prints a small, versioned result on stdout and sends every human-readable line to stderr, so it can
217
- be piped into `jq`, an editor or an AI agent. Each result has `schemaVersion` and a `kind` (`profile`,
218
- `evaluation`, `compare` or `reports`) and points at the full reports on disk rather than embedding them.
219
- Findings carry the file, line, cost in ms and a suggested fix. The format is described by a JSON Schema
220
- shipped with the package (`schema/result.schema.json`); additive changes keep `schemaVersion`, breaking
221
- changes bump it. Saved reports carry their own `schemaVersion` too.
222
-
223
- ## Use it from your AI assistant
224
-
225
- Spectra is an [MCP](https://modelcontextprotocol.io) server too, so an AI coding assistant can profile a page,
226
- fix what it finds, and prove each fix with before/after measurements.
227
-
228
- **Claude Code**, with the plugin (adds an *improve-performance* skill and `/spectra:audit`):
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. |
229
139
 
230
- ```
231
- /plugin marketplace add progen-labs/spectra
232
- /plugin install spectra@progen-labs
233
- ```
234
-
235
- **Any MCP client** (Claude Code without the plugin, Claude Desktop, Cursor, VS Code, Windsurf…): run
236
- `npx -y @progen-labs/spectra mcp` as a stdio server (Spectra 0.3.0 or later). For example:
140
+ ## Measure without changing anything
237
141
 
238
142
  ```bash
239
- 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
240
147
  ```
241
148
 
242
- ```json
243
- { "mcpServers": { "spectra": { "command": "npx", "args": ["-y", "@progen-labs/spectra", "mcp", "--project", "/path/to/your/app"] } } }
244
149
  ```
245
-
246
- Tools: `profile_page`, `verify_change` (re-profile and compare against a baseline), `compare_profiles`,
247
- `run_golden_paths`, `list_reports` and `get_report`. The server profiles pages on this machine only (start it with
248
- `--allow-remote` to lift that), runs one browser at a time, and stops Chrome and any dev server it started when a
249
- call is cancelled. See the [MCP guide](https://progen-labs.github.io/website/#spectra/docs/mcp-server).
250
-
251
- ## The AI fix harness
252
-
253
- `spectra fix` hands the costliest findings in your own code to a coding agent, one at a time, and keeps a change only
254
- when your checks still pass and Spectra measures the page faster beyond run-to-run noise. Kept changes arrive as
255
- commits on a new branch, `spectra/fix-<time>`, for you to review; everything else is undone.
256
-
257
- ```bash
258
- npx spectra fix # Claude Code (signed in) fixes up to 3 findings
259
- npx spectra fix --check "npm run e2e" --max-fixes 5
260
- 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.
261
155
  ```
262
156
 
263
- The harness, not the agent, makes every decision:
264
-
265
- - **Isolation.** It works in a git worktree of your last commit, with its own dev server. Your working tree is never
266
- touched, and nothing is pushed or merged.
267
- - **Your checks first.** Your test, type-check and build scripts (or `--check`, which can test the running app at
268
- `$SPECTRA_FIX_URL`) must pass before any change and after each one. A faster page that breaks is undone.
269
- - **Scope rules.** A change may not touch `package.json`, lockfiles, configuration, tests or CI, delete files, or
270
- exceed 150 lines.
271
- - **Proof.** The change is kept only if `spectra compare` says *improved* with medium or high confidence and no new
272
- critical finding; with low confidence it measures again.
273
- - **A record.** Each kept commit carries its evidence; `.spectra/fix/<time>/report.md` summarises the session, and a
274
- history skips findings that failed before. A finding that an earlier kept fix already cleared is skipped too.
275
-
276
- By default the agent is Claude Code in headless mode, allowed only to read and edit files (no shell, no web, no MCP),
277
- with a spending cap per finding. A test bench (`npm run bench`) checks the harness's decisions in CI: a real fix is
278
- kept, a "faster" change that breaks the page is caught, a cosmetic change doesn't count, and an edit to
279
- `package.json` is refused. With Claude Code on the demo app, it kept two of three fixes and cut JavaScript CPU time
280
- 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).
281
-
282
- ## 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)
283
158
 
284
- The Spectra extension (`vscode/`) puts results where you work: every finding in the **Problems panel** at the file
285
- and line responsible, **CodeLens** above the costliest components and functions
286
- (`⚡ Spectra: Row · 7,200 renders · 1.44 s rendering`), headline numbers in the **status bar**, **Verify against
287
- baseline** after a change, golden paths, and the dashboard inside the editor. Results that the CLI or an AI
288
- assistant writes to `.spectra/results` appear automatically, and on VS Code 1.101+ it offers Spectra's MCP server to
289
- 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).
290
166
 
291
- 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
292
168
 
293
- ```bash
294
- 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
295
179
  ```
296
180
 
297
- For Cursor, Windsurf or VSCodium (Open VSX), until it is listed there: `cd vscode && npx @vscode/vsce package
298
- --no-dependencies`, then install `spectra-performance-0.1.0.vsix` with **Extensions: Install from VSIX…**.
299
-
300
- See the [VS Code guide](https://progen-labs.github.io/website/#spectra/docs/vscode).
301
-
302
- ## Safe by default
303
-
304
- Auto-exploration never triggers destructive actions. Spectra detects controls that would mutate state —
305
- anything labelled delete / pay / checkout / log out, logout links, and `POST`/`PUT`/`DELETE` form submits —
306
- and **skips** them unless you explicitly allow them. Form fields are filled with synthetic values; GET
307
- searches and navigations are fair game. If a session expires and the app sends Spectra back to its login page,
308
- Spectra signs in again.
309
-
310
- ## 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.
311
184
 
312
- Reports are written to `.spectra/reports/` in your project (add it to `.gitignore`). Each golden path is a
313
- full report you can open in `spectra dashboard`, export to PDF, or compare against another commit.
185
+ ## Project health
314
186
 
315
- ## 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>
316
197
 
317
- Spectra launches Chrome via `puppeteer-core`, records a CDP trace + CPU profile, and injects a probe that
318
- tracks component renders, slow interactions and Web Vitals. It maps sampled frames back to your source
319
- through source maps (and bundler markers as a fallback), then ranks the files, functions and components
320
- that cost the most main-thread time. See the
321
- [deep-dive docs](https://github.com/progen-labs/spectra/blob/main/DOCS.md) for how capture, correlation
322
- 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).
323
204
 
324
205
  ## Documentation
325
206
 
326
- - **[The guide](https://progen-labs.github.io/website/#spectra/docs/introduction)**: every feature, with
327
- annotated screenshots. Start with
328
- [Quick start](https://progen-labs.github.io/website/#spectra/docs/quick-start),
329
- [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),
330
211
  [Budgets and CI](https://progen-labs.github.io/website/#spectra/docs/budgets),
331
- [JSON output](https://progen-labs.github.io/website/#spectra/docs/json-output),
332
- [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
333
214
  [Findings reference](https://progen-labs.github.io/website/#spectra/docs/findings) and
334
215
  [Troubleshooting](https://progen-labs.github.io/website/#spectra/docs/troubleshooting).
335
216
  - **[DOCS.md](DOCS.md)**: the in-repo manual, the technical deep dive, and how to contribute.