@a5c-ai/babysitter-opencode 0.1.1-staging.0dc03363
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 +169 -0
- package/bin/cli.cjs +194 -0
- package/bin/cli.js +55 -0
- package/bin/install-shared.cjs +406 -0
- package/bin/install.cjs +97 -0
- package/bin/install.js +110 -0
- package/bin/uninstall.cjs +90 -0
- package/bin/uninstall.js +46 -0
- package/commands/assimilate.md +37 -0
- package/commands/call.md +7 -0
- package/commands/cleanup.md +20 -0
- package/commands/contrib.md +33 -0
- package/commands/doctor.md +426 -0
- package/commands/forever.md +7 -0
- package/commands/help.md +244 -0
- package/commands/observe.md +12 -0
- package/commands/plan.md +7 -0
- package/commands/plugins.md +255 -0
- package/commands/project-install.md +17 -0
- package/commands/resume.md +8 -0
- package/commands/retrospect.md +55 -0
- package/commands/status.md +8 -0
- package/commands/user-install.md +17 -0
- package/commands/yolo.md +7 -0
- package/hooks/hooks.json +46 -0
- package/hooks/session-created.js +180 -0
- package/hooks/session-idle.js +122 -0
- package/hooks/shell-env.js +86 -0
- package/hooks/tool-execute-after.js +105 -0
- package/hooks/tool-execute-before.js +107 -0
- package/package.json +46 -0
- package/plugin.json +25 -0
- package/scripts/sync-command-docs.cjs +105 -0
- package/scripts/sync-command-surfaces.js +52 -0
- package/skills/assimilate/SKILL.md +38 -0
- package/skills/babysit/SKILL.md +35 -0
- package/skills/call/SKILL.md +8 -0
- package/skills/cleanup/SKILL.md +21 -0
- package/skills/contrib/SKILL.md +34 -0
- package/skills/doctor/SKILL.md +427 -0
- package/skills/forever/SKILL.md +8 -0
- package/skills/help/SKILL.md +245 -0
- package/skills/observe/SKILL.md +13 -0
- package/skills/plan/SKILL.md +8 -0
- package/skills/plugins/SKILL.md +257 -0
- package/skills/project-install/SKILL.md +18 -0
- package/skills/resume/SKILL.md +9 -0
- package/skills/retrospect/SKILL.md +56 -0
- package/skills/user-install/SKILL.md +18 -0
- package/skills/yolo/SKILL.md +8 -0
- package/versions.json +4 -0
package/hooks/hooks.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"description": "Babysitter hook registration for OpenCode. Maps OpenCode plugin events to babysitter hook scripts.",
|
|
4
|
+
"hooks": {
|
|
5
|
+
"session.created": [
|
|
6
|
+
{
|
|
7
|
+
"type": "command",
|
|
8
|
+
"script": "hooks/session-created.js",
|
|
9
|
+
"description": "Initialize babysitter session state and inject context",
|
|
10
|
+
"timeoutMs": 30000
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"session.idle": [
|
|
14
|
+
{
|
|
15
|
+
"type": "command",
|
|
16
|
+
"script": "hooks/session-idle.js",
|
|
17
|
+
"description": "Check for pending babysitter effects when agent goes idle",
|
|
18
|
+
"timeoutMs": 30000
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"shell.env": [
|
|
22
|
+
{
|
|
23
|
+
"type": "command",
|
|
24
|
+
"script": "hooks/shell-env.js",
|
|
25
|
+
"description": "Inject BABYSITTER_SESSION_ID and other env vars into shell",
|
|
26
|
+
"timeoutMs": 5000
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"tool.execute.before": [
|
|
30
|
+
{
|
|
31
|
+
"type": "command",
|
|
32
|
+
"script": "hooks/tool-execute-before.js",
|
|
33
|
+
"description": "Pre-tool-use hook for babysitter awareness",
|
|
34
|
+
"timeoutMs": 10000
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"tool.execute.after": [
|
|
38
|
+
{
|
|
39
|
+
"type": "command",
|
|
40
|
+
"script": "hooks/tool-execute-after.js",
|
|
41
|
+
"description": "Post-tool-use hook for babysitter awareness",
|
|
42
|
+
"timeoutMs": 10000
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Babysitter Session Created Hook for OpenCode
|
|
4
|
+
*
|
|
5
|
+
* Fires when an OpenCode session is created. Ensures the babysitter SDK CLI
|
|
6
|
+
* is installed, then delegates to `babysitter hook:run --hook-type session-start`
|
|
7
|
+
* to create baseline session state.
|
|
8
|
+
*
|
|
9
|
+
* OpenCode plugin protocol:
|
|
10
|
+
* - Receives event context as JSON via process.argv or stdin
|
|
11
|
+
* - Outputs JSON to stdout
|
|
12
|
+
* - Exit 0 = success
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
"use strict";
|
|
16
|
+
|
|
17
|
+
const { execSync, execFileSync } = require("child_process");
|
|
18
|
+
const { readFileSync, mkdirSync, appendFileSync, existsSync, writeFileSync } = require("fs");
|
|
19
|
+
const path = require("path");
|
|
20
|
+
const crypto = require("crypto");
|
|
21
|
+
|
|
22
|
+
const PLUGIN_ROOT = process.env.OPENCODE_PLUGIN_ROOT || path.resolve(__dirname, "..");
|
|
23
|
+
const STATE_DIR = process.env.BABYSITTER_STATE_DIR || path.join(process.cwd(), ".a5c");
|
|
24
|
+
const LOG_DIR = process.env.BABYSITTER_LOG_DIR || path.join(PLUGIN_ROOT, ".a5c", "logs");
|
|
25
|
+
const LOG_FILE = path.join(LOG_DIR, "babysitter-session-created-hook.log");
|
|
26
|
+
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Logging
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
function ensureDir(dir) {
|
|
32
|
+
try { mkdirSync(dir, { recursive: true }); } catch { /* best-effort */ }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function blog(msg) {
|
|
36
|
+
ensureDir(LOG_DIR);
|
|
37
|
+
const ts = new Date().toISOString();
|
|
38
|
+
try {
|
|
39
|
+
appendFileSync(LOG_FILE, `[INFO] ${ts} ${msg}\n`);
|
|
40
|
+
} catch { /* best-effort */ }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
// SDK version & install
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
|
|
47
|
+
function getSdkVersion() {
|
|
48
|
+
try {
|
|
49
|
+
const versions = JSON.parse(readFileSync(path.join(PLUGIN_ROOT, "versions.json"), "utf8"));
|
|
50
|
+
return versions.sdkVersion || "latest";
|
|
51
|
+
} catch {
|
|
52
|
+
return "latest";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function hasBabysitterCli() {
|
|
57
|
+
try {
|
|
58
|
+
execSync("babysitter --version", { stdio: "pipe", timeout: 10000 });
|
|
59
|
+
return true;
|
|
60
|
+
} catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function installSdk(version) {
|
|
66
|
+
const marker = path.join(PLUGIN_ROOT, ".babysitter-install-attempted");
|
|
67
|
+
if (existsSync(marker)) return;
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
execSync(`npm i -g "@a5c-ai/babysitter-sdk@${version}" --loglevel=error`, {
|
|
71
|
+
stdio: "pipe",
|
|
72
|
+
timeout: 120000,
|
|
73
|
+
});
|
|
74
|
+
blog(`Installed SDK globally (${version})`);
|
|
75
|
+
} catch {
|
|
76
|
+
// Try user-local prefix
|
|
77
|
+
try {
|
|
78
|
+
const prefix = path.join(process.env.HOME || process.env.USERPROFILE || "~", ".local");
|
|
79
|
+
execSync(`npm i -g "@a5c-ai/babysitter-sdk@${version}" --prefix "${prefix}" --loglevel=error`, {
|
|
80
|
+
stdio: "pipe",
|
|
81
|
+
timeout: 120000,
|
|
82
|
+
});
|
|
83
|
+
blog(`Installed SDK to user prefix (${version})`);
|
|
84
|
+
} catch {
|
|
85
|
+
blog("SDK installation failed");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
try { writeFileSync(marker, version); } catch { /* best-effort */ }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
// CLI execution helper
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
|
|
96
|
+
function runBabysitterHook(hookType, inputJson) {
|
|
97
|
+
const sdkVersion = getSdkVersion();
|
|
98
|
+
const args = [
|
|
99
|
+
"hook:run",
|
|
100
|
+
"--hook-type", hookType,
|
|
101
|
+
"--harness", "opencode",
|
|
102
|
+
"--plugin-root", PLUGIN_ROOT,
|
|
103
|
+
"--state-dir", STATE_DIR,
|
|
104
|
+
"--json",
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const result = execSync(`babysitter ${args.join(" ")}`, {
|
|
109
|
+
input: inputJson,
|
|
110
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
111
|
+
timeout: 30000,
|
|
112
|
+
env: { ...process.env, BABYSITTER_STATE_DIR: STATE_DIR },
|
|
113
|
+
});
|
|
114
|
+
return result.toString("utf8").trim();
|
|
115
|
+
} catch (err) {
|
|
116
|
+
// Fall back to npx
|
|
117
|
+
try {
|
|
118
|
+
const result = execSync(`npx -y "@a5c-ai/babysitter-sdk@${sdkVersion}" ${args.join(" ")}`, {
|
|
119
|
+
input: inputJson,
|
|
120
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
121
|
+
timeout: 60000,
|
|
122
|
+
env: { ...process.env, BABYSITTER_STATE_DIR: STATE_DIR },
|
|
123
|
+
});
|
|
124
|
+
return result.toString("utf8").trim();
|
|
125
|
+
} catch (npxErr) {
|
|
126
|
+
blog(`Hook execution failed: ${npxErr.message}`);
|
|
127
|
+
return "{}";
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
// Main
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
|
|
136
|
+
function main() {
|
|
137
|
+
blog("session-created hook invoked");
|
|
138
|
+
blog(`PLUGIN_ROOT=${PLUGIN_ROOT}`);
|
|
139
|
+
|
|
140
|
+
// Generate a session ID if OpenCode doesn't provide one
|
|
141
|
+
const sessionId = process.env.OPENCODE_SESSION_ID
|
|
142
|
+
|| process.env.BABYSITTER_SESSION_ID
|
|
143
|
+
|| crypto.randomUUID();
|
|
144
|
+
|
|
145
|
+
// Set env var so downstream hooks can pick it up
|
|
146
|
+
process.env.BABYSITTER_SESSION_ID = sessionId;
|
|
147
|
+
|
|
148
|
+
const sdkVersion = getSdkVersion();
|
|
149
|
+
|
|
150
|
+
// Ensure SDK is installed
|
|
151
|
+
if (!hasBabysitterCli()) {
|
|
152
|
+
blog("SDK CLI not found, attempting install");
|
|
153
|
+
installSdk(sdkVersion);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Build hook input
|
|
157
|
+
const hookInput = JSON.stringify({
|
|
158
|
+
session_id: sessionId,
|
|
159
|
+
cwd: process.cwd(),
|
|
160
|
+
harness: "opencode",
|
|
161
|
+
plugin_root: PLUGIN_ROOT,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
blog(`Hook input: ${hookInput}`);
|
|
165
|
+
|
|
166
|
+
// Delegate to SDK hook handler
|
|
167
|
+
const result = runBabysitterHook("session-start", hookInput);
|
|
168
|
+
|
|
169
|
+
blog(`Hook result: ${result}`);
|
|
170
|
+
|
|
171
|
+
// Output result
|
|
172
|
+
try {
|
|
173
|
+
const parsed = JSON.parse(result);
|
|
174
|
+
process.stdout.write(JSON.stringify(parsed) + "\n");
|
|
175
|
+
} catch {
|
|
176
|
+
process.stdout.write("{}\n");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
main();
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Babysitter Session Idle Hook for OpenCode
|
|
4
|
+
*
|
|
5
|
+
* Fires when the OpenCode agent goes idle. Checks if the current babysitter
|
|
6
|
+
* run has pending effects that need attention. Since OpenCode does NOT have a
|
|
7
|
+
* blocking stop hook, this is fire-and-forget -- it outputs context about
|
|
8
|
+
* pending effects so the agent can decide whether to continue iterating.
|
|
9
|
+
*
|
|
10
|
+
* Delegates to `babysitter hook:run --hook-type stop` (which handles the
|
|
11
|
+
* run-state inspection and iteration tracking).
|
|
12
|
+
*
|
|
13
|
+
* OpenCode plugin protocol:
|
|
14
|
+
* - Receives event context as JSON via stdin
|
|
15
|
+
* - Outputs JSON to stdout
|
|
16
|
+
* - Exit 0 = success
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
const { execSync } = require("child_process");
|
|
22
|
+
const { readFileSync, mkdirSync, appendFileSync } = require("fs");
|
|
23
|
+
const path = require("path");
|
|
24
|
+
|
|
25
|
+
const PLUGIN_ROOT = process.env.OPENCODE_PLUGIN_ROOT || path.resolve(__dirname, "..");
|
|
26
|
+
const STATE_DIR = process.env.BABYSITTER_STATE_DIR || path.join(process.cwd(), ".a5c");
|
|
27
|
+
const LOG_DIR = process.env.BABYSITTER_LOG_DIR || path.join(PLUGIN_ROOT, ".a5c", "logs");
|
|
28
|
+
const LOG_FILE = path.join(LOG_DIR, "babysitter-session-idle-hook.log");
|
|
29
|
+
|
|
30
|
+
function ensureDir(dir) {
|
|
31
|
+
try { mkdirSync(dir, { recursive: true }); } catch { /* best-effort */ }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function blog(msg) {
|
|
35
|
+
ensureDir(LOG_DIR);
|
|
36
|
+
const ts = new Date().toISOString();
|
|
37
|
+
try {
|
|
38
|
+
appendFileSync(LOG_FILE, `[INFO] ${ts} ${msg}\n`);
|
|
39
|
+
} catch { /* best-effort */ }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getSdkVersion() {
|
|
43
|
+
try {
|
|
44
|
+
const versions = JSON.parse(readFileSync(path.join(PLUGIN_ROOT, "versions.json"), "utf8"));
|
|
45
|
+
return versions.sdkVersion || "latest";
|
|
46
|
+
} catch {
|
|
47
|
+
return "latest";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function runBabysitterHook(hookType, inputJson) {
|
|
52
|
+
const sdkVersion = getSdkVersion();
|
|
53
|
+
const args = [
|
|
54
|
+
"hook:run",
|
|
55
|
+
"--hook-type", hookType,
|
|
56
|
+
"--harness", "opencode",
|
|
57
|
+
"--plugin-root", PLUGIN_ROOT,
|
|
58
|
+
"--state-dir", STATE_DIR,
|
|
59
|
+
"--json",
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const result = execSync(`babysitter ${args.join(" ")}`, {
|
|
64
|
+
input: inputJson,
|
|
65
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
66
|
+
timeout: 30000,
|
|
67
|
+
env: { ...process.env, BABYSITTER_STATE_DIR: STATE_DIR },
|
|
68
|
+
});
|
|
69
|
+
return result.toString("utf8").trim();
|
|
70
|
+
} catch {
|
|
71
|
+
try {
|
|
72
|
+
const result = execSync(`npx -y "@a5c-ai/babysitter-sdk@${sdkVersion}" ${args.join(" ")}`, {
|
|
73
|
+
input: inputJson,
|
|
74
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
75
|
+
timeout: 60000,
|
|
76
|
+
env: { ...process.env, BABYSITTER_STATE_DIR: STATE_DIR },
|
|
77
|
+
});
|
|
78
|
+
return result.toString("utf8").trim();
|
|
79
|
+
} catch (err) {
|
|
80
|
+
blog(`Hook execution failed: ${err.message}`);
|
|
81
|
+
return "{}";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function main() {
|
|
87
|
+
blog("session-idle hook invoked");
|
|
88
|
+
|
|
89
|
+
const sessionId = process.env.BABYSITTER_SESSION_ID
|
|
90
|
+
|| process.env.OPENCODE_SESSION_ID
|
|
91
|
+
|| "";
|
|
92
|
+
|
|
93
|
+
if (!sessionId) {
|
|
94
|
+
blog("No session ID -- nothing to check");
|
|
95
|
+
process.stdout.write("{}\n");
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const hookInput = JSON.stringify({
|
|
100
|
+
session_id: sessionId,
|
|
101
|
+
cwd: process.cwd(),
|
|
102
|
+
harness: "opencode",
|
|
103
|
+
plugin_root: PLUGIN_ROOT,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
blog(`Checking run status for session ${sessionId}`);
|
|
107
|
+
|
|
108
|
+
// Delegate to the stop hook handler, which inspects run state
|
|
109
|
+
// and returns block/allow decisions
|
|
110
|
+
const result = runBabysitterHook("stop", hookInput);
|
|
111
|
+
|
|
112
|
+
blog(`Hook result: ${result}`);
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
const parsed = JSON.parse(result);
|
|
116
|
+
process.stdout.write(JSON.stringify(parsed) + "\n");
|
|
117
|
+
} catch {
|
|
118
|
+
process.stdout.write("{}\n");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
main();
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Babysitter Shell Environment Hook for OpenCode
|
|
4
|
+
*
|
|
5
|
+
* Fires when OpenCode initializes a shell environment. Injects babysitter
|
|
6
|
+
* environment variables (BABYSITTER_SESSION_ID, BABYSITTER_STATE_DIR, etc.)
|
|
7
|
+
* so that subprocesses and other hooks can discover the active session.
|
|
8
|
+
*
|
|
9
|
+
* This is critical for OpenCode because it does NOT natively inject
|
|
10
|
+
* distinctive env vars into plugins -- the babysitter plugin must self-inject
|
|
11
|
+
* them via this hook.
|
|
12
|
+
*
|
|
13
|
+
* OpenCode plugin protocol:
|
|
14
|
+
* - Outputs env var assignments as JSON: { "env": { "KEY": "VALUE" } }
|
|
15
|
+
* - Exit 0 = success
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
"use strict";
|
|
19
|
+
|
|
20
|
+
const { readFileSync, mkdirSync, appendFileSync, existsSync } = require("fs");
|
|
21
|
+
const path = require("path");
|
|
22
|
+
const crypto = require("crypto");
|
|
23
|
+
|
|
24
|
+
const PLUGIN_ROOT = process.env.OPENCODE_PLUGIN_ROOT || path.resolve(__dirname, "..");
|
|
25
|
+
const STATE_DIR = process.env.BABYSITTER_STATE_DIR || path.join(process.cwd(), ".a5c");
|
|
26
|
+
const RUNS_DIR = process.env.BABYSITTER_RUNS_DIR || path.join(STATE_DIR, "runs");
|
|
27
|
+
const LOG_DIR = process.env.BABYSITTER_LOG_DIR || path.join(PLUGIN_ROOT, ".a5c", "logs");
|
|
28
|
+
const LOG_FILE = path.join(LOG_DIR, "babysitter-shell-env-hook.log");
|
|
29
|
+
|
|
30
|
+
function ensureDir(dir) {
|
|
31
|
+
try { mkdirSync(dir, { recursive: true }); } catch { /* best-effort */ }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function blog(msg) {
|
|
35
|
+
ensureDir(LOG_DIR);
|
|
36
|
+
const ts = new Date().toISOString();
|
|
37
|
+
try {
|
|
38
|
+
appendFileSync(LOG_FILE, `[INFO] ${ts} ${msg}\n`);
|
|
39
|
+
} catch { /* best-effort */ }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getSdkVersion() {
|
|
43
|
+
try {
|
|
44
|
+
const versions = JSON.parse(readFileSync(path.join(PLUGIN_ROOT, "versions.json"), "utf8"));
|
|
45
|
+
return versions.sdkVersion || "latest";
|
|
46
|
+
} catch {
|
|
47
|
+
return "latest";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function main() {
|
|
52
|
+
blog("shell-env hook invoked");
|
|
53
|
+
|
|
54
|
+
// Resolve or generate session ID
|
|
55
|
+
const sessionId = process.env.BABYSITTER_SESSION_ID
|
|
56
|
+
|| process.env.OPENCODE_SESSION_ID
|
|
57
|
+
|| crypto.randomUUID();
|
|
58
|
+
|
|
59
|
+
const sdkVersion = getSdkVersion();
|
|
60
|
+
|
|
61
|
+
// Build env vars to inject
|
|
62
|
+
const env = {
|
|
63
|
+
BABYSITTER_SESSION_ID: sessionId,
|
|
64
|
+
OPENCODE_SESSION_ID: sessionId,
|
|
65
|
+
BABYSITTER_STATE_DIR: STATE_DIR,
|
|
66
|
+
BABYSITTER_RUNS_DIR: RUNS_DIR,
|
|
67
|
+
OPENCODE_PLUGIN_ROOT: PLUGIN_ROOT,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Add SDK version for downstream hooks
|
|
71
|
+
if (sdkVersion && sdkVersion !== "latest") {
|
|
72
|
+
env.BABYSITTER_SDK_VERSION = sdkVersion;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Add global state dir if defined
|
|
76
|
+
const globalStateDir = process.env.BABYSITTER_GLOBAL_STATE_DIR;
|
|
77
|
+
if (globalStateDir) {
|
|
78
|
+
env.BABYSITTER_GLOBAL_STATE_DIR = globalStateDir;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
blog(`Injecting env: ${JSON.stringify(env)}`);
|
|
82
|
+
|
|
83
|
+
process.stdout.write(JSON.stringify({ env }) + "\n");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
main();
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Babysitter Tool Execute After Hook for OpenCode
|
|
4
|
+
*
|
|
5
|
+
* Fires after a tool execution in OpenCode. Delegates to
|
|
6
|
+
* `babysitter hook:run --hook-type post-tool-use` for post-tool-use awareness.
|
|
7
|
+
*
|
|
8
|
+
* This hook can be used to:
|
|
9
|
+
* - Log tool execution results for babysitter run observability
|
|
10
|
+
* - Trigger babysitter effects based on tool outputs
|
|
11
|
+
* - Update session state after tool executions
|
|
12
|
+
*
|
|
13
|
+
* OpenCode plugin protocol:
|
|
14
|
+
* - Receives tool result context as JSON via stdin
|
|
15
|
+
* - Outputs JSON to stdout
|
|
16
|
+
* - Exit 0 = success
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
const { execSync } = require("child_process");
|
|
22
|
+
const { readFileSync, mkdirSync, appendFileSync } = require("fs");
|
|
23
|
+
const path = require("path");
|
|
24
|
+
|
|
25
|
+
const PLUGIN_ROOT = process.env.OPENCODE_PLUGIN_ROOT || path.resolve(__dirname, "..");
|
|
26
|
+
const STATE_DIR = process.env.BABYSITTER_STATE_DIR || path.join(process.cwd(), ".a5c");
|
|
27
|
+
const LOG_DIR = process.env.BABYSITTER_LOG_DIR || path.join(PLUGIN_ROOT, ".a5c", "logs");
|
|
28
|
+
const LOG_FILE = path.join(LOG_DIR, "babysitter-tool-after-hook.log");
|
|
29
|
+
|
|
30
|
+
function ensureDir(dir) {
|
|
31
|
+
try { mkdirSync(dir, { recursive: true }); } catch { /* best-effort */ }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function blog(msg) {
|
|
35
|
+
ensureDir(LOG_DIR);
|
|
36
|
+
const ts = new Date().toISOString();
|
|
37
|
+
try {
|
|
38
|
+
appendFileSync(LOG_FILE, `[INFO] ${ts} ${msg}\n`);
|
|
39
|
+
} catch { /* best-effort */ }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getSdkVersion() {
|
|
43
|
+
try {
|
|
44
|
+
const versions = JSON.parse(readFileSync(path.join(PLUGIN_ROOT, "versions.json"), "utf8"));
|
|
45
|
+
return versions.sdkVersion || "latest";
|
|
46
|
+
} catch {
|
|
47
|
+
return "latest";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function main() {
|
|
52
|
+
const sessionId = process.env.BABYSITTER_SESSION_ID
|
|
53
|
+
|| process.env.OPENCODE_SESSION_ID
|
|
54
|
+
|| "";
|
|
55
|
+
|
|
56
|
+
if (!sessionId) {
|
|
57
|
+
process.stdout.write("{}\n");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Read stdin for tool result context
|
|
62
|
+
let inputData = "";
|
|
63
|
+
try {
|
|
64
|
+
inputData = require("fs").readFileSync(0, "utf8");
|
|
65
|
+
} catch {
|
|
66
|
+
// No stdin available
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
blog(`tool-execute-after: session=${sessionId}`);
|
|
70
|
+
|
|
71
|
+
const hookInput = JSON.stringify({
|
|
72
|
+
session_id: sessionId,
|
|
73
|
+
cwd: process.cwd(),
|
|
74
|
+
harness: "opencode",
|
|
75
|
+
plugin_root: PLUGIN_ROOT,
|
|
76
|
+
tool_result: inputData ? JSON.parse(inputData) : {},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const sdkVersion = getSdkVersion();
|
|
80
|
+
const args = [
|
|
81
|
+
"hook:run",
|
|
82
|
+
"--hook-type", "post-tool-use",
|
|
83
|
+
"--harness", "opencode",
|
|
84
|
+
"--plugin-root", PLUGIN_ROOT,
|
|
85
|
+
"--state-dir", STATE_DIR,
|
|
86
|
+
"--json",
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const result = execSync(`babysitter ${args.join(" ")}`, {
|
|
91
|
+
input: hookInput,
|
|
92
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
93
|
+
timeout: 10000,
|
|
94
|
+
env: { ...process.env, BABYSITTER_STATE_DIR: STATE_DIR },
|
|
95
|
+
});
|
|
96
|
+
const output = result.toString("utf8").trim();
|
|
97
|
+
blog(`Hook result: ${output}`);
|
|
98
|
+
process.stdout.write((output || "{}") + "\n");
|
|
99
|
+
} catch {
|
|
100
|
+
blog("Post-tool-use hook failed -- non-blocking");
|
|
101
|
+
process.stdout.write("{}\n");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
main();
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Babysitter Tool Execute Before Hook for OpenCode
|
|
4
|
+
*
|
|
5
|
+
* Fires before a tool execution in OpenCode. Delegates to
|
|
6
|
+
* `babysitter hook:run --hook-type pre-tool-use` for pre-tool-use awareness.
|
|
7
|
+
*
|
|
8
|
+
* This hook can be used to:
|
|
9
|
+
* - Log tool invocations for babysitter run observability
|
|
10
|
+
* - Block certain tool calls during specific orchestration phases
|
|
11
|
+
* - Inject babysitter context into tool arguments
|
|
12
|
+
*
|
|
13
|
+
* OpenCode plugin protocol:
|
|
14
|
+
* - Receives tool context as JSON via stdin
|
|
15
|
+
* - Outputs JSON to stdout (empty = allow, { block: true } = block)
|
|
16
|
+
* - Exit 0 = success
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
const { execSync } = require("child_process");
|
|
22
|
+
const { readFileSync, mkdirSync, appendFileSync } = require("fs");
|
|
23
|
+
const path = require("path");
|
|
24
|
+
|
|
25
|
+
const PLUGIN_ROOT = process.env.OPENCODE_PLUGIN_ROOT || path.resolve(__dirname, "..");
|
|
26
|
+
const STATE_DIR = process.env.BABYSITTER_STATE_DIR || path.join(process.cwd(), ".a5c");
|
|
27
|
+
const LOG_DIR = process.env.BABYSITTER_LOG_DIR || path.join(PLUGIN_ROOT, ".a5c", "logs");
|
|
28
|
+
const LOG_FILE = path.join(LOG_DIR, "babysitter-tool-before-hook.log");
|
|
29
|
+
|
|
30
|
+
function ensureDir(dir) {
|
|
31
|
+
try { mkdirSync(dir, { recursive: true }); } catch { /* best-effort */ }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function blog(msg) {
|
|
35
|
+
ensureDir(LOG_DIR);
|
|
36
|
+
const ts = new Date().toISOString();
|
|
37
|
+
try {
|
|
38
|
+
appendFileSync(LOG_FILE, `[INFO] ${ts} ${msg}\n`);
|
|
39
|
+
} catch { /* best-effort */ }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getSdkVersion() {
|
|
43
|
+
try {
|
|
44
|
+
const versions = JSON.parse(readFileSync(path.join(PLUGIN_ROOT, "versions.json"), "utf8"));
|
|
45
|
+
return versions.sdkVersion || "latest";
|
|
46
|
+
} catch {
|
|
47
|
+
return "latest";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function main() {
|
|
52
|
+
const sessionId = process.env.BABYSITTER_SESSION_ID
|
|
53
|
+
|| process.env.OPENCODE_SESSION_ID
|
|
54
|
+
|| "";
|
|
55
|
+
|
|
56
|
+
if (!sessionId) {
|
|
57
|
+
// No session -- pass through without intervention
|
|
58
|
+
process.stdout.write("{}\n");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Read stdin for tool context
|
|
63
|
+
let inputData = "";
|
|
64
|
+
try {
|
|
65
|
+
inputData = require("fs").readFileSync(0, "utf8");
|
|
66
|
+
} catch {
|
|
67
|
+
// No stdin available
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
blog(`tool-execute-before: session=${sessionId}`);
|
|
71
|
+
|
|
72
|
+
const hookInput = JSON.stringify({
|
|
73
|
+
session_id: sessionId,
|
|
74
|
+
cwd: process.cwd(),
|
|
75
|
+
harness: "opencode",
|
|
76
|
+
plugin_root: PLUGIN_ROOT,
|
|
77
|
+
tool_context: inputData ? JSON.parse(inputData) : {},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const sdkVersion = getSdkVersion();
|
|
81
|
+
const args = [
|
|
82
|
+
"hook:run",
|
|
83
|
+
"--hook-type", "pre-tool-use",
|
|
84
|
+
"--harness", "opencode",
|
|
85
|
+
"--plugin-root", PLUGIN_ROOT,
|
|
86
|
+
"--state-dir", STATE_DIR,
|
|
87
|
+
"--json",
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
const result = execSync(`babysitter ${args.join(" ")}`, {
|
|
92
|
+
input: hookInput,
|
|
93
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
94
|
+
timeout: 10000,
|
|
95
|
+
env: { ...process.env, BABYSITTER_STATE_DIR: STATE_DIR },
|
|
96
|
+
});
|
|
97
|
+
const output = result.toString("utf8").trim();
|
|
98
|
+
blog(`Hook result: ${output}`);
|
|
99
|
+
process.stdout.write((output || "{}") + "\n");
|
|
100
|
+
} catch {
|
|
101
|
+
// On failure, allow the tool execution to proceed
|
|
102
|
+
blog("Pre-tool-use hook failed -- allowing execution");
|
|
103
|
+
process.stdout.write("{}\n");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@a5c-ai/babysitter-opencode",
|
|
3
|
+
"version": "0.1.1-staging.0dc03363",
|
|
4
|
+
"description": "Babysitter orchestration plugin for OpenCode with SDK-managed process-library bootstrapping and in-turn iteration model",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "node test/integration.test.js",
|
|
7
|
+
"test:integration": "node test/integration.test.js",
|
|
8
|
+
"sync:commands": "node scripts/sync-command-docs.cjs",
|
|
9
|
+
"postinstall": "node bin/install.cjs",
|
|
10
|
+
"preuninstall": "node bin/uninstall.cjs",
|
|
11
|
+
"deploy": "npm publish --access public",
|
|
12
|
+
"deploy:staging": "npm publish --access public --tag staging"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"babysitter-opencode": "bin/cli.cjs"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin/",
|
|
19
|
+
"commands/",
|
|
20
|
+
"hooks/",
|
|
21
|
+
"scripts/",
|
|
22
|
+
"skills/",
|
|
23
|
+
"plugin.json",
|
|
24
|
+
"versions.json"
|
|
25
|
+
],
|
|
26
|
+
"keywords": [
|
|
27
|
+
"babysitter",
|
|
28
|
+
"opencode",
|
|
29
|
+
"orchestration",
|
|
30
|
+
"ai-agent",
|
|
31
|
+
"sdk-integration"
|
|
32
|
+
],
|
|
33
|
+
"author": "a5c.ai",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/a5c-ai/babysitter"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/a5c-ai/babysitter/tree/main/plugins/babysitter-opencode#readme",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@a5c-ai/babysitter-sdk": "0.0.184-staging.0dc03363"
|
|
45
|
+
}
|
|
46
|
+
}
|