@h-rig/core 0.0.6-alpha.18 → 0.0.6-alpha.181
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/src/agent-role-registry.d.ts +4 -0
- package/dist/src/agent-role-registry.js +27 -0
- package/dist/src/authority-paths.d.ts +15 -0
- package/dist/src/authority-paths.js +80 -0
- package/dist/src/baked-secrets.d.ts +3 -0
- package/dist/src/baked-secrets.js +63 -0
- package/dist/src/build-time-config.d.ts +12 -0
- package/dist/src/build-time-config.js +25 -0
- package/dist/src/build-time-config.macro.d.ts +1 -0
- package/dist/src/capability-loaders.d.ts +51 -0
- package/dist/src/capability-loaders.js +870 -0
- package/dist/src/capability.d.ts +79 -0
- package/dist/src/capability.js +63 -0
- package/dist/src/checkout-root.d.ts +1 -0
- package/dist/src/checkout-root.js +30 -0
- package/dist/src/config-env.d.ts +4 -0
- package/dist/src/config-env.js +23 -0
- package/dist/src/config.d.ts +3 -0
- package/dist/src/config.js +44 -0
- package/dist/src/declarative-config.d.ts +14 -0
- package/dist/src/declarative-config.js +85 -0
- package/dist/src/default-kernel.d.ts +1 -0
- package/dist/src/default-kernel.js +12 -0
- package/dist/src/define-config.d.ts +20 -0
- package/dist/src/define-config.js +28 -15
- package/dist/src/define-plugin.d.ts +13 -0
- package/dist/src/define-plugin.js +4 -43
- package/dist/src/embedded-plugins.d.ts +59 -0
- package/dist/src/embedded-plugins.js +22 -0
- package/dist/src/exec.d.ts +13 -0
- package/dist/src/exec.js +101 -0
- package/dist/src/harness-paths.d.ts +9 -0
- package/dist/src/harness-paths.js +126 -0
- package/dist/src/hook-materializer.d.ts +21 -0
- package/dist/src/hook-materializer.js +152 -0
- package/dist/src/hook-protocol.d.ts +2 -0
- package/dist/src/hook-protocol.js +432 -0
- package/dist/src/hook-runner.d.ts +48 -0
- package/dist/src/hook-runner.js +868 -0
- package/dist/src/hook-runtime.d.ts +52 -0
- package/dist/src/hook-runtime.js +432 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.js +210 -2499
- package/dist/src/json-files.d.ts +9 -0
- package/dist/src/json-files.js +124 -0
- package/dist/src/kernel-boot.d.ts +2 -0
- package/dist/src/kernel-boot.js +10 -0
- package/dist/src/kernel-entrypoint.d.ts +22 -0
- package/dist/src/kernel-entrypoint.js +660 -0
- package/dist/src/kernel-plugin-abi.d.ts +1 -0
- package/dist/src/kernel-plugin-abi.js +1 -0
- package/dist/src/kernel-resolver.d.ts +2 -0
- package/dist/src/kernel-resolver.js +6 -0
- package/dist/src/layout.d.ts +10 -0
- package/dist/src/layout.js +138 -0
- package/dist/src/load-config.d.ts +2 -0
- package/dist/src/load-config.js +535 -30
- package/dist/src/placement.d.ts +58 -0
- package/dist/src/placement.js +53 -0
- package/dist/src/plugin-host-context.d.ts +65 -0
- package/dist/src/plugin-host-context.js +1171 -0
- package/dist/src/plugin-host-registries.d.ts +31 -0
- package/dist/src/plugin-host-registries.js +79 -0
- package/dist/src/plugin-host.d.ts +77 -0
- package/dist/src/plugin-host.js +127 -63
- package/dist/src/plugin-runtime.d.ts +173 -0
- package/dist/src/project-plugins.d.ts +63 -0
- package/dist/src/project-plugins.js +905 -0
- package/dist/src/remote-config.d.ts +125 -0
- package/dist/src/remote-config.js +85 -0
- package/dist/src/root-resolver.d.ts +5 -0
- package/dist/src/root-resolver.js +68 -0
- package/dist/src/run-provisioning.d.ts +37 -0
- package/dist/src/run-provisioning.js +35 -0
- package/dist/src/runtime-context.d.ts +20 -0
- package/dist/src/runtime-context.js +257 -0
- package/dist/src/runtime-events.d.ts +44 -0
- package/dist/src/runtime-events.js +208 -0
- package/dist/src/runtime-overlay.d.ts +11 -0
- package/dist/src/runtime-overlay.js +69 -0
- package/dist/src/runtime-paths.d.ts +21 -0
- package/dist/src/runtime-paths.js +181 -0
- package/dist/src/runtime-provisioning-env.d.ts +5 -0
- package/dist/src/runtime-provisioning-env.js +217 -0
- package/dist/src/runtime-runner-context.d.ts +12 -0
- package/dist/src/runtime-runner-context.js +1 -0
- package/dist/src/safe-identifiers.d.ts +44 -0
- package/dist/src/safe-identifiers.js +96 -0
- package/dist/src/scope-rules.d.ts +4 -0
- package/dist/src/scope-rules.js +21 -0
- package/dist/src/server-paths.d.ts +22 -0
- package/dist/src/server-paths.js +219 -0
- package/dist/src/setup-version.d.ts +3 -0
- package/dist/src/setup-version.js +14 -0
- package/dist/src/task-record-reader.d.ts +3 -0
- package/dist/src/task-record-reader.js +9 -0
- package/dist/src/validator-registry.d.ts +27 -0
- package/dist/src/validator-registry.js +64 -0
- package/package.json +162 -10
- package/dist/src/engineReadModelReducer.js +0 -1780
- package/dist/src/rig-init-builder.js +0 -57
- package/dist/src/rigSelectors.js +0 -293
- package/dist/src/taskGraph.js +0 -64
- package/dist/src/taskGraphCodes.js +0 -26
- package/dist/src/taskGraphLayout.js +0 -374
package/dist/src/exec.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/core/src/exec.ts
|
|
3
|
+
import { existsSync, readFileSync } from "fs";
|
|
4
|
+
function runCapture(command, cwd, env) {
|
|
5
|
+
const result = Bun.spawnSync(command, {
|
|
6
|
+
cwd,
|
|
7
|
+
env: env ? { ...process.env, ...env } : process.env,
|
|
8
|
+
stdout: "pipe",
|
|
9
|
+
stderr: "pipe"
|
|
10
|
+
});
|
|
11
|
+
return {
|
|
12
|
+
exitCode: result.exitCode,
|
|
13
|
+
stdout: result.stdout.toString(),
|
|
14
|
+
stderr: result.stderr.toString()
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
var DEFAULT_VALIDATION_TIMEOUT_MS = 30000;
|
|
18
|
+
function getValidationTimeoutMs() {
|
|
19
|
+
const envVal = process.env.RIG_VALIDATION_TIMEOUT_MS;
|
|
20
|
+
if (envVal) {
|
|
21
|
+
const parsed = Number(envVal);
|
|
22
|
+
if (Number.isFinite(parsed) && parsed > 0) {
|
|
23
|
+
return parsed;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return DEFAULT_VALIDATION_TIMEOUT_MS;
|
|
27
|
+
}
|
|
28
|
+
async function runCaptureAsync(command, cwd, env, timeoutMs) {
|
|
29
|
+
const timeout = timeoutMs ?? getValidationTimeoutMs();
|
|
30
|
+
const proc = Bun.spawn(command, {
|
|
31
|
+
cwd,
|
|
32
|
+
env: env ? { ...process.env, ...env } : process.env,
|
|
33
|
+
stdout: "pipe",
|
|
34
|
+
stderr: "pipe"
|
|
35
|
+
});
|
|
36
|
+
const stdoutPromise = new Response(proc.stdout).text();
|
|
37
|
+
const stderrPromise = new Response(proc.stderr).text();
|
|
38
|
+
const timeoutResult = Symbol("timeout");
|
|
39
|
+
const exitOrTimeout = await Promise.race([
|
|
40
|
+
proc.exited,
|
|
41
|
+
Bun.sleep(timeout).then(() => timeoutResult)
|
|
42
|
+
]);
|
|
43
|
+
if (exitOrTimeout === timeoutResult) {
|
|
44
|
+
proc.kill("SIGKILL");
|
|
45
|
+
const [stdout2, stderr2] = await Promise.all([
|
|
46
|
+
Promise.race([stdoutPromise, Bun.sleep(2000).then(() => "")]),
|
|
47
|
+
Promise.race([stderrPromise, Bun.sleep(2000).then(() => "")])
|
|
48
|
+
]);
|
|
49
|
+
return {
|
|
50
|
+
exitCode: 124,
|
|
51
|
+
stdout: stdout2,
|
|
52
|
+
stderr: `${stderr2}
|
|
53
|
+
[TIMEOUT] Process killed after ${timeout}ms`
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const [stdout, stderr] = await Promise.all([stdoutPromise, stderrPromise]);
|
|
57
|
+
const exitCode = exitOrTimeout;
|
|
58
|
+
return { exitCode, stdout, stderr };
|
|
59
|
+
}
|
|
60
|
+
function runInherit(command, cwd, env) {
|
|
61
|
+
const proc = Bun.spawnSync(command, {
|
|
62
|
+
cwd,
|
|
63
|
+
env: env ? { ...process.env, ...env } : process.env,
|
|
64
|
+
stdin: "inherit",
|
|
65
|
+
stdout: "inherit",
|
|
66
|
+
stderr: "inherit"
|
|
67
|
+
});
|
|
68
|
+
return proc.exitCode;
|
|
69
|
+
}
|
|
70
|
+
function readJsonFile(path, fallback) {
|
|
71
|
+
if (!existsSync(path)) {
|
|
72
|
+
return fallback;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
76
|
+
} catch {
|
|
77
|
+
return fallback;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function nowIso() {
|
|
81
|
+
return new Date().toISOString();
|
|
82
|
+
}
|
|
83
|
+
function unique(values) {
|
|
84
|
+
return [...new Set(values)];
|
|
85
|
+
}
|
|
86
|
+
function fileLines(path) {
|
|
87
|
+
if (!existsSync(path)) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
return readFileSync(path, "utf-8").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
unique,
|
|
94
|
+
runInherit,
|
|
95
|
+
runCaptureAsync,
|
|
96
|
+
runCapture,
|
|
97
|
+
readJsonFile,
|
|
98
|
+
nowIso,
|
|
99
|
+
getValidationTimeoutMs,
|
|
100
|
+
fileLines
|
|
101
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/core/src/harness-paths.ts
|
|
3
|
+
import { resolve as resolve3 } from "path";
|
|
4
|
+
|
|
5
|
+
// packages/core/src/layout.ts
|
|
6
|
+
import { resolve as resolve2 } from "path";
|
|
7
|
+
import {
|
|
8
|
+
RIG_DEFINITION_DIRNAME,
|
|
9
|
+
RIG_STATE_DIRNAME
|
|
10
|
+
} from "@rig/contracts";
|
|
11
|
+
|
|
12
|
+
// packages/core/src/checkout-root.ts
|
|
13
|
+
import { dirname, resolve } from "path";
|
|
14
|
+
import { existsSync } from "fs";
|
|
15
|
+
function findNearestGitCheckoutRoot(startDir) {
|
|
16
|
+
let current = resolve(startDir);
|
|
17
|
+
for (;; ) {
|
|
18
|
+
if (existsSync(resolve(current, ".git")))
|
|
19
|
+
return current;
|
|
20
|
+
const parent = dirname(current);
|
|
21
|
+
if (parent === current)
|
|
22
|
+
return null;
|
|
23
|
+
current = parent;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function resolveCheckoutRoot(projectRoot) {
|
|
27
|
+
const normalizedProjectRoot = resolve(projectRoot);
|
|
28
|
+
const explicit = process.env.MONOREPO_ROOT?.trim();
|
|
29
|
+
if (explicit) {
|
|
30
|
+
const explicitRoot = resolve(explicit);
|
|
31
|
+
const gitRoot = findNearestGitCheckoutRoot(explicitRoot);
|
|
32
|
+
if (gitRoot)
|
|
33
|
+
return gitRoot;
|
|
34
|
+
throw new Error(`MONOREPO_ROOT points to ${explicitRoot}, but no git checkout was found there or above it.`);
|
|
35
|
+
}
|
|
36
|
+
return findNearestGitCheckoutRoot(normalizedProjectRoot) ?? normalizedProjectRoot;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// packages/core/src/layout.ts
|
|
40
|
+
var resolveMonorepoRoot = resolveCheckoutRoot;
|
|
41
|
+
function resolveRuntimeWorkspaceLayout(workspaceDir) {
|
|
42
|
+
const root = resolve2(workspaceDir);
|
|
43
|
+
const rigRoot = resolve2(root, ".rig");
|
|
44
|
+
const logsDir = resolve2(rigRoot, "logs");
|
|
45
|
+
const stateDir = resolve2(rigRoot, "state");
|
|
46
|
+
const runtimeDir = resolve2(rigRoot, "runtime");
|
|
47
|
+
const binDir = resolve2(rigRoot, "bin");
|
|
48
|
+
return {
|
|
49
|
+
workspaceDir: root,
|
|
50
|
+
rigRoot,
|
|
51
|
+
stateDir,
|
|
52
|
+
logsDir,
|
|
53
|
+
runtimeDir,
|
|
54
|
+
homeDir: resolve2(rigRoot, "home"),
|
|
55
|
+
tmpDir: resolve2(rigRoot, "tmp"),
|
|
56
|
+
cacheDir: resolve2(rigRoot, "cache"),
|
|
57
|
+
sessionDir: resolve2(rigRoot, "session"),
|
|
58
|
+
binDir,
|
|
59
|
+
distDir: resolve2(rigRoot, "dist"),
|
|
60
|
+
pluginBinDir: resolve2(binDir, "plugins"),
|
|
61
|
+
contextPath: resolve2(rigRoot, "runtime-context.json"),
|
|
62
|
+
controlPlaneEventsFile: resolve2(logsDir, "control-plane.events.jsonl")
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function resolveActiveRuntimeWorkspaceRoot(_monorepoRoot) {
|
|
66
|
+
const explicit = process.env.RIG_TASK_WORKSPACE?.trim();
|
|
67
|
+
if (!explicit) {
|
|
68
|
+
throw new Error("No active runtime workspace. Set RIG_TASK_WORKSPACE or provision a task runtime first.");
|
|
69
|
+
}
|
|
70
|
+
return resolve2(explicit);
|
|
71
|
+
}
|
|
72
|
+
function resolveRigLayout(projectRoot) {
|
|
73
|
+
const monorepoRoot = resolveMonorepoRoot(projectRoot);
|
|
74
|
+
const definitionRoot = resolve2(projectRoot, RIG_DEFINITION_DIRNAME);
|
|
75
|
+
const runtimeWorkspaceRoot = resolveActiveRuntimeWorkspaceRoot(monorepoRoot);
|
|
76
|
+
const runtimeLayout = resolveRuntimeWorkspaceLayout(runtimeWorkspaceRoot);
|
|
77
|
+
const policyDir = resolve2(definitionRoot, "policy");
|
|
78
|
+
return {
|
|
79
|
+
projectRoot,
|
|
80
|
+
monorepoRoot,
|
|
81
|
+
definitionRoot,
|
|
82
|
+
runtimeWorkspaceRoot,
|
|
83
|
+
stateRoot: runtimeLayout.rigRoot,
|
|
84
|
+
configPath: resolve2(definitionRoot, "config.sh"),
|
|
85
|
+
policyDir,
|
|
86
|
+
policyFile: resolve2(policyDir, "policy.json"),
|
|
87
|
+
pluginsDir: resolve2(definitionRoot, "plugins"),
|
|
88
|
+
hooksDir: resolve2(definitionRoot, "hooks"),
|
|
89
|
+
toolsDir: resolve2(definitionRoot, "tools"),
|
|
90
|
+
templatesDir: resolve2(definitionRoot, "templates"),
|
|
91
|
+
validationDir: resolve2(definitionRoot, "validation"),
|
|
92
|
+
stateDir: runtimeLayout.stateDir,
|
|
93
|
+
logsDir: runtimeLayout.logsDir,
|
|
94
|
+
notificationsDir: resolve2(definitionRoot, "notifications"),
|
|
95
|
+
runtimeDir: runtimeLayout.runtimeDir,
|
|
96
|
+
distDir: runtimeLayout.distDir,
|
|
97
|
+
binDir: runtimeLayout.binDir,
|
|
98
|
+
pluginBinDir: runtimeLayout.pluginBinDir,
|
|
99
|
+
keybindingsPath: resolve2(definitionRoot, "keybindings.json"),
|
|
100
|
+
controlPlaneEventsFile: runtimeLayout.controlPlaneEventsFile
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// packages/core/src/harness-paths.ts
|
|
105
|
+
function resolveHarnessPaths(projectRoot) {
|
|
106
|
+
const hasRuntimeWorkspace = Boolean(process.env.RIG_TASK_WORKSPACE?.trim());
|
|
107
|
+
const monorepoRoot = resolveCheckoutRoot(projectRoot);
|
|
108
|
+
const harnessRoot = resolve3(projectRoot, "rig");
|
|
109
|
+
const stateRoot = resolve3(projectRoot, ".rig");
|
|
110
|
+
const layout = hasRuntimeWorkspace ? resolveRigLayout(projectRoot) : null;
|
|
111
|
+
const stateDir = layout?.stateDir ?? resolve3(stateRoot, "state");
|
|
112
|
+
const logsDir = layout?.logsDir ?? resolve3(stateRoot, "logs");
|
|
113
|
+
const binDir = layout?.binDir ?? resolve3(stateRoot, "bin");
|
|
114
|
+
return {
|
|
115
|
+
harnessRoot,
|
|
116
|
+
stateDir: process.env.RIG_STATE_DIR || stateDir,
|
|
117
|
+
logsDir: process.env.RIG_LOGS_DIR || logsDir,
|
|
118
|
+
binDir,
|
|
119
|
+
hooksDir: resolve3(harnessRoot, "hooks"),
|
|
120
|
+
validationDir: resolve3(harnessRoot, "validation"),
|
|
121
|
+
monorepoRoot
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
resolveHarnessPaths
|
|
126
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HookRegistration } from "@rig/contracts";
|
|
2
|
+
export type { PluginHookEntry } from "@rig/contracts";
|
|
3
|
+
/**
|
|
4
|
+
* Resolve the path to the typed-hook runner entrypoint.
|
|
5
|
+
*
|
|
6
|
+
* Workspace/dev checkouts (and consumer projects with `@rig/core` in
|
|
7
|
+
* node_modules of THIS process) resolve the sibling source file directly.
|
|
8
|
+
* When that file isn't on disk (for example a compiled/virtualized runtime),
|
|
9
|
+
* fall back to the consumer project's own node_modules via
|
|
10
|
+
* `$CLAUDE_PROJECT_DIR`; Claude Code expands that variable when it runs the
|
|
11
|
+
* hook command.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveHookRunnerPath(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Build the shell shim command for a typed hook. The command invokes the
|
|
16
|
+
* hook-runner, which loads the project's rig config, finds the plugin's typed
|
|
17
|
+
* implementation, and bridges stdin/stdout to the hook protocol.
|
|
18
|
+
* `--event` is informational (the runner trusts the metadata registration);
|
|
19
|
+
* `--plugin`/`--hook`/`--project-root` are the runner's actual inputs.
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildTypedHookShimCommand(pluginName: string, hook: HookRegistration, projectRoot: string): string;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/core/src/hook-materializer.ts
|
|
3
|
+
import { existsSync as existsSync2 } from "fs";
|
|
4
|
+
import { resolve as resolve2 } from "path";
|
|
5
|
+
|
|
6
|
+
// packages/core/src/hook-runtime.ts
|
|
7
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, realpathSync, writeSync } from "fs";
|
|
8
|
+
import { resolve } from "path";
|
|
9
|
+
import { RIG_DEFINITION_DIRNAME, RIG_STATE_DIRNAME } from "@rig/contracts";
|
|
10
|
+
function bunRuntime() {
|
|
11
|
+
const runtime = globalThis;
|
|
12
|
+
return runtime.Bun;
|
|
13
|
+
}
|
|
14
|
+
function normalizeBuildConfig(value) {
|
|
15
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
return Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string"));
|
|
19
|
+
}
|
|
20
|
+
function readBuildConfigForCoreHooks() {
|
|
21
|
+
if (typeof __RIG_BUILD_CONFIG__ !== "undefined") {
|
|
22
|
+
return normalizeBuildConfig(__RIG_BUILD_CONFIG__);
|
|
23
|
+
}
|
|
24
|
+
const raw = process.env.RIG_BUILD_CONFIG_JSON?.trim();
|
|
25
|
+
if (!raw) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
return normalizeBuildConfig(JSON.parse(raw));
|
|
30
|
+
} catch {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
var BUILD_CONFIG = readBuildConfigForCoreHooks();
|
|
35
|
+
var BAKED_PROJECT_ROOT = BUILD_CONFIG.AGENT_PROJECT_ROOT ?? "";
|
|
36
|
+
var BAKED_TASK_ID = BUILD_CONFIG.AGENT_TASK_ID ?? "";
|
|
37
|
+
var BAKED_STATE_DIR = BUILD_CONFIG.AGENT_STATE_DIR ?? "";
|
|
38
|
+
var BAKED_BUN_PATH = BUILD_CONFIG.AGENT_BUN_PATH ?? "";
|
|
39
|
+
var BAKED_TASK_CONFIG = BUILD_CONFIG.AGENT_TASK_CONFIG ?? "";
|
|
40
|
+
var BAKED_POLICY_CONTENT = BUILD_CONFIG.AGENT_POLICY_CONTENT ?? "";
|
|
41
|
+
var BAKED_TASK_SCOPES = BUILD_CONFIG.AGENT_TASK_SCOPES ?? "";
|
|
42
|
+
function normalizeExecutablePath(candidate) {
|
|
43
|
+
if (!candidate) {
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
const normalized = resolve(candidate);
|
|
47
|
+
if (!existsSync(normalized)) {
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
return realpathSync(normalized);
|
|
52
|
+
} catch {
|
|
53
|
+
return normalized;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function looksLikeRuntimeGateway(candidate) {
|
|
57
|
+
const normalized = resolve(candidate).replace(/\\/g, "/");
|
|
58
|
+
return normalized.includes("/.rig/bin/") || normalized.endsWith("/rig-shell") || normalized.endsWith("/rig-agent");
|
|
59
|
+
}
|
|
60
|
+
function resolveBunBinaryPath() {
|
|
61
|
+
const explicit = normalizeExecutablePath(process.env.RIG_BUN_PATH?.trim());
|
|
62
|
+
if (explicit) {
|
|
63
|
+
return explicit;
|
|
64
|
+
}
|
|
65
|
+
const bunWhich = bunRuntime()?.which?.("bun");
|
|
66
|
+
const pathBun = normalizeExecutablePath(bunWhich?.trim());
|
|
67
|
+
if (pathBun && !looksLikeRuntimeGateway(pathBun)) {
|
|
68
|
+
return pathBun;
|
|
69
|
+
}
|
|
70
|
+
const home = process.env.HOME?.trim();
|
|
71
|
+
const fallbackCandidates = [
|
|
72
|
+
home ? resolve(home, ".bun/bin/bun") : "",
|
|
73
|
+
"/opt/homebrew/bin/bun",
|
|
74
|
+
"/usr/local/bin/bun",
|
|
75
|
+
"/usr/bin/bun"
|
|
76
|
+
];
|
|
77
|
+
for (const candidate of fallbackCandidates) {
|
|
78
|
+
const normalized = normalizeExecutablePath(candidate);
|
|
79
|
+
if (normalized) {
|
|
80
|
+
return normalized;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const execPath = normalizeExecutablePath(process.execPath?.trim());
|
|
84
|
+
if (execPath && !looksLikeRuntimeGateway(execPath)) {
|
|
85
|
+
return execPath;
|
|
86
|
+
}
|
|
87
|
+
throw new Error("bun not found in PATH");
|
|
88
|
+
}
|
|
89
|
+
function resolveBunCliInvocation() {
|
|
90
|
+
if (BAKED_BUN_PATH) {
|
|
91
|
+
return {
|
|
92
|
+
command: BAKED_BUN_PATH,
|
|
93
|
+
env: {}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (process.env.RIG_BUN_PATH?.trim()) {
|
|
97
|
+
return {
|
|
98
|
+
command: process.env.RIG_BUN_PATH.trim(),
|
|
99
|
+
env: {}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const systemBun = resolveBunBinaryPath();
|
|
104
|
+
return {
|
|
105
|
+
command: systemBun,
|
|
106
|
+
env: {}
|
|
107
|
+
};
|
|
108
|
+
} catch {}
|
|
109
|
+
if (process.execPath?.trim()) {
|
|
110
|
+
return {
|
|
111
|
+
command: process.execPath,
|
|
112
|
+
env: { BUN_BE_BUN: "1" }
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return { command: "bun", env: {} };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// packages/core/src/hook-materializer.ts
|
|
119
|
+
function shellQuote(value) {
|
|
120
|
+
return `'${value.replaceAll("'", `'\\''`)}'`;
|
|
121
|
+
}
|
|
122
|
+
function resolveHookRunnerPath() {
|
|
123
|
+
const sibling = resolve2(import.meta.dirname, "hook-runner.ts");
|
|
124
|
+
if (existsSync2(sibling)) {
|
|
125
|
+
return sibling;
|
|
126
|
+
}
|
|
127
|
+
return "$CLAUDE_PROJECT_DIR/node_modules/@rig/core/src/hook-runner.ts";
|
|
128
|
+
}
|
|
129
|
+
function buildTypedHookShimCommand(pluginName, hook, projectRoot) {
|
|
130
|
+
const runnerPath = resolveHookRunnerPath();
|
|
131
|
+
const runnerArg = runnerPath.startsWith("$CLAUDE_PROJECT_DIR") ? `"${runnerPath}"` : shellQuote(runnerPath);
|
|
132
|
+
const bun = resolveBunCliInvocation();
|
|
133
|
+
const envPrefix = Object.entries(bun.env).map(([key, value]) => `${key}=${shellQuote(value)}`).join(" ");
|
|
134
|
+
const parts = [
|
|
135
|
+
envPrefix,
|
|
136
|
+
shellQuote(bun.command),
|
|
137
|
+
runnerArg,
|
|
138
|
+
"--plugin",
|
|
139
|
+
shellQuote(pluginName),
|
|
140
|
+
"--hook",
|
|
141
|
+
shellQuote(hook.id),
|
|
142
|
+
"--event",
|
|
143
|
+
shellQuote(hook.event),
|
|
144
|
+
"--project-root",
|
|
145
|
+
shellQuote(projectRoot)
|
|
146
|
+
].filter(Boolean);
|
|
147
|
+
return parts.join(" ");
|
|
148
|
+
}
|
|
149
|
+
export {
|
|
150
|
+
resolveHookRunnerPath,
|
|
151
|
+
buildTypedHookShimCommand
|
|
152
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type { HookInput, ParsedHookInput, TypedHookOptions } from "./hook-runtime";
|
|
2
|
+
export { BAKED_BUN_PATH, BAKED_POLICY_CONTENT, BAKED_PROJECT_ROOT, BAKED_STATE_DIR, BAKED_TASK_CONFIG, BAKED_TASK_ID, BAKED_TASK_SCOPES, block, buildPluginHookContext, escapeRegExp, extractToolFilePaths, hookResultToProtocol, isTestFilePath, readHookInput, resolveBunCli, resolveBunCliInvocation, resolvePolicyContent, resolveProjectRoot, resolveTaskConfig, resolveTaskIdForHook, resolveTaskScopes, runTypedHook, } from "./hook-runtime";
|