@presto1314w/vite-devtools-browser 0.1.3 → 0.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 CHANGED
@@ -1,14 +1,70 @@
1
1
  # vite-browser
2
2
 
3
- Agent Skill for AI coding assistants to debug Vite applications with structured access to Vue/React/Svelte runtime state. The CLI is the supporting runtime used by the skill for component trees, store/router inspection, logs, network traces, screenshots, and scripted page evaluation.
3
+ `vite-browser` is a runtime diagnostics toolchain for Vite applications.
4
4
 
5
- ## Skills
5
+ It gives agents and developers structured access to:
6
+
7
+ - Vue, React, and Svelte runtime state
8
+ - Vite HMR activity and runtime health
9
+ - event-window correlation between current errors and recent hot updates
10
+ - rule-based HMR diagnosis with confidence levels
11
+ - module graph snapshots and diffs
12
+ - mapped error output with optional source snippets
13
+ - network, logs, screenshots, and page evaluation
14
+
15
+ It ships in two forms:
16
+
17
+ - Agent Skill: scenario-based debugging workflows for coding assistants
18
+ - CLI Runtime (`@presto1314w/vite-devtools-browser`): structured shell commands for local Vite debugging
19
+
20
+ Current documented baseline: `v0.2.0`.
21
+
22
+ ## What's New In v0.2
23
+
24
+ `v0.2.0` moves `vite-browser` from snapshot-style inspection toward runtime diagnosis:
25
+
26
+ - browser/runtime events are captured into a daemon-side event queue
27
+ - `correlate errors` links the current error to recent HMR-updated modules
28
+ - `diagnose hmr` turns runtime, trace, and error signals into structured findings
29
+ - skills and CLI flows now route more directly to runtime triage instead of raw log inspection
30
+
31
+ ## Built For Agents
32
+
33
+ `vite-browser` is designed for agent workflows as much as local debugging.
34
+
35
+ Models do not work well with a DevTools panel that has to be visually inspected step by step. They work much better when runtime signals are exposed as structured commands that can be queried, compared, and chained in a loop. `vite-browser` turns framework state, Vite runtime status, HMR activity, module graph changes, mapped errors, logs, and network activity into terminal output that an agent can actually reason about.
36
+
37
+ Under the hood, each command is a one-shot request against a long-lived browser daemon. That keeps the CLI simple for users while letting agent loops inspect a running app repeatedly without having to manage browser lifecycle on every step.
38
+
39
+ ## Why vite-browser
40
+
41
+ Most browser CLIs are optimized for automation. Most framework devtools are optimized for humans in a GUI.
42
+
43
+ `vite-browser` is optimized for structured Vite runtime debugging:
44
+
45
+ - it can inspect framework state like a devtools bridge
46
+ - it can explain Vite-specific behavior like HMR updates and module graph changes
47
+ - it can correlate recent updates with current failures
48
+ - it returns structured text that AI agents can consume directly in loops
49
+
50
+ ## Positioning
51
+
52
+ | Tool | Best for | Notable gap compared with `vite-browser` |
53
+ | --- | --- | --- |
54
+ | `agent-browser` | general browser automation | not focused on Vite runtime diagnostics |
55
+ | `next-browser` | Next.js + React debugging | not designed as a Vite runtime tool |
56
+ | `vite-plugin-vue-mcp` | Vue MCP integration inside Vite | plugin/MCP-first, not a standalone diagnostics CLI |
57
+ | `vite-browser` | Vite runtime diagnostics for agents and developers | browser lifecycle coverage still being expanded |
58
+
59
+ ## Install
60
+
61
+ ### Install Skill
6
62
 
7
63
  ```bash
8
64
  npx skills add MapleCity1314/vite-browser
9
65
  ```
10
66
 
11
- ## CLI Installation (Optional)
67
+ ### Install CLI
12
68
 
13
69
  ```bash
14
70
  npm install -g @presto1314w/vite-devtools-browser
@@ -18,100 +74,217 @@ npx playwright install chromium
18
74
  ## Quick Start
19
75
 
20
76
  ```bash
21
- # Start your Vite dev server
22
- cd my-vue-app
77
+ # terminal A: start Vite app
78
+ cd my-app
23
79
  npm run dev
24
80
 
25
- # In another terminal
81
+ # terminal B: inspect runtime
26
82
  vite-browser open http://localhost:5173
