debug-run 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/README.md +357 -0
- package/dist/index.cjs +7129 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
# debug-run
|
|
2
|
+
|
|
3
|
+
A CLI tool that enables AI agents to programmatically debug code via the [Debug Adapter Protocol (DAP)](https://microsoft.github.io/debug-adapter-protocol/).
|
|
4
|
+
|
|
5
|
+
## Why?
|
|
6
|
+
|
|
7
|
+
Agents can write and run code, but when something goes wrong, they're blind. They can only see error messages and stack traces—they can't inspect actual runtime state. Human developers reach for the debugger; agents should too.
|
|
8
|
+
|
|
9
|
+
**debug-run** exposes debugging capabilities through structured JSON output that agents can parse and act on.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Multi-language support**: .NET, Python, Node.js, C/C++/Rust (via LLDB)
|
|
14
|
+
- **Breakpoints**: Line, conditional (`file:line?condition`), hit count (`file:line#count`)
|
|
15
|
+
- **Exception breakpoints**: Break on thrown/uncaught exceptions
|
|
16
|
+
- **Variable inspection**: Automatic recursive expansion of locals and `this`
|
|
17
|
+
- **Expression evaluation**: Evaluate arbitrary expressions at breakpoints
|
|
18
|
+
- **Assertion-based debugging**: Declare invariants that halt on violation
|
|
19
|
+
- **Trace mode**: Automatically step through execution paths
|
|
20
|
+
- **Stepping**: Step over, step into, step out with state capture
|
|
21
|
+
- **Logpoints**: Log messages without breaking execution
|
|
22
|
+
- **Attach mode**: Debug running processes
|
|
23
|
+
- **Structured output**: NDJSON event stream for easy parsing
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Clone and install
|
|
29
|
+
git clone https://github.com/Chris-Cullins/debug-run.git
|
|
30
|
+
cd debug-run
|
|
31
|
+
npm install
|
|
32
|
+
|
|
33
|
+
# Run via tsx (development)
|
|
34
|
+
npx tsx ./src/index.ts --help
|
|
35
|
+
|
|
36
|
+
# Or build and run
|
|
37
|
+
npm run build
|
|
38
|
+
node dist/index.js --help
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
### List available adapters
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npx tsx ./src/index.ts list-adapters
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Debug a .NET application
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npx tsx ./src/index.ts ./bin/Debug/net8.0/MyApp.dll \
|
|
53
|
+
-a dotnet \
|
|
54
|
+
-b "src/OrderService.cs:45" \
|
|
55
|
+
--pretty
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Debug Python
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npx tsx ./src/index.ts ./main.py \
|
|
62
|
+
-a python \
|
|
63
|
+
-b "processor.py:123" \
|
|
64
|
+
-e "data.count" \
|
|
65
|
+
--pretty
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Debug Node.js
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npx tsx ./src/index.ts ./dist/index.js \
|
|
72
|
+
-a node \
|
|
73
|
+
-b "src/handler.ts:30" \
|
|
74
|
+
--pretty
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## CLI Reference
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
Usage: debug-run [options] [command] [program]
|
|
81
|
+
|
|
82
|
+
Arguments:
|
|
83
|
+
program Program to debug
|
|
84
|
+
|
|
85
|
+
Options:
|
|
86
|
+
-a, --adapter <name> Debug adapter (dotnet, python, node, lldb)
|
|
87
|
+
--args <args...> Arguments to pass to the program
|
|
88
|
+
--cwd <path> Working directory for the program
|
|
89
|
+
-b, --breakpoint <spec...> Breakpoint specs (file:line, file:line?cond, file:line#count)
|
|
90
|
+
-e, --eval <expr...> Expressions to evaluate at breakpoints
|
|
91
|
+
--assert <expr...> Invariant expressions; stops on first violation
|
|
92
|
+
-l, --logpoint <spec...> Logpoints (file:line|message with {expr})
|
|
93
|
+
--break-on-exception <filter...> Break on exceptions (all, uncaught, user-unhandled)
|
|
94
|
+
-t, --timeout <duration> Session timeout (default: 60s)
|
|
95
|
+
--capture-locals Capture local variables (default: true)
|
|
96
|
+
--pretty Pretty print JSON output
|
|
97
|
+
-s, --steps <count> Steps to execute after breakpoint hit
|
|
98
|
+
--capture-each-step Capture state at each step
|
|
99
|
+
--trace Enable trace mode - step through code
|
|
100
|
+
--trace-into Use stepIn instead of stepOver in trace
|
|
101
|
+
--trace-limit <N> Max steps in trace mode (default: 500)
|
|
102
|
+
--trace-until <expr> Stop trace when expression is truthy
|
|
103
|
+
--attach Attach to running process
|
|
104
|
+
--pid <id> Process ID to attach to
|
|
105
|
+
--env <key=value...> Environment variables
|
|
106
|
+
|
|
107
|
+
Commands:
|
|
108
|
+
list-adapters List available debug adapters
|
|
109
|
+
install-adapter <name> Install a debug adapter
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Breakpoint Syntax
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# Simple line breakpoint
|
|
116
|
+
-b "src/file.cs:45"
|
|
117
|
+
|
|
118
|
+
# Conditional breakpoint (break when condition is true)
|
|
119
|
+
-b "src/file.cs:45?order.Total > 1000"
|
|
120
|
+
|
|
121
|
+
# Hit count breakpoint (break on Nth hit)
|
|
122
|
+
-b "src/file.cs:45#3"
|
|
123
|
+
|
|
124
|
+
# Logpoint (log without breaking)
|
|
125
|
+
-l "src/file.cs:45|Processing order {order.Id} with total {order.Total}"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Output Format
|
|
129
|
+
|
|
130
|
+
debug-run outputs newline-delimited JSON (NDJSON) events:
|
|
131
|
+
|
|
132
|
+
```json
|
|
133
|
+
{"type":"session_start","timestamp":"...","adapter":"dotnet","program":"./app.dll"}
|
|
134
|
+
{"type":"breakpoint_set","id":1,"file":"src/Service.cs","line":45,"verified":true}
|
|
135
|
+
{"type":"process_launched","timestamp":"..."}
|
|
136
|
+
{"type":"breakpoint_hit","id":1,"threadId":1,"location":{...},"locals":{...},"evaluations":{...}}
|
|
137
|
+
{"type":"process_exited","exitCode":0}
|
|
138
|
+
{"type":"session_end","summary":{"breakpointsHit":1,"duration":1234}}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Breakpoint Hit Event
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"type": "breakpoint_hit",
|
|
146
|
+
"id": 1,
|
|
147
|
+
"threadId": 1,
|
|
148
|
+
"timestamp": "2025-01-15T10:30:01.234Z",
|
|
149
|
+
"location": {
|
|
150
|
+
"file": "src/OrderService.cs",
|
|
151
|
+
"line": 45,
|
|
152
|
+
"function": "ProcessOrder"
|
|
153
|
+
},
|
|
154
|
+
"stackTrace": [...],
|
|
155
|
+
"locals": {
|
|
156
|
+
"order": {
|
|
157
|
+
"type": "OrderDto",
|
|
158
|
+
"value": {
|
|
159
|
+
"Id": "abc-123",
|
|
160
|
+
"Total": 150.00,
|
|
161
|
+
"Items": {"type": "List<Item>", "count": 3, "items": [...]}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
"this": {...}
|
|
165
|
+
},
|
|
166
|
+
"evaluations": {
|
|
167
|
+
"order.Items.Count": {"result": "3", "type": "int"}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Supported Debug Adapters
|
|
173
|
+
|
|
174
|
+
| Adapter | Languages | Installation |
|
|
175
|
+
|---------|-----------|--------------|
|
|
176
|
+
| `dotnet` / `vsdbg` | C#, F#, VB.NET | VS Code C# extension (auto-detected) |
|
|
177
|
+
| `netcoredbg` | C#, F#, VB.NET | `debug-run install-adapter netcoredbg` |
|
|
178
|
+
| `python` / `debugpy` | Python | `pip install debugpy` |
|
|
179
|
+
| `node` | JavaScript, TypeScript | VS Code (js-debug built-in) |
|
|
180
|
+
| `lldb` | C, C++, Rust, Swift | Xcode CLI tools or LLVM |
|
|
181
|
+
|
|
182
|
+
### Checking adapter status
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
$ npx tsx ./src/index.ts list-adapters
|
|
186
|
+
|
|
187
|
+
Available debug adapters:
|
|
188
|
+
|
|
189
|
+
dotnet
|
|
190
|
+
ID: coreclr
|
|
191
|
+
Status: ✓ installed (/path/to/vsdbg)
|
|
192
|
+
|
|
193
|
+
debugpy
|
|
194
|
+
ID: python
|
|
195
|
+
Status: ✓ installed (python3)
|
|
196
|
+
|
|
197
|
+
node
|
|
198
|
+
ID: pwa-node
|
|
199
|
+
Status: ✗ not installed
|
|
200
|
+
|
|
201
|
+
lldb
|
|
202
|
+
ID: lldb
|
|
203
|
+
Status: ✗ not installed
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Examples
|
|
207
|
+
|
|
208
|
+
### Investigate a test failure
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
npx tsx ./src/index.ts ./bin/Debug/net8.0/TestApp.dll \
|
|
212
|
+
-a dotnet \
|
|
213
|
+
-b "src/InventoryService.cs:34" \
|
|
214
|
+
-e "requestedQuantity" \
|
|
215
|
+
-e "availableStock" \
|
|
216
|
+
--pretty
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Step through code
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
npx tsx ./src/index.ts ./app.dll \
|
|
223
|
+
-a dotnet \
|
|
224
|
+
-b "src/PricingService.cs:45" \
|
|
225
|
+
--steps 10 \
|
|
226
|
+
--capture-each-step \
|
|
227
|
+
--pretty
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Break on exceptions
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
npx tsx ./src/index.ts ./app.dll \
|
|
234
|
+
-a dotnet \
|
|
235
|
+
--break-on-exception "all" \
|
|
236
|
+
--pretty
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Conditional breakpoint
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
npx tsx ./src/index.ts ./app.dll \
|
|
243
|
+
-a dotnet \
|
|
244
|
+
-b "src/OrderService.cs:67?order.Total > 1000" \
|
|
245
|
+
--pretty
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Assertion-based debugging
|
|
249
|
+
|
|
250
|
+
Declare invariants that must remain true. The debugger halts immediately when any assertion fails:
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
npx tsx ./src/index.ts ./app.dll \
|
|
254
|
+
-a dotnet \
|
|
255
|
+
-b "src/OrderService.cs:45" \
|
|
256
|
+
--assert "order.Total >= 0" \
|
|
257
|
+
--assert "order.Items.Count > 0" \
|
|
258
|
+
--assert "customer != null" \
|
|
259
|
+
--pretty
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
When an assertion fails, you get an `assertion_failed` event with:
|
|
263
|
+
- The failed assertion expression
|
|
264
|
+
- The actual value
|
|
265
|
+
- Full stack trace and locals
|
|
266
|
+
- Location where it failed
|
|
267
|
+
|
|
268
|
+
Assertions are checked at breakpoints, during stepping, and during trace mode.
|
|
269
|
+
|
|
270
|
+
### Trace mode (follow execution path)
|
|
271
|
+
|
|
272
|
+
Automatically step through code after hitting a breakpoint:
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
npx tsx ./src/index.ts ./app.dll \
|
|
276
|
+
-a dotnet \
|
|
277
|
+
-b "src/OrderService.cs:45" \
|
|
278
|
+
--trace \
|
|
279
|
+
--trace-limit 100 \
|
|
280
|
+
--pretty
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Trace mode options:
|
|
284
|
+
- `--trace`: Enable trace mode
|
|
285
|
+
- `--trace-into`: Follow into function calls (default: step over)
|
|
286
|
+
- `--trace-limit <N>`: Max steps before stopping (default: 500)
|
|
287
|
+
- `--trace-until <expr>`: Stop when expression becomes truthy
|
|
288
|
+
|
|
289
|
+
## Agent Integration
|
|
290
|
+
|
|
291
|
+
debug-run is designed for AI agents to use programmatically:
|
|
292
|
+
|
|
293
|
+
```python
|
|
294
|
+
import subprocess
|
|
295
|
+
import json
|
|
296
|
+
|
|
297
|
+
result = subprocess.run([
|
|
298
|
+
"npx", "tsx", "./src/index.ts",
|
|
299
|
+
"./bin/Debug/net8.0/MyApp.dll",
|
|
300
|
+
"-a", "dotnet",
|
|
301
|
+
"-b", "src/Service.cs:45",
|
|
302
|
+
"-e", "order.Total",
|
|
303
|
+
"-t", "30s"
|
|
304
|
+
], capture_output=True, text=True)
|
|
305
|
+
|
|
306
|
+
for line in result.stdout.strip().split('\n'):
|
|
307
|
+
event = json.loads(line)
|
|
308
|
+
if event['type'] == 'breakpoint_hit':
|
|
309
|
+
print(f"Hit breakpoint at {event['location']['file']}:{event['location']['line']}")
|
|
310
|
+
print(f"Locals: {event['locals']}")
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Development
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
# Install dependencies
|
|
317
|
+
npm install
|
|
318
|
+
|
|
319
|
+
# Run in development mode
|
|
320
|
+
npx tsx ./src/index.ts [args...]
|
|
321
|
+
|
|
322
|
+
# Type check
|
|
323
|
+
npm run typecheck
|
|
324
|
+
|
|
325
|
+
# Build
|
|
326
|
+
npm run build
|
|
327
|
+
|
|
328
|
+
# Run tests
|
|
329
|
+
npm test
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Architecture
|
|
333
|
+
|
|
334
|
+
```
|
|
335
|
+
src/
|
|
336
|
+
├── index.ts # Entry point
|
|
337
|
+
├── cli.ts # Command-line parsing
|
|
338
|
+
├── dap/ # DAP client implementation
|
|
339
|
+
│ ├── client.ts # Main DAP client
|
|
340
|
+
│ ├── transport.ts # Content-Length framing
|
|
341
|
+
│ └── protocol.ts # DAP message types
|
|
342
|
+
├── session/ # Debug session management
|
|
343
|
+
│ ├── manager.ts # Session lifecycle
|
|
344
|
+
│ ├── variables.ts # Variable inspection
|
|
345
|
+
│ └── breakpoints.ts
|
|
346
|
+
├── adapters/ # Debug adapter configurations
|
|
347
|
+
│ ├── base.ts # Adapter interface
|
|
348
|
+
│ ├── debugpy.ts # Python
|
|
349
|
+
│ ├── node.ts # Node.js
|
|
350
|
+
│ ├── lldb.ts # LLDB
|
|
351
|
+
│ └── ...
|
|
352
|
+
└── output/ # Event formatting
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## License
|
|
356
|
+
|
|
357
|
+
MIT
|