@a5c-ai/babysitter-cursor 0.1.4 → 0.1.5-staging.06f78f92

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
@@ -34,20 +34,10 @@ Install through Cursor's marketplace UI using the repo-root
34
34
  2. Open the marketplace entry named **a5c-ai**
35
35
  3. Install the plugin named **babysitter**
36
36
 
37
- ### Via Babysitter plugin manager
38
-
39
- This path installs the Babysitter plugin package named
40
- `babysitter-cursor` from the SDK marketplace, not the Cursor UI plugin
41
- entry:
42
-
43
- ```bash
44
- babysitter plugin:install babysitter-cursor --marketplace-name a5c-ai --global
45
- ```
46
-
47
- ### Workspace installation
37
+ ### Via Babysitter harness install
48
38
 
49
39
  ```bash
50
- babysitter plugin:install babysitter-cursor --marketplace-name a5c-ai --project
40
+ babysitter harness:install-plugin cursor
51
41
  ```
52
42
 
53
43
  If the workspace does not already have an active process-library binding, the
@@ -91,10 +81,10 @@ ln -s "$(pwd)/plugins/babysitter-cursor" ~/.cursor/plugins/local/babysitter-curs
91
81
  babysitter-cursor uninstall
92
82
  ```
93
83
 
94
- Or via the plugin manager:
84
+ Or via npm:
95
85
 
96
86
  ```bash
97
- babysitter plugin:uninstall babysitter-cursor --global
87
+ npm uninstall -g @a5c-ai/babysitter-cursor
98
88
  ```
99
89
 
100
90
  ## Plugin Structure (Directory Layout)
@@ -294,7 +284,7 @@ behavior within sessions.
294
284
  | `CURSOR_API_KEY` | -- | API key for headless CLI mode (required) |
295
285
  | `CURSOR_PLUGIN_ROOT` | Plugin directory | Plugin root directory |
296
286
  | `BABYSITTER_STATE_DIR` | `<cwd>/.a5c` | State directory for session data |
297
- | `BABYSITTER_LOG_DIR` | `<plugin>/.a5c/logs` | Log output directory |
287
+ | `BABYSITTER_LOG_DIR` | `~/.a5c/logs` | Log output directory override; default is the user-global Babysitter log root |
298
288
 
299
289
  ### SDK Version Pinning
300
290
 
@@ -362,9 +352,7 @@ The repo-root Cursor marketplace manifest lives at `/.cursor-plugin/marketplace.
362
352
  ### User Commands
363
353
 
364
354
  ```bash
365
- babysitter plugin:add-marketplace --marketplace-url https://github.com/a5c-ai/babysitter --marketplace-path plugins/a5c/marketplace/marketplace.json --global
366
- babysitter plugin:list-plugins --marketplace-name a5c-ai --global
367
- babysitter plugin:install babysitter-cursor --marketplace-name a5c-ai --global
355
+ babysitter harness:install-plugin cursor
368
356
  ```
369
357
 
370
358
  ## Troubleshooting
@@ -378,7 +366,7 @@ session health:
378
366
  $doctor
