debug-run 0.5.1 → 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,262 @@
1
+ # .NET Debugging Guide
2
+
3
+ This guide covers debugging .NET applications with debug-run using the vsdbg adapter.
4
+
5
+ ## Prerequisites
6
+
7
+ ### vsdbg Adapter
8
+
9
+ The vsdbg adapter is automatically detected if you have the VS Code C# extension installed:
10
+
11
+ ```bash
12
+ npx debug-run list-adapters
13
+ # Should show: vsdbg - Status: installed (path)
14
+ ```
15
+
16
+ If not installed, install the [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) in VS Code.
17
+
18
+ ### Alternative: netcoredbg
19
+
20
+ Open-source alternative (less stable on some platforms):
21
+
22
+ ```bash
23
+ npx debug-run install-adapter netcoredbg
24
+ ```
25
+
26
+ ## Build Your Application
27
+
28
+ Before debugging, build your .NET application:
29
+
30
+ ```bash
31
+ dotnet build
32
+ ```
33
+
34
+ ## Launch Mode (Debug New Process)
35
+
36
+ ### Basic Debugging
37
+
38
+ ```bash
39
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
40
+ -a vsdbg \
41
+ -b "src/Services/OrderService.cs:42" \
42
+ --pretty \
43
+ -t 30s
44
+ ```
45
+
46
+ ### With Expression Evaluation
47
+
48
+ ```bash
49
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
50
+ -a vsdbg \
51
+ -b "src/Services/OrderService.cs:42" \
52
+ -e "order.Total" \
53
+ -e "order.Items.Count" \
54
+ -e "this._inventory.Count" \
55
+ --pretty \
56
+ -t 30s
57
+ ```
58
+
59
+ ### With Assertions
60
+
61
+ ```bash
62
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
63
+ -a vsdbg \
64
+ -b "src/Services/OrderService.cs:42" \
65
+ --assert "order.Total >= 0" \
66
+ --assert "order.Items.Count > 0" \
67
+ --assert "this._inventory != null" \
68
+ --pretty \
69
+ -t 30s
70
+ ```
71
+
72
+ ### Exception Handling
73
+
74
+ Break on all exceptions with chain flattening:
75
+
76
+ ```bash
77
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
78
+ -a vsdbg \
79
+ --break-on-exception all \
80
+ --pretty \
81
+ -t 30s
82
+ ```
83
+
84
+ ## Attach Mode (ASP.NET / Long-Running Services)
85
+
86
+ For debugging running ASP.NET applications or services:
87
+
88
+ ### 1. Start Your Application
89
+
90
+ ```bash
91
+ cd MyWebApi
92
+ dotnet run
93
+ # Note the process - find PID with: ps aux | grep dotnet
94
+ ```
95
+
96
+ ### 2. Attach debug-run
97
+
98
+ ```bash
99
+ npx debug-run --attach --pid <PID> \
100
+ -a vsdbg \
101
+ -b "src/Controllers/OrderController.cs:28" \
102
+ -e "request.OrderId" \
103
+ --pretty \
104
+ -t 60s
105
+ ```
106
+
107
+ ### Important Notes for Attach Mode
108
+
109
+ 1. **Timing matters**: After `process_attached` event, wait 10-15 seconds before triggering the code path
110
+ 2. **Breakpoints start unverified**: `verified: false` is normal; they verify when the code path is hit
111
+ 3. **Process survives**: In attach mode, the debuggee keeps running after debug-run exits
112
+
113
+ ### Example: Debug ASP.NET Endpoint
114
+
115
+ ```bash
116
+ # Terminal 1: Start the API
117
+ cd samples/aspnet/SampleApi
118
+ dotnet run # Runs on http://localhost:5009
119
+
120
+ # Terminal 2: Attach debugger
121
+ npx debug-run --attach --pid $(pgrep -f SampleApi) \
122
+ -a vsdbg \
123
+ -b "samples/aspnet/SampleApi/Program.cs:16" \
124
+ --pretty \
125
+ -t 60s
126
+
127
+ # Terminal 3: Trigger the endpoint
128
+ curl http://localhost:5009/orders
129
+ ```
130
+
131
+ ## Test Debugging (NUnit, xUnit, MSTest)
132
+
133
+ debug-run supports debugging .NET unit tests with automatic test runner orchestration:
134
+
135
+ ### Quick Start
136
+
137
+ ```bash
138
+ # Build the test project first
139
+ cd samples/nunit && dotnet build && cd ../..
140
+
141
+ # Debug tests
142
+ npx debug-run --test-project samples/nunit \
143
+ -b "samples/nunit/CalculatorTests.cs:57" \
144
+ --pretty \
145
+ -t 60s
146
+ ```
147
+
148
+ ### Filter Specific Tests
149
+
150
+ ```bash
151
+ npx debug-run --test-project samples/nunit \
152
+ --test-filter "Add_TwoPositiveNumbers_ReturnsSum" \
153
+ -b "samples/nunit/CalculatorTests.cs:57" \
154
+ --pretty
155
+ ```
156
+
157
+ ### With Expression Evaluation
158
+
159
+ ```bash
160
+ npx debug-run --test-project samples/nunit \
161
+ -b "samples/nunit/CalculatorTests.cs:57" \
162
+ -e "a" -e "b" -e "result" \
163
+ --pretty
164
+ ```
165
+
166
+ ### How It Works
167
+
168
+ 1. Launches `dotnet test --no-build` with `VSTEST_HOST_DEBUG=1`
169
+ 2. Parses the testhost PID from the output
170
+ 3. Automatically attaches the debugger to the testhost process
171
+ 4. Sets breakpoints and captures variables
172
+
173
+ ## Trace Mode
174
+
175
+ Follow execution flow after hitting a breakpoint:
176
+
177
+ ```bash
178
+ # Basic trace
179
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
180
+ -a vsdbg \
181
+ -b "src/Services/OrderService.cs:42" \
182
+ --trace \
183
+ --pretty
184
+
185
+ # Trace into function calls
186
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
187
+ -a vsdbg \
188
+ -b "src/Services/OrderService.cs:42" \
189
+ --trace \
190
+ --trace-into \
191
+ --trace-limit 50 \
192
+ --pretty
193
+
194
+ # Trace with variable diffing
195
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
196
+ -a vsdbg \
197
+ -b "src/Services/OrderService.cs:42" \
198
+ --trace \
199
+ --diff-vars \
200
+ --pretty
201
+ ```
202
+
203
+ ## Sample Application
204
+
205
+ A sample .NET console application is included for testing:
206
+
207
+ ```bash
208
+ # Build
209
+ cd samples/dotnet && dotnet build && cd ../..
210
+
211
+ # Debug
212
+ npx debug-run ./samples/dotnet/bin/Debug/net8.0/SampleApp.dll \
213
+ -a vsdbg \
214
+ -b "samples/dotnet/Program.cs:67" \
215
+ --pretty \
216
+ -t 30s
217
+ ```
218
+
219
+ ### Good Breakpoint Locations
220
+
221
+ | Line | Location | Description |
222
+ |------|----------|-------------|
223
+ | 67 | `ProcessOrder` | Inside order processing method |
224
+ | 51 | `Main` | After configuration setup |
225
+ | 78 | `CalculateDiscount` | Discount calculation logic |
226
+
227
+ ## Token Efficiency for .NET
228
+
229
+ ### Blocked Properties (Automatic)
230
+
231
+ debug-run automatically filters verbose .NET reflection metadata:
232
+ - `EqualityContract` - C# record equality (often 4KB+ of noise)
233
+ - `CustomAttributes`, `DeclaredConstructors`, `DeclaredMethods`
234
+ - `[More]`, `Raw View`, `Static members`, `Non-Public members`
235
+
236
+ ### Service Type Compaction
237
+
238
+ Common service patterns are compacted by default:
239
+ ```json
240
+ "_logger": { "type": "ILogger<OrderService>", "value": "{ILogger}" }
241
+ "_repository": { "type": "OrderRepository", "value": "{Repository}" }
242
+ ```
243
+
244
+ Override with `--expand-services` if you need full expansion.
245
+
246
+ ## Troubleshooting
247
+
248
+ | Issue | Solution |
249
+ |-------|----------|
250
+ | vsdbg license warning | Informational only, can be ignored |
251
+ | netcoredbg SIGSEGV | Use vsdbg instead (`-a vsdbg`) |
252
+ | "Adapter not installed" | Install VS Code C# extension |
253
+ | Breakpoint not verified | Wait longer after attach, or check file path |
254
+ | Test not stopping | Ensure `--no-build` and build manually first |
255
+
256
+ ### Debug Adapter Communication
257
+
258
+ Enable verbose DAP logging:
259
+
260
+ ```bash
261
+ DEBUG_DAP=1 npx debug-run ./app.dll -a vsdbg -b "file.cs:10" --pretty
262
+ ```
@@ -0,0 +1,282 @@
1
+ # Python Debugging Guide
2
+
3
+ This guide covers debugging Python applications with debug-run using the debugpy adapter.
4
+
5
+ ## Prerequisites
6
+
7
+ ### debugpy Adapter
8
+
9
+ The debugpy adapter is automatically detected from two sources:
10
+
11
+ 1. **VS Code Python Extension** (recommended) - debugpy is bundled with it
12
+ 2. **pip installation** - `pip install debugpy`
13
+
14
+ Check availability:
15
+
16
+ ```bash
17
+ npx debug-run list-adapters
18
+ # Should show: debugpy - Status: installed (VS Code Python extension or pip)
19
+ ```
20
+
21
+ ### Installing debugpy
22
+
23
+ **Option 1: VS Code Python Extension (Recommended)**
24
+ - Install the [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) in VS Code
25
+ - debugpy is bundled automatically
26
+
27
+ **Option 2: pip**
28
+ ```bash
29
+ pip install debugpy
30
+ # or
31
+ pip3 install debugpy
32
+ ```
33
+
34
+ ## Launch Mode (Debug Python Script)
35
+
36
+ ### Basic Debugging
37
+
38
+ ```bash
39
+ npx debug-run ./main.py \
40
+ -a python \
41
+ -b "src/processor.py:25" \
42
+ --pretty \
43
+ -t 30s
44
+ ```
45
+
46
+ ### With Expression Evaluation
47
+
48
+ ```bash
49
+ npx debug-run ./main.py \
50
+ -a python \
51
+ -b "src/processor.py:42" \
52
+ -e "subtotal" \
53
+ -e "tax" \
54
+ -e "order.order_id" \
55
+ -e "len(order.items)" \
56
+ --pretty \
57
+ -t 30s
58
+ ```
59
+
60
+ ### With Assertions
61
+
62
+ ```bash
63
+ npx debug-run ./main.py \
64
+ -a python \
65
+ -b "src/processor.py:42" \
66
+ --assert "subtotal >= 0" \
67
+ --assert "len(order.items) > 0" \
68
+ --assert "customer is not None" \
69
+ --pretty \
70
+ -t 30s
71
+ ```
72
+
73
+ ### Exception Handling
74
+
75
+ Break on raised or uncaught exceptions:
76
+
77
+ ```bash
78
+ # Break on all raised exceptions
79
+ npx debug-run ./main.py \
80
+ -a python \
81
+ --break-on-exception raised \
82
+ --pretty \
83
+ -t 30s
84
+
85
+ # Break on uncaught exceptions only
86
+ npx debug-run ./main.py \
87
+ -a python \
88
+ --break-on-exception uncaught \
89
+ --pretty \
90
+ -t 30s
91
+ ```
92
+
93
+ ## Adapter Aliases
94
+
95
+ Both `-a python` and `-a debugpy` work identically:
96
+
97
+ ```bash
98
+ # These are equivalent
99
+ npx debug-run ./main.py -a python -b "main.py:10" --pretty
100
+ npx debug-run ./main.py -a debugpy -b "main.py:10" --pretty
101
+ ```
102
+
103
+ ## Sample Application
104
+
105
+ A sample Python application is included for testing:
106
+
107
+ ```bash
108
+ # Debug the sample app
109
+ npx debug-run samples/python/sample_app.py \
110
+ -a python \
111
+ -b "samples/python/sample_app.py:185" \
112
+ --pretty \
113
+ -t 30s
114
+ ```
115
+
116
+ ### With Expression Evaluation
117
+
118
+ ```bash
119
+ npx debug-run samples/python/sample_app.py \
120
+ -a python \
121
+ -b "samples/python/sample_app.py:188" \
122
+ -e "subtotal" \
123
+ -e "tax" \
124
+ -e "discount" \
125
+ -e "order.order_id" \
126
+ --pretty \
127
+ -t 30s
128
+ ```
129
+
130
+ ### Good Breakpoint Locations (Sample App)
131
+
132
+ | Line | Location | Description |
133
+ |------|----------|-------------|
134
+ | 185 | `process_order` | After variable setup, before loyalty points |
135
+ | 140 | `calculate_discount` | After discount rate calculation |
136
+ | 298 | `main` | Before processing first order |
137
+ | 178 | `process_order` | Inside inventory loop |
138
+
139
+ ## Trace Mode
140
+
141
+ Follow execution flow after hitting a breakpoint:
142
+
143
+ ```bash
144
+ # Basic trace
145
+ npx debug-run ./main.py \
146
+ -a python \
147
+ -b "src/processor.py:25" \
148
+ --trace \
149
+ --pretty
150
+
151
+ # Trace into function calls
152
+ npx debug-run ./main.py \
153
+ -a python \
154
+ -b "src/processor.py:25" \
155
+ --trace \
156
+ --trace-into \
157
+ --trace-limit 50 \
158
+ --pretty
159
+
160
+ # Trace with variable diffing
161
+ npx debug-run ./main.py \
162
+ -a python \
163
+ -b "src/processor.py:25" \
164
+ --trace \
165
+ --diff-vars \
166
+ --pretty
167
+ ```
168
+
169
+ ## Python-Specific Notes
170
+
171
+ ### Breakpoint Timing
172
+
173
+ Breakpoints are set AFTER launch for Python (debugpy's DAP flow differs from .NET). This is handled automatically by debug-run.
174
+
175
+ ### Dataclass Variables
176
+
177
+ Python dataclasses show a `special variables` section in locals containing class metadata. This is normal debugpy behavior. The actual instance fields are shown alongside.
178
+
179
+ ```json
180
+ {
181
+ "customer": {
182
+ "type": "Customer",
183
+ "value": {
184
+ "special variables": {...}, // Class metadata
185
+ "id": { "type": "str", "value": "CUST-001" },
186
+ "name": { "type": "str", "value": "Alice" },
187
+ "email": { "type": "str", "value": "alice@example.com" }
188
+ }
189
+ }
190
+ }
191
+ ```
192
+
193
+ ### justMyCode
194
+
195
+ By default, debug-run sets `justMyCode: false` to allow stepping into library code. The default Python debugger behavior only stops in user code.
196
+
197
+ ### Expression Syntax
198
+
199
+ Use Python syntax for expressions:
200
+
201
+ ```bash
202
+ # Python expressions
203
+ -e "len(items)"
204
+ -e "order.items[0].price"
205
+ -e "sum(item.quantity for item in order.items)"
206
+ -e "customer.loyalty_tier.value"
207
+ ```
208
+
209
+ ## Working with Virtual Environments
210
+
211
+ If your project uses a virtual environment, activate it before running debug-run:
212
+
213
+ ```bash
214
+ # Activate venv
215
+ source .venv/bin/activate # Linux/macOS
216
+ # or
217
+ .venv\Scripts\activate # Windows
218
+
219
+ # Then debug
220
+ npx debug-run ./main.py -a python -b "main.py:10" --pretty
221
+ ```
222
+
223
+ debug-run uses the active Python interpreter, which will have access to your virtual environment's packages.
224
+
225
+ ## Troubleshooting
226
+
227
+ | Issue | Solution |
228
+ |-------|----------|
229
+ | "debugpy not found" | Install VS Code Python extension or `pip install debugpy` |
230
+ | "python not found" | Ensure Python 3 is in PATH (`python3 --version`) |
231
+ | Variables show as "not defined" | Expression is evaluated BEFORE the line executes |
232
+ | Breakpoint not hitting | Check file path is correct and line has executable code |
233
+ | Timeout before breakpoint | Increase timeout with `-t 60s` or `-t 2m` |
234
+
235
+ ### Debug Adapter Communication
236
+
237
+ Enable verbose DAP logging to troubleshoot:
238
+
239
+ ```bash
240
+ DEBUG_DAP=1 npx debug-run ./main.py -a python -b "main.py:10" --pretty
241
+ ```
242
+
243
+ ### Verify debugpy Installation
244
+
245
+ ```bash
246
+ # Check if debugpy is importable
247
+ python3 -c "import debugpy; print(debugpy.__version__)"
248
+
249
+ # Check adapter detection
250
+ npx debug-run list-adapters
251
+ ```
252
+
253
+ ## Common Patterns
254
+
255
+ ### Debug a Flask/Django App
256
+
257
+ ```bash
258
+ # Flask
259
+ npx debug-run app.py \
260
+ -a python \
261
+ -b "app.py:25" \
262
+ --pretty \
263
+ -t 120s
264
+
265
+ # Django (using manage.py)
266
+ npx debug-run manage.py runserver \
267
+ -a python \
268
+ -b "myapp/views.py:42" \
269
+ --pretty \
270
+ -t 120s
271
+ ```
272
+
273
+ ### Debug with Arguments
274
+
275
+ ```bash
276
+ npx debug-run ./script.py -- --input data.json --verbose \
277
+ -a python \
278
+ -b "script.py:15" \
279
+ --pretty
280
+ ```
281
+
282
+ Arguments after `--` are passed to your Python script.
@@ -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
+ ```
package/README.md CHANGED
@@ -25,17 +25,38 @@ Agents can write and run code, but when something goes wrong, they're blind. The
25
25
  ## Installation
26
26
 
27
27
  ```bash
28
- # Clone and install
28
+ # Install globally
29
+ npm install -g debug-run
30
+
31
+ # Or run directly with npx
32
+ npx debug-run --help
33
+ ```
34
+
35
+ ### Claude Code Skill (Recommended)
36
+
37
+ To enable Claude Code to use debug-run effectively, copy the skill to your skills directory:
38
+
39
+ ```bash
40
+ # Create skills directory if it doesn't exist
41
+ mkdir -p ~/.claude/skills
42
+
43
+ # Copy the debug-run skill
44
+ cp -r node_modules/debug-run/.claude/skills/debug-run ~/.claude/skills/
45
+ ```
46
+
47
+ This installs the skill which teaches Claude how to use debug-run for debugging .NET, Python, and TypeScript applications. The skill includes:
48
+ - `SKILL.md` - Main skill with options reference and best practices
49
+ - `DOTNET.md` - .NET-specific guide (vsdbg, ASP.NET, NUnit)
50
+ - `PYTHON.md` - Python-specific guide (debugpy)
51
+ - `TYPESCRIPT.md` - TypeScript/JavaScript guide (js-debug)
52
+
53
+ ### Development Setup
54
+
55
+ ```bash
29
56
  git clone https://github.com/Chris-Cullins/debug-run.git
30
57
  cd debug-run
31
58
  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
59
+ npx tsx ./src/index.ts --help # run from source
39
60
  ```
40
61
 
41
62
  ## Quick Start
@@ -43,13 +64,13 @@ node dist/index.js --help
43
64
  ### List available adapters
44
65
 
45
66
  ```bash
46
- npx tsx ./src/index.ts list-adapters
67
+ npx debug-run list-adapters
47
68
  ```
48
69
 
49
70
  ### Debug a .NET application
50
71
 
51
72
  ```bash
52
- npx tsx ./src/index.ts ./bin/Debug/net8.0/MyApp.dll \
73
+ npx debug-run ./bin/Debug/net8.0/MyApp.dll \
53
74
  -a dotnet \
54
75
  -b "src/OrderService.cs:45" \
55
76
  --pretty
@@ -58,7 +79,7 @@ npx tsx ./src/index.ts ./bin/Debug/net8.0/MyApp.dll \
58
79
  ### Debug Python
59
80
 
60
81
  ```bash
61
- npx tsx ./src/index.ts ./main.py \
82
+ npx debug-run ./main.py \
62
83
  -a python \
63
84
  -b "processor.py:123" \
64
85
  -e "data.count" \
@@ -68,7 +89,7 @@ npx tsx ./src/index.ts ./main.py \
68
89
  ### Debug Node.js
69
90
 
70
91
  ```bash
71
- npx tsx ./src/index.ts ./dist/index.js \
92
+ npx debug-run ./dist/index.js \
72
93
  -a node \
73
94
  -b "src/handler.ts:30" \
74
95
  --pretty
@@ -182,7 +203,7 @@ debug-run outputs newline-delimited JSON (NDJSON) events:
182
203
  ### Checking adapter status
183
204
 
184
205
  ```bash
185
- $ npx tsx ./src/index.ts list-adapters
206
+ $ npx debug-run list-adapters
186
207
 
187
208
  Available debug adapters:
188
209
 
@@ -208,7 +229,7 @@ Available debug adapters:
208
229
  ### Investigate a test failure
209
230
 
210
231
  ```bash
211
- npx tsx ./src/index.ts ./bin/Debug/net8.0/TestApp.dll \
232
+ npx debug-run ./bin/Debug/net8.0/TestApp.dll \
212
233
  -a dotnet \
213
234
  -b "src/InventoryService.cs:34" \
214
235
  -e "requestedQuantity" \
@@ -219,7 +240,7 @@ npx tsx ./src/index.ts ./bin/Debug/net8.0/TestApp.dll \
219
240
  ### Step through code
220
241
 
221
242
  ```bash
222
- npx tsx ./src/index.ts ./app.dll \
243
+ npx debug-run ./app.dll \
223
244
  -a dotnet \
224
245
  -b "src/PricingService.cs:45" \
225
246
  --steps 10 \
@@ -230,7 +251,7 @@ npx tsx ./src/index.ts ./app.dll \
230
251
  ### Break on exceptions
231
252
 
232
253
  ```bash
233
- npx tsx ./src/index.ts ./app.dll \
254
+ npx debug-run ./app.dll \
234
255
  -a dotnet \
235
256
  --break-on-exception "all" \
236
257
  --pretty
@@ -239,7 +260,7 @@ npx tsx ./src/index.ts ./app.dll \
239
260
  ### Conditional breakpoint
240
261
 
241
262
  ```bash
242
- npx tsx ./src/index.ts ./app.dll \
263
+ npx debug-run ./app.dll \
243
264
  -a dotnet \
244
265
  -b "src/OrderService.cs:67?order.Total > 1000" \
245
266
  --pretty
@@ -250,7 +271,7 @@ npx tsx ./src/index.ts ./app.dll \
250
271
  Declare invariants that must remain true. The debugger halts immediately when any assertion fails:
251
272
 
252
273
  ```bash
253
- npx tsx ./src/index.ts ./app.dll \
274
+ npx debug-run ./app.dll \
254
275
  -a dotnet \
255
276
  -b "src/OrderService.cs:45" \
256
277
  --assert "order.Total >= 0" \
@@ -272,7 +293,7 @@ Assertions are checked at breakpoints, during stepping, and during trace mode.
272
293
  Automatically step through code after hitting a breakpoint:
273
294
 
274
295
  ```bash
275
- npx tsx ./src/index.ts ./app.dll \
296
+ npx debug-run ./app.dll \
276
297
  -a dotnet \
277
298
  -b "src/OrderService.cs:45" \
278
299
  --trace \
@@ -295,7 +316,7 @@ import subprocess
295
316
  import json
296
317
 
297
318
  result = subprocess.run([
298
- "npx", "tsx", "./src/index.ts",
319
+ "npx", "debug-run",
299
320
  "./bin/Debug/net8.0/MyApp.dll",
300
321
  "-a", "dotnet",
301
322
  "-b", "src/Service.cs:45",
@@ -316,7 +337,7 @@ for line in result.stdout.strip().split('\n'):
316
337
  # Install dependencies
317
338
  npm install
318
339
 
319
- # Run in development mode
340
+ # Run from source
320
341
  npx tsx ./src/index.ts [args...]
321
342
 
322
343
  # Type check
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "debug-run",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "CLI tool enabling AI agents to programmatically debug code via DAP",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",