@_deep4wee/agent-lens 1.0.1 → 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.
- package/README.md +141 -31
- package/dist/cli.d.mts +2 -1
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +1169 -957
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1268 -974
- package/dist/cli.mjs.map +1 -1
- package/dist/dsl-BIjVN1M0.d.mts +204 -0
- package/dist/dsl-BIjVN1M0.d.ts +204 -0
- package/dist/index.d.mts +131 -155
- package/dist/index.d.ts +131 -155
- package/dist/index.js +1506 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1479 -3
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/a11y-tree/index.d.mts +11 -0
- package/dist/plugins/a11y-tree/index.d.ts +11 -0
- package/dist/plugins/a11y-tree/index.js +190 -0
- package/dist/plugins/a11y-tree/index.js.map +1 -0
- package/dist/plugins/a11y-tree/index.mjs +155 -0
- package/dist/plugins/a11y-tree/index.mjs.map +1 -0
- package/dist/plugins/desktop-webview2/index.d.mts +14 -0
- package/dist/plugins/desktop-webview2/index.d.ts +14 -0
- package/dist/plugins/desktop-webview2/index.js +258 -0
- package/dist/plugins/desktop-webview2/index.js.map +1 -0
- package/dist/plugins/desktop-webview2/index.mjs +221 -0
- package/dist/plugins/desktop-webview2/index.mjs.map +1 -0
- package/dist/plugins/live-controller/index.d.mts +35 -0
- package/dist/plugins/live-controller/index.d.ts +35 -0
- package/dist/plugins/live-controller/index.js +303 -0
- package/dist/plugins/live-controller/index.js.map +1 -0
- package/dist/plugins/live-controller/index.mjs +261 -0
- package/dist/plugins/live-controller/index.mjs.map +1 -0
- package/dist/plugins/mock-ipc/index.d.mts +30 -0
- package/dist/plugins/mock-ipc/index.d.ts +30 -0
- package/dist/plugins/mock-ipc/index.js +210 -0
- package/dist/plugins/mock-ipc/index.js.map +1 -0
- package/dist/plugins/mock-ipc/index.mjs +181 -0
- package/dist/plugins/mock-ipc/index.mjs.map +1 -0
- package/dist/plugins/visual-diff/index.d.mts +30 -0
- package/dist/plugins/visual-diff/index.d.ts +30 -0
- package/dist/plugins/visual-diff/index.js +163 -0
- package/dist/plugins/visual-diff/index.js.map +1 -0
- package/dist/plugins/visual-diff/index.mjs +127 -0
- package/dist/plugins/visual-diff/index.mjs.map +1 -0
- package/docs/plugins.md +415 -0
- package/package.json +40 -2
- package/skills/agent-lens/SKILL.md +142 -37
- package/skills/agent-lens/examples/06-state-testing-with-mock-ipc.md +13 -12
- package/skills/agent-lens/examples/07-live-controller-interactive-loop.md +108 -0
- package/skills/agent-lens/examples/08-accessibility-semantic-inspection.md +80 -0
- package/skills/agent-lens/examples/09-visual-regression-and-pixel-diffing.md +66 -0
- package/skills/agent-lens/examples/10-authoring-custom-agent-plugins.md +85 -0
- package/skills/agent-lens/references/plugin-development.md +165 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# 🔌 Reference: Authoring AgentLens Plugins On-The-Fly
|
|
2
|
+
|
|
3
|
+
This reference guide is designed for **AI coding agents** working with AgentLens. When you encounter a project constraint that cannot be met with default flags or DSL actions, **do not attempt fragile workarounds**. Instead, write a 1-file AgentLens plugin.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ⚡ When Should You (The Agent) Write a Plugin?
|
|
8
|
+
|
|
9
|
+
Write a custom plugin when:
|
|
10
|
+
1. **Authentication / Session Gate**: The application requires pre-set `localStorage`, cookies, or headers to access pages without going through an interactive OAuth/login flow.
|
|
11
|
+
2. **Custom Assertions**: You need to verify custom DOM states, Canvas/WebGL rendering, CSS animations, or WebWorker states.
|
|
12
|
+
3. **Database / File Seeding**: You need to initialize a mock database, seed test files, or clear temporary caches in `setup()`, and guarantee cleanup in `teardown()`.
|
|
13
|
+
4. **Third-Party Service Mocking**: You need to intercept WebSockets, Server-Sent Events, or specific IPC bridge protocols.
|
|
14
|
+
5. **Specialized Reporting**: You want to compute custom metrics (bundle size, accessibility score, custom element count) and output them directly into `report.md`.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 📁 Where to Put Your Plugin
|
|
19
|
+
|
|
20
|
+
AgentLens automatically discovers plugins placed in:
|
|
21
|
+
- `.agent-lens/plugins/<name>.ts`
|
|
22
|
+
- `plugins/<name>.ts`
|
|
23
|
+
|
|
24
|
+
Because AgentLens uses `jiti`, you can write modern TypeScript directly without compiling to JavaScript!
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 🧩 The 1-File Plugin Template
|
|
29
|
+
|
|
30
|
+
Create `.agent-lens/plugins/my-feature.ts`:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { definePlugin, type AgentLensPlugin } from 'agent-lens';
|
|
34
|
+
|
|
35
|
+
export const myFeaturePlugin: AgentLensPlugin = definePlugin({
|
|
36
|
+
name: 'my-feature',
|
|
37
|
+
version: '1.0.0',
|
|
38
|
+
|
|
39
|
+
// 1. Setup: Prepare environment or seed files before browser launch
|
|
40
|
+
setup: async (hookContext) => {
|
|
41
|
+
hookContext.state.set('startTime', Date.now());
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
// 2. Injected into browser before any scripts run (localStorage, cookies, headers)
|
|
45
|
+
onContextCreated: async (context, hookContext) => {
|
|
46
|
+
await context.addInitScript(() => {
|
|
47
|
+
// Runs in browser window context
|
|
48
|
+
window.localStorage.setItem('AUTH_TOKEN', 'mock-token-xyz');
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
// 3. Extend ctx: Add custom helper methods accessible inside scenario run(ctx)
|
|
53
|
+
extendContext: (_ctx, page, hookContext) => {
|
|
54
|
+
return {
|
|
55
|
+
myCustomAction: async (value: string) => {
|
|
56
|
+
await page.evaluate((v) => console.log('Action triggered:', v), value);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
// 4. Enrich report.md: Add custom markdown tables or checklists
|
|
62
|
+
onAfterRun: async (reportData, hookContext) => {
|
|
63
|
+
if (!reportData.customSections) return;
|
|
64
|
+
const elapsed = Date.now() - ((hookContext.state.get('startTime') as number) || Date.now());
|
|
65
|
+
|
|
66
|
+
reportData.customSections.push({
|
|
67
|
+
title: '🎯 My Custom Verification',
|
|
68
|
+
content: `Total plugin execution time: **${elapsed}ms**\n\n- [x] Custom assertion passed successfully`
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
// 5. Teardown: Always executes in finally block
|
|
73
|
+
teardown: async (hookContext) => {
|
|
74
|
+
// Clean up temporary files, reset state
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export default myFeaturePlugin;
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 🚀 How to Execute Your Plugin
|
|
84
|
+
|
|
85
|
+
### Option A: Via Quick Snap CLI
|
|
86
|
+
```bash
|
|
87
|
+
npx agent-lens snap --plugin=my-feature --url=http://localhost:5173
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Option B: In a Scripted Scenario
|
|
91
|
+
```typescript
|
|
92
|
+
import { defineVisualTest } from 'agent-lens';
|
|
93
|
+
import myFeaturePlugin from '../.agent-lens/plugins/my-feature';
|
|
94
|
+
|
|
95
|
+
export default defineVisualTest({
|
|
96
|
+
id: 'custom-check',
|
|
97
|
+
plugins: [myFeaturePlugin], // Pass plugin instance or string name
|
|
98
|
+
run: async (ctx) => {
|
|
99
|
+
// Call custom method added by extendContext:
|
|
100
|
+
await (ctx as any).myCustomAction('Hello from Agent!');
|
|
101
|
+
await ctx.capture('01_verified');
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 🛠️ Common Plugin Recipes for Agents
|
|
109
|
+
|
|
110
|
+
### Recipe 1: Pre-Populating LocalStorage / Redux / Zustand State
|
|
111
|
+
```typescript
|
|
112
|
+
// .agent-lens/plugins/seed-store.ts
|
|
113
|
+
import { definePlugin } from 'agent-lens';
|
|
114
|
+
|
|
115
|
+
export default definePlugin({
|
|
116
|
+
name: 'seed-store',
|
|
117
|
+
onContextCreated: async (context) => {
|
|
118
|
+
await context.addInitScript(() => {
|
|
119
|
+
window.localStorage.setItem('user-settings', JSON.stringify({
|
|
120
|
+
theme: 'dark',
|
|
121
|
+
onboardingCompleted: true,
|
|
122
|
+
features: { betaAccess: true }
|
|
123
|
+
}));
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Recipe 2: Intercepting WebSocket or GraphQL Subscriptions
|
|
130
|
+
```typescript
|
|
131
|
+
// .agent-lens/plugins/mock-ws.ts
|
|
132
|
+
import { definePlugin } from 'agent-lens';
|
|
133
|
+
|
|
134
|
+
export default definePlugin({
|
|
135
|
+
name: 'mock-ws',
|
|
136
|
+
onContextCreated: async (context) => {
|
|
137
|
+
await context.addInitScript(() => {
|
|
138
|
+
// Mock global WebSocket if needed
|
|
139
|
+
(window as any).__MOCK_WS_CONNECTED = true;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Recipe 3: Checking Element Visual Dimensions (No Layout Overflow)
|
|
146
|
+
```typescript
|
|
147
|
+
// .agent-lens/plugins/layout-checker.ts
|
|
148
|
+
import { definePlugin } from 'agent-lens';
|
|
149
|
+
|
|
150
|
+
export default definePlugin({
|
|
151
|
+
name: 'layout-checker',
|
|
152
|
+
extendContext: (_ctx, page) => {
|
|
153
|
+
return {
|
|
154
|
+
assertNoHorizontalScroll: async () => {
|
|
155
|
+
const hasScroll = await page.evaluate(() => {
|
|
156
|
+
return document.documentElement.scrollWidth > window.innerWidth;
|
|
157
|
+
});
|
|
158
|
+
if (hasScroll) {
|
|
159
|
+
throw new Error('❌ Detected unwanted horizontal scrolling! CSS layout overflow.');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
```
|