@a5c-ai/babysitter-codex 5.0.1-staging.5cd43600 → 5.0.1-staging.6e094dee

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,166 @@
1
+ #!/usr/bin/env bash
2
+ # Unified Session Start Hook - routes through hooks-proxy for all hook execution.
3
+ #
4
+ # Ensures the babysitter CLI and hooks-proxy are installed (from versions.json
5
+ # sdkVersion), then delegates to the TypeScript handler via hooks-proxy.
6
+ set -euo pipefail
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
10
+ GLOBAL_ROOT="${BABYSITTER_GLOBAL_STATE_DIR:-$HOME/.a5c}"
11
+ STATE_DIR="${BABYSITTER_STATE_DIR:-${GLOBAL_ROOT}/state}"
12
+ LOG_DIR="${BABYSITTER_LOG_DIR:-${GLOBAL_ROOT}/logs}"
13
+ LOG_FILE="$LOG_DIR/babysitter-session-start-hook.log"
14
+ SDK_MARKER_FILE="${PLUGIN_ROOT}/.babysitter-install-attempted"
15
+ PROXY_MARKER_FILE="${PLUGIN_ROOT}/.hooks-proxy-install-attempted"
16
+
17
+ export CODEX_PLUGIN_ROOT="${CODEX_PLUGIN_ROOT:-${PLUGIN_ROOT}}"
18
+ export BABYSITTER_STATE_DIR="${STATE_DIR}"
19
+
20
+ mkdir -p "$LOG_DIR" 2>/dev/null
21
+
22
+ blog() {
23
+ local msg="$1"
24
+ local ts
25
+ ts="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
26
+ echo "[INFO] $ts $msg" >> "$LOG_FILE" 2>/dev/null
27
+ if command -v babysitter &>/dev/null; then
28
+ babysitter log --type hook --label "hook:session-start" --message "$msg" --source shell-hook 2>/dev/null || true
29
+ fi
30
+ }
31
+
32
+ blog "Unified hook script invoked"
33
+ blog "PLUGIN_ROOT=$PLUGIN_ROOT"
34
+ blog "STATE_DIR=$STATE_DIR"
35
+
36
+ # Get required SDK version from versions.json (used for both SDK and hooks-proxy)
37
+ 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")
38
+
39
+ # ---------------------------------------------------------------------------
40
+ # SDK install/upgrade
41
+ # ---------------------------------------------------------------------------
42
+
43
+ install_sdk() {
44
+ local target_version="$1"
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
+ if npm i -g "@a5c-ai/babysitter-sdk@${target_version}" --prefix "$HOME/.local" --loglevel=error 2>/dev/null; then
50
+ export PATH="$HOME/.local/bin:$PATH"
51
+ blog "Installed SDK to user prefix (${target_version})"
52
+ return 0
53
+ fi
54
+ fi
55
+ return 1
56
+ }
57
+
58
+ NEEDS_SDK_INSTALL=false
59
+ if command -v babysitter &>/dev/null; then
60
+ CURRENT_VERSION=$(babysitter --version 2>/dev/null || echo "unknown")
61
+ if [ "$CURRENT_VERSION" != "$SDK_VERSION" ]; then
62
+ blog "SDK version mismatch: installed=${CURRENT_VERSION}, required=${SDK_VERSION}"
63
+ NEEDS_SDK_INSTALL=true
64
+ else
65
+ blog "SDK version OK: ${CURRENT_VERSION}"
66
+ fi
67
+ else
68
+ blog "SDK CLI not found, will install"
69
+ NEEDS_SDK_INSTALL=true
70
+ fi
71
+
72
+ if [ "$NEEDS_SDK_INSTALL" = true ] && [ ! -f "$SDK_MARKER_FILE" ]; then
73
+ install_sdk "$SDK_VERSION"
74
+ echo "$SDK_VERSION" > "$SDK_MARKER_FILE" 2>/dev/null
75
+ fi
76
+
77
+ if ! command -v babysitter &>/dev/null; then
78
+ blog "CLI not found after install, using npx fallback"
79
+ babysitter() { npx -y "@a5c-ai/babysitter-sdk@${SDK_VERSION}" "$@"; }
80
+ export -f babysitter
81
+ fi
82
+
83
+ # ---------------------------------------------------------------------------
84
+ # Hooks-proxy install/upgrade (same pattern as SDK)
85
+ # ---------------------------------------------------------------------------
86
+
87
+ install_hooks_proxy() {
88
+ local target_version="$1"
89
+ if npm i -g "@a5c-ai/hooks-proxy-cli@${target_version}" --loglevel=error 2>/dev/null; then
90
+ blog "Installed hooks-proxy globally (${target_version})"
91
+ return 0
92
+ else
93
+ if npm i -g "@a5c-ai/hooks-proxy-cli@${target_version}" --prefix "$HOME/.local" --loglevel=error 2>/dev/null; then
94
+ export PATH="$HOME/.local/bin:$PATH"
95
+ blog "Installed hooks-proxy to user prefix (${target_version})"
96
+ return 0
97
+ fi
98
+ fi
99
+ return 1
100
+ }
101
+
102
+ NEEDS_PROXY_INSTALL=false
103
+ if command -v a5c-hooks-proxy &>/dev/null; then
104
+ PROXY_VERSION=$(a5c-hooks-proxy --version 2>/dev/null || echo "unknown")
105
+ if [ "$PROXY_VERSION" != "$SDK_VERSION" ]; then
106
+ blog "hooks-proxy version mismatch: installed=${PROXY_VERSION}, required=${SDK_VERSION}"
107
+ NEEDS_PROXY_INSTALL=true
108
+ else
109
+ blog "hooks-proxy version OK: ${PROXY_VERSION}"
110
+ fi
111
+ elif [ -f "$HOME/.local/bin/a5c-hooks-proxy" ]; then
112
+ export PATH="$HOME/.local/bin:$PATH"
113
+ PROXY_VERSION=$(a5c-hooks-proxy --version 2>/dev/null || echo "unknown")
114
+ if [ "$PROXY_VERSION" != "$SDK_VERSION" ]; then
115
+ blog "hooks-proxy version mismatch: installed=${PROXY_VERSION}, required=${SDK_VERSION}"
116
+ NEEDS_PROXY_INSTALL=true
117
+ else
118
+ blog "hooks-proxy version OK: ${PROXY_VERSION}"
119
+ fi
120
+ else
121
+ blog "hooks-proxy not found, will install"
122
+ NEEDS_PROXY_INSTALL=true
123
+ fi
124
+
125
+ if [ "$NEEDS_PROXY_INSTALL" = true ] && [ ! -f "$PROXY_MARKER_FILE" ]; then
126
+ install_hooks_proxy "$SDK_VERSION"
127
+ echo "$SDK_VERSION" > "$PROXY_MARKER_FILE" 2>/dev/null
128
+ fi
129
+
130
+ # Resolve hooks-proxy binary (npx fallback if still not found)
131
+ PROXY=""
132
+ if command -v a5c-hooks-proxy &>/dev/null; then
133
+ PROXY="a5c-hooks-proxy"
134
+ elif [ -f "$HOME/.local/bin/a5c-hooks-proxy" ]; then
135
+ PROXY="$HOME/.local/bin/a5c-hooks-proxy"
136
+ fi
137
+
138
+ if [ -z "$PROXY" ]; then
139
+ blog "hooks-proxy not found after install, using npx fallback"
140
+ PROXY="npx -y @a5c-ai/hooks-proxy-cli@${SDK_VERSION} "
141
+ fi
142
+
143
+ # ---------------------------------------------------------------------------
144
+ # Capture stdin and delegate to hooks-proxy
145
+ # ---------------------------------------------------------------------------
146
+
147
+ INPUT_FILE=$(mktemp 2>/dev/null || echo "/tmp/codex-session-start-hook-$$.json")
148
+ cat > "$INPUT_FILE"
149
+
150
+ blog "Hook input received ($(wc -c < "$INPUT_FILE") bytes)"
151
+
152
+ STDERR_LOG="$LOG_DIR/babysitter-session-start-hook-stderr.log"
153
+
154
+ blog "Using hooks-proxy: $PROXY"
155
+ RESULT=$($PROXY invoke \
156
+ --adapter codex \
157
+ --handler "babysitter hook:run --harness unified --hook-type session-start --plugin-root ${CODEX_PLUGIN_ROOT} --state-dir ${BABYSITTER_STATE_DIR}" \
158
+ --json \
159
+ < "$INPUT_FILE" 2>"$STDERR_LOG")
160
+ EXIT_CODE=$?
161
+
162
+ blog "CLI exit code=$EXIT_CODE"
163
+
164
+ rm -f "$INPUT_FILE" 2>/dev/null
165
+ printf '%s\n' "$RESULT"
166
+ exit $EXIT_CODE
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env bash
2
+ # Unified Stop Hook - routes through hooks-proxy for all hook execution.
3
+ set -euo pipefail
4
+
5
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
+ PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
7
+ GLOBAL_ROOT="${BABYSITTER_GLOBAL_STATE_DIR:-$HOME/.a5c}"
8
+ STATE_DIR="${BABYSITTER_STATE_DIR:-${GLOBAL_ROOT}/state}"
9
+ LOG_DIR="${BABYSITTER_LOG_DIR:-${GLOBAL_ROOT}/logs}"
10
+ LOG_FILE="$LOG_DIR/babysitter-stop-hook.log"
11
+ PROXY_MARKER_FILE="${PLUGIN_ROOT}/.hooks-proxy-install-attempted"
12
+
13
+ export CODEX_PLUGIN_ROOT="${CODEX_PLUGIN_ROOT:-${PLUGIN_ROOT}}"
14
+ export BABYSITTER_STATE_DIR="${STATE_DIR}"
15
+
16
+ mkdir -p "$LOG_DIR" 2>/dev/null
17
+
18
+ blog() {
19
+ local msg="$1"
20
+ local ts
21
+ ts="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
22
+ echo "[INFO] $ts $msg" >> "$LOG_FILE" 2>/dev/null
23
+ if command -v babysitter &>/dev/null; then
24
+ babysitter log --type hook --label "hook:stop" --message "$msg" --source shell-hook 2>/dev/null || true
25
+ fi
26
+ }
27
+
28
+ blog "Unified hook script invoked"
29
+ blog "PLUGIN_ROOT=$PLUGIN_ROOT"
30
+ blog "STATE_DIR=$STATE_DIR"
31
+
32
+ # Get required version from versions.json (used for hooks-proxy)
33
+ 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")
34
+
35
+ # ---------------------------------------------------------------------------
36
+ # Hooks-proxy install (same pattern as SDK install in session-start)
37
+ # ---------------------------------------------------------------------------
38
+
39
+ install_hooks_proxy() {
40
+ local target_version="$1"
41
+ if npm i -g "@a5c-ai/hooks-proxy-cli@${target_version}" --loglevel=error 2>/dev/null; then
42
+ blog "Installed hooks-proxy globally (${target_version})"
43
+ return 0
44
+ else
45
+ if npm i -g "@a5c-ai/hooks-proxy-cli@${target_version}" --prefix "$HOME/.local" --loglevel=error 2>/dev/null; then
46
+ export PATH="$HOME/.local/bin:$PATH"
47
+ blog "Installed hooks-proxy to user prefix (${target_version})"
48
+ return 0
49
+ fi
50
+ fi
51
+ return 1
52
+ }
53
+
54
+ # Resolve hooks-proxy binary
55
+ PROXY=""
56
+ if command -v a5c-hooks-proxy &>/dev/null; then
57
+ PROXY="a5c-hooks-proxy"
58
+ elif [ -f "$HOME/.local/bin/a5c-hooks-proxy" ]; then
59
+ PROXY="$HOME/.local/bin/a5c-hooks-proxy"
60
+ fi
61
+
62
+ # Install if not found (only attempt once per plugin version)
63
+ if [ -z "$PROXY" ] && [ ! -f "$PROXY_MARKER_FILE" ]; then
64
+ blog "hooks-proxy not found, attempting install"
65
+ install_hooks_proxy "$SDK_VERSION"
66
+ echo "$SDK_VERSION" > "$PROXY_MARKER_FILE" 2>/dev/null
67
+ if command -v a5c-hooks-proxy &>/dev/null; then
68
+ PROXY="a5c-hooks-proxy"
69
+ elif [ -f "$HOME/.local/bin/a5c-hooks-proxy" ]; then
70
+ PROXY="$HOME/.local/bin/a5c-hooks-proxy"
71
+ fi
72
+ fi
73
+
74
+ # npx fallback if still not found
75
+ if [ -z "$PROXY" ]; then
76
+ blog "hooks-proxy not found after install, using npx fallback"
77
+ PROXY="npx -y @a5c-ai/hooks-proxy-cli@${SDK_VERSION} "
78
+ fi
79
+
80
+ # ---------------------------------------------------------------------------
81
+ # Capture stdin and delegate to hooks-proxy
82
+ # ---------------------------------------------------------------------------
83
+
84
+ INPUT_FILE=$(mktemp 2>/dev/null || echo "/tmp/codex-stop-hook-$$.json")
85
+ cat > "$INPUT_FILE"
86
+
87
+ blog "Hook input received ($(wc -c < "$INPUT_FILE") bytes)"
88
+
89
+ STDERR_LOG="$LOG_DIR/babysitter-stop-hook-stderr.log"
90
+
91
+ blog "Using hooks-proxy: $PROXY"
92
+ RESULT=$($PROXY invoke \
93
+ --adapter codex \
94
+ --handler "babysitter hook:run --harness unified --hook-type stop --plugin-root ${CODEX_PLUGIN_ROOT} --state-dir ${BABYSITTER_STATE_DIR}" \
95
+ --json \
96
+ < "$INPUT_FILE" 2>"$STDERR_LOG")
97
+ EXIT_CODE=$?
98
+
99
+ blog "CLI exit code=$EXIT_CODE"
100
+
101
+ rm -f "$INPUT_FILE" 2>/dev/null
102
+ printf '%s\n' "$RESULT"
103
+ exit $EXIT_CODE
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env bash
2
+ # Unified UserPromptSubmit Hook - routes through hooks-proxy for all hook execution.
3
+ set -euo pipefail
4
+
5
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
+ PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
7
+ GLOBAL_ROOT="${BABYSITTER_GLOBAL_STATE_DIR:-$HOME/.a5c}"
8
+ STATE_DIR="${BABYSITTER_STATE_DIR:-${GLOBAL_ROOT}/state}"
9
+ LOG_DIR="${BABYSITTER_LOG_DIR:-${GLOBAL_ROOT}/logs}"
10
+ PROXY_MARKER_FILE="${PLUGIN_ROOT}/.hooks-proxy-install-attempted"
11
+
12
+ export CODEX_PLUGIN_ROOT="${CODEX_PLUGIN_ROOT:-${PLUGIN_ROOT}}"
13
+ export BABYSITTER_STATE_DIR="${STATE_DIR}"
14
+
15
+ mkdir -p "$LOG_DIR" 2>/dev/null
16
+
17
+ # Get required version from versions.json (used for hooks-proxy)
18
+ 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")
19
+
20
+ # ---------------------------------------------------------------------------
21
+ # Hooks-proxy install (same pattern as SDK install in session-start)
22
+ # ---------------------------------------------------------------------------
23
+
24
+ install_hooks_proxy() {
25
+ local target_version="$1"
26
+ if npm i -g "@a5c-ai/hooks-proxy-cli@${target_version}" --loglevel=error 2>/dev/null; then
27
+ return 0
28
+ else
29
+ if npm i -g "@a5c-ai/hooks-proxy-cli@${target_version}" --prefix "$HOME/.local" --loglevel=error 2>/dev/null; then
30
+ export PATH="$HOME/.local/bin:$PATH"
31
+ return 0
32
+ fi
33
+ fi
34
+ return 1
35
+ }
36
+
37
+ # Resolve hooks-proxy binary
38
+ PROXY=""
39
+ if command -v a5c-hooks-proxy &>/dev/null; then
40
+ PROXY="a5c-hooks-proxy"
41
+ elif [ -f "$HOME/.local/bin/a5c-hooks-proxy" ]; then
42
+ PROXY="$HOME/.local/bin/a5c-hooks-proxy"
43
+ fi
44
+
45
+ # Install if not found (only attempt once per plugin version)
46
+ if [ -z "$PROXY" ] && [ ! -f "$PROXY_MARKER_FILE" ]; then
47
+ install_hooks_proxy "$SDK_VERSION"
48
+ echo "$SDK_VERSION" > "$PROXY_MARKER_FILE" 2>/dev/null
49
+ if command -v a5c-hooks-proxy &>/dev/null; then
50
+ PROXY="a5c-hooks-proxy"
51
+ elif [ -f "$HOME/.local/bin/a5c-hooks-proxy" ]; then
52
+ PROXY="$HOME/.local/bin/a5c-hooks-proxy"
53
+ fi
54
+ fi
55
+
56
+ # npx fallback if still not found
57
+ if [ -z "$PROXY" ]; then
58
+ PROXY="npx -y @a5c-ai/hooks-proxy-cli@${SDK_VERSION} "
59
+ fi
60
+
61
+ # ---------------------------------------------------------------------------
62
+ # Capture stdin and delegate to hooks-proxy
63
+ # ---------------------------------------------------------------------------
64
+
65
+ INPUT_FILE=$(mktemp 2>/dev/null || echo "/tmp/codex-user-prompt-submit-hook-$$.json")
66
+ cat > "$INPUT_FILE"
67
+
68
+ if command -v babysitter &>/dev/null; then
69
+ babysitter log --type hook --label "hook:user-prompt-submit" --message "Unified hook invoked" --source shell-hook 2>/dev/null || true
70
+ fi
71
+
72
+ STDERR_LOG="$LOG_DIR/babysitter-user-prompt-submit-hook-stderr.log"
73
+
74
+ RESULT=$($PROXY invoke \
75
+ --adapter codex \
76
+ --handler "babysitter hook:run --harness unified --hook-type user-prompt-submit --plugin-root ${CODEX_PLUGIN_ROOT} --state-dir ${BABYSITTER_STATE_DIR}" \
77
+ --json \
78
+ < "$INPUT_FILE" 2>"$STDERR_LOG")
79
+ EXIT_CODE=$?
80
+
81
+ if command -v babysitter &>/dev/null; then
82
+ babysitter log --type hook --label "hook:user-prompt-submit" --message "CLI exit code=$EXIT_CODE" --source shell-hook 2>/dev/null || true
83
+ fi
84
+
85
+ rm -f "$INPUT_FILE" 2>/dev/null
86
+ if [ -n "$RESULT" ]; then
87
+ printf '%s\n' "$RESULT"
88
+ fi
89
+ exit $EXIT_CODE
@@ -0,0 +1,38 @@
1
+ {
2
+ "_comment": "NOT ACTIVE — Alternative hooks.json using per-hook unified scripts with hooks-proxy support. To activate, replace hooks.json with this file.",
3
+ "hooks": {
4
+ "SessionStart": [
5
+ {
6
+ "matcher": ".*",
7
+ "hooks": [
8
+ {
9
+ "type": "command",
10
+ "command": "./hooks/babysitter-proxied-session-start.sh"
11
+ }
12
+ ]
13
+ }
14
+ ],
15
+ "UserPromptSubmit": [
16
+ {
17
+ "matcher": ".*",
18
+ "hooks": [
19
+ {
20
+ "type": "command",
21
+ "command": "./hooks/babysitter-proxied-user-prompt-submit.sh"
22
+ }
23
+ ]
24
+ }
25
+ ],
26
+ "Stop": [
27
+ {
28
+ "matcher": ".*",
29
+ "hooks": [
30
+ {
31
+ "type": "command",
32
+ "command": "./hooks/babysitter-proxied-stop-hook.sh"
33
+ }
34
+ ]
35
+ }
36
+ ]
37
+ }
38
+ }
package/hooks.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "hooks": [
7
7
  {
8
8
  "type": "command",
9
- "command": "./hooks/babysitter-session-start.sh"
9
+ "command": "./hooks/babysitter-proxied-session-start.sh"
10
10
  }
11
11
  ]
