@h-rig/core 0.0.0-e2e-live.20260630085347

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 (101) hide show
  1. package/README.md +9 -0
  2. package/dist/src/agent-role-registry.d.ts +4 -0
  3. package/dist/src/agent-role-registry.js +27 -0
  4. package/dist/src/authority-paths.d.ts +15 -0
  5. package/dist/src/authority-paths.js +80 -0
  6. package/dist/src/baked-secrets.d.ts +3 -0
  7. package/dist/src/baked-secrets.js +63 -0
  8. package/dist/src/build-time-config.d.ts +12 -0
  9. package/dist/src/build-time-config.js +25 -0
  10. package/dist/src/build-time-config.macro.d.ts +1 -0
  11. package/dist/src/capability-loaders.d.ts +51 -0
  12. package/dist/src/capability-loaders.js +761 -0
  13. package/dist/src/capability.d.ts +79 -0
  14. package/dist/src/capability.js +63 -0
  15. package/dist/src/checkout-root.d.ts +1 -0
  16. package/dist/src/checkout-root.js +30 -0
  17. package/dist/src/config-env.d.ts +4 -0
  18. package/dist/src/config-env.js +23 -0
  19. package/dist/src/config.d.ts +3 -0
  20. package/dist/src/config.js +44 -0
  21. package/dist/src/declarative-config.d.ts +14 -0
  22. package/dist/src/declarative-config.js +85 -0
  23. package/dist/src/default-kernel.d.ts +1 -0
  24. package/dist/src/default-kernel.js +12 -0
  25. package/dist/src/define-config.d.ts +20 -0
  26. package/dist/src/define-config.js +37 -0
  27. package/dist/src/define-plugin.d.ts +13 -0
  28. package/dist/src/define-plugin.js +11 -0
  29. package/dist/src/embedded-plugins.d.ts +59 -0
  30. package/dist/src/embedded-plugins.js +22 -0
  31. package/dist/src/exec.d.ts +13 -0
  32. package/dist/src/exec.js +101 -0
  33. package/dist/src/harness-paths.d.ts +9 -0
  34. package/dist/src/harness-paths.js +126 -0
  35. package/dist/src/hook-materializer.d.ts +21 -0
  36. package/dist/src/hook-materializer.js +152 -0
  37. package/dist/src/hook-protocol.d.ts +2 -0
  38. package/dist/src/hook-protocol.js +432 -0
  39. package/dist/src/hook-runner.d.ts +48 -0
  40. package/dist/src/hook-runner.js +759 -0
  41. package/dist/src/hook-runtime.d.ts +52 -0
  42. package/dist/src/hook-runtime.js +432 -0
  43. package/dist/src/index.d.ts +8 -0
  44. package/dist/src/index.js +327 -0
  45. package/dist/src/json-files.d.ts +9 -0
  46. package/dist/src/json-files.js +124 -0
  47. package/dist/src/kernel-boot.d.ts +2 -0
  48. package/dist/src/kernel-boot.js +10 -0
  49. package/dist/src/kernel-entrypoint.d.ts +22 -0
  50. package/dist/src/kernel-entrypoint.js +551 -0
  51. package/dist/src/kernel-plugin-abi.d.ts +1 -0
  52. package/dist/src/kernel-plugin-abi.js +1 -0
  53. package/dist/src/kernel-resolver.d.ts +2 -0
  54. package/dist/src/kernel-resolver.js +6 -0
  55. package/dist/src/layout.d.ts +10 -0
  56. package/dist/src/layout.js +138 -0
  57. package/dist/src/load-config.d.ts +2 -0
  58. package/dist/src/load-config.js +445 -0
  59. package/dist/src/placement.d.ts +58 -0
  60. package/dist/src/placement.js +53 -0
  61. package/dist/src/plugin-host-context.d.ts +65 -0
  62. package/dist/src/plugin-host-context.js +1059 -0
  63. package/dist/src/plugin-host-registries.d.ts +31 -0
  64. package/dist/src/plugin-host-registries.js +79 -0
  65. package/dist/src/plugin-host.d.ts +77 -0
  66. package/dist/src/plugin-host.js +222 -0
  67. package/dist/src/plugin-runtime.d.ts +173 -0
  68. package/dist/src/plugin-runtime.js +1 -0
  69. package/dist/src/project-plugins.d.ts +63 -0
  70. package/dist/src/project-plugins.js +796 -0
  71. package/dist/src/remote-config.d.ts +125 -0
  72. package/dist/src/remote-config.js +85 -0
  73. package/dist/src/root-resolver.d.ts +5 -0
  74. package/dist/src/root-resolver.js +68 -0
  75. package/dist/src/run-provisioning.d.ts +37 -0
  76. package/dist/src/run-provisioning.js +35 -0
  77. package/dist/src/runtime-context.d.ts +20 -0
  78. package/dist/src/runtime-context.js +257 -0
  79. package/dist/src/runtime-events.d.ts +44 -0
  80. package/dist/src/runtime-events.js +208 -0
  81. package/dist/src/runtime-overlay.d.ts +11 -0
  82. package/dist/src/runtime-overlay.js +69 -0
  83. package/dist/src/runtime-paths.d.ts +21 -0
  84. package/dist/src/runtime-paths.js +181 -0
  85. package/dist/src/runtime-provisioning-env.d.ts +5 -0
  86. package/dist/src/runtime-provisioning-env.js +217 -0
  87. package/dist/src/runtime-runner-context.d.ts +12 -0
  88. package/dist/src/runtime-runner-context.js +1 -0
  89. package/dist/src/safe-identifiers.d.ts +44 -0
  90. package/dist/src/safe-identifiers.js +96 -0
  91. package/dist/src/scope-rules.d.ts +4 -0
  92. package/dist/src/scope-rules.js +21 -0
  93. package/dist/src/server-paths.d.ts +22 -0
  94. package/dist/src/server-paths.js +219 -0
  95. package/dist/src/setup-version.d.ts +3 -0
  96. package/dist/src/setup-version.js +14 -0
  97. package/dist/src/task-record-reader.d.ts +3 -0
  98. package/dist/src/task-record-reader.js +9 -0
  99. package/dist/src/validator-registry.d.ts +27 -0
  100. package/dist/src/validator-registry.js +64 -0
  101. package/package.json +189 -0
@@ -0,0 +1,327 @@
1
+ // @bun
2
+ // packages/core/src/define-plugin.ts
3
+ import { Schema } from "effect";
4
+ import { RigPlugin as RigPluginManifest } from "@rig/contracts";
5
+ function definePlugin(plugin) {
6
+ Schema.decodeUnknownSync(RigPluginManifest)(plugin);
7
+ return plugin;
8
+ }
9
+ // packages/core/src/define-config.ts
10
+ import { Schema as Schema2 } from "effect";
11
+ import { RigConfig } from "@rig/contracts";
12
+ function normalizeWorkspaceConfig(raw) {
13
+ const workspace = raw && typeof raw === "object" && !Array.isArray(raw) ? { ...raw } : {};
14
+ if (workspace.mainRepo === undefined)
15
+ workspace.mainRepo = ".";
16
+ if (workspace.checkout === undefined && workspace.isolation !== undefined)
17
+ workspace.checkout = workspace.isolation;
18
+ if (workspace.isolation === undefined && workspace.checkout !== undefined)
19
+ workspace.isolation = workspace.checkout;
20
+ return workspace;
21
+ }
22
+ function applyConfigDefaults(raw) {
23
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
24
+ return raw;
25
+ const record = raw;
26
+ return {
27
+ ...record,
28
+ plugins: Array.isArray(record.plugins) ? record.plugins.flat() : [],
29
+ workspace: normalizeWorkspaceConfig(record.workspace)
30
+ };
31
+ }
32
+ function defineConfig(cfg) {
33
+ const withDefaults = applyConfigDefaults(cfg);
34
+ const explicitPlugins = Array.isArray(withDefaults.plugins) ? [...withDefaults.plugins] : [];
35
+ const decoded = Schema2.decodeUnknownSync(RigConfig)({
36
+ ...withDefaults,
37
+ plugins: explicitPlugins
38
+ });
39
+ return { ...decoded, plugins: explicitPlugins };
40
+ }
41
+ // packages/core/src/plugin-host.ts
42
+ function indexById(contributions, kind) {
43
+ const map = new Map;
44
+ const registrant = new Map;
45
+ for (const { item, pluginName } of contributions) {
46
+ if (map.has(item.id)) {
47
+ throw new Error(`duplicate ${kind} id "${item.id}": registered by plugins "${registrant.get(item.id)}" and "${pluginName}"`);
48
+ }
49
+ map.set(item.id, item);
50
+ registrant.set(item.id, pluginName);
51
+ }
52
+ return map;
53
+ }
54
+ function assertUniquePluginNames(plugins) {
55
+ const seen = new Set;
56
+ for (const plugin of plugins) {
57
+ if (seen.has(plugin.name)) {
58
+ throw new Error(`duplicate plugin name "${plugin.name}"`);
59
+ }
60
+ seen.add(plugin.name);
61
+ }
62
+ }
63
+ function createPluginHost(plugins) {
64
+ assertUniquePluginNames(plugins);
65
+ const validators = [];
66
+ const hooks = [];
67
+ const skills = [];
68
+ const repoSources = [];
69
+ const agentRoles = [];
70
+ const taskFieldExtensions = [];
71
+ const taskSources = [];
72
+ const cliCommands = [];
73
+ const capabilities = [];
74
+ const panels = [];
75
+ const blockerClassifiers = [];
76
+ const sessionExtensions = [];
77
+ const seedEntrypoints = [];
78
+ const stages = [];
79
+ const stageMutations = [];
80
+ const stageExecutors = {};
81
+ for (const plugin of plugins) {
82
+ const c = plugin.contributes;
83
+ if (!c)
84
+ continue;
85
+ const pluginName = plugin.name;
86
+ if (c.validators)
87
+ validators.push(...c.validators.map((item) => ({ item, pluginName })));
88
+ if (c.hooks)
89
+ hooks.push(...c.hooks.map((item) => ({ item, pluginName })));
90
+ if (c.skills)
91
+ skills.push(...c.skills.map((item) => ({ item, pluginName })));
92
+ if (c.repoSources)
93
+ repoSources.push(...c.repoSources.map((item) => ({ item, pluginName })));
94
+ if (c.agentRoles)
95
+ agentRoles.push(...c.agentRoles.map((item) => ({ item, pluginName })));
96
+ if (c.taskFieldSchemas)
97
+ taskFieldExtensions.push(...c.taskFieldSchemas.map((item) => ({ item, pluginName })));
98
+ if (c.taskSources)
99
+ taskSources.push(...c.taskSources.map((item) => ({ item, pluginName })));
100
+ if (c.cliCommands)
101
+ cliCommands.push(...c.cliCommands.map((item) => ({ item, pluginName })));
102
+ if (c.capabilities)
103
+ capabilities.push(...c.capabilities.map((item) => ({ item, pluginName })));
104
+ if (c.panels)
105
+ panels.push(...c.panels.map((item) => ({ item, pluginName })));
106
+ if (c.blockerClassifiers)
107
+ blockerClassifiers.push(...c.blockerClassifiers.map((item) => ({ item, pluginName })));
108
+ if (c.sessionExtensions)
109
+ sessionExtensions.push(...c.sessionExtensions.map((item) => ({ item, pluginName })));
110
+ if (c.seedEntrypoints)
111
+ seedEntrypoints.push(...c.seedEntrypoints.map((item) => ({ item, pluginName })));
112
+ if (c.stageMutations)
113
+ stageMutations.push(...c.stageMutations.map((item) => ({ item, pluginName })));
114
+ if (c.stages) {
115
+ for (const stage of c.stages) {
116
+ stages.push({ item: stage, pluginName });
117
+ if (stage.run)
118
+ stageExecutors[stage.id] = stage.run;
119
+ }
120
+ }
121
+ }
122
+ const validatorMap = indexById(validators, "validator");
123
+ const hookMap = indexById(hooks, "hook");
124
+ const skillMap = indexById(skills, "skill");
125
+ const repoSourceMap = indexById(repoSources, "repoSource");
126
+ const agentRoleMap = indexById(agentRoles, "agentRole");
127
+ const taskFieldExtMap = indexById(taskFieldExtensions, "taskFieldExtension");
128
+ const taskSourceMap = indexById(taskSources, "taskSource");
129
+ const cliCommandMap = indexById(cliCommands, "cliCommand");
130
+ const capabilityMap = indexById(capabilities, "capability");
131
+ const panelMap = indexById(panels, "panel");
132
+ const blockerClassifierMap = indexById(blockerClassifiers, "blockerClassifier");
133
+ indexById(sessionExtensions, "sessionExtension");
134
+ indexById(seedEntrypoints, "seedEntrypoint");
135
+ const taskSourceFactoryByKind = new Map;
136
+ const taskSourceKindRegistrant = new Map;
137
+ for (const { item, pluginName } of taskSources) {
138
+ if (taskSourceFactoryByKind.has(item.kind)) {
139
+ throw new Error(`duplicate task source kind "${item.kind}": registered by plugins "${taskSourceKindRegistrant.get(item.kind)}" and "${pluginName}"`);
140
+ }
141
+ taskSourceFactoryByKind.set(item.kind, item);
142
+ taskSourceKindRegistrant.set(item.kind, pluginName);
143
+ }
144
+ const seedEntrypointByBasename = new Map;
145
+ const seedEntrypointByWorkerArg = new Map;
146
+ let insidePtySeedEntrypoint;
147
+ const registerSeedEntrypointSelector = (map, selectorKind, selector, contribution) => {
148
+ const existing = map.get(selector);
149
+ if (existing) {
150
+ throw new Error(`duplicate seed entrypoint ${selectorKind} "${selector}": registered by entrypoint "${existing.item.id}" from plugin "${existing.pluginName}" and entrypoint "${contribution.item.id}" from plugin "${contribution.pluginName}"`);
151
+ }
152
+ map.set(selector, contribution);
153
+ };
154
+ for (const contribution of seedEntrypoints) {
155
+ const entrypoint = contribution.item;
156
+ let selectorCount = 0;
157
+ if (entrypoint.basename) {
158
+ selectorCount += 1;
159
+ registerSeedEntrypointSelector(seedEntrypointByBasename, "basename", entrypoint.basename, contribution);
160
+ }
161
+ if (entrypoint.workerArg) {
162
+ selectorCount += 1;
163
+ registerSeedEntrypointSelector(seedEntrypointByWorkerArg, "workerArg", entrypoint.workerArg, contribution);
164
+ }
165
+ if (entrypoint.insidePty) {
166
+ selectorCount += 1;
167
+ if (insidePtySeedEntrypoint) {
168
+ throw new Error(`duplicate seed entrypoint inside-pty selector: registered by entrypoint "${insidePtySeedEntrypoint.item.id}" from plugin "${insidePtySeedEntrypoint.pluginName}" and entrypoint "${entrypoint.id}" from plugin "${contribution.pluginName}"`);
169
+ }
170
+ insidePtySeedEntrypoint = contribution;
171
+ }
172
+ if (selectorCount === 0) {
173
+ throw new Error(`seed entrypoint "${entrypoint.id}" from plugin "${contribution.pluginName}" must declare at least one selector (basename, workerArg, or insidePty)`);
174
+ }
175
+ }
176
+ const allValidators = validators.map((c) => c.item);
177
+ const allHooks = hooks.map((c) => c.item);
178
+ const allSkills = skills.map((c) => c.item);
179
+ const allRepoSources = repoSources.map((c) => c.item);
180
+ const allAgentRoles = agentRoles.map((c) => c.item);
181
+ const allTaskFieldExtensions = taskFieldExtensions.map((c) => c.item);
182
+ const allTaskSources = taskSources.map((c) => c.item);
183
+ const allCliCommands = cliCommands.map((c) => c.item);
184
+ const allStageMutations = stageMutations.map((c) => c.item);
185
+ const allStages = stages.map((c) => c.item);
186
+ const allCapabilities = capabilities.map((c) => c.item);
187
+ const allPanels = panels.map((c) => c.item);
188
+ const allBlockerClassifiers = blockerClassifiers.map((c) => c.item);
189
+ const allSessionExtensions = sessionExtensions.map((c) => c.item);
190
+ const allSeedEntrypoints = seedEntrypoints.map((c) => c.item);
191
+ const executableCliCommandByName = new Map;
192
+ const registerExecutableCliCommandSelector = (selector, contribution) => {
193
+ const existing = executableCliCommandByName.get(selector);
194
+ if (existing && existing.item.id !== contribution.item.id) {
195
+ throw new Error(`duplicate executable CLI selector "${selector}" registered by command "${existing.item.id}" from plugin "${existing.pluginName}" and command "${contribution.item.id}" from plugin "${contribution.pluginName}"`);
196
+ }
197
+ executableCliCommandByName.set(selector, contribution);
198
+ };
199
+ for (const contribution of cliCommands) {
200
+ const command = contribution.item;
201
+ const family = command.family ?? command.id;
202
+ registerExecutableCliCommandSelector(command.id, contribution);
203
+ registerExecutableCliCommandSelector(family, contribution);
204
+ for (const alias of command.aliases ?? []) {
205
+ registerExecutableCliCommandSelector(alias, contribution);
206
+ }
207
+ }
208
+ let defaultRootCliCommand;
209
+ for (const contribution of cliCommands) {
210
+ if (!contribution.item.rootDefault)
211
+ continue;
212
+ if (defaultRootCliCommand) {
213
+ throw new Error(`duplicate default root CLI command registered by command "${defaultRootCliCommand.item.id}" from plugin "${defaultRootCliCommand.pluginName}" and command "${contribution.item.id}" from plugin "${contribution.pluginName}"`);
214
+ }
215
+ defaultRootCliCommand = contribution;
216
+ }
217
+ return {
218
+ getValidator: (id) => validatorMap.get(id),
219
+ getHook: (id) => hookMap.get(id),
220
+ getSkill: (id) => skillMap.get(id),
221
+ getRepoSource: (id) => repoSourceMap.get(id),
222
+ getAgentRole: (id) => agentRoleMap.get(id),
223
+ getTaskFieldExtension: (id) => taskFieldExtMap.get(id),
224
+ getTaskSource: (id) => taskSourceMap.get(id),
225
+ getCliCommand: (id) => cliCommandMap.get(id),
226
+ getCapability: (id) => capabilityMap.get(id),
227
+ getPanel: (id) => panelMap.get(id),
228
+ getBlockerClassifier: (id) => blockerClassifierMap.get(id),
229
+ listValidators: () => allValidators,
230
+ listHooks: () => allHooks,
231
+ listSkills: () => allSkills,
232
+ listRepoSources: () => allRepoSources,
233
+ listAgentRoles: () => allAgentRoles,
234
+ listTaskFieldExtensions: () => allTaskFieldExtensions,
235
+ listTaskSources: () => allTaskSources,
236
+ listCliCommands: () => allCliCommands,
237
+ listCapabilities: () => allCapabilities,
238
+ listPanels: () => allPanels,
239
+ listBlockerClassifiers: () => allBlockerClassifiers,
240
+ listStages: () => allStages,
241
+ listStageMutations: () => allStageMutations,
242
+ listStageExecutors: () => stageExecutors,
243
+ listExecutableValidators: () => allValidators.filter((v) => typeof v.run === "function"),
244
+ listExecutableTaskSources: () => allTaskSources,
245
+ listExecutableCapabilities: () => allCapabilities.filter((c) => typeof c.run === "function"),
246
+ listExecutablePanels: () => allPanels.filter((p) => typeof p.produce === "function"),
247
+ listExecutableBlockerClassifiers: () => allBlockerClassifiers,
248
+ listExecutableCliCommands: () => allCliCommands,
249
+ listSessionExtensions: () => allSessionExtensions,
250
+ listSeedEntrypoints: () => allSeedEntrypoints,
251
+ resolveSeedEntrypointByBasename: (value) => seedEntrypointByBasename.get(value)?.item,
252
+ resolveSeedEntrypointByWorkerArg: (value) => seedEntrypointByWorkerArg.get(value)?.item,
253
+ resolveInsidePtySeedEntrypoint: () => insidePtySeedEntrypoint?.item,
254
+ resolveExecutableCliCommand: (requested) => executableCliCommandByName.get(requested)?.item,
255
+ resolveDefaultRootCliCommand: () => defaultRootCliCommand?.item,
256
+ resolveTaskSourceFactoryByKind: (kind) => taskSourceFactoryByKind.get(kind)
257
+ };
258
+ }
259
+ // packages/core/src/capability.ts
260
+ import { resolveCapability } from "@rig/kernel-seed";
261
+
262
+ class CapabilityProviderMissingError extends Error {
263
+ capabilityId;
264
+ name = "CapabilityProviderMissingError";
265
+ constructor(capabilityId) {
266
+ super(`No provider resolved for capability "${capabilityId}"`);
267
+ this.capabilityId = capabilityId;
268
+ }
269
+ }
270
+ function isFactory(impl) {
271
+ return typeof impl === "function";
272
+ }
273
+ function defineCapability(id) {
274
+ const idString = String(id);
275
+ const tag = idString;
276
+ async function resolve(host) {
277
+ const providers = host.listExecutableCapabilities().filter((c) => c.id === idString && typeof c.run === "function").map((c) => ({
278
+ name: c.id,
279
+ provides: [c.id],
280
+ capabilityProviders: { [c.id]: c.run }
281
+ }));
282
+ const resolution = resolveCapability(providers, tag);
283
+ const run = resolution?.value;
284
+ if (!run)
285
+ return null;
286
+ return await run(undefined);
287
+ }
288
+ return {
289
+ id,
290
+ provide(impl, opts) {
291
+ return {
292
+ id: idString,
293
+ title: opts?.title ?? idString,
294
+ ...opts?.description !== undefined ? { description: opts.description } : {},
295
+ run: isFactory(impl) ? () => impl() : () => impl
296
+ };
297
+ },
298
+ resolve,
299
+ async require(host) {
300
+ const value = await resolve(host);
301
+ if (value === null)
302
+ throw new CapabilityProviderMissingError(idString);
303
+ return value;
304
+ }
305
+ };
306
+ }
307
+ function defineServiceCapability(id) {
308
+ const capability = defineCapability(id);
309
+ return {
310
+ ...capability,
311
+ provideService: capability.provide,
312
+ resolveService: capability.resolve,
313
+ requireService: capability.require
314
+ };
315
+ }
316
+
317
+ // packages/core/src/index.ts
318
+ var RIG_CORE_PACKAGE = "@rig/core";
319
+ export {
320
+ defineServiceCapability,
321
+ definePlugin,
322
+ defineConfig,
323
+ defineCapability,
324
+ createPluginHost,
325
+ RIG_CORE_PACKAGE,
326
+ CapabilityProviderMissingError
327
+ };
@@ -0,0 +1,9 @@
1
+ export declare function appendJsonlRecord(path: string, value: unknown): void;
2
+ export declare function writeJsonFile(path: string, value: unknown): void;
3
+ export declare function readJsonFile<T>(path: string, fallback: T): T;
4
+ export declare function readAuthorityStateJson<T>(projectRoot: string, relativePath: string, fallback: T): T;
5
+ export declare function writeAuthorityStateJson(projectRoot: string, relativePath: string, value: unknown): string;
6
+ export declare function readAuthorityProjectStateJson<T>(projectRoot: string, relativePath: string, fallback: T): T;
7
+ export declare function writeAuthorityProjectStateJson(projectRoot: string, relativePath: string, value: unknown): string;
8
+ export declare function readJsonlFile(path: string): unknown[];
9
+ export declare function stripAuthorityRunLiveCollabFields<T extends Record<string, unknown>>(record: T): T;
@@ -0,0 +1,124 @@
1
+ // @bun
2
+ // packages/core/src/json-files.ts
3
+ import { appendFileSync, existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "fs";
4
+ import { dirname as dirname2, resolve as resolve2 } from "path";
5
+
6
+ // packages/core/src/layout.ts
7
+ import {
8
+ RIG_DEFINITION_DIRNAME,
9
+ RIG_STATE_DIRNAME
10
+ } from "@rig/contracts";
11
+
12
+ // packages/core/src/authority-paths.ts
13
+ import { existsSync } from "fs";
14
+ import { dirname, resolve } from "path";
15
+ function normalizeOptionalString(value) {
16
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
17
+ }
18
+ function resolveAuthorityStateRoot(projectRoot) {
19
+ const normalizedRoot = resolve(projectRoot);
20
+ const taskWorkspace = normalizeOptionalString(process.env.RIG_TASK_WORKSPACE);
21
+ if (taskWorkspace) {
22
+ return resolve(taskWorkspace, ".rig");
23
+ }
24
+ const stateDir = normalizeOptionalString(process.env.RIG_STATE_DIR);
25
+ if (stateDir) {
26
+ return dirname(resolve(stateDir));
27
+ }
28
+ const logsDir = normalizeOptionalString(process.env.RIG_LOGS_DIR);
29
+ if (logsDir) {
30
+ return dirname(resolve(logsDir));
31
+ }
32
+ const sessionFile = normalizeOptionalString(process.env.RIG_SESSION_FILE);
33
+ if (sessionFile) {
34
+ return dirname(dirname(resolve(sessionFile)));
35
+ }
36
+ const projectStateRoot = resolve(normalizedRoot, ".rig");
37
+ if (existsSync(projectStateRoot)) {
38
+ return projectStateRoot;
39
+ }
40
+ return resolve(normalizedRoot, ".rig");
41
+ }
42
+ function resolveAuthorityStateDir(projectRoot) {
43
+ const explicit = normalizeOptionalString(process.env.RIG_STATE_DIR);
44
+ if (explicit) {
45
+ return resolve(explicit);
46
+ }
47
+ return resolve(resolveAuthorityStateRoot(projectRoot), "state");
48
+ }
49
+ function resolveAuthorityProjectStateDir(projectRoot) {
50
+ const explicit = normalizeOptionalString(process.env.RIG_STATE_DIR);
51
+ if (explicit) {
52
+ return resolve(explicit);
53
+ }
54
+ return resolve(resolve(projectRoot), ".rig", "state");
55
+ }
56
+ // packages/core/src/json-files.ts
57
+ function appendJsonlRecord(path, value) {
58
+ mkdirSync(dirname2(path), { recursive: true });
59
+ appendFileSync(path, `${JSON.stringify(value)}
60
+ `, "utf8");
61
+ }
62
+ function writeJsonFile(path, value) {
63
+ mkdirSync(dirname2(path), { recursive: true });
64
+ writeFileSync(path, `${JSON.stringify(value, null, 2)}
65
+ `, "utf8");
66
+ }
67
+ function readJsonFile(path, fallback) {
68
+ if (!existsSync2(path))
69
+ return fallback;
70
+ try {
71
+ return JSON.parse(readFileSync(path, "utf8"));
72
+ } catch {
73
+ return fallback;
74
+ }
75
+ }
76
+ function readAuthorityStateJson(projectRoot, relativePath, fallback) {
77
+ return readJsonFile(resolve2(resolveAuthorityStateDir(projectRoot), relativePath), fallback);
78
+ }
79
+ function writeAuthorityStateJson(projectRoot, relativePath, value) {
80
+ const path = resolve2(resolveAuthorityStateDir(projectRoot), relativePath);
81
+ writeJsonFile(path, value);
82
+ return path;
83
+ }
84
+ function readAuthorityProjectStateJson(projectRoot, relativePath, fallback) {
85
+ return readJsonFile(resolve2(resolveAuthorityProjectStateDir(projectRoot), relativePath), fallback);
86
+ }
87
+ function writeAuthorityProjectStateJson(projectRoot, relativePath, value) {
88
+ const path = resolve2(resolveAuthorityProjectStateDir(projectRoot), relativePath);
89
+ writeJsonFile(path, value);
90
+ return path;
91
+ }
92
+ function readJsonlFile(path) {
93
+ if (!existsSync2(path))
94
+ return [];
95
+ return readFileSync(path, "utf8").split(/\r?\n/).map((line) => line.trim()).filter(Boolean).flatMap((line) => {
96
+ try {
97
+ return [JSON.parse(line)];
98
+ } catch {
99
+ return [];
100
+ }
101
+ });
102
+ }
103
+ function stripAuthorityRunLiveCollabFields(record) {
104
+ const {
105
+ collabLink: _collabLink,
106
+ collabWebLink: _collabWebLink,
107
+ collabRoomId: _collabRoomId,
108
+ collabRelayUrl: _collabRelayUrl,
109
+ collabToken: _collabToken,
110
+ ...rest
111
+ } = record;
112
+ return rest;
113
+ }
114
+ export {
115
+ writeJsonFile,
116
+ writeAuthorityStateJson,
117
+ writeAuthorityProjectStateJson,
118
+ stripAuthorityRunLiveCollabFields,
119
+ readJsonlFile,
120
+ readJsonFile,
121
+ readAuthorityStateJson,
122
+ readAuthorityProjectStateJson,
123
+ appendJsonlRecord
124
+ };
@@ -0,0 +1,2 @@
1
+ export { bootDefaultKernelIntoProcess, getProcessKernel, } from "@rig/kernel-seed/boot-default";
2
+ export type { DefaultKernelBootRecord } from "@rig/kernel-seed/boot-default";
@@ -0,0 +1,10 @@
1
+ // @bun
2
+ // packages/core/src/kernel-boot.ts
3
+ import {
4
+ bootDefaultKernelIntoProcess,
5
+ getProcessKernel
6
+ } from "@rig/kernel-seed/boot-default";
7
+ export {
8
+ getProcessKernel,
9
+ bootDefaultKernelIntoProcess
10
+ };
@@ -0,0 +1,22 @@
1
+ import type { JournalCapability, TransportCapability } from "@rig/contracts";
2
+ import { type DefaultKernelBootRecord } from "./kernel-boot";
3
+ import type { CapabilityProviderPlugin } from "./kernel-plugin-abi";
4
+ export type HydrationResult = {
5
+ readonly projectRoot: string;
6
+ readonly dotenvLoaded: boolean;
7
+ readonly configLoaded: boolean;
8
+ readonly errors: readonly string[];
9
+ };
10
+ export type HydrateProjectProcessEnvOptions = {
11
+ readonly env?: NodeJS.ProcessEnv;
12
+ readonly dotenvPath?: string;
13
+ };
14
+ export type AdoptKernelOptions = HydrateProjectProcessEnvOptions & {
15
+ readonly entrypoint?: string;
16
+ readonly journal?: JournalCapability;
17
+ readonly transport?: TransportCapability;
18
+ readonly hydrateEnv?: boolean;
19
+ };
20
+ export declare function createPlacementKernelTransportPlugin(transport: TransportCapability): CapabilityProviderPlugin;
21
+ export declare function hydrateProjectProcessEnv(projectRoot: string, options?: HydrateProjectProcessEnvOptions): Promise<HydrationResult>;
22
+ export declare function adopt(root?: string, options?: AdoptKernelOptions): Promise<DefaultKernelBootRecord>;