@saptools/cf-debugger 0.1.15 โ†’ 0.1.16

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
@@ -22,7 +22,7 @@ Signal the remote process, enable SSH if needed, forward `9229` to a free local
22
22
 
23
23
  - ๐Ÿš€ **One-shot tunnel** โ€” auth, target, SSH-enable, USR1 signal, port forward, readiness probe โ€” all hidden behind `cf-debugger start`
24
24
  - ๐Ÿงต **Multi-debugger concurrency** โ€” run N debuggers for N apps at once; each session gets its own local port, isolated `CF_HOME`, and an entry in the shared state file
25
- - ๐ŸŽฏ **Exact process targeting** โ€” select a CF process, instance, and optional Node PID; ambiguous Node processes fail closed
25
+ - ๐ŸŽฏ **Exact process targeting** โ€” select a CF process, instance, and optional Node PID; when several Node processes exist the one owning the app's `$PORT` listening socket is auto-selected, otherwise selection fails closed
26
26
  - ๐Ÿ›ก๏ธ **Duplicate-session protection** โ€” the same `region/org/space/app/process/instance` cannot be debugged twice simultaneously (returns `SESSION_ALREADY_RUNNING`)
27
27
  - ๐Ÿงน **Crash-proof state** โ€” provably dead entries are pruned, while ownership mismatches are retained for safe recovery instead of being deleted blindly
28
28
  - ๐Ÿ”Œ **Deterministic ports** โ€” auto-assigned from a safe range (`20000โ€“20999`), or pick your own with `--port`
@@ -102,7 +102,7 @@ cf-debugger start --region eu10 --org my-org --space dev --app my-app --timeout
102
102
  | `--app <name>` | **Required.** CF app name |
103
103
  | `--process <name>` | CF process name (default: `web`) |
104
104
  | `-i, --instance <index>` | Zero-based CF process instance (default: `0`) |
105
- | `--node-pid <pid>` | Exact remote Node.js PID; otherwise one unambiguous PID is discovered |
105
+ | `--node-pid <pid>` | Exact remote Node.js PID; otherwise the app-`$PORT` listener is auto-selected, else one unambiguous PID is discovered |
106
106
  | `--port <number>` | Preferred local port (auto-assigned in `20000โ€“20999` if omitted) |
107
107
  | `--timeout <seconds>` | Tunnel-ready timeout (default: `180`) |
108
108
  | `--verbose` | Print every status transition |
package/dist/cli.js CHANGED
@@ -530,8 +530,10 @@ var NODE_INSPECTOR_SCRIPT = [
530
530
  ' candidate_exe="$(readlink "/proc/$candidate_pid/exe" 2>/dev/null || true)"',
531
531
  ' [ "${candidate_exe##*/}" = node ] || [ "${candidate_exe##*/}" = nodejs ]',
532
532
  "}",
533
- "find_inspector_owner() {",
534
- ` socket_inode="$(awk '$2 ~ /:240D$/ && $4 == "0A" { print $10; exit }' /proc/net/tcp /proc/net/tcp6 2>/dev/null)"`,
533
+ "find_listener_pid() {",
534
+ ' listener_hex="$1"',
535
+ ' [ -n "$listener_hex" ] || return 0',
536
+ ` socket_inode="$(awk -v ph=":$listener_hex" '$4 == "0A" && $2 ~ (ph "$") { print $10; exit }' /proc/net/tcp /proc/net/tcp6 2>/dev/null)"`,
535
537
  ' [ -n "$socket_inode" ] || return 0',
536
538
  " for pid_dir in /proc/[0-9]*; do",
537
539
  ' [ -d "$pid_dir/fd" ] || continue',
@@ -544,6 +546,14 @@ var NODE_INSPECTOR_SCRIPT = [
544
546
  " done",
545
547
  " done",
546
548
  "}",
549
+ "find_inspector_owner() {",
550
+ " find_listener_pid 240D",
551
+ "}",
552
+ "find_app_port_listener() {",
553
+ ' [ -n "${PORT:-}" ] || return 0',
554
+ ` app_port_hex="$(printf '%04X' "$PORT" 2>/dev/null || true)"`,
555
+ ' find_listener_pid "$app_port_hex"',
556
+ "}",
547
557
  'owner_pid="$(find_inspector_owner)"',
548
558
  'selected_pid=""',
549
559
  'if [ -n "$requested_node_pid" ]; then',
@@ -565,7 +575,14 @@ var NODE_INSPECTOR_SCRIPT = [
565
575
  ' selected_pid="$candidate_pid"',
566
576
  " done",
567
577
  ' if [ "$candidate_count" -eq 0 ]; then echo saptools-inspector-node-not-found; exit 0; fi',
568
- ' if [ "$candidate_count" -ne 1 ]; then echo "saptools-inspector-node-ambiguous=$candidate_pids"; exit 0; fi',
578
+ ' if [ "$candidate_count" -ne 1 ]; then',
579
+ ' app_port_pid="$(find_app_port_listener)"',
580
+ ' if [ -n "$app_port_pid" ] && is_node_pid "$app_port_pid"; then',
581
+ ' selected_pid="$app_port_pid"',
582
+ " else",
583
+ ' echo "saptools-inspector-node-ambiguous=$candidate_pids"; exit 0',
584
+ " fi",
585
+ " fi",
569
586
  "fi",
570
587
  'if [ -n "$owner_pid" ]; then',
571
588
  ' if [ "$owner_pid" != "$selected_pid" ]; then echo "saptools-inspector-owner-mismatch=$selected_pid:$owner_pid"; exit 0; fi',