@h-rig/core 0.0.6-alpha.18 → 0.0.6-alpha.180

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 (105) hide show
  1. package/dist/src/agent-role-registry.d.ts +4 -0
  2. package/dist/src/agent-role-registry.js +27 -0
  3. package/dist/src/authority-paths.d.ts +15 -0
  4. package/dist/src/authority-paths.js +80 -0
  5. package/dist/src/baked-secrets.d.ts +3 -0
  6. package/dist/src/baked-secrets.js +63 -0
  7. package/dist/src/build-time-config.d.ts +12 -0
  8. package/dist/src/build-time-config.js +25 -0
  9. package/dist/src/build-time-config.macro.d.ts +1 -0
  10. package/dist/src/capability-loaders.d.ts +51 -0
  11. package/dist/src/capability-loaders.js +870 -0
  12. package/dist/src/capability.d.ts +79 -0
  13. package/dist/src/capability.js +63 -0
  14. package/dist/src/checkout-root.d.ts +1 -0
  15. package/dist/src/checkout-root.js +30 -0
  16. package/dist/src/config-env.d.ts +4 -0
  17. package/dist/src/config-env.js +23 -0
  18. package/dist/src/config.d.ts +3 -0
  19. package/dist/src/config.js +44 -0
  20. package/dist/src/declarative-config.d.ts +14 -0
  21. package/dist/src/declarative-config.js +85 -0
  22. package/dist/src/default-kernel.d.ts +1 -0
  23. package/dist/src/default-kernel.js +12 -0
  24. package/dist/src/define-config.d.ts +20 -0
  25. package/dist/src/define-config.js +28 -15
  26. package/dist/src/define-plugin.d.ts +13 -0
  27. package/dist/src/define-plugin.js +4 -43
  28. package/dist/src/embedded-plugins.d.ts +59 -0
  29. package/dist/src/embedded-plugins.js +22 -0
  30. package/dist/src/exec.d.ts +13 -0
  31. package/dist/src/exec.js +101 -0
  32. package/dist/src/harness-paths.d.ts +9 -0
  33. package/dist/src/harness-paths.js +126 -0
  34. package/dist/src/hook-materializer.d.ts +21 -0
  35. package/dist/src/hook-materializer.js +152 -0
  36. package/dist/src/hook-protocol.d.ts +2 -0
  37. package/dist/src/hook-protocol.js +432 -0
  38. package/dist/src/hook-runner.d.ts +48 -0
  39. package/dist/src/hook-runner.js +868 -0
  40. package/dist/src/hook-runtime.d.ts +52 -0
  41. package/dist/src/hook-runtime.js +432 -0
  42. package/dist/src/index.d.ts +8 -0
  43. package/dist/src/index.js +210 -2499
  44. package/dist/src/json-files.d.ts +9 -0
  45. package/dist/src/json-files.js +124 -0
  46. package/dist/src/kernel-boot.d.ts +2 -0
  47. package/dist/src/kernel-boot.js +10 -0
  48. package/dist/src/kernel-entrypoint.d.ts +22 -0
  49. package/dist/src/kernel-entrypoint.js +660 -0
  50. package/dist/src/kernel-plugin-abi.d.ts +1 -0
  51. package/dist/src/kernel-plugin-abi.js +1 -0
  52. package/dist/src/kernel-resolver.d.ts +2 -0
  53. package/dist/src/kernel-resolver.js +6 -0
  54. package/dist/src/layout.d.ts +10 -0
  55. package/dist/src/layout.js +138 -0
  56. package/dist/src/load-config.d.ts +2 -0
  57. package/dist/src/load-config.js +535 -30
  58. package/dist/src/placement.d.ts +58 -0
  59. package/dist/src/placement.js +53 -0
  60. package/dist/src/plugin-host-context.d.ts +65 -0
  61. package/dist/src/plugin-host-context.js +1171 -0
  62. package/dist/src/plugin-host-registries.d.ts +31 -0
  63. package/dist/src/plugin-host-registries.js +79 -0
  64. package/dist/src/plugin-host.d.ts +77 -0
  65. package/dist/src/plugin-host.js +127 -63
  66. package/dist/src/plugin-runtime.d.ts +173 -0
  67. package/dist/src/project-plugins.d.ts +63 -0
  68. package/dist/src/project-plugins.js +905 -0
  69. package/dist/src/remote-config.d.ts +125 -0
  70. package/dist/src/remote-config.js +85 -0
  71. package/dist/src/root-resolver.d.ts +5 -0
  72. package/dist/src/root-resolver.js +68 -0
  73. package/dist/src/run-provisioning.d.ts +37 -0
  74. package/dist/src/run-provisioning.js +35 -0
  75. package/dist/src/runtime-context.d.ts +20 -0
  76. package/dist/src/runtime-context.js +257 -0
  77. package/dist/src/runtime-events.d.ts +44 -0
  78. package/dist/src/runtime-events.js +208 -0
  79. package/dist/src/runtime-overlay.d.ts +11 -0
  80. package/dist/src/runtime-overlay.js +69 -0
  81. package/dist/src/runtime-paths.d.ts +21 -0
  82. package/dist/src/runtime-paths.js +181 -0
  83. package/dist/src/runtime-provisioning-env.d.ts +5 -0
  84. package/dist/src/runtime-provisioning-env.js +217 -0
  85. package/dist/src/runtime-runner-context.d.ts +12 -0
  86. package/dist/src/runtime-runner-context.js +1 -0
  87. package/dist/src/safe-identifiers.d.ts +44 -0
  88. package/dist/src/safe-identifiers.js +96 -0
  89. package/dist/src/scope-rules.d.ts +4 -0
  90. package/dist/src/scope-rules.js +21 -0
  91. package/dist/src/server-paths.d.ts +22 -0
  92. package/dist/src/server-paths.js +219 -0
  93. package/dist/src/setup-version.d.ts +3 -0
  94. package/dist/src/setup-version.js +14 -0
  95. package/dist/src/task-record-reader.d.ts +3 -0
  96. package/dist/src/task-record-reader.js +9 -0
  97. package/dist/src/validator-registry.d.ts +27 -0
  98. package/dist/src/validator-registry.js +64 -0
  99. package/package.json +162 -10
  100. package/dist/src/engineReadModelReducer.js +0 -1780
  101. package/dist/src/rig-init-builder.js +0 -57
  102. package/dist/src/rigSelectors.js +0 -293
  103. package/dist/src/taskGraph.js +0 -64
  104. package/dist/src/taskGraphCodes.js +0 -26
  105. package/dist/src/taskGraphLayout.js +0 -374
@@ -0,0 +1,52 @@
1
+ import { type HookContext as PluginHookContext, type HookEvent, type HookImplementation, type HookResult } from "@rig/contracts";
2
+ export type HookInput = {
3
+ tool_name?: string;
4
+ tool_input?: Record<string, unknown>;
5
+ command?: string;
6
+ };
7
+ export type ParsedHookInput = {
8
+ input: HookInput;
9
+ valid: boolean;
10
+ hadPayload: boolean;
11
+ };
12
+ export interface TypedHookOptions {
13
+ readonly event: HookEvent;
14
+ readonly projectRoot?: string;
15
+ readonly taskId?: string;
16
+ }
17
+ export declare const BAKED_PROJECT_ROOT: string;
18
+ export declare const BAKED_TASK_ID: string;
19
+ export declare const BAKED_STATE_DIR: string;
20
+ export declare const BAKED_BUN_PATH: string;
21
+ export declare const BAKED_TASK_CONFIG: string;
22
+ export declare const BAKED_POLICY_CONTENT: string;
23
+ export declare const BAKED_TASK_SCOPES: string;
24
+ export declare function resolveProjectRoot(): string;
25
+ export declare function resolveTaskIdForHook(_projectRoot: string): string;
26
+ export declare function resolveTaskConfig(_projectRoot: string, _taskId: string): Promise<{
27
+ scope?: string[];
28
+ validation?: string[];
29
+ role?: string;
30
+ }>;
31
+ export declare function resolveTaskScopes(projectRoot: string, taskId: string): Promise<string[]>;
32
+ export declare function resolvePolicyContent(projectRoot: string): string;
33
+ export declare function readHookInput(): Promise<ParsedHookInput>;
34
+ export declare function extractToolFilePaths(toolName: string, input: Record<string, unknown>): string[];
35
+ export declare function isTestFilePath(path: string): boolean;
36
+ export declare function buildPluginHookContext(parsed: ParsedHookInput, opts: {
37
+ event: HookEvent;
38
+ projectRoot: string;
39
+ taskId: string;
40
+ }): PluginHookContext;
41
+ export declare function hookResultToProtocol(result: HookResult): {
42
+ exitCode: 0 | 1;
43
+ stdout: string;
44
+ };
45
+ export declare function escapeRegExp(value: string): string;
46
+ export declare function block(hookName: string, message: string, projectRoot: string): never;
47
+ export declare function resolveBunCli(): string;
48
+ export declare function resolveBunCliInvocation(): {
49
+ command: string;
50
+ env: Record<string, string>;
51
+ };
52
+ export declare function runTypedHook(fn: HookImplementation, opts: TypedHookOptions): Promise<never>;
@@ -0,0 +1,432 @@
1
+ // @bun
2
+ // packages/core/src/hook-runtime.ts
3
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, realpathSync, writeSync } from "fs";
4
+ import { resolve } from "path";
5
+ import { RIG_DEFINITION_DIRNAME, RIG_STATE_DIRNAME } from "@rig/contracts";
6
+ function bunRuntime() {
7
+ const runtime = globalThis;
8
+ return runtime.Bun;
9
+ }
10
+ function normalizeBuildConfig(value) {
11
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
12
+ return {};
13
+ }
14
+ return Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string"));
15
+ }
16
+ function readBuildConfigForCoreHooks() {
17
+ if (typeof __RIG_BUILD_CONFIG__ !== "undefined") {
18
+ return normalizeBuildConfig(__RIG_BUILD_CONFIG__);
19
+ }
20
+ const raw = process.env.RIG_BUILD_CONFIG_JSON?.trim();
21
+ if (!raw) {
22
+ return {};
23
+ }
24
+ try {
25
+ return normalizeBuildConfig(JSON.parse(raw));
26
+ } catch {
27
+ return {};
28
+ }
29
+ }
30
+ var BUILD_CONFIG = readBuildConfigForCoreHooks();
31
+ var BAKED_PROJECT_ROOT = BUILD_CONFIG.AGENT_PROJECT_ROOT ?? "";
32
+ var BAKED_TASK_ID = BUILD_CONFIG.AGENT_TASK_ID ?? "";
33
+ var BAKED_STATE_DIR = BUILD_CONFIG.AGENT_STATE_DIR ?? "";
34
+ var BAKED_BUN_PATH = BUILD_CONFIG.AGENT_BUN_PATH ?? "";
35
+ var BAKED_TASK_CONFIG = BUILD_CONFIG.AGENT_TASK_CONFIG ?? "";
36
+ var BAKED_POLICY_CONTENT = BUILD_CONFIG.AGENT_POLICY_CONTENT ?? "";
37
+ var BAKED_TASK_SCOPES = BUILD_CONFIG.AGENT_TASK_SCOPES ?? "";
38
+ var RUNTIME_CONTEXT_ENV = "RIG_RUNTIME_CONTEXT_FILE";
39
+ function isPlainObject(value) {
40
+ return typeof value === "object" && value !== null && !Array.isArray(value);
41
+ }
42
+ function isStringArray(value) {
43
+ return Array.isArray(value) && value.every((item) => typeof item === "string");
44
+ }
45
+ function loadHookContextFromEnv() {
46
+ const contextFile = process.env[RUNTIME_CONTEXT_ENV]?.trim();
47
+ let filePath = contextFile || "";
48
+ if (!filePath) {
49
+ let current = resolve(process.cwd());
50
+ while (true) {
51
+ const candidate = resolve(current, "runtime-context.json");
52
+ if (existsSync(candidate)) {
53
+ filePath = candidate;
54
+ break;
55
+ }
56
+ const parent = resolve(current, "..");
57
+ if (parent === current) {
58
+ break;
59
+ }
60
+ current = parent;
61
+ }
62
+ }
63
+ if (!filePath || !existsSync(filePath)) {
64
+ return null;
65
+ }
66
+ try {
67
+ const raw = JSON.parse(readFileSync(filePath, "utf-8"));
68
+ if (!isPlainObject(raw)) {
69
+ return null;
70
+ }
71
+ const taskId = typeof raw.taskId === "string" ? raw.taskId : "";
72
+ const role = typeof raw.role === "string" ? raw.role : "";
73
+ const scopes = isStringArray(raw.scopes) ? raw.scopes : [];
74
+ const validation = isStringArray(raw.validation) ? raw.validation : [];
75
+ const hostProjectRoot = typeof raw.hostProjectRoot === "string" ? raw.hostProjectRoot : undefined;
76
+ const monorepoMainRoot = typeof raw.monorepoMainRoot === "string" ? raw.monorepoMainRoot : undefined;
77
+ const stateDir = typeof raw.stateDir === "string" ? raw.stateDir : "";
78
+ const policyFile = typeof raw.policyFile === "string" ? raw.policyFile : "";
79
+ if (!taskId || !stateDir) {
80
+ return null;
81
+ }
82
+ return {
83
+ taskId,
84
+ role,
85
+ scopes,
86
+ validation,
87
+ hostProjectRoot,
88
+ monorepoMainRoot,
89
+ stateDir,
90
+ policyFile
91
+ };
92
+ } catch {
93
+ return null;
94
+ }
95
+ }
96
+ var cachedContext;
97
+ function getContext() {
98
+ if (cachedContext !== undefined) {
99
+ return cachedContext;
100
+ }
101
+ cachedContext = loadHookContextFromEnv();
102
+ return cachedContext;
103
+ }
104
+ function resolveProjectRoot() {
105
+ const ctx = getContext();
106
+ if (ctx?.hostProjectRoot)
107
+ return ctx.hostProjectRoot;
108
+ if (BAKED_PROJECT_ROOT) {
109
+ return BAKED_PROJECT_ROOT;
110
+ }
111
+ if (process.env.PROJECT_RIG_ROOT) {
112
+ return process.env.PROJECT_RIG_ROOT;
113
+ }
114
+ const candidates = [process.cwd(), resolve(import.meta.dirname, "../..")];
115
+ for (const candidate of candidates) {
116
+ if (existsSync(resolve(candidate, RIG_DEFINITION_DIRNAME)) || existsSync(resolve(candidate, RIG_STATE_DIRNAME))) {
117
+ return candidate;
118
+ }
119
+ }
120
+ return resolve(import.meta.dirname, "../..");
121
+ }
122
+ function resolveTaskIdForHook(_projectRoot) {
123
+ const ctx = getContext();
124
+ if (ctx)
125
+ return ctx.taskId;
126
+ if (BAKED_TASK_ID) {
127
+ return BAKED_TASK_ID;
128
+ }
129
+ const fromEnv = (process.env.RIG_TASK_ID || "").trim();
130
+ if (fromEnv) {
131
+ return fromEnv;
132
+ }
133
+ const runtimeId = (process.env.RIG_TASK_RUNTIME_ID || "").trim();
134
+ if (runtimeId.startsWith("task-") && runtimeId.length > "task-".length) {
135
+ return runtimeId.slice("task-".length);
136
+ }
137
+ return "";
138
+ }
139
+ function isTaskConfigEntry(value) {
140
+ if (!isPlainObject(value)) {
141
+ return false;
142
+ }
143
+ if ("role" in value && value.role !== undefined && typeof value.role !== "string") {
144
+ return false;
145
+ }
146
+ if ("scope" in value && value.scope !== undefined && !isStringArray(value.scope)) {
147
+ return false;
148
+ }
149
+ if ("validation" in value && value.validation !== undefined && !isStringArray(value.validation)) {
150
+ return false;
151
+ }
152
+ return true;
153
+ }
154
+ async function resolveTaskConfig(_projectRoot, _taskId) {
155
+ const ctx = getContext();
156
+ if (ctx) {
157
+ return {
158
+ scope: ctx.scopes,
159
+ validation: ctx.validation,
160
+ role: ctx.role
161
+ };
162
+ }
163
+ if (BAKED_TASK_CONFIG) {
164
+ try {
165
+ const parsed = JSON.parse(BAKED_TASK_CONFIG);
166
+ if (isTaskConfigEntry(parsed) && Object.keys(parsed).length > 0) {
167
+ return parsed;
168
+ }
169
+ } catch {}
170
+ }
171
+ return {};
172
+ }
173
+ async function resolveTaskScopes(projectRoot, taskId) {
174
+ const ctx = getContext();
175
+ if (ctx && ctx.scopes.length > 0)
176
+ return ctx.scopes;
177
+ if (BAKED_TASK_SCOPES) {
178
+ try {
179
+ const parsed = JSON.parse(BAKED_TASK_SCOPES);
180
+ if (Array.isArray(parsed) && parsed.length > 0 && parsed.every((item) => typeof item === "string")) {
181
+ return parsed;
182
+ }
183
+ } catch {}
184
+ }
185
+ return (await resolveTaskConfig(projectRoot, taskId)).scope || [];
186
+ }
187
+ function resolvePolicyContent(projectRoot) {
188
+ const ctx = getContext();
189
+ if (ctx?.policyFile && existsSync(ctx.policyFile)) {
190
+ return readFileSync(ctx.policyFile, "utf-8");
191
+ }
192
+ if (BAKED_POLICY_CONTENT)
193
+ return BAKED_POLICY_CONTENT;
194
+ const policyPath = resolve(projectRoot, "rig/policy/policy.json");
195
+ if (existsSync(policyPath))
196
+ return readFileSync(policyPath, "utf-8");
197
+ return "{}";
198
+ }
199
+ async function readHookInput() {
200
+ let text = "";
201
+ const inputFile = process.env.RIG_HOOK_INPUT_FILE?.trim();
202
+ if (inputFile) {
203
+ text = readFileSync(inputFile, "utf-8");
204
+ } else {
205
+ try {
206
+ text = readFileSync("/dev/stdin", "utf-8");
207
+ } catch {
208
+ text = readFileSync(0, "utf-8");
209
+ }
210
+ }
211
+ if (!text.trim()) {
212
+ return { input: {}, valid: true, hadPayload: false };
213
+ }
214
+ try {
215
+ return {
216
+ input: JSON.parse(text),
217
+ valid: true,
218
+ hadPayload: true
219
+ };
220
+ } catch {
221
+ return { input: {}, valid: false, hadPayload: true };
222
+ }
223
+ }
224
+ function extractToolFilePaths(toolName, input) {
225
+ const paths = [];
226
+ const add = (value) => {
227
+ if (typeof value === "string" && value.trim()) {
228
+ paths.push(value.trim());
229
+ }
230
+ };
231
+ if (toolName === "Read" || toolName === "Write" || toolName === "Edit" || toolName === "MultiEdit") {
232
+ add(input.file_path);
233
+ add(input.path);
234
+ } else if (toolName === "Glob") {
235
+ add(input.path);
236
+ } else if (toolName === "Grep") {
237
+ add(input.path);
238
+ } else {
239
+ add(input.file_path);
240
+ add(input.path);
241
+ }
242
+ return paths;
243
+ }
244
+ function isTestFilePath(path) {
245
+ return /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(path) || /\/(__tests__|tests|test)\//.test(path);
246
+ }
247
+ function buildPluginHookContext(parsed, opts) {
248
+ const toolName = parsed.input.tool_name;
249
+ const toolInput = parsed.input.tool_input ?? {};
250
+ return {
251
+ event: opts.event,
252
+ toolName,
253
+ toolInput,
254
+ filePaths: toolName ? extractToolFilePaths(toolName, toolInput) : [],
255
+ projectRoot: opts.projectRoot,
256
+ taskId: opts.taskId
257
+ };
258
+ }
259
+ function hookResultToProtocol(result) {
260
+ if (result.decision === "block") {
261
+ const lines = [`BLOCKED: ${result.reason ?? "blocked by plugin hook"}`];
262
+ if (result.systemMessage) {
263
+ lines.push(result.systemMessage);
264
+ }
265
+ return { exitCode: 1, stdout: `${lines.join(`
266
+ `)}
267
+ ` };
268
+ }
269
+ return {
270
+ exitCode: 0,
271
+ stdout: result.systemMessage ? `${result.systemMessage}
272
+ ` : ""
273
+ };
274
+ }
275
+ function escapeRegExp(value) {
276
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
277
+ }
278
+ function block(hookName, message, projectRoot) {
279
+ const runtimeWorkspace = process.env.RIG_TASK_WORKSPACE?.trim();
280
+ const stateDir = BAKED_STATE_DIR || (runtimeWorkspace ? resolve(runtimeWorkspace, ".rig", "state") : resolve(projectRoot, ".rig", "state"));
281
+ mkdirSync(stateDir, { recursive: true });
282
+ const tripLog = resolve(stateDir, "hook_trips.log");
283
+ let count = 0;
284
+ if (existsSync(tripLog)) {
285
+ const content = readFileSync(tripLog, "utf-8");
286
+ count = (content.match(new RegExp(`^${escapeRegExp(hookName)}\\s`, "gm")) || []).length;
287
+ }
288
+ appendFileSync(tripLog, `${hookName} ${new Date().toISOString()}
289
+ `, "utf-8");
290
+ count += 1;
291
+ const lines = [
292
+ `BLOCKED: ${message}`,
293
+ "",
294
+ "Re-read CLAUDE.md safety rules before your next action."
295
+ ];
296
+ if (count >= 3) {
297
+ lines.push("");
298
+ lines.push(`REPEATED VIOLATION (${count}x ${hookName}).`);
299
+ lines.push("STOP. Read the FULL CLAUDE.md from top to bottom.");
300
+ lines.push("If stuck, record the failed approach in the task-state failure log and request help.");
301
+ }
302
+ writeSync(1, `${lines.join(`
303
+ `)}
304
+ `);
305
+ process.exit(1);
306
+ }
307
+ function normalizeExecutablePath(candidate) {
308
+ if (!candidate) {
309
+ return "";
310
+ }
311
+ const normalized = resolve(candidate);
312
+ if (!existsSync(normalized)) {
313
+ return "";
314
+ }
315
+ try {
316
+ return realpathSync(normalized);
317
+ } catch {
318
+ return normalized;
319
+ }
320
+ }
321
+ function looksLikeRuntimeGateway(candidate) {
322
+ const normalized = resolve(candidate).replace(/\\/g, "/");
323
+ return normalized.includes("/.rig/bin/") || normalized.endsWith("/rig-shell") || normalized.endsWith("/rig-agent");
324
+ }
325
+ function resolveBunBinaryPath() {
326
+ const explicit = normalizeExecutablePath(process.env.RIG_BUN_PATH?.trim());
327
+ if (explicit) {
328
+ return explicit;
329
+ }
330
+ const bunWhich = bunRuntime()?.which?.("bun");
331
+ const pathBun = normalizeExecutablePath(bunWhich?.trim());
332
+ if (pathBun && !looksLikeRuntimeGateway(pathBun)) {
333
+ return pathBun;
334
+ }
335
+ const home = process.env.HOME?.trim();
336
+ const fallbackCandidates = [
337
+ home ? resolve(home, ".bun/bin/bun") : "",
338
+ "/opt/homebrew/bin/bun",
339
+ "/usr/local/bin/bun",
340
+ "/usr/bin/bun"
341
+ ];
342
+ for (const candidate of fallbackCandidates) {
343
+ const normalized = normalizeExecutablePath(candidate);
344
+ if (normalized) {
345
+ return normalized;
346
+ }
347
+ }
348
+ const execPath = normalizeExecutablePath(process.execPath?.trim());
349
+ if (execPath && !looksLikeRuntimeGateway(execPath)) {
350
+ return execPath;
351
+ }
352
+ throw new Error("bun not found in PATH");
353
+ }
354
+ function resolveBunCli() {
355
+ return resolveBunCliInvocation().command;
356
+ }
357
+ function resolveBunCliInvocation() {
358
+ if (BAKED_BUN_PATH) {
359
+ return {
360
+ command: BAKED_BUN_PATH,
361
+ env: {}
362
+ };
363
+ }
364
+ if (process.env.RIG_BUN_PATH?.trim()) {
365
+ return {
366
+ command: process.env.RIG_BUN_PATH.trim(),
367
+ env: {}
368
+ };
369
+ }
370
+ try {
371
+ const systemBun = resolveBunBinaryPath();
372
+ return {
373
+ command: systemBun,
374
+ env: {}
375
+ };
376
+ } catch {}
377
+ if (process.execPath?.trim()) {
378
+ return {
379
+ command: process.execPath,
380
+ env: { BUN_BE_BUN: "1" }
381
+ };
382
+ }
383
+ return { command: "bun", env: {} };
384
+ }
385
+ async function runTypedHook(fn, opts) {
386
+ const parsed = await readHookInput();
387
+ const projectRoot = opts.projectRoot ?? resolveProjectRoot();
388
+ const taskId = opts.taskId ?? resolveTaskIdForHook(projectRoot);
389
+ const ctx = buildPluginHookContext(parsed, {
390
+ event: opts.event,
391
+ projectRoot,
392
+ taskId
393
+ });
394
+ let result;
395
+ try {
396
+ result = await fn(ctx);
397
+ } catch (err) {
398
+ const message = err instanceof Error ? err.message : String(err);
399
+ writeSync(2, `[rig hook] typed hook threw: ${message}
400
+ `);
401
+ process.exit(0);
402
+ }
403
+ const { exitCode, stdout } = hookResultToProtocol(result);
404
+ if (stdout) {
405
+ writeSync(1, stdout);
406
+ }
407
+ process.exit(exitCode);
408
+ }
409
+ export {
410
+ runTypedHook,
411
+ resolveTaskScopes,
412
+ resolveTaskIdForHook,
413
+ resolveTaskConfig,
414
+ resolveProjectRoot,
415
+ resolvePolicyContent,
416
+ resolveBunCliInvocation,
417
+ resolveBunCli,
418
+ readHookInput,
419
+ isTestFilePath,
420
+ hookResultToProtocol,
421
+ extractToolFilePaths,
422
+ escapeRegExp,
423
+ buildPluginHookContext,
424
+ block,
425
+ BAKED_TASK_SCOPES,
426
+ BAKED_TASK_ID,
427
+ BAKED_TASK_CONFIG,
428
+ BAKED_STATE_DIR,
429
+ BAKED_PROJECT_ROOT,
430
+ BAKED_POLICY_CONTENT,
431
+ BAKED_BUN_PATH
432
+ };
@@ -0,0 +1,8 @@
1
+ export declare const RIG_CORE_PACKAGE = "@rig/core";
2
+ export { definePlugin } from "./define-plugin";
3
+ export { defineConfig } from "./define-config";
4
+ export { createPluginHost } from "./plugin-host";
5
+ export type { PluginHost } from "./plugin-host";
6
+ export { defineCapability, defineServiceCapability, CapabilityProviderMissingError } from "./capability";
7
+ export type { Capability, CapabilityImpl, CapabilityProvideOptions, ServiceCapability, ServiceCapabilityImpl, } from "./capability";
8
+ export type { RigPlugin, PluginContributes, Validator, TaskSource, FeatureCapability, Panel, BlockerClassifierEntry, CliCommand, Hook, StageEntry, SessionExtensionEntry, SessionExtensionInstall, SeedEntrypoint, SeedEntrypointContext, SeedEntrypointRunResult, TaskSourceFactoryContext, RuntimeCliContext, ValidatorContext, ValidatorResult, } from "./plugin-runtime";