@a5c-ai/babysitter-sdk 0.0.29 → 0.0.30

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.
Files changed (36) hide show
  1. package/dist/cli/commands/runIterate.d.ts +32 -0
  2. package/dist/cli/commands/runIterate.d.ts.map +1 -0
  3. package/dist/cli/commands/runIterate.js +143 -0
  4. package/dist/cli/main.d.ts.map +1 -1
  5. package/dist/cli/main.js +50 -485
  6. package/dist/cli/nodeTaskRunner.d.ts.map +1 -1
  7. package/dist/cli/nodeTaskRunner.js +39 -0
  8. package/dist/hooks/dispatcher.d.ts +10 -0
  9. package/dist/hooks/dispatcher.d.ts.map +1 -0
  10. package/dist/hooks/dispatcher.js +164 -0
  11. package/dist/hooks/index.d.ts +15 -0
  12. package/dist/hooks/index.d.ts.map +1 -0
  13. package/dist/hooks/index.js +19 -0
  14. package/dist/hooks/types.d.ts +154 -0
  15. package/dist/hooks/types.d.ts.map +1 -0
  16. package/dist/hooks/types.js +6 -0
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1 -0
  20. package/dist/runtime/createRun.d.ts.map +1 -1
  21. package/dist/runtime/createRun.js +18 -0
  22. package/dist/runtime/hooks/runtime.d.ts +31 -0
  23. package/dist/runtime/hooks/runtime.d.ts.map +1 -0
  24. package/dist/runtime/hooks/runtime.js +67 -0
  25. package/dist/runtime/intrinsics/hook.d.ts +26 -0
  26. package/dist/runtime/intrinsics/hook.d.ts.map +1 -0
  27. package/dist/runtime/intrinsics/hook.js +45 -0
  28. package/dist/runtime/orchestrateIteration.d.ts.map +1 -1
  29. package/dist/runtime/orchestrateIteration.js +42 -0
  30. package/dist/runtime/processContext.d.ts.map +1 -1
  31. package/dist/runtime/processContext.js +2 -0
  32. package/dist/runtime/types.d.ts +6 -0
  33. package/dist/runtime/types.d.ts.map +1 -1
  34. package/package.json +1 -1
  35. package/skills/babysitter/SKILL.md +0 -203
  36. package/skills/babysitter-score/SKILL.md +0 -35
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.runNodeTaskFromCli = runNodeTaskFromCli;
7
+ const path_1 = __importDefault(require("path"));
4
8
  const tasks_1 = require("../storage/tasks");
5
9
  const env_1 = require("../runner/env");
6
10
  const nodeRunner_1 = require("../runner/nodeRunner");
11
+ const runtime_1 = require("../runtime/hooks/runtime");
7
12
  async function runNodeTaskFromCli(options) {
8
13
  const task = options.task ?? (await loadTaskDefinition(options.runDir, options.effectId));
9
14
  const hydration = (0, env_1.hydrateCliNodeTaskEnv)(task, {
@@ -11,6 +16,22 @@ async function runNodeTaskFromCli(options) {
11
16
  envOverrides: options.envOverrides,
12
17
  baseEnv: options.baseEnv ?? process.env,
13
18
  });
19
+ const runId = extractRunIdFromPath(options.runDir);
20
+ const taskStartTime = Date.now();
21
+ // Compute project root for hook calls (parent of .a5c dir where plugins/ is located)
22
+ // runDir is like: /path/to/project/.a5c/runs/<runId>
23
+ // So we need 3 levels up: runs -> .a5c -> project
24
+ const projectRoot = path_1.default.dirname(path_1.default.dirname(path_1.default.dirname(options.runDir)));
25
+ // Call on-task-start hook
26
+ await (0, runtime_1.callRuntimeHook)("on-task-start", {
27
+ runId,
28
+ effectId: options.effectId,
29
+ taskId: extractInvocationKey(task) || options.effectId,
30
+ kind: "node",
31
+ }, {
32
+ cwd: projectRoot,
33
+ logger: options.logger,
34
+ });
14
35
  const result = await (0, nodeRunner_1.runNodeTask)({
15
36
  ...options,
16
37
  task,
@@ -26,6 +47,17 @@ async function runNodeTaskFromCli(options) {
26
47
  result,
27
48
  });
28
49
  }
50
+ // Call on-task-complete hook
51
+ await (0, runtime_1.callRuntimeHook)("on-task-complete", {
52
+ runId,
53
+ effectId: options.effectId,
54
+ taskId: extractInvocationKey(task) || options.effectId,
55
+ status: result.exitCode === 0 ? "ok" : "error",
56
+ duration: Date.now() - taskStartTime,
57
+ }, {
58
+ cwd: projectRoot,
59
+ logger: options.logger,
60
+ });
29
61
  return {
30
62
  ...result,
31
63
  hydratedKeys: hydration.hydratedKeys,
@@ -44,3 +76,10 @@ function extractInvocationKey(task) {
44
76
  const raw = task?.invocationKey;
45
77
  return typeof raw === "string" && raw.trim().length > 0 ? raw : undefined;
46
78
  }
79
+ function extractRunIdFromPath(runDir) {
80
+ // Extract runId from path like .a5c/runs/<runId> or absolute path ending with runId
81
+ const normalized = path_1.default.normalize(runDir);
82
+ const parts = normalized.split(path_1.default.sep);
83
+ // Get the last non-empty part
84
+ return parts[parts.length - 1] || "unknown";
85
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Hook Dispatcher
3
+ * Executes shell hooks from Node.js
4
+ */
5
+ import type { HookDispatcherOptions, HookResult } from "./types";
6
+ /**
7
+ * Call a hook by dispatching to the shell hook-dispatcher.sh
8
+ */
9
+ export declare function callHook(options: HookDispatcherOptions): Promise<HookResult>;
10
+ //# sourceMappingURL=dispatcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/hooks/dispatcher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EACV,qBAAqB,EACrB,UAAU,EAEX,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,UAAU,CAAC,CAkHrB"}
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ /**
3
+ * Hook Dispatcher
4
+ * Executes shell hooks from Node.js
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.callHook = callHook;
41
+ const node_child_process_1 = require("node:child_process");
42
+ const path = __importStar(require("node:path"));
43
+ /**
44
+ * Call a hook by dispatching to the shell hook-dispatcher.sh
45
+ */
46
+ async function callHook(options) {
47
+ const { hookType, payload, cwd = process.cwd(), timeout = 30000, throwOnFailure = false, } = options;
48
+ // Find the hook-dispatcher.sh script
49
+ // Assume it's in plugins/babysitter/hooks/hook-dispatcher.sh
50
+ const dispatcherPath = path.join(cwd, "plugins", "babysitter", "hooks", "hook-dispatcher.sh");
51
+ const payloadJson = JSON.stringify(payload);
52
+ const startTime = Date.now();
53
+ return new Promise((resolve, reject) => {
54
+ const child = (0, node_child_process_1.spawn)("bash", [dispatcherPath, hookType], {
55
+ cwd,
56
+ stdio: ["pipe", "pipe", "pipe"],
57
+ timeout,
58
+ });
59
+ let stdout = "";
60
+ let stderr = "";
61
+ let timedOut = false;
62
+ // Send payload via stdin
63
+ child.stdin.write(payloadJson);
64
+ child.stdin.end();
65
+ // Collect output
66
+ child.stdout.on("data", (data) => {
67
+ stdout += data.toString();
68
+ });
69
+ child.stderr.on("data", (data) => {
70
+ stderr += data.toString();
71
+ });
72
+ // Handle timeout
73
+ const timeoutHandle = setTimeout(() => {
74
+ timedOut = true;
75
+ child.kill("SIGTERM");
76
+ }, timeout);
77
+ child.on("error", (error) => {
78
+ clearTimeout(timeoutHandle);
79
+ const result = {
80
+ hookType,
81
+ success: false,
82
+ error: `Failed to spawn hook dispatcher: ${error.message}`,
83
+ executedHooks: [],
84
+ };
85
+ if (throwOnFailure) {
86
+ reject(new Error(result.error));
87
+ }
88
+ else {
89
+ resolve(result);
90
+ }
91
+ });
92
+ child.on("close", (exitCode) => {
93
+ clearTimeout(timeoutHandle);
94
+ const duration = Date.now() - startTime;
95
+ if (timedOut) {
96
+ const result = {
97
+ hookType,
98
+ success: false,
99
+ error: `Hook execution timed out after ${timeout}ms`,
100
+ executedHooks: [],
101
+ };
102
+ if (throwOnFailure) {
103
+ reject(new Error(result.error));
104
+ }
105
+ else {
106
+ resolve(result);
107
+ }
108
+ return;
109
+ }
110
+ // Parse execution results from stderr
111
+ const executedHooks = parseHookExecutionSummary(stderr);
112
+ const result = {
113
+ hookType,
114
+ success: exitCode === 0,
115
+ output: stdout ? tryParseJson(stdout) : undefined,
116
+ error: exitCode !== 0
117
+ ? `Hook dispatcher exited with code ${exitCode}`
118
+ : undefined,
119
+ executedHooks,
120
+ };
121
+ if (throwOnFailure && !result.success) {
122
+ reject(new Error(result.error ||
123
+ `Hook ${hookType} failed with exit code ${exitCode}`));
124
+ }
125
+ else {
126
+ resolve(result);
127
+ }
128
+ });
129
+ });
130
+ }
131
+ /**
132
+ * Parse hook execution summary from stderr output
133
+ * Looks for lines like: "plugin:logger.sh:success"
134
+ */
135
+ function parseHookExecutionSummary(stderr) {
136
+ const results = [];
137
+ const lines = stderr.split("\n");
138
+ for (const line of lines) {
139
+ // Look for summary lines: "location:hookname:status[:exitcode]"
140
+ const match = line.match(/^(per-repo|per-user|plugin):([^:]+):([^:]+)(?::(\d+))?$/);
141
+ if (match) {
142
+ const [, location, hookName, status, exitCodeStr] = match;
143
+ results.push({
144
+ hookPath: `unknown`, // We don't have full path in summary
145
+ hookName,
146
+ hookLocation: location,
147
+ status: status,
148
+ exitCode: exitCodeStr ? parseInt(exitCodeStr, 10) : undefined,
149
+ });
150
+ }
151
+ }
152
+ return results;
153
+ }
154
+ /**
155
+ * Try to parse JSON, return raw string if it fails
156
+ */
157
+ function tryParseJson(str) {
158
+ try {
159
+ return JSON.parse(str);
160
+ }
161
+ catch {
162
+ return str.trim();
163
+ }
164
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Hook System API
3
+ * Public interface for calling hooks from process files
4
+ */
5
+ export { callHook, } from "./dispatcher";
6
+ export type { HookType, HookResult, HookExecutionResult, HookPayload, HookDispatcherOptions, OnRunStartPayload, OnRunCompletePayload, OnRunFailPayload, OnTaskStartPayload, OnTaskCompletePayload, OnStepDispatchPayload, OnIterationStartPayload, OnIterationEndPayload, OnBreakpointPayload, PreCommitPayload, PreBranchPayload, PostPlanningPayload, OnScorePayload, } from "./types";
7
+ /**
8
+ * Helper function to create hook payloads with proper typing
9
+ */
10
+ export declare function createHookPayload<T extends {
11
+ hookType: string;
12
+ }>(payload: T): T & {
13
+ timestamp: string;
14
+ };
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,QAAQ,GACT,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,QAAQ,EACR,UAAU,EACV,mBAAmB,EACnB,WAAW,EACX,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,GACf,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EAC9D,OAAO,EAAE,CAAC,GACT,CAAC,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAK3B"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /**
3
+ * Hook System API
4
+ * Public interface for calling hooks from process files
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.callHook = void 0;
8
+ exports.createHookPayload = createHookPayload;
9
+ var dispatcher_1 = require("./dispatcher");
10
+ Object.defineProperty(exports, "callHook", { enumerable: true, get: function () { return dispatcher_1.callHook; } });
11
+ /**
12
+ * Helper function to create hook payloads with proper typing
13
+ */
14
+ function createHookPayload(payload) {
15
+ return {
16
+ ...payload,
17
+ timestamp: new Date().toISOString(),
18
+ };
19
+ }
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Hook System Types
3
+ * Type definitions for the generalized hook system
4
+ */
5
+ export type HookType = "on-run-start" | "on-run-complete" | "on-run-fail" | "on-task-start" | "on-task-complete" | "on-step-dispatch" | "on-iteration-start" | "on-iteration-end" | "on-breakpoint" | "pre-commit" | "pre-branch" | "post-planning" | "on-score" | string;
6
+ export interface HookResult {
7
+ hookType: HookType;
8
+ success: boolean;
9
+ output?: unknown;
10
+ error?: string;
11
+ executedHooks: HookExecutionResult[];
12
+ }
13
+ export interface HookExecutionResult {
14
+ hookPath: string;
15
+ hookName: string;
16
+ hookLocation: "per-repo" | "per-user" | "plugin";
17
+ status: "success" | "failed";
18
+ exitCode?: number;
19
+ error?: string;
20
+ }
21
+ export interface OnRunStartPayload {
22
+ hookType: "on-run-start";
23
+ runId: string;
24
+ processId: string;
25
+ entry: string;
26
+ inputs?: unknown;
27
+ timestamp: string;
28
+ }
29
+ export interface OnRunCompletePayload {
30
+ hookType: "on-run-complete";
31
+ runId: string;
32
+ status: "completed";
33
+ output?: unknown;
34
+ duration: number;
35
+ timestamp: string;
36
+ }
37
+ export interface OnRunFailPayload {
38
+ hookType: "on-run-fail";
39
+ runId: string;
40
+ status: "failed";
41
+ error: string;
42
+ duration: number;
43
+ timestamp: string;
44
+ }
45
+ export interface OnTaskStartPayload {
46
+ hookType: "on-task-start";
47
+ runId: string;
48
+ effectId: string;
49
+ taskId: string;
50
+ kind: string;
51
+ label?: string;
52
+ timestamp: string;
53
+ }
54
+ export interface OnTaskCompletePayload {
55
+ hookType: "on-task-complete";
56
+ runId: string;
57
+ effectId: string;
58
+ taskId: string;
59
+ status: "ok" | "error" | "timeout";
60
+ result?: unknown;
61
+ duration: number;
62
+ timestamp: string;
63
+ }
64
+ export interface OnStepDispatchPayload {
65
+ hookType: "on-step-dispatch";
66
+ runId: string;
67
+ stepId: string;
68
+ action: string;
69
+ timestamp: string;
70
+ }
71
+ export interface OnIterationStartPayload {
72
+ hookType: "on-iteration-start";
73
+ runId: string;
74
+ iteration: number;
75
+ timestamp: string;
76
+ }
77
+ export interface OnIterationEndPayload {
78
+ hookType: "on-iteration-end";
79
+ runId: string;
80
+ iteration: number;
81
+ status: "completed" | "failed" | "waiting";
82
+ timestamp: string;
83
+ }
84
+ export interface OnBreakpointPayload {
85
+ hookType: "on-breakpoint";
86
+ question: string;
87
+ title?: string;
88
+ runId?: string;
89
+ reason?: string;
90
+ context?: {
91
+ runId?: string;
92
+ files?: Array<{
93
+ path: string;
94
+ format: "markdown" | "code";
95
+ language?: string;
96
+ }>;
97
+ };
98
+ }
99
+ export interface PreCommitPayload {
100
+ hookType: "pre-commit";
101
+ runId: string;
102
+ files: string[];
103
+ message: string;
104
+ author?: string;
105
+ timestamp: string;
106
+ }
107
+ export interface PreBranchPayload {
108
+ hookType: "pre-branch";
109
+ runId: string;
110
+ branch: string;
111
+ base: string;
112
+ timestamp: string;
113
+ }
114
+ export interface PostPlanningPayload {
115
+ hookType: "post-planning";
116
+ runId: string;
117
+ planFile: string;
118
+ timestamp: string;
119
+ }
120
+ export interface OnScorePayload {
121
+ hookType: "on-score";
122
+ runId: string;
123
+ target: string;
124
+ score?: number;
125
+ metrics?: Record<string, unknown>;
126
+ timestamp: string;
127
+ }
128
+ export type HookPayload = OnRunStartPayload | OnRunCompletePayload | OnRunFailPayload | OnTaskStartPayload | OnTaskCompletePayload | OnStepDispatchPayload | OnIterationStartPayload | OnIterationEndPayload | OnBreakpointPayload | PreCommitPayload | PreBranchPayload | PostPlanningPayload | OnScorePayload | {
129
+ hookType: string;
130
+ [key: string]: unknown;
131
+ };
132
+ export interface HookDispatcherOptions {
133
+ /**
134
+ * Hook type to execute (e.g., "on-run-start", "pre-commit")
135
+ */
136
+ hookType: HookType;
137
+ /**
138
+ * Payload to pass to hooks (will be JSON.stringify'd and sent via stdin)
139
+ */
140
+ payload: HookPayload;
141
+ /**
142
+ * Working directory for hook execution (defaults to process.cwd())
143
+ */
144
+ cwd?: string;
145
+ /**
146
+ * Timeout in milliseconds for hook execution (defaults to 30000)
147
+ */
148
+ timeout?: number;
149
+ /**
150
+ * Whether to throw on hook execution failures (defaults to false)
151
+ */
152
+ throwOnFailure?: boolean;
153
+ }
154
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/hooks/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,QAAQ,GAEhB,cAAc,GACd,iBAAiB,GACjB,aAAa,GACb,eAAe,GACf,kBAAkB,GAClB,kBAAkB,GAClB,oBAAoB,GACpB,kBAAkB,GAElB,eAAe,GACf,YAAY,GACZ,YAAY,GACZ,eAAe,GACf,UAAU,GAEV,MAAM,CAAC;AAEX,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,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C;AAEjD,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,OAAO,EAAE,WAAW,CAAC;IAErB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Hook System Types
4
+ * Type definitions for the generalized hook system
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/index.d.ts CHANGED
@@ -7,4 +7,5 @@ export * from "./runner";
7
7
  export * from "./cli/nodeTaskRunner";
8
8
  export * from "./cli/main";
9
9
  export * from "./testing";
10
+ export * from "./hooks";
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -23,3 +23,4 @@ __exportStar(require("./runner"), exports);
23
23
  __exportStar(require("./cli/nodeTaskRunner"), exports);
24
24
  __exportStar(require("./cli/main"), exports);
25
25
  __exportStar(require("./testing"), exports);
26
+ __exportStar(require("./hooks"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"createRun.d.ts","sourceRoot":"","sources":["../../src/runtime/createRun.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEjE,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAkDnF"}
1
+ {"version":3,"file":"createRun.d.ts","sourceRoot":"","sources":["../../src/runtime/createRun.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAGjE,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAyEnF"}
@@ -10,6 +10,7 @@ const journal_1 = require("../storage/journal");
10
10
  const lock_1 = require("../storage/lock");
11
11
  const paths_1 = require("../storage/paths");
12
12
  const ulids_1 = require("../storage/ulids");
13
+ const runtime_1 = require("./hooks/runtime");
13
14
  async function createRun(options) {
14
15
  const runId = options.runId ?? (0, ulids_1.nextUlid)();
15
16
  validateRunId(runId);
@@ -54,6 +55,23 @@ async function createRun(options) {
54
55
  await (0, lock_1.releaseRunLock)(runDir);
55
56
  }
56
57
  }
58
+ // Call on-run-start hook
59
+ const entryString = metadata.entrypoint.exportName
60
+ ? `${metadata.entrypoint.importPath}#${metadata.entrypoint.exportName}`
61
+ : metadata.entrypoint.importPath;
62
+ // Call hook from project root (parent of .a5c dir) where plugins/ is located
63
+ // runDir is like: /path/to/project/.a5c/runs/<runId>
64
+ // So we need 3 levels up: runs -> .a5c -> project
65
+ const projectRoot = path_1.default.dirname(path_1.default.dirname(path_1.default.dirname(runDir)));
66
+ await (0, runtime_1.callRuntimeHook)("on-run-start", {
67
+ runId,
68
+ processId: metadata.processId,
69
+ entry: entryString,
70
+ inputs: options.inputs,
71
+ }, {
72
+ cwd: projectRoot,
73
+ logger: options.logger,
74
+ });
57
75
  return {
58
76
  runId,
59
77
  runDir,
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Runtime hook integration helpers
3
+ *
4
+ * Provides safe hook calling with error handling for SDK runtime.
5
+ * Hook failures are logged but do not break orchestration.
6
+ */
7
+ import type { HookType, HookResult } from "../../hooks/types";
8
+ export interface RuntimeHookOptions {
9
+ cwd: string;
10
+ timeout?: number;
11
+ logger?: (message: string) => void;
12
+ }
13
+ /**
14
+ * Safely call a hook from SDK runtime with error handling.
15
+ *
16
+ * Hook failures are logged but do not throw - orchestration continues.
17
+ *
18
+ * @param hookType - The type of hook to call
19
+ * @param payload - The hook payload
20
+ * @param options - Runtime options (cwd, timeout, logger)
21
+ * @returns HookResult with execution details
22
+ */
23
+ export declare function callRuntimeHook(hookType: HookType, payload: Record<string, unknown>, options: RuntimeHookOptions): Promise<HookResult>;
24
+ /**
25
+ * Create a hook payload with automatic timestamp.
26
+ */
27
+ export declare function createRuntimeHookPayload<T extends Record<string, unknown>>(hookType: HookType, data: T): T & {
28
+ hookType: HookType;
29
+ timestamp: string;
30
+ };
31
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/runtime/hooks/runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE9D,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,UAAU,CAAC,CA2CrB;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxE,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,CAAC,GACN,CAAC,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAM/C"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /**
3
+ * Runtime hook integration helpers
4
+ *
5
+ * Provides safe hook calling with error handling for SDK runtime.
6
+ * Hook failures are logged but do not break orchestration.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.callRuntimeHook = callRuntimeHook;
10
+ exports.createRuntimeHookPayload = createRuntimeHookPayload;
11
+ const dispatcher_1 = require("../../hooks/dispatcher");
12
+ /**
13
+ * Safely call a hook from SDK runtime with error handling.
14
+ *
15
+ * Hook failures are logged but do not throw - orchestration continues.
16
+ *
17
+ * @param hookType - The type of hook to call
18
+ * @param payload - The hook payload
19
+ * @param options - Runtime options (cwd, timeout, logger)
20
+ * @returns HookResult with execution details
21
+ */
22
+ async function callRuntimeHook(hookType, payload, options) {
23
+ const { cwd, timeout = 30000, logger } = options;
24
+ try {
25
+ // Ensure timestamp is present
26
+ const fullPayload = {
27
+ ...payload,
28
+ hookType,
29
+ timestamp: payload.timestamp || new Date().toISOString(),
30
+ };
31
+ const result = await (0, dispatcher_1.callHook)({
32
+ hookType,
33
+ payload: fullPayload,
34
+ cwd,
35
+ timeout,
36
+ });
37
+ // Log hook execution if logger provided
38
+ if (logger && result.executedHooks.length > 0) {
39
+ logger(`[hooks] Executed ${result.executedHooks.length} hook(s) for ${hookType}`);
40
+ }
41
+ return result;
42
+ }
43
+ catch (error) {
44
+ // Hook failures should not break orchestration
45
+ const errorMessage = error instanceof Error ? error.message : String(error);
46
+ if (logger) {
47
+ logger(`[hooks] Hook execution failed for ${hookType}: ${errorMessage}`);
48
+ }
49
+ // Return a failure result instead of throwing
50
+ return {
51
+ hookType,
52
+ success: false,
53
+ error: errorMessage,
54
+ executedHooks: [],
55
+ };
56
+ }
57
+ }
58
+ /**
59
+ * Create a hook payload with automatic timestamp.
60
+ */
61
+ function createRuntimeHookPayload(hookType, data) {
62
+ return {
63
+ ...data,
64
+ hookType,
65
+ timestamp: new Date().toISOString(),
66
+ };
67
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Hook Intrinsic
3
+ * Allows process files to call hooks directly
4
+ */
5
+ import type { InternalProcessContext } from "../processContext";
6
+ import type { HookResult } from "../../hooks/types";
7
+ export interface HookIntrinsicOptions {
8
+ /**
9
+ * Optional label for this hook invocation (for journal/logging)
10
+ */
11
+ label?: string;
12
+ /**
13
+ * Timeout in milliseconds (defaults to 30000)
14
+ */
15
+ timeout?: number;
16
+ /**
17
+ * Whether to throw on hook failures (defaults to false)
18
+ */
19
+ throwOnFailure?: boolean;
20
+ }
21
+ /**
22
+ * Run a hook from within a process
23
+ * This is exposed as ctx.hook() in process files
24
+ */
25
+ export declare function runHookIntrinsic(hookType: string, payload: Record<string, unknown>, context: InternalProcessContext, options?: HookIntrinsicOptions): Promise<HookResult>;
26
+ //# sourceMappingURL=hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../../src/runtime/intrinsics/hook.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,EAAE,sBAAsB,EAC/B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,UAAU,CAAC,CAwCrB"}