@a5c-ai/babysitter-gemini 4.0.153

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,129 @@
1
+ #!/bin/bash
2
+ # Babysitter SessionStart Hook for Gemini CLI
3
+ #
4
+ # Fires when a new Gemini CLI session begins.
5
+ # Ensures the babysitter SDK CLI is installed (from versions.json sdkVersion),
6
+ # then delegates to the TypeScript handler via babysitter hook:run.
7
+ #
8
+ # Protocol:
9
+ # Input: JSON via stdin (contains session_id, cwd, etc.)
10
+ # Output: JSON via stdout ({} on success)
11
+ # Stderr: debug/log output only
12
+ # Exit 0: success
13
+ # Exit 2: block (fatal error)
14
+
15
+ set -euo pipefail
16
+
17
+ EXTENSION_PATH="${GEMINI_EXTENSION_PATH:-$(cd "$(dirname "$0")/.." && pwd)}"
18
+ MARKER_FILE="${EXTENSION_PATH}/.babysitter-install-attempted"
19
+
20
+ LOG_DIR="${BABYSITTER_LOG_DIR:-${EXTENSION_PATH}/.a5c/logs}"
21
+ LOG_FILE="$LOG_DIR/babysitter-session-start-hook.log"
22
+ mkdir -p "$LOG_DIR" 2>/dev/null
23
+
24
+ # Structured logging helper — writes to both local and global log
25
+ blog() {
26
+ local msg="$1"
27
+ local ts
28
+ ts="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
29
+ echo "[INFO] $ts $msg" >> "$LOG_FILE" 2>/dev/null
30
+ # Use CLI structured logging when available; fall back to direct append
31
+ if command -v babysitter &>/dev/null; then
32
+ babysitter log --type hook --label "hook:session-start" --message "$msg" --source shell-hook 2>/dev/null || true
33
+ fi
34
+ }
35
+
36
+ blog "SessionStart hook invoked"
37
+ blog "EXTENSION_PATH=$EXTENSION_PATH"
38
+
39
+ # ---------------------------------------------------------------------------
40
+ # Get required SDK version from versions.json
41
+ # ---------------------------------------------------------------------------
42
+
43
+ SDK_VERSION=$(node -e "try{console.log(JSON.parse(require('fs').readFileSync('${EXTENSION_PATH}/versions.json','utf8')).sdkVersion||'latest')}catch{console.log('latest')}" 2>/dev/null || echo "latest")
44
+
45
+ # ---------------------------------------------------------------------------
46
+ # Function to install/upgrade SDK
47
+ # ---------------------------------------------------------------------------
48
+
49
+ install_sdk() {
50
+ local target_version="$1"
51
+ # Try global install first, fall back to user-local if permissions fail
52
+ if npm i -g "@a5c-ai/babysitter-sdk@${target_version}" --loglevel=error 2>/dev/null; then
53
+ blog "Installed SDK globally (${target_version})"
54
+ return 0
55
+ else
56
+ # Global install failed (permissions) — try user-local prefix
57
+ if npm i -g "@a5c-ai/babysitter-sdk@${target_version}" --prefix "$HOME/.local" --loglevel=error 2>/dev/null; then
58
+ export PATH="$HOME/.local/bin:$PATH"
59
+ blog "Installed SDK to user prefix (${target_version})"
60
+ return 0
61
+ fi
62
+ fi
63
+ return 1
64
+ }
65
+
66
+ # ---------------------------------------------------------------------------
67
+ # Check if babysitter CLI exists and if version matches
68
+ # ---------------------------------------------------------------------------
69
+
70
+ NEEDS_INSTALL=false
71
+ if command -v babysitter &>/dev/null; then
72
+ CURRENT_VERSION=$(babysitter --version 2>/dev/null || echo "unknown")
73
+ if [ "$CURRENT_VERSION" != "$SDK_VERSION" ]; then
74
+ blog "SDK version mismatch: installed=${CURRENT_VERSION}, required=${SDK_VERSION}"
75
+ NEEDS_INSTALL=true
76
+ else
77
+ blog "SDK version OK: ${CURRENT_VERSION}"
78
+ fi
79
+ else
80
+ blog "SDK CLI not found, will install"
81
+ NEEDS_INSTALL=true
82
+ fi
83
+
84
+ # Install/upgrade if needed (only attempt once per plugin version)
85
+ if [ "$NEEDS_INSTALL" = true ] && [ ! -f "$MARKER_FILE" ]; then
86
+ install_sdk "$SDK_VERSION"
87
+ echo "$SDK_VERSION" > "$MARKER_FILE" 2>/dev/null
88
+ fi
89
+
90
+ # If still not available after install attempt, try npx as last resort
91
+ if ! command -v babysitter &>/dev/null; then
92
+ blog "CLI not found after install, using npx fallback"
93
+ babysitter() { npx -y "@a5c-ai/babysitter-sdk@${SDK_VERSION}" "$@"; }
94
+ export -f babysitter
95
+ fi
96
+
97
+ # ---------------------------------------------------------------------------
98
+ # Capture stdin to temp file (prevents stdin from keeping event loop alive)
99
+ # ---------------------------------------------------------------------------
100
+
101
+ INPUT_FILE=$(mktemp 2>/dev/null || echo "/tmp/bsitter-session-start-$$.json")
102
+ cat > "$INPUT_FILE"
103
+
104
+ blog "Hook input received ($(wc -c < "$INPUT_FILE") bytes)"
105
+
106
+ # ---------------------------------------------------------------------------
107
+ # Delegate to SDK CLI
108
+ # ---------------------------------------------------------------------------
109
+
110
+ RESULT=$(babysitter hook:run \
111
+ --hook-type session-start \
112
+ --harness gemini-cli \
113
+ --plugin-root "$EXTENSION_PATH" \
114
+ --state-dir ".a5c/state" \
115
+ --verbose --json < "$INPUT_FILE" 2>"$LOG_DIR/babysitter-session-start-hook-stderr.log")
116
+ EXIT_CODE=$?
117
+
118
+ blog "CLI exit code=$EXIT_CODE"
119
+
120
+ rm -f "$INPUT_FILE" 2>/dev/null
121
+
122
+ # Output result (must be valid JSON on stdout)
123
+ if [ -n "$RESULT" ]; then
124
+ printf '%s\n' "$RESULT"
125
+ else
126
+ printf '{}\n'
127
+ fi
128
+
129
+ exit $EXIT_CODE
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@a5c-ai/babysitter-gemini",
3
+ "version": "4.0.153",
4
+ "description": "Babysitter plugin for Gemini CLI — event-sourced orchestration with AfterAgent continuation hooks, session binding, and human-in-the-loop approval gates",
5
+ "scripts": {
6
+ "test": "node test/integration.test.js",
7
+ "postinstall": "node bin/postinstall.js",
8
+ "preuninstall": "node bin/preuninstall.js",
9
+ "deploy": "npm publish --access public",
10
+ "deploy:staging": "npm publish --access public --tag staging"
11
+ },
12
+ "bin": {
13
+ "babysitter-gemini": "bin/cli.js"
14
+ },
15
+ "files": [
16
+ "GEMINI.md",
17
+ "README.md",
18
+ "commands/",
19
+ "hooks/",
20
+ "skills/",
21
+ "scripts/",
22
+ "gemini-extension.json",
23
+ "plugin.json",
24
+ "versions.json",
25
+ "bin/"
26
+ ],
27
+ "keywords": [
28
+ "babysitter",
29
+ "gemini",
30
+ "gemini-cli",
31
+ "gemini-cli-extension",
32
+ "orchestration",
33
+ "extension",
34
+ "ai-agent",
35
+ "event-sourced"
36
+ ],
37
+ "author": "a5c.ai",
38
+ "license": "MIT",
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/a5c-ai/babysitter"
45
+ },
46
+ "homepage": "https://github.com/a5c-ai/babysitter/tree/main/plugins/babysitter-gemini#readme",
47
+ "dependencies": {
48
+ "@a5c-ai/babysitter-sdk": "0.0.184-staging.8e8a0133"
49
+ }
50
+ }
package/plugin.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "babysitter",
3
+ "version": "4.0.153",
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
+ "author": "a5c.ai",
6
+ "license": "MIT",
7
+ "harness": "gemini-cli",
8
+ "hooks": {
9
+ "SessionStart": "hooks/session-start.sh",
10
+ "AfterAgent": "hooks/after-agent.sh"
11
+ },
12
+ "commands": [
13
+ "commands/assimilate.md",
14
+ "commands/call.md",
15
+ "commands/cleanup.md",
16
+ "commands/contrib.md",
17
+ "commands/doctor.md",
18
+ "commands/forever.md",
19
+ "commands/help.md",
20
+ "commands/observe.md",
21
+ "commands/plan.md",
22
+ "commands/plugins.md",
23
+ "commands/project-install.md",
24
+ "commands/resume.md",
25
+ "commands/retrospect.md",
26
+ "commands/user-install.md",
27
+ "commands/yolo.md"
28
+ ],
29
+ "skills": [],
30
+ "contextFileName": "GEMINI.md",
31
+ "extensionManifest": "gemini-extension.json",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/a5c-ai/babysitter"
35
+ },
36
+ "keywords": [
37
+ "orchestration",
38
+ "workflow",
39
+ "automation",
40
+ "event-sourced",
41
+ "hooks",
42
+ "TDD",
43
+ "quality-convergence",
44
+ "agent",
45
+ "LLM",
46
+ "gemini-cli"
47
+ ]
48
+ }
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const {
5
+ listDirectories,
6
+ listMarkdownBasenames,
7
+ reportCheckResult,
8
+ syncCommandMirrors,
9
+ syncSkillsFromCommands,
10
+ } = require('../../../scripts/plugin-command-sync-lib.cjs');
11
+
12
+ const PACKAGE_ROOT = path.resolve(__dirname, '..');
13
+ const REPO_ROOT = path.resolve(PACKAGE_ROOT, '..', '..');
14
+ const ROOT_COMMANDS = path.join(REPO_ROOT, 'plugins', 'babysitter', 'commands');
15
+ const PLUGIN_COMMANDS = path.join(PACKAGE_ROOT, 'commands');
16
+ const PLUGIN_SKILLS = path.join(PACKAGE_ROOT, 'skills');
17
+ const LABEL = 'babysitter-gemini sync';
18
+
19
+ function getMirroredCommandNames() {
20
+ const local = new Set(listMarkdownBasenames(PLUGIN_COMMANDS));
21
+ return listMarkdownBasenames(ROOT_COMMANDS).filter((name) => local.has(name));
22
+ }
23
+
24
+ function getDerivedSkillNames() {
25
+ const local = new Set(listDirectories(PLUGIN_SKILLS));
26
+ return listMarkdownBasenames(PLUGIN_COMMANDS).filter((name) => local.has(name));
27
+ }
28
+
29
+ function main() {
30
+ const check = process.argv.includes('--check');
31
+ const mirrorResult = syncCommandMirrors({
32
+ label: LABEL,
33
+ sourceRoot: ROOT_COMMANDS,
34
+ targetRoot: PLUGIN_COMMANDS,
35
+ names: getMirroredCommandNames(),
36
+ check,
37
+ cwd: PACKAGE_ROOT,
38
+ });
39
+ const skillsResult = syncSkillsFromCommands({
40
+ label: LABEL,
41
+ sourceRoot: PLUGIN_COMMANDS,
42
+ skillsRoot: PLUGIN_SKILLS,
43
+ names: getDerivedSkillNames(),
44
+ check,
45
+ cwd: PACKAGE_ROOT,
46
+ });
47
+
48
+ if (check) {
49
+ reportCheckResult(LABEL, [...mirrorResult.stale, ...skillsResult.stale]);
50
+ return;
51
+ }
52
+
53
+ const updated = mirrorResult.updated + skillsResult.updated;
54
+ if (updated === 0) {
55
+ console.log(`[${LABEL}] no Gemini plugin command changes were needed.`);
56
+ return;
57
+ }
58
+
59
+ console.log(`[${LABEL}] updated ${updated} Gemini plugin file(s).`);
60
+ }
61
+
62
+ main();
package/versions.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "sdkVersion": "0.0.184-staging.8e8a0133",
3
+ "extensionVersion": "4.0.153"
4
+ }