@h-rig/cli 0.0.6-alpha.20 → 0.0.6-alpha.200

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 (50) hide show
  1. package/README.md +6 -28
  2. package/package.json +9 -28
  3. package/dist/bin/build-rig-binaries.js +0 -107
  4. package/dist/bin/rig.js +0 -10443
  5. package/dist/src/commands/_authority-runs.js +0 -111
  6. package/dist/src/commands/_cli-format.js +0 -106
  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/_operator-surface.js +0 -204
  10. package/dist/src/commands/_operator-view.js +0 -496
  11. package/dist/src/commands/_parsers.js +0 -107
  12. package/dist/src/commands/_paths.js +0 -50
  13. package/dist/src/commands/_pi-install.js +0 -185
  14. package/dist/src/commands/_pi-session.js +0 -253
  15. package/dist/src/commands/_policy.js +0 -79
  16. package/dist/src/commands/_preflight.js +0 -483
  17. package/dist/src/commands/_probes.js +0 -13
  18. package/dist/src/commands/_run-driver-helpers.js +0 -289
  19. package/dist/src/commands/_server-client.js +0 -435
  20. package/dist/src/commands/_snapshot-upload.js +0 -318
  21. package/dist/src/commands/_task-picker.js +0 -76
  22. package/dist/src/commands/agent.js +0 -499
  23. package/dist/src/commands/browser.js +0 -890
  24. package/dist/src/commands/connect.js +0 -180
  25. package/dist/src/commands/dist.js +0 -402
  26. package/dist/src/commands/doctor.js +0 -517
  27. package/dist/src/commands/github.js +0 -281
  28. package/dist/src/commands/inbox.js +0 -160
  29. package/dist/src/commands/init.js +0 -1563
  30. package/dist/src/commands/inspect.js +0 -174
  31. package/dist/src/commands/inspector.js +0 -256
  32. package/dist/src/commands/plugin.js +0 -167
  33. package/dist/src/commands/profile-and-review.js +0 -178
  34. package/dist/src/commands/queue.js +0 -198
  35. package/dist/src/commands/remote.js +0 -507
  36. package/dist/src/commands/repo-git-harness.js +0 -221
  37. package/dist/src/commands/run.js +0 -1132
  38. package/dist/src/commands/server.js +0 -373
  39. package/dist/src/commands/setup.js +0 -687
  40. package/dist/src/commands/task-report-bug.js +0 -1083
  41. package/dist/src/commands/task-run-driver.js +0 -2469
  42. package/dist/src/commands/task.js +0 -1715
  43. package/dist/src/commands/test.js +0 -39
  44. package/dist/src/commands/workspace.js +0 -123
  45. package/dist/src/commands.js +0 -10122
  46. package/dist/src/index.js +0 -10461
  47. package/dist/src/launcher.js +0 -133
  48. package/dist/src/report-bug.js +0 -260
  49. package/dist/src/runner.js +0 -273
  50. package/dist/src/withMutedConsole.js +0 -42
@@ -1,496 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/_server-client.ts
3
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
4
- import { resolve as resolve2 } 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
-
15
- // packages/cli/src/commands/_server-client.ts
16
- import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
17
-
18
- // packages/cli/src/commands/_connection-state.ts
19
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
20
- import { homedir } from "os";
21
- import { dirname, resolve } from "path";
22
- function resolveGlobalConnectionsPath(env = process.env) {
23
- const explicit = env.RIG_CONNECTIONS_FILE?.trim();
24
- if (explicit)
25
- return resolve(explicit);
26
- const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
27
- if (stateDir)
28
- return resolve(stateDir, "connections.json");
29
- return resolve(homedir(), ".rig", "connections.json");
30
- }
31
- function resolveRepoConnectionPath(projectRoot) {
32
- return resolve(projectRoot, ".rig", "state", "connection.json");
33
- }
34
- function readJsonFile(path) {
35
- if (!existsSync(path))
36
- return null;
37
- try {
38
- return JSON.parse(readFileSync(path, "utf8"));
39
- } catch (error) {
40
- throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
41
- }
42
- }
43
- function normalizeConnection(value) {
44
- if (!value || typeof value !== "object" || Array.isArray(value))
45
- return null;
46
- const record = value;
47
- if (record.kind === "local")
48
- return { kind: "local", mode: "auto" };
49
- if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
50
- const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
51
- return { kind: "remote", baseUrl };
52
- }
53
- return null;
54
- }
55
- function readGlobalConnections(options = {}) {
56
- const path = resolveGlobalConnectionsPath(options.env ?? process.env);
57
- const payload = readJsonFile(path);
58
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
59
- return { connections: {} };
60
- }
61
- const rawConnections = payload.connections;
62
- const connections = {};
63
- if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
64
- for (const [alias, raw] of Object.entries(rawConnections)) {
65
- const connection = normalizeConnection(raw);
66
- if (connection)
67
- connections[alias] = connection;
68
- }
69
- }
70
- return { connections };
71
- }
72
- function readRepoConnection(projectRoot) {
73
- const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
74
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
75
- return null;
76
- const record = payload;
77
- const selected = typeof record.selected === "string" ? record.selected.trim() : "";
78
- if (!selected)
79
- return null;
80
- return {
81
- selected,
82
- project: typeof record.project === "string" ? record.project : undefined,
83
- linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
84
- };
85
- }
86
- function resolveSelectedConnection(projectRoot, options = {}) {
87
- const repo = readRepoConnection(projectRoot);
88
- if (!repo)
89
- return null;
90
- if (repo.selected === "local")
91
- return { alias: "local", connection: { kind: "local", mode: "auto" } };
92
- const global = readGlobalConnections(options);
93
- const connection = global.connections[repo.selected];
94
- if (!connection) {
95
- throw new CliError2(`Selected Rig connection "${repo.selected}" was not found. Run \`rig connect list\` or \`rig connect use local\`.`, 1);
96
- }
97
- return { alias: repo.selected, connection };
98
- }
99
-
100
- // packages/cli/src/commands/_server-client.ts
101
- var scopedGitHubBearerTokens = new Map;
102
- function cleanToken(value) {
103
- const trimmed = value?.trim();
104
- return trimmed ? trimmed : null;
105
- }
106
- function readPrivateRemoteSessionToken(projectRoot) {
107
- const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
108
- if (!existsSync2(path))
109
- return null;
110
- try {
111
- const parsed = JSON.parse(readFileSync2(path, "utf8"));
112
- return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
113
- } catch {
114
- return null;
115
- }
116
- }
117
- function readGitHubBearerTokenForRemote(projectRoot) {
118
- const scopedKey = resolve2(projectRoot);
119
- if (scopedGitHubBearerTokens.has(scopedKey))
120
- return scopedGitHubBearerTokens.get(scopedKey) ?? null;
121
- const privateSession = readPrivateRemoteSessionToken(projectRoot);
122
- if (privateSession)
123
- return privateSession;
124
- return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
125
- }
126
- async function ensureServerForCli(projectRoot) {
127
- try {
128
- const selected = resolveSelectedConnection(projectRoot);
129
- if (selected?.connection.kind === "remote") {
130
- return {
131
- baseUrl: selected.connection.baseUrl,
132
- authToken: readGitHubBearerTokenForRemote(projectRoot),
133
- connectionKind: "remote"
134
- };
135
- }
136
- const connection = await ensureLocalRigServerConnection(projectRoot);
137
- return {
138
- baseUrl: connection.baseUrl,
139
- authToken: connection.authToken,
140
- connectionKind: "local"
141
- };
142
- } catch (error) {
143
- if (error instanceof Error) {
144
- throw new CliError2(error.message, 1);
145
- }
146
- throw error;
147
- }
148
- }
149
- function mergeHeaders(headers, authToken) {
150
- const merged = new Headers(headers);
151
- if (authToken) {
152
- merged.set("authorization", `Bearer ${authToken}`);
153
- }
154
- return merged;
155
- }
156
- function diagnosticMessage(payload) {
157
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
158
- return null;
159
- const record = payload;
160
- const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
161
- const messages = diagnostics.flatMap((entry) => {
162
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
163
- return [];
164
- const diagnostic = entry;
165
- const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
166
- const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
167
- return message ? [`${kind}: ${message}`] : [];
168
- });
169
- return messages.length > 0 ? messages.join("; ") : null;
170
- }
171
- async function requestServerJson(context, pathname, init = {}) {
172
- const server = await ensureServerForCli(context.projectRoot);
173
- const response = await fetch(`${server.baseUrl}${pathname}`, {
174
- ...init,
175
- headers: mergeHeaders(init.headers, server.authToken)
176
- });
177
- const text = await response.text();
178
- const payload = text.trim().length > 0 ? (() => {
179
- try {
180
- return JSON.parse(text);
181
- } catch {
182
- return null;
183
- }
184
- })() : null;
185
- if (!response.ok) {
186
- const diagnostics = diagnosticMessage(payload);
187
- const detail = diagnostics ?? (text || response.statusText);
188
- throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
189
- }
190
- return payload;
191
- }
192
- async function getRunDetailsViaServer(context, runId) {
193
- const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}`);
194
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
195
- }
196
- async function getRunLogsViaServer(context, runId, options = {}) {
197
- const url = new URL(`http://rig.local/api/runs/${encodeURIComponent(runId)}/logs`);
198
- if (options.limit !== undefined)
199
- url.searchParams.set("limit", String(options.limit));
200
- if (options.cursor)
201
- url.searchParams.set("cursor", options.cursor);
202
- const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
203
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { entries: [] };
204
- }
205
- async function getRunTimelineViaServer(context, runId, options = {}) {
206
- const url = new URL(`http://rig.local/api/runs/${encodeURIComponent(runId)}/timeline`);
207
- if (options.limit !== undefined)
208
- url.searchParams.set("limit", String(options.limit));
209
- if (options.cursor)
210
- url.searchParams.set("cursor", options.cursor);
211
- const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
212
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { entries: [] };
213
- }
214
- async function stopRunViaServer(context, runId) {
215
- const payload = await requestServerJson(context, "/api/runs/stop", {
216
- method: "POST",
217
- headers: { "content-type": "application/json" },
218
- body: JSON.stringify({ runId })
219
- });
220
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { ok: true, runId };
221
- }
222
- async function steerRunViaServer(context, runId, message) {
223
- const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/steer`, {
224
- method: "POST",
225
- headers: { "content-type": "application/json" },
226
- body: JSON.stringify({ message })
227
- });
228
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { ok: true };
229
- }
230
-
231
- // packages/cli/src/commands/_operator-surface.ts
232
- import { createInterface } from "readline";
233
- var CANONICAL_STAGES = [
234
- "Connect",
235
- "GitHub/task sync",
236
- "Prepare workspace",
237
- "Launch Pi",
238
- "Plan",
239
- "Implement",
240
- "Validate",
241
- "Commit",
242
- "Open PR",
243
- "Review/CI",
244
- "Merge",
245
- "Complete"
246
- ];
247
- function logDetail(log) {
248
- return typeof log.detail === "string" ? log.detail.trim() : "";
249
- }
250
- function parseProviderProtocolLog(title, detail) {
251
- if (title.trim().toLowerCase() !== "agent output")
252
- return null;
253
- if (!detail.startsWith("{") || !detail.endsWith("}"))
254
- return null;
255
- try {
256
- const record = JSON.parse(detail);
257
- if (!record || typeof record !== "object" || Array.isArray(record))
258
- return null;
259
- const type = record.type;
260
- return typeof type === "string" && [
261
- "assistant",
262
- "message_start",
263
- "message_update",
264
- "message_end",
265
- "stream_event",
266
- "tool_result",
267
- "tool_execution_start",
268
- "tool_execution_update",
269
- "tool_execution_end",
270
- "turn_start",
271
- "turn_end"
272
- ].includes(type) ? record : null;
273
- } catch {
274
- return null;
275
- }
276
- }
277
- function renderProviderProtocolLog(record) {
278
- const type = typeof record.type === "string" ? record.type : "";
279
- if (type === "tool_execution_start" || type === "tool_execution_update" || type === "tool_execution_end") {
280
- const toolName = String(record.toolName ?? record.name ?? "tool");
281
- const status = type === "tool_execution_start" ? "started" : type === "tool_execution_end" ? record.isError === true || record.result && typeof record.result === "object" && !Array.isArray(record.result) && record.result.isError === true ? "failed" : "completed" : "running";
282
- return `[Pi tool] ${toolName} ${status}`;
283
- }
284
- return null;
285
- }
286
- function entryId(entry, fallback) {
287
- return typeof entry.id === "string" && entry.id.trim() ? entry.id : fallback;
288
- }
289
- function renderOperatorSnapshot(snapshot) {
290
- const run = snapshot.run.run && typeof snapshot.run.run === "object" ? snapshot.run.run : snapshot.run;
291
- const runId = String(run.runId ?? run.id ?? "run");
292
- const status = String(run.status ?? "unknown");
293
- const logs = snapshot.logs ?? [];
294
- const latestByStage = new Map;
295
- for (const log of logs) {
296
- const title = String(log.title ?? "").toLowerCase();
297
- const stageName = String(log.stage ?? "").toLowerCase();
298
- const stage = CANONICAL_STAGES.find((candidate) => candidate.toLowerCase() === title || candidate.toLowerCase() === stageName);
299
- if (stage)
300
- latestByStage.set(stage, log);
301
- }
302
- const stageLines = CANONICAL_STAGES.flatMap((stage) => {
303
- const match = latestByStage.get(stage);
304
- return match ? [`${stage}: ${String(match.status ?? status)}${logDetail(match) ? ` \u2014 ${logDetail(match)}` : ""}`] : [];
305
- });
306
- return [`Rig run ${runId}: ${status}`, ...stageLines].join(`
307
- `);
308
- }
309
- function createPiRunStreamRenderer(output = process.stdout) {
310
- let lastSnapshot = "";
311
- const assistantTextById = new Map;
312
- const seenTimeline = new Set;
313
- const seenLogs = new Set;
314
- const writeLine = (line) => output.write(`${line}
315
- `);
316
- return {
317
- renderSnapshot(snapshot) {
318
- const rendered = renderOperatorSnapshot(snapshot);
319
- if (rendered && rendered !== lastSnapshot) {
320
- writeLine(rendered);
321
- lastSnapshot = rendered;
322
- }
323
- },
324
- renderTimeline(entries) {
325
- for (const [index, entry] of entries.entries()) {
326
- const id = entryId(entry, `timeline:${index}:${String(entry.cursor ?? "")}`);
327
- if (entry.type === "assistant_message" && typeof entry.text === "string") {
328
- const text = entry.text;
329
- const previousText = assistantTextById.get(id) ?? "";
330
- if (!previousText && text.trim()) {
331
- writeLine("[Pi assistant]");
332
- }
333
- if (text.startsWith(previousText)) {
334
- const delta = text.slice(previousText.length);
335
- if (delta)
336
- output.write(delta);
337
- } else if (text.trim() && text !== previousText) {
338
- if (previousText)
339
- writeLine(`
340
- [Pi assistant]`);
341
- output.write(text);
342
- }
343
- assistantTextById.set(id, text);
344
- continue;
345
- }
346
- if (seenTimeline.has(id))
347
- continue;
348
- seenTimeline.add(id);
349
- if (entry.type === "tool_execution_start" || entry.type === "tool_execution_update" || entry.type === "tool_execution_end" || entry.type === "mcp_tool_call") {
350
- writeLine(`[Pi tool] ${String(entry.toolName ?? entry.name ?? entry.title ?? entry.type)} ${String(entry.status ?? entry.state ?? "")}`.trim());
351
- continue;
352
- }
353
- if (entry.type === "timeline_warning") {
354
- writeLine(`[Rig timeline] ${String(entry.detail ?? entry.message ?? "timeline unavailable")}`);
355
- }
356
- }
357
- },
358
- renderLogs(entries) {
359
- for (const [index, entry] of entries.entries()) {
360
- const id = entryId(entry, `log:${index}:${String(entry.createdAt ?? "")}:${String(entry.title ?? "")}`);
361
- if (seenLogs.has(id))
362
- continue;
363
- seenLogs.add(id);
364
- const title = String(entry.title ?? "");
365
- if (CANONICAL_STAGES.some((stage) => stage.toLowerCase() === title.toLowerCase()))
366
- continue;
367
- const detail = logDetail(entry);
368
- if (!detail)
369
- continue;
370
- const protocolRecord = parseProviderProtocolLog(title, detail);
371
- if (protocolRecord) {
372
- const protocolLine = renderProviderProtocolLog(protocolRecord);
373
- if (protocolLine)
374
- writeLine(protocolLine);
375
- continue;
376
- }
377
- writeLine(`[${title || "Rig log"}] ${detail}`);
378
- }
379
- }
380
- };
381
- }
382
- function createOperatorSurface(options = {}) {
383
- const input = options.input ?? process.stdin;
384
- const output = options.output ?? process.stdout;
385
- const errorOutput = options.errorOutput ?? process.stderr;
386
- const renderer = createPiRunStreamRenderer(output);
387
- const writeLine = (line) => output.write(`${line}
388
- `);
389
- return {
390
- mode: "pi-compatible-text",
391
- ...renderer,
392
- info: writeLine,
393
- error: (message) => errorOutput.write(`${message}
394
- `),
395
- attachCommandInput(handler) {
396
- if (options.interactive === false || !input.isTTY)
397
- return null;
398
- const rl = createInterface({ input, output: process.stdout, terminal: false });
399
- rl.on("line", (line) => {
400
- Promise.resolve(handler(line)).catch((error) => writeLine(`Operator command failed: ${error instanceof Error ? error.message : String(error)}`));
401
- });
402
- return { close: () => rl.close() };
403
- }
404
- };
405
- }
406
-
407
- // packages/cli/src/commands/_operator-view.ts
408
- var TERMINAL_RUN_STATUSES = new Set(["completed", "failed", "stopped", "cancelled", "canceled", "closed", "merged", "needs_attention", "needs-attention"]);
409
- function runStatusFromPayload(payload) {
410
- const run = payload.run && typeof payload.run === "object" && !Array.isArray(payload.run) ? payload.run : payload;
411
- return String(run.status ?? "unknown").toLowerCase();
412
- }
413
- async function applyOperatorCommand(context, input, deps = {}) {
414
- const line = input.line.trim();
415
- if (!line)
416
- return { action: "ignored" };
417
- if (line === "/detach" || line === "/quit" || line === "/q") {
418
- return { action: "detach", message: "Detached from run." };
419
- }
420
- if (line === "/stop") {
421
- await (deps.stop ?? stopRunViaServer)(context, input.runId);
422
- return { action: "stopped", message: "Stop requested." };
423
- }
424
- const userMessage = line.startsWith("/user ") ? line.slice("/user ".length).trim() : line;
425
- if (!userMessage)
426
- return { action: "ignored" };
427
- await (deps.steer ?? steerRunViaServer)(context, input.runId, userMessage);
428
- return { action: "continue", message: "Steering message queued." };
429
- }
430
- async function readOperatorSnapshot(context, runId, options = {}) {
431
- const run = await getRunDetailsViaServer(context, runId);
432
- const logsPage = await getRunLogsViaServer(context, runId, { limit: 100 });
433
- const timelinePage = await getRunTimelineViaServer(context, runId, { limit: 200, ...options.timelineCursor ? { cursor: options.timelineCursor } : {} }).catch((error) => ({
434
- entries: [{
435
- id: `timeline-unavailable:${runId}`,
436
- type: "timeline_warning",
437
- detail: `Selected Rig server did not provide run timeline events: ${error instanceof Error ? error.message : String(error)}`,
438
- createdAt: new Date().toISOString()
439
- }],
440
- nextCursor: options.timelineCursor ?? null
441
- }));
442
- const logs = Array.isArray(logsPage.entries) ? logsPage.entries.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry))).toReversed() : [];
443
- const timeline = Array.isArray(timelinePage.entries) ? timelinePage.entries.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry))) : [];
444
- const timelineCursor = typeof timelinePage.nextCursor === "string" ? timelinePage.nextCursor : options.timelineCursor ?? null;
445
- return { run, logs, timeline, timelineCursor, rendered: renderOperatorSnapshot({ run, logs, timeline }) };
446
- }
447
- async function attachRunOperatorView(context, input) {
448
- let steered = false;
449
- if (input.message?.trim()) {
450
- await steerRunViaServer(context, input.runId, input.message.trim());
451
- steered = true;
452
- }
453
- const surface = createOperatorSurface({ interactive: input.interactive !== false });
454
- let snapshot = await readOperatorSnapshot(context, input.runId);
455
- if (context.outputMode === "text") {
456
- surface.renderSnapshot(snapshot);
457
- surface.renderTimeline(snapshot.timeline);
458
- surface.renderLogs(snapshot.logs);
459
- if (steered)
460
- surface.info("Steering message queued.");
461
- }
462
- let detached = false;
463
- let commandInput = null;
464
- if (input.follow && !input.once && context.outputMode === "text") {
465
- if (input.interactive !== false && process.stdin.isTTY) {
466
- surface.info("Controls: /user <message>, /stop, /detach");
467
- commandInput = surface.attachCommandInput(async (line) => {
468
- const result = await applyOperatorCommand(context, { runId: input.runId, line });
469
- if (result.message)
470
- surface.info(result.message);
471
- if (result.action === "detach" || result.action === "stopped") {
472
- detached = true;
473
- commandInput?.close();
474
- }
475
- });
476
- }
477
- const pollMs = Math.max(250, Math.trunc(input.pollMs ?? 2000));
478
- let timelineCursor = snapshot.timelineCursor;
479
- while (!detached && !TERMINAL_RUN_STATUSES.has(runStatusFromPayload(snapshot.run))) {
480
- await Bun.sleep(pollMs);
481
- snapshot = await readOperatorSnapshot(context, input.runId, { timelineCursor });
482
- timelineCursor = snapshot.timelineCursor;
483
- surface.renderSnapshot(snapshot);
484
- surface.renderTimeline(snapshot.timeline);
485
- surface.renderLogs(snapshot.logs);
486
- }
487
- commandInput?.close();
488
- }
489
- return { ...snapshot, steered, detached };
490
- }
491
- export {
492
- renderOperatorSnapshot,
493
- createPiRunStreamRenderer,
494
- attachRunOperatorView,
495
- applyOperatorCommand
496
- };
@@ -1,107 +0,0 @@
1
- // @bun
2
- var __require = import.meta.require;
3
-
4
- // packages/cli/src/commands/_parsers.ts
5
- import { homedir } from "os";
6
- import { resolve } from "path";
7
-
8
- // packages/cli/src/runner.ts
9
- import { EventBus } from "@rig/runtime/control-plane/runtime/events";
10
- import { CliError } from "@rig/runtime/control-plane/errors";
11
- import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
12
- import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
13
- import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
14
- import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
15
- import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
16
-
17
- // packages/cli/src/commands/_parsers.ts
18
- function parsePositiveInt(value, option, fallback) {
19
- if (!value) {
20
- return fallback;
21
- }
22
- const parsed = Number.parseInt(value, 10);
23
- if (!Number.isFinite(parsed) || parsed <= 0) {
24
- throw new CliError2(`Invalid ${option} value: ${value}`);
25
- }
26
- return parsed;
27
- }
28
- function parseOptionalPositiveInt(value, option) {
29
- if (!value) {
30
- return;
31
- }
32
- const parsed = Number.parseInt(value, 10);
33
- if (!Number.isFinite(parsed) || parsed <= 0) {
34
- throw new CliError2(`Invalid ${option} value: ${value}`);
35
- }
36
- return parsed;
37
- }
38
- function parseRequiredPositiveInt(value, option) {
39
- if (!value) {
40
- throw new CliError2(`Missing value for ${option}.`);
41
- }
42
- const parsed = Number.parseInt(value, 10);
43
- if (!Number.isFinite(parsed) || parsed <= 0) {
44
- throw new CliError2(`Invalid ${option} value: ${value}`);
45
- }
46
- return parsed;
47
- }
48
- function parseAction(value) {
49
- if (!value || value === "validate") {
50
- return "validate";
51
- }
52
- if (value === "verify") {
53
- return "verify";
54
- }
55
- if (value === "pipeline") {
56
- return "pipeline";
57
- }
58
- throw new CliError2(`Invalid --action value: ${value}. Use validate, verify, or pipeline.`);
59
- }
60
- function parseIsolationMode(value, allowOff) {
61
- if (!value) {
62
- return "worktree";
63
- }
64
- if (value === "worktree") {
65
- return value;
66
- }
67
- if (allowOff && value === "off") {
68
- return value;
69
- }
70
- throw new CliError2(`Invalid isolation mode: ${value}. Use ${allowOff ? "off|" : ""}worktree.`);
71
- }
72
- function parseInstallScope(value) {
73
- if (!value || value === "user") {
74
- return "user";
75
- }
76
- if (value === "system") {
77
- return "system";
78
- }
79
- throw new CliError2(`Invalid --scope value: ${value}. Use user|system.`);
80
- }
81
- function resolveInstallDir(scope, explicitPath) {
82
- if (explicitPath) {
83
- return resolve(explicitPath);
84
- }
85
- if (scope === "system") {
86
- return "/usr/local/bin";
87
- }
88
- return resolve(homedir(), ".local/bin");
89
- }
90
- async function loadRigConfigOrNull(projectRoot) {
91
- try {
92
- const { loadConfig } = await import("@rig/core/load-config");
93
- return await loadConfig(projectRoot);
94
- } catch {
95
- return null;
96
- }
97
- }
98
- export {
99
- resolveInstallDir,
100
- parseRequiredPositiveInt,
101
- parsePositiveInt,
102
- parseOptionalPositiveInt,
103
- parseIsolationMode,
104
- parseInstallScope,
105
- parseAction,
106
- loadRigConfigOrNull
107
- };
@@ -1,50 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/_paths.ts
3
- import { resolve } from "path";
4
- import { resolveMonorepoRoot } from "@rig/runtime/control-plane/native/utils";
5
- function resolveControlPlaneMonorepoRoot(projectRoot) {
6
- return resolveMonorepoRoot(projectRoot);
7
- }
8
- function resolveControlPlaneTaskConfigPath(projectRoot) {
9
- return resolve(resolveControlPlaneMonorepoRoot(projectRoot), ".rig", "task-config.json");
10
- }
11
- function resolveControlPlaneHostStateRoot(projectRoot) {
12
- return resolve(projectRoot, ".rig");
13
- }
14
- function resolveControlPlaneHostStateDir(projectRoot) {
15
- return resolve(resolveControlPlaneHostStateRoot(projectRoot), "state");
16
- }
17
- function resolveControlPlaneHostLogsDir(projectRoot) {
18
- return resolve(resolveControlPlaneHostStateRoot(projectRoot), "logs");
19
- }
20
- function resolveControlPlaneHostBinDir(projectRoot) {
21
- return resolve(resolveControlPlaneHostStateRoot(projectRoot), "bin");
22
- }
23
- function resolveControlPlaneHostDistDir(projectRoot) {
24
- return resolve(resolveControlPlaneHostStateRoot(projectRoot), "dist");
25
- }
26
- function resolveControlPlaneMonorepoStateRoot(projectRoot) {
27
- return resolve(resolveControlPlaneMonorepoRoot(projectRoot), ".rig");
28
- }
29
- function resolveControlPlaneMonorepoRuntimeDir(projectRoot) {
30
- return resolve(resolveControlPlaneMonorepoStateRoot(projectRoot), "runtime");
31
- }
32
- function resolveControlPlaneArtifactsDir(projectRoot) {
33
- return resolve(resolveControlPlaneMonorepoRoot(projectRoot), "artifacts");
34
- }
35
- function resolveControlPlaneDefinitionRoot(projectRoot) {
36
- return resolve(projectRoot, "rig");
37
- }
38
- export {
39
- resolveControlPlaneTaskConfigPath,
40
- resolveControlPlaneMonorepoStateRoot,
41
- resolveControlPlaneMonorepoRuntimeDir,
42
- resolveControlPlaneMonorepoRoot,
43
- resolveControlPlaneHostStateRoot,
44
- resolveControlPlaneHostStateDir,
45
- resolveControlPlaneHostLogsDir,
46
- resolveControlPlaneHostDistDir,
47
- resolveControlPlaneHostBinDir,
48
- resolveControlPlaneDefinitionRoot,
49
- resolveControlPlaneArtifactsDir
50
- };