agent-dbg 0.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/.bin/ndbg +0 -0
- package/.claude/settings.local.json +21 -0
- package/.claude/skills/ndbg-debugger/ndbg-debugger/SKILL.md +116 -0
- package/.claude/skills/ndbg-debugger/ndbg-debugger/references/commands.md +173 -0
- package/CLAUDE.md +43 -0
- package/PROGRESS.md +261 -0
- package/README.md +67 -0
- package/biome.json +41 -0
- package/ndbg-spec.md +958 -0
- package/package.json +30 -0
- package/src/cdp/client.ts +198 -0
- package/src/cdp/types.ts +16 -0
- package/src/cli/parser.ts +287 -0
- package/src/cli/registry.ts +7 -0
- package/src/cli/types.ts +24 -0
- package/src/commands/attach.ts +47 -0
- package/src/commands/blackbox-ls.ts +38 -0
- package/src/commands/blackbox-rm.ts +57 -0
- package/src/commands/blackbox.ts +48 -0
- package/src/commands/break-ls.ts +57 -0
- package/src/commands/break-rm.ts +40 -0
- package/src/commands/break-toggle.ts +42 -0
- package/src/commands/break.ts +145 -0
- package/src/commands/breakable.ts +69 -0
- package/src/commands/catch.ts +38 -0
- package/src/commands/console.ts +61 -0
- package/src/commands/continue.ts +46 -0
- package/src/commands/eval.ts +70 -0
- package/src/commands/exceptions.ts +61 -0
- package/src/commands/hotpatch.ts +67 -0
- package/src/commands/launch.ts +69 -0
- package/src/commands/logpoint.ts +78 -0
- package/src/commands/pause.ts +46 -0
- package/src/commands/props.ts +77 -0
- package/src/commands/restart-frame.ts +36 -0
- package/src/commands/run-to.ts +70 -0
- package/src/commands/scripts.ts +57 -0
- package/src/commands/search.ts +73 -0
- package/src/commands/sessions.ts +71 -0
- package/src/commands/set-return.ts +49 -0
- package/src/commands/set.ts +61 -0
- package/src/commands/source.ts +59 -0
- package/src/commands/sourcemap.ts +66 -0
- package/src/commands/stack.ts +64 -0
- package/src/commands/state.ts +124 -0
- package/src/commands/status.ts +57 -0
- package/src/commands/step.ts +50 -0
- package/src/commands/stop.ts +27 -0
- package/src/commands/vars.ts +71 -0
- package/src/daemon/client.ts +147 -0
- package/src/daemon/entry.ts +242 -0
- package/src/daemon/paths.ts +26 -0
- package/src/daemon/server.ts +185 -0
- package/src/daemon/session-blackbox.ts +41 -0
- package/src/daemon/session-breakpoints.ts +492 -0
- package/src/daemon/session-execution.ts +121 -0
- package/src/daemon/session-inspection.ts +701 -0
- package/src/daemon/session-mutation.ts +197 -0
- package/src/daemon/session-state.ts +258 -0
- package/src/daemon/session.ts +938 -0
- package/src/daemon/spawn.ts +53 -0
- package/src/formatter/errors.ts +15 -0
- package/src/formatter/source.ts +74 -0
- package/src/formatter/stack.ts +70 -0
- package/src/formatter/values.ts +269 -0
- package/src/formatter/variables.ts +20 -0
- package/src/main.ts +45 -0
- package/src/protocol/messages.ts +316 -0
- package/src/refs/ref-table.ts +120 -0
- package/src/refs/resolver.ts +24 -0
- package/src/sourcemap/resolver.ts +318 -0
- package/tests/fixtures/async-app.js +34 -0
- package/tests/fixtures/console-app.js +12 -0
- package/tests/fixtures/error-app.js +28 -0
- package/tests/fixtures/exception-app.js +6 -0
- package/tests/fixtures/inspect-app.js +10 -0
- package/tests/fixtures/mutation-app.js +9 -0
- package/tests/fixtures/simple-app.js +50 -0
- package/tests/fixtures/step-app.js +13 -0
- package/tests/fixtures/ts-app/src/app.ts +21 -0
- package/tests/fixtures/ts-app/tsconfig.json +14 -0
- package/tests/integration/blackbox.test.ts +135 -0
- package/tests/integration/break-extras.test.ts +241 -0
- package/tests/integration/breakpoint.test.ts +217 -0
- package/tests/integration/console.test.ts +275 -0
- package/tests/integration/execution.test.ts +247 -0
- package/tests/integration/inspection.test.ts +311 -0
- package/tests/integration/mutation.test.ts +178 -0
- package/tests/integration/session.test.ts +223 -0
- package/tests/integration/source.test.ts +209 -0
- package/tests/integration/sourcemap.test.ts +214 -0
- package/tests/integration/state.test.ts +208 -0
- package/tests/unit/cdp-client.test.ts +422 -0
- package/tests/unit/daemon.test.ts +286 -0
- package/tests/unit/formatter.test.ts +716 -0
- package/tests/unit/parser.test.ts +105 -0
- package/tests/unit/refs.test.ts +383 -0
- package/tests/unit/sourcemap.test.ts +236 -0
- package/tsconfig.json +32 -0
package/.bin/ndbg
ADDED
|
Binary file
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(python3:*)",
|
|
5
|
+
"Bash(npx tsx:*)",
|
|
6
|
+
"Bash(bun run build:*)",
|
|
7
|
+
"Bash(timeout 15 ./dist/ndbg launch tsx:*)",
|
|
8
|
+
"Bash(echo:*)",
|
|
9
|
+
"Bash(timeout:*)",
|
|
10
|
+
"Bash(./dist/ndbg stop:*)",
|
|
11
|
+
"Bash(npm install:*)",
|
|
12
|
+
"Bash(tsx:*)",
|
|
13
|
+
"Bash(./dist/ndbg state:*)",
|
|
14
|
+
"Bash(./dist/ndbg:*)",
|
|
15
|
+
"Bash(bun test:*)",
|
|
16
|
+
"Bash(bun:*)",
|
|
17
|
+
"Bash(grep:*)",
|
|
18
|
+
"Bash(npm view:*)"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ndbg-debugger
|
|
3
|
+
description: >
|
|
4
|
+
Debug Node.js/TypeScript/JavaScript applications using the ndbg CLI debugger.
|
|
5
|
+
Use when: (1) investigating runtime bugs by stepping through code, (2) inspecting
|
|
6
|
+
variable values at specific execution points, (3) setting breakpoints and conditional
|
|
7
|
+
breakpoints, (4) evaluating expressions in a paused context, (5) hot-patching code
|
|
8
|
+
without restarting, (6) debugging test failures by attaching to a running process,
|
|
9
|
+
(7) any task where understanding runtime behavior requires a debugger.
|
|
10
|
+
Triggers: "debug this", "set a breakpoint", "step through", "inspect variables",
|
|
11
|
+
"why is this value wrong", "trace execution", "attach debugger", "runtime error".
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# ndbg Debugger
|
|
15
|
+
|
|
16
|
+
`ndbg` is a CLI debugger for Node.js wrapping the V8 Inspector (CDP). It uses short `@refs` for all entities -- use them instead of long IDs.
|
|
17
|
+
|
|
18
|
+
## Core Debug Loop
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# 1. Launch with breakpoint at first line
|
|
22
|
+
ndbg launch --brk node app.js
|
|
23
|
+
|
|
24
|
+
# 2. Set breakpoints at suspicious locations
|
|
25
|
+
ndbg break src/handler.ts:42
|
|
26
|
+
ndbg break src/utils.ts:15 --condition "count > 10"
|
|
27
|
+
|
|
28
|
+
# 3. Run to breakpoint
|
|
29
|
+
ndbg continue
|
|
30
|
+
|
|
31
|
+
# 4. Inspect state (shows location, source, locals, stack)
|
|
32
|
+
ndbg state
|
|
33
|
+
|
|
34
|
+
# 5. Drill into values
|
|
35
|
+
ndbg props @v1 # expand object
|
|
36
|
+
ndbg props @v1 --depth 3 # expand nested 3 levels
|
|
37
|
+
ndbg eval "items.filter(x => x.active)"
|
|
38
|
+
|
|
39
|
+
# 6. Fix and verify
|
|
40
|
+
ndbg set count 0 # change variable
|
|
41
|
+
ndbg hotpatch src/utils.js # live-edit (reads file from disk)
|
|
42
|
+
ndbg continue # verify fix
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Debugging Strategies
|
|
46
|
+
|
|
47
|
+
### Bug investigation -- narrow down with breakpoints
|
|
48
|
+
```bash
|
|
49
|
+
ndbg launch --brk node app.js
|
|
50
|
+
ndbg break src/api.ts:50 # suspect line
|
|
51
|
+
ndbg break src/api.ts:60 --condition "!user" # conditional
|
|
52
|
+
ndbg continue
|
|
53
|
+
ndbg vars # check locals
|
|
54
|
+
ndbg eval "JSON.stringify(req.body)" # inspect deeply
|
|
55
|
+
ndbg step over # advance one line
|
|
56
|
+
ndbg state # see new state
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Attach to running/test process
|
|
60
|
+
```bash
|
|
61
|
+
# Start node with inspector
|
|
62
|
+
node --inspect app.js
|
|
63
|
+
# Or attach by PID
|
|
64
|
+
ndbg attach 12345
|
|
65
|
+
ndbg state
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Trace execution flow with logpoints (no pause)
|
|
69
|
+
```bash
|
|
70
|
+
ndbg logpoint src/auth.ts:20 "login attempt: ${username}"
|
|
71
|
+
ndbg logpoint src/auth.ts:45 "auth result: ${result}"
|
|
72
|
+
ndbg continue
|
|
73
|
+
ndbg console # see logged output
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Exception debugging
|
|
77
|
+
```bash
|
|
78
|
+
ndbg catch uncaught # pause on uncaught exceptions
|
|
79
|
+
ndbg continue # runs until exception
|
|
80
|
+
ndbg state # see where it threw
|
|
81
|
+
ndbg eval "err.message" # inspect the error
|
|
82
|
+
ndbg stack # full call stack
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### TypeScript source map support
|
|
86
|
+
ndbg automatically resolves `.ts` paths via source maps. Set breakpoints using `.ts` paths, see `.ts` source in output. Use `--generated` to see compiled `.js` if needed.
|
|
87
|
+
|
|
88
|
+
## Ref System
|
|
89
|
+
|
|
90
|
+
Every output assigns short refs. Use them everywhere:
|
|
91
|
+
- `@v1..@vN` -- variables: `ndbg props @v1`, `ndbg set @v2 true`
|
|
92
|
+
- `@f0..@fN` -- stack frames: `ndbg eval --frame @f1 "this"`
|
|
93
|
+
- `BP#1..N` -- breakpoints: `ndbg break-rm BP#1`, `ndbg break-toggle BP#1`
|
|
94
|
+
- `LP#1..N` -- logpoints: `ndbg break-rm LP#1`
|
|
95
|
+
|
|
96
|
+
Refs `@v`/`@f` reset on each pause. `BP#`/`LP#` persist until removed.
|
|
97
|
+
|
|
98
|
+
## Key Flags
|
|
99
|
+
|
|
100
|
+
- `--json` -- machine-readable JSON output on any command
|
|
101
|
+
- `--session NAME` -- target a specific session (default: "default")
|
|
102
|
+
- `--generated` -- bypass source maps, show compiled JS (on state/source/stack)
|
|
103
|
+
|
|
104
|
+
## Command Reference
|
|
105
|
+
|
|
106
|
+
See [references/commands.md](references/commands.md) for full command details and options.
|
|
107
|
+
|
|
108
|
+
## Tips
|
|
109
|
+
|
|
110
|
+
- `ndbg state` after stepping always shows location + source + locals -- usually enough context
|
|
111
|
+
- `ndbg state -c` for source only, `-v` for vars only, `-s` for stack only -- save tokens
|
|
112
|
+
- `ndbg eval` supports `await` -- useful for async inspection
|
|
113
|
+
- `ndbg blackbox "node_modules/**"` -- skip stepping into dependencies
|
|
114
|
+
- `ndbg hotpatch file` reads the file from disk -- edit the file first, then hotpatch
|
|
115
|
+
- Execution commands (`continue`, `step`, `pause`, `run-to`) auto-return status
|
|
116
|
+
- `ndbg stop` kills the debugged process and daemon
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# ndbg Command Reference
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
- [Session](#session)
|
|
5
|
+
- [Execution](#execution)
|
|
6
|
+
- [Inspection](#inspection)
|
|
7
|
+
- [Breakpoints](#breakpoints)
|
|
8
|
+
- [Mutation](#mutation)
|
|
9
|
+
- [Blackboxing](#blackboxing)
|
|
10
|
+
- [Source Maps](#source-maps)
|
|
11
|
+
- [Global Flags](#global-flags)
|
|
12
|
+
|
|
13
|
+
## Session
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
ndbg launch [--brk] <command...> # Start + attach debugger (--brk pauses at first line)
|
|
17
|
+
ndbg attach <pid|ws-url|port> # Attach to running process
|
|
18
|
+
ndbg stop # Kill process + daemon
|
|
19
|
+
ndbg sessions [--cleanup] # List active sessions
|
|
20
|
+
ndbg status # Session info (pid, state, pause location)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Execution
|
|
24
|
+
|
|
25
|
+
All execution commands automatically return session status (state + pause info).
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
ndbg continue # Resume to next breakpoint or completion
|
|
29
|
+
ndbg step [over|into|out] # Step one statement (default: over)
|
|
30
|
+
ndbg run-to <file>:<line> # Continue to specific location
|
|
31
|
+
ndbg pause # Interrupt running process
|
|
32
|
+
ndbg restart-frame [@fN] # Re-execute frame from beginning
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Inspection
|
|
36
|
+
|
|
37
|
+
### state -- composite snapshot
|
|
38
|
+
```bash
|
|
39
|
+
ndbg state # Full snapshot: location, source, locals, stack, breakpoints
|
|
40
|
+
ndbg state -v # Locals only
|
|
41
|
+
ndbg state -s # Stack only
|
|
42
|
+
ndbg state -c # Source code only
|
|
43
|
+
ndbg state -b # Breakpoints only
|
|
44
|
+
ndbg state --depth 3 # Expand object values to depth 3
|
|
45
|
+
ndbg state --lines 10 # Show 10 lines of source context
|
|
46
|
+
ndbg state --frame @f1 # Inspect a different stack frame
|
|
47
|
+
ndbg state --all-scopes # Include closure scope variables
|
|
48
|
+
ndbg state --compact # Compact output
|
|
49
|
+
ndbg state --generated # Show compiled JS paths instead of TS
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### vars -- local variables
|
|
53
|
+
```bash
|
|
54
|
+
ndbg vars # All locals in current frame
|
|
55
|
+
ndbg vars name1 name2 # Filter specific variables
|
|
56
|
+
ndbg vars --frame @f1 # Variables from a different frame
|
|
57
|
+
ndbg vars --all-scopes # Include closure scope
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### stack -- call stack
|
|
61
|
+
```bash
|
|
62
|
+
ndbg stack # Full call stack
|
|
63
|
+
ndbg stack --async-depth 5 # Include async frames
|
|
64
|
+
ndbg stack --generated # Show compiled JS paths
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### eval -- evaluate expression
|
|
68
|
+
```bash
|
|
69
|
+
ndbg eval <expression> # Evaluate in current frame
|
|
70
|
+
ndbg eval "await fetchUser(id)" # Await supported
|
|
71
|
+
ndbg eval --frame @f1 "this" # Evaluate in different frame
|
|
72
|
+
ndbg eval --silent "setup()" # No output (side effects only)
|
|
73
|
+
ndbg eval --side-effect-free "x + 1" # Abort if side effects detected
|
|
74
|
+
ndbg eval --timeout 5000 "slowFn()" # Custom timeout in ms
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### props -- expand object
|
|
78
|
+
```bash
|
|
79
|
+
ndbg props @v1 # Expand object properties
|
|
80
|
+
ndbg props @v1 --depth 3 # Nested expansion
|
|
81
|
+
ndbg props @v1 --own # Own properties only
|
|
82
|
+
ndbg props @v1 --private # Include private fields
|
|
83
|
+
ndbg props @v1 --internal # Include internal slots
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### source -- view source code
|
|
87
|
+
```bash
|
|
88
|
+
ndbg source # Source around current line
|
|
89
|
+
ndbg source --lines 20 # 20 lines of context
|
|
90
|
+
ndbg source --file src/app.ts # Source of a specific file
|
|
91
|
+
ndbg source --all # Entire file
|
|
92
|
+
ndbg source --generated # Show compiled JS
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Other inspection
|
|
96
|
+
```bash
|
|
97
|
+
ndbg search "query" # Search loaded scripts
|
|
98
|
+
ndbg search "pattern" --regex # Regex search
|
|
99
|
+
ndbg search "text" --case-sensitive # Case-sensitive search
|
|
100
|
+
ndbg search "text" --file <id> # Search in specific script
|
|
101
|
+
ndbg scripts # List loaded scripts
|
|
102
|
+
ndbg scripts --filter "src/" # Filter by pattern
|
|
103
|
+
ndbg console # Show console output
|
|
104
|
+
ndbg console --since 5 # Last 5 messages
|
|
105
|
+
ndbg console --level error # Filter by level
|
|
106
|
+
ndbg console --clear # Clear console buffer
|
|
107
|
+
ndbg exceptions # Show captured exceptions
|
|
108
|
+
ndbg exceptions --since 3 # Last 3 exceptions
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Breakpoints
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
ndbg break <file>:<line> # Set breakpoint
|
|
115
|
+
ndbg break src/app.ts:42 --condition "x > 10" # Conditional
|
|
116
|
+
ndbg break src/app.ts:42 --hit-count 5 # Break on Nth hit
|
|
117
|
+
ndbg break src/app.ts:42 --continue # Log but don't pause
|
|
118
|
+
ndbg break --pattern "handler":15 # Regex URL match
|
|
119
|
+
ndbg break-rm BP#1 # Remove specific breakpoint
|
|
120
|
+
ndbg break-rm all # Remove all breakpoints
|
|
121
|
+
ndbg break-ls # List all breakpoints
|
|
122
|
+
ndbg break-toggle BP#1 # Disable/enable one breakpoint
|
|
123
|
+
ndbg break-toggle all # Disable/enable all
|
|
124
|
+
ndbg breakable src/app.ts:10-50 # List valid breakpoint locations
|
|
125
|
+
ndbg logpoint src/app.ts:20 "x=${x}" # Log without pausing
|
|
126
|
+
ndbg logpoint src/app.ts:20 "x=${x}" --condition "x > 0"
|
|
127
|
+
ndbg catch all # Pause on all exceptions
|
|
128
|
+
ndbg catch uncaught # Pause on uncaught only
|
|
129
|
+
ndbg catch none # Don't pause on exceptions
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Mutation
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
ndbg set <@ref|name> <value> # Change variable value
|
|
136
|
+
ndbg set count 0 # By name
|
|
137
|
+
ndbg set @v2 true # By ref
|
|
138
|
+
ndbg set-return "newValue" # Change return value (at return point)
|
|
139
|
+
ndbg hotpatch <file> # Live-edit script from disk
|
|
140
|
+
ndbg hotpatch <file> --dry-run # Preview without applying
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Blackboxing
|
|
144
|
+
|
|
145
|
+
Skip stepping into matching scripts (useful for node_modules).
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
ndbg blackbox "node_modules/**" # Add pattern
|
|
149
|
+
ndbg blackbox "lib/**" "vendor/**" # Multiple patterns
|
|
150
|
+
ndbg blackbox-ls # List patterns
|
|
151
|
+
ndbg blackbox-rm "node_modules/**" # Remove specific pattern
|
|
152
|
+
ndbg blackbox-rm all # Remove all patterns
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Source Maps
|
|
156
|
+
|
|
157
|
+
ndbg auto-detects source maps from `Debugger.scriptParsed` events. TypeScript `.ts` paths work transparently for breakpoints and display.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
ndbg sourcemap # List all loaded source maps
|
|
161
|
+
ndbg sourcemap src/app.ts # Info for specific file
|
|
162
|
+
ndbg sourcemap --disable # Disable resolution globally
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Global Flags
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
--session NAME # Target session (default: "default")
|
|
169
|
+
--json # JSON output
|
|
170
|
+
--color # Enable ANSI colors
|
|
171
|
+
--help-agent # LLM-optimized reference card
|
|
172
|
+
--help # Human help
|
|
173
|
+
```
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# ndbg — Node.js Debugger CLI for AI Agents
|
|
2
|
+
|
|
3
|
+
## Project Overview
|
|
4
|
+
CLI debugger for Node.js built with Bun, optimized for AI agent consumption.
|
|
5
|
+
See `ndbg-spec.md` for full specification, `PROGRESS.md` for implementation status.
|
|
6
|
+
|
|
7
|
+
## Tech Stack
|
|
8
|
+
- **Runtime**: Bun (compiled to standalone binary via `bun build --compile`)
|
|
9
|
+
- **Language**: TypeScript (strict mode)
|
|
10
|
+
- **Linting/Formatting**: Biome
|
|
11
|
+
- **Testing**: bun:test
|
|
12
|
+
- **Validation**: Zod v4 (mini)
|
|
13
|
+
- **Dependencies**: Minimal — leverage Bun built-ins (WebSocket, test runner, file I/O)
|
|
14
|
+
|
|
15
|
+
## Project Structure
|
|
16
|
+
```
|
|
17
|
+
src/
|
|
18
|
+
cli/ # CLI argument parsing, command routing
|
|
19
|
+
daemon/ # Background daemon process, Unix socket server
|
|
20
|
+
cdp/ # Chrome DevTools Protocol WebSocket client
|
|
21
|
+
refs/ # @ref system (mapping short refs to V8 IDs)
|
|
22
|
+
formatter/ # Output formatting (variables, source, stack traces)
|
|
23
|
+
commands/ # Command implementations (break, step, eval, etc.)
|
|
24
|
+
protocol/ # CLI-to-daemon JSON protocol types
|
|
25
|
+
tests/
|
|
26
|
+
unit/ # Unit tests
|
|
27
|
+
integration/ # Integration tests
|
|
28
|
+
fixtures/ # Test fixture scripts
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Commands
|
|
32
|
+
- `bun run dev` — run in development
|
|
33
|
+
- `bun test` — run all tests
|
|
34
|
+
- `bun run build` — compile standalone binary
|
|
35
|
+
- `bun run lint` — lint with biome
|
|
36
|
+
- `bun run format` — format with biome
|
|
37
|
+
|
|
38
|
+
## Guidelines
|
|
39
|
+
- Use Bun APIs over Node.js equivalents (WebSocket, Bun.serve, Bun.$, etc.)
|
|
40
|
+
- No ANSI colors by default (token efficiency for AI agents)
|
|
41
|
+
- Every error should suggest the next valid command
|
|
42
|
+
- Keep output compact — one entity per line where possible
|
|
43
|
+
- Use @refs for all inspectable entities in output
|
package/PROGRESS.md
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# ndbg Development Progress
|
|
2
|
+
|
|
3
|
+
> Status legend: `[ ]` Not started | `[~]` In progress | `[x]` Done | `[-]` Blocked
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Phase 0 — Project Setup
|
|
8
|
+
|
|
9
|
+
- [x] Initialize Bun project with TypeScript `bun init`
|
|
10
|
+
- [x] Set up project structure (src/, tests/, fixtures/)
|
|
11
|
+
- [x] Configure `bun build --compile` for standalone binary
|
|
12
|
+
- [x] Set up test framework (bun:test)
|
|
13
|
+
- [x] Set up CLI argument parser (command + subcommands + flags)
|
|
14
|
+
- [x] Configure linting / formatting
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Phase 1 — Core Infrastructure
|
|
19
|
+
|
|
20
|
+
### 1.1 Daemon Architecture
|
|
21
|
+
|
|
22
|
+
- [x] Daemon process spawning and backgrounding
|
|
23
|
+
- [x] Unix socket server (listen on `$XDG_RUNTIME_DIR/ndbg/<session>.sock`)
|
|
24
|
+
- [x] CLI-to-daemon request/response protocol (newline-delimited JSON)
|
|
25
|
+
- [x] Daemon auto-termination on process exit
|
|
26
|
+
- [x] Daemon idle timeout (configurable, default 300s)
|
|
27
|
+
- [x] Lock file to prevent duplicate daemons per session
|
|
28
|
+
- [x] Crash recovery: detect dead socket, suggest `ndbg attach`
|
|
29
|
+
|
|
30
|
+
### 1.2 CDP (Chrome DevTools Protocol) Connection
|
|
31
|
+
|
|
32
|
+
- [x] WebSocket client to V8 inspector (`ws://127.0.0.1:<port>`)
|
|
33
|
+
- [x] CDP message send/receive with request ID tracking
|
|
34
|
+
- [x] CDP event subscription and dispatching
|
|
35
|
+
- [x] Enable required CDP domains (Debugger, Runtime, Profiler, HeapProfiler)
|
|
36
|
+
- [x] `Runtime.runIfWaitingForDebugger` on attach
|
|
37
|
+
|
|
38
|
+
### 1.3 @ref System
|
|
39
|
+
|
|
40
|
+
- [x] Ref table data structure (map short refs to V8 remote object IDs)
|
|
41
|
+
- [x] `@v` refs — variable/value refs (regenerated on each pause)
|
|
42
|
+
- [x] `@f` refs — stack frame refs (regenerated on each pause)
|
|
43
|
+
- [x] `@o` refs — expanded object refs (append-only, persist across pauses)
|
|
44
|
+
- [x] `BP#` refs — breakpoint refs (persist until removed)
|
|
45
|
+
- [x] `LP#` refs — logpoint refs (persist until removed)
|
|
46
|
+
- [x] `HS#` refs — heap snapshot refs (persist until session ends)
|
|
47
|
+
- [x] Ref resolution: resolve `@ref` in CLI arguments to V8 IDs
|
|
48
|
+
- [x] `ndbg gc-refs` — clear accumulated `@o` refs
|
|
49
|
+
|
|
50
|
+
### 1.4 Output Formatter
|
|
51
|
+
|
|
52
|
+
- [x] Variable formatting (Objects, Arrays, Functions, Promises, Errors, Buffers, Map, Set)
|
|
53
|
+
- [x] Smart truncation (~80 chars per value)
|
|
54
|
+
- [x] Source code display (line numbers, `→` current line, `●` breakpoint markers)
|
|
55
|
+
- [x] Stack trace display (`@f` refs, async gap markers, blackboxed frame collapsing)
|
|
56
|
+
- [x] Error output with actionable suggestions (`→ Try: ...`)
|
|
57
|
+
- [x] `--color` flag for ANSI terminal colors
|
|
58
|
+
- [x] `--json` flag for JSON output mode
|
|
59
|
+
- [x] Truncation hints (`... (ndbg props @oN for more)`)
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Phase 2 — Session Management
|
|
64
|
+
|
|
65
|
+
- [x] `ndbg launch [--brk] [--session NAME] <command...>` — spawn + attach
|
|
66
|
+
- [x] `ndbg launch --brk` — spawn with `--inspect-brk`, pause on first line
|
|
67
|
+
- [x] `ndbg launch --port PORT` — use specific inspector port
|
|
68
|
+
- [x] `ndbg launch --timeout SECS` — configure daemon idle timeout
|
|
69
|
+
- [x] `ndbg attach <pid | ws-url | port>` — attach to running process
|
|
70
|
+
- [x] `ndbg stop [--session NAME]` — kill process + daemon
|
|
71
|
+
- [x] `ndbg sessions` — list active sessions (PID, status, name)
|
|
72
|
+
- [x] `ndbg sessions --cleanup` — kill orphaned daemons
|
|
73
|
+
- [x] `ndbg status` — session info (PID, pause state, breakpoints, memory, uptime)
|
|
74
|
+
- [x] Multi-session support (`--session NAME` on any command)
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Phase 3 — State Snapshot
|
|
79
|
+
|
|
80
|
+
- [x] `ndbg state` — full state snapshot (source + locals + stack + breakpoints)
|
|
81
|
+
- [x] State filtering: `-v` / `--vars` (locals only)
|
|
82
|
+
- [x] State filtering: `-s` / `--stack` (stack trace only)
|
|
83
|
+
- [x] State filtering: `-b` / `--breakpoints` (breakpoints/logpoints only)
|
|
84
|
+
- [x] State filtering: `-c` / `--code` (source context only)
|
|
85
|
+
- [x] `--compact` flag — one-line-per-section summary
|
|
86
|
+
- [x] `--depth N` — object expansion depth (default: 1)
|
|
87
|
+
- [x] `--lines N` — source context lines (default: 3)
|
|
88
|
+
- [x] `--frame @fN` — state from perspective of frame N
|
|
89
|
+
- [x] `--all-scopes` — include closure and global scope
|
|
90
|
+
- [x] `--json` — full state as JSON
|
|
91
|
+
- [x] Auto-state return after execution commands (continue, step, etc.)
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Phase 4 — Breakpoints
|
|
96
|
+
|
|
97
|
+
- [x] `ndbg break <file>:<line>` — set breakpoint (`Debugger.setBreakpointByUrl`)
|
|
98
|
+
- [x] `ndbg break --condition <expr>` — conditional breakpoint
|
|
99
|
+
- [x] `ndbg break --hit-count <n>` — pause on Nth hit
|
|
100
|
+
- [x] `ndbg break --continue` — set breakpoint + immediately continue
|
|
101
|
+
- [ ] `ndbg break --log <template>` — shortcut to logpoint
|
|
102
|
+
- [x] `ndbg break --pattern <urlRegex>:<line>` — regex pattern breakpoint
|
|
103
|
+
- [ ] `ndbg break-fn <expr>` — breakpoint on function call
|
|
104
|
+
- [ ] `ndbg break-on-load [--sourcemap]` — break on new script parse
|
|
105
|
+
- [x] `ndbg break-rm <BP# | LP# | all>` — remove breakpoints
|
|
106
|
+
- [x] `ndbg break-ls` — list all breakpoints/logpoints with locations and conditions
|
|
107
|
+
- [x] `ndbg break-toggle [BP# | all]` — enable/disable breakpoints
|
|
108
|
+
- [x] `ndbg breakable <file>:<start>-<end>` — list valid breakpoint locations
|
|
109
|
+
- [x] `ndbg logpoint <file>:<line> <template>` — set logpoint (no pause)
|
|
110
|
+
- [ ] Logpoint `--max <n>` — auto-pause after N emissions (default: 100)
|
|
111
|
+
- [x] Logpoint `--condition <expr>` — conditional logpoint
|
|
112
|
+
- [x] `ndbg catch [all | uncaught | caught | none]` — pause-on-exception config
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Phase 5 — Execution Control
|
|
117
|
+
|
|
118
|
+
- [x] `ndbg continue` — resume execution (+ auto-state return)
|
|
119
|
+
- [x] `ndbg step over` — step one statement over (default)
|
|
120
|
+
- [x] `ndbg step into` — step into function call
|
|
121
|
+
- [x] `ndbg step out` — step out of current function
|
|
122
|
+
- [ ] `ndbg step into --break-on-async` — pause on first async task
|
|
123
|
+
- [ ] `ndbg step --skip <pattern>` — inline blackboxing during step
|
|
124
|
+
- [x] `ndbg run-to <file>:<line>` — continue to location (no persistent breakpoint)
|
|
125
|
+
- [x] `ndbg restart-frame [@fN]` — re-execute frame from beginning
|
|
126
|
+
- [x] `ndbg pause` — interrupt running process
|
|
127
|
+
- [ ] `ndbg kill-execution` — terminate JS execution, keep session alive
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Phase 6 — Inspection
|
|
132
|
+
|
|
133
|
+
- [x] `ndbg vars [name1, name2, ...]` — show local variables with `@v` refs
|
|
134
|
+
- [x] `ndbg stack [--async-depth N]` — show call stack with `@f` refs
|
|
135
|
+
- [x] `ndbg eval <expression>` — evaluate in current frame context
|
|
136
|
+
- [x] `ndbg eval` with `await` support (CDP `awaitPromise`)
|
|
137
|
+
- [x] `ndbg eval` with `@ref` interpolation
|
|
138
|
+
- [x] `ndbg eval --frame @fN` — evaluate in specific frame
|
|
139
|
+
- [x] `ndbg eval --silent` — suppress exception reporting
|
|
140
|
+
- [x] `ndbg eval --timeout MS` — kill after N ms (default: 5000)
|
|
141
|
+
- [x] `ndbg eval --side-effect-free` — throw on side effects
|
|
142
|
+
- [x] `ndbg props <@ref>` — expand object properties (returns `@o` refs)
|
|
143
|
+
- [x] `ndbg props --own` — only own properties
|
|
144
|
+
- [x] `ndbg props --depth N` — recursive expansion
|
|
145
|
+
- [x] `ndbg props --private` — include private fields
|
|
146
|
+
- [x] `ndbg props --internal` — V8 internal properties (`[[PromiseState]]`)
|
|
147
|
+
- [ ] `ndbg instances <expression>` — find all live instances of prototype
|
|
148
|
+
- [ ] `ndbg globals` — list global let/const/class declarations
|
|
149
|
+
- [x] `ndbg source [--lines N] [--file <path>] [--all]` — show source code
|
|
150
|
+
- [x] `ndbg search <query> [--regex] [--case-sensitive] [--file <id>]` — search scripts
|
|
151
|
+
- [x] `ndbg scripts [--filter <pattern>]` — list loaded scripts
|
|
152
|
+
- [x] `ndbg console [--follow] [--since N] [--level] [--clear]` — console output
|
|
153
|
+
- [x] `ndbg exceptions [--follow] [--since N]` — captured exceptions
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Phase 7 — Mutation
|
|
158
|
+
|
|
159
|
+
- [x] `ndbg set <@vRef | varName> <value>` — change variable value
|
|
160
|
+
- [x] `ndbg set-return <value>` — change return value (at return point)
|
|
161
|
+
- [x] `ndbg hotpatch <file>` — live-edit script source (`Debugger.setScriptSource`)
|
|
162
|
+
- [x] `ndbg hotpatch --dry-run` — check without applying
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Phase 8 — Blackboxing
|
|
167
|
+
|
|
168
|
+
- [x] `ndbg blackbox <pattern...>` — skip stepping into matching scripts
|
|
169
|
+
- [x] `ndbg blackbox-ls` — list current patterns
|
|
170
|
+
- [x] `ndbg blackbox-rm <pattern | all>` — remove patterns
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Phase 9 — Source Map Support
|
|
175
|
+
|
|
176
|
+
- [x] Fetch and cache source maps from `Debugger.scriptParsed` events
|
|
177
|
+
- [x] Resolve `.ts` locations to `.js` for breakpoint setting
|
|
178
|
+
- [x] Display source-mapped paths in all output (stack traces, source, breakpoints)
|
|
179
|
+
- [x] Show original source (TypeScript) in `ndbg source`
|
|
180
|
+
- [x] Graceful fallback when no source map exists
|
|
181
|
+
- [x] `ndbg sourcemap <file>` — show source map info
|
|
182
|
+
- [x] `ndbg sourcemap --disable` — disable resolution globally
|
|
183
|
+
- [x] `--generated` flag — bypass source map resolution per-command (state, source, stack)
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Phase 10 — CPU Profiling
|
|
188
|
+
|
|
189
|
+
- [ ] `ndbg cpu start [--interval <us>]` — start V8 CPU profiler
|
|
190
|
+
- [ ] `ndbg cpu stop [--top N]` — stop profiling + report (function, file:line, self%, total%, deopt)
|
|
191
|
+
- [ ] Save full profile to file for external tools
|
|
192
|
+
- [ ] `ndbg coverage start [--detailed]` — start code coverage
|
|
193
|
+
- [ ] `ndbg coverage stop [--file] [--uncovered]` — stop + report
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Phase 11 — Memory / Heap
|
|
198
|
+
|
|
199
|
+
- [ ] `ndbg heap usage` — quick heap statistics
|
|
200
|
+
- [ ] `ndbg heap snapshot [--tag <name>]` — full heap snapshot (assigns `HS#` ref)
|
|
201
|
+
- [ ] `ndbg heap diff <HS#a> <HS#b> [--top N]` — compare snapshots
|
|
202
|
+
- [ ] `ndbg heap sample start [--interval] [--include-gc]` — sampling profiler
|
|
203
|
+
- [ ] `ndbg heap sample stop [--top N]` — stop sampling + report
|
|
204
|
+
- [ ] `ndbg heap track start` — allocation tracking (timeline)
|
|
205
|
+
- [ ] `ndbg heap track stop` — stop tracking + report
|
|
206
|
+
- [ ] `ndbg heap inspect <heapObjectId>` — get runtime ref from snapshot node
|
|
207
|
+
- [ ] `ndbg gc` — force garbage collection
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## Phase 12 — Advanced / Utility
|
|
212
|
+
|
|
213
|
+
- [ ] `ndbg inject-hook <name>` — create runtime binding (`__ndbg_<name>()`)
|
|
214
|
+
- [ ] `ndbg hooks [--follow]` — view hook invocations
|
|
215
|
+
- [ ] `ndbg contexts` — list V8 execution contexts
|
|
216
|
+
- [ ] `ndbg async-depth <N>` — set async call stack depth
|
|
217
|
+
- [ ] `ndbg config [key] [value]` — get/set daemon configuration
|
|
218
|
+
- [ ] `ndbg gc-refs` — clear `@o` refs to free memory
|
|
219
|
+
- [ ] `ndbg --help-agent` — compact LLM-optimized reference card
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Phase 13 — Distribution & Integration
|
|
224
|
+
|
|
225
|
+
- [ ] `bun build --compile` producing standalone binaries (linux-x64, darwin-arm64, etc.)
|
|
226
|
+
- [ ] npm package (`npx ndbg` support)
|
|
227
|
+
- [ ] SKILL.md for Claude Code agent integration
|
|
228
|
+
- [ ] `--help-agent` output matching spec reference card
|
|
229
|
+
- [ ] GitHub releases with prebuilt binaries
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Phase 14 — Testing
|
|
234
|
+
|
|
235
|
+
### Unit Tests
|
|
236
|
+
|
|
237
|
+
- [ ] Ref system: creation, resolution, lifecycle, collision handling
|
|
238
|
+
- [ ] Output formatters: variable formatting, truncation, source display
|
|
239
|
+
- [ ] Source map resolution: .ts → .js mapping, inline source maps, missing maps
|
|
240
|
+
- [ ] Command argument parsing
|
|
241
|
+
|
|
242
|
+
### Integration Tests
|
|
243
|
+
|
|
244
|
+
- [ ] Launch + attach + breakpoint + step + inspect + stop lifecycle
|
|
245
|
+
- [ ] Conditional breakpoints with expression evaluation
|
|
246
|
+
- [ ] Logpoint emission and flood throttling
|
|
247
|
+
- [ ] Source map resolution end-to-end (TypeScript project)
|
|
248
|
+
- [ ] Hotpatch: edit, verify, dry-run, blocked scenarios
|
|
249
|
+
- [ ] Multi-session: two concurrent debug sessions
|
|
250
|
+
- [ ] Heap snapshot, diff, sampling
|
|
251
|
+
- [ ] CPU profiling and coverage collection
|
|
252
|
+
- [ ] Daemon crash recovery and orphan cleanup
|
|
253
|
+
|
|
254
|
+
### Agent Simulation Tests
|
|
255
|
+
|
|
256
|
+
- [ ] Race condition debugging scenario (bash script)
|
|
257
|
+
- [ ] Circular dependency tracing scenario
|
|
258
|
+
- [ ] Memory leak detection scenario
|
|
259
|
+
- [ ] Metric: total tool calls needed
|
|
260
|
+
- [ ] Metric: total tokens in output
|
|
261
|
+
- [ ] Metric: success rate vs MCP-based debuggers
|
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# ndbg
|
|
2
|
+
|
|
3
|
+
Node.js debugger CLI built for AI agents. Fast, token-efficient, no fluff.
|
|
4
|
+
|
|
5
|
+
**Why?** Agents waste tokens on print-debugging. A real debugger gives precise state inspection in minimal output — variables, stack, breakpoints — all via short `@ref` handles.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Requires [Bun](https://bun.sh).
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bunx ndbg
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Setup
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
git clone <repo> && cd ndbg
|
|
19
|
+
bun install
|
|
20
|
+
bun run build # -> dist/ndbg
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
ndbg launch --brk node app.js
|
|
27
|
+
# Session "default" started (pid 12345)
|
|
28
|
+
# Paused at app.js:1:1
|
|
29
|
+
|
|
30
|
+
ndbg break src/handler.ts:42
|
|
31
|
+
# BP#1 src/handler.ts:42
|
|
32
|
+
|
|
33
|
+
ndbg continue
|
|
34
|
+
# Paused at src/handler.ts:42:5 (breakpoint)
|
|
35
|
+
|
|
36
|
+
ndbg vars
|
|
37
|
+
# @v1 x 42
|
|
38
|
+
# @v2 name "alice"
|
|
39
|
+
# @v3 opts {timeout: 3000}
|
|
40
|
+
|
|
41
|
+
ndbg props @v3
|
|
42
|
+
# @o1 timeout 3000
|
|
43
|
+
|
|
44
|
+
ndbg eval "x + 1"
|
|
45
|
+
# 43
|
|
46
|
+
|
|
47
|
+
ndbg step over
|
|
48
|
+
# Paused at src/handler.ts:43:5 (step)
|
|
49
|
+
|
|
50
|
+
ndbg set @v1 100
|
|
51
|
+
# @v1 changed to 100
|
|
52
|
+
|
|
53
|
+
ndbg stop
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Commands
|
|
57
|
+
|
|
58
|
+
| Category | Commands |
|
|
59
|
+
|---|---|
|
|
60
|
+
| Session | `launch`, `attach`, `stop`, `status`, `sessions` |
|
|
61
|
+
| Execution | `continue`, `step [over\|into\|out]`, `pause`, `run-to`, `restart-frame` |
|
|
62
|
+
| Inspection | `state`, `vars`, `stack`, `eval`, `props`, `source`, `scripts`, `search`, `console`, `exceptions` |
|
|
63
|
+
| Breakpoints | `break`, `break-rm`, `break-ls`, `break-toggle`, `breakable`, `logpoint`, `catch` |
|
|
64
|
+
| Mutation | `set`, `set-return`, `hotpatch` |
|
|
65
|
+
| Blackbox | `blackbox`, `blackbox-ls`, `blackbox-rm` |
|
|
66
|
+
|
|
67
|
+
Run `ndbg --help` or `ndbg --help-agent` for the full reference.
|