@h-rig/cli 0.0.6-alpha.27 → 0.0.6-alpha.280

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 (52) hide show
  1. package/README.md +6 -28
  2. package/package.json +11 -28
  3. package/dist/bin/build-rig-binaries.js +0 -107
  4. package/dist/bin/rig.js +0 -11321
  5. package/dist/src/commands/_authority-runs.js +0 -111
  6. package/dist/src/commands/_cli-format.js +0 -164
  7. package/dist/src/commands/_connection-state.js +0 -123
  8. package/dist/src/commands/_doctor-checks.js +0 -507
  9. package/dist/src/commands/_help-catalog.js +0 -203
  10. package/dist/src/commands/_operator-surface.js +0 -204
  11. package/dist/src/commands/_operator-view.js +0 -1147
  12. package/dist/src/commands/_parsers.js +0 -107
  13. package/dist/src/commands/_paths.js +0 -50
  14. package/dist/src/commands/_pi-frontend.js +0 -843
  15. package/dist/src/commands/_pi-install.js +0 -185
  16. package/dist/src/commands/_pi-worker-bridge-extension.js +0 -761
  17. package/dist/src/commands/_policy.js +0 -79
  18. package/dist/src/commands/_preflight.js +0 -403
  19. package/dist/src/commands/_probes.js +0 -13
  20. package/dist/src/commands/_run-driver-helpers.js +0 -289
  21. package/dist/src/commands/_server-client.js +0 -514
  22. package/dist/src/commands/_snapshot-upload.js +0 -318
  23. package/dist/src/commands/_task-picker.js +0 -76
  24. package/dist/src/commands/agent.js +0 -499
  25. package/dist/src/commands/browser.js +0 -890
  26. package/dist/src/commands/connect.js +0 -288
  27. package/dist/src/commands/dist.js +0 -402
  28. package/dist/src/commands/doctor.js +0 -517
  29. package/dist/src/commands/github.js +0 -281
  30. package/dist/src/commands/inbox.js +0 -160
  31. package/dist/src/commands/init.js +0 -1563
  32. package/dist/src/commands/inspect.js +0 -174
  33. package/dist/src/commands/inspector.js +0 -256
  34. package/dist/src/commands/plugin.js +0 -167
  35. package/dist/src/commands/profile-and-review.js +0 -178
  36. package/dist/src/commands/queue.js +0 -198
  37. package/dist/src/commands/remote.js +0 -507
  38. package/dist/src/commands/repo-git-harness.js +0 -221
  39. package/dist/src/commands/run.js +0 -1688
  40. package/dist/src/commands/server.js +0 -571
  41. package/dist/src/commands/setup.js +0 -687
  42. package/dist/src/commands/task-report-bug.js +0 -1083
  43. package/dist/src/commands/task-run-driver.js +0 -2600
  44. package/dist/src/commands/task.js +0 -2200
  45. package/dist/src/commands/test.js +0 -39
  46. package/dist/src/commands/workspace.js +0 -123
  47. package/dist/src/commands.js +0 -11000
  48. package/dist/src/index.js +0 -11339
  49. package/dist/src/launcher.js +0 -133
  50. package/dist/src/report-bug.js +0 -260
  51. package/dist/src/runner.js +0 -273
  52. package/dist/src/withMutedConsole.js +0 -42
@@ -1,79 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/_policy.ts
3
- import { appendFileSync, mkdirSync } from "fs";
4
- import { resolve } from "path";
5
-
6
- // packages/cli/src/runner.ts
7
- import { EventBus } from "@rig/runtime/control-plane/runtime/events";
8
- import { CliError } from "@rig/runtime/control-plane/errors";
9
- import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
10
- import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
11
- import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
12
- import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
13
- import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
14
- function formatCommand(parts) {
15
- return parts.map((part) => /[^a-zA-Z0-9_./:-]/.test(part) ? JSON.stringify(part) : part).join(" ");
16
- }
17
-
18
- // packages/cli/src/commands/_policy.ts
19
- import { evaluate as evaluate2, loadPolicy as loadPolicy2, resolveAction as resolveAction2 } from "@rig/runtime/control-plane/runtime/guard";
20
- import { resolveHarnessPaths } from "@rig/runtime/control-plane/native/utils";
21
- function resolveEffectivePolicyMode(context) {
22
- const envMode = process.env.RIG_BASH_MODE;
23
- if (envMode === "off" || envMode === "observe" || envMode === "enforce") {
24
- return envMode;
25
- }
26
- return context.policyMode || loadPolicy2(context.projectRoot).mode;
27
- }
28
- function appendControlledBashAudit(context, mode, command, args, matchedRuleIds, action) {
29
- if (mode === "off") {
30
- return;
31
- }
32
- const logsDir = resolveHarnessPaths(context.projectRoot).logsDir;
33
- const logFile = resolve(logsDir, "controlled-bash.jsonl");
34
- mkdirSync(logsDir, { recursive: true });
35
- const payload = {
36
- timestamp: new Date().toISOString(),
37
- mode,
38
- cwd: process.cwd(),
39
- pid: process.pid,
40
- ppid: process.ppid,
41
- argv: args,
42
- command,
43
- matchedRuleIds
44
- };
45
- if (action) {
46
- payload.action = action;
47
- }
48
- appendFileSync(logFile, `${JSON.stringify(payload)}
49
- `, "utf-8");
50
- }
51
- async function enforceNativeCommandPolicy(context, args, options) {
52
- const mode = resolveEffectivePolicyMode(context);
53
- const command = formatCommand([options.commandPrefix, ...args]);
54
- const decision = evaluate2({
55
- projectRoot: context.projectRoot,
56
- evaluation: { type: "command", command }
57
- });
58
- const action = resolveAction2(mode, decision.matchedRules);
59
- const matchedRuleIds = decision.matchedRules.map((rule) => rule.id);
60
- await context.emitEvent("policy.decision", {
61
- target: "command",
62
- command,
63
- mode,
64
- allowed: action !== "block",
65
- matchedRuleIds,
66
- reasons: decision.matchedRules.map((rule) => rule.reason)
67
- });
68
- if (options.writeAuditLog) {
69
- appendControlledBashAudit(context, mode, command, args, matchedRuleIds, action === "block" ? "blocked" : action === "warn" ? "warn" : undefined);
70
- }
71
- if (action === "block") {
72
- throw new CliError2(`Policy blocked command: ${command}`, 126);
73
- }
74
- }
75
- export {
76
- resolveEffectivePolicyMode,
77
- enforceNativeCommandPolicy,
78
- appendControlledBashAudit
79
- };
@@ -1,403 +0,0 @@
1
- // @bun
2
- // packages/cli/src/runner.ts
3
- import { EventBus } from "@rig/runtime/control-plane/runtime/events";
4
- import { CliError } from "@rig/runtime/control-plane/errors";
5
- import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
6
- import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
7
- import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
8
- import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
9
- import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
10
-
11
- // packages/cli/src/commands/_preflight.ts
12
- import { ensureProjectMainFreshBeforeRun } from "@rig/runtime/control-plane/project-main-pre-run-sync";
13
-
14
- // packages/cli/src/commands/_connection-state.ts
15
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
16
- import { homedir } from "os";
17
- import { dirname, resolve } from "path";
18
- function resolveGlobalConnectionsPath(env = process.env) {
19
- const explicit = env.RIG_CONNECTIONS_FILE?.trim();
20
- if (explicit)
21
- return resolve(explicit);
22
- const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
23
- if (stateDir)
24
- return resolve(stateDir, "connections.json");
25
- return resolve(homedir(), ".rig", "connections.json");
26
- }
27
- function resolveRepoConnectionPath(projectRoot) {
28
- return resolve(projectRoot, ".rig", "state", "connection.json");
29
- }
30
- function readJsonFile(path) {
31
- if (!existsSync(path))
32
- return null;
33
- try {
34
- return JSON.parse(readFileSync(path, "utf8"));
35
- } catch (error) {
36
- throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
37
- }
38
- }
39
- function normalizeConnection(value) {
40
- if (!value || typeof value !== "object" || Array.isArray(value))
41
- return null;
42
- const record = value;
43
- if (record.kind === "local")
44
- return { kind: "local", mode: "auto" };
45
- if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
46
- const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
47
- return { kind: "remote", baseUrl };
48
- }
49
- return null;
50
- }
51
- function readGlobalConnections(options = {}) {
52
- const path = resolveGlobalConnectionsPath(options.env ?? process.env);
53
- const payload = readJsonFile(path);
54
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
55
- return { connections: {} };
56
- }
57
- const rawConnections = payload.connections;
58
- const connections = {};
59
- if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
60
- for (const [alias, raw] of Object.entries(rawConnections)) {
61
- const connection = normalizeConnection(raw);
62
- if (connection)
63
- connections[alias] = connection;
64
- }
65
- }
66
- return { connections };
67
- }
68
- function readRepoConnection(projectRoot) {
69
- const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
70
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
71
- return null;
72
- const record = payload;
73
- const selected = typeof record.selected === "string" ? record.selected.trim() : "";
74
- if (!selected)
75
- return null;
76
- return {
77
- selected,
78
- project: typeof record.project === "string" ? record.project : undefined,
79
- linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
80
- };
81
- }
82
- function resolveSelectedConnection(projectRoot, options = {}) {
83
- const repo = readRepoConnection(projectRoot);
84
- if (!repo)
85
- return null;
86
- if (repo.selected === "local")
87
- return { alias: "local", connection: { kind: "local", mode: "auto" } };
88
- const global = readGlobalConnections(options);
89
- const connection = global.connections[repo.selected];
90
- if (!connection) {
91
- throw new CliError2(`Selected Rig connection "${repo.selected}" was not found. Run \`rig connect list\` or \`rig connect use local\`.`, 1);
92
- }
93
- return { alias: repo.selected, connection };
94
- }
95
-
96
- // packages/cli/src/commands/_server-client.ts
97
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
98
- import { resolve as resolve2 } from "path";
99
- import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
100
- var scopedGitHubBearerTokens = new Map;
101
- function cleanToken(value) {
102
- const trimmed = value?.trim();
103
- return trimmed ? trimmed : null;
104
- }
105
- function readPrivateRemoteSessionToken(projectRoot) {
106
- const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
107
- if (!existsSync2(path))
108
- return null;
109
- try {
110
- const parsed = JSON.parse(readFileSync2(path, "utf8"));
111
- return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
112
- } catch {
113
- return null;
114
- }
115
- }
116
- function readGitHubBearerTokenForRemote(projectRoot) {
117
- const scopedKey = resolve2(projectRoot);
118
- if (scopedGitHubBearerTokens.has(scopedKey))
119
- return scopedGitHubBearerTokens.get(scopedKey) ?? null;
120
- const privateSession = readPrivateRemoteSessionToken(projectRoot);
121
- if (privateSession)
122
- return privateSession;
123
- return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
124
- }
125
- async function ensureServerForCli(projectRoot) {
126
- try {
127
- const selected = resolveSelectedConnection(projectRoot);
128
- if (selected?.connection.kind === "remote") {
129
- return {
130
- baseUrl: selected.connection.baseUrl,
131
- authToken: readGitHubBearerTokenForRemote(projectRoot),
132
- connectionKind: "remote"
133
- };
134
- }
135
- const connection = await ensureLocalRigServerConnection(projectRoot);
136
- return {
137
- baseUrl: connection.baseUrl,
138
- authToken: connection.authToken,
139
- connectionKind: "local"
140
- };
141
- } catch (error) {
142
- if (error instanceof Error) {
143
- throw new CliError2(error.message, 1);
144
- }
145
- throw error;
146
- }
147
- }
148
- function mergeHeaders(headers, authToken) {
149
- const merged = new Headers(headers);
150
- if (authToken) {
151
- merged.set("authorization", `Bearer ${authToken}`);
152
- }
153
- return merged;
154
- }
155
- function diagnosticMessage(payload) {
156
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
157
- return null;
158
- const record = payload;
159
- const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
160
- const messages = diagnostics.flatMap((entry) => {
161
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
162
- return [];
163
- const diagnostic = entry;
164
- const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
165
- const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
166
- return message ? [`${kind}: ${message}`] : [];
167
- });
168
- return messages.length > 0 ? messages.join("; ") : null;
169
- }
170
- async function requestServerJson(context, pathname, init = {}) {
171
- const server = await ensureServerForCli(context.projectRoot);
172
- const response = await fetch(`${server.baseUrl}${pathname}`, {
173
- ...init,
174
- headers: mergeHeaders(init.headers, server.authToken)
175
- });
176
- const text = await response.text();
177
- const payload = text.trim().length > 0 ? (() => {
178
- try {
179
- return JSON.parse(text);
180
- } catch {
181
- return null;
182
- }
183
- })() : null;
184
- if (!response.ok) {
185
- const diagnostics = diagnosticMessage(payload);
186
- const detail = diagnostics ?? (text || response.statusText);
187
- throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
188
- }
189
- return payload;
190
- }
191
-
192
- // packages/cli/src/commands/_preflight.ts
193
- function preflightCheck(id, label, status, detail, remediation) {
194
- return {
195
- id,
196
- label,
197
- status,
198
- ...detail ? { detail } : {},
199
- ...remediation ? { remediation } : {}
200
- };
201
- }
202
- function message(error) {
203
- return error instanceof Error ? error.message : String(error);
204
- }
205
- function isAuthenticated(payload) {
206
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
207
- return false;
208
- const record = payload;
209
- return record.signedIn === true || record.authenticated === true || record.status === "authenticated" || record.ok === true && typeof record.login === "string" && record.login.trim().length > 0;
210
- }
211
- function taskMatchesId(entry, taskId) {
212
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
213
- return false;
214
- const record = entry;
215
- if (record.id === taskId || record.taskId === taskId)
216
- return true;
217
- const raw = record.raw;
218
- if (raw && typeof raw === "object" && !Array.isArray(raw)) {
219
- const rawRecord = raw;
220
- if (String(rawRecord.number ?? "") === taskId.replace(/^#/, ""))
221
- return true;
222
- }
223
- return false;
224
- }
225
- function isActiveRunStatus(status) {
226
- const normalized = String(status ?? "running").toLowerCase();
227
- return !["completed", "complete", "done", "merged", "closed", "failed", "cancelled", "canceled", "needs_attention", "needs-attention", "stopped"].includes(normalized);
228
- }
229
- function permissionAllowsPr(payload) {
230
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
231
- return null;
232
- const record = payload;
233
- if (record.canOpenPullRequest === true || record.pullRequests === true || record.push === true || record.maintain === true || record.admin === true)
234
- return true;
235
- if (record.canOpenPullRequest === false || record.pullRequests === false || record.push === false)
236
- return false;
237
- const permissions = record.permissions;
238
- if (permissions && typeof permissions === "object" && !Array.isArray(permissions)) {
239
- const p = permissions;
240
- if (p.push === true || p.maintain === true || p.admin === true)
241
- return true;
242
- if (p.push === false && p.maintain !== true && p.admin !== true)
243
- return false;
244
- }
245
- return null;
246
- }
247
- function isNotFoundError(error) {
248
- return /\b(404|not found)\b/i.test(message(error));
249
- }
250
- function projectCheckoutReady(payload) {
251
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
252
- return null;
253
- const record = payload;
254
- if (record.checkoutReady === true || record.ready === true)
255
- return true;
256
- if (record.checkoutReady === false || record.ready === false)
257
- return false;
258
- const project = record.project;
259
- if (project && typeof project === "object" && !Array.isArray(project)) {
260
- const checkouts = project.checkouts;
261
- if (Array.isArray(checkouts))
262
- return checkouts.length > 0;
263
- }
264
- return null;
265
- }
266
- function activeDuplicateRun(runs, taskId) {
267
- if (!Array.isArray(runs))
268
- return null;
269
- for (const run of runs) {
270
- if (!run || typeof run !== "object" || Array.isArray(run))
271
- continue;
272
- const record = run;
273
- if ((record.taskId === taskId || record.task === taskId) && isActiveRunStatus(record.status))
274
- return record;
275
- }
276
- return null;
277
- }
278
- async function runFastTaskRunPreflight(context, options = {}) {
279
- const checks = [];
280
- const request = options.requestJson ?? ((pathname, init) => requestServerJson(context, pathname, init));
281
- const taskId = options.taskId?.trim() || null;
282
- const requiresCurrentRunApi = Boolean(taskId);
283
- const selectedServer = options.requestJson ? null : await ensureServerForCli(context.projectRoot).catch(() => null);
284
- const allowLocalLegacyTaskRunCompatibility = selectedServer?.connectionKind === "local";
285
- let legacyServerCompatibility = false;
286
- try {
287
- await request("/api/server/status");
288
- checks.push(preflightCheck("server", "Rig server reachable", "pass"));
289
- } catch (error) {
290
- if (isNotFoundError(error)) {
291
- try {
292
- await request("/health");
293
- legacyServerCompatibility = !requiresCurrentRunApi || allowLocalLegacyTaskRunCompatibility;
294
- checks.push(requiresCurrentRunApi && !allowLocalLegacyTaskRunCompatibility ? preflightCheck("server", "Rig server reachable", "fail", "legacy /health endpoint only; current task-run APIs are required", "Upgrade/select the Rig server before launching a task run.") : preflightCheck("server", "Rig server reachable", "pass", allowLocalLegacyTaskRunCompatibility ? "local legacy /health endpoint; submit endpoint will be authoritative" : "legacy /health endpoint"));
295
- } catch (healthError) {
296
- checks.push(preflightCheck("server", "Rig server reachable", "fail", message(healthError), "Start or select a reachable Rig server."));
297
- }
298
- } else {
299
- checks.push(preflightCheck("server", "Rig server reachable", "fail", message(error), "Start or select a reachable Rig server."));
300
- }
301
- }
302
- const repo = readRepoConnection(context.projectRoot);
303
- checks.push(repo ? preflightCheck("project-link", "project linked to Rig connection", repo.project ? "pass" : "warn", `${repo.selected}${repo.project ? ` -> ${repo.project}` : ""}`, "Run `rig init --yes --repo owner/repo` to record the GitHub repo slug.") : preflightCheck("project-link", "project linked to Rig connection", legacyServerCompatibility ? "warn" : "fail", "missing .rig/state/connection.json", "Run `rig init` or `rig connect use <alias|local>`."));
304
- try {
305
- const auth = await request("/api/github/auth/status");
306
- checks.push(isAuthenticated(auth) ? preflightCheck("github-auth", "GitHub auth valid", "pass") : preflightCheck("github-auth", "GitHub auth valid", legacyServerCompatibility ? "warn" : "fail", "not authenticated", "Run `rig github auth import-gh` or `rig github auth token --token <token>`."));
307
- } catch (error) {
308
- checks.push(preflightCheck("github-auth", "GitHub auth valid", legacyServerCompatibility ? "warn" : "fail", message(error), "Fix GitHub auth on the selected Rig server."));
309
- }
310
- try {
311
- const projection = await request("/api/workspace/task-projection");
312
- checks.push(preflightCheck("task-projection", "task projection ready", "pass", JSON.stringify(projection).slice(0, 120)));
313
- } catch (error) {
314
- checks.push(preflightCheck("task-projection", "task projection ready", "warn", message(error), "Refresh task projection with `rig task list` before launching."));
315
- }
316
- try {
317
- const permissions = await request("/api/github/repo/permissions");
318
- const allowed = permissionAllowsPr(permissions);
319
- checks.push(allowed === false ? preflightCheck("github-repo-permissions", "GitHub PR permissions", "fail", JSON.stringify(permissions).slice(0, 120), "Grant the selected GitHub token permission to push branches and open PRs.") : preflightCheck("github-repo-permissions", "GitHub PR permissions", allowed === true ? "pass" : "warn", JSON.stringify(permissions).slice(0, 120), "Confirm the selected token can push branches and open PRs."));
320
- } catch (error) {
321
- checks.push(preflightCheck("github-repo-permissions", "GitHub PR permissions", "warn", message(error), "Ensure the selected token can push branches and open PRs."));
322
- }
323
- if (repo?.project) {
324
- try {
325
- const project = await request(`/api/projects/${encodeURIComponent(repo.project)}`);
326
- const ready = projectCheckoutReady(project);
327
- checks.push(ready === false ? preflightCheck("remote-checkout", "execution checkout ready", "fail", JSON.stringify(project).slice(0, 120), "Repair the server checkout or rerun `rig init` with a valid checkout strategy.") : preflightCheck("remote-checkout", "execution checkout ready", ready === true ? "pass" : "warn", JSON.stringify(project).slice(0, 120), "Confirm the selected server has a prepared execution checkout."));
328
- } catch (error) {
329
- checks.push(preflightCheck("remote-checkout", "execution checkout ready", "warn", message(error), "Run `rig init` or repair the server checkout before launch."));
330
- }
331
- }
332
- if (taskId) {
333
- try {
334
- const tasks = await request(`/api/workspace/tasks?limit=200&refresh=1`);
335
- const found = Array.isArray(tasks) && tasks.some((task) => taskMatchesId(task, taskId));
336
- checks.push(found ? preflightCheck("issue", "task/issue accessible", "pass", taskId) : preflightCheck("issue", "task/issue accessible", legacyServerCompatibility ? "warn" : "fail", taskId, "Confirm the issue exists and matches the configured task filters."));
337
- } catch (error) {
338
- checks.push(preflightCheck("issue", "task/issue accessible", legacyServerCompatibility ? "warn" : "fail", message(error), "Fix the task source before launching a run."));
339
- }
340
- try {
341
- const runs = await request("/api/runs?limit=200");
342
- const duplicate = activeDuplicateRun(runs, taskId);
343
- checks.push(duplicate ? preflightCheck("duplicate-active-run", "one active run per task", "fail", String(duplicate.runId ?? taskId), "Attach to or stop the existing run before starting another one for this task.") : preflightCheck("duplicate-active-run", "one active run per task", "pass", taskId));
344
- } catch (error) {
345
- checks.push(preflightCheck("duplicate-active-run", "one active run per task", "warn", message(error), "Could not list active runs; the server will still reject conflicting runs if configured."));
346
- }
347
- }
348
- if ((options.runtimeAdapter ?? "pi") === "pi") {
349
- checks.push(preflightCheck("runtime", "worker Pi SDK session daemon", "pass", selectedServer?.connectionKind === "remote" ? "remote worker-owned runtime" : "bundled server-owned runtime"));
350
- } else {
351
- checks.push(preflightCheck("runtime", "runtime adapter", "pass", options.runtimeAdapter));
352
- }
353
- const failures = checks.filter((check) => check.status === "fail");
354
- if (failures.length > 0) {
355
- const summary = failures.map((check) => `${check.label}${check.detail ? `: ${check.detail}` : ""}`).join("; ");
356
- if (failures.some((check) => check.id === "duplicate-active-run") && taskId) {
357
- throw new CliError2(`Task ${taskId} already has an active Rig run. ${summary}`, 1);
358
- }
359
- throw new CliError2(`Task run preflight failed: ${summary}`, 1);
360
- }
361
- return { ok: true, checks };
362
- }
363
- async function runProjectMainSyncPreflight(context, options) {
364
- if (context.dryRun) {
365
- if (context.outputMode === "text" && !options.disabled) {
366
- console.log("[dry-run] project-rig pre-run sync check");
367
- }
368
- return;
369
- }
370
- const result = await ensureProjectMainFreshBeforeRun({
371
- projectRoot: context.projectRoot,
372
- disabled: options.disabled,
373
- runBootstrap: async () => {
374
- const bootstrap = await context.runCommand(["bun", "run", "bootstrap"]);
375
- if (bootstrap.exitCode !== 0) {
376
- throw new CliError2(bootstrap.stderr || bootstrap.stdout || "bun run bootstrap failed during project pre-run sync", bootstrap.exitCode || 1);
377
- }
378
- }
379
- });
380
- if (context.outputMode !== "text") {
381
- return;
382
- }
383
- switch (result.status) {
384
- case "disabled":
385
- console.log("Project pre-run sync skipped (--skip-project-sync).");
386
- break;
387
- case "skipped_not_main":
388
- console.log(`Project pre-run sync skipped (current branch: ${result.branch}).`);
389
- break;
390
- case "up_to_date":
391
- break;
392
- case "local_ahead":
393
- console.log(`Project pre-run sync skipped (local main ahead by ${result.localAhead} commit(s)).`);
394
- break;
395
- case "updated":
396
- console.log(`Project pre-run sync updated local main from origin/main (+${result.remoteAhead}) and bootstrapped.`);
397
- break;
398
- }
399
- }
400
- export {
401
- runProjectMainSyncPreflight,
402
- runFastTaskRunPreflight
403
- };
@@ -1,13 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/_probes.ts
3
- async function runQuietBinaryProbe(binaryPath, args, cwd) {
4
- try {
5
- const run = await Bun.$`${binaryPath} ${args}`.cwd(cwd).quiet().nothrow();
6
- return run.exitCode === 0;
7
- } catch {
8
- return false;
9
- }
10
- }
11
- export {
12
- runQuietBinaryProbe
13
- };