abapgit-agent 1.9.0 → 1.10.1

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 CHANGED
@@ -150,6 +150,27 @@ abapgit-agent dump --date TODAY
150
150
  abapgit-agent dump --user DEVELOPER --date TODAY --detail 1
151
151
  ```
152
152
 
153
+ ### Debug Commands
154
+
155
+ ```bash
156
+ # Set a breakpoint
157
+ abapgit-agent debug set --files abap/zcl_my_class.clas.abap:42
158
+
159
+ # Attach and debug interactively (human REPL)
160
+ abapgit-agent debug attach
161
+
162
+ # Attach in scripted AI mode — emits JSON on hit, starts background daemon
163
+ abapgit-agent debug attach --json
164
+
165
+ # Step, inspect variables, call stack (no --session needed)
166
+ abapgit-agent debug step --type over --json
167
+ abapgit-agent debug vars --json
168
+ abapgit-agent debug stack --json
169
+
170
+ # Always release the frozen work process when done
171
+ abapgit-agent debug step --type continue --json
172
+ ```
173
+
153
174
  ### Utility Commands
154
175
 
155
176
  ```bash
@@ -193,6 +214,7 @@ npm run pull -- --url <git-url> --branch main
193
214
  | preview Command | [docs/preview-command.md](docs/preview-command.md) |
194
215
  | where Command | [docs/where-command.md](docs/where-command.md) |
195
216
  | dump Command | [docs/dump-command.md](docs/dump-command.md) |
217
+ | debug Command | [docs/debug-command.md](docs/debug-command.md) |
196
218
  | ref Command | [docs/ref-command.md](docs/ref-command.md) |
197
219
  | REST API Reference | [API.md](API.md) |
198
220
  | Error Handling | [ERROR_HANDLING.md](ERROR_HANDLING.md) |
package/abap/CLAUDE.md CHANGED
@@ -256,106 +256,138 @@ abapgit-agent unit --files src/zcl_test1.clas.testclasses.abap,src/zcl_test2.cla
256
256
 
257
257
  ---
258
258
 
259
- ### 9. Use `dump` Command to Investigate Runtime Errors (ST22)
259
+ ### 9. Troubleshooting ABAP Issues
260
260
 
261
- **When a user reports an ABAP runtime error, OR when any command returns HTTP 500 / an unexpected ABAP error, proactively check for short dumps.**
261
+ Two commands are available for investigating bugs at runtime:
262
262
 
263
- ```
264
- ❌ WRONG: Ask user to open ST22 transaction manually
265
- WRONG: Give up after an HTTP 500 without checking what caused it
266
- CORRECT: Use abapgit-agent dump to query short dumps and find the root cause
267
- ```
263
+ | Command | Use when | What it gives you |
264
+ |---------|----------|-------------------|
265
+ | `dump` | Error already occurred (ST22 crash) | Error type, call stack, exact source line |
266
+ | `debug` | Need to trace logic step-by-step | Live variable values, step into/over, expand structures |
268
267
 
269
- #### When to Use `dump`
268
+ #### When Something Goes Wrong — Start with `dump`
270
269
 
271
- | Scenario | Action |
272
- |----------|--------|
273
- | User reports "there was a dump in production" | `dump --user <user> --date TODAY` |
274
- | Any command returns HTTP 500 or unexpected error | `dump --date TODAY` (check for recent dumps) |
275
- | `pull` or `inspect` fails with internal ABAP error | `dump --date TODAY` |
276
- | Test run fails with runtime error | `dump --program <program> --date TODAY` |
277
- | Investigating TIME_OUT or other specific error | `dump --error TIME_OUT` |
278
- | Finding all errors from a specific user | `dump --user DEVELOPER` |
279
- | Full error analysis with source location | `dump --detail 1` (after listing) |
280
-
281
- #### Typical Investigation Workflow
270
+ **First reflex** for any HTTP 500, runtime error, or user-reported crash:
282
271
 
283
272
  ```bash
284
- # Step 1: List recent dumps (last 7 days by default)
285
- abapgit-agent dump
273
+ abapgit-agent dump --date TODAY # list today's dumps
274
+ abapgit-agent dump --date TODAY --detail 1 # full detail: call stack + source
275
+ ```
286
276
 
287
- # Step 2: Narrow by program or user if known
288
- abapgit-agent dump --program ZMY_PROGRAM --date TODAY
277
+ The `--detail` output shows the exact failing line (`>>>>>` marker), call stack,
278
+ and SAP's error analysis. Use it before asking the user to open ST22.
289
279
 
290
- # Step 3: View full details of the first result
291
- abapgit-agent dump --program ZMY_PROGRAM --date TODAY --detail 1
280
+ Common filters:
281
+ ```bash
282
+ abapgit-agent dump --user DEVELOPER --date TODAY # specific user
283
+ abapgit-agent dump --error TIME_OUT # specific error type
284
+ abapgit-agent dump --program ZMY_PROGRAM --detail 1 # specific program, full detail
292
285
  ```