12
12
  }
@@ -17,7 +17,7 @@
17
17
  "hooks": [
18
18
  {
19
19
  "type": "command",
20
- "command": "./hooks/user-prompt-submit.sh"
20
+ "command": "./hooks/babysitter-proxied-user-prompt-submit.sh"
21
21
  }
22
22
  ]
23
23
  }
@@ -28,7 +28,7 @@
28
28
  "hooks": [
29
29
  {
30
30
  "type": "command",
31
- "command": "./hooks/babysitter-stop-hook.sh"
31
+ "command": "./hooks/babysitter-proxied-stop-hook.sh"
32
32
  }
33
33
  ]
34
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a5c-ai/babysitter-codex",
3
- "version": "5.0.1-staging.5cd43600",
3
+ "version": "5.0.1-staging.6e094dee",
4
4
  "description": "Babysitter Codex skill bundle and integration package for OpenAI Codex CLI with SDK-managed process-library bootstrapping, 15 orchestration modes, and BOM-safe SKILL installation",
5
5
  "scripts": {
6
6
  "test": "node test/integration.test.js && node test/packaged-install.test.js",
@@ -46,6 +46,6 @@
46
46
  },
47
47
  "homepage": "https://github.com/a5c-ai/babysitter/tree/main/plugins/babysitter-codex#readme",
48
48
  "dependencies": {
49
- "@a5c-ai/babysitter-sdk": "5.0.1-staging.5cd43600"
49
+ "@a5c-ai/babysitter-sdk": "5.0.1-staging.6e094dee"
50
50
  }
51
51
  }