@h-rig/core 0.0.6-alpha.16 → 0.0.6-alpha.161
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 +6 -0
- package/dist/src/baked-secrets.js +121 -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 +749 -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 +82 -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 +18 -0
- package/dist/src/harness-paths.js +141 -0
- package/dist/src/hook-materializer.d.ts +72 -0
- package/dist/src/hook-materializer.js +274 -0
- package/dist/src/hook-runner.d.ts +48 -0
- package/dist/src/hook-runner.js +752 -0
- package/dist/src/hook-runtime.d.ts +11 -0
- package/dist/src/hook-runtime.js +307 -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 +125 -0
- package/dist/src/kernel-entrypoint.d.ts +22 -0
- package/dist/src/kernel-entrypoint.js +537 -0
- package/dist/src/layout.d.ts +10 -0
- package/dist/src/layout.js +144 -0
- package/dist/src/load-config.d.ts +2 -0
- package/dist/src/load-config.js +421 -28
- package/dist/src/placement.d.ts +50 -0
- package/dist/src/placement.js +996 -0
- package/dist/src/plugin-host-context.d.ts +66 -0
- package/dist/src/plugin-host-context.js +1276 -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/profile-ops.d.ts +9 -0
- package/dist/src/profile-ops.js +252 -0
- package/dist/src/project-plugins.d.ts +63 -0
- package/dist/src/project-plugins.js +783 -0
- package/dist/src/remote-config.d.ts +183 -0
- package/dist/src/remote-config.js +574 -0
- package/dist/src/root-resolver.d.ts +5 -0
- package/dist/src/root-resolver.js +69 -0
- package/dist/src/run-provisioning.d.ts +58 -0
- package/dist/src/run-provisioning.js +128 -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 +212 -0
- package/dist/src/runtime-overlay.d.ts +11 -0
- package/dist/src/runtime-overlay.js +71 -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 +26 -0
- package/dist/src/server-paths.js +308 -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 +146 -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
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type HookEvent, type HookImplementation } from "@rig/contracts";
|
|
2
|
+
export interface TypedHookOptions {
|
|
3
|
+
readonly event: HookEvent;
|
|
4
|
+
readonly projectRoot?: string;
|
|
5
|
+
readonly taskId?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function resolveBunCliInvocation(): {
|
|
8
|
+
command: string;
|
|
9
|
+
env: Record<string, string>;
|
|
10
|
+
};
|
|
11
|
+
export declare function runTypedHook(fn: HookImplementation, opts: TypedHookOptions): Promise<never>;
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/core/src/hook-runtime.ts
|
|
3
|
+
import { existsSync, readFileSync, realpathSync, writeSync } from "fs";
|
|
4
|
+
import { resolve } from "path";
|
|
5
|
+
import { RIG_DEFINITION_DIRNAME, RIG_STATE_DIRNAME } from "@rig/contracts";
|
|
6
|
+
function normalizeBuildConfig(value) {
|
|
7
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
8
|
+
return {};
|
|
9
|
+
}
|
|
10
|
+
return Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string"));
|
|
11
|
+
}
|
|
12
|
+
function readBuildConfigForCoreHooks() {
|
|
13
|
+
if (typeof __RIG_BUILD_CONFIG__ !== "undefined") {
|
|
14
|
+
return normalizeBuildConfig(__RIG_BUILD_CONFIG__);
|
|
15
|
+
}
|
|
16
|
+
const raw = process.env.RIG_BUILD_CONFIG_JSON?.trim();
|
|
17
|
+
if (!raw) {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
return normalizeBuildConfig(JSON.parse(raw));
|
|
22
|
+
} catch {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
var BUILD_CONFIG = readBuildConfigForCoreHooks();
|
|
27
|
+
var BAKED_PROJECT_ROOT = BUILD_CONFIG.AGENT_PROJECT_ROOT ?? "";
|
|
28
|
+
var BAKED_TASK_ID = BUILD_CONFIG.AGENT_TASK_ID ?? "";
|
|
29
|
+
var BAKED_BUN_PATH = BUILD_CONFIG.AGENT_BUN_PATH ?? "";
|
|
30
|
+
var RUNTIME_CONTEXT_ENV = "RIG_RUNTIME_CONTEXT_FILE";
|
|
31
|
+
function isPlainObject(value) {
|
|
32
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
|
+
}
|
|
34
|
+
function isStringArray(value) {
|
|
35
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
36
|
+
}
|
|
37
|
+
function loadHookContextFromEnv() {
|
|
38
|
+
const contextFile = process.env[RUNTIME_CONTEXT_ENV]?.trim();
|
|
39
|
+
let filePath = contextFile || "";
|
|
40
|
+
if (!filePath) {
|
|
41
|
+
let current = resolve(process.cwd());
|
|
42
|
+
while (true) {
|
|
43
|
+
const candidate = resolve(current, "runtime-context.json");
|
|
44
|
+
if (existsSync(candidate)) {
|
|
45
|
+
filePath = candidate;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
const parent = resolve(current, "..");
|
|
49
|
+
if (parent === current) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
current = parent;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!filePath || !existsSync(filePath)) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const raw = JSON.parse(readFileSync(filePath, "utf-8"));
|
|
60
|
+
if (!isPlainObject(raw)) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const taskId = typeof raw.taskId === "string" ? raw.taskId : "";
|
|
64
|
+
const role = typeof raw.role === "string" ? raw.role : "";
|
|
65
|
+
const scopes = isStringArray(raw.scopes) ? raw.scopes : [];
|
|
66
|
+
const validation = isStringArray(raw.validation) ? raw.validation : [];
|
|
67
|
+
const hostProjectRoot = typeof raw.hostProjectRoot === "string" ? raw.hostProjectRoot : undefined;
|
|
68
|
+
const monorepoMainRoot = typeof raw.monorepoMainRoot === "string" ? raw.monorepoMainRoot : undefined;
|
|
69
|
+
const stateDir = typeof raw.stateDir === "string" ? raw.stateDir : "";
|
|
70
|
+
const policyFile = typeof raw.policyFile === "string" ? raw.policyFile : "";
|
|
71
|
+
if (!taskId || !stateDir) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
taskId,
|
|
76
|
+
role,
|
|
77
|
+
scopes,
|
|
78
|
+
validation,
|
|
79
|
+
hostProjectRoot,
|
|
80
|
+
monorepoMainRoot,
|
|
81
|
+
stateDir,
|
|
82
|
+
policyFile
|
|
83
|
+
};
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
var cachedContext;
|
|
89
|
+
function getContext() {
|
|
90
|
+
if (cachedContext !== undefined) {
|
|
91
|
+
return cachedContext;
|
|
92
|
+
}
|
|
93
|
+
cachedContext = loadHookContextFromEnv();
|
|
94
|
+
return cachedContext;
|
|
95
|
+
}
|
|
96
|
+
function resolveProjectRoot() {
|
|
97
|
+
const ctx = getContext();
|
|
98
|
+
if (ctx?.hostProjectRoot)
|
|
99
|
+
return ctx.hostProjectRoot;
|
|
100
|
+
if (BAKED_PROJECT_ROOT) {
|
|
101
|
+
return BAKED_PROJECT_ROOT;
|
|
102
|
+
}
|
|
103
|
+
if (process.env.PROJECT_RIG_ROOT) {
|
|
104
|
+
return process.env.PROJECT_RIG_ROOT;
|
|
105
|
+
}
|
|
106
|
+
const candidates = [process.cwd(), resolve(import.meta.dirname, "../..")];
|
|
107
|
+
for (const candidate of candidates) {
|
|
108
|
+
if (existsSync(resolve(candidate, RIG_DEFINITION_DIRNAME)) || existsSync(resolve(candidate, RIG_STATE_DIRNAME))) {
|
|
109
|
+
return candidate;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return resolve(import.meta.dirname, "../..");
|
|
113
|
+
}
|
|
114
|
+
function resolveTaskIdForHook(_projectRoot) {
|
|
115
|
+
const ctx = getContext();
|
|
116
|
+
if (ctx)
|
|
117
|
+
return ctx.taskId;
|
|
118
|
+
if (BAKED_TASK_ID) {
|
|
119
|
+
return BAKED_TASK_ID;
|
|
120
|
+
}
|
|
121
|
+
const fromEnv = (process.env.RIG_TASK_ID || "").trim();
|
|
122
|
+
if (fromEnv) {
|
|
123
|
+
return fromEnv;
|
|
124
|
+
}
|
|
125
|
+
const runtimeId = (process.env.RIG_TASK_RUNTIME_ID || "").trim();
|
|
126
|
+
if (runtimeId.startsWith("task-") && runtimeId.length > "task-".length) {
|
|
127
|
+
return runtimeId.slice("task-".length);
|
|
128
|
+
}
|
|
129
|
+
return "";
|
|
130
|
+
}
|
|
131
|
+
async function readHookInput() {
|
|
132
|
+
let text = "";
|
|
133
|
+
const inputFile = process.env.RIG_HOOK_INPUT_FILE?.trim();
|
|
134
|
+
if (inputFile) {
|
|
135
|
+
text = readFileSync(inputFile, "utf-8");
|
|
136
|
+
} else {
|
|
137
|
+
try {
|
|
138
|
+
text = readFileSync("/dev/stdin", "utf-8");
|
|
139
|
+
} catch {
|
|
140
|
+
text = readFileSync(0, "utf-8");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!text.trim()) {
|
|
144
|
+
return { input: {}, valid: true, hadPayload: false };
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
return {
|
|
148
|
+
input: JSON.parse(text),
|
|
149
|
+
valid: true,
|
|
150
|
+
hadPayload: true
|
|
151
|
+
};
|
|
152
|
+
} catch {
|
|
153
|
+
return { input: {}, valid: false, hadPayload: true };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function extractToolFilePaths(toolName, input) {
|
|
157
|
+
const paths = [];
|
|
158
|
+
const add = (value) => {
|
|
159
|
+
if (typeof value === "string" && value.trim()) {
|
|
160
|
+
paths.push(value.trim());
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
if (toolName === "Read" || toolName === "Write" || toolName === "Edit" || toolName === "MultiEdit") {
|
|
164
|
+
add(input.file_path);
|
|
165
|
+
add(input.path);
|
|
166
|
+
} else if (toolName === "Glob") {
|
|
167
|
+
add(input.path);
|
|
168
|
+
} else if (toolName === "Grep") {
|
|
169
|
+
add(input.path);
|
|
170
|
+
} else {
|
|
171
|
+
add(input.file_path);
|
|
172
|
+
add(input.path);
|
|
173
|
+
}
|
|
174
|
+
return paths;
|
|
175
|
+
}
|
|
176
|
+
function buildPluginHookContext(parsed, opts) {
|
|
177
|
+
const toolName = parsed.input.tool_name;
|
|
178
|
+
const toolInput = parsed.input.tool_input ?? {};
|
|
179
|
+
return {
|
|
180
|
+
event: opts.event,
|
|
181
|
+
toolName,
|
|
182
|
+
toolInput,
|
|
183
|
+
filePaths: toolName ? extractToolFilePaths(toolName, toolInput) : [],
|
|
184
|
+
projectRoot: opts.projectRoot,
|
|
185
|
+
taskId: opts.taskId
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function hookResultToProtocol(result) {
|
|
189
|
+
if (result.decision === "block") {
|
|
190
|
+
const lines = [`BLOCKED: ${result.reason ?? "blocked by plugin hook"}`];
|
|
191
|
+
if (result.systemMessage) {
|
|
192
|
+
lines.push(result.systemMessage);
|
|
193
|
+
}
|
|
194
|
+
return { exitCode: 1, stdout: `${lines.join(`
|
|
195
|
+
`)}
|
|
196
|
+
` };
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
exitCode: 0,
|
|
200
|
+
stdout: result.systemMessage ? `${result.systemMessage}
|
|
201
|
+
` : ""
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function normalizeExecutablePath(candidate) {
|
|
205
|
+
if (!candidate) {
|
|
206
|
+
return "";
|
|
207
|
+
}
|
|
208
|
+
const normalized = resolve(candidate);
|
|
209
|
+
if (!existsSync(normalized)) {
|
|
210
|
+
return "";
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
return realpathSync(normalized);
|
|
214
|
+
} catch {
|
|
215
|
+
return normalized;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function looksLikeRuntimeGateway(candidate) {
|
|
219
|
+
const normalized = resolve(candidate).replace(/\\/g, "/");
|
|
220
|
+
return normalized.includes("/.rig/bin/") || normalized.endsWith("/rig-shell") || normalized.endsWith("/rig-agent");
|
|
221
|
+
}
|
|
222
|
+
function resolveBunBinaryPath() {
|
|
223
|
+
const explicit = normalizeExecutablePath(process.env.RIG_BUN_PATH?.trim());
|
|
224
|
+
if (explicit) {
|
|
225
|
+
return explicit;
|
|
226
|
+
}
|
|
227
|
+
const bunGlobal = globalThis.Bun;
|
|
228
|
+
const bunWhich = bunGlobal?.which?.("bun");
|
|
229
|
+
const pathBun = normalizeExecutablePath(bunWhich?.trim());
|
|
230
|
+
if (pathBun && !looksLikeRuntimeGateway(pathBun)) {
|
|
231
|
+
return pathBun;
|
|
232
|
+
}
|
|
233
|
+
const home = process.env.HOME?.trim();
|
|
234
|
+
const fallbackCandidates = [
|
|
235
|
+
home ? resolve(home, ".bun/bin/bun") : "",
|
|
236
|
+
"/opt/homebrew/bin/bun",
|
|
237
|
+
"/usr/local/bin/bun",
|
|
238
|
+
"/usr/bin/bun"
|
|
239
|
+
];
|
|
240
|
+
for (const candidate of fallbackCandidates) {
|
|
241
|
+
const normalized = normalizeExecutablePath(candidate);
|
|
242
|
+
if (normalized) {
|
|
243
|
+
return normalized;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const execPath = normalizeExecutablePath(process.execPath?.trim());
|
|
247
|
+
if (execPath && !looksLikeRuntimeGateway(execPath)) {
|
|
248
|
+
return execPath;
|
|
249
|
+
}
|
|
250
|
+
throw new Error("bun not found in PATH");
|
|
251
|
+
}
|
|
252
|
+
function resolveBunCliInvocation() {
|
|
253
|
+
if (BAKED_BUN_PATH) {
|
|
254
|
+
return {
|
|
255
|
+
command: BAKED_BUN_PATH,
|
|
256
|
+
env: {}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
if (process.env.RIG_BUN_PATH?.trim()) {
|
|
260
|
+
return {
|
|
261
|
+
command: process.env.RIG_BUN_PATH.trim(),
|
|
262
|
+
env: {}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
const systemBun = resolveBunBinaryPath();
|
|
267
|
+
return {
|
|
268
|
+
command: systemBun,
|
|
269
|
+
env: {}
|
|
270
|
+
};
|
|
271
|
+
} catch {}
|
|
272
|
+
if (process.execPath?.trim()) {
|
|
273
|
+
return {
|
|
274
|
+
command: process.execPath,
|
|
275
|
+
env: { BUN_BE_BUN: "1" }
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
return { command: "bun", env: {} };
|
|
279
|
+
}
|
|
280
|
+
async function runTypedHook(fn, opts) {
|
|
281
|
+
const parsed = await readHookInput();
|
|
282
|
+
const projectRoot = opts.projectRoot ?? resolveProjectRoot();
|
|
283
|
+
const taskId = opts.taskId ?? resolveTaskIdForHook(projectRoot);
|
|
284
|
+
const ctx = buildPluginHookContext(parsed, {
|
|
285
|
+
event: opts.event,
|
|
286
|
+
projectRoot,
|
|
287
|
+
taskId
|
|
288
|
+
});
|
|
289
|
+
let result;
|
|
290
|
+
try {
|
|
291
|
+
result = await fn(ctx);
|
|
292
|
+
} catch (err) {
|
|
293
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
294
|
+
writeSync(2, `[rig hook] typed hook threw: ${message}
|
|
295
|
+
`);
|
|
296
|
+
process.exit(0);
|
|
297
|
+
}
|
|
298
|
+
const { exitCode, stdout } = hookResultToProtocol(result);
|
|
299
|
+
if (stdout) {
|
|
300
|
+
writeSync(1, stdout);
|
|
301
|
+
}
|
|
302
|
+
process.exit(exitCode);
|
|
303
|
+
}
|
|
304
|
+
export {
|
|
305
|
+
runTypedHook,
|
|
306
|
+
resolveBunCliInvocation
|
|
307
|
+
};
|
|
@@ -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";
|