293
286
 
294
- The `--detail` output includes:
295
- - **What happened** — high-level error description
296
- - **Error analysis** — detailed SAP explanation
297
- - **Call stack** — method-by-method trace with line numbers
298
- - **Source with `>>>>>` marker** — exact line where the dump occurred
287
+ After identifying the failing class/method, use `view` for broader context:
288
+ ```bash
289
+ abapgit-agent view --objects ZCL_MY_CLASS
290
+ ```
291
+
292
+ #### When There Is No Dump — Use `debug`
299
293
 
300
- #### Reading Detail Output
294
+ Use `debug` when:
295
+ - The bug is a logic error (wrong output, no crash)
296
+ - You need to inspect variable values mid-execution
297
+ - You want to verify which branch of code runs
301
298
 
299
+ **Step 1 — set a breakpoint** on the first executable statement you want to inspect:
300
+ ```bash
301
+ abapgit-agent debug set --files src/zcl_my_class.clas.abap:42 # from local file
302
+ abapgit-agent debug set --objects ZCL_MY_CLASS:42 # by name (no local file needed)
303
+ abapgit-agent debug list # confirm it was registered
302
304
  ```
303
- Short Dump Detail
304
305
 
305
- Error MESSAGE_TYPE_X
306
- Date 2024-01-15 (Europe/Berlin)
307
- Time 09:26:53
308
- User DEVELOPER
309
- Program ZMY_PROGRAM
306
+ > **Line number must point to an executable statement** — not a comment, blank line,
307
+ > `DATA` declaration, or `METHOD`/`ENDMETHOD`. Use `view --objects` to find valid lines.
310
308
 
311
- What happened:
312
- -------------------------------------------------------
313
- A RAISE statement raised the exception "MESSAGE_TYPE_X".
309
+ **Step 2 — attach and trigger**
314
310
 
315
- Call stack:
316
- -------------------------------------------------------
317
- 1 ZCL_MY_CLASS->DO_SOMETHING (line 42)
318
- 2 ZMY_PROGRAM START-OF-SELECTION (line 5)
311
+ Two modes depending on context:
319
312
 
320
- Source (ZCL_MY_CLASS=============CM003, line 42):
321
- -------------------------------------------------------
322
- METHOD do_something.
323
- DATA lv_val TYPE i.
324
- >>>>> RAISE EXCEPTION TYPE cx_my_error. ← error here
325
- lv_val = lv_val + 1.
326
- ENDMETHOD.
313
+ *Interactive (human in a terminal):*
314
+ ```bash
315
+ # Terminal 1 — attach (blocks waiting for breakpoint, opens REPL on hit)
316
+ abapgit-agent debug attach
317
+
318
+ # Terminal 2 trigger (any command that calls the backend)
319
+ abapgit-agent unit --files src/zcl_my_class.clas.testclasses.abap
320
+ abapgit-agent inspect --files src/zcl_my_class.clas.abap
327
321
  ```
328
322
 
329
- **After identifying the error location**, use `view` to understand the class context:
323
+ *Scripted (AI / automation) best practice: individual sequential calls:*
324
+
325
+ Once the daemon is running and the session is saved to the state file, each
326
+ `vars/stack/step` command is a plain standalone call — no bash script needed.
330
327
 
331
328
  ```bash
332
- # View the class/method where the dump occurred
333
- abapgit-agent view --objects ZCL_MY_CLASS
334
- ```
329
+ # Step 1: start attach listener in background (spawns a daemon, saves session to state file)
330
+ abapgit-agent debug attach --json > /tmp/attach.json 2>&1 &
331
+ sleep 2
335
332
 
336
- #### Filters Reference
333
+ # Step 2: trigger in background — MUST stay alive for the whole session
334
+ abapgit-agent unit --files src/zcl_my_class.clas.testclasses.abap > /tmp/trigger.json 2>&1 &
337
335
 
338
- ```bash
339
- # Filter by user
340
- abapgit-agent dump --user DEVELOPER
336
+ # Step 3: poll until breakpoint fires and session JSON appears in attach output
337
+ SESSION=""
338
+ for i in $(seq 1 30); do
339
+ sleep 0.5
340
+ SESSION=$(grep -o '"session":"[^"]*"' /tmp/attach.json 2>/dev/null | head -1 | cut -d'"' -f4)
341
+ [ -n "$SESSION" ] && break
342
+ done
341
343
 
342
- # Filter by date (system timezone)
343
- abapgit-agent dump --date TODAY
344
- abapgit-agent dump --date YESTERDAY
345
- abapgit-agent dump --date 2024-01-01..2024-01-31
344
+ # Step 4: inspect and step — each is an individual call, no --session needed
345
+ abapgit-agent debug stack --json
346
+ abapgit-agent debug vars --json
347
+ abapgit-agent debug vars --expand LS_OBJECT --json
348
+ abapgit-agent debug step --type over --json
349
+ abapgit-agent debug vars --json
346
350
 
347
- # Filter by program
348
- abapgit-agent dump --program ZMY_PROGRAM
351
+ # Step 5: ALWAYS release the ABAP work process before finishing
352
+ abapgit-agent debug step --type continue --json
349
353
 
350
- # Filter by error type
351
- abapgit-agent dump --error TIME_OUT
352
- abapgit-agent dump --error MESSAGE_TYPE_X
354
+ # Step 6: check trigger result
355
+ cat /tmp/trigger.json
356
+ rm -f /tmp/attach.json /tmp/trigger.json
357
+ ```
358
+
359
+ > **Four rules for scripted mode:**
360
+ > 1. `sleep 2` after starting attach — the listener must register on the server before the trigger fires
361
+ > 2. Keep the trigger process alive in the background for the entire session — if it exits, the ABAP work process is released and the session ends
362
+ > 3. Always finish with `step --type continue` — this releases the frozen work process so the trigger can complete normally
363
+ > 4. **Never pass `--session` to `step/vars/stack`** — it bypasses the daemon IPC and causes `noSessionAttached`. Omit it and let commands auto-load from the saved state file.
353
364
 
354
- # Show full detail for result #N (combine with same filters)
355
- abapgit-agent dump --user DEVELOPER --date TODAY --detail 1
365
+ **Step 3 step through and inspect**
356
366
 
357
- # Use explicit timezone (e.g., for distributed teams)
358
- abapgit-agent dump --date TODAY --timezone Europe/Berlin
367
+ *Interactive REPL commands (after `attach` without `--json`):*
368
+ ```
369
+ debug> v — show all variables
370
+ debug> x LT_DATA — expand a table or structure
371
+ debug> n — step over
372
+ debug> s — step into
373
+ debug> bt — call stack
374
+ debug> q — detach (program continues); kill — hard abort
375
+ ```
376
+
377
+ *Scripted commands (after `attach --json`) — omit `--session`, commands auto-load from state file:*
378
+ ```bash
379
+ abapgit-agent debug vars --json # all variables
380
+ abapgit-agent debug vars --name LV_RESULT --json # one variable
381
+ abapgit-agent debug vars --expand LT_DATA --json # drill into table/structure
382
+ abapgit-agent debug step --type over --json # step over
383
+ abapgit-agent debug step --type into --json # step into
384
+ abapgit-agent debug step --type continue --json # continue to next breakpoint / finish
385
+ abapgit-agent debug stack --json # call stack (shows which test method is active)
386
+ ```
387
+
388
+ **Clean up** when done:
389
+ ```bash
390
+ abapgit-agent debug delete --all
359
391
  ```
360
392
 
361
393
  ---
package/bin/abapgit-agent CHANGED
@@ -51,6 +51,7 @@ async function main() {
51
51
  preview: require('../src/commands/preview'),
52
52
  where: require('../src/commands/where'),
53
53
  dump: require('../src/commands/dump'),
54
+ debug: require('../src/commands/debug'),
54
55
  ref: require('../src/commands/ref'),
55
56
  init: require('../src/commands/init'),
56
57
  pull: require('../src/commands/pull'),
@@ -120,4 +121,11 @@ To enable integration:
120
121
  process.exit(1);
121
122
  }
122
123
 
123
- main();
124
+ main().catch((err) => {
125
+ // Known CLI errors (e.g. pull conflict) already printed their own output — skip re-printing.
126
+ // For all other unexpected errors, print the message without the stack trace.
127
+ if (!err._isPullError) {
128
+ console.error(err.message || err);
129
+ }
130
+ process.exit(1);
131
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abapgit-agent",
3
- "version": "1.9.0",
3
+ "version": "1.10.1",
4
4
  "description": "ABAP Git Agent - Pull and activate ABAP code via abapGit from any git repository",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -34,9 +34,15 @@
34
34
  "test:cmd:preview": "node tests/run-all.js --cmd --command=preview",
35
35
  "test:cmd:tree": "node tests/run-all.js --cmd --command=tree",
36
36
  "test:cmd:dump": "node tests/run-all.js --cmd --command=dump",
37
+ "test:cmd:debug": "node tests/run-all.js --cmd --command=debug",
38
+ "test:debug:scenarios": "bash tests/integration/debug-scenarios.sh",
39
+ "test:debug:scenarios:1": "bash tests/integration/debug-scenarios.sh 1",
40
+ "test:debug:scenarios:2": "bash tests/integration/debug-scenarios.sh 2",
41
+ "test:debug:scenarios:3": "bash tests/integration/debug-scenarios.sh 3",
37
42
  "test:cmd:upgrade": "node tests/run-all.js --cmd --command=upgrade",
38
43
  "test:lifecycle": "node tests/run-all.js --lifecycle",
39
44
  "test:pull": "node tests/run-all.js --pull",
45
+ "test:conflict": "node tests/run-all.js --conflict",
40
46
  "pull": "node bin/abapgit-agent",
41
47
  "release": "node scripts/release.js",
42
48
  "unrelease": "node scripts/unrelease.js"