379
367
  ```
380
368
 
381
- Also check log output in `<plugin-root>/.a5c/logs/`:
369
+ Also check log output in `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/`:
382
370
 
383
371
  - `babysitter-session-start-hook.log`
384
372
  - `babysitter-stop-hook.log`
@@ -4,9 +4,9 @@ argument-hint: "[run-id] Optional run ID to diagnose. If omitted, uses the most
4
4
  allowed-tools: Read, Grep, Write, Task, Bash, Edit, Grep, Glob, WebFetch, WebSearch, Search, AskUserQuestion, TodoWrite, TodoRead, Skill, BashOutput, KillShell, MultiEdit, LS
5
5
  ---
6
6
 
7
- You are a diagnostic agent for the babysitter runtime. Your job is to perform a comprehensive health check across 10 areas and produce a structured diagnostic report. Follow each section methodically. Track results as you go and produce the final summary at the end.
7
+ You are a diagnostic agent for the babysitter runtime. Your job is to perform a comprehensive health check across 14 areas and produce a structured diagnostic report. Follow each section methodically. Track results as you go and produce the final summary at the end.
8
8
 
9
- Initialize a results tracker with these 10 checks, all starting as PENDING:
9
+ Initialize a results tracker with these 14 checks, all starting as PENDING:
10
10
  1. Run Discovery
11
11
  2. Journal Integrity
12
12
  3. State Cache Consistency
@@ -17,6 +17,10 @@ Initialize a results tracker with these 10 checks, all starting as PENDING:
17
17
  8. Disk Usage
18
18
  9. Process Validation
19
19
  10. Hook Execution Health
20
+ 11. Session-ID Provenance
21
+ 12. Ancestor Liveness
22
+ 13. Concurrent Session Detection
23
+ 14. Windows Ancestor-Walk Strategy
20
24
 
21
25
  ---
22
26
 
@@ -177,13 +181,13 @@ Mark as PASS if no issues. Mark as WARN if runaway loops or stale sessions detec
177
181
  **Goal:** Analyze babysitter log files for errors, warnings, and stop hook decisions.
178
182
 
179
183
  Read the last 50 lines of each of these log files (if they exist):
180
- - `$CLAUDE_PLUGIN_ROOT/.a5c/logs/hooks.log`
181
- - `$CLAUDE_PLUGIN_ROOT/.a5c/logs/babysitter-stop-hook.log`
182
- - `$CLAUDE_PLUGIN_ROOT/.a5c/logs/babysitter-stop-hook-stderr.log`
183
- - `$CLAUDE_PLUGIN_ROOT/.a5c/logs/babysitter-session-start-hook.log`
184
- - `$CLAUDE_PLUGIN_ROOT/.a5c/logs/babysitter-session-start-hook-stderr.log`
185
- - `$CLAUDE_PLUGIN_ROOT/.a5c/logs/babysitter.log`
186
- - `$HOME/.a5c/logs/` and relevant logs and run/session specific logs there
184
+ - `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/hooks.log`
185
+ - `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/babysitter-stop-hook.log`
186
+ - `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/babysitter-stop-hook-stderr.log`
187
+ - `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/babysitter-session-start-hook.log`
188
+ - `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/babysitter-session-start-hook-stderr.log`
189
+ - `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/babysitter.log`
190
+ - `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/` and relevant run/session specific logs there
187
191
 
188
192
 
189
193
  For each log file:
@@ -285,7 +289,7 @@ The hooks delegate to the `babysitter` CLI. Check if it is available:
285
289
  Check whether the stop hook has actually been invoked during this run's lifetime:
286
290
 
287
291
  **From log files:**
288
- - Read `$CLAUDE_PLUGIN_ROOT/.a5c/logs/babysitter-stop-hook.log` (if it exists).
292
+ - Read `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/babysitter-stop-hook.log` (if it exists).
289
293
  - Count the number of "Hook script invoked" lines. This is the total invocation count.
290
294
  - Count the number of "CLI exit code=" lines and extract exit codes.
291
295
  - If the log file does not exist or has zero invocations, the stop hook has NOT been running.
@@ -297,7 +301,7 @@ Check whether the stop hook has actually been invoked during this run's lifetime
297
301
  - If no STOP_HOOK_INVOKED events exist in the journal, note that the stop hook has not recorded any decisions for this run.
298
302
 
299
303
  **From stderr:**
300
- - Read `$CLAUDE_PLUGIN_ROOT/.a5c/logs/babysitter-stop-hook-stderr.log`.
304
+ - Read `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/babysitter-stop-hook-stderr.log`.
301
305
  - If it contains error output, display it and diagnose:
302
306
  - "command not found" or exit code 127 → CLI not installed (see 10c)
303
307
  - "MODULE_NOT_FOUND" or "Cannot find module" → SDK package corrupted or not built
@@ -350,9 +354,65 @@ Mark as FAIL if:
350
354
 
351
355
  ---
352
356
 
357
+ ## 11. Session-ID Provenance
358
+
359
+ **Goal:** Verify how the current babysitter session ID was resolved and flag stale or shadowed values.
360
+
361
+ - Invoke: `npx babysitter session:whoami --json`
362
+ - Parse the output and inspect the `resolvedFrom` field. Classify as follows:
363
+ - `resolvedFrom: "pid-marker"` → mark as PASS ("Session ID derives from the live Claude Code ancestor process -- authoritative").
364
+ - `resolvedFrom: "env-file"` → mark as PASS with a note ("CLAUDE_ENV_FILE was used; typically healthy").
365
+ - `resolvedFrom: "env-var"` → mark as WARN ("`BABYSITTER_SESSION_ID` is set without a corroborating PID marker. Likely stale from a prior Claude Code session -- see GitHub issue #130").
366
+ - Remediation: run `babysitter session:cleanup` and start a fresh Claude Code session, or `unset BABYSITTER_SESSION_ID` before invoking babysitter.
367
+ - `resolvedFrom: "none"` → mark as ERROR ("No session ID resolvable. Either no session-start hook fired, or the ancestor walk failed").
368
+
369
+ **Env-var shadow check:**
370
+ - Independently inspect `envVarPresent` and `envVarMatches` in the output.
371
+ - If `envVarPresent && !envVarMatches`, mark as WARN ("`BABYSITTER_SESSION_ID` in env does not match the resolved session ID; a stale value is shadowing the authoritative one. Unset the env var").
372
+
373
+ ---
374
+
375
+ ## 12. Ancestor Liveness
376
+
377
+ **Goal:** Confirm the PID marker references a live Claude Code process.
378
+
379
+ - Reuse the `session:whoami --json` output from check 11.
380
+ - Inspect the `ancestorAlive` field.
381
+ - If `ancestorAlive === false`, mark as ERROR ("The PID marker references a dead Claude Code process").
382
+ - Remediation: `babysitter session:cleanup`.
383
+ - Otherwise mark as PASS.
384
+
385
+ ---
386
+
387
+ ## 13. Concurrent Session Detection
388
+
389
+ **Goal:** Surface multiple live harness sessions that may compete for the same session ID.
390
+
391
+ - Enumerate files in `~/.a5c/` matching the pattern `current-session-*-pid-*`.
392
+ - Count markers per harness (derived from the filename).
393
+ - If more than one live marker exists for the same harness, mark as INFO ("Multiple live Claude Code / harness sessions detected; ensure each shell scopes `BABYSITTER_SESSION_ID` appropriately -- the PID marker handles this automatically").
394
+ - Otherwise mark as PASS.
395
+
396
+ ---
397
+
398
+ ## 14. Windows Ancestor-Walk Strategy
399
+
400
+ **Goal:** Verify the ancestor-walk strategy works on Windows, where `wmic` is no longer guaranteed to be present.
401
+
402
+ - Only run this check when `process.platform === 'win32'`. On other platforms, mark as PASS ("Not applicable -- non-Windows platform").
403
+ - Attempt the ancestor walk by invoking `npx babysitter session:whoami --json` (reuse output from check 11 if available).
404
+ - If resolution succeeded (any `resolvedFrom` other than `none`), mark as PASS.
405
+ - If `resolvedFrom: "none"` on Windows:
406
+ - Test `wmic` availability: `where wmic` via shell.
407
+ - If absent, document that Windows 11 24H2 removed `wmic`; the fallback PowerShell CIM path should handle this.
408
+ - If the PowerShell ancestor walk also failed, mark as ERROR with remediation: ensure PowerShell is available (`powershell -NoProfile -Command "Get-CimInstance Win32_Process -Filter ProcessId=$PID"` should work).
409
+ - If the cascade works but is slow (>5s on first probe), add an INFO note on first-probe latency.
410
+
411
+ ---
412
+
353
413
  ## Final Report
354
414
 
355
- After completing all 10 checks, produce the diagnostic report in this format:
415
+ After completing all 14 checks, produce the diagnostic report in this format:
356
416
 
357
417
  ```
358
418
  ============================================
@@ -379,6 +439,10 @@ OVERALL HEALTH: <HEALTHY | WARNING | CRITICAL>
379
439
  | 8 | Disk Usage | <status> |
380
440
  | 9 | Process Validation | <status> |
381
441
  | 10 | Hook Execution Health | <status> |
442
+ | 11 | Session-ID Provenance | <status> |
443
+ | 12 | Ancestor Liveness | <status> |
444
+ | 13 | Concurrent Session Detection | <status> |
445
+ | 14 | Windows Ancestor-Walk Strategy | <status> |
382
446
 
383
447
  --------------------------------------------
384
448
  ISSUES & RECOMMENDATIONS
@@ -392,9 +456,9 @@ OVERALL HEALTH: <HEALTHY | WARNING | CRITICAL>
392
456
  ```
393
457
 
394
458
  **Overall health determination:**
395
- - **HEALTHY**: All 10 checks are PASS.
396
- - **WARNING**: At least one check is WARN but none are FAIL.
397
- - **CRITICAL**: At least one check is FAIL.
459
+ - **HEALTHY**: All 14 checks are PASS (INFO notes are acceptable).
460
+ - **WARNING**: At least one check is WARN but none are FAIL or ERROR.
461
+ - **CRITICAL**: At least one check is FAIL or ERROR.
398
462
 
399
463
  Present the full detailed findings for each check BEFORE the summary table, so the user can see the evidence. End with the summary table and recommendations. Also, create a single HTML report file with all the findings that uses the arwes UI framework and open it for the user in the browser.
400
464
 
@@ -424,3 +488,25 @@ After diagnosing issues, prompt the user to report or fix what was found -- they
424
488
  Example prompt after diagnosis:
425
489
 
426
490
  > "Diagnosis found a stale lock -- process 12847 crashed without cleanup. This is a known edge case in the orchestration loop. Even if you don't want to fix it yourself, reporting it helps: run `/babysitter:contrib bug report: orchestration loop doesn't release lock on unhandled rejection` to open an issue."
491
+
492
+ ---
493
+
494
+ ## Self-Heal Suggestions
495
+
496
+ If any of checks 11-14 surface issues (stale env vars, dead ancestor PIDs, shadowed session IDs, or Windows ancestor-walk failures), suggest the following remediation sequence, in order. Present it as an actionable block:
497
+
498
+ ```bash
499
+ # 1. Cleanup dead markers and orphaned state files
500
+ babysitter session:cleanup --dry-run # preview
501
+ babysitter session:cleanup # apply
502
+
503
+ # 2. Unset a stale env var
504
+ unset BABYSITTER_SESSION_ID
505
+
506
+ # 3. Re-bind a run explicitly if needed
507
+ babysitter session:resume --session-id <fresh-id> --state-dir ~/.a5c --run-id <runId> --runs-dir .a5c/runs
508
+
509
+ # 4. Start a fresh Claude Code session (closes and reopens the session)
510
+ ```
511
+
512
+ Run steps 1 and 2 first; re-run `/babysitter:doctor` after each step to confirm the session-provenance checks return to PASS. Step 3 is only needed when a specific run must be re-bound to the fresh session. If the issue persists after step 4, escalate via `/debug` or `/babysitter:contrib`.
@@ -18,7 +18,7 @@ $MarkerFile = Join-Path $PluginRoot ".babysitter-install-attempted"
18
18
  $env:CURSOR_PLUGIN_ROOT = $PluginRoot
19
19
  $env:BABYSITTER_STATE_DIR = $StateDir
20
20
 
21
- $LogDir = if ($env:BABYSITTER_LOG_DIR) { $env:BABYSITTER_LOG_DIR } else { Join-Path $PluginRoot ".a5c\logs" }
21
+ $LogDir = if ($env:BABYSITTER_LOG_DIR) { $env:BABYSITTER_LOG_DIR } else { Join-Path $HOME ".a5c\logs" }
22
22
  $LogFile = Join-Path $LogDir "babysitter-session-start-hook.log"
23
23
  New-Item -ItemType Directory -Path $LogDir -Force -ErrorAction SilentlyContinue | Out-Null
24
24
 
@@ -15,7 +15,7 @@ set -euo pipefail
15
15
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16
16
  PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
17
17
  STATE_DIR="${BABYSITTER_STATE_DIR:-${PWD}/.a5c}"
18
- LOG_DIR="${BABYSITTER_LOG_DIR:-$PLUGIN_ROOT/.a5c/logs}"
18
+ LOG_DIR="${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}"
19
19
  LOG_FILE="$LOG_DIR/babysitter-session-start-hook.log"
20
20
 
21
21
  export CURSOR_PLUGIN_ROOT="${CURSOR_PLUGIN_ROOT:-${PLUGIN_ROOT}}"
@@ -15,7 +15,7 @@ $StateDir = if ($env:BABYSITTER_STATE_DIR) { $env:BABYSITTER_STATE_DIR } else {
15
15
  $env:CURSOR_PLUGIN_ROOT = $PluginRoot
16
16
  $env:BABYSITTER_STATE_DIR = $StateDir
17
17
 
18
- $LogDir = if ($env:BABYSITTER_LOG_DIR) { $env:BABYSITTER_LOG_DIR } else { Join-Path $PluginRoot ".a5c\logs" }
18
+ $LogDir = if ($env:BABYSITTER_LOG_DIR) { $env:BABYSITTER_LOG_DIR } else { Join-Path $HOME ".a5c\logs" }
19
19
  $LogFile = Join-Path $LogDir "babysitter-stop-hook.log"
20
20
  New-Item -ItemType Directory -Path $LogDir -Force -ErrorAction SilentlyContinue | Out-Null
21
21
 
@@ -13,7 +13,7 @@ set -euo pipefail
13
13
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
14
14
  PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
15
15
  STATE_DIR="${BABYSITTER_STATE_DIR:-${PWD}/.a5c}"
16
- LOG_DIR="${BABYSITTER_LOG_DIR:-$PLUGIN_ROOT/.a5c/logs}"
16
+ LOG_DIR="${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}"
17
17
  LOG_FILE="$LOG_DIR/babysitter-stop-hook.log"
18
18
 
19
19
  export CURSOR_PLUGIN_ROOT="${CURSOR_PLUGIN_ROOT:-${PLUGIN_ROOT}}"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a5c-ai/babysitter-cursor",
3
- "version": "0.1.4",
3
+ "version": "0.1.5-staging.06f78f92",
4
4
  "description": "Babysitter orchestration plugin for Cursor IDE with SDK-managed process-library bootstrapping and in-turn iteration model",
5
5
  "scripts": {
6
6
  "test": "node scripts/sync-command-surfaces.js --check",
@@ -44,6 +44,6 @@
44
44
  },
45
45
  "homepage": "https://github.com/a5c-ai/babysitter/tree/main/plugins/babysitter-cursor#readme",
46
46
  "dependencies": {
47
- "@a5c-ai/babysitter-sdk": "0.0.187"
47
+ "@a5c-ai/babysitter-sdk": "0.0.188-staging.06f78f92"
48
48
  }
49
49
  }
@@ -18,28 +18,21 @@ Read the SDK version from `versions.json` to ensure version compatibility:
18
18
 
19
19
  ```bash
20
20
  SDK_VERSION=$(node -e "try{console.log(JSON.parse(require('fs').readFileSync('${PLUGIN_ROOT}/versions.json','utf8')).sdkVersion||'latest')}catch{console.log('latest')}")
21
+ CLI="npx -y @a5c-ai/babysitter-sdk@$SDK_VERSION"
21
22
  ```
22
23
 
23
- Then ensure the CLI is installed:
24
-
25
- ```bash
26
- sudo npm i -g @a5c-ai/babysitter-sdk@$SDK_VERSION
27
- ```
28
-
29
- Use the CLI alias: `CLI="babysitter"`
30
-
31
- **Alternatively:** `CLI="npx -y @a5c-ai/babysitter-sdk@$SDK_VERSION"`
24
+ If `babysitter` is already installed globally at the correct version, you may use `CLI="babysitter"` instead.
32
25
 
33
26
  ### jq
34
27
 
35
- make sure you have jq installed and available in the path. if not, install it.
28
+ Make sure `jq` is installed and available in the path. If not, install it.
36
29
 
37
30
  ## Instructions
38
31
 
39
32
  Run the following command to get full orchestration instructions:
40
33
 
41
34
  ```bash
42
- babysitter instructions:babysit-skill --harness cursor --json
35
+ $CLI instructions:babysit-skill --harness cursor --json
43
36
  ```
44
37
 
45
38
  Follow the instructions returned by the command above to orchestrate the run.
@@ -53,9 +46,9 @@ automatically re-enter the orchestration loop.
53
46
  Therefore, you MUST use **in-turn iteration**: run the full orchestration loop
54
47
  within a single session turn. The pattern is:
55
48
 
56
- 1. `babysitter run:iterate --json` -- get pending actions
49
+ 1. `$CLI run:iterate --json` -- get pending actions
57
50
  2. For each pending action: execute it (run tasks, post results via `task:post`)
58
- 3. `babysitter run:iterate --json` -- check for more pending actions
51
+ 3. `$CLI run:iterate --json` -- check for more pending actions
59
52
  4. Repeat steps 2-3 until run completes or reaches a breakpoint requiring user input
60
53
  5. If a breakpoint requires user input, ask the user and post the response, then continue iterating
61
54
 
@@ -67,7 +60,7 @@ the orchestration loop. The agent drives the loop directly by calling
67
60
 
68
61
  ```bash
69
62
  # Initial iterate
70
- RESULT=$(babysitter run:iterate --run-id "$RUN_ID" --json)
63
+ RESULT=$($CLI run:iterate --run-id "$RUN_ID" --json)
71
64
  STATUS=$(echo "$RESULT" | jq -r '.status')
72
65
 
73
66
  while [ "$STATUS" != "completed" ] && [ "$STATUS" != "failed" ]; do
@@ -75,7 +68,7 @@ while [ "$STATUS" != "completed" ] && [ "$STATUS" != "failed" ]; do
75
68
  # ... execute tasks, post results ...
76
69
 
77
70
  # Iterate again
78
- RESULT=$(babysitter run:iterate --run-id "$RUN_ID" --json)
71
+ RESULT=$($CLI run:iterate --run-id "$RUN_ID" --json)
79
72
  STATUS=$(echo "$RESULT" | jq -r '.status')
80
73
  done
81
74
  ```
@@ -5,9 +5,9 @@ description: Diagnose babysitter run health - journal integrity, state cache, ef
5
5
 
6
6
  # doctor
7
7
 
8
- You are a diagnostic agent for the babysitter runtime. Your job is to perform a comprehensive health check across 10 areas and produce a structured diagnostic report. Follow each section methodically. Track results as you go and produce the final summary at the end.
8
+ You are a diagnostic agent for the babysitter runtime. Your job is to perform a comprehensive health check across 14 areas and produce a structured diagnostic report. Follow each section methodically. Track results as you go and produce the final summary at the end.
9
9
 
10
- Initialize a results tracker with these 10 checks, all starting as PENDING:
10
+ Initialize a results tracker with these 14 checks, all starting as PENDING:
11
11
  1. Run Discovery
12
12
  2. Journal Integrity
13
13
  3. State Cache Consistency
@@ -18,6 +18,10 @@ Initialize a results tracker with these 10 checks, all starting as PENDING:
18
18
  8. Disk Usage
19
19
  9. Process Validation
20
20
  10. Hook Execution Health
21
+ 11. Session-ID Provenance
22
+ 12. Ancestor Liveness
23
+ 13. Concurrent Session Detection
24
+ 14. Windows Ancestor-Walk Strategy
21
25
 
22
26
  ---
23
27
 
@@ -178,13 +182,13 @@ Mark as PASS if no issues. Mark as WARN if runaway loops or stale sessions detec
178
182
  **Goal:** Analyze babysitter log files for errors, warnings, and stop hook decisions.
179
183
 
180
184
  Read the last 50 lines of each of these log files (if they exist):
181
- - `$CLAUDE_PLUGIN_ROOT/.a5c/logs/hooks.log`
182
- - `$CLAUDE_PLUGIN_ROOT/.a5c/logs/babysitter-stop-hook.log`
183
- - `$CLAUDE_PLUGIN_ROOT/.a5c/logs/babysitter-stop-hook-stderr.log`
184
- - `$CLAUDE_PLUGIN_ROOT/.a5c/logs/babysitter-session-start-hook.log`
185
- - `$CLAUDE_PLUGIN_ROOT/.a5c/logs/babysitter-session-start-hook-stderr.log`
186
- - `$CLAUDE_PLUGIN_ROOT/.a5c/logs/babysitter.log`
187
- - `$HOME/.a5c/logs/` and relevant logs and run/session specific logs there
185
+ - `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/hooks.log`
186
+ - `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/babysitter-stop-hook.log`
187
+ - `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/babysitter-stop-hook-stderr.log`
188
+ - `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/babysitter-session-start-hook.log`
189
+ - `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/babysitter-session-start-hook-stderr.log`
190
+ - `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/babysitter.log`
191
+ - `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/` and relevant run/session specific logs there
188
192
 
189
193
 
190
194
  For each log file:
@@ -286,7 +290,7 @@ The hooks delegate to the `babysitter` CLI. Check if it is available:
286
290
  Check whether the stop hook has actually been invoked during this run's lifetime:
287
291
 
288
292
  **From log files:**
289
- - Read `$CLAUDE_PLUGIN_ROOT/.a5c/logs/babysitter-stop-hook.log` (if it exists).
293
+ - Read `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/babysitter-stop-hook.log` (if it exists).
290
294
  - Count the number of "Hook script invoked" lines. This is the total invocation count.
291
295
  - Count the number of "CLI exit code=" lines and extract exit codes.
292
296
  - If the log file does not exist or has zero invocations, the stop hook has NOT been running.
@@ -298,7 +302,7 @@ Check whether the stop hook has actually been invoked during this run's lifetime
298
302
  - If no STOP_HOOK_INVOKED events exist in the journal, note that the stop hook has not recorded any decisions for this run.
299
303
 
300
304
  **From stderr:**
301
- - Read `$CLAUDE_PLUGIN_ROOT/.a5c/logs/babysitter-stop-hook-stderr.log`.
305
+ - Read `${BABYSITTER_LOG_DIR:-$HOME/.a5c/logs}/babysitter-stop-hook-stderr.log`.
302
306
  - If it contains error output, display it and diagnose:
303
307
  - "command not found" or exit code 127 → CLI not installed (see 10c)
304
308
  - "MODULE_NOT_FOUND" or "Cannot find module" → SDK package corrupted or not built
@@ -351,9 +355,65 @@ Mark as FAIL if:
351
355
 
352
356
  ---
353
357
 
358
+ ## 11. Session-ID Provenance
359
+
360
+ **Goal:** Verify how the current babysitter session ID was resolved and flag stale or shadowed values.
361
+
362
+ - Invoke: `npx babysitter session:whoami --json`
363
+ - Parse the output and inspect the `resolvedFrom` field. Classify as follows:
364
+ - `resolvedFrom: "pid-marker"` → mark as PASS ("Session ID derives from the live Claude Code ancestor process -- authoritative").
365
+ - `resolvedFrom: "env-file"` → mark as PASS with a note ("CLAUDE_ENV_FILE was used; typically healthy").
366
+ - `resolvedFrom: "env-var"` → mark as WARN ("`BABYSITTER_SESSION_ID` is set without a corroborating PID marker. Likely stale from a prior Claude Code session -- see GitHub issue #130").
367
+ - Remediation: run `babysitter session:cleanup` and start a fresh Claude Code session, or `unset BABYSITTER_SESSION_ID` before invoking babysitter.
368
+ - `resolvedFrom: "none"` → mark as ERROR ("No session ID resolvable. Either no session-start hook fired, or the ancestor walk failed").
369
+
370
+ **Env-var shadow check:**
371
+ - Independently inspect `envVarPresent` and `envVarMatches` in the output.
372
+ - If `envVarPresent && !envVarMatches`, mark as WARN ("`BABYSITTER_SESSION_ID` in env does not match the resolved session ID; a stale value is shadowing the authoritative one. Unset the env var").
373
+
374
+ ---
375
+
376
+ ## 12. Ancestor Liveness
377
+
378
+ **Goal:** Confirm the PID marker references a live Claude Code process.
379
+
380
+ - Reuse the `session:whoami --json` output from check 11.
381
+ - Inspect the `ancestorAlive` field.
382
+ - If `ancestorAlive === false`, mark as ERROR ("The PID marker references a dead Claude Code process").
383
+ - Remediation: `babysitter session:cleanup`.
384
+ - Otherwise mark as PASS.
385
+
386
+ ---
387
+
388
+ ## 13. Concurrent Session Detection
389
+
390
+ **Goal:** Surface multiple live harness sessions that may compete for the same session ID.
391
+
392
+ - Enumerate files in `~/.a5c/` matching the pattern `current-session-*-pid-*`.
393
+ - Count markers per harness (derived from the filename).
394
+ - If more than one live marker exists for the same harness, mark as INFO ("Multiple live Claude Code / harness sessions detected; ensure each shell scopes `BABYSITTER_SESSION_ID` appropriately -- the PID marker handles this automatically").
395
+ - Otherwise mark as PASS.
396
+
397
+ ---
398
+
399
+ ## 14. Windows Ancestor-Walk Strategy
400
+
401
+ **Goal:** Verify the ancestor-walk strategy works on Windows, where `wmic` is no longer guaranteed to be present.
402
+
403
+ - Only run this check when `process.platform === 'win32'`. On other platforms, mark as PASS ("Not applicable -- non-Windows platform").
404
+ - Attempt the ancestor walk by invoking `npx babysitter session:whoami --json` (reuse output from check 11 if available).
405
+ - If resolution succeeded (any `resolvedFrom` other than `none`), mark as PASS.
406
+ - If `resolvedFrom: "none"` on Windows:
407
+ - Test `wmic` availability: `where wmic` via shell.
408
+ - If absent, document that Windows 11 24H2 removed `wmic`; the fallback PowerShell CIM path should handle this.
409
+ - If the PowerShell ancestor walk also failed, mark as ERROR with remediation: ensure PowerShell is available (`powershell -NoProfile -Command "Get-CimInstance Win32_Process -Filter ProcessId=$PID"` should work).
410
+ - If the cascade works but is slow (>5s on first probe), add an INFO note on first-probe latency.
411
+
412
+ ---
413
+
354
414
  ## Final Report
355
415
 
356
- After completing all 10 checks, produce the diagnostic report in this format:
416
+ After completing all 14 checks, produce the diagnostic report in this format:
357
417
 
358
418
  ```
359
419
  ============================================
@@ -380,6 +440,10 @@ OVERALL HEALTH: <HEALTHY | WARNING | CRITICAL>
380
440
  | 8 | Disk Usage | <status> |
381
441
  | 9 | Process Validation | <status> |
382
442
  | 10 | Hook Execution Health | <status> |
443
+ | 11 | Session-ID Provenance | <status> |
444
+ | 12 | Ancestor Liveness | <status> |
445
+ | 13 | Concurrent Session Detection | <status> |
446
+ | 14 | Windows Ancestor-Walk Strategy | <status> |
383
447
 
384
448
  --------------------------------------------
385
449
  ISSUES & RECOMMENDATIONS
@@ -393,9 +457,9 @@ OVERALL HEALTH: <HEALTHY | WARNING | CRITICAL>
393
457
  ```
394
458
 
395
459
  **Overall health determination:**
396
- - **HEALTHY**: All 10 checks are PASS.
397
- - **WARNING**: At least one check is WARN but none are FAIL.
398
- - **CRITICAL**: At least one check is FAIL.
460
+ - **HEALTHY**: All 14 checks are PASS (INFO notes are acceptable).
461
+ - **WARNING**: At least one check is WARN but none are FAIL or ERROR.
462
+ - **CRITICAL**: At least one check is FAIL or ERROR.
399
463
 
400
464
  Present the full detailed findings for each check BEFORE the summary table, so the user can see the evidence. End with the summary table and recommendations. Also, create a single HTML report file with all the findings that uses the arwes UI framework and open it for the user in the browser.
401
465
 
@@ -425,3 +489,25 @@ After diagnosing issues, prompt the user to report or fix what was found -- they
425
489
  Example prompt after diagnosis:
426
490
 
427
491
  > "Diagnosis found a stale lock -- process 12847 crashed without cleanup. This is a known edge case in the orchestration loop. Even if you don't want to fix it yourself, reporting it helps: run `/babysitter:contrib bug report: orchestration loop doesn't release lock on unhandled rejection` to open an issue."
492
+
493
+ ---
494
+
495
+ ## Self-Heal Suggestions
496
+
497
+ If any of checks 11-14 surface issues (stale env vars, dead ancestor PIDs, shadowed session IDs, or Windows ancestor-walk failures), suggest the following remediation sequence, in order. Present it as an actionable block:
498
+
499
+ ```bash
500
+ # 1. Cleanup dead markers and orphaned state files
501
+ babysitter session:cleanup --dry-run # preview
502
+ babysitter session:cleanup # apply
503
+
504
+ # 2. Unset a stale env var
505
+ unset BABYSITTER_SESSION_ID
506
+
507
+ # 3. Re-bind a run explicitly if needed
508
+ babysitter session:resume --session-id <fresh-id> --state-dir ~/.a5c --run-id <runId> --runs-dir .a5c/runs
509
+
510
+ # 4. Start a fresh Claude Code session (closes and reopens the session)
511
+ ```
512
+
513
+ Run steps 1 and 2 first; re-run `/babysitter:doctor` after each step to confirm the session-provenance checks return to PASS. Step 3 is only needed when a specific run must be re-bound to the fresh session. If the issue persists after step 4, escalate via `/debug` or `/babysitter:contrib`.
package/versions.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "sdkVersion": "0.0.187"
2
+ "sdkVersion": "0.0.188-staging.06f78f92"
3
3
  }