@a5c-ai/babysitter-sdk 0.0.169 → 0.0.170-staging.00aac85c
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/dist/cli/commands/configure.d.ts +124 -0
- package/dist/cli/commands/configure.d.ts.map +1 -0
- package/dist/cli/commands/configure.js +514 -0
- package/dist/cli/commands/health.d.ts +89 -0
- package/dist/cli/commands/health.d.ts.map +1 -0
- package/dist/cli/commands/health.js +579 -0
- package/dist/cli/commands/hookLog.d.ts +15 -0
- package/dist/cli/commands/hookLog.d.ts.map +1 -0
- package/dist/cli/commands/hookLog.js +286 -0
- package/dist/cli/commands/hookRun.d.ts +20 -0
- package/dist/cli/commands/hookRun.d.ts.map +1 -0
- package/dist/cli/commands/hookRun.js +544 -0
- package/dist/cli/commands/runExecuteTasks.d.ts +42 -0
- package/dist/cli/commands/runExecuteTasks.d.ts.map +1 -0
- package/dist/cli/commands/runExecuteTasks.js +377 -0
- package/dist/cli/commands/runIterate.d.ts +5 -1
- package/dist/cli/commands/runIterate.d.ts.map +1 -1
- package/dist/cli/commands/runIterate.js +75 -6
- package/dist/cli/commands/session.d.ts +97 -0
- package/dist/cli/commands/session.d.ts.map +1 -0
- package/dist/cli/commands/session.js +922 -0
- package/dist/cli/commands/skill.d.ts +87 -0
- package/dist/cli/commands/skill.d.ts.map +1 -0
- package/dist/cli/commands/skill.js +869 -0
- package/dist/cli/completionProof.d.ts +4 -0
- package/dist/cli/completionProof.d.ts.map +1 -0
- package/dist/cli/{completionSecret.js → completionProof.js} +7 -7
- package/dist/cli/main.d.ts +14 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +649 -16
- package/dist/config/defaults.d.ts +165 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +281 -0
- package/dist/config/index.d.ts +25 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +35 -0
- package/dist/hooks/dispatcher.d.ts.map +1 -1
- package/dist/hooks/dispatcher.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/runtime/constants.d.ts +1 -1
- package/dist/runtime/constants.d.ts.map +1 -1
- package/dist/runtime/createRun.d.ts.map +1 -1
- package/dist/runtime/createRun.js +7 -3
- package/dist/runtime/exceptions.d.ts +186 -3
- package/dist/runtime/exceptions.d.ts.map +1 -1
- package/dist/runtime/exceptions.js +416 -15
- package/dist/runtime/types.d.ts +1 -0
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/session/index.d.ts +9 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +30 -0
- package/dist/session/parse.d.ts +45 -0
- package/dist/session/parse.d.ts.map +1 -0
- package/dist/session/parse.js +159 -0
- package/dist/session/types.d.ts +194 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +45 -0
- package/dist/session/write.d.ts +50 -0
- package/dist/session/write.d.ts.map +1 -0
- package/dist/session/write.js +196 -0
- package/dist/storage/createRunDir.d.ts.map +1 -1
- package/dist/storage/createRunDir.js +1 -0
- package/dist/storage/paths.d.ts +5 -1
- package/dist/storage/paths.d.ts.map +1 -1
- package/dist/storage/paths.js +6 -1
- package/dist/storage/types.d.ts +3 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/tasks/kinds/index.d.ts.map +1 -1
- package/dist/tasks/kinds/index.js +6 -1
- package/dist/testing/runHarness.d.ts.map +1 -1
- package/dist/testing/runHarness.js +5 -1
- package/package.json +1 -2
- package/dist/cli/completionSecret.d.ts +0 -4
- package/dist/cli/completionSecret.d.ts.map +0 -1
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* hook:log CLI command.
|
|
4
|
+
*
|
|
5
|
+
* Reads a hook payload from stdin, extracts the relevant fields for the
|
|
6
|
+
* given hook type, formats a structured log line, and appends it to the
|
|
7
|
+
* specified log file. This consolidates the field-extraction logic that
|
|
8
|
+
* was previously duplicated across 13 logger.sh shell scripts.
|
|
9
|
+
*/
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
22
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
23
|
+
}) : function(o, v) {
|
|
24
|
+
o["default"] = v;
|
|
25
|
+
});
|
|
26
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
27
|
+
var ownKeys = function(o) {
|
|
28
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
29
|
+
var ar = [];
|
|
30
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
31
|
+
return ar;
|
|
32
|
+
};
|
|
33
|
+
return ownKeys(o);
|
|
34
|
+
};
|
|
35
|
+
return function (mod) {
|
|
36
|
+
if (mod && mod.__esModule) return mod;
|
|
37
|
+
var result = {};
|
|
38
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
39
|
+
__setModuleDefault(result, mod);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.handleHookLog = handleHookLog;
|
|
45
|
+
const node_fs_1 = require("node:fs");
|
|
46
|
+
const path = __importStar(require("node:path"));
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// Event label mapping (matches the label used in the original logger.sh)
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
const HOOK_EVENT_LABELS = {
|
|
51
|
+
"on-run-start": "RUN_START",
|
|
52
|
+
"on-run-complete": "RUN_COMPLETE",
|
|
53
|
+
"on-run-fail": "RUN_FAIL",
|
|
54
|
+
"on-task-start": "TASK_START",
|
|
55
|
+
"on-task-complete": "TASK_COMPLETE",
|
|
56
|
+
"on-step-dispatch": "STEP_DISPATCH",
|
|
57
|
+
"on-iteration-start": "ITERATION_START",
|
|
58
|
+
"on-iteration-end": "ITERATION_END",
|
|
59
|
+
"on-breakpoint": "BREAKPOINT",
|
|
60
|
+
"pre-commit": "PRE_COMMIT",
|
|
61
|
+
"pre-branch": "PRE_BRANCH",
|
|
62
|
+
"post-planning": "POST_PLANNING",
|
|
63
|
+
"on-score": "SCORE",
|
|
64
|
+
};
|
|
65
|
+
const KNOWN_HOOK_TYPES = new Set(Object.keys(HOOK_EVENT_LABELS));
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
// Payload helpers
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
/** Safely read a string field from a parsed JSON object. */
|
|
70
|
+
function str(payload, key, fallback = "unknown") {
|
|
71
|
+
const value = payload[key];
|
|
72
|
+
if (typeof value === "string")
|
|
73
|
+
return value;
|
|
74
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
75
|
+
return String(value);
|
|
76
|
+
return fallback;
|
|
77
|
+
}
|
|
78
|
+
/** Safely read a nested string field (e.g. ".context.runId"). */
|
|
79
|
+
function nestedStr(payload, outerKey, innerKey, fallback = "unknown") {
|
|
80
|
+
const outer = payload[outerKey];
|
|
81
|
+
if (outer && typeof outer === "object" && !Array.isArray(outer)) {
|
|
82
|
+
const inner = outer[innerKey];
|
|
83
|
+
if (typeof inner === "string")
|
|
84
|
+
return inner;
|
|
85
|
+
}
|
|
86
|
+
return fallback;
|
|
87
|
+
}
|
|
88
|
+
/** Safely read the length of an array field. */
|
|
89
|
+
function arrayLength(payload, key) {
|
|
90
|
+
const value = payload[key];
|
|
91
|
+
if (Array.isArray(value))
|
|
92
|
+
return String(value.length);
|
|
93
|
+
return "unknown";
|
|
94
|
+
}
|
|
95
|
+
const FIELD_EXTRACTORS = {
|
|
96
|
+
"on-run-start": (p) => [
|
|
97
|
+
["runId", str(p, "runId")],
|
|
98
|
+
["processId", str(p, "processId")],
|
|
99
|
+
["entry", str(p, "entry")],
|
|
100
|
+
],
|
|
101
|
+
"on-run-complete": (p) => [
|
|
102
|
+
["runId", str(p, "runId")],
|
|
103
|
+
["status", str(p, "status")],
|
|
104
|
+
["duration", str(p, "duration")],
|
|
105
|
+
],
|
|
106
|
+
"on-run-fail": (p) => [
|
|
107
|
+
["runId", str(p, "runId")],
|
|
108
|
+
["error", str(p, "error")],
|
|
109
|
+
["duration", str(p, "duration")],
|
|
110
|
+
],
|
|
111
|
+
"on-task-start": (p) => [
|
|
112
|
+
["runId", str(p, "runId")],
|
|
113
|
+
["effectId", str(p, "effectId")],
|
|
114
|
+
["taskId", str(p, "taskId")],
|
|
115
|
+
["kind", str(p, "kind")],
|
|
116
|
+
],
|
|
117
|
+
"on-task-complete": (p) => [
|
|
118
|
+
["runId", str(p, "runId")],
|
|
119
|
+
["effectId", str(p, "effectId")],
|
|
120
|
+
["taskId", str(p, "taskId")],
|
|
121
|
+
["status", str(p, "status")],
|
|
122
|
+
["duration", str(p, "duration")],
|
|
123
|
+
],
|
|
124
|
+
"on-step-dispatch": (p) => [
|
|
125
|
+
["runId", str(p, "runId")],
|
|
126
|
+
["stepId", str(p, "stepId")],
|
|
127
|
+
["action", str(p, "action")],
|
|
128
|
+
],
|
|
129
|
+
"on-iteration-start": (p) => [
|
|
130
|
+
["runId", str(p, "runId")],
|
|
131
|
+
["iteration", str(p, "iteration")],
|
|
132
|
+
],
|
|
133
|
+
"on-iteration-end": (p) => [
|
|
134
|
+
["runId", str(p, "runId")],
|
|
135
|
+
["iteration", str(p, "iteration")],
|
|
136
|
+
["status", str(p, "status")],
|
|
137
|
+
],
|
|
138
|
+
"on-breakpoint": (p) => [
|
|
139
|
+
// The original logger.sh uses: .runId // .context.runId // "unknown"
|
|
140
|
+
["runId", typeof p.runId === "string" ? p.runId : nestedStr(p, "context", "runId")],
|
|
141
|
+
["question", str(p, "question", "N/A")],
|
|
142
|
+
["reason", str(p, "reason", "N/A")],
|
|
143
|
+
],
|
|
144
|
+
"pre-commit": (p) => [
|
|
145
|
+
["runId", str(p, "runId")],
|
|
146
|
+
["files", arrayLength(p, "files")],
|
|
147
|
+
["message", str(p, "message")],
|
|
148
|
+
],
|
|
149
|
+
"pre-branch": (p) => [
|
|
150
|
+
["runId", str(p, "runId")],
|
|
151
|
+
["branch", str(p, "branch")],
|
|
152
|
+
["base", str(p, "base")],
|
|
153
|
+
],
|
|
154
|
+
"post-planning": (p) => [
|
|
155
|
+
["runId", str(p, "runId")],
|
|
156
|
+
["planFile", str(p, "planFile")],
|
|
157
|
+
],
|
|
158
|
+
"on-score": (p) => [
|
|
159
|
+
["runId", str(p, "runId")],
|
|
160
|
+
["target", str(p, "target")],
|
|
161
|
+
["score", str(p, "score")],
|
|
162
|
+
],
|
|
163
|
+
};
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
// Log line formatting
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
function formatLogLine(hookType, eventLabel, fields) {
|
|
168
|
+
const timestamp = new Date().toISOString();
|
|
169
|
+
const kvPairs = fields.map(([k, v]) => `${k}=${v}`).join(" ");
|
|
170
|
+
return `[${timestamp}] [${eventLabel}] hook=${hookType} ${kvPairs}`;
|
|
171
|
+
}
|
|
172
|
+
// ---------------------------------------------------------------------------
|
|
173
|
+
// Stdin reader (reusable)
|
|
174
|
+
// ---------------------------------------------------------------------------
|
|
175
|
+
function readStdinUtf8() {
|
|
176
|
+
return new Promise((resolve, reject) => {
|
|
177
|
+
const chunks = [];
|
|
178
|
+
process.stdin.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
|
|
179
|
+
process.stdin.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
|
|
180
|
+
process.stdin.on("error", reject);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
// ---------------------------------------------------------------------------
|
|
184
|
+
// Main handler
|
|
185
|
+
// ---------------------------------------------------------------------------
|
|
186
|
+
async function handleHookLog(args) {
|
|
187
|
+
const { hookType, logFile, json } = args;
|
|
188
|
+
// Validate --hook-type
|
|
189
|
+
if (!hookType) {
|
|
190
|
+
const error = { error: "MISSING_HOOK_TYPE", message: "--hook-type is required" };
|
|
191
|
+
if (json) {
|
|
192
|
+
console.error(JSON.stringify(error));
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
console.error("Error: --hook-type is required for hook:log");
|
|
196
|
+
}
|
|
197
|
+
return 1;
|
|
198
|
+
}
|
|
199
|
+
// Validate --log-file
|
|
200
|
+
if (!logFile) {
|
|
201
|
+
const error = { error: "MISSING_LOG_FILE", message: "--log-file is required" };
|
|
202
|
+
if (json) {
|
|
203
|
+
console.error(JSON.stringify(error));
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
console.error("Error: --log-file is required for hook:log");
|
|
207
|
+
}
|
|
208
|
+
return 1;
|
|
209
|
+
}
|
|
210
|
+
// Read payload from stdin
|
|
211
|
+
let rawPayload;
|
|
212
|
+
try {
|
|
213
|
+
rawPayload = await readStdinUtf8();
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
217
|
+
const error = { error: "STDIN_READ_ERROR", message: msg };
|
|
218
|
+
if (json) {
|
|
219
|
+
console.error(JSON.stringify(error));
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
console.error(`Error: Failed to read stdin: ${msg}`);
|
|
223
|
+
}
|
|
224
|
+
return 1;
|
|
225
|
+
}
|
|
226
|
+
// Parse JSON payload
|
|
227
|
+
let payload;
|
|
228
|
+
try {
|
|
229
|
+
const parsed = JSON.parse(rawPayload.trim() || "{}");
|
|
230
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
231
|
+
throw new Error("Payload must be a JSON object");
|
|
232
|
+
}
|
|
233
|
+
payload = parsed;
|
|
234
|
+
}
|
|
235
|
+
catch (e) {
|
|
236
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
237
|
+
const error = { error: "INVALID_PAYLOAD", message: msg };
|
|
238
|
+
if (json) {
|
|
239
|
+
console.error(JSON.stringify(error));
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
console.error(`Error: Failed to parse JSON payload: ${msg}`);
|
|
243
|
+
}
|
|
244
|
+
return 1;
|
|
245
|
+
}
|
|
246
|
+
// Determine event label and field extractor
|
|
247
|
+
const isKnown = KNOWN_HOOK_TYPES.has(hookType);
|
|
248
|
+
const eventLabel = isKnown
|
|
249
|
+
? HOOK_EVENT_LABELS[hookType]
|
|
250
|
+
: hookType.toUpperCase().replace(/-/g, "_");
|
|
251
|
+
const fields = isKnown
|
|
252
|
+
? FIELD_EXTRACTORS[hookType](payload)
|
|
253
|
+
: [["runId", str(payload, "runId")]];
|
|
254
|
+
// Format log line
|
|
255
|
+
const logLine = formatLogLine(hookType, eventLabel, fields);
|
|
256
|
+
// Ensure log directory exists and append
|
|
257
|
+
try {
|
|
258
|
+
const logDir = path.dirname(path.resolve(logFile));
|
|
259
|
+
await node_fs_1.promises.mkdir(logDir, { recursive: true });
|
|
260
|
+
await node_fs_1.promises.appendFile(path.resolve(logFile), logLine + "\n", "utf8");
|
|
261
|
+
}
|
|
262
|
+
catch (e) {
|
|
263
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
264
|
+
const error = { error: "LOG_WRITE_ERROR", message: msg };
|
|
265
|
+
if (json) {
|
|
266
|
+
console.error(JSON.stringify(error));
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
console.error(`Error: Failed to write to log file: ${msg}`);
|
|
270
|
+
}
|
|
271
|
+
return 1;
|
|
272
|
+
}
|
|
273
|
+
// Output confirmation
|
|
274
|
+
if (json) {
|
|
275
|
+
console.log(JSON.stringify({
|
|
276
|
+
hookType,
|
|
277
|
+
eventLabel,
|
|
278
|
+
logFile: path.resolve(logFile),
|
|
279
|
+
logLine,
|
|
280
|
+
}));
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
console.log(logLine);
|
|
284
|
+
}
|
|
285
|
+
return 0;
|
|
286
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hook:run CLI command.
|
|
3
|
+
*
|
|
4
|
+
* Replaces heavy bash hook scripts with a single TypeScript command.
|
|
5
|
+
* Dispatches to the appropriate handler based on --hook-type:
|
|
6
|
+
* - "stop" → handleHookRunStop (replaces babysitter-stop-hook.sh)
|
|
7
|
+
* - "session-start" → handleHookRunSessionStart (replaces babysitter-session-start-hook.sh)
|
|
8
|
+
*/
|
|
9
|
+
export interface HookRunCommandArgs {
|
|
10
|
+
hookType: string;
|
|
11
|
+
/** Which host tool is invoking the hook. Defaults to "claude-code". */
|
|
12
|
+
harness: string;
|
|
13
|
+
pluginRoot?: string;
|
|
14
|
+
stateDir?: string;
|
|
15
|
+
runsDir?: string;
|
|
16
|
+
json: boolean;
|
|
17
|
+
verbose?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function handleHookRun(args: HookRunCommandArgs): Promise<number>;
|
|
20
|
+
//# sourceMappingURL=hookRun.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hookRun.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/hookRun.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA+EH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAggBD,wBAAsB,aAAa,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAiD7E"}
|