@_deep4wee/agent-lens 1.0.1 โ 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +227 -221
- package/dist/cli.d.mts +2 -1
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +255 -200
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +255 -205
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +32 -9
- package/dist/index.d.ts +32 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/skills/agent-lens/SKILL.md +24 -6
- package/skills/agent-lens/examples/06-state-testing-with-mock-ipc.md +13 -12
package/README.md
CHANGED
|
@@ -1,221 +1,227 @@
|
|
|
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
|
-
[](https://www.npmjs.com/package/@_deep4wee/agent-lens)
|
|
7
|
-
[](https://www.npmjs.com/package/@_deep4wee/agent-lens)
|
|
8
|
-
[](https://github.com/deep4wee/agent-lens/blob/main/LICENSE)
|
|
9
|
-
[](https://www.typescriptlang.org/)
|
|
10
|
-
[](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
|
|
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
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
await ctx.
|
|
115
|
-
|
|
116
|
-
// ---
|
|
117
|
-
await ctx.
|
|
118
|
-
await ctx.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
|
153
|
-
|
|
|
154
|
-
|
|
|
155
|
-
|
|
|
156
|
-
| `--
|
|
157
|
-
| `--
|
|
158
|
-
| `--
|
|
159
|
-
| `--
|
|
160
|
-
| `--
|
|
161
|
-
| `--
|
|
162
|
-
| `--
|
|
163
|
-
| `--
|
|
164
|
-
| `--
|
|
165
|
-
| `--
|
|
166
|
-
| `--
|
|
167
|
-
|
|
168
|
-
>
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
+
[](https://www.npmjs.com/package/@_deep4wee/agent-lens)
|
|
7
|
+
[](https://www.npmjs.com/package/@_deep4wee/agent-lens)
|
|
8
|
+
[](https://github.com/deep4wee/agent-lens/blob/main/LICENSE)
|
|
9
|
+
[](https://www.typescriptlang.org/)
|
|
10
|
+
[](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).
|
package/dist/cli.d.mts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
export { }
|
package/dist/cli.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
export { }
|