27
- vite-browser detect # vue@3.5.29 / react@19.x / svelte@x
28
- vite-browser vue tree # Vue component tree
29
- vite-browser react tree # React component tree
30
- vite-browser svelte tree # Svelte component tree (best effort)
31
- vite-browser screenshot # Take screenshot
32
- vite-browser logs # Console logs
33
- vite-browser network # Network requests
83
+ vite-browser detect
84
+ vite-browser vite runtime
85
+ vite-browser errors --mapped --inline-source
86
+ vite-browser correlate errors --mapped --window 5000
87
+ vite-browser diagnose hmr --limit 50
88
+ vite-browser vite hmr trace --limit 20
89
+ vite-browser vite module-graph trace --limit 50
90
+ vite-browser network
34
91
  vite-browser close
35
92
  ```
36
93
 
37
- ## Features
94
+ For component/state debugging, then branch into framework-specific commands:
38
95
 
39
- - Framework Detection: Auto-detect Vue, React, Svelte and versions (best effort)
40
- - Vue DevTools: Component tree, props, state, computed properties, source locations
41
- - React DevTools: Component tree + component inspection (props/hooks/state/context)
42
- - Svelte Support: Component tree + component detail inspection when runtime metadata is available
43
- - Pinia Integration: Inspect store state and getters
44
- - Vue Router: Current route, params, query, all routes
45
- - Network Monitoring: Track requests, headers, bodies, and response payloads
46
- - Console Logs: Capture console.log, warn, error, debug
47
- - Screenshots: Full-page PNG screenshots
48
- - JavaScript Evaluation: Run arbitrary JS in page context
49
- - Vite Integration: Error tracking, HMR monitoring
96
+ ```bash
97
+ vite-browser vue tree
98
+ vite-browser vue pinia
99
+ vite-browser vue router
100
+ vite-browser react tree
101
+ vite-browser svelte tree
102
+ ```
50
103
 
51
- ## Commands
104
+ ## What It Looks Like
52
105
 
53
- ### Browser Control
54
106
  ```bash
55
- vite-browser open <url> # Launch browser and navigate
56
- vite-browser close # Close browser and daemon
57
- vite-browser goto <url> # Navigate to URL
58
- vite-browser back # Go back
59
- vite-browser reload # Reload page
107
+ $ vite-browser vite runtime
108
+ # Vite Runtime
109
+ URL: http://localhost:5173/
110
+ Framework: vue
111
+ Vite Client: loaded
112
+ HMR Socket: open
113
+ Error Overlay: none
114
+ Tracked HMR Events: 3
115
+
116
+ $ vite-browser vite hmr trace --limit 5
117
+ # HMR Trace
118
+ [12:34:10] connected [vite] connected.
119
+ [12:34:15] update /src/App.vue
120
+
121
+ $ vite-browser errors --mapped --inline-source
122
+ Failed to resolve import "./missing"
123
+
124
+ # Mapped Stack
125
+ - http://localhost:5173/src/main.ts:12:4 -> /src/main.ts:12:4
126
+ 12 | import "./missing"
127
+
128
+ $ vite-browser correlate errors --mapped --window 5000
129
+ # Error Correlation
130
+ ## Current Error
131
+ TypeError: boom at /src/App.tsx:4:2
132
+
133
+ ## Correlation
134
+ Confidence: high
135
+ HMR update observed within 5000ms of the current error
136
+ Matching modules: /src/App.tsx
137
+
138
+ $ vite-browser diagnose hmr --limit 50
139
+ # HMR Diagnosis
140
+ ## missing-module
141
+ Status: fail
142
+ Confidence: high
143
+ A module import failed to resolve during HMR.
144
+ Suggestion: Verify the import path, file extension, alias configuration, and whether the module exists on disk.
60
145
  ```
61
146
 
62
- ### Framework Detection
147
+ ## Core Capabilities
148
+
149
+ - Framework detection: Vue/React/Svelte best-effort detection and version hinting
150
+ - Vue runtime inspection: component tree/details, Pinia stores/getters, Vue Router state
151
+ - React runtime inspection: component tree/details (props/state/hooks/context/source)
152
+ - Svelte runtime inspection: component tree/details when metadata is available
153
+ - Vite runtime diagnostics:
154
+ - runtime status summary
155
+ - HMR summary/timeline/clear
156
+ - module-graph snapshot/diff/clear
157
+ - error/HMR correlation over recent event windows
158
+ - rule-based HMR diagnosis with confidence levels
159
+ - source-mapped errors with optional inline source snippet
160
+ - Debug utilities: console logs, network tracing, screenshot, page `eval`
161
+
162
+ ## Recommended Workflows
163
+
164
+ ### Runtime/HMR triage
165
+
166
+ ```bash
167
+ vite-browser vite runtime
168
+ vite-browser errors --mapped --inline-source
169
+ vite-browser correlate errors --mapped --window 5000
170
+ vite-browser diagnose hmr --limit 50
171
+ vite-browser vite hmr trace --limit 50
172
+ vite-browser vite module-graph trace --limit 200
173
+ ```
174
+
175
+ ### Data/API triage
176
+
177
+ ```bash
178
+ vite-browser errors --mapped
179
+ vite-browser logs
180
+ vite-browser network
181
+ vite-browser network <idx>
182
+ vite-browser eval '<state probe>'
183
+ ```
184
+
185
+ ### Component/state triage
186
+
63
187
  ```bash
64
- vite-browser detect # Detect framework and version
188
+ vite-browser detect
189
+ vite-browser vue tree
190
+ vite-browser vue pinia
191
+ vite-browser vue router
192
+ vite-browser react tree
193
+ vite-browser svelte tree
65
194
  ```
66
195
 
67
- ### Vue DevTools
196
+ ## Current Boundaries
197
+
198
+ `vite-browser` v0.2 is strong at:
199
+
200
+ - surfacing runtime state as structured shell output
201
+ - linking current errors to recent HMR/module activity
202
+ - detecting several common HMR failure patterns quickly
203
+
204
+ It is not yet a full propagation-trace engine. In particular, it does not reliably infer deep chains like `store -> component A -> component B -> error` across arbitrary component graphs.
205
+
206
+ ## Command Reference
207
+
208
+ ### Browser
209
+
68
210
  ```bash
69
- vite-browser vue tree # Show component tree
70
- vite-browser vue tree <id> # Inspect component details
71
- vite-browser vue pinia # List all Pinia stores
72
- vite-browser vue pinia <store> # Inspect specific store
73
- vite-browser vue router # Show router information
211
+ vite-browser open <url> [--cookies-json <file>]
212
+ vite-browser close
213
+ vite-browser goto <url>
214
+ vite-browser back
215
+ vite-browser reload
74
216
  ```
75
217
 
76
- ### React DevTools
218
+ ### Framework
219
+
77
220
  ```bash
78
- vite-browser react tree # Show React component tree
79
- vite-browser react tree <id> # Inspect props/hooks/state/context/source
221
+ vite-browser detect
222
+ vite-browser vue tree [id]
223
+ vite-browser vue pinia [store]
224
+ vite-browser vue router
225
+ vite-browser react tree [id]
226
+ vite-browser svelte tree [id]
80
227
  ```
81
228
 
82
- ### Svelte
229
+ ### Vite Runtime
230
+
83
231
  ```bash
84
- vite-browser svelte tree # Show Svelte component tree
85
- vite-browser svelte tree <id> # Inspect Svelte component details
232
+ vite-browser vite restart
233
+ vite-browser vite runtime
234
+ vite-browser vite hmr
235
+ vite-browser vite hmr trace [--limit <n>]
236
+ vite-browser vite hmr clear
237
+ vite-browser vite module-graph [--filter <txt>] [--limit <n>]
238
+ vite-browser vite module-graph trace [--filter <txt>] [--limit <n>]
239
+ vite-browser vite module-graph clear
240
+ vite-browser errors
241
+ vite-browser errors --mapped
242
+ vite-browser errors --mapped --inline-source
243
+ vite-browser correlate errors [--window <ms>]
244
+ vite-browser correlate errors --mapped --inline-source
245
+ vite-browser diagnose hmr [--window <ms>] [--limit <n>]
86
246
  ```
87
247
 
88
- ### Debugging
248
+ ### Utilities
249
+
89
250
  ```bash
90
- vite-browser screenshot # Take full-page screenshot
91
- vite-browser eval <script> # Run JavaScript in page
92
- vite-browser logs # Show console logs
93
- vite-browser errors # Show Vite errors
94
- vite-browser network # List network requests
95
- vite-browser network <idx> # Inspect specific request
251
+ vite-browser logs
252
+ vite-browser network [idx]
253
+ vite-browser screenshot
254
+ vite-browser eval <script>
96
255
  ```
97
256
 
98
- ## Architecture
257
+ ## Skill Packs
99
258
 
100
- - Daemon + Socket: Background process with socket communication
101
- - Playwright: Headed Chromium browser
102
- - One Browser, One Page: Single persistent browser instance
103
- - Auto-start: Daemon starts automatically on first command
259
+ The entry skill routes to specialized workflows:
104
260
 
105
- ## Requirements
261
+ - `skills/vite-browser-core-debug/SKILL.md`
262
+ - `skills/vite-browser-runtime-diagnostics/SKILL.md`
263
+ - `skills/vite-browser-network-regression/SKILL.md`
264
+ - `skills/vite-browser-release-smoke/SKILL.md`
106
265
 
107
- - Node.js 20+
108
- - Chromium (via Playwright)
109
- - Vite dev server running
110
- - Vue/React/Svelte app for framework-specific commands
266
+ Router definition: [skills/SKILL.md](./skills/SKILL.md)
111
267
 
112
- ## Documentation
268
+ ## Local Development
269
+
270
+ ```bash
271
+ pnpm install
272
+ pnpm build
273
+ pnpm test
274
+ pnpm test:coverage
275
+ pnpm test:evals
276
+ pnpm test:evals:e2e
277
+ ```
278
+
279
+ ## Discovery
280
+
281
+ If you want to introduce the project to new users, start with the launch kit in [docs/launch-kit.md](./docs/launch-kit.md).
282
+
283
+ ## Requirements
113
284
 
114
- See [SKILL.md](./skills/SKILL.md) for complete command reference and usage examples.
285
+ - Node.js `>=20`
286
+ - Chromium installed via Playwright
287
+ - Running Vite dev server
115
288
 
116
289
  ## License
117
290
 
package/dist/browser.d.ts CHANGED
@@ -1,9 +1,48 @@
1
+ import { type BrowserContext, type Page } from "playwright";
2
+ import { resolveViaSourceMap } from "./sourcemap.js";
3
+ import { EventQueue } from "./event-queue.js";
4
+ type HmrEventType = "connecting" | "connected" | "update" | "full-reload" | "error" | "log";
5
+ export type HmrEvent = {
6
+ timestamp: number;
7
+ type: HmrEventType;
8
+ message: string;
9
+ path?: string;
10
+ };
11
+ export type RuntimeSnapshot = {
12
+ url: string;
13
+ hasViteClient: boolean;
14
+ wsState: string;
15
+ hasErrorOverlay: boolean;
16
+ timestamp: number;
17
+ };
18
+ export type ModuleRow = {
19
+ url: string;
20
+ initiator: string;
21
+ durationMs: number;
22
+ };
23
+ export type ModuleGraphMode = "snapshot" | "trace" | "clear";
24
+ export declare function setEventQueue(queue: EventQueue): void;
25
+ export declare function getEventQueue(): EventQueue | null;
26
+ export declare function getCurrentPage(): Page | null;
27
+ /**
28
+ * Flush browser events into daemon event queue
29
+ */
30
+ export declare function flushBrowserEvents(currentPage: Page, queue: EventQueue): Promise<void>;
1
31
  export declare function open(url: string | undefined): Promise<void>;
2
32
  export declare function cookies(cookies: {
3
33
  name: string;
4
34
  value: string;
5
35
  }[], domain: string): Promise<number>;
6
36
  export declare function close(): Promise<void>;
37
+ export declare function contextUsable(current: Pick<BrowserContext, "pages"> | null): current is Pick<BrowserContext, "pages">;
38
+ export declare function isClosedTargetError(error: unknown): boolean;
39
+ export declare function recordConsoleMessage(logs: string[], events: HmrEvent[], type: string, message: string, maxLogs?: number, maxEvents?: number): void;
40
+ export declare function parseViteLog(message: string): HmrEvent;
41
+ export declare function normalizeLimit(limit: number, fallback: number, max: number): number;
42
+ export declare function formatRuntimeStatus(runtime: RuntimeSnapshot, currentFramework: string, events: HmrEvent[]): string;
43
+ export declare function formatHmrTrace(mode: "summary" | "trace", events: HmrEvent[], limit: number): string;
44
+ export declare function formatModuleGraphSnapshot(rows: ModuleRow[], filter?: string, limit?: number): string;
45
+ export declare function formatModuleGraphTrace(currentUrls: string[], previousUrls: Set<string> | null, filter?: string, limit?: number): string;
7
46
  export declare function goto(url: string): Promise<string>;
8
47
  export declare function back(): Promise<void>;
9
48
  export declare function reload(): Promise<string>;
@@ -17,9 +56,11 @@ export declare function viteRestart(): Promise<string>;
17
56
  export declare function viteHMR(): Promise<string>;
18
57
  export declare function viteRuntimeStatus(): Promise<string>;
19
58
  export declare function viteHMRTrace(mode: "summary" | "trace" | "clear", limit?: number): Promise<string>;
20
- export declare function viteModuleGraph(filter?: string, limit?: number, mode?: "snapshot" | "trace" | "clear"): Promise<string>;
59
+ export declare function viteModuleGraph(filter?: string, limit?: number, mode?: ModuleGraphMode): Promise<string>;
21
60
  export declare function errors(mapped?: boolean, inlineSource?: boolean): Promise<string>;
22
61
  export declare function logs(): Promise<string>;
23
62
  export declare function screenshot(): Promise<string>;
24
63
  export declare function evaluate(script: string): Promise<string>;
25
64
  export declare function network(idx?: number): Promise<string>;
65
+ export declare function mapStackTrace(stack: string, origin: string, inlineSource?: boolean, resolver?: typeof resolveViaSourceMap): Promise<string>;
66
+ export {};