debug-run 0.1.0 → 0.5.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.
@@ -0,0 +1,228 @@
1
+ ---
2
+ name: debug-run
3
+ description: Programmatically debug code using debug-run CLI with DAP. Use when debugging .NET, Python, or JavaScript/TypeScript applications, setting breakpoints, capturing variables, evaluating expressions, or attaching to running processes.
4
+ ---
5
+
6
+ # debug-run Debugging Skill
7
+
8
+ Use the `debug-run` CLI tool to programmatically debug applications via the Debug Adapter Protocol (DAP). This skill enables you to set breakpoints, capture variable state, and evaluate expressions without interactive debugger sessions.
9
+
10
+ ## When to Use This Skill
11
+
12
+ - Debugging .NET applications (using vsdbg adapter)
13
+ - Debugging Python applications (using debugpy adapter)
14
+ - Debugging JavaScript/TypeScript applications (using js-debug/node adapter)
15
+ - Capturing runtime state at specific code locations
16
+ - Evaluating expressions to inspect object properties
17
+ - Attaching to running processes for live debugging
18
+
19
+ ## Prerequisites
20
+
21
+ Ensure debug-run is installed in the project:
22
+
23
+ ```bash
24
+ npm install # in the debug-run directory
25
+ ```
26
+
27
+ Check available adapters:
28
+
29
+ ```bash
30
+ npx debug-run list-adapters
31
+ ```
32
+
33
+ ## Language-Specific Guides
34
+
35
+ For detailed setup, examples, and troubleshooting for each language:
36
+
37
+ - [.NET Debugging Guide](DOTNET.md) - vsdbg adapter, ASP.NET attach mode, NUnit test debugging
38
+ - [Python Debugging Guide](PYTHON.md) - debugpy adapter, VS Code integration, sample app
39
+ - [TypeScript/JavaScript Debugging Guide](TYPESCRIPT.md) - js-debug adapter, source maps, Node.js
40
+
41
+ ## Basic Usage
42
+
43
+ ```bash
44
+ npx debug-run <program> -a <adapter> -b "<file:line>" [options]
45
+ ```
46
+
47
+ ### Quick Examples
48
+
49
+ ```bash
50
+ # .NET
51
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll -a vsdbg -b "src/Service.cs:42" --pretty
52
+
53
+ # Python
54
+ npx debug-run ./main.py -a python -b "src/processor.py:25" --pretty
55
+
56
+ # TypeScript/JavaScript
57
+ npx debug-run ./dist/index.js -a node -b "src/index.ts:100" --pretty
58
+ ```
59
+
60
+ ## Options Reference
61
+
62
+ ### Core Options
63
+
64
+ | Option | Description |
65
+ |--------|-------------|
66
+ | `-a, --adapter <name>` | Debug adapter: `vsdbg` (.NET), `python`/`debugpy` (Python), `node`/`js` (JS/TS) |
67
+ | `-b, --breakpoint <loc>` | Breakpoint location as `file:line` (can specify multiple) |
68
+ | `-e, --eval <expr>` | Expression to evaluate at breakpoints (can specify multiple) |
69
+ | `--assert <expr>` | Invariant expression; halts on first violation (can specify multiple) |
70
+ | `-t, --timeout <time>` | Timeout duration: `30s`, `2m`, `5m` (default: 60s) |
71
+ | `--pretty` | Pretty-print JSON output |
72
+ | `-o, --output <file>` | Write events to file instead of stdout |
73
+
74
+ ### Attach Mode
75
+
76
+ | Option | Description |
77
+ |--------|-------------|
78
+ | `--attach` | Attach to running process instead of launching |
79
+ | `--pid <id>` | Process ID for attach mode |
80
+
81
+ ### Trace Mode
82
+
83
+ | Option | Description |
84
+ |--------|-------------|
85
+ | `--trace` | Enable trace mode - step through code after breakpoint |
86
+ | `--trace-into` | Use stepIn instead of stepOver (follow into functions) |
87
+ | `--trace-limit <N>` | Max steps in trace mode (default: 500) |
88
+ | `--trace-until <expr>` | Stop trace when expression is truthy |
89
+ | `--diff-vars` | Show only changed variables in trace steps |
90
+
91
+ ### Token Efficiency
92
+
93
+ | Option | Description |
94
+ |--------|-------------|
95
+ | `--expand-services` | Fully expand service types (Logger, Repository, etc.) |
96
+ | `--show-null-props` | Include null/undefined properties in output |
97
+ | `--no-dedupe` | Disable content-based deduplication |
98
+
99
+ ### Event Filtering
100
+
101
+ | Option | Description |
102
+ |--------|-------------|
103
+ | `--include <types...>` | Only emit these event types |
104
+ | `--exclude <types...>` | Suppress these event types |
105
+
106
+ ### Exception Handling
107
+
108
+ | Option | Description |
109
+ |--------|-------------|
110
+ | `--break-on-exception <filter>` | Break on exceptions: `all`, `uncaught`, `raised` |
111
+ | `--no-flatten-exceptions` | Disable exception chain analysis |
112
+ | `--exception-chain-depth <n>` | Max depth to traverse (default: 10) |
113
+
114
+ ## Assertions
115
+
116
+ Use `--assert` to declare invariants. The debugger halts immediately when any assertion fails:
117
+
118
+ ```bash
119
+ npx debug-run ./app.dll -a vsdbg \
120
+ -b "src/OrderService.cs:42" \
121
+ --assert "order.Total >= 0" \
122
+ --assert "order.Items.Count > 0" \
123
+ --pretty
124
+ ```
125
+
126
+ Assertions are checked at every breakpoint hit, trace step, and regular step.
127
+
128
+ ## Trace Mode
129
+
130
+ Trace mode automatically steps through code after hitting a breakpoint:
131
+
132
+ ```bash
133
+ # Basic trace
134
+ npx debug-run ./app.dll -a vsdbg -b "src/Service.cs:42" --trace --pretty
135
+
136
+ # Trace into function calls with limit
137
+ npx debug-run ./app.dll -a vsdbg -b "src/Service.cs:42" --trace --trace-into --trace-limit 100 --pretty
138
+
139
+ # Trace until condition
140
+ npx debug-run ./app.dll -a vsdbg -b "src/Service.cs:42" --trace --trace-until "total > 100" --pretty
141
+
142
+ # Trace with variable diffing (shows only changes)
143
+ npx debug-run ./app.dll -a vsdbg -b "src/Service.cs:42" --trace --diff-vars --pretty
144
+ ```
145
+
146
+ ## Output Format
147
+
148
+ debug-run outputs NDJSON (newline-delimited JSON) events:
149
+
150
+ ### Event Types
151
+
152
+ | Event | Description |
153
+ |-------|-------------|
154
+ | `session_start` | Debug session initialized |
155
+ | `breakpoint_set` | Breakpoint configured (check `verified` field) |
156
+ | `process_launched` | Debuggee process started |
157
+ | `process_attached` | Attached to running process |
158
+ | `breakpoint_hit` | Breakpoint was hit with locals and evaluations |
159
+ | `assertion_failed` | Assertion violation with context |
160
+ | `trace_started` | Trace mode began |
161
+ | `trace_step` | Single trace step (with `changes` if `--diff-vars`) |
162
+ | `trace_completed` | Trace finished |
163
+ | `exception_thrown` | Exception occurred |
164
+ | `program_output` | stdout/stderr from debuggee |
165
+ | `process_exited` | Program terminated |
166
+ | `session_end` | Summary with statistics |
167
+
168
+ ### breakpoint_hit Example
169
+
170
+ ```json
171
+ {
172
+ "type": "breakpoint_hit",
173
+ "timestamp": "...",
174
+ "location": {
175
+ "file": "src/Services/OrderService.cs",
176
+ "line": 42,
177
+ "function": "ProcessOrder"
178
+ },
179
+ "stackTrace": [...],
180
+ "locals": {
181
+ "order": { "type": "Order", "value": {...} },
182
+ "this": {...}
183
+ },
184
+ "evaluations": {
185
+ "order.Total": { "result": "125.50" },
186
+ "order.Items.Count": { "result": "3" }
187
+ }
188
+ }
189
+ ```
190
+
191
+ ## Token Efficiency
192
+
193
+ debug-run includes automatic optimizations for enterprise applications:
194
+
195
+ ### Service Type Compaction (default)
196
+ Types like `Logger`, `Repository`, `Service` are shown in compact form:
197
+ ```json
198
+ "logger": { "type": "Logger", "value": "{Logger}" }
199
+ ```
200
+
201
+ ### Null Property Omission (default)
202
+ Properties with null/undefined values are omitted.
203
+
204
+ ### Content-Based Deduplication (default)
205
+ Repeated object content references the first occurrence:
206
+ ```json
207
+ "loyaltyService._features": { "value": "[see: discountService._features]", "deduplicated": true }
208
+ ```
209
+
210
+ ## Best Practices
211
+
212
+ 1. **Use relative paths for breakpoints**: `-b "src/MyFile.cs:42"` not `-b "MyFile.cs:42"`
213
+
214
+ 2. **Expression timing**: Expressions evaluate BEFORE the breakpoint line executes. Variables assigned on that line will be null/unset.
215
+
216
+ 3. **Unverified breakpoints**: In attach mode, breakpoints start as `verified: false`. They verify when the code path is hit.
217
+
218
+ 4. **Long-running processes**: Use appropriate timeouts (`-t 5m`) and trigger the code path while debug-run is waiting.
219
+
220
+ ## Troubleshooting
221
+
222
+ | Issue | Solution |
223
+ |-------|----------|
224
+ | "Adapter not installed" | Run `list-adapters` to check available adapters |
225
+ | Breakpoint not hitting | Verify path is relative to working directory and line has executable code |
226
+ | Session timeout | Increase timeout with `-t 2m` or `-t 5m` |
227
+
228
+ For language-specific troubleshooting, see the language guides linked above.
@@ -0,0 +1,378 @@
1
+ # TypeScript/JavaScript Debugging Guide
2
+
3
+ This guide covers debugging TypeScript and JavaScript applications with debug-run using the js-debug (Node.js) adapter.
4
+
5
+ ## Prerequisites
6
+
7
+ ### js-debug Adapter
8
+
9
+ The js-debug adapter is detected from two sources:
10
+
11
+ 1. **VS Code js-debug extension** - Built into VS Code or install separately
12
+ 2. **Installed via debug-run** - `npx debug-run install-adapter node`
13
+
14
+ Check availability:
15
+
16
+ ```bash
17
+ npx debug-run list-adapters
18
+ # Should show: node - Status: installed (path)
19
+ ```
20
+
21
+ ### Installing js-debug
22
+
23
+ **Option 1: VS Code (Recommended)**
24
+ - js-debug is built into VS Code
25
+ - Or install the [JavaScript Debugger (Nightly)](https://marketplace.visualstudio.com/items?itemName=ms-vscode.js-debug-nightly) extension
26
+
27
+ **Option 2: debug-run installer**
28
+ ```bash
29
+ npx debug-run install-adapter node
30
+ ```
31
+
32
+ ### Node.js
33
+
34
+ Ensure Node.js is installed:
35
+ ```bash
36
+ node --version # Should be v18+ recommended
37
+ ```
38
+
39
+ ## Build TypeScript Projects
40
+
41
+ For TypeScript, compile to JavaScript first:
42
+
43
+ ```bash
44
+ # Install dependencies and build
45
+ npm install
46
+ npm run build # or: npx tsc
47
+ ```
48
+
49
+ ## Launch Mode (Debug JavaScript)
50
+
51
+ ### Basic Debugging
52
+
53
+ ```bash
54
+ npx debug-run ./dist/index.js \
55
+ -a node \
56
+ -b "src/index.ts:42" \
57
+ --pretty \
58
+ -t 30s
59
+ ```
60
+
61
+ Note: Set breakpoints using the **source TypeScript file path**, not the compiled JavaScript path. Source maps enable this mapping.
62
+
63
+ ### With Expression Evaluation
64
+
65
+ ```bash
66
+ npx debug-run ./dist/index.js \
67
+ -a node \
68
+ -b "src/services/OrderService.ts:55" \
69
+ -e "order.total" \
70
+ -e "order.items.length" \
71
+ -e "this.config" \
72
+ --pretty \
73
+ -t 30s
74
+ ```
75
+
76
+ ### With Assertions
77
+
78
+ ```bash
79
+ npx debug-run ./dist/index.js \
80
+ -a node \
81
+ -b "src/services/OrderService.ts:55" \
82
+ --assert "order.total >= 0" \
83
+ --assert "order.items.length > 0" \
84
+ --assert "this.inventory !== null" \
85
+ --pretty \
86
+ -t 30s
87
+ ```
88
+
89
+ ### Exception Handling
90
+
91
+ Break on exceptions:
92
+
93
+ ```bash
94
+ # Break on all exceptions
95
+ npx debug-run ./dist/index.js \
96
+ -a node \
97
+ --break-on-exception all \
98
+ --pretty \
99
+ -t 30s
100
+
101
+ # Break on uncaught exceptions only
102
+ npx debug-run ./dist/index.js \
103
+ -a node \
104
+ --break-on-exception uncaught \
105
+ --pretty \
106
+ -t 30s
107
+ ```
108
+
109
+ ## Adapter Aliases
110
+
111
+ Multiple aliases work for the Node.js adapter:
112
+
113
+ ```bash
114
+ # These are all equivalent
115
+ npx debug-run ./dist/index.js -a node -b "src/index.ts:10" --pretty
116
+ npx debug-run ./dist/index.js -a nodejs -b "src/index.ts:10" --pretty
117
+ npx debug-run ./dist/index.js -a js -b "src/index.ts:10" --pretty
118
+ npx debug-run ./dist/index.js -a javascript -b "src/index.ts:10" --pretty
119
+ ```
120
+
121
+ ## Sample Application
122
+
123
+ A sample TypeScript application is included for testing:
124
+
125
+ ```bash
126
+ # Build the sample
127
+ cd samples/typescript && npm install && npm run build && cd ../..
128
+
129
+ # Debug
130
+ npx debug-run samples/typescript/dist/index.js \
131
+ -a node \
132
+ -b "samples/typescript/src/index.ts:160" \
133
+ --pretty \
134
+ -t 30s
135
+ ```
136
+
137
+ ### With Expression Evaluation
138
+
139
+ ```bash
140
+ npx debug-run samples/typescript/dist/index.js \
141
+ -a node \
142
+ -b "samples/typescript/src/index.ts:177" \
143
+ -e "subtotal" \
144
+ -e "tax" \
145
+ -e "discount" \
146
+ -e "order.orderId" \
147
+ --pretty \
148
+ -t 30s
149
+ ```
150
+
151
+ ### Good Breakpoint Locations (Sample App)
152
+
153
+ | Line | Location | Description |
154
+ |------|----------|-------------|
155
+ | 160 | `processOrder` | Start of order processing method |
156
+ | 177 | `processOrder` | After calculating subtotal, tax, discount |
157
+ | 168 | `processOrder` | Inside inventory check loop |
158
+ | 304 | `main` | Before processing first order |
159
+
160
+ ## Source Maps
161
+
162
+ debug-run automatically uses source maps to map breakpoints from TypeScript source files to compiled JavaScript.
163
+
164
+ ### Requirements
165
+
166
+ 1. **Enable source maps in tsconfig.json**:
167
+ ```json
168
+ {
169
+ "compilerOptions": {
170
+ "sourceMap": true,
171
+ "outDir": "./dist"
172
+ }
173
+ }
174
+ ```
175
+
176
+ 2. **Set breakpoints using TypeScript paths**:
177
+ ```bash
178
+ # Correct: Use .ts source file
179
+ -b "src/services/OrderService.ts:42"
180
+
181
+ # Incorrect: Don't use .js compiled file
182
+ -b "dist/services/OrderService.js:42"
183
+ ```
184
+
185
+ ### How Source Maps Work
186
+
187
+ When you compile TypeScript:
188
+ - `src/index.ts` → `dist/index.js` + `dist/index.js.map`
189
+
190
+ debug-run tells js-debug to:
191
+ 1. Run `dist/index.js`
192
+ 2. Use source maps to show original TypeScript
193
+ 3. Set breakpoints in TypeScript that map to correct JS locations
194
+
195
+ ## Trace Mode
196
+
197
+ Follow execution flow after hitting a breakpoint:
198
+
199
+ ```bash
200
+ # Basic trace
201
+ npx debug-run ./dist/index.js \
202
+ -a node \
203
+ -b "src/index.ts:42" \
204
+ --trace \
205
+ --pretty
206
+
207
+ # Trace into function calls
208
+ npx debug-run ./dist/index.js \
209
+ -a node \
210
+ -b "src/index.ts:42" \
211
+ --trace \
212
+ --trace-into \
213
+ --trace-limit 50 \
214
+ --pretty
215
+
216
+ # Trace with variable diffing
217
+ npx debug-run ./dist/index.js \
218
+ -a node \
219
+ -b "src/index.ts:42" \
220
+ --trace \
221
+ --diff-vars \
222
+ --pretty
223
+ ```
224
+
225
+ ## JavaScript-Specific Notes
226
+
227
+ ### Provisional Breakpoints
228
+
229
+ js-debug uses "provisional breakpoints" that start as unverified:
230
+ ```json
231
+ {
232
+ "type": "breakpoint_set",
233
+ "verified": false,
234
+ "message": "breakpoint.provisionalBreakpoint"
235
+ }
236
+ ```
237
+
238
+ This is normal - breakpoints verify when the code is loaded.
239
+
240
+ ### Internal Code
241
+
242
+ By default, debug-run configures js-debug to skip internal Node.js code:
243
+ ```json
244
+ "skipFiles": ["<node_internals>/**"]
245
+ ```
246
+
247
+ Stack traces may show `[Internal Code]` for Node.js internals.
248
+
249
+ ### Expression Syntax
250
+
251
+ Use JavaScript syntax for expressions:
252
+
253
+ ```bash
254
+ # JavaScript expressions
255
+ -e "items.length"
256
+ -e "order.items[0].price"
257
+ -e "order.items.reduce((sum, item) => sum + item.quantity, 0)"
258
+ -e "customer?.loyaltyTier ?? 'none'"
259
+ ```
260
+
261
+ ### this Context
262
+
263
+ In class methods, `this` is automatically captured in locals:
264
+
265
+ ```json
266
+ {
267
+ "locals": {
268
+ "this": {
269
+ "type": "OrderService",
270
+ "value": {
271
+ "config": {...},
272
+ "inventory": {...}
273
+ }
274
+ }
275
+ }
276
+ }
277
+ ```
278
+
279
+ ## Debugging Plain JavaScript
280
+
281
+ For plain JavaScript (no TypeScript):
282
+
283
+ ```bash
284
+ npx debug-run ./index.js \
285
+ -a node \
286
+ -b "index.js:25" \
287
+ --pretty \
288
+ -t 30s
289
+ ```
290
+
291
+ No build step needed - just point to the .js file directly.
292
+
293
+ ## Debugging ESM vs CommonJS
294
+
295
+ debug-run works with both module systems:
296
+
297
+ ```bash
298
+ # ESM (type: "module" in package.json)
299
+ npx debug-run ./dist/index.js -a node -b "src/index.ts:10" --pretty
300
+
301
+ # CommonJS
302
+ npx debug-run ./dist/index.js -a node -b "src/index.ts:10" --pretty
303
+ ```
304
+
305
+ The adapter auto-detects the module system.
306
+
307
+ ## Troubleshooting
308
+
309
+ | Issue | Solution |
310
+ |-------|----------|
311
+ | "Adapter not installed" | Run `npx debug-run install-adapter node` or install VS Code |
312
+ | Breakpoint not hitting | Check source maps exist (`.js.map` files) |
313
+ | Wrong line numbers | Rebuild TypeScript (`npm run build`) |
314
+ | "Cannot find module" | Run `npm install` first |
315
+ | Provisional breakpoint never verifies | Check file path matches source exactly |
316
+
317
+ ### Debug Adapter Communication
318
+
319
+ Enable verbose DAP logging:
320
+
321
+ ```bash
322
+ DEBUG_DAP=1 npx debug-run ./dist/index.js -a node -b "src/index.ts:10" --pretty
323
+ ```
324
+
325
+ ### Verify Source Maps
326
+
327
+ Check that source maps are generated:
328
+ ```bash
329
+ ls dist/*.js.map # Should list .map files
330
+ ```
331
+
332
+ Check tsconfig.json has `"sourceMap": true`.
333
+
334
+ ## Common Patterns
335
+
336
+ ### Debug with Arguments
337
+
338
+ ```bash
339
+ npx debug-run ./dist/cli.js -- --input data.json --verbose \
340
+ -a node \
341
+ -b "src/cli.ts:15" \
342
+ --pretty
343
+ ```
344
+
345
+ Arguments after `--` are passed to your script.
346
+
347
+ ### Debug Tests (Jest/Mocha)
348
+
349
+ For test debugging, run the test file directly:
350
+
351
+ ```bash
352
+ # Jest (compile first if TypeScript)
353
+ npx debug-run ./node_modules/jest/bin/jest.js -- --runInBand tests/order.test.ts \
354
+ -a node \
355
+ -b "tests/order.test.ts:25" \
356
+ --pretty \
357
+ -t 60s
358
+
359
+ # Mocha
360
+ npx debug-run ./node_modules/mocha/bin/mocha.js -- dist/tests/**/*.js \
361
+ -a node \
362
+ -b "src/tests/order.test.ts:25" \
363
+ --pretty \
364
+ -t 60s
365
+ ```
366
+
367
+ ### Debug Express/Fastify Server
368
+
369
+ ```bash
370
+ npx debug-run ./dist/server.js \
371
+ -a node \
372
+ -b "src/routes/orders.ts:42" \
373
+ --pretty \
374
+ -t 120s
375
+
376
+ # In another terminal, trigger the endpoint:
377
+ # curl http://localhost:3000/orders
378
+ ```
@@ -0,0 +1,4 @@
1
+ dist/
2
+ node_modules/
3
+ samples/
4
+ *.md