@_deep4wee/agent-lens 1.1.0 โ†’ 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +331 -227
  2. package/dist/cli.js +1068 -911
  3. package/dist/cli.js.map +1 -1
  4. package/dist/cli.mjs +1277 -1033
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/dsl-BIjVN1M0.d.mts +204 -0
  7. package/dist/dsl-BIjVN1M0.d.ts +204 -0
  8. package/dist/index.d.mts +131 -178
  9. package/dist/index.d.ts +131 -178
  10. package/dist/index.js +1506 -8
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +1479 -3
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/plugins/a11y-tree/index.d.mts +11 -0
  15. package/dist/plugins/a11y-tree/index.d.ts +11 -0
  16. package/dist/plugins/a11y-tree/index.js +190 -0
  17. package/dist/plugins/a11y-tree/index.js.map +1 -0
  18. package/dist/plugins/a11y-tree/index.mjs +155 -0
  19. package/dist/plugins/a11y-tree/index.mjs.map +1 -0
  20. package/dist/plugins/desktop-webview2/index.d.mts +14 -0
  21. package/dist/plugins/desktop-webview2/index.d.ts +14 -0
  22. package/dist/plugins/desktop-webview2/index.js +258 -0
  23. package/dist/plugins/desktop-webview2/index.js.map +1 -0
  24. package/dist/plugins/desktop-webview2/index.mjs +221 -0
  25. package/dist/plugins/desktop-webview2/index.mjs.map +1 -0
  26. package/dist/plugins/live-controller/index.d.mts +35 -0
  27. package/dist/plugins/live-controller/index.d.ts +35 -0
  28. package/dist/plugins/live-controller/index.js +303 -0
  29. package/dist/plugins/live-controller/index.js.map +1 -0
  30. package/dist/plugins/live-controller/index.mjs +261 -0
  31. package/dist/plugins/live-controller/index.mjs.map +1 -0
  32. package/dist/plugins/mock-ipc/index.d.mts +30 -0
  33. package/dist/plugins/mock-ipc/index.d.ts +30 -0
  34. package/dist/plugins/mock-ipc/index.js +210 -0
  35. package/dist/plugins/mock-ipc/index.js.map +1 -0
  36. package/dist/plugins/mock-ipc/index.mjs +181 -0
  37. package/dist/plugins/mock-ipc/index.mjs.map +1 -0
  38. package/dist/plugins/visual-diff/index.d.mts +30 -0
  39. package/dist/plugins/visual-diff/index.d.ts +30 -0
  40. package/dist/plugins/visual-diff/index.js +163 -0
  41. package/dist/plugins/visual-diff/index.js.map +1 -0
  42. package/dist/plugins/visual-diff/index.mjs +127 -0
  43. package/dist/plugins/visual-diff/index.mjs.map +1 -0
  44. package/docs/plugins.md +415 -0
  45. package/package.json +40 -2
  46. package/skills/agent-lens/SKILL.md +130 -43
  47. package/skills/agent-lens/examples/07-live-controller-interactive-loop.md +108 -0
  48. package/skills/agent-lens/examples/08-accessibility-semantic-inspection.md +80 -0
  49. package/skills/agent-lens/examples/09-visual-regression-and-pixel-diffing.md +66 -0
  50. package/skills/agent-lens/examples/10-authoring-custom-agent-plugins.md +85 -0
  51. package/skills/agent-lens/references/plugin-development.md +165 -0
package/README.md CHANGED
@@ -1,227 +1,331 @@
1
- <div align="center">
2
- <h1>๐Ÿ‘๏ธ AgentLens</h1>
3
- <p><b>Give your AI coding agent eyes.</b></p>
4
- <p>Visual self-check, responsive layout verification, and console crash detection before reporting back to humans.</p>
5
-
6
- [![npm version](https://img.shields.io/npm/v/@_deep4wee/agent-lens.svg?color=blue)](https://www.npmjs.com/package/@_deep4wee/agent-lens)
7
- [![npm downloads](https://img.shields.io/npm/dm/@_deep4wee/agent-lens.svg)](https://www.npmjs.com/package/@_deep4wee/agent-lens)
8
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/deep4wee/agent-lens/blob/main/LICENSE)
9
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg)](https://www.typescriptlang.org/)
10
- [![Playwright](https://img.shields.io/badge/Powered%20By-Playwright-orange.svg)](https://playwright.dev/)
11
- </div>
12
-
13
- ---
14
-
15
- ## ๐Ÿค” The Problem
16
-
17
- AI coding agents (like Cursor, Claude Code, Gemini CLI, or Roo) are great at writing code, but they are **blind**.
18
-
19
- When an agent builds a UI, it reports *"Done!"*, but it doesn't know if:
20
- - The CSS layout shifted or broken on mobile viewports.
21
- - The modal opened off-screen or clips behind another layer.
22
- - An unhandled JavaScript error or `undefined` prop just crashed the React tree.
23
-
24
- Humans are forced to manually open the browser, take screenshots, and tell the agent what to fix.
25
-
26
- ## ๐Ÿ’ก The Solution
27
-
28
- **AgentLens** is a visual testing harness built specifically for AI coding agents. It allows the agent to:
29
- 1. Write the frontend or desktop code.
30
- 2. **"See" the result immediately** using a one-shot `snap` command or scripted scenarios.
31
- 3. Catch silent console crashes, missing assets, and runtime errors.
32
- 4. Auto-clean temporary test files and cache so no corrupted state is left behind.
33
- 5. Fix its own mistakes *before* presenting the final result to the user!
34
-
35
- ---
36
-
37
- ## โœจ Features
38
-
39
- - โšก **Instant One-Shot Verification (`snap`)**: Verify any live URL across desktop and mobile in seconds without writing test files.
40
- - ๐ŸŒ **Network API Route Mocking**: Intercept REST/GraphQL calls (`mockRoutes` / `ctx.setMockRoute`) to test empty states, error boundaries, and edge cases without backend dependencies.
41
- - ๐Ÿš€ **Managed Process Lifecycle**: Auto-launch dev servers (`--start="npm run dev"`), wait for the port, run tests, and cleanly shut down the process tree.
42
- - ๐Ÿ“ธ **Multi-Viewport Snapshots**: Test Desktop, Tablet, Mobile, and Widescreen layouts simultaneously.
43
-
44
- - ๐Ÿ“ **Dynamic Auto-Resize (`resizeToFit`)**: Automatically fit the browser viewport tightly around any component to inspect it in isolation.
45
- - ๐ŸŽฌ **Burst Animations**: Capture frame-by-frame sequences of hover states, transitions, and dropdown menus.
46
- - ๐Ÿ”ด **Console Crash Tracker**: Automatically intercepts `console.error`, `console.warn`, and unhandled exceptions (`pageerror`) with stack traces.
47
- - ๐Ÿ–ฅ๏ธ **Native Desktop Testing**: Test compiled `.exe` binaries (WebView2 / Electron / .NET) over Chrome DevTools Protocol (CDP) with startup crash diagnostics.
48
- - ๐Ÿงน **Guaranteed Clean Teardown**: Built-in `setup()`, `teardown()`, and `--clean` flags that execute in a `finally` block even if the test fails.
49
- - ๐Ÿค– **Agent-First Markdown Reports**: Generates a clean `report.md` formatted for LLM reading tools, complete with checklists and embedded screenshot links.
50
-
51
- ---
52
-
53
- ## ๐Ÿš€ Quickstart
54
-
55
- ### 1. Instant One-Shot Check (`snap`)
56
-
57
- The fastest way to verify changes without writing any test files:
58
-
59
- ```bash
60
- # Run directly via npx:
61
- npx @_deep4wee/agent-lens snap --url=http://localhost:5173
62
-
63
- # Auto-start dev server, wait until ready, snap, and auto-terminate:
64
- npx @_deep4wee/agent-lens snap --start="npm run dev" --url=http://localhost:5173
65
-
66
- # Focus on a specific component:
67
- npx @_deep4wee/agent-lens snap --url=http://localhost:5173/settings --selector=".pricing-card"
68
- ```
69
-
70
- ### 2. Scripted Scenarios
71
-
72
- Install as a development dependency:
73
- ```bash
74
- npm install -D @_deep4wee/agent-lens
75
- ```
76
-
77
- Initialize starter scenario:
78
- ```bash
79
- npx agent-lens init
80
- ```
81
-
82
- Run a scenario:
83
- ```bash
84
- npx agent-lens --scenario=smoke --url=http://localhost:5173
85
- ```
86
-
87
- ---
88
-
89
- ## ๐Ÿ› ๏ธ API Reference (Scenario DSL)
90
-
91
- Write scenarios in `scenarios/<name>.scenario.ts`:
92
-
93
- ```typescript
94
- import { defineVisualTest, VIEWPORT_PRESETS, type TestContext } from 'agent-lens';
95
-
96
- export default defineVisualTest({
97
- id: 'checkout-flow',
98
- title: 'Checkout Flow Verification',
99
- route: '/checkout',
100
- viewports: [VIEWPORT_PRESETS.DEFAULT, VIEWPORT_PRESETS.MIN_SUPPORTED],
101
-
102
- // 1. Setup: Prepare clean test environment
103
- setup: async () => {
104
- // fs.mkdirSync('./tmp_test_data', { recursive: true });
105
- },
106
-
107
- // 2. Main Test Execution
108
- run: async (ctx: TestContext) => {
109
- // --- Navigation & Viewport ---
110
- await ctx.setPreset(VIEWPORT_PRESETS.DEFAULT);
111
- await ctx.capture('01_checkout_initial');
112
-
113
- // --- Mock Network API ---
114
- await ctx.setMockRoute('**/api/checkout/summary', { subtotal: 80, discount: 20, total: 60 });
115
-
116
- // --- Interaction ---
117
- await ctx.type('input[name="coupon"]', 'DISCOUNT2026');
118
- await ctx.click('button.apply-coupon');
119
- await ctx.wait(500);
120
-
121
- // --- Component Isolation ---
122
-
123
- await ctx.resizeToFit('.cart-summary', 15);
124
- await ctx.capture('02_cart_summary_fitted');
125
-
126
- // --- Assertions & DOM Inspection ---
127
- const totalText = await ctx.readText('.total-amount');
128
- ctx.log(`Verified total amount: ${totalText}`);
129
-
130
- // --- Check Console Errors ---
131
- const errors = ctx.getConsoleErrors();
132
- if (errors.length > 0) {
133
- ctx.log(`๐Ÿšจ UI errors detected: ${errors.length}`);
134
- }
135
- },
136
-
137
- // 3. Teardown: Guaranteed to execute even if run() crashes!
138
- teardown: async () => {
139
- // fs.rmSync('./tmp_test_data', { recursive: true, force: true });
140
- }
141
- });
142
- ```
143
-
144
- ---
145
-
146
- ## ๐Ÿ’ป CLI Flags Reference
147
-
148
- ```bash
149
- npx agent-lens [command] [options]
150
- ```
151
-
152
- | Flag | Description | Default |
153
- | :--- | :--- | :--- |
154
- | `snap` | Subcommand: Instant one-shot verification of a URL | โ€” |
155
- | `init` | Subcommand: Scaffold a starter `template.scenario.ts` | โ€” |
156
- | `--url=<url>` | Target URL to test (live dev server or preview) | *Auto-detected* |
157
- | `--start="<cmd>"` | Command to launch dev server/backend before test | โ€” |
158
- | `--start-cwd=<path>` | Directory to run `--start` in (e.g. `--start-cwd=./Frontend`) | *Auto-detected* |
159
- | `--clean-artifacts` | Purge previous test runs in `artifacts/` | `false` |
160
- | `--selector=<css>` | Component selector to focus on / resize-to-fit | โ€” |
161
- | `--viewports=<list>`| Viewport presets (`desktop,mobile,tablet` or `1200x800`) | `desktop,mobile` |
162
- | `--wait=<ms>` | Milliseconds to wait after page load before capture | `1000` |
163
- | `--scenario=<id>` | Name or prefix of scenario file to run | โ€” |
164
- | `--all` | Run all discovered scenarios | `false` |
165
- | `--mode=<mode>` | Engine mode: `preview` (Web/Live) or `desktop` (native .exe) | `preview` |
166
- | `--exe=<path>` | Path to compiled desktop executable for desktop mode | โ€” |
167
- | `--port=<port>` | CDP remote debugging port for desktop mode | `9222` |
168
- | `--build[=<cmd>]` | Build command to run before testing | `npm run build` |
169
- | `--clean=<paths>` | Comma-separated paths to purge upon test completion | โ€” |
170
- | `--folder=<path>` | Folder to store artifacts and reports (also `--outDir`) | `artifacts` |
171
- | `--headed` | Show Chromium browser window (for human debugging) | `false` |
172
- | `--detach` | Do not close browser or app after tests finish | `false` |
173
-
174
- > ๐Ÿ’ก **Tip for AI Agents:** AgentLens always maintains a persistent copy of the most recent report at `artifacts/latest/report.md`. You can inspect this file directly without needing to compute or match timestamped directory names.
175
-
176
- ---
177
-
178
- ## โš™๏ธ Configuration (`agent-lens.json`)
179
-
180
- You can define options globally in an `agent-lens.json` file in your repository root:
181
-
182
- ```json
183
- {
184
- "url": "http://localhost:5173",
185
- "startCommand": "npm run dev",
186
- "scenarios": "scenarios",
187
- "outDir": "visual-reports",
188
- "clean": ["./cache", "./tmp_test_data"],
189
- "autoBuild": false
190
- }
191
- ```
192
-
193
- Or under the `"agentLens"` property in your `package.json`:
194
-
195
- ```json
196
- {
197
- "agentLens": {
198
- "url": "http://localhost:3000",
199
- "scenarios": "tests/visual"
200
- }
201
- }
202
- ```
203
-
204
- ---
205
-
206
- ## ๐Ÿง  Equipping AI Agents (`SKILL.md`)
207
-
208
- When installed via NPM, AgentLens automatically copies the agent skill into your project's `.agents/skills/agent-lens/` folder. This equips agents (like Cursor, Gemini, Claude, and Roo) with the exact system instructions and example workflows needed to use AgentLens autonomously.
209
-
210
- Check the `skills/agent-lens/examples/` directory for detailed walkthroughs:
211
- - **[01-instant-verification-snap.md](skills/agent-lens/examples/01-instant-verification-snap.md)**: Zero-config quick checks.
212
- - **[02-dev-server-live-testing.md](skills/agent-lens/examples/02-dev-server-live-testing.md)**: Live dev server workflows.
213
- - **[03-component-isolation-and-animations.md](skills/agent-lens/examples/03-component-isolation-and-animations.md)**: Deep component and animation testing.
214
- - **[04-desktop-native-testing.md](skills/agent-lens/examples/04-desktop-native-testing.md)**: Native `.exe` and WebView2 testing.
215
- - **[05-clean-teardown-and-sandboxing.md](skills/agent-lens/examples/05-clean-teardown-and-sandboxing.md)**: Preventing leftover test data.
216
- - **[06-state-testing-with-mock-ipc.md](skills/agent-lens/examples/06-state-testing-with-mock-ipc.md)**: Empty states and error handling.
217
-
218
- ---
219
-
220
- ## ๐Ÿ“„ License & Disclaimer
221
-
222
- Released under the [MIT License](https://github.com/deep4wee/agent-lens/blob/main/LICENSE). Free for open-source and commercial use.
223
-
224
- > [!NOTE]
225
- > **Autonomous Agent Usage Disclaimer**: AgentLens is designed to execute commands, launch local dev servers, and interact with web browsers or desktop binaries as instructed by scripts or AI agents. The author and contributors assume no liability for any unintentional file modifications, port conflicts, process terminations, or data loss caused by autonomous agent actions or third-party code tested with this tool. Run agents and test scripts in appropriate development environments or containers.
226
-
227
- Copyright ยฉ 2026 [deep4wee](https://github.com/deep4wee).
1
+ <div align="center">
2
+ <h1>๐Ÿ‘๏ธ AgentLens</h1>
3
+ <p><b>Give your AI coding agent eyes and hands.</b></p>
4
+ <p>A Microkernel Agentic UI Platform for visual self-checks, responsive layout verification, interactive live control, accessibility inspection, and pixel regression testing before reporting back to humans.</p>
5
+
6
+ [![npm version](https://img.shields.io/npm/v/@_deep4wee/agent-lens.svg?color=blue)](https://www.npmjs.com/package/@_deep4wee/agent-lens)
7
+ [![npm downloads](https://img.shields.io/npm/dm/@_deep4wee/agent-lens.svg)](https://www.npmjs.com/package/@_deep4wee/agent-lens)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/deep4wee/agent-lens/blob/main/LICENSE)
9
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg)](https://www.typescriptlang.org/)
10
+ [![Playwright](https://img.shields.io/badge/Powered%20By-Playwright-orange.svg)](https://playwright.dev/)
11
+ </div>
12
+
13
+ ---
14
+
15
+ ## ๐Ÿค” The Problem
16
+
17
+ AI coding agents (such as Cursor, Claude Code, Gemini CLI, or Roo) are remarkably capable at writing code, but they are **blind**.
18
+
19
+ When an agent builds or refactors a user interface, it reports *"Done!"*, yet it cannot know if:
20
+ - The CSS layout shifted or broke on mobile viewports.
21
+ - The modal opened off-screen or clips behind another layer.
22
+ - An unhandled JavaScript runtime error or undefined prop crashed the React tree.
23
+ - Text-only reasoning models have no structured way to understand the interactive DOM hierarchy.
24
+
25
+ Humans are forced to manually launch browsers, take screenshots, and tell the agent what to fix.
26
+
27
+ ## ๐Ÿ’ก The Solution
28
+
29
+ **AgentLens** is a visual testing platform built specifically for AI coding agents. It provides a modular **Microkernel architecture** that enables agents to:
30
+ 1. Write frontend or desktop code.
31
+ 2. **"See" the result immediately** using one-shot `snap` commands or scripted scenarios.
32
+ 3. **Interact in real-time** via the persistent `live` controller loop with coordinate clicks and input typing.
33
+ 4. **"Read" semantic UI hierarchies** using the built-in accessibility tree plugin (essential for text-only LLMs).
34
+ 5. **Detect pixel-level visual regressions** using automated `pixelmatch` diffing.
35
+ 6. Intercept silent console crashes, network failures, and runtime exceptions.
36
+ 7. Author **1-file plugins on-the-fly** to solve project-specific constraints.
37
+ 8. Self-correct mistakes *before* presenting the final result to the user!
38
+
39
+ ---
40
+
41
+ ## ๐Ÿ—๏ธ Architecture: The Microkernel Platform
42
+
43
+ AgentLens separates the core execution engine from drivers, state bridges, and developer tools:
44
+
45
+ ```mermaid
46
+ flowchart TD
47
+ CLI["AgentLens CLI (snap / live / test)"] --> Core["AgentLens Core Microkernel Engine"]
48
+ Core --> Runner["Scenario Runner & Lifecycle Orchestrator"]
49
+ Core --> PM["PluginManager (JITI / Zero-Compile TS)"]
50
+
51
+ PM --> P1["๐Ÿ“ฆ desktop-webview2 (Native .exe & CDP)"]
52
+ PM --> P2["๐Ÿ“ฆ mock-ipc (Hybrid Desktop Bridge)"]
53
+ PM --> P3["๐Ÿš€ live-controller (Interactive CDP CLI & --full)"]
54
+ PM --> P4["โ™ฟ a11y-tree (Semantic Markdown for Text LLMs)"]
55
+ PM --> P5["๐ŸŽจ visual-diff (Pixelmatch Regression Diffing)"]
56
+ PM --> P6["๐Ÿ› ๏ธ Custom Workspace Plugins (.agent-lens/plugins/*.ts)"]
57
+
58
+ Runner --> Report["VisualReporter (artifacts/latest/report.md)"]
59
+ ```
60
+
61
+ ---
62
+
63
+ ## โœจ Features & Official Plugins
64
+
65
+ - โšก **Instant One-Shot Verification (`snap`)**: Verify any live URL across desktop and mobile in seconds without writing test files.
66
+ - ๐Ÿ“œ **Full-Page Screen Captures (`--full`)**: Capture entire scrollable page heights beyond the default viewport.
67
+ - ๐Ÿš€ **Interactive Live Controller (`live`)**: Persistent background browser session with sub-50ms command execution (`click <x> <y>`, `type <sel> <text>`, `snap --full`, `stop`).
68
+ - โ™ฟ **Semantic Accessibility Inspector (`a11y-tree`)**: Extracts clean Markdown accessibility trees (roles, names, states, focus) so text-only LLMs can "read" the UI layout.
69
+ - ๐ŸŽจ **Visual Regression Diffing (`visual-diff`)**: Automated pixel-by-pixel comparisons with baseline images using `pixelmatch` + `pngjs`, generating difference masks (`*_diff.png`) and changed pixel percentages.
70
+ - ๐Ÿ–ฅ๏ธ **Native Desktop Testing (`desktop-webview2`)**: Test compiled Windows `.exe` binaries (WebView2 / Electron / Photino) over CDP with process tree management (`treeKill`).
71
+ - ๐Ÿ“ฆ **Hybrid IPC Mock Bridge (`mock-ipc`)**: Intercept desktop IPC calls (`window.__mockIpc` and `window.external.sendMessage`) for error boundaries and offline states.
72
+ - ๐ŸŒ **Network API Route Mocking**: Intercept REST/GraphQL calls (`mockRoutes` / `ctx.setMockRoute`) without backend dependencies.
73
+ - ๐Ÿ”ด **Console Crash Tracker**: Intercepts `console.error`, `console.warn`, and unhandled exceptions (`pageerror`) with stack traces.
74
+ - ๐Ÿงน **Guaranteed Clean Teardown**: Built-in `setup()`, `teardown()`, and `--clean` flags that execute in a `finally` block even if the test fails.
75
+ - ๐Ÿค– **Agent-First Markdown Reports**: Produces a standardized `artifacts/latest/report.md` formatted for LLM file-reading tools.
76
+ - ๐Ÿ”Œ **Extensible Plugin System**: Agents can author custom 1-file plugins in `.agent-lens/plugins/` using modern TypeScript without compiling.
77
+
78
+ ---
79
+
80
+ ## ๐Ÿš€ Quickstart
81
+
82
+ ### 1. Instant One-Shot Check (`snap`)
83
+
84
+ The fastest way to verify changes without writing any test files:
85
+
86
+ ```bash
87
+ # Run directly via npx:
88
+ npx @_deep4wee/agent-lens snap --url=http://localhost:5173
89
+
90
+ # Capture full scrollable page:
91
+ npx @_deep4wee/agent-lens snap --url=http://localhost:5173 --full
92
+
93
+ # Auto-start dev server, wait until ready, snap, and auto-terminate:
94
+ npx @_deep4wee/agent-lens snap --start="npm run dev" --url=http://localhost:5173
95
+
96
+ # Focus on a specific component:
97
+ npx @_deep4wee/agent-lens snap --url=http://localhost:5173/settings --selector=".pricing-card"
98
+
99
+ # Extract semantic accessibility tree during snap:
100
+ npx @_deep4wee/agent-lens snap --url=http://localhost:5173 --plugin=a11y-tree
101
+ ```
102
+
103
+ ---
104
+
105
+ ### 2. Interactive Live Controller Loop (`live`)
106
+
107
+ Keep a browser running in the background and send commands step-by-step with sub-50ms latency:
108
+
109
+ ```bash
110
+ # 1. Start background live session:
111
+ npx agent-lens live start --url=http://localhost:5173
112
+
113
+ # 2. Click coordinates (for Vision AI models) or CSS selectors:
114
+ npx agent-lens live click 450 180
115
+ npx agent-lens live click "button.open-modal"
116
+
117
+ # 3. Fill in form fields:
118
+ npx agent-lens live type "input[name='email']" "agent@example.com"
119
+
120
+ # 4. Take live snapshots (updates artifacts/live/current.png):
121
+ npx agent-lens live snap step_02 --full
122
+
123
+ # 5. Stop session when done:
124
+ npx agent-lens live stop
125
+ ```
126
+
127
+ ---
128
+
129
+ ### 3. Scripted Scenarios
130
+
131
+ Install as a development dependency:
132
+ ```bash
133
+ npm install -D @_deep4wee/agent-lens
134
+ ```
135
+
136
+ Initialize starter scenario and mocks:
137
+ ```bash
138
+ npx agent-lens init
139
+ ```
140
+
141
+ Run a scenario:
142
+ ```bash
143
+ npx agent-lens --scenario=smoke --url=http://localhost:5173
144
+ ```
145
+
146
+ ---
147
+
148
+ ## ๐Ÿ› ๏ธ API Reference (Scenario DSL)
149
+
150
+ Write scenarios in `scenarios/<name>.scenario.ts`:
151
+
152
+ ```typescript
153
+ import { defineVisualTest, VIEWPORT_PRESETS, type TestContext } from 'agent-lens';
154
+
155
+ export default defineVisualTest({
156
+ id: 'checkout-flow',
157
+ title: 'Checkout Flow Verification',
158
+ route: '/checkout',
159
+ viewports: [VIEWPORT_PRESETS.DEFAULT, VIEWPORT_PRESETS.MIN_SUPPORTED],
160
+
161
+ // Enable official or custom plugins:
162
+ plugins: ['a11y-tree', 'visual-diff'],
163
+
164
+ // 1. Setup: Prepare clean test environment
165
+ setup: async () => {
166
+ // fs.mkdirSync('./tmp_test_data', { recursive: true });
167
+ },
168
+
169
+ // 2. Main Test Execution
170
+ run: async (ctx: TestContext) => {
171
+ // --- Navigation & Viewport ---
172
+ await ctx.setPreset(VIEWPORT_PRESETS.DEFAULT);
173
+ await ctx.capture('01_checkout_initial');
174
+
175
+ // --- Mock Network API ---
176
+ await ctx.setMockRoute('**/api/checkout/summary', { subtotal: 80, discount: 20, total: 60 });
177
+
178
+ // --- Interaction ---
179
+ await ctx.type('input[name="coupon"]', 'DISCOUNT2026');
180
+ await ctx.click('button.apply-coupon');
181
+ await ctx.wait(500);
182
+
183
+ // --- Component Isolation ---
184
+ await ctx.resizeToFit('.cart-summary', 15);
185
+ await ctx.capture('02_cart_summary_fitted');
186
+
187
+ // --- Semantic Accessibility Inspection (a11y-tree plugin) ---
188
+ const a11y = await (ctx as any).dumpAccessibilityTree({ compact: true });
189
+ ctx.log('Accessibility hierarchy captured.');
190
+
191
+ // --- Visual Regression Check (visual-diff plugin) ---
192
+ // await (ctx as any).captureAndCompare('03_checkout_final', 'baselines/checkout.png');
193
+
194
+ // --- Assertions & DOM Inspection ---
195
+ const totalText = await ctx.readText('.total-amount');
196
+ ctx.log(`Verified total amount: ${totalText}`);
197
+
198
+ // --- Check Console Errors ---
199
+ const errors = ctx.getConsoleErrors();
200
+ if (errors.length > 0) {
201
+ ctx.log(`๐Ÿšจ UI errors detected: ${errors.length}`);
202
+ }
203
+ },
204
+
205
+ // 3. Teardown: Guaranteed to execute even if run() crashes!
206
+ teardown: async () => {
207
+ // fs.rmSync('./tmp_test_data', { recursive: true, force: true });
208
+ }
209
+ });
210
+ ```
211
+
212
+ ---
213
+
214
+ ## ๐Ÿ’ป CLI Flags Reference
215
+
216
+ ```bash
217
+ npx agent-lens [command] [options]
218
+ ```
219
+
220
+ | Command / Flag | Description | Default |
221
+ | :--- | :--- | :--- |
222
+ | `snap` | Subcommand: Instant one-shot verification of a URL | โ€” |
223
+ | `live <action>` | Subcommand: Interactive controller (`start`, `click`, `type`, `snap`, `stop`) | โ€” |
224
+ | `init` | Subcommand: Scaffold starter `template.scenario.ts` and `mocks.ts` | โ€” |
225
+ | `--url=<url>` | Target URL to test (live dev server or preview) | *Auto-detected* |
226
+ | `--start="<cmd>"` | Command to launch dev server/backend before test | โ€” |
227
+ | `--start-cwd=<path>` | Directory to run `--start` in (e.g. `--start-cwd=./Frontend`) | *Auto-detected* |
228
+ | `--clean-artifacts` | Purge previous test runs in `artifacts/` | `false` |
229
+ | `--full` | Capture full scrollable page height instead of viewport | `false` |
230
+ | `--selector=<css>` | Component selector to focus on / resize-to-fit | โ€” |
231
+ | `--viewports=<list>`| Viewport presets (`desktop,mobile,tablet` or `1200x800`) | `desktop,mobile` |
232
+ | `--wait=<ms>` | Milliseconds to wait after page load before capture | `1000` |
233
+ | `--plugin=<list>` | Comma-separated plugins to load (`--plugin=a11y-tree,visual-diff`) | โ€” |
234
+ | `--scenario=<id>` | Name or prefix of scenario file to run | โ€” |
235
+ | `--all` | Run all discovered scenarios | `false` |
236
+ | `--mode=<mode>` | Engine mode: `preview` (Web/Live) or `desktop` (native .exe) | `preview` |
237
+ | `--exe=<path>` | Path to compiled desktop executable for desktop mode | โ€” |
238
+ | `--port=<port>` | CDP remote debugging port for desktop mode | `9222` |
239
+ | `--build[=<cmd>]` | Build command to run before testing | `npm run build` |
240
+ | `--clean=<paths>` | Comma-separated paths to purge upon test completion | โ€” |
241
+ | `--folder=<path>` | Folder to store artifacts and reports (also `--outDir`) | `artifacts` |
242
+ | `--headed` | Show Chromium browser window (for human debugging) | `false` |
243
+ | `--detach` | Do not close browser or app after tests finish | `false` |
244
+
245
+ > ๐Ÿ’ก **Tip for AI Agents:** AgentLens always maintains a persistent copy of the most recent report at `artifacts/latest/report.md`. You can inspect this file directly without needing to compute or match timestamped directory names.
246
+
247
+ ---
248
+
249
+ ## ๐Ÿ”Œ Developing Custom Plugins
250
+
251
+ AgentLens makes it effortless to author custom plugins. When an AI agent or developer faces unique project constraints (e.g., custom OAuth token injection, IndexedDB pre-population, or Canvas drawing assertions), they can create a 1-file plugin in `.agent-lens/plugins/<name>.ts`.
252
+
253
+ ```typescript
254
+ // .agent-lens/plugins/mock-auth.ts
255
+ import { definePlugin } from 'agent-lens';
256
+
257
+ export default definePlugin({
258
+ name: 'mock-auth',
259
+ onContextCreated: async (context) => {
260
+ await context.addInitScript(() => {
261
+ window.localStorage.setItem('auth_token', 'mock-agent-jwt');
262
+ });
263
+ }
264
+ });
265
+ ```
266
+
267
+ Execute immediately with zero build steps:
268
+ ```bash
269
+ npx agent-lens snap --plugin=mock-auth --url=http://localhost:5173
270
+ ```
271
+
272
+ ๐Ÿ‘‰ **Read the full [Plugin Development Guide](docs/plugins.md)** for interface specifications, lifecycle hooks, and complete recipes.
273
+
274
+ ---
275
+
276
+ ## โš™๏ธ Configuration (`agent-lens.json`)
277
+
278
+ You can define options globally in an `agent-lens.json` file in your repository root:
279
+
280
+ ```json
281
+ {
282
+ "url": "http://localhost:5173",
283
+ "startCommand": "npm run dev",
284
+ "scenarios": "scenarios",
285
+ "outDir": "visual-reports",
286
+ "clean": ["./cache", "./tmp_test_data"],
287
+ "plugins": ["a11y-tree"],
288
+ "autoBuild": false
289
+ }
290
+ ```
291
+
292
+ Or under the `"agentLens"` property in your `package.json`:
293
+
294
+ ```json
295
+ {
296
+ "agentLens": {
297
+ "url": "http://localhost:3000",
298
+ "scenarios": "tests/visual",
299
+ "plugins": ["a11y-tree", "visual-diff"]
300
+ }
301
+ }
302
+ ```
303
+
304
+ ---
305
+
306
+ ## ๐Ÿง  Equipping AI Agents (`SKILL.md`)
307
+
308
+ When installed via NPM, AgentLens automatically copies the agent skill into your project's `.agents/skills/agent-lens/` folder. This equips agents (like Cursor, Gemini, Claude, and Roo) with the exact system instructions and example workflows needed to use AgentLens autonomously.
309
+
310
+ Check the `skills/agent-lens/examples/` directory for detailed walkthroughs:
311
+ - **[01-instant-verification-snap.md](skills/agent-lens/examples/01-instant-verification-snap.md)**: Zero-config quick checks.
312
+ - **[02-dev-server-live-testing.md](skills/agent-lens/examples/02-dev-server-live-testing.md)**: Live dev server workflows.
313
+ - **[03-component-isolation-and-animations.md](skills/agent-lens/examples/03-component-isolation-and-animations.md)**: Deep component and animation testing.
314
+ - **[04-desktop-native-testing.md](skills/agent-lens/examples/04-desktop-native-testing.md)**: Native `.exe` and WebView2 testing.
315
+ - **[05-clean-teardown-and-sandboxing.md](skills/agent-lens/examples/05-clean-teardown-and-sandboxing.md)**: Preventing leftover test data.
316
+ - **[06-state-testing-with-mock-ipc.md](skills/agent-lens/examples/06-state-testing-with-mock-ipc.md)**: Empty states and error handling.
317
+ - **[07-live-controller-interactive-loop.md](skills/agent-lens/examples/07-live-controller-interactive-loop.md)**: Low-latency real-time control via CLI commands.
318
+ - **[08-accessibility-semantic-inspection.md](skills/agent-lens/examples/08-accessibility-semantic-inspection.md)**: Extracting UI hierarchies for text LLMs.
319
+ - **[09-visual-regression-and-pixel-diffing.md](skills/agent-lens/examples/09-visual-regression-and-pixel-diffing.md)**: Automated pixelmatch difference masks.
320
+ - **[10-authoring-custom-agent-plugins.md](skills/agent-lens/examples/10-authoring-custom-agent-plugins.md)**: Writing 1-file plugins on-the-fly.
321
+
322
+ ---
323
+
324
+ ## ๐Ÿ“„ License & Disclaimer
325
+
326
+ Released under the [MIT License](https://github.com/deep4wee/agent-lens/blob/main/LICENSE). Free for open-source and commercial use.
327
+
328
+ > [!NOTE]
329
+ > **Autonomous Agent Usage Disclaimer**: AgentLens is designed to execute commands, launch local dev servers, and interact with web browsers or desktop binaries as instructed by scripts or AI agents. The author and contributors assume no liability for any unintentional file modifications, port conflicts, process terminations, or data loss caused by autonomous agent actions or third-party code tested with this tool. Run agents and test scripts in appropriate development environments or containers.
330
+
331
+ Copyright ยฉ 2026 [deep4wee](https://github.com/deep4wee).