@a5c-ai/babysitter-github 5.0.1-staging.3902b3b7 → 5.0.1-staging.542f8525

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.
@@ -362,13 +362,13 @@ Mark as FAIL if:
362
362
  - Parse the output and inspect the `resolvedFrom` field. Classify as follows:
363
363
  - `resolvedFrom: "pid-marker"` → mark as PASS ("Session ID derives from the live Claude Code ancestor process -- authoritative").
364
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.
365
+ - `resolvedFrom: "env-var"` → mark as WARN ("`AGENT_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 AGENT_SESSION_ID` before invoking babysitter.
367
367
  - `resolvedFrom: "none"` → mark as ERROR ("No session ID resolvable. Either no session-start hook fired, or the ancestor walk failed").
368
368
 
369
369
  **Env-var shadow check:**
370
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").
371
+ - If `envVarPresent && !envVarMatches`, mark as WARN ("`AGENT_SESSION_ID` in env does not match the resolved session ID; a stale value is shadowing the authoritative one. Unset the env var").
372
372
 
373
373
  ---
374
374
 
@@ -390,7 +390,7 @@ Mark as FAIL if:
390
390
 
391
391
  - Enumerate files in `~/.a5c/` matching the pattern `current-session-*-pid-*`.
392
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").
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 `AGENT_SESSION_ID` appropriately -- the PID marker handles this automatically").
394
394
  - Otherwise mark as PASS.
395
395
 
396
396
  ---
@@ -501,7 +501,7 @@ babysitter session:cleanup --dry-run # preview
501
501
  babysitter session:cleanup # apply
502
502
 
503
503
  # 2. Unset a stale env var
504
- unset BABYSITTER_SESSION_ID
504
+ unset AGENT_SESSION_ID
505
505
 
506
506
  # 3. Re-bind a run explicitly if needed
507
507
  babysitter session:resume --session-id <fresh-id> --state-dir ~/.a5c --run-id <runId> --runs-dir .a5c/runs
@@ -100,10 +100,10 @@ $stderrLog = Join-Path $LogDir "babysitter-session-end-hook-stderr.log"
100
100
  try {
101
101
  if ($Proxy) {
102
102
  Write-Blog "Using hooks-proxy: $Proxy"
103
- Get-Content $InputFile | & $Proxy invoke --adapter copilot --handler "babysitter hook:run --harness unified --hook-type session-end --plugin-root $PluginRoot --json" --json 2>$stderrLog | Out-Null
103
+ Get-Content $InputFile | & $Proxy invoke --adapter copilot --handler "babysitter hook:run --harness unified --hook-type session-end --json" --json 2>$stderrLog | Out-Null
104
104
  } else {
105
105
  Write-Blog "hooks-proxy not found after install, using npx fallback"
106
- Get-Content $InputFile | & npx -y "@a5c-ai/hooks-proxy-cli@$SdkVersion" invoke --adapter copilot --handler "babysitter hook:run --harness unified --hook-type session-end --plugin-root $PluginRoot --json" --json 2>$stderrLog | Out-Null
106
+ Get-Content $InputFile | & npx -y "@a5c-ai/hooks-proxy-cli@$SdkVersion" invoke --adapter copilot --handler "babysitter hook:run --harness unified --hook-type session-end --json" --json 2>$stderrLog | Out-Null
107
107
  }
108
108
  } catch {
109
109
  Write-Blog "Hook error: $_"
@@ -101,7 +101,7 @@ STDERR_LOG="$LOG_DIR/babysitter-session-end-hook-stderr.log"
101
101
  blog "Using hooks-proxy: $PROXY"
102
102
  $PROXY invoke \
103
103
  --adapter copilot \
104
- --handler "babysitter hook:run --harness unified --hook-type session-end --plugin-root ${PLUGIN_ROOT} --json" \
104
+ --handler "babysitter hook:run --harness unified --hook-type session-end --json" \
105
105
  --json \
106
106
  < "$INPUT_FILE" 2>"$STDERR_LOG" || true
107
107
 
@@ -174,11 +174,11 @@ $stderrLog = Join-Path $LogDir "babysitter-session-start-hook-stderr.log"
174
174
 
175
175
  if ($Proxy) {
176
176
  Write-Blog "Using hooks-proxy: $Proxy"
177
- $Result = Get-Content $InputFile | & $Proxy invoke --adapter copilot --handler "babysitter hook:run --harness unified --hook-type session-start --plugin-root $PluginRoot --json" --json 2>$stderrLog
177
+ $Result = Get-Content $InputFile | & $Proxy invoke --adapter copilot --handler "babysitter hook:run --harness unified --hook-type session-start --json" --json 2>$stderrLog
178
178
  $ExitCode = $LASTEXITCODE
179
179
  } else {
180
180
  Write-Blog "hooks-proxy not found after install, using npx fallback"
181
- $Result = Get-Content $InputFile | & npx -y "@a5c-ai/hooks-proxy-cli@$SdkVersion" invoke --adapter copilot --handler "babysitter hook:run --harness unified --hook-type session-start --plugin-root $PluginRoot --json" --json 2>$stderrLog
181
+ $Result = Get-Content $InputFile | & npx -y "@a5c-ai/hooks-proxy-cli@$SdkVersion" invoke --adapter copilot --handler "babysitter hook:run --harness unified --hook-type session-start --json" --json 2>$stderrLog
182
182
  $ExitCode = $LASTEXITCODE
183
183
  }
184
184
 
@@ -161,7 +161,7 @@ STDERR_LOG="$LOG_DIR/babysitter-session-start-hook-stderr.log"
161
161
  blog "Using hooks-proxy: $PROXY"
162
162
  RESULT=$($PROXY invoke \
163
163
  --adapter copilot \
164
- --handler "babysitter hook:run --harness unified --hook-type session-start --plugin-root ${PLUGIN_ROOT} --json" \
164
+ --handler "babysitter hook:run --harness unified --hook-type session-start --json" \
165
165
  --json \
166
166
  < "$INPUT_FILE" 2>"$STDERR_LOG")
167
167
  EXIT_CODE=$?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a5c-ai/babysitter-github",
3
- "version": "5.0.1-staging.3902b3b7",
3
+ "version": "5.0.1-staging.542f8525",
4
4
  "description": "Babysitter orchestration plugin for GitHub Copilot CLI with lifecycle hooks and SDK-managed process-library bootstrapping",
5
5
  "scripts": {
6
6
  "test": "node scripts/sync-command-surfaces.js --check && node test/cloud-agent-install.test.js",
@@ -45,6 +45,6 @@
45
45
  },
46
46
  "homepage": "https://github.com/a5c-ai/babysitter/tree/main/plugins/babysitter-github#readme",
47
47
  "dependencies": {
48
- "@a5c-ai/babysitter-sdk": "5.0.1-staging.3902b3b7"
48
+ "@a5c-ai/babysitter-sdk": "5.0.1-staging.542f8525"
49
49
  }
50
50
  }
package/plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babysitter",
3
- "version": "5.0.1-staging.3902b3b7",
3
+ "version": "5.0.1-staging.542f8525",
4
4
  "description": "Orchestrate complex, multi-step workflows with event-sourced state management, hook-based extensibility, and human-in-the-loop approval -- powered by the Babysitter SDK",
5
5
  "author": {
6
6
  "name": "a5c.ai",
@@ -363,13 +363,13 @@ Mark as FAIL if:
363
363
  - Parse the output and inspect the `resolvedFrom` field. Classify as follows:
364
364
  - `resolvedFrom: "pid-marker"` → mark as PASS ("Session ID derives from the live Claude Code ancestor process -- authoritative").
365
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.
366
+ - `resolvedFrom: "env-var"` → mark as WARN ("`AGENT_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 AGENT_SESSION_ID` before invoking babysitter.
368
368
  - `resolvedFrom: "none"` → mark as ERROR ("No session ID resolvable. Either no session-start hook fired, or the ancestor walk failed").
369
369
 
370
370
  **Env-var shadow check:**
371
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").
372
+ - If `envVarPresent && !envVarMatches`, mark as WARN ("`AGENT_SESSION_ID` in env does not match the resolved session ID; a stale value is shadowing the authoritative one. Unset the env var").
373
373
 
374
374
  ---
375
375
 
@@ -391,7 +391,7 @@ Mark as FAIL if:
391
391
 
392
392
  - Enumerate files in `~/.a5c/` matching the pattern `current-session-*-pid-*`.
393
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").
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 `AGENT_SESSION_ID` appropriately -- the PID marker handles this automatically").
395
395
  - Otherwise mark as PASS.
396
396
 
397
397
  ---
@@ -502,7 +502,7 @@ babysitter session:cleanup --dry-run # preview
502
502
  babysitter session:cleanup # apply
503
503
 
504
504
  # 2. Unset a stale env var
505
- unset BABYSITTER_SESSION_ID
505
+ unset AGENT_SESSION_ID
506
506
 
507
507
  # 3. Re-bind a run explicitly if needed
508
508
  babysitter session:resume --session-id <fresh-id> --state-dir ~/.a5c --run-id <runId> --runs-dir .a5c/runs
package/versions.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "sdkVersion": "5.0.1-staging.3902b3b7"
2
+ "sdkVersion": "5.0.1-staging.542f8525"
3
3
  }
@@ -1,69 +0,0 @@
1
- # Babysitter Session End Hook for GitHub Copilot CLI (PowerShell)
2
- # Cleanup and logging on session exit.
3
- #
4
- # NOTE: Unlike Claude Code's Stop hook, sessionEnd output is IGNORED by
5
- # Copilot CLI. This hook cannot block session exit or drive an orchestration
6
- # loop. It is purely for cleanup and logging.
7
-
8
- $ErrorActionPreference = "Continue"
9
-
10
- $PluginRoot = if ($env:COPILOT_PLUGIN_DIR) { $env:COPILOT_PLUGIN_DIR } else { Split-Path -Parent $PSScriptRoot }
11
-
12
- # Resolve babysitter CLI
13
- $hasBabysitter = [bool](Get-Command babysitter -ErrorAction SilentlyContinue)
14
- $useFallback = $false
15
-
16
- if (-not $hasBabysitter) {
17
- $localBin = Join-Path $env:USERPROFILE ".local\bin\babysitter.cmd"
18
- if (Test-Path $localBin) {
19
- $env:PATH = "$(Split-Path $localBin);$env:PATH"
20
- $hasBabysitter = $true
21
- } else {
22
- $versionsFile = Join-Path $PluginRoot "versions.json"
23
- try {
24
- $SdkVersion = (Get-Content $versionsFile -Raw | ConvertFrom-Json).sdkVersion
25
- if (-not $SdkVersion) { $SdkVersion = "latest" }
26
- } catch {
27
- $SdkVersion = "latest"
28
- }
29
- $useFallback = $true
30
- }
31
- }
32
-
33
- $GlobalRoot = if ($env:BABYSITTER_GLOBAL_STATE_DIR) { $env:BABYSITTER_GLOBAL_STATE_DIR } else { Join-Path $HOME ".a5c" }
34
- $LogDir = if ($env:BABYSITTER_LOG_DIR) { $env:BABYSITTER_LOG_DIR } else { Join-Path $GlobalRoot "logs" }
35
- $LogFile = Join-Path $LogDir "babysitter-session-end-hook.log"
36
- New-Item -ItemType Directory -Path $LogDir -Force -ErrorAction SilentlyContinue | Out-Null
37
-
38
- function Write-Blog {
39
- param([string]$Message)
40
- $ts = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
41
- Add-Content -Path $LogFile -Value "[INFO] $ts $Message" -ErrorAction SilentlyContinue
42
- }
43
-
44
- Write-Blog "Hook script invoked"
45
- Write-Blog "PLUGIN_ROOT=$PluginRoot"
46
-
47
- # Capture stdin
48
- $InputFile = [System.IO.Path]::GetTempFileName()
49
- $input | Out-File -FilePath $InputFile -Encoding utf8
50
-
51
- Write-Blog "Hook input received"
52
-
53
- $stderrLog = Join-Path $LogDir "babysitter-session-end-hook-stderr.log"
54
-
55
- try {
56
- if ($useFallback) {
57
- Get-Content $InputFile | & npx -y "@a5c-ai/babysitter-sdk@$SdkVersion" hook:run --hook-type session-end --harness github-copilot --plugin-root $PluginRoot --json 2>$stderrLog | Out-Null
58
- } elseif ($hasBabysitter) {
59
- Get-Content $InputFile | & babysitter hook:run --hook-type session-end --harness github-copilot --plugin-root $PluginRoot --json 2>$stderrLog | Out-Null
60
- }
61
- } catch {
62
- Write-Blog "Hook error: $_"
63
- }
64
-
65
- Write-Blog "Session end hook complete"
66
-
67
- Remove-Item $InputFile -Force -ErrorAction SilentlyContinue
68
-
69
- exit 0
@@ -1,54 +0,0 @@
1
- #!/bin/bash
2
- # Babysitter Session End Hook for GitHub Copilot CLI
3
- # Cleanup and logging on session exit.
4
- #
5
- # NOTE: Unlike Claude Code's Stop hook, sessionEnd output is IGNORED by
6
- # Copilot CLI. This hook cannot block session exit or drive an orchestration
7
- # loop. It is purely for cleanup and logging.
8
- #
9
- # Protocol:
10
- # Input: JSON via stdin (session context)
11
- # Output: IGNORED by Copilot CLI
12
- # Exit 0: success (exit code also ignored)
13
-
14
- set -uo pipefail
15
-
16
- PLUGIN_ROOT="${COPILOT_PLUGIN_DIR:-$(cd "$(dirname "$0")/.." && pwd)}"
17
-
18
- if ! command -v babysitter &>/dev/null; then
19
- # No CLI available — exit 0 (no-op, proceed with original command)
20
- exit 0
21
- fi
22
-
23
- GLOBAL_ROOT="${BABYSITTER_GLOBAL_STATE_DIR:-$HOME/.a5c}"
24
- LOG_DIR="${BABYSITTER_LOG_DIR:-${GLOBAL_ROOT}/logs}"
25
- LOG_FILE="$LOG_DIR/babysitter-session-end-hook.log"
26
-
27
- mkdir -p "$LOG_DIR" 2>/dev/null
28
-
29
- # Structured logging helper
30
- blog() {
31
- local msg="$1"
32
- local ts
33
- ts="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
34
- echo "[INFO] $ts $msg" >> "$LOG_FILE" 2>/dev/null
35
- babysitter log --type hook --label "hook:session-end" --message "$msg" --source shell-hook 2>/dev/null || true
36
- }
37
-
38
- blog "Hook script invoked"
39
- blog "PLUGIN_ROOT=$PLUGIN_ROOT"
40
-
41
- # Capture stdin so we can log size and pass to CLI
42
- INPUT_FILE=$(mktemp 2>/dev/null || echo "/tmp/hook-session-end-$$.json")
43
- cat > "$INPUT_FILE"
44
-
45
- blog "Hook input received ($(wc -c < "$INPUT_FILE") bytes)"
46
-
47
- # Run cleanup/logging via CLI; output is ignored by Copilot CLI
48
- babysitter hook:run --hook-type session-end --harness github-copilot --plugin-root "$PLUGIN_ROOT" --json < "$INPUT_FILE" 2>"$LOG_DIR/babysitter-session-end-hook-stderr.log" || true
49
-
50
- blog "Session end hook complete"
51
-
52
- rm -f "$INPUT_FILE" 2>/dev/null
53
-
54
- exit 0
@@ -1,111 +0,0 @@
1
- # Babysitter Session Start Hook for GitHub Copilot CLI (PowerShell)
2
- # Ensures the babysitter SDK CLI is installed (from versions.json sdkVersion),
3
- # then delegates to the TypeScript handler.
4
- #
5
- # Protocol:
6
- # Input: JSON via stdin (contains session_id, cwd, etc.)
7
- # Output: JSON via stdout ({} on success)
8
- # Stderr: debug/log output only
9
- # Exit 0: success
10
- # Exit 2: block (fatal error)
11
-
12
- $ErrorActionPreference = "Stop"
13
-
14
- $PluginRoot = if ($env:COPILOT_PLUGIN_DIR) { $env:COPILOT_PLUGIN_DIR } else { Split-Path -Parent $PSScriptRoot }
15
- $MarkerFile = Join-Path $PluginRoot ".babysitter-install-attempted"
16
-
17
- $GlobalRoot = if ($env:BABYSITTER_GLOBAL_STATE_DIR) { $env:BABYSITTER_GLOBAL_STATE_DIR } else { Join-Path $HOME ".a5c" }
18
- $LogDir = if ($env:BABYSITTER_LOG_DIR) { $env:BABYSITTER_LOG_DIR } else { Join-Path $GlobalRoot "logs" }
19
- $LogFile = Join-Path $LogDir "babysitter-session-start-hook.log"
20
- New-Item -ItemType Directory -Path $LogDir -Force -ErrorAction SilentlyContinue | Out-Null
21
-
22
- function Write-Blog {
23
- param([string]$Message)
24
- $ts = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
25
- Add-Content -Path $LogFile -Value "[INFO] $ts $Message" -ErrorAction SilentlyContinue
26
- if (Get-Command babysitter -ErrorAction SilentlyContinue) {
27
- & babysitter log --type hook --label "hook:session-start" --message $Message --source shell-hook 2>$null
28
- }
29
- }
30
-
31
- Write-Blog "Hook script invoked"
32
- Write-Blog "PLUGIN_ROOT=$PluginRoot"
33
-
34
- # Get required SDK version from versions.json
35
- $versionsFile = Join-Path $PluginRoot "versions.json"
36
- try {
37
- $SdkVersion = (Get-Content $versionsFile -Raw | ConvertFrom-Json).sdkVersion
38
- if (-not $SdkVersion) { $SdkVersion = "latest" }
39
- } catch {
40
- $SdkVersion = "latest"
41
- }
42
-
43
- function Install-Sdk {
44
- param([string]$TargetVersion)
45
- try {
46
- & npm i -g "@a5c-ai/babysitter-sdk@$TargetVersion" --loglevel=error 2>$null
47
- if ($LASTEXITCODE -eq 0) {
48
- Write-Blog "Installed SDK globally ($TargetVersion)"
49
- return $true
50
- }
51
- } catch {}
52
- try {
53
- $prefix = Join-Path $env:USERPROFILE ".local"
54
- & npm i -g "@a5c-ai/babysitter-sdk@$TargetVersion" --prefix $prefix --loglevel=error 2>$null
55
- if ($LASTEXITCODE -eq 0) {
56
- $env:PATH = "$prefix\bin;$env:PATH"
57
- Write-Blog "Installed SDK to user prefix ($TargetVersion)"
58
- return $true
59
- }
60
- } catch {}
61
- return $false
62
- }
63
-
64
- # Check if babysitter CLI exists and if version matches
65
- $NeedsInstall = $false
66
- if (Get-Command babysitter -ErrorAction SilentlyContinue) {
67
- $CurrentVersion = & babysitter --version 2>$null
68
- if ($CurrentVersion -ne $SdkVersion) {
69
- Write-Blog "SDK version mismatch: installed=$CurrentVersion, required=$SdkVersion"
70
- $NeedsInstall = $true
71
- } else {
72
- Write-Blog "SDK version OK: $CurrentVersion"
73
- }
74
- } else {
75
- Write-Blog "SDK CLI not found, will install"
76
- $NeedsInstall = $true
77
- }
78
-
79
- # Install/upgrade if needed (only attempt once per plugin version)
80
- if ($NeedsInstall -and -not (Test-Path $MarkerFile)) {
81
- Install-Sdk $SdkVersion | Out-Null
82
- Set-Content -Path $MarkerFile -Value $SdkVersion -ErrorAction SilentlyContinue
83
- }
84
-
85
- # If still not available after install attempt, try npx as last resort
86
- $useFallback = $false
87
- if (-not (Get-Command babysitter -ErrorAction SilentlyContinue)) {
88
- Write-Blog "CLI not found after install, using npx fallback"
89
- $useFallback = $true
90
- }
91
-
92
- # Capture stdin
93
- $InputFile = [System.IO.Path]::GetTempFileName()
94
- $input | Out-File -FilePath $InputFile -Encoding utf8
95
-
96
- Write-Blog "Hook input received"
97
-
98
- $stderrLog = Join-Path $LogDir "babysitter-session-start-hook-stderr.log"
99
-
100
- if ($useFallback) {
101
- $Result = Get-Content $InputFile | & npx -y "@a5c-ai/babysitter-sdk@$SdkVersion" hook:run --hook-type session-start --harness github-copilot --plugin-root $PluginRoot --json 2>$stderrLog
102
- } else {
103
- $Result = Get-Content $InputFile | & babysitter hook:run --hook-type session-start --harness github-copilot --plugin-root $PluginRoot --json 2>$stderrLog
104
- }
105
- $ExitCode = $LASTEXITCODE
106
-
107
- Write-Blog "CLI exit code=$ExitCode"
108
-
109
- Remove-Item $InputFile -Force -ErrorAction SilentlyContinue
110
- Write-Output $Result
111
- exit $ExitCode
@@ -1,101 +0,0 @@
1
- #!/bin/bash
2
- # Babysitter Session Start Hook for GitHub Copilot CLI
3
- # Ensures the babysitter SDK CLI is installed (from versions.json sdkVersion),
4
- # then delegates to the TypeScript handler.
5
- #
6
- # Protocol:
7
- # Input: JSON via stdin (contains session_id, cwd, etc.)
8
- # Output: JSON via stdout ({} on success)
9
- # Stderr: debug/log output only
10
- # Exit 0: success
11
- # Exit 2: block (fatal error)
12
-
13
- set -euo pipefail
14
-
15
- PLUGIN_ROOT="${COPILOT_PLUGIN_DIR:-$(cd "$(dirname "$0")/.." && pwd)}"
16
- MARKER_FILE="${PLUGIN_ROOT}/.babysitter-install-attempted"
17
-
18
- GLOBAL_ROOT="${BABYSITTER_GLOBAL_STATE_DIR:-$HOME/.a5c}"
19
- LOG_DIR="${BABYSITTER_LOG_DIR:-${GLOBAL_ROOT}/logs}"
20
- LOG_FILE="$LOG_DIR/babysitter-session-start-hook.log"
21
- mkdir -p "$LOG_DIR" 2>/dev/null
22
-
23
- # Structured logging helper -- writes to both local and global log
24
- blog() {
25
- local msg="$1"
26
- local ts
27
- ts="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
28
- echo "[INFO] $ts $msg" >> "$LOG_FILE" 2>/dev/null
29
- # Use CLI structured logging when available; fall back to direct append
30
- if command -v babysitter &>/dev/null; then
31
- babysitter log --type hook --label "hook:session-start" --message "$msg" --source shell-hook 2>/dev/null || true
32
- fi
33
- }
34
-
35
- blog "Hook script invoked"
36
- blog "PLUGIN_ROOT=$PLUGIN_ROOT"
37
-
38
- # Get required SDK version from versions.json
39
- SDK_VERSION=$(node -e "try{console.log(JSON.parse(require('fs').readFileSync('${PLUGIN_ROOT}/versions.json','utf8')).sdkVersion||'latest')}catch{console.log('latest')}" 2>/dev/null || echo "latest")
40
-
41
- # Function to install/upgrade SDK
42
- install_sdk() {
43
- local target_version="$1"
44
- # Try global install first, fall back to user-local if permissions fail
45
- if npm i -g "@a5c-ai/babysitter-sdk@${target_version}" --loglevel=error 2>/dev/null; then
46
- blog "Installed SDK globally (${target_version})"
47
- return 0
48
- else
49
- # Global install failed (permissions) -- try user-local prefix
50
- if npm i -g "@a5c-ai/babysitter-sdk@${target_version}" --prefix "$HOME/.local" --loglevel=error 2>/dev/null; then
51
- export PATH="$HOME/.local/bin:$PATH"
52
- blog "Installed SDK to user prefix (${target_version})"
53
- return 0
54
- fi
55
- fi
56
- return 1
57
- }
58
-
59
- # Check if babysitter CLI exists and if version matches
60
- NEEDS_INSTALL=false
61
- if command -v babysitter &>/dev/null; then
62
- CURRENT_VERSION=$(babysitter --version 2>/dev/null || echo "unknown")
63
- if [ "$CURRENT_VERSION" != "$SDK_VERSION" ]; then
64
- blog "SDK version mismatch: installed=${CURRENT_VERSION}, required=${SDK_VERSION}"
65
- NEEDS_INSTALL=true
66
- else
67
- blog "SDK version OK: ${CURRENT_VERSION}"
68
- fi
69
- else
70
- blog "SDK CLI not found, will install"
71
- NEEDS_INSTALL=true
72
- fi
73
-
74
- # Install/upgrade if needed (only attempt once per plugin version)
75
- if [ "$NEEDS_INSTALL" = true ] && [ ! -f "$MARKER_FILE" ]; then
76
- install_sdk "$SDK_VERSION"
77
- echo "$SDK_VERSION" > "$MARKER_FILE" 2>/dev/null
78
- fi
79
-
80
- # If still not available after install attempt, try npx as last resort
81
- if ! command -v babysitter &>/dev/null; then
82
- blog "CLI not found after install, using npx fallback"
83
- babysitter() { npx -y "@a5c-ai/babysitter-sdk@${SDK_VERSION}" "$@"; }
84
- export -f babysitter
85
- fi
86
-
87
- # Capture stdin to a temp file so the CLI receives a clean EOF
88
- # (piping /dev/stdin directly can keep the Node.js event loop alive)
89
- INPUT_FILE=$(mktemp 2>/dev/null || echo "/tmp/hook-session-start-$$.json")
90
- cat > "$INPUT_FILE"
91
-
92
- blog "Hook input received ($(wc -c < "$INPUT_FILE") bytes)"
93
-
94
- RESULT=$(babysitter hook:run --hook-type session-start --harness github-copilot --plugin-root "$PLUGIN_ROOT" --json < "$INPUT_FILE" 2>"$LOG_DIR/babysitter-session-start-hook-stderr.log")
95
- EXIT_CODE=$?
96
-
97
- blog "CLI exit code=$EXIT_CODE"
98
-
99
- rm -f "$INPUT_FILE" 2>/dev/null
100
- printf '%s\n' "$RESULT"
101
- exit $EXIT_CODE
@@ -1,52 +0,0 @@
1
- # Babysitter userPromptSubmitted Hook for GitHub Copilot CLI (PowerShell)
2
- # Applies density-filter compression to long user prompts.
3
- #
4
- # NOTE: Output from this hook is IGNORED by Copilot CLI.
5
- # This hook is for logging and side-effects only.
6
-
7
- $ErrorActionPreference = "Continue"
8
-
9
- $PluginRoot = if ($env:COPILOT_PLUGIN_DIR) { $env:COPILOT_PLUGIN_DIR } else { Split-Path -Parent $PSScriptRoot }
10
-
11
- # Resolve babysitter CLI
12
- $hasBabysitter = [bool](Get-Command babysitter -ErrorAction SilentlyContinue)
13
- $useFallback = $false
14
-
15
- if (-not $hasBabysitter) {
16
- $localBin = Join-Path $env:USERPROFILE ".local\bin\babysitter.cmd"
17
- if (Test-Path $localBin) {
18
- $env:PATH = "$(Split-Path $localBin);$env:PATH"
19
- $hasBabysitter = $true
20
- } else {
21
- $versionsFile = Join-Path $PluginRoot "versions.json"
22
- try {
23
- $SdkVersion = (Get-Content $versionsFile -Raw | ConvertFrom-Json).sdkVersion
24
- if (-not $SdkVersion) { $SdkVersion = "latest" }
25
- } catch {
26
- $SdkVersion = "latest"
27
- }
28
- $useFallback = $true
29
- }
30
- }
31
-
32
- $GlobalRoot = if ($env:BABYSITTER_GLOBAL_STATE_DIR) { $env:BABYSITTER_GLOBAL_STATE_DIR } else { Join-Path $HOME ".a5c" }
33
- $LogDir = if ($env:BABYSITTER_LOG_DIR) { $env:BABYSITTER_LOG_DIR } else { Join-Path $GlobalRoot "logs" }
34
- New-Item -ItemType Directory -Path $LogDir -Force -ErrorAction SilentlyContinue | Out-Null
35
-
36
- # Capture stdin
37
- $InputFile = [System.IO.Path]::GetTempFileName()
38
- $input | Out-File -FilePath $InputFile -Encoding utf8
39
-
40
- $stderrLog = Join-Path $LogDir "babysitter-user-prompt-submitted-hook-stderr.log"
41
-
42
- try {
43
- if ($useFallback) {
44
- Get-Content $InputFile | & npx -y "@a5c-ai/babysitter-sdk@$SdkVersion" hook:run --hook-type user-prompt-submitted --harness github-copilot --json 2>$stderrLog | Out-Null
45
- } elseif ($hasBabysitter) {
46
- Get-Content $InputFile | & babysitter hook:run --hook-type user-prompt-submitted --harness github-copilot --json 2>$stderrLog | Out-Null
47
- }
48
- } catch {}
49
-
50
- Remove-Item $InputFile -Force -ErrorAction SilentlyContinue
51
-
52
- exit 0
@@ -1,31 +0,0 @@
1
- #!/bin/bash
2
- # Babysitter userPromptSubmitted Hook for GitHub Copilot CLI
3
- # Applies density-filter compression to long user prompts.
4
- # Delegates to SDK CLI: babysitter hook:run --hook-type user-prompt-submitted
5
- #
6
- # NOTE: Output from this hook is IGNORED by Copilot CLI.
7
- # This hook is for logging and side-effects only.
8
-
9
- PLUGIN_ROOT="${COPILOT_PLUGIN_DIR:-$(cd "$(dirname "$0")/.." && pwd)}"
10
-
11
- if ! command -v babysitter &>/dev/null; then
12
- # No CLI available — exit 0 (no-op, proceed with original command)
13
- exit 0
14
- fi
15
-
16
- GLOBAL_ROOT="${BABYSITTER_GLOBAL_STATE_DIR:-$HOME/.a5c}"
17
- LOG_DIR="${BABYSITTER_LOG_DIR:-${GLOBAL_ROOT}/logs}"
18
- mkdir -p "$LOG_DIR" 2>/dev/null
19
-
20
- INPUT_FILE=$(mktemp 2>/dev/null || echo "/tmp/hook-user-prompt-submitted-$$.json")
21
- cat > "$INPUT_FILE"
22
-
23
- babysitter log --type hook --label "hook:user-prompt-submitted" --message "Hook invoked" --source shell-hook 2>/dev/null || true
24
-
25
- babysitter hook:run --hook-type user-prompt-submitted --harness github-copilot --json < "$INPUT_FILE" 2>"$LOG_DIR/babysitter-user-prompt-submitted-hook-stderr.log" || true
26
-
27
- babysitter log --type hook --label "hook:user-prompt-submitted" --message "Hook complete" --source shell-hook 2>/dev/null || true
28
-
29
- rm -f "$INPUT_FILE" 2>/dev/null
30
-
31
- exit 0