agent-dbg 0.1.0 → 0.1.2
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/.claude/settings.local.json +7 -5
- package/.claude/skills/agent-dbg/SKILL.md +116 -0
- package/.claude/skills/agent-dbg/references/commands.md +173 -0
- package/.vscode/launch.json +19 -0
- package/CLAUDE.md +2 -2
- package/PROGRESS.md +91 -91
- package/README.md +45 -17
- package/{ndbg-spec.md → SPEC.md} +152 -152
- package/dist/main.js +12500 -0
- package/package.json +3 -3
- package/src/cdp/client.ts +18 -4
- package/src/cdp/logger.ts +69 -0
- package/src/cli/parser.ts +54 -43
- package/src/commands/attach.ts +2 -2
- package/src/commands/blackbox-ls.ts +1 -1
- package/src/commands/blackbox-rm.ts +3 -3
- package/src/commands/blackbox.ts +2 -2
- package/src/commands/break-ls.ts +3 -2
- package/src/commands/break-rm.ts +2 -2
- package/src/commands/break-toggle.ts +2 -2
- package/src/commands/break.ts +46 -17
- package/src/commands/breakable.ts +2 -2
- package/src/commands/catch.ts +2 -2
- package/src/commands/console.ts +1 -1
- package/src/commands/continue.ts +5 -18
- package/src/commands/eval.ts +2 -2
- package/src/commands/exceptions.ts +1 -1
- package/src/commands/hotpatch.ts +2 -2
- package/src/commands/launch.ts +7 -11
- package/src/commands/logpoint.ts +7 -6
- package/src/commands/logs.ts +116 -0
- package/src/commands/pause.ts +5 -18
- package/src/commands/print-state.ts +85 -0
- package/src/commands/props.ts +2 -2
- package/src/commands/restart-frame.ts +1 -1
- package/src/commands/restart.ts +42 -0
- package/src/commands/run-to.ts +7 -20
- package/src/commands/scripts.ts +1 -1
- package/src/commands/search.ts +4 -3
- package/src/commands/set-return.ts +2 -2
- package/src/commands/set.ts +3 -3
- package/src/commands/source.ts +3 -2
- package/src/commands/sourcemap.ts +1 -1
- package/src/commands/stack.ts +1 -1
- package/src/commands/state.ts +3 -73
- package/src/commands/status.ts +3 -2
- package/src/commands/step.ts +5 -18
- package/src/commands/vars.ts +3 -1
- package/src/daemon/entry.ts +16 -6
- package/src/daemon/paths.ts +6 -2
- package/src/daemon/server.ts +1 -1
- package/src/daemon/session-breakpoints.ts +7 -2
- package/src/daemon/session-inspection.ts +6 -10
- package/src/daemon/session-state.ts +6 -5
- package/src/daemon/session.ts +23 -3
- package/src/formatter/logs.ts +110 -0
- package/src/formatter/path.ts +27 -0
- package/src/formatter/stack.ts +5 -2
- package/src/formatter/variables.ts +48 -1
- package/src/main.ts +2 -0
- package/src/protocol/messages.ts +3 -0
- package/tests/fixtures/async-app.js +1 -1
- package/tests/fixtures/error-app.js +1 -1
- package/tests/fixtures/simple-app.js +1 -1
- package/tests/fixtures/ts-app/src/app.ts +4 -0
- package/tests/integration/state.test.ts +7 -7
- package/tests/unit/daemon.test.ts +1 -1
- package/tests/unit/formatter.test.ts +8 -4
- package/.bin/ndbg +0 -0
- package/.claude/skills/ndbg-debugger/ndbg-debugger/SKILL.md +0 -116
- package/.claude/skills/ndbg-debugger/ndbg-debugger/references/commands.md +0 -173
package/{ndbg-spec.md → SPEC.md}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# agent-dbg — Node.js Debugger CLI for AI Agents
|
|
2
2
|
|
|
3
3
|
## Specification v1.0
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
## 1. Vision
|
|
8
8
|
|
|
9
|
-
`
|
|
9
|
+
`agent-dbg` is a command-line debugger for Node.js designed specifically for AI coding agents (Claude Code, Codex, Cursor, Gemini CLI, etc.). It wraps the V8 Inspector Protocol (Chrome DevTools Protocol) behind a token-efficient, stateless CLI interface that lets agents autonomously set breakpoints, step through code, inspect variables, profile memory, and even hot-patch code — all through bash.
|
|
10
10
|
|
|
11
11
|
**Core principle:** every tool call should return maximum debugging insight for minimum token cost.
|
|
12
12
|
|
|
@@ -28,9 +28,9 @@ Humans can use it too. `--color` flag enables ANSI colors for terminal use.
|
|
|
28
28
|
|
|
29
29
|
### 2.2 CLI over MCP
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
agent-dbg is a CLI tool, not an MCP server. Rationale:
|
|
32
32
|
|
|
33
|
-
- **Zero setup** — `npm i -g
|
|
33
|
+
- **Zero setup** — `npm i -g agent-dbg` or `npx agent-dbg`, no MCP config files
|
|
34
34
|
- **Context efficient** — no JSON-RPC overhead, no schema in every call
|
|
35
35
|
- **Composable** — can pipe to grep/jq, chain with other bash commands
|
|
36
36
|
- **Universal** — works with any agent that has shell access, not just MCP clients
|
|
@@ -38,9 +38,9 @@ ndbg is a CLI tool, not an MCP server. Rationale:
|
|
|
38
38
|
|
|
39
39
|
### 2.3 Daemon architecture
|
|
40
40
|
|
|
41
|
-
Debugging is inherently stateful (a process paused at a breakpoint).
|
|
41
|
+
Debugging is inherently stateful (a process paused at a breakpoint). agent-dbg uses a background daemon model:
|
|
42
42
|
|
|
43
|
-
- `
|
|
43
|
+
- `agent-dbg launch` starts a daemon that holds the WebSocket connection to the V8 inspector
|
|
44
44
|
- All subsequent CLI calls communicate with the daemon via a local Unix socket
|
|
45
45
|
- Each CLI invocation is fast and stateless from the agent's perspective
|
|
46
46
|
- The daemon manages the debug session lifecycle
|
|
@@ -57,7 +57,7 @@ Debugging is inherently stateful (a process paused at a breakpoint). ndbg uses a
|
|
|
57
57
|
|
|
58
58
|
## 3. The @ref System
|
|
59
59
|
|
|
60
|
-
Inspired by agent-browser's `@e1` element refs,
|
|
60
|
+
Inspired by agent-browser's `@e1` element refs, agent-dbg assigns short stable references to every inspectable entity in its output. Agents use these refs instead of long object IDs, file paths, or frame indices.
|
|
61
61
|
|
|
62
62
|
### 3.1 Ref types
|
|
63
63
|
|
|
@@ -65,7 +65,7 @@ Inspired by agent-browser's `@e1` element refs, ndbg assigns short stable refere
|
|
|
65
65
|
|--------|--------|---------|----------|
|
|
66
66
|
| `@v` | Variable / value | `@v1`, `@v2` | Until next pause (step/continue) |
|
|
67
67
|
| `@f` | Stack frame | `@f0`, `@f1` | Until next pause |
|
|
68
|
-
| `@o` | Expanded object | `@o1`, `@o2` | Until session ends or `
|
|
68
|
+
| `@o` | Expanded object | `@o1`, `@o2` | Until session ends or `agent-dbg gc-refs` |
|
|
69
69
|
| `BP#` | Breakpoint | `BP#1`, `BP#2` | Until removed |
|
|
70
70
|
| `LP#` | Logpoint | `LP#1`, `LP#2` | Until removed |
|
|
71
71
|
| `HS#` | Heap snapshot | `HS#1`, `HS#2` | Until session ends |
|
|
@@ -75,13 +75,13 @@ Inspired by agent-browser's `@e1` element refs, ndbg assigns short stable refere
|
|
|
75
75
|
Refs can be used anywhere an identifier is expected:
|
|
76
76
|
|
|
77
77
|
```bash
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
agent-dbg props @v1 # expand variable @v1
|
|
79
|
+
agent-dbg eval "@v1.retryCount" # use ref in expressions
|
|
80
|
+
agent-dbg set @v2 true # mutate variable @v2
|
|
81
|
+
agent-dbg frame @f1 # switch to stack frame @f1
|
|
82
|
+
agent-dbg restart-frame @f0 # restart frame @f0
|
|
83
|
+
agent-dbg break-rm BP#1 # remove breakpoint BP#1
|
|
84
|
+
agent-dbg heap diff HS#1 HS#2 # diff two heap snapshots
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
### 3.3 Ref resolution
|
|
@@ -149,7 +149,7 @@ Breakpoints:
|
|
|
149
149
|
|
|
150
150
|
Commands that return state: `continue`, `step`, `step over`, `step into`, `step out`, `run-to`, `restart-frame`, `pause`.
|
|
151
151
|
|
|
152
|
-
The auto-returned state uses the same format as `
|
|
152
|
+
The auto-returned state uses the same format as `agent-dbg state` and respects a configurable default verbosity (see `agent-dbg config`).
|
|
153
153
|
|
|
154
154
|
---
|
|
155
155
|
|
|
@@ -158,7 +158,7 @@ The auto-returned state uses the same format as `ndbg state` and respects a conf
|
|
|
158
158
|
### 5.1 Session Management
|
|
159
159
|
|
|
160
160
|
```
|
|
161
|
-
|
|
161
|
+
agent-dbg launch [--brk] [--session NAME] <command...>
|
|
162
162
|
```
|
|
163
163
|
Start a Node.js process with `--inspect` (or `--inspect-brk` if `--brk` is passed) and attach the debugger daemon. Returns initial state if `--brk`.
|
|
164
164
|
|
|
@@ -168,27 +168,27 @@ Start a Node.js process with `--inspect` (or `--inspect-brk` if `--brk` is passe
|
|
|
168
168
|
- `--timeout SECS` — daemon idle timeout (default: 300)
|
|
169
169
|
|
|
170
170
|
```
|
|
171
|
-
|
|
171
|
+
agent-dbg attach <pid | ws-url | port>
|
|
172
172
|
```
|
|
173
173
|
Attach to an already-running Node.js process (started with `--inspect`).
|
|
174
174
|
|
|
175
175
|
```
|
|
176
|
-
|
|
176
|
+
agent-dbg stop [--session NAME]
|
|
177
177
|
```
|
|
178
178
|
Kill the debugged process and shut down the daemon.
|
|
179
179
|
|
|
180
180
|
```
|
|
181
|
-
|
|
181
|
+
agent-dbg sessions
|
|
182
182
|
```
|
|
183
183
|
List active debug sessions with PID, status (paused/running), and session name.
|
|
184
184
|
|
|
185
185
|
```
|
|
186
|
-
|
|
186
|
+
agent-dbg sessions --cleanup
|
|
187
187
|
```
|
|
188
188
|
Kill all orphaned daemon processes.
|
|
189
189
|
|
|
190
190
|
```
|
|
191
|
-
|
|
191
|
+
agent-dbg status
|
|
192
192
|
```
|
|
193
193
|
Current session info: PID, pause state, attached breakpoints, memory usage, uptime.
|
|
194
194
|
|
|
@@ -197,7 +197,7 @@ Current session info: PID, pause state, attached breakpoints, memory usage, upti
|
|
|
197
197
|
### 5.2 Breakpoints
|
|
198
198
|
|
|
199
199
|
```
|
|
200
|
-
|
|
200
|
+
agent-dbg break <file>:<line> [OPTIONS]
|
|
201
201
|
```
|
|
202
202
|
Set a breakpoint. Returns the breakpoint ID and resolved location (with source map).
|
|
203
203
|
|
|
@@ -205,45 +205,45 @@ Options:
|
|
|
205
205
|
- `--condition <expr>` — only pause when expression is truthy
|
|
206
206
|
- `--hit-count <n>` — only pause on the Nth hit
|
|
207
207
|
- `--continue` — immediately continue after setting (composite command)
|
|
208
|
-
- `--log <template>` — convert to logpoint (shortcut for `
|
|
208
|
+
- `--log <template>` — convert to logpoint (shortcut for `agent-dbg logpoint`)
|
|
209
209
|
|
|
210
210
|
```
|
|
211
|
-
|
|
211
|
+
agent-dbg break --pattern <urlRegex>:<line>
|
|
212
212
|
```
|
|
213
213
|
Set breakpoint on all files matching a URL regex pattern. Useful for breaking in `node_modules` or dynamically loaded scripts.
|
|
214
214
|
|
|
215
215
|
```
|
|
216
|
-
|
|
216
|
+
agent-dbg break-fn <expr>
|
|
217
217
|
```
|
|
218
|
-
Set a breakpoint on every call to the function returned by evaluating `<expr>`. Example: `
|
|
218
|
+
Set a breakpoint on every call to the function returned by evaluating `<expr>`. Example: `agent-dbg break-fn "require('express').Router"`.
|
|
219
219
|
|
|
220
220
|
```
|
|
221
|
-
|
|
221
|
+
agent-dbg break-on-load [--sourcemap]
|
|
222
222
|
```
|
|
223
223
|
Break whenever a new script is parsed. With `--sourcemap`, only break on scripts with source maps (i.e., your code, not node internals).
|
|
224
224
|
|
|
225
225
|
```
|
|
226
|
-
|
|
226
|
+
agent-dbg break-rm <BP#id | LP#id | all>
|
|
227
227
|
```
|
|
228
228
|
Remove a breakpoint or logpoint by ref. `all` removes everything.
|
|
229
229
|
|
|
230
230
|
```
|
|
231
|
-
|
|
231
|
+
agent-dbg break-ls
|
|
232
232
|
```
|
|
233
233
|
List all breakpoints and logpoints with their locations, conditions, and hit counts.
|
|
234
234
|
|
|
235
235
|
```
|
|
236
|
-
|
|
236
|
+
agent-dbg break-toggle [BP#id | all]
|
|
237
237
|
```
|
|
238
238
|
Enable/disable breakpoint(s) without removing them.
|
|
239
239
|
|
|
240
240
|
```
|
|
241
|
-
|
|
241
|
+
agent-dbg breakable <file>:<start>-<end>
|
|
242
242
|
```
|
|
243
243
|
List valid breakpoint locations in a line range. Useful when the agent picks a non-breakable line.
|
|
244
244
|
|
|
245
245
|
```
|
|
246
|
-
|
|
246
|
+
agent-dbg logpoint <file>:<line> <template>
|
|
247
247
|
```
|
|
248
248
|
Set a logpoint — logs the interpolated template string each time the line is hit, without pausing. Template uses `${expr}` syntax.
|
|
249
249
|
|
|
@@ -251,7 +251,7 @@ Set a logpoint — logs the interpolated template string each time the line is h
|
|
|
251
251
|
- `--condition <expr>` — only log when condition is true
|
|
252
252
|
|
|
253
253
|
```
|
|
254
|
-
|
|
254
|
+
agent-dbg catch [all | uncaught | caught | none]
|
|
255
255
|
```
|
|
256
256
|
Configure pause-on-exception behavior. `all` catches even exceptions inside try/catch. `uncaught` is the most useful default.
|
|
257
257
|
|
|
@@ -262,12 +262,12 @@ Configure pause-on-exception behavior. `all` catches even exceptions inside try/
|
|
|
262
262
|
All execution commands **return a state snapshot** when the process next pauses.
|
|
263
263
|
|
|
264
264
|
```
|
|
265
|
-
|
|
265
|
+
agent-dbg continue
|
|
266
266
|
```
|
|
267
267
|
Resume execution until next breakpoint, exception, or manual pause.
|
|
268
268
|
|
|
269
269
|
```
|
|
270
|
-
|
|
270
|
+
agent-dbg step [over | into | out]
|
|
271
271
|
```
|
|
272
272
|
Step one statement. Default is `over`.
|
|
273
273
|
|
|
@@ -275,22 +275,22 @@ Step one statement. Default is `over`.
|
|
|
275
275
|
- `step over` / `step into` — accept `--skip <pattern>` to skip over matching files (inline blackboxing)
|
|
276
276
|
|
|
277
277
|
```
|
|
278
|
-
|
|
278
|
+
agent-dbg run-to <file>:<line>
|
|
279
279
|
```
|
|
280
280
|
Continue execution until a specific location. Does not create a persistent breakpoint.
|
|
281
281
|
|
|
282
282
|
```
|
|
283
|
-
|
|
283
|
+
agent-dbg restart-frame [@fN]
|
|
284
284
|
```
|
|
285
285
|
Re-execute the specified frame (or current frame) from the beginning. The process continues immediately and pauses at the beginning of the restarted function.
|
|
286
286
|
|
|
287
287
|
```
|
|
288
|
-
|
|
288
|
+
agent-dbg pause
|
|
289
289
|
```
|
|
290
290
|
Interrupt a running process. Returns state at the interrupt point.
|
|
291
291
|
|
|
292
292
|
```
|
|
293
|
-
|
|
293
|
+
agent-dbg kill-execution
|
|
294
294
|
```
|
|
295
295
|
Terminate the current JavaScript execution without killing the Node.js process. Useful for stopping infinite loops while keeping the debug session alive.
|
|
296
296
|
|
|
@@ -299,34 +299,34 @@ Terminate the current JavaScript execution without killing the Node.js process.
|
|
|
299
299
|
### 5.4 Inspection
|
|
300
300
|
|
|
301
301
|
```
|
|
302
|
-
|
|
302
|
+
agent-dbg state [FLAGS]
|
|
303
303
|
```
|
|
304
304
|
Return the current debug state snapshot. See Section 4 for flags.
|
|
305
305
|
|
|
306
306
|
```
|
|
307
|
-
|
|
307
|
+
agent-dbg vars [name1, name2, ...]
|
|
308
308
|
```
|
|
309
309
|
Show local variables in the current frame. Optionally filter to specific names. Output assigns `@v` refs.
|
|
310
310
|
|
|
311
311
|
```
|
|
312
|
-
|
|
312
|
+
agent-dbg stack [--async-depth N]
|
|
313
313
|
```
|
|
314
314
|
Show the call stack. `--async-depth` controls how many async frames to resolve (default: 8, 0 to disable).
|
|
315
315
|
|
|
316
316
|
```
|
|
317
|
-
|
|
317
|
+
agent-dbg eval <expression>
|
|
318
318
|
```
|
|
319
319
|
Evaluate an expression in the context of the current call frame.
|
|
320
320
|
|
|
321
321
|
- Supports `await` (uses CDP's `awaitPromise`)
|
|
322
|
-
- Supports `@ref` interpolation: `
|
|
322
|
+
- Supports `@ref` interpolation: `agent-dbg eval "@v1.retryCount"`
|
|
323
323
|
- `--frame @fN` — evaluate in a specific frame
|
|
324
324
|
- `--silent` — suppress exception reporting
|
|
325
325
|
- `--timeout MS` — kill evaluation after N milliseconds (default: 5000)
|
|
326
326
|
- `--side-effect-free` — throw if expression has side effects (safe inspection)
|
|
327
327
|
|
|
328
328
|
```
|
|
329
|
-
|
|
329
|
+
agent-dbg props <@ref> [OPTIONS]
|
|
330
330
|
```
|
|
331
331
|
Expand the properties of an object ref. Returns `@o` refs for nested values.
|
|
332
332
|
|
|
@@ -336,17 +336,17 @@ Expand the properties of an object ref. Returns `@o` refs for nested values.
|
|
|
336
336
|
- `--internal` — include V8 internal properties (e.g., `[[PromiseState]]`)
|
|
337
337
|
|
|
338
338
|
```
|
|
339
|
-
|
|
339
|
+
agent-dbg instances <expression>
|
|
340
340
|
```
|
|
341
|
-
Find all live instances of a prototype/constructor. Evaluates the expression to get a prototype, then queries all objects sharing it. Example: `
|
|
341
|
+
Find all live instances of a prototype/constructor. Evaluates the expression to get a prototype, then queries all objects sharing it. Example: `agent-dbg instances "EventEmitter.prototype"`.
|
|
342
342
|
|
|
343
343
|
```
|
|
344
|
-
|
|
344
|
+
agent-dbg globals
|
|
345
345
|
```
|
|
346
346
|
List all global `let`, `const`, and `class` declarations in the current execution context.
|
|
347
347
|
|
|
348
348
|
```
|
|
349
|
-
|
|
349
|
+
agent-dbg source [OPTIONS]
|
|
350
350
|
```
|
|
351
351
|
Show source code around the current pause location.
|
|
352
352
|
|
|
@@ -355,7 +355,7 @@ Show source code around the current pause location.
|
|
|
355
355
|
- `--all` — show full file
|
|
356
356
|
|
|
357
357
|
```
|
|
358
|
-
|
|
358
|
+
agent-dbg search <query> [OPTIONS]
|
|
359
359
|
```
|
|
360
360
|
Search across all loaded scripts.
|
|
361
361
|
|
|
@@ -364,12 +364,12 @@ Search across all loaded scripts.
|
|
|
364
364
|
- `--file <scriptId>` — search within a specific script
|
|
365
365
|
|
|
366
366
|
```
|
|
367
|
-
|
|
367
|
+
agent-dbg scripts [--filter <pattern>]
|
|
368
368
|
```
|
|
369
369
|
List all loaded scripts (files). Useful to find the right `scriptId` for breakpoints in dynamically loaded code.
|
|
370
370
|
|
|
371
371
|
```
|
|
372
|
-
|
|
372
|
+
agent-dbg console [OPTIONS]
|
|
373
373
|
```
|
|
374
374
|
Show captured console output (log, warn, error, etc.) with timestamps and stack traces.
|
|
375
375
|
|
|
@@ -379,7 +379,7 @@ Show captured console output (log, warn, error, etc.) with timestamps and stack
|
|
|
379
379
|
- `--clear` — clear captured console buffer
|
|
380
380
|
|
|
381
381
|
```
|
|
382
|
-
|
|
382
|
+
agent-dbg exceptions [OPTIONS]
|
|
383
383
|
```
|
|
384
384
|
Show captured uncaught exceptions.
|
|
385
385
|
|
|
@@ -393,28 +393,28 @@ Show captured uncaught exceptions.
|
|
|
393
393
|
These commands let an agent **test hypotheses and fixes without restarting**.
|
|
394
394
|
|
|
395
395
|
```
|
|
396
|
-
|
|
396
|
+
agent-dbg set <@vRef | varName> <value>
|
|
397
397
|
```
|
|
398
398
|
Change the value of a local, closure, or catch-scope variable in the current frame.
|
|
399
399
|
|
|
400
400
|
- Value is parsed as JSON or as a JavaScript primitive
|
|
401
401
|
- Only works on `local`, `closure`, and `catch` scope types (V8 limitation)
|
|
402
|
-
- Example: `
|
|
402
|
+
- Example: `agent-dbg set @v2 true`, `agent-dbg set retryCount 0`
|
|
403
403
|
|
|
404
404
|
```
|
|
405
|
-
|
|
405
|
+
agent-dbg set-return <value>
|
|
406
406
|
```
|
|
407
407
|
Change the return value of the current function. Only available when paused at a return point.
|
|
408
408
|
|
|
409
409
|
```
|
|
410
|
-
|
|
410
|
+
agent-dbg hotpatch <file>
|
|
411
411
|
```
|
|
412
412
|
Live-edit the source of a loaded script. Reads the file from disk and pushes it to V8 via `Debugger.setScriptSource`.
|
|
413
413
|
|
|
414
414
|
- If the edited function is the top-most stack frame (and only activation), it auto-restarts
|
|
415
415
|
- `--dry-run` — check if the edit would succeed without applying
|
|
416
416
|
- Returns status: `Ok`, `CompileError`, `BlockedByActiveFunction`, etc.
|
|
417
|
-
- **This is
|
|
417
|
+
- **This is agent-dbg's killer feature for agents** — fix code and immediately verify, no restart
|
|
418
418
|
|
|
419
419
|
---
|
|
420
420
|
|
|
@@ -423,20 +423,20 @@ Live-edit the source of a loaded script. Reads the file from disk and pushes it
|
|
|
423
423
|
Control which code the debugger steps into, preventing agents from getting lost in framework internals.
|
|
424
424
|
|
|
425
425
|
```
|
|
426
|
-
|
|
426
|
+
agent-dbg blackbox <pattern...>
|
|
427
427
|
```
|
|
428
428
|
Skip stepping into scripts matching the given patterns (regex). Stepping into a blackboxed function will step over it instead.
|
|
429
429
|
|
|
430
|
-
- Example: `
|
|
430
|
+
- Example: `agent-dbg blackbox "node_modules" "internal/"`
|
|
431
431
|
- Stacks with previous patterns
|
|
432
432
|
|
|
433
433
|
```
|
|
434
|
-
|
|
434
|
+
agent-dbg blackbox-ls
|
|
435
435
|
```
|
|
436
436
|
List current blackbox patterns.
|
|
437
437
|
|
|
438
438
|
```
|
|
439
|
-
|
|
439
|
+
agent-dbg blackbox-rm <pattern | all>
|
|
440
440
|
```
|
|
441
441
|
Remove blackbox patterns.
|
|
442
442
|
|
|
@@ -445,12 +445,12 @@ Remove blackbox patterns.
|
|
|
445
445
|
### 5.7 CPU Profiling
|
|
446
446
|
|
|
447
447
|
```
|
|
448
|
-
|
|
448
|
+
agent-dbg cpu start [--interval <μs>]
|
|
449
449
|
```
|
|
450
450
|
Start the V8 CPU profiler. Default sampling interval is 1000μs.
|
|
451
451
|
|
|
452
452
|
```
|
|
453
|
-
|
|
453
|
+
agent-dbg cpu stop [--top N]
|
|
454
454
|
```
|
|
455
455
|
Stop profiling and return results.
|
|
456
456
|
|
|
@@ -459,12 +459,12 @@ Stop profiling and return results.
|
|
|
459
459
|
- Full profile saved to a file for external tools
|
|
460
460
|
|
|
461
461
|
```
|
|
462
|
-
|
|
462
|
+
agent-dbg coverage start [--detailed]
|
|
463
463
|
```
|
|
464
464
|
Start precise code coverage collection. `--detailed` enables block-level granularity (not just function-level).
|
|
465
465
|
|
|
466
466
|
```
|
|
467
|
-
|
|
467
|
+
agent-dbg coverage stop [OPTIONS]
|
|
468
468
|
```
|
|
469
469
|
Stop coverage and report.
|
|
470
470
|
|
|
@@ -477,22 +477,22 @@ Stop coverage and report.
|
|
|
477
477
|
### 5.8 Memory / Heap
|
|
478
478
|
|
|
479
479
|
```
|
|
480
|
-
|
|
480
|
+
agent-dbg heap usage
|
|
481
481
|
```
|
|
482
482
|
Quick heap statistics: used, total, embedder heap, backing store. No snapshot needed.
|
|
483
483
|
|
|
484
484
|
```
|
|
485
|
-
|
|
485
|
+
agent-dbg heap snapshot [--tag <name>]
|
|
486
486
|
```
|
|
487
487
|
Take a full V8 heap snapshot. Assigns an `HS#` ref.
|
|
488
488
|
|
|
489
489
|
```
|
|
490
|
-
|
|
490
|
+
agent-dbg heap diff <HS#a> <HS#b> [--top N]
|
|
491
491
|
```
|
|
492
492
|
Compare two heap snapshots. Output: table of constructors with delta count and delta size, sorted by size impact.
|
|
493
493
|
|
|
494
494
|
```
|
|
495
|
-
|
|
495
|
+
agent-dbg heap sample start [--interval <bytes>] [--include-gc]
|
|
496
496
|
```
|
|
497
497
|
Start sampling heap profiler. Lightweight alternative to full snapshots.
|
|
498
498
|
|
|
@@ -500,27 +500,27 @@ Start sampling heap profiler. Lightweight alternative to full snapshots.
|
|
|
500
500
|
- `--include-gc` — include objects already garbage-collected (shows temporary allocations)
|
|
501
501
|
|
|
502
502
|
```
|
|
503
|
-
|
|
503
|
+
agent-dbg heap sample stop [--top N]
|
|
504
504
|
```
|
|
505
505
|
Stop sampling and report top allocation sites.
|
|
506
506
|
|
|
507
507
|
```
|
|
508
|
-
|
|
508
|
+
agent-dbg heap track start
|
|
509
509
|
```
|
|
510
510
|
Start allocation tracking over time (timeline mode).
|
|
511
511
|
|
|
512
512
|
```
|
|
513
|
-
|
|
513
|
+
agent-dbg heap track stop
|
|
514
514
|
```
|
|
515
515
|
Stop tracking and report allocation rate by callsite.
|
|
516
516
|
|
|
517
517
|
```
|
|
518
|
-
|
|
518
|
+
agent-dbg heap inspect <heapObjectId>
|
|
519
519
|
```
|
|
520
520
|
Get a remote object reference from a heap snapshot node, bridging heap analysis with runtime inspection. Returns an `@o` ref.
|
|
521
521
|
|
|
522
522
|
```
|
|
523
|
-
|
|
523
|
+
agent-dbg gc
|
|
524
524
|
```
|
|
525
525
|
Force a garbage collection cycle. Useful before taking a snapshot to see what truly leaks.
|
|
526
526
|
|
|
@@ -529,26 +529,26 @@ Force a garbage collection cycle. Useful before taking a snapshot to see what tr
|
|
|
529
529
|
### 5.9 Advanced / Utility
|
|
530
530
|
|
|
531
531
|
```
|
|
532
|
-
|
|
532
|
+
agent-dbg inject-hook <name>
|
|
533
533
|
```
|
|
534
534
|
Create a runtime binding that, when called from application code, sends a notification to the daemon. Use for custom instrumentation.
|
|
535
535
|
|
|
536
|
-
- Adds a global function `
|
|
536
|
+
- Adds a global function `__agent-dbg_<name>()` that the app can call
|
|
537
537
|
- When called, the daemon captures the call's arguments and stack
|
|
538
|
-
- View with: `
|
|
538
|
+
- View with: `agent-dbg hooks [--follow]`
|
|
539
539
|
|
|
540
540
|
```
|
|
541
|
-
|
|
541
|
+
agent-dbg contexts
|
|
542
542
|
```
|
|
543
543
|
List all V8 execution contexts (useful for debugging Jest VM sandboxes, workers, or vm.runInContext scenarios). Each context gets an ID.
|
|
544
544
|
|
|
545
545
|
```
|
|
546
|
-
|
|
546
|
+
agent-dbg async-depth <N>
|
|
547
547
|
```
|
|
548
548
|
Set the async call stack trace depth. Default: 16. Set to 0 to disable async stacks. Higher values cost more memory but show the full async chain.
|
|
549
549
|
|
|
550
550
|
```
|
|
551
|
-
|
|
551
|
+
agent-dbg config [key] [value]
|
|
552
552
|
```
|
|
553
553
|
Get/set daemon configuration:
|
|
554
554
|
|
|
@@ -560,12 +560,12 @@ Get/set daemon configuration:
|
|
|
560
560
|
- `timeout` — daemon idle timeout in seconds
|
|
561
561
|
|
|
562
562
|
```
|
|
563
|
-
|
|
563
|
+
agent-dbg gc-refs
|
|
564
564
|
```
|
|
565
565
|
Clear accumulated `@o` refs to free memory. `@v` and `@f` refs are cleared automatically on each pause.
|
|
566
566
|
|
|
567
567
|
```
|
|
568
|
-
|
|
568
|
+
agent-dbg --help-agent
|
|
569
569
|
```
|
|
570
570
|
Output a compact LLM-optimized reference card with core workflow, quick reference, and common debugging patterns. Designed to be injected into an agent's context window.
|
|
571
571
|
|
|
@@ -580,7 +580,7 @@ Output a compact LLM-optimized reference card with core workflow, quick referenc
|
|
|
580
580
|
3. **@refs inline** — every inspectable value is prefixed with its ref
|
|
581
581
|
4. **Timing annotations** — execution commands report elapsed time since last pause
|
|
582
582
|
5. **No JSON by default** — JSON wastes tokens on syntax. Available with `--json` flag
|
|
583
|
-
6. **Truncation with hints** — large outputs are truncated with a `... (
|
|
583
|
+
6. **Truncation with hints** — large outputs are truncated with a `... (agent-dbg props @oN for more)` hint
|
|
584
584
|
|
|
585
585
|
### 6.2 Variable formatting
|
|
586
586
|
|
|
@@ -641,17 +641,17 @@ Errors always suggest the next action:
|
|
|
641
641
|
```
|
|
642
642
|
✗ Cannot set breakpoint at src/queue/processor.ts:46 — no breakable location
|
|
643
643
|
Nearest valid lines: 45, 47
|
|
644
|
-
→ Try:
|
|
644
|
+
→ Try: agent-dbg break src/queue/processor.ts:47
|
|
645
645
|
|
|
646
646
|
✗ Variable 'foo' not found in current scope
|
|
647
647
|
Available locals: job, lock, this
|
|
648
|
-
→ Try:
|
|
648
|
+
→ Try: agent-dbg vars
|
|
649
649
|
|
|
650
650
|
✗ Cannot step — process is running (not paused)
|
|
651
|
-
→ Try:
|
|
651
|
+
→ Try: agent-dbg pause
|
|
652
652
|
|
|
653
653
|
✗ Session "default" not found — no active debug session
|
|
654
|
-
→ Try:
|
|
654
|
+
→ Try: agent-dbg launch --brk "node app.js"
|
|
655
655
|
```
|
|
656
656
|
|
|
657
657
|
---
|
|
@@ -664,16 +664,16 @@ Source maps are a first-class concern, not an afterthought.
|
|
|
664
664
|
|
|
665
665
|
- All user-facing locations display **source-mapped paths and line numbers** (TypeScript, etc.)
|
|
666
666
|
- The `Debugger.scriptParsed` event provides `sourceMapURL`; the daemon fetches and caches it
|
|
667
|
-
- `
|
|
667
|
+
- `agent-dbg break src/foo.ts:42` resolves to the generated `.js` location automatically
|
|
668
668
|
- Stack traces always show source-mapped locations
|
|
669
|
-
- `
|
|
669
|
+
- `agent-dbg source` shows the original source (TypeScript), not compiled JS
|
|
670
670
|
- If no source map exists, the generated JS is shown (no error)
|
|
671
671
|
|
|
672
672
|
### 7.2 Source map commands
|
|
673
673
|
|
|
674
674
|
```
|
|
675
|
-
|
|
676
|
-
|
|
675
|
+
agent-dbg sourcemap <file> # Show source map info for a file
|
|
676
|
+
agent-dbg sourcemap --disable # Disable source map resolution globally
|
|
677
677
|
```
|
|
678
678
|
|
|
679
679
|
---
|
|
@@ -682,11 +682,11 @@ ndbg sourcemap --disable # Disable source map resolution globally
|
|
|
682
682
|
|
|
683
683
|
### 8.1 Daemon lifecycle
|
|
684
684
|
|
|
685
|
-
1. `
|
|
685
|
+
1. `agent-dbg launch` starts a background daemon process
|
|
686
686
|
2. Daemon opens a WebSocket to the Node.js inspector (`ws://127.0.0.1:<port>`)
|
|
687
|
-
3. Daemon listens on a Unix socket at `$XDG_RUNTIME_DIR/
|
|
687
|
+
3. Daemon listens on a Unix socket at `$XDG_RUNTIME_DIR/agent-dbg/<session-name>.sock` (or `$TMPDIR` fallback)
|
|
688
688
|
4. CLI commands connect to the Unix socket, send a request, receive a response, disconnect
|
|
689
|
-
5. Daemon shuts down when: process exits, `
|
|
689
|
+
5. Daemon shuts down when: process exits, `agent-dbg stop` is called, or idle timeout is reached
|
|
690
690
|
|
|
691
691
|
### 8.2 Internal protocol
|
|
692
692
|
|
|
@@ -705,20 +705,20 @@ CLI-to-daemon communication uses newline-delimited JSON over Unix socket. Each r
|
|
|
705
705
|
- Each debug session has a unique name (default: `"default"`)
|
|
706
706
|
- Multiple sessions can run simultaneously (e.g., debugging a client and server)
|
|
707
707
|
- `--session NAME` on any command targets a specific session
|
|
708
|
-
- `
|
|
708
|
+
- `agent-dbg sessions` lists all active sessions
|
|
709
709
|
|
|
710
710
|
### 8.4 Crash recovery
|
|
711
711
|
|
|
712
712
|
- If the daemon crashes, the CLI detects the dead socket and reports:
|
|
713
713
|
`✗ Session "default" daemon is not running. The debugged process (PID 42871) is still alive.`
|
|
714
|
-
`→ Try:
|
|
714
|
+
`→ Try: agent-dbg attach 42871`
|
|
715
715
|
- Lock files prevent duplicate daemons for the same session
|
|
716
716
|
|
|
717
717
|
---
|
|
718
718
|
|
|
719
719
|
## 9. SKILL.md for Agent Integration
|
|
720
720
|
|
|
721
|
-
|
|
721
|
+
agent-dbg ships with a SKILL.md for Claude Code's skill system and compatible agents.
|
|
722
722
|
|
|
723
723
|
```yaml
|
|
724
724
|
---
|
|
@@ -735,73 +735,73 @@ description: >
|
|
|
735
735
|
|
|
736
736
|
### 9.1 `--help-agent` output
|
|
737
737
|
|
|
738
|
-
The `
|
|
738
|
+
The `agent-dbg --help-agent` command outputs a compact reference designed for agent context windows:
|
|
739
739
|
|
|
740
740
|
```
|
|
741
|
-
|
|
741
|
+
agent-dbg — Node.js debugger CLI for AI agents
|
|
742
742
|
|
|
743
743
|
CORE LOOP:
|
|
744
|
-
1.
|
|
745
|
-
2.
|
|
746
|
-
3.
|
|
747
|
-
4. Inspect:
|
|
748
|
-
5. Mutate/fix:
|
|
744
|
+
1. agent-dbg launch --brk "node app.js" → pauses at first line, returns state
|
|
745
|
+
2. agent-dbg break src/file.ts:42 → set breakpoint
|
|
746
|
+
3. agent-dbg continue → run to breakpoint, returns state
|
|
747
|
+
4. Inspect: agent-dbg vars, agent-dbg eval, agent-dbg props @v1
|
|
748
|
+
5. Mutate/fix: agent-dbg set @v1 value, agent-dbg hotpatch src/file.ts
|
|
749
749
|
6. Repeat from 3
|
|
750
750
|
|
|
751
751
|
REFS: Every output assigns @refs. Use them everywhere:
|
|
752
|
-
@v1..@vN variables │
|
|
753
|
-
@f0..@fN stack frames │
|
|
754
|
-
BP#1..N breakpoints │
|
|
755
|
-
HS#1..N heap snaps │
|
|
752
|
+
@v1..@vN variables │ agent-dbg props @v1, agent-dbg set @v2 true
|
|
753
|
+
@f0..@fN stack frames │ agent-dbg frame @f1, agent-dbg restart-frame @f0
|
|
754
|
+
BP#1..N breakpoints │ agent-dbg break-rm BP#1
|
|
755
|
+
HS#1..N heap snaps │ agent-dbg heap diff HS#1 HS#2
|
|
756
756
|
|
|
757
757
|
EXECUTION (all return state automatically):
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
758
|
+
agent-dbg continue Resume to next breakpoint
|
|
759
|
+
agent-dbg step [over|into|out] Step one statement
|
|
760
|
+
agent-dbg run-to file:line Continue to location
|
|
761
|
+
agent-dbg pause Interrupt running process
|
|
762
|
+
agent-dbg restart-frame @f0 Re-run current function
|
|
763
763
|
|
|
764
764
|
BREAKPOINTS:
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
765
|
+
agent-dbg break file:line [--condition expr]
|
|
766
|
+
agent-dbg logpoint file:line "template ${var}"
|
|
767
|
+
agent-dbg catch [all|uncaught|none]
|
|
768
|
+
agent-dbg blackbox "node_modules/**"
|
|
769
769
|
|
|
770
770
|
INSPECTION:
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
771
|
+
agent-dbg state [-v|-s|-b|-c] [--depth N]
|
|
772
|
+
agent-dbg vars [name...]
|
|
773
|
+
agent-dbg eval <expr> (await supported)
|
|
774
|
+
agent-dbg props @ref [--depth N]
|
|
775
|
+
agent-dbg instances "Class.prototype"
|
|
776
|
+
agent-dbg search "query" [--regex]
|
|
777
777
|
|
|
778
778
|
MUTATION:
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
779
|
+
agent-dbg set @v1 <value> Change variable
|
|
780
|
+
agent-dbg set-return <value> Change return value
|
|
781
|
+
agent-dbg hotpatch <file> Live-edit code (no restart!)
|
|
782
782
|
|
|
783
783
|
PROFILING:
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
784
|
+
agent-dbg cpu start / stop [--top N]
|
|
785
|
+
agent-dbg coverage start [--detailed] / stop [--uncovered]
|
|
786
|
+
agent-dbg heap usage | snapshot | diff | sample | gc
|
|
787
787
|
|
|
788
788
|
PATTERNS:
|
|
789
789
|
# Race condition → trace with logpoints
|
|
790
|
-
|
|
791
|
-
|
|
790
|
+
agent-dbg logpoint src/lock.ts:31 "acquire: ${jobId} by ${workerId}"
|
|
791
|
+
agent-dbg continue
|
|
792
792
|
|
|
793
793
|
# Circular dependency → trace require chain
|
|
794
|
-
|
|
795
|
-
|
|
794
|
+
agent-dbg break-on-load --sourcemap
|
|
795
|
+
agent-dbg logpoint node_modules/jest-runtime/build/index.js:348 "${from} → ${moduleName}"
|
|
796
796
|
|
|
797
797
|
# Memory leak → snapshot before/after
|
|
798
|
-
|
|
798
|
+
agent-dbg heap snapshot --tag before
|
|
799
799
|
# ... trigger load ...
|
|
800
|
-
|
|
801
|
-
|
|
800
|
+
agent-dbg heap snapshot --tag after
|
|
801
|
+
agent-dbg heap diff HS#1 HS#2 --top 5
|
|
802
802
|
|
|
803
803
|
# Skip framework noise
|
|
804
|
-
|
|
804
|
+
agent-dbg blackbox "node_modules" "internal/"
|
|
805
805
|
```
|
|
806
806
|
|
|
807
807
|
---
|
|
@@ -812,32 +812,32 @@ PATTERNS:
|
|
|
812
812
|
|
|
813
813
|
```bash
|
|
814
814
|
# npx (zero install — recommended for first use)
|
|
815
|
-
npx
|
|
815
|
+
npx agent-dbg launch --brk "node app.js"
|
|
816
816
|
|
|
817
817
|
# Global install
|
|
818
|
-
npm install -g
|
|
818
|
+
npm install -g agent-dbg
|
|
819
819
|
|
|
820
820
|
# Compiled binary (no runtime needed)
|
|
821
|
-
# Download from GitHub releases:
|
|
822
|
-
curl -fsSL https://github.com/<org>/
|
|
823
|
-
chmod +x /usr/local/bin/
|
|
821
|
+
# Download from GitHub releases: agent-dbg-linux-x64, agent-dbg-darwin-arm64, etc.
|
|
822
|
+
curl -fsSL https://github.com/<org>/agent-dbg/releases/latest/download/agent-dbg-$(uname -s)-$(uname -m) -o /usr/local/bin/agent-dbg
|
|
823
|
+
chmod +x /usr/local/bin/agent-dbg
|
|
824
824
|
```
|
|
825
825
|
|
|
826
826
|
### 10.2 Skill installation (for Claude Code and compatible agents)
|
|
827
827
|
|
|
828
828
|
```bash
|
|
829
829
|
# Via vercel skills CLI
|
|
830
|
-
npx skills add <org>/
|
|
830
|
+
npx skills add <org>/agent-dbg
|
|
831
831
|
|
|
832
832
|
# Manual: copy SKILL.md to Claude Code skills directory
|
|
833
|
-
cp node_modules/
|
|
833
|
+
cp node_modules/agent-dbg/skills/node-debugger/SKILL.md ~/.claude/skills/node-debugger/SKILL.md
|
|
834
834
|
```
|
|
835
835
|
|
|
836
836
|
### 10.3 Requirements
|
|
837
837
|
|
|
838
838
|
- **Debugged process**: Node.js 16+ (for V8 inspector support)
|
|
839
|
-
- **
|
|
840
|
-
- **
|
|
839
|
+
- **agent-dbg binary**: no runtime dependency (standalone compiled binary)
|
|
840
|
+
- **agent-dbg via npm/npx**: Bun or Node.js 18+ on the host
|
|
841
841
|
|
|
842
842
|
---
|
|
843
843
|
|
|
@@ -854,21 +854,21 @@ cp node_modules/ndbg/skills/node-debugger/SKILL.md ~/.claude/skills/node-debugge
|
|
|
854
854
|
|
|
855
855
|
### 11.2 Out of scope (v1)
|
|
856
856
|
|
|
857
|
-
- **Browser debugging** —
|
|
857
|
+
- **Browser debugging** — agent-dbg targets Node.js processes only (no DOM, no CSS)
|
|
858
858
|
- **Other languages** — no Python, Rust, Go, etc. (use dedicated tools)
|
|
859
859
|
- **GUI** — no TUI, no web UI (output is text for terminal/agent consumption)
|
|
860
860
|
- **MCP server mode** — may be added later as an optional adapter, but CLI is primary
|
|
861
861
|
- **Remote debugging** — v1 targets localhost only (SSH tunneling is the recommended approach for remote)
|
|
862
862
|
- **Recording/replay** — time-travel debugging (may be a v2 feature)
|
|
863
|
-
- **Test framework integration** —
|
|
863
|
+
- **Test framework integration** — agent-dbg debugs any Node.js process; it doesn't know about Jest/Vitest internals (but can debug them)
|
|
864
864
|
|
|
865
865
|
---
|
|
866
866
|
|
|
867
867
|
## 12. V8 Inspector Protocol Mapping
|
|
868
868
|
|
|
869
|
-
Reference for implementors. Maps
|
|
869
|
+
Reference for implementors. Maps agent-dbg commands to CDP methods.
|
|
870
870
|
|
|
871
|
-
|
|
|
871
|
+
| agent-dbg command | CDP domain | CDP method(s) |
|
|
872
872
|
|---|---|---|
|
|
873
873
|
| `launch --brk` | — | Spawns `node --inspect-brk` + `Runtime.runIfWaitingForDebugger` |
|
|
874
874
|
| `break file:line` | Debugger | `setBreakpointByUrl` |
|