@h-rig/task-sources-plugin 0.0.6-alpha.156 → 0.0.6-alpha.158

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 (51) hide show
  1. package/dist/src/control-plane/native/github-token-env.d.ts +3 -0
  2. package/dist/src/control-plane/native/github-token-env.js +26 -0
  3. package/dist/src/control-plane/native/native-git.d.ts +18 -0
  4. package/dist/src/control-plane/native/native-git.js +291 -0
  5. package/dist/src/control-plane/native/runtime-binary-build.d.ts +9 -0
  6. package/dist/src/control-plane/native/runtime-binary-build.js +107 -0
  7. package/dist/src/control-plane/native/task-ops.d.ts +52 -0
  8. package/dist/src/control-plane/native/task-ops.js +3192 -0
  9. package/dist/src/control-plane/native/task-state.d.ts +30 -0
  10. package/dist/src/control-plane/native/task-state.js +944 -0
  11. package/dist/src/control-plane/native/utils.d.ts +7 -0
  12. package/dist/src/control-plane/native/utils.js +110 -0
  13. package/dist/src/control-plane/native/validator-binaries.d.ts +3 -0
  14. package/dist/src/control-plane/native/validator-binaries.js +175 -0
  15. package/dist/src/control-plane/native/validator.d.ts +44 -0
  16. package/dist/src/control-plane/native/validator.js +979 -0
  17. package/dist/src/control-plane/state-sync/index.d.ts +4 -0
  18. package/dist/src/control-plane/state-sync/index.js +1205 -0
  19. package/dist/src/control-plane/state-sync/native-git.d.ts +1 -0
  20. package/dist/src/control-plane/state-sync/native-git.js +281 -0
  21. package/dist/src/control-plane/state-sync/read.d.ts +46 -0
  22. package/dist/src/control-plane/state-sync/read.js +564 -0
  23. package/dist/src/control-plane/state-sync/reconcile.d.ts +28 -0
  24. package/dist/src/control-plane/state-sync/reconcile.js +260 -0
  25. package/dist/src/control-plane/state-sync/repo.d.ts +1 -0
  26. package/dist/src/control-plane/state-sync/repo.js +42 -0
  27. package/dist/src/control-plane/state-sync/types.d.ts +28 -0
  28. package/dist/src/control-plane/state-sync/types.js +111 -0
  29. package/dist/src/control-plane/state-sync/write.d.ts +83 -0
  30. package/dist/src/control-plane/state-sync/write.js +1165 -0
  31. package/dist/src/control-plane/task-data-service.d.ts +17 -0
  32. package/dist/src/control-plane/task-data-service.js +3653 -0
  33. package/dist/src/control-plane/task-fields.d.ts +1 -0
  34. package/dist/src/control-plane/task-fields.js +6 -0
  35. package/dist/src/control-plane/task-io-service.d.ts +6 -0
  36. package/dist/src/control-plane/task-io-service.js +108 -0
  37. package/dist/src/control-plane/task-source-bootstrap.d.ts +1 -0
  38. package/dist/src/control-plane/task-source-bootstrap.js +6 -0
  39. package/dist/src/control-plane/task-source.d.ts +2 -0
  40. package/dist/src/control-plane/task-source.js +6 -0
  41. package/dist/src/control-plane/tasks/legacy-task-config-source.d.ts +19 -0
  42. package/dist/src/control-plane/tasks/legacy-task-config-source.js +124 -0
  43. package/dist/src/control-plane/tasks/plugin-task-source.d.ts +30 -0
  44. package/dist/src/control-plane/tasks/plugin-task-source.js +99 -0
  45. package/dist/src/control-plane/tasks/source-aware-task-config-source.d.ts +28 -0
  46. package/dist/src/control-plane/tasks/source-aware-task-config-source.js +642 -0
  47. package/dist/src/control-plane/tasks/source-lifecycle.d.ts +56 -0
  48. package/dist/src/control-plane/tasks/source-lifecycle.js +834 -0
  49. package/dist/src/plugin.d.ts +1 -1
  50. package/dist/src/plugin.js +3927 -64
  51. package/package.json +57 -4
@@ -0,0 +1,3 @@
1
+ export declare function cleanToken(value: string | null | undefined): string | null;
2
+ export declare function authStateToken(env?: Record<string, string | undefined>): string | null;
3
+ export declare function resolveGitHubAuthToken(env?: Record<string, string | undefined>): string | null;
@@ -0,0 +1,26 @@
1
+ // @bun
2
+ // packages/task-sources-plugin/src/control-plane/native/github-token-env.ts
3
+ import { existsSync, readFileSync } from "fs";
4
+ function cleanToken(value) {
5
+ const trimmed = value?.trim() ?? "";
6
+ return trimmed.length > 0 ? trimmed : null;
7
+ }
8
+ function authStateToken(env = process.env) {
9
+ const file = env.RIG_GITHUB_AUTH_STATE_FILE?.trim();
10
+ if (!file || !existsSync(file))
11
+ return null;
12
+ try {
13
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
14
+ return cleanToken(typeof parsed.token === "string" ? parsed.token : undefined);
15
+ } catch {
16
+ return null;
17
+ }
18
+ }
19
+ function resolveGitHubAuthToken(env = process.env) {
20
+ return cleanToken(env.RIG_GITHUB_TOKEN) ?? cleanToken(env.GH_TOKEN) ?? cleanToken(env.GITHUB_TOKEN) ?? authStateToken(env);
21
+ }
22
+ export {
23
+ resolveGitHubAuthToken,
24
+ cleanToken,
25
+ authStateToken
26
+ };
@@ -0,0 +1,18 @@
1
+ export type PendingFile = {
2
+ path: string;
3
+ status: string;
4
+ };
5
+ export type TreeCommitUpdate = {
6
+ path: string;
7
+ content: string;
8
+ sourceFilePath?: never;
9
+ } | {
10
+ path: string;
11
+ sourceFilePath: string;
12
+ content?: never;
13
+ };
14
+ export declare function nativePendingFiles(repoPath: string): PendingFile[] | null;
15
+ export declare function nativeFetchRef(repoPath: string, remote: string, branch: string): string;
16
+ export declare function nativeReadBlobAtRef(repoPath: string, ref: string, path: string): string;
17
+ export declare function nativeWriteTreeCommit(repoPath: string, baseRef: string, updates: TreeCommitUpdate[], message: string): string;
18
+ export declare function nativePushRefWithLease(repoPath: string, localOid: string, remoteRef: string, expectedOldOid: string, remote?: string): string;
@@ -0,0 +1,291 @@
1
+ // @bun
2
+ // packages/task-sources-plugin/src/control-plane/native/native-git.ts
3
+ import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "fs";
4
+ import { tmpdir } from "os";
5
+ import { dirname, isAbsolute, resolve } from "path";
6
+ import { createHash } from "crypto";
7
+ var taskSourcesGitNativeOutputDir = resolve(tmpdir(), "rig-task-sources-native");
8
+ var taskSourcesGitNativeOutputPath = resolve(taskSourcesGitNativeOutputDir, `rig-git-${process.platform}-${process.arch}${process.platform === "win32" ? ".exe" : ""}`);
9
+ var trackerCommandUsageProbe = "usage: rig-git fetch-ref <repo-path> <remote> <branch>";
10
+ function nativePendingFiles(repoPath) {
11
+ const result = runGitNative("pending-files", [repoPath]);
12
+ if (!result.ok)
13
+ return null;
14
+ if ("files" in result && Array.isArray(result.files)) {
15
+ return result.files.map((file) => ({ path: file.path, status: file.status }));
16
+ }
17
+ return null;
18
+ }
19
+ function nativeFetchRef(repoPath, remote, branch) {
20
+ return requireGitNativeString("fetch-ref", [repoPath, remote, branch]);
21
+ }
22
+ function nativeReadBlobAtRef(repoPath, ref, path) {
23
+ const requestDir = resolve(taskSourcesGitNativeOutputDir, "reads", `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`);
24
+ mkdirSync(requestDir, { recursive: true });
25
+ const outputPath = resolve(requestDir, "blob.txt");
26
+ try {
27
+ requireGitNative("read-blob-at-ref", [repoPath, ref, path, outputPath]);
28
+ return readFileSync(outputPath, "utf8");
29
+ } finally {
30
+ rmSync(requestDir, { recursive: true, force: true });
31
+ }
32
+ }
33
+ function nativeWriteTreeCommit(repoPath, baseRef, updates, message) {
34
+ const requestDir = resolve(taskSourcesGitNativeOutputDir, "requests", `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`);
35
+ mkdirSync(requestDir, { recursive: true });
36
+ const messagePath = resolve(requestDir, "message.txt");
37
+ const updatesPath = resolve(requestDir, "updates.json");
38
+ try {
39
+ writeFileSync(messagePath, message, "utf8");
40
+ writeFileSync(updatesPath, `${JSON.stringify(serializeTreeCommitUpdates(updates), null, 2)}
41
+ `, "utf8");
42
+ return requireGitNativeString("write-tree-commit", [repoPath, baseRef, messagePath, updatesPath]);
43
+ } finally {
44
+ rmSync(requestDir, { recursive: true, force: true });
45
+ }
46
+ }
47
+ function nativePushRefWithLease(repoPath, localOid, remoteRef, expectedOldOid, remote = "origin") {
48
+ return requireGitNativeString("push-ref-with-lease", [repoPath, localOid, remoteRef, expectedOldOid, remote]);
49
+ }
50
+ function runGitNative(command, args) {
51
+ if (process.env.RIG_DISABLE_ZIG_NATIVE === "1") {
52
+ return { ok: false, error: "rig-git native disabled" };
53
+ }
54
+ let binaryPath;
55
+ try {
56
+ binaryPath = resolveGitBinaryPath() ?? ensureRigGitBinaryPathSync(preferredGitBinaryOutputPath());
57
+ } catch (error) {
58
+ const message = error instanceof Error ? error.message : String(error);
59
+ return { ok: false, error: message.includes("rig-git.zig source file not found") ? "rig-git binary not found" : message };
60
+ }
61
+ try {
62
+ const proc = Bun.spawnSync([binaryPath, command, ...args], {
63
+ stdout: "pipe",
64
+ stderr: "pipe",
65
+ env: gitNativeEnv()
66
+ });
67
+ if (proc.exitCode !== 0) {
68
+ const stdoutText = proc.stdout.toString().trim();
69
+ if (stdoutText) {
70
+ try {
71
+ const parsed = JSON.parse(stdoutText);
72
+ if (!parsed.ok) {
73
+ return parsed;
74
+ }
75
+ } catch {}
76
+ }
77
+ const error = proc.stderr.toString().trim() || `exit code ${proc.exitCode}`;
78
+ return { ok: false, error };
79
+ }
80
+ return JSON.parse(proc.stdout.toString().trim());
81
+ } catch (error) {
82
+ return { ok: false, error: String(error) };
83
+ }
84
+ }
85
+ function requireGitNative(command, args) {
86
+ const result = runGitNative(command, args);
87
+ if (!result.ok) {
88
+ throw new Error(`rig-git ${command} failed: ${result.error}`);
89
+ }
90
+ return result;
91
+ }
92
+ function requireGitNativeString(command, args) {
93
+ const result = requireGitNative(command, args);
94
+ if ("value" in result && typeof result.value === "string") {
95
+ return result.value;
96
+ }
97
+ throw new Error(`rig-git ${command} returned an unexpected result payload`);
98
+ }
99
+ function serializeTreeCommitUpdates(updates) {
100
+ return updates.map((update) => {
101
+ if (typeof update.content === "string") {
102
+ return { path: update.path, kind: "text", content: update.content };
103
+ }
104
+ if (!isAbsolute(update.sourceFilePath)) {
105
+ throw new Error("tree commit binary updates require an absolute sourceFilePath");
106
+ }
107
+ return { path: update.path, kind: "file", sourceFilePath: update.sourceFilePath };
108
+ });
109
+ }
110
+ function gitNativeEnv() {
111
+ const env = { ...process.env };
112
+ const token = env.GITHUB_TOKEN?.trim() || env.GH_TOKEN?.trim() || env.RIG_GITHUB_TOKEN?.trim() || "";
113
+ if (token) {
114
+ env.RIG_GITHUB_TOKEN = env.RIG_GITHUB_TOKEN || token;
115
+ env.GITHUB_TOKEN = env.GITHUB_TOKEN || token;
116
+ env.GH_TOKEN = env.GH_TOKEN || token;
117
+ env.GIT_TERMINAL_PROMPT = "0";
118
+ env.GIT_CONFIG_COUNT = "2";
119
+ env.GIT_CONFIG_KEY_0 = "credential.helper";
120
+ env.GIT_CONFIG_VALUE_0 = "";
121
+ env.GIT_CONFIG_KEY_1 = "credential.helper";
122
+ env.GIT_CONFIG_VALUE_1 = '!f() { test "$1" = get || exit 0; token="${GITHUB_TOKEN:-${GH_TOKEN:-${RIG_GITHUB_TOKEN:-}}}"; test -n "$token" || exit 0; echo username=x-access-token; echo password="$token"; }; f';
123
+ }
124
+ return env;
125
+ }
126
+ function runtimeRigGitFileName() {
127
+ return `rig-git${process.platform === "win32" ? ".exe" : ""}`;
128
+ }
129
+ function preferredGitBinaryOutputPath() {
130
+ const explicit = process.env.RIG_NATIVE_GIT_BIN?.trim() || "";
131
+ return explicit || taskSourcesGitNativeOutputPath;
132
+ }
133
+ function resolveGitBinaryPath() {
134
+ const explicit = process.env.RIG_NATIVE_GIT_BIN?.trim() || "";
135
+ if (explicit && existsSync(explicit)) {
136
+ return explicit;
137
+ }
138
+ if (explicit) {
139
+ return null;
140
+ }
141
+ for (const candidate of rigGitBinaryCandidates()) {
142
+ if (candidate && existsSync(candidate)) {
143
+ return candidate;
144
+ }
145
+ }
146
+ return null;
147
+ }
148
+ function ensureRigGitBinaryPathSync(outputPath = taskSourcesGitNativeOutputPath) {
149
+ const explicit = process.env.RIG_NATIVE_GIT_BIN?.trim() || "";
150
+ if (explicit && existsSync(explicit)) {
151
+ return explicit;
152
+ }
153
+ const sourcePath = resolveGitSourcePath();
154
+ if (!sourcePath) {
155
+ const binaryPath = resolveGitBinaryPath();
156
+ if (binaryPath) {
157
+ return binaryPath;
158
+ }
159
+ throw new Error("rig-git.zig source file not found.");
160
+ }
161
+ const zigBinary = Bun.which("zig");
162
+ if (!zigBinary) {
163
+ throw new Error("zig is required to build native Rig git tools.");
164
+ }
165
+ mkdirSync(dirname(outputPath), { recursive: true });
166
+ const buildKey = JSON.stringify({
167
+ version: 1,
168
+ zigBinary,
169
+ platform: process.platform,
170
+ arch: process.arch,
171
+ sourcePath,
172
+ sourceDigest: createHash("sha256").update(readFileSync(sourcePath)).digest("hex")
173
+ });
174
+ const manifestPath = `${outputPath}.build-manifest.json`;
175
+ if (nativeBuildIsFresh(outputPath, manifestPath, buildKey)) {
176
+ chmodSync(outputPath, 493);
177
+ return outputPath;
178
+ }
179
+ const tempOutputPath = resolve(dirname(outputPath), `.rig-git-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}${process.platform === "win32" ? ".exe" : ""}`);
180
+ const build = Bun.spawnSync([
181
+ zigBinary,
182
+ "build-exe",
183
+ sourcePath,
184
+ "-O",
185
+ "ReleaseFast",
186
+ `-femit-bin=${tempOutputPath}`
187
+ ], {
188
+ cwd: dirname(sourcePath),
189
+ stdout: "pipe",
190
+ stderr: "pipe"
191
+ });
192
+ if (build.exitCode !== 0 || !existsSync(tempOutputPath)) {
193
+ const details = [build.stderr.toString().trim(), build.stdout.toString().trim()].filter(Boolean).join(`
194
+ `);
195
+ throw new Error(`Failed to build native Rig git tools: ${details || `zig exited with code ${build.exitCode}`}`);
196
+ }
197
+ chmodSync(tempOutputPath, 493);
198
+ renameSync(tempOutputPath, outputPath);
199
+ if (!binarySupportsTrackerCommands(outputPath)) {
200
+ rmSync(outputPath, { force: true });
201
+ throw new Error("Failed to build native Rig git tools: tracker command probe failed");
202
+ }
203
+ writeFileSync(manifestPath, `${JSON.stringify({ version: 1, buildKey }, null, 2)}
204
+ `, "utf8");
205
+ return outputPath;
206
+ }
207
+ function nativeBuildIsFresh(outputPath, manifestPath, buildKey) {
208
+ if (!existsSync(outputPath) || !existsSync(manifestPath)) {
209
+ return false;
210
+ }
211
+ try {
212
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
213
+ return manifest.version === 1 && manifest.buildKey === buildKey && binarySupportsTrackerCommands(outputPath);
214
+ } catch {
215
+ return false;
216
+ }
217
+ }
218
+ function binarySupportsTrackerCommands(binaryPath) {
219
+ try {
220
+ const probe = Bun.spawnSync([binaryPath, "fetch-ref", "."], {
221
+ stdout: "pipe",
222
+ stderr: "pipe"
223
+ });
224
+ const stdout = probe.stdout.toString().trim();
225
+ const stderr = probe.stderr.toString().trim();
226
+ if (stdout.includes('"error":"unknown command"')) {
227
+ return false;
228
+ }
229
+ return probe.exitCode === 2 && stderr.includes(trackerCommandUsageProbe);
230
+ } catch {
231
+ return false;
232
+ }
233
+ }
234
+ function resolveGitSourcePath() {
235
+ for (const candidate of rigGitSourceCandidates()) {
236
+ if (candidate && existsSync(candidate)) {
237
+ return candidate;
238
+ }
239
+ }
240
+ return null;
241
+ }
242
+ function rigGitSourceCandidates() {
243
+ const execDir = process.execPath?.trim() ? dirname(process.execPath.trim()) : "";
244
+ const cwd = process.cwd()?.trim() || "";
245
+ const projectRoot = process.env.PROJECT_RIG_ROOT?.trim() || "";
246
+ const hostProjectRoot = process.env.RIG_HOST_PROJECT_ROOT?.trim() || "";
247
+ return [...new Set([
248
+ process.env.RIG_NATIVE_GIT_SOURCE?.trim() || "",
249
+ resolve(import.meta.dir, "../../../native/rig-git.zig"),
250
+ projectRoot ? resolve(projectRoot, "packages/task-sources-plugin/native/rig-git.zig") : "",
251
+ projectRoot ? resolve(projectRoot, "packages/isolation-plugin/native/rig-git.zig") : "",
252
+ projectRoot ? resolve(projectRoot, "packages/shared/native/rig-git.zig") : "",
253
+ hostProjectRoot ? resolve(hostProjectRoot, "packages/task-sources-plugin/native/rig-git.zig") : "",
254
+ hostProjectRoot ? resolve(hostProjectRoot, "packages/isolation-plugin/native/rig-git.zig") : "",
255
+ hostProjectRoot ? resolve(hostProjectRoot, "packages/shared/native/rig-git.zig") : "",
256
+ cwd ? resolve(cwd, "packages/task-sources-plugin/native/rig-git.zig") : "",
257
+ cwd ? resolve(cwd, "packages/isolation-plugin/native/rig-git.zig") : "",
258
+ cwd ? resolve(cwd, "packages/shared/native/rig-git.zig") : "",
259
+ execDir ? resolve(execDir, "..", "native", "rig-git.zig") : ""
260
+ ].filter(Boolean))];
261
+ }
262
+ function rigGitBinaryCandidates() {
263
+ const execDir = process.execPath?.trim() ? dirname(process.execPath.trim()) : "";
264
+ const fileName = runtimeRigGitFileName();
265
+ return [...new Set([
266
+ ...nativePackageBinaryCandidates(import.meta.dir, fileName),
267
+ execDir ? resolve(execDir, fileName) : "",
268
+ execDir ? resolve(execDir, "..", fileName) : "",
269
+ execDir ? resolve(execDir, "..", "bin", fileName) : "",
270
+ taskSourcesGitNativeOutputPath
271
+ ].filter(Boolean))];
272
+ }
273
+ function nativePackageBinaryCandidates(fromDir, fileName) {
274
+ const candidates = [];
275
+ let cursor = resolve(fromDir);
276
+ for (let index = 0;index < 8; index += 1) {
277
+ candidates.push(resolve(cursor, "native", `${process.platform}-${process.arch}`, fileName), resolve(cursor, "native", `${process.platform}-${process.arch}`, "bin", fileName), resolve(cursor, "native", fileName), resolve(cursor, "native", "bin", fileName));
278
+ const parent = dirname(cursor);
279
+ if (parent === cursor)
280
+ break;
281
+ cursor = parent;
282
+ }
283
+ return candidates;
284
+ }
285
+ export {
286
+ nativeWriteTreeCommit,
287
+ nativeReadBlobAtRef,
288
+ nativePushRefWithLease,
289
+ nativePendingFiles,
290
+ nativeFetchRef
291
+ };
@@ -0,0 +1,9 @@
1
+ export type RuntimeBinaryBuildOptions = {
2
+ sourcePath: string;
3
+ outputPath: string;
4
+ cwd: string;
5
+ define?: Record<string, string>;
6
+ env?: Record<string, string | undefined>;
7
+ external?: string[];
8
+ };
9
+ export declare function buildRuntimeBinary(options: RuntimeBinaryBuildOptions): Promise<void>;
@@ -0,0 +1,107 @@
1
+ // @bun
2
+ // packages/task-sources-plugin/src/control-plane/native/runtime-binary-build.ts
3
+ import { chmodSync, existsSync, mkdirSync, renameSync, rmSync } from "fs";
4
+ import { basename, dirname, isAbsolute, resolve } from "path";
5
+ var runtimeBinaryBuildQueue = Promise.resolve();
6
+ async function buildRuntimeBinary(options) {
7
+ await runSerializedRuntimeBinaryBuild(async () => {
8
+ const entrypoint = isAbsolute(options.sourcePath) ? options.sourcePath : resolve(options.cwd, options.sourcePath);
9
+ const outputPath = resolve(options.outputPath);
10
+ const tempBuildDir = resolve(dirname(outputPath), `.bun-build-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`);
11
+ const tempOutputPath = resolve(tempBuildDir, basename(outputPath));
12
+ mkdirSync(tempBuildDir, { recursive: true });
13
+ await withTemporaryEnv({
14
+ ...options.env,
15
+ ...options.define ? { RIG_BUILD_CONFIG_JSON: JSON.stringify(options.define) } : {}
16
+ }, async () => withTemporaryCwd(tempBuildDir, async () => {
17
+ const buildResult = await Bun.build({
18
+ entrypoints: [entrypoint],
19
+ compile: {
20
+ target: currentCompileTarget(),
21
+ outfile: tempOutputPath
22
+ },
23
+ target: "bun",
24
+ format: "esm",
25
+ minify: true,
26
+ bytecode: true,
27
+ ...options.external ? { external: options.external } : {},
28
+ ...options.define ? { define: { __RIG_BUILD_CONFIG__: JSON.stringify(options.define) } } : {}
29
+ });
30
+ if (!buildResult.success) {
31
+ const details = buildResult.logs.map((log) => [
32
+ log.message,
33
+ log.position?.file ? `${log.position.file}:${log.position.line}:${log.position.column}` : ""
34
+ ].filter(Boolean).join(" ")).filter(Boolean).join(`
35
+ `);
36
+ throw new Error(`Failed to build ${entrypoint}: ${details || "Bun.build() returned errors"}`);
37
+ }
38
+ if (!existsSync(tempOutputPath)) {
39
+ const emitted = buildResult.outputs.map((output) => output.path).join(", ") || "(none)";
40
+ throw new Error(`Failed to build ${entrypoint}: Bun.build() did not emit ${tempOutputPath}. Emitted: ${emitted}`);
41
+ }
42
+ renameSync(tempOutputPath, outputPath);
43
+ chmodSync(outputPath, 493);
44
+ })).finally(() => {
45
+ rmSync(tempBuildDir, { recursive: true, force: true });
46
+ });
47
+ });
48
+ }
49
+ function currentCompileTarget() {
50
+ if (process.platform === "darwin") {
51
+ return process.arch === "arm64" ? "bun-darwin-arm64" : "bun-darwin-x64";
52
+ }
53
+ if (process.platform === "linux") {
54
+ return process.arch === "arm64" ? "bun-linux-arm64" : "bun-linux-x64";
55
+ }
56
+ return "bun-windows-x64";
57
+ }
58
+ async function runSerializedRuntimeBinaryBuild(action) {
59
+ const previous = runtimeBinaryBuildQueue;
60
+ let release;
61
+ runtimeBinaryBuildQueue = new Promise((resolveRelease) => {
62
+ release = resolveRelease;
63
+ });
64
+ await previous;
65
+ try {
66
+ return await action();
67
+ } finally {
68
+ release();
69
+ }
70
+ }
71
+ async function withTemporaryEnv(env, action) {
72
+ if (!env) {
73
+ return action();
74
+ }
75
+ const previousValues = new Map;
76
+ for (const [key, value] of Object.entries(env)) {
77
+ previousValues.set(key, process.env[key]);
78
+ if (value === undefined) {
79
+ delete process.env[key];
80
+ } else {
81
+ process.env[key] = value;
82
+ }
83
+ }
84
+ try {
85
+ return await action();
86
+ } finally {
87
+ for (const [key, value] of previousValues.entries()) {
88
+ if (value === undefined) {
89
+ delete process.env[key];
90
+ } else {
91
+ process.env[key] = value;
92
+ }
93
+ }
94
+ }
95
+ }
96
+ async function withTemporaryCwd(cwd, action) {
97
+ const previousCwd = process.cwd();
98
+ process.chdir(cwd);
99
+ try {
100
+ return await action();
101
+ } finally {
102
+ process.chdir(previousCwd);
103
+ }
104
+ }
105
+ export {
106
+ buildRuntimeBinary
107
+ };
@@ -0,0 +1,52 @@
1
+ import type { RuntimeInstructionProvider } from "@rig/contracts";
2
+ import type { ValidatorRegistry } from "@rig/validator-kit";
3
+ export declare function taskInfo(projectRoot: string, taskId?: string, runtimeProviderOverride?: RuntimeInstructionProvider): Promise<void>;
4
+ export declare function taskReady(projectRoot: string): Promise<void>;
5
+ export declare function taskScope(projectRoot: string, expandFiles: boolean, taskId?: string): Promise<void>;
6
+ export declare function taskDeps(projectRoot: string, taskId?: string): Promise<void>;
7
+ export declare function taskStatus(projectRoot: string): void;
8
+ export declare function taskLookup(projectRoot: string, id: string): string;
9
+ export declare function taskRecord(projectRoot: string, type: "decision" | "failure", text: string, taskId?: string): void;
10
+ export declare function taskArtifacts(projectRoot: string, taskId?: string): void;
11
+ /**
12
+ * Print the absolute artifact directory path for the current task.
13
+ * CWD-safe — always resolves from project root, not relative paths.
14
+ */
15
+ export declare function taskArtifactDir(projectRoot: string, taskId?: string): string;
16
+ /**
17
+ * Write an artifact file to the task's artifact directory.
18
+ * Handles all path resolution so agents don't need to care about CWD.
19
+ *
20
+ * @param content - File content to write
21
+ * @param filename - Target filename (e.g. "collection-audit.md")
22
+ */
23
+ export declare function taskArtifactWrite(projectRoot: string, filename: string, content: string, taskId?: string): void;
24
+ export type TaskArtifactReadResult = {
25
+ path: string;
26
+ sizeBytes: number;
27
+ contents: string;
28
+ truncated: boolean;
29
+ maxBytes: number;
30
+ };
31
+ export declare function taskArtifactRead(projectRoot: string, filename: string, options?: {
32
+ taskId?: string;
33
+ maxBytes?: number;
34
+ }): TaskArtifactReadResult;
35
+ export declare function taskValidate(projectRoot: string, taskId?: string, validatorRegistry?: ValidatorRegistry): Promise<boolean>;
36
+ export type TaskReopenSummary = {
37
+ mode: "all" | "single";
38
+ requestedTaskId: string | null;
39
+ dryRun: boolean;
40
+ closedFound: number;
41
+ reopened: string[];
42
+ failed: string[];
43
+ skipped: string[];
44
+ };
45
+ export declare function taskReopen(projectRoot: string, options: {
46
+ all: boolean;
47
+ taskId?: string;
48
+ dryRun?: boolean;
49
+ }): TaskReopenSummary;
50
+ export declare function taskDependencyIds(projectRoot: string, taskId: string): string[];
51
+ export declare function changedFilesForTask(projectRoot: string, taskId: string, scoped: boolean): string[];
52
+ export declare function pendingFilesForTask(projectRoot: string, taskId: string, scoped: boolean): string[];