@a5c-ai/babysitter-sdk 0.0.30 → 0.0.32
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/runIterate.d.ts +2 -0
- package/dist/cli/commands/runIterate.d.ts.map +1 -1
- package/dist/cli/commands/runIterate.js +37 -0
- package/dist/hooks/dispatcher.d.ts +7 -0
- package/dist/hooks/dispatcher.d.ts.map +1 -1
- package/dist/hooks/dispatcher.js +38 -3
- package/dist/runtime/processContext.d.ts.map +1 -1
- package/dist/runtime/processContext.js +15 -1
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* The command does NOT loop - it handles exactly one iteration.
|
|
11
11
|
*/
|
|
12
|
+
import type { EffectAction } from "../../runtime/types";
|
|
12
13
|
export interface RunIterateOptions {
|
|
13
14
|
runDir: string;
|
|
14
15
|
iteration?: number;
|
|
@@ -22,6 +23,7 @@ export interface RunIterateResult {
|
|
|
22
23
|
reason?: string;
|
|
23
24
|
count?: number;
|
|
24
25
|
until?: number;
|
|
26
|
+
nextActions?: EffectAction[];
|
|
25
27
|
metadata?: {
|
|
26
28
|
runId: string;
|
|
27
29
|
processId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runIterate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/runIterate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAC;IACjE,MAAM,CAAC,EAAE,MA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,7 @@ exports.runIterate = runIterate;
|
|
|
48
48
|
const path = __importStar(require("path"));
|
|
49
49
|
const runFiles_1 = require("../../storage/runFiles");
|
|
50
50
|
const runtime_1 = require("../../runtime/hooks/runtime");
|
|
51
|
+
const orchestrateIteration_1 = require("../../runtime/orchestrateIteration");
|
|
51
52
|
async function runIterate(options) {
|
|
52
53
|
const { runDir, verbose } = options;
|
|
53
54
|
// Read run metadata
|
|
@@ -71,6 +72,42 @@ async function runIterate(options) {
|
|
|
71
72
|
cwd: projectRoot,
|
|
72
73
|
logger: verbose ? ((msg) => console.error(msg)) : undefined,
|
|
73
74
|
});
|
|
75
|
+
// If no hooks executed, fall back to running one real orchestration step (runtime iteration).
|
|
76
|
+
// This ensures `run:iterate` works even without a plugin install / hooks configuration.
|
|
77
|
+
if (!hookResult.executedHooks?.length) {
|
|
78
|
+
const iterationResult = await (0, orchestrateIteration_1.orchestrateIteration)({ runDir });
|
|
79
|
+
const status = iterationResult.status === "waiting"
|
|
80
|
+
? "waiting"
|
|
81
|
+
: iterationResult.status === "completed"
|
|
82
|
+
? "completed"
|
|
83
|
+
: "failed";
|
|
84
|
+
// Still call on-iteration-end (will be a no-op if no hooks are installed).
|
|
85
|
+
await (0, runtime_1.callRuntimeHook)("on-iteration-end", {
|
|
86
|
+
runId,
|
|
87
|
+
iteration,
|
|
88
|
+
action: status === "waiting" ? "waiting" : "none",
|
|
89
|
+
status,
|
|
90
|
+
reason: "no-hooks-fallback",
|
|
91
|
+
count: iterationResult.status === "waiting" ? iterationResult.nextActions.length : undefined,
|
|
92
|
+
timestamp: new Date().toISOString(),
|
|
93
|
+
}, {
|
|
94
|
+
cwd: projectRoot,
|
|
95
|
+
logger: verbose ? ((msg) => console.error(msg)) : undefined,
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
iteration,
|
|
99
|
+
status,
|
|
100
|
+
action: status === "waiting" ? "waiting" : "none",
|
|
101
|
+
reason: "no-hooks-fallback",
|
|
102
|
+
count: iterationResult.status === "waiting" ? iterationResult.nextActions.length : undefined,
|
|
103
|
+
nextActions: iterationResult.status === "waiting" ? iterationResult.nextActions : undefined,
|
|
104
|
+
metadata: {
|
|
105
|
+
runId,
|
|
106
|
+
processId: metadata.processId,
|
|
107
|
+
hookStatus: "none",
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
74
111
|
// Parse hook output
|
|
75
112
|
let hookDecision = {};
|
|
76
113
|
if (hookResult.output) {
|
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
* Executes shell hooks from Node.js
|
|
4
4
|
*/
|
|
5
5
|
import type { HookDispatcherOptions, HookResult } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* Find `plugins/babysitter/hooks/hook-dispatcher.sh` by walking up from cwd.
|
|
8
|
+
* This allows running from nested projects/fixtures inside a mono-repo.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function findHookDispatcherPath(startCwd: string): string | null;
|
|
6
13
|
/**
|
|
7
14
|
* Call a hook by dispatching to the shell hook-dispatcher.sh
|
|
8
15
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/hooks/dispatcher.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/hooks/dispatcher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EACV,qBAAqB,EACrB,UAAU,EAEX,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAiBtE;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,UAAU,CAAC,CAoHrB"}
|
package/dist/hooks/dispatcher.js
CHANGED
|
@@ -37,17 +37,52 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
37
37
|
};
|
|
38
38
|
})();
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.findHookDispatcherPath = findHookDispatcherPath;
|
|
40
41
|
exports.callHook = callHook;
|
|
41
42
|
const node_child_process_1 = require("node:child_process");
|
|
43
|
+
const node_fs_1 = require("node:fs");
|
|
42
44
|
const path = __importStar(require("node:path"));
|
|
45
|
+
/**
|
|
46
|
+
* Find `plugins/babysitter/hooks/hook-dispatcher.sh` by walking up from cwd.
|
|
47
|
+
* This allows running from nested projects/fixtures inside a mono-repo.
|
|
48
|
+
*
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
function findHookDispatcherPath(startCwd) {
|
|
52
|
+
const claudePluginRoot = process.env.CLAUDE_PLUGIN_ROOT;
|
|
53
|
+
if (claudePluginRoot) {
|
|
54
|
+
const candidate = path.join(path.resolve(claudePluginRoot), "hooks", "hook-dispatcher.sh");
|
|
55
|
+
if ((0, node_fs_1.existsSync)(candidate))
|
|
56
|
+
return candidate;
|
|
57
|
+
}
|
|
58
|
+
let current = path.resolve(startCwd);
|
|
59
|
+
// Guard against infinite loops: stop once we stop making progress.
|
|
60
|
+
for (let i = 0; i < 50; i++) {
|
|
61
|
+
const candidate = path.join(current, "plugins", "babysitter", "hooks", "hook-dispatcher.sh");
|
|
62
|
+
if ((0, node_fs_1.existsSync)(candidate))
|
|
63
|
+
return candidate;
|
|
64
|
+
const parent = path.dirname(current);
|
|
65
|
+
if (parent === current)
|
|
66
|
+
break;
|
|
67
|
+
current = parent;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
43
71
|
/**
|
|
44
72
|
* Call a hook by dispatching to the shell hook-dispatcher.sh
|
|
45
73
|
*/
|
|
46
74
|
async function callHook(options) {
|
|
47
75
|
const { hookType, payload, cwd = process.cwd(), timeout = 30000, throwOnFailure = false, } = options;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
76
|
+
const dispatcherPath = findHookDispatcherPath(cwd);
|
|
77
|
+
if (!dispatcherPath) {
|
|
78
|
+
return {
|
|
79
|
+
hookType,
|
|
80
|
+
success: false,
|
|
81
|
+
error: `Hook dispatcher not found. Expected plugins/babysitter/hooks/hook-dispatcher.sh ` +
|
|
82
|
+
`in ${cwd} or any parent directory.`,
|
|
83
|
+
executedHooks: [],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
51
86
|
const payloadJson = JSON.stringify(payload);
|
|
52
87
|
const startTime = Date.now();
|
|
53
88
|
return new Promise((resolve, reject) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processContext.d.ts","sourceRoot":"","sources":["../../src/runtime/processContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAM3E,OAAO,EAAE,cAAc,EAAmB,MAAM,SAAS,CAAC;AAG1D,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,oBAAoB,EAAE,KAAK,CAAC;IAC3E,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,sBAAuB,SAAQ,oBAAoB;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,IAAI,CAAC;CACjB;AAID,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,cAAc,CAAC;IACxB,eAAe,EAAE,sBAAsB,CAAC;CACzC;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,kBAAkB,GAAG,0BAA0B,
|
|
1
|
+
{"version":3,"file":"processContext.d.ts","sourceRoot":"","sources":["../../src/runtime/processContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAM3E,OAAO,EAAE,cAAc,EAAmB,MAAM,SAAS,CAAC;AAG1D,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,oBAAoB,EAAE,KAAK,CAAC;IAC3E,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,sBAAuB,SAAQ,oBAAoB;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,IAAI,CAAC;CACjB;AAID,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,cAAc,CAAC;IACxB,eAAe,EAAE,sBAAsB,CAAC;CACzC;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,kBAAkB,GAAG,0BAA0B,CA4CzF;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,QAAQ,EAAE,sBAAsB,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE5G;AAED,wBAAgB,uBAAuB,IAAI,sBAAsB,GAAG,SAAS,CAE5E;AAED,wBAAgB,qBAAqB,IAAI,sBAAsB,CAM9D"}
|
|
@@ -14,8 +14,10 @@ const parallel_1 = require("./intrinsics/parallel");
|
|
|
14
14
|
const exceptions_1 = require("./exceptions");
|
|
15
15
|
const contextStorage = new async_hooks_1.AsyncLocalStorage();
|
|
16
16
|
function createProcessContext(init) {
|
|
17
|
+
const safeLogger = typeof init.logger === "function" ? init.logger : undefined;
|
|
17
18
|
const internal = {
|
|
18
19
|
...init,
|
|
20
|
+
logger: safeLogger,
|
|
19
21
|
now: init.now ?? (() => new Date()),
|
|
20
22
|
};
|
|
21
23
|
const parallelHelpers = {
|
|
@@ -35,7 +37,19 @@ function createProcessContext(init) {
|
|
|
35
37
|
orchestratorTask: (payload, options) => (0, orchestratorTask_1.runOrchestratorTaskIntrinsic)(payload, internal, options),
|
|
36
38
|
hook: (hookType, payload, options) => (0, hook_1.runHookIntrinsic)(hookType, payload, internal, options),
|
|
37
39
|
parallel: parallelHelpers,
|
|
38
|
-
log
|
|
40
|
+
// Always provide a callable logger to processes so `ctx.log(...)` never throws.
|
|
41
|
+
// If no logger was configured, this becomes a no-op.
|
|
42
|
+
log: (...args) => {
|
|
43
|
+
const logger = internal.logger;
|
|
44
|
+
if (typeof logger !== "function")
|
|
45
|
+
return;
|
|
46
|
+
try {
|
|
47
|
+
logger(...args);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// Never let logging break an orchestration.
|
|
51
|
+
}
|
|
52
|
+
},
|
|
39
53
|
};
|
|
40
54
|
return {
|
|
41
55
|
context: processContext,
|