@h-rig/cli 0.0.6-alpha.5 → 0.0.6-alpha.51

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 +1 -1
  2. package/dist/bin/rig.js +4129 -1207
  3. package/dist/src/commands/_cli-format.js +369 -0
  4. package/dist/src/commands/_connection-state.js +12 -6
  5. package/dist/src/commands/_doctor-checks.js +79 -34
  6. package/dist/src/commands/_help-catalog.js +445 -0
  7. package/dist/src/commands/_operator-surface.js +220 -0
  8. package/dist/src/commands/_operator-view.js +1124 -64
  9. package/dist/src/commands/_parsers.js +0 -2
  10. package/dist/src/commands/_pi-frontend.js +1080 -0
  11. package/dist/src/commands/_pi-install.js +4 -3
  12. package/dist/src/commands/_pi-remote-session.js +771 -0
  13. package/dist/src/commands/_pi-worker-bridge-extension.js +834 -0
  14. package/dist/src/commands/_policy.js +0 -2
  15. package/dist/src/commands/_preflight.js +98 -116
  16. package/dist/src/commands/_run-driver-helpers.js +2 -2
  17. package/dist/src/commands/_server-client.js +225 -48
  18. package/dist/src/commands/_snapshot-upload.js +74 -30
  19. package/dist/src/commands/_spinner.js +63 -0
  20. package/dist/src/commands/_task-picker.js +44 -16
  21. package/dist/src/commands/agent.js +8 -9
  22. package/dist/src/commands/browser.js +4 -6
  23. package/dist/src/commands/connect.js +134 -26
  24. package/dist/src/commands/dist.js +4 -6
  25. package/dist/src/commands/doctor.js +79 -34
  26. package/dist/src/commands/github.js +76 -32
  27. package/dist/src/commands/inbox.js +410 -31
  28. package/dist/src/commands/init.js +398 -90
  29. package/dist/src/commands/inspect.js +296 -23
  30. package/dist/src/commands/inspector.js +2 -4
  31. package/dist/src/commands/pi.js +168 -0
  32. package/dist/src/commands/plugin.js +81 -22
  33. package/dist/src/commands/profile-and-review.js +8 -10
  34. package/dist/src/commands/queue.js +2 -3
  35. package/dist/src/commands/remote.js +18 -20
  36. package/dist/src/commands/repo-git-harness.js +6 -8
  37. package/dist/src/commands/run.js +1422 -131
  38. package/dist/src/commands/server.js +280 -40
  39. package/dist/src/commands/setup.js +84 -45
  40. package/dist/src/commands/task-report-bug.js +5 -7
  41. package/dist/src/commands/task-run-driver.js +676 -70
  42. package/dist/src/commands/task.js +1861 -260
  43. package/dist/src/commands/test.js +3 -5
  44. package/dist/src/commands/workspace.js +4 -6
  45. package/dist/src/commands.js +4111 -1183
  46. package/dist/src/index.js +4122 -1203
  47. package/dist/src/launcher.js +5 -3
  48. package/dist/src/report-bug.js +3 -3
  49. package/dist/src/runner.js +5 -19
  50. package/package.json +7 -4
@@ -1,14 +1,12 @@
1
1
  // @bun
2
2
  // packages/cli/src/commands/inbox.ts
3
- import { writeFileSync } from "fs";
4
- import { resolve } from "path";
3
+ import { writeFileSync as writeFileSync2 } from "fs";
4
+ import { resolve as resolve3 } from "path";
5
5
 
6
6
  // packages/cli/src/runner.ts
7
7
  import { EventBus } from "@rig/runtime/control-plane/runtime/events";
8
8
  import { CliError } from "@rig/runtime/control-plane/errors";
9
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
10
  import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
13
11
  import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
14
12
  function takeOption(args, option) {
@@ -44,6 +42,393 @@ import {
44
42
  readJsonlFile,
45
43
  resolveAuthorityRunDir
46
44
  } from "@rig/runtime/control-plane/authority-files";
45
+
46
+ // packages/cli/src/commands/_cli-format.ts
47
+ import { log, note } from "@clack/prompts";
48
+ import pc from "picocolors";
49
+ function stringField(record, key, fallback = "") {
50
+ const value = record[key];
51
+ return typeof value === "string" && value.trim() ? value.trim() : fallback;
52
+ }
53
+ function statusColor(status) {
54
+ const normalized = status.toLowerCase();
55
+ if (["completed", "merged", "closed", "done", "accepted", "pass", "selected", "approved"].includes(normalized))
56
+ return pc.green;
57
+ if (["failed", "needs_attention", "needs-attention", "blocked", "error", "rejected"].includes(normalized))
58
+ return pc.red;
59
+ if (["running", "reviewing", "validating", "in_progress", "in-progress", "remote"].includes(normalized))
60
+ return pc.cyan;
61
+ if (["ready", "open", "queued", "created", "preparing", "local", "pending"].includes(normalized))
62
+ return pc.yellow;
63
+ return pc.dim;
64
+ }
65
+ function firstString(record, keys, fallback = "") {
66
+ for (const key of keys) {
67
+ const value = stringField(record, key);
68
+ if (value)
69
+ return value;
70
+ }
71
+ return fallback;
72
+ }
73
+ function requestIdOf(entry) {
74
+ return firstString(entry, ["requestId", "id", "approvalId", "inputId"], "(unknown-request)");
75
+ }
76
+ function shouldUseClackOutput() {
77
+ return Boolean(process.stdout.isTTY) && process.env.RIG_CLI_PLAIN_HELP !== "1";
78
+ }
79
+ function printFormattedOutput(message, options = {}) {
80
+ if (!shouldUseClackOutput()) {
81
+ console.log(message);
82
+ return;
83
+ }
84
+ if (options.title)
85
+ note(message, options.title);
86
+ else
87
+ log.message(message);
88
+ }
89
+ function formatStatusPill(status) {
90
+ const label = status || "unknown";
91
+ return statusColor(label)(`\u25CF ${label}`);
92
+ }
93
+ function formatSection(title, subtitle) {
94
+ return `${pc.bold(pc.cyan("\u25C6"))} ${pc.bold(title)}${subtitle ? pc.dim(` \u2014 ${subtitle}`) : ""}`;
95
+ }
96
+ function formatNextSteps(steps) {
97
+ if (steps.length === 0)
98
+ return [];
99
+ return [pc.bold("Next"), ...steps.map((step) => `${pc.dim("\u203A")} ${step}`)];
100
+ }
101
+ function formatInboxList(kind, entries) {
102
+ const title = kind === "approvals" ? "Approval inbox" : "Input inbox";
103
+ if (entries.length === 0) {
104
+ return [
105
+ formatSection(title, "empty"),
106
+ pc.dim(kind === "approvals" ? "No pending approvals." : "No pending user-input requests."),
107
+ "",
108
+ ...formatNextSteps(["Check runs: `rig run status`", "Start work: `rig task run --next`"])
109
+ ].join(`
110
+ `);
111
+ }
112
+ const lines = [formatSection(title, `${entries.length} pending`)];
113
+ for (const entry of entries) {
114
+ const record = entry.record && typeof entry.record === "object" && !Array.isArray(entry.record) ? entry.record : entry;
115
+ const runId = firstString(entry, ["runId"], firstString(record, ["runId"]));
116
+ const taskId = firstString(entry, ["taskId"], firstString(record, ["taskId", "task"]));
117
+ const requestId = requestIdOf(record);
118
+ const status = firstString(record, ["status", "state"], "pending");
119
+ const prompt = firstString(record, ["prompt", "message", "reason", "title", "summary"], kind === "approvals" ? "Approval requested" : "Input requested");
120
+ lines.push(`${pc.dim("\u2502")} ${pc.bold(requestId)} ${formatStatusPill(status)} ${prompt}`);
121
+ lines.push(`${pc.dim("\u2502")} ${pc.dim("run ")} ${runId || "(unknown-run)"}${taskId ? pc.dim(` task ${taskId}`) : ""}`);
122
+ }
123
+ lines.push("", ...formatNextSteps(kind === "approvals" ? ["Resolve: `rig inbox approve --run <run-id> --request <request-id> --decision approve|reject`", "Rejoin: `rig run attach <run-id> --follow`"] : ["Respond: `rig inbox respond --run <run-id> --request <request-id> --answer key=value`", "Rejoin: `rig run attach <run-id> --follow`"]));
124
+ return lines.join(`
125
+ `);
126
+ }
127
+
128
+ // packages/cli/src/commands/_connection-state.ts
129
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
130
+ import { homedir } from "os";
131
+ import { dirname, resolve } from "path";
132
+ function resolveGlobalConnectionsPath(env = process.env) {
133
+ const explicit = env.RIG_CONNECTIONS_FILE?.trim();
134
+ if (explicit)
135
+ return resolve(explicit);
136
+ const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
137
+ if (stateDir)
138
+ return resolve(stateDir, "connections.json");
139
+ return resolve(homedir(), ".rig", "connections.json");
140
+ }
141
+ function resolveRepoConnectionPath(projectRoot) {
142
+ return resolve(projectRoot, ".rig", "state", "connection.json");
143
+ }
144
+ function readJsonFile(path) {
145
+ if (!existsSync(path))
146
+ return null;
147
+ try {
148
+ return JSON.parse(readFileSync(path, "utf8"));
149
+ } catch (error) {
150
+ throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
151
+ }
152
+ }
153
+ function writeJsonFile(path, value) {
154
+ mkdirSync(dirname(path), { recursive: true });
155
+ writeFileSync(path, `${JSON.stringify(value, null, 2)}
156
+ `, "utf8");
157
+ }
158
+ function normalizeConnection(value) {
159
+ if (!value || typeof value !== "object" || Array.isArray(value))
160
+ return null;
161
+ const record = value;
162
+ if (record.kind === "local")
163
+ return { kind: "local", mode: "auto" };
164
+ if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
165
+ const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
166
+ return { kind: "remote", baseUrl };
167
+ }
168
+ return null;
169
+ }
170
+ function readGlobalConnections(options = {}) {
171
+ const path = resolveGlobalConnectionsPath(options.env ?? process.env);
172
+ const payload = readJsonFile(path);
173
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
174
+ return { connections: {} };
175
+ }
176
+ const rawConnections = payload.connections;
177
+ const connections = {};
178
+ if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
179
+ for (const [alias, raw] of Object.entries(rawConnections)) {
180
+ const connection = normalizeConnection(raw);
181
+ if (connection)
182
+ connections[alias] = connection;
183
+ }
184
+ }
185
+ return { connections };
186
+ }
187
+ function readRepoConnection(projectRoot) {
188
+ const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
189
+ if (!payload || typeof payload !== "object" || Array.isArray(payload))
190
+ return null;
191
+ const record = payload;
192
+ const selected = typeof record.selected === "string" ? record.selected.trim() : "";
193
+ if (!selected)
194
+ return null;
195
+ return {
196
+ selected,
197
+ project: typeof record.project === "string" ? record.project : undefined,
198
+ linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
199
+ serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
200
+ };
201
+ }
202
+ function writeRepoConnection(projectRoot, state) {
203
+ writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
204
+ }
205
+ function resolveSelectedConnection(projectRoot, options = {}) {
206
+ const repo = readRepoConnection(projectRoot);
207
+ if (!repo)
208
+ return null;
209
+ if (repo.selected === "local")
210
+ return { alias: "local", connection: { kind: "local", mode: "auto" }, serverProjectRoot: repo.serverProjectRoot };
211
+ const global = readGlobalConnections(options);
212
+ const connection = global.connections[repo.selected];
213
+ if (!connection) {
214
+ throw new CliError2(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
215
+ }
216
+ return { alias: repo.selected, connection, serverProjectRoot: repo.serverProjectRoot };
217
+ }
218
+ function writeRepoServerProjectRoot(projectRoot, serverProjectRoot) {
219
+ const repo = readRepoConnection(projectRoot);
220
+ if (!repo)
221
+ return;
222
+ writeRepoConnection(projectRoot, { ...repo, serverProjectRoot });
223
+ }
224
+
225
+ // packages/cli/src/commands/_server-client.ts
226
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
227
+ import { resolve as resolve2 } from "path";
228
+ import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
229
+ var scopedGitHubBearerTokens = new Map;
230
+ function cleanToken(value) {
231
+ const trimmed = value?.trim();
232
+ return trimmed ? trimmed : null;
233
+ }
234
+ function readPrivateRemoteSessionToken(projectRoot) {
235
+ const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
236
+ if (!existsSync2(path))
237
+ return null;
238
+ try {
239
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
240
+ return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
241
+ } catch {
242
+ return null;
243
+ }
244
+ }
245
+ function readGitHubBearerTokenForRemote(projectRoot) {
246
+ const scopedKey = resolve2(projectRoot);
247
+ if (scopedGitHubBearerTokens.has(scopedKey))
248
+ return scopedGitHubBearerTokens.get(scopedKey) ?? null;
249
+ const privateSession = readPrivateRemoteSessionToken(projectRoot);
250
+ if (privateSession)
251
+ return privateSession;
252
+ return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
253
+ }
254
+ function readStoredGitHubAuthToken(projectRoot) {
255
+ const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
256
+ if (!existsSync2(path))
257
+ return null;
258
+ try {
259
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
260
+ return cleanToken(typeof parsed.token === "string" ? parsed.token : undefined);
261
+ } catch {
262
+ return null;
263
+ }
264
+ }
265
+ function readLocalConnectionFallbackToken(projectRoot) {
266
+ return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
267
+ }
268
+ async function ensureServerForCli(projectRoot) {
269
+ try {
270
+ const selected = resolveSelectedConnection(projectRoot);
271
+ if (selected?.connection.kind === "remote") {
272
+ const authToken = readGitHubBearerTokenForRemote(projectRoot);
273
+ const serverProjectRoot = selected.serverProjectRoot ?? await backfillRemoteServerProjectRoot(projectRoot, selected.connection.baseUrl, authToken);
274
+ return {
275
+ baseUrl: selected.connection.baseUrl,
276
+ authToken,
277
+ connectionKind: "remote",
278
+ serverProjectRoot
279
+ };
280
+ }
281
+ const connection = await ensureLocalRigServerConnection(projectRoot);
282
+ return {
283
+ baseUrl: connection.baseUrl,
284
+ authToken: connection.authToken ?? readLocalConnectionFallbackToken(projectRoot),
285
+ connectionKind: "local",
286
+ serverProjectRoot: resolve2(projectRoot)
287
+ };
288
+ } catch (error) {
289
+ if (error instanceof Error) {
290
+ throw new CliError2(error.message, 1);
291
+ }
292
+ throw error;
293
+ }
294
+ }
295
+ async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
296
+ const repo = readRepoConnection(projectRoot);
297
+ const slug = repo?.project?.trim();
298
+ if (!slug)
299
+ return null;
300
+ try {
301
+ const response = await fetch(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`, {
302
+ headers: mergeHeaders(undefined, authToken)
303
+ });
304
+ if (!response.ok)
305
+ return null;
306
+ const payload = await response.json();
307
+ const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
308
+ const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
309
+ const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
310
+ const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
311
+ if (path)
312
+ writeRepoServerProjectRoot(projectRoot, path);
313
+ return path;
314
+ } catch {
315
+ return null;
316
+ }
317
+ }
318
+ function mergeHeaders(headers, authToken) {
319
+ const merged = new Headers(headers);
320
+ if (authToken) {
321
+ merged.set("authorization", `Bearer ${authToken}`);
322
+ }
323
+ return merged;
324
+ }
325
+ function diagnosticMessage(payload) {
326
+ if (!payload || typeof payload !== "object" || Array.isArray(payload))
327
+ return null;
328
+ const record = payload;
329
+ const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
330
+ const messages = diagnostics.flatMap((entry) => {
331
+ if (!entry || typeof entry !== "object" || Array.isArray(entry))
332
+ return [];
333
+ const diagnostic = entry;
334
+ const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
335
+ const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
336
+ return message ? [`${kind}: ${message}`] : [];
337
+ });
338
+ return messages.length > 0 ? messages.join("; ") : null;
339
+ }
340
+ async function requestServerJson(context, pathname, init = {}) {
341
+ const server = await ensureServerForCli(context.projectRoot);
342
+ const headers = mergeHeaders(init.headers, server.authToken);
343
+ if (server.serverProjectRoot)
344
+ headers.set("x-rig-project-root", server.serverProjectRoot);
345
+ const response = await fetch(`${server.baseUrl}${pathname}`, {
346
+ ...init,
347
+ headers
348
+ });
349
+ const text = await response.text();
350
+ const payload = text.trim().length > 0 ? (() => {
351
+ try {
352
+ return JSON.parse(text);
353
+ } catch {
354
+ return null;
355
+ }
356
+ })() : null;
357
+ if (!response.ok) {
358
+ const diagnostics = diagnosticMessage(payload);
359
+ const detail = diagnostics ?? (text || response.statusText);
360
+ throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
361
+ }
362
+ return payload;
363
+ }
364
+ async function listRunsViaServer(context, options = {}) {
365
+ const url = new URL("http://rig.local/api/runs");
366
+ if (options.limit !== undefined)
367
+ url.searchParams.set("limit", String(options.limit));
368
+ const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
369
+ const runs = Array.isArray(payload) ? payload : payload && typeof payload === "object" && !Array.isArray(payload) && Array.isArray(payload.runs) ? payload.runs : [];
370
+ return runs.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry)));
371
+ }
372
+ async function getRunDetailsViaServer(context, runId) {
373
+ const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}`);
374
+ return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
375
+ }
376
+
377
+ // packages/cli/src/commands/inbox.ts
378
+ function isRemoteConnectionSelected(projectRoot) {
379
+ return resolveSelectedConnection(projectRoot)?.connection.kind === "remote";
380
+ }
381
+ function runMatches(entry, filters) {
382
+ const runId = typeof entry.runId === "string" ? entry.runId : typeof entry.id === "string" ? entry.id : "";
383
+ const taskId = typeof entry.taskId === "string" ? entry.taskId : "";
384
+ return (!filters.run || runId === filters.run) && (!filters.task || taskId === filters.task);
385
+ }
386
+ function normalizeRemoteRunDetails(payload) {
387
+ const run = payload.run;
388
+ if (run && typeof run === "object" && !Array.isArray(run)) {
389
+ return {
390
+ ...run,
391
+ ...Array.isArray(payload.timeline) ? { timeline: payload.timeline } : {},
392
+ ...Array.isArray(payload.approvals) ? { approvals: payload.approvals } : {},
393
+ ...Array.isArray(payload.userInputs) ? { userInputs: payload.userInputs } : {}
394
+ };
395
+ }
396
+ return payload;
397
+ }
398
+ function remoteRecordsFromRun(run, kind) {
399
+ const key = kind === "approvals" ? "approvals" : "userInputs";
400
+ const direct = run[key];
401
+ if (!Array.isArray(direct))
402
+ return [];
403
+ const runId = typeof run.runId === "string" ? run.runId : typeof run.id === "string" ? run.id : "";
404
+ const taskId = typeof run.taskId === "string" ? run.taskId : "";
405
+ return direct.filter((record) => Boolean(record && typeof record === "object" && !Array.isArray(record))).map((record) => ({ runId, taskId, record }));
406
+ }
407
+ async function listRemoteInboxRecords(context, kind, filters) {
408
+ const runs = (await listRunsViaServer(context, { limit: 100 })).filter((entry) => runMatches(entry, filters));
409
+ const records = [];
410
+ for (const run of runs) {
411
+ const runId = typeof run.runId === "string" ? run.runId : typeof run.id === "string" ? run.id : "";
412
+ const detailed = runId ? normalizeRemoteRunDetails(await getRunDetailsViaServer(context, runId).catch(() => run)) : run;
413
+ records.push(...remoteRecordsFromRun(detailed, kind));
414
+ }
415
+ return records;
416
+ }
417
+ function listLocalInboxRecords(context, kind, filters) {
418
+ const fileName = kind === "approvals" ? "approvals.jsonl" : "user-input.jsonl";
419
+ const runs = listAuthorityRuns(context.projectRoot).filter((entry) => (!filters.run || entry.runId === filters.run) && (!filters.task || entry.taskId === filters.task));
420
+ return runs.flatMap((entry) => readJsonlFile(resolve3(resolveAuthorityRunDir(context.projectRoot, entry.runId), fileName)).map((record) => ({
421
+ runId: entry.runId,
422
+ taskId: entry.taskId ?? undefined,
423
+ record
424
+ })));
425
+ }
426
+ async function listInboxRecords(context, kind, filters) {
427
+ if (isRemoteConnectionSelected(context.projectRoot)) {
428
+ return listRemoteInboxRecords(context, kind, filters);
429
+ }
430
+ return listLocalInboxRecords(context, kind, filters);
431
+ }
47
432
  async function executeInbox(context, args) {
48
433
  const [command = "approvals", ...rest] = args;
49
434
  switch (command) {
@@ -53,16 +438,10 @@ async function executeInbox(context, args) {
53
438
  pending = run.rest;
54
439
  const task = takeOption(pending, "--task");
55
440
  pending = task.rest;
56
- requireNoExtraArgs(pending, "bun run rig inbox approvals [--run <id>] [--task <id>]");
57
- const runs = listAuthorityRuns(context.projectRoot).filter((entry) => (!run.value || entry.runId === run.value) && (!task.value || entry.taskId === task.value));
58
- const approvals = runs.flatMap((entry) => readJsonlFile(resolve(resolveAuthorityRunDir(context.projectRoot, entry.runId), "approvals.jsonl")).map((record) => ({
59
- runId: entry.runId,
60
- record
61
- })));
441
+ requireNoExtraArgs(pending, "rig inbox approvals [--run <id>] [--task <id>]");
442
+ const approvals = await listInboxRecords(context, "approvals", { run: run.value, task: task.value });
62
443
  if (context.outputMode === "text") {
63
- for (const approval of approvals) {
64
- console.log(JSON.stringify(approval));
65
- }
444
+ printFormattedOutput(formatInboxList("approvals", approvals));
66
445
  }
67
446
  return { ok: true, group: "inbox", command, details: { approvals } };
68
447
  }
@@ -74,20 +453,23 @@ async function executeInbox(context, args) {
74
453
  pending = request.rest;
75
454
  const decision = takeOption(pending, "--decision");
76
455
  pending = decision.rest;
77
- const note = takeOption(pending, "--note");
78
- pending = note.rest;
79
- requireNoExtraArgs(pending, "bun run rig inbox approve --run <id> --request <id> --decision approve|reject [--note <text>]");
456
+ const note2 = takeOption(pending, "--note");
457
+ pending = note2.rest;
458
+ requireNoExtraArgs(pending, "rig inbox approve --run <id> --request <id> --decision approve|reject [--note <text>]");
80
459
  if (!run.value || !request.value || !decision.value) {
81
460
  throw new CliError2("approve requires --run, --request, and --decision.");
82
461
  }
83
462
  if (decision.value !== "approve" && decision.value !== "reject") {
84
463
  throw new CliError2("decision must be approve or reject.");
85
464
  }
86
- const approvalsPath = resolve(resolveAuthorityRunDir(context.projectRoot, run.value), "approvals.jsonl");
465
+ if (isRemoteConnectionSelected(context.projectRoot)) {
466
+ throw new CliError2("Remote approval resolution is not available from this CLI yet; use the server UI/API or switch to local state for direct JSONL edits.", 2);
467
+ }
468
+ const approvalsPath = resolve3(resolveAuthorityRunDir(context.projectRoot, run.value), "approvals.jsonl");
87
469
  const approvals = readJsonlFile(approvalsPath);
88
470
  const resolvedAt = new Date().toISOString();
89
- const next = approvals.map((entry) => entry.requestId === request.value || entry.id === request.value ? { ...entry, status: "resolved", decision: decision.value, note: note.value ?? null, resolvedAt } : entry);
90
- writeFileSync(approvalsPath, `${next.map((entry) => JSON.stringify(entry)).join(`
471
+ const next = approvals.map((entry) => entry.requestId === request.value || entry.id === request.value ? { ...entry, status: "resolved", decision: decision.value, note: note2.value ?? null, resolvedAt } : entry);
472
+ writeFileSync2(approvalsPath, `${next.map((entry) => JSON.stringify(entry)).join(`
91
473
  `)}
92
474
  `, "utf8");
93
475
  return { ok: true, group: "inbox", command, details: { runId: run.value, requestId: request.value, decision: decision.value } };
@@ -98,16 +480,10 @@ async function executeInbox(context, args) {
98
480
  pending = run.rest;
99
481
  const task = takeOption(pending, "--task");
100
482
  pending = task.rest;
101
- requireNoExtraArgs(pending, "bun run rig inbox inputs [--run <id>] [--task <id>]");
102
- const runs = listAuthorityRuns(context.projectRoot).filter((entry) => (!run.value || entry.runId === run.value) && (!task.value || entry.taskId === task.value));
103
- const requests = runs.flatMap((entry) => readJsonlFile(resolve(resolveAuthorityRunDir(context.projectRoot, entry.runId), "user-input.jsonl")).map((record) => ({
104
- runId: entry.runId,
105
- record
106
- })));
483
+ requireNoExtraArgs(pending, "rig inbox inputs [--run <id>] [--task <id>]");
484
+ const requests = await listInboxRecords(context, "inputs", { run: run.value, task: task.value });
107
485
  if (context.outputMode === "text") {
108
- for (const request of requests) {
109
- console.log(JSON.stringify(request));
110
- }
486
+ printFormattedOutput(formatInboxList("inputs", requests));
111
487
  }
112
488
  return { ok: true, group: "inbox", command, details: { requests } };
113
489
  }
@@ -134,19 +510,22 @@ async function executeInbox(context, args) {
134
510
  remaining.push(current);
135
511
  }
136
512
  }
137
- requireNoExtraArgs(remaining, "bun run rig inbox respond --run <id> --request <id> --answer key=value [--answer key=value]");
513
+ requireNoExtraArgs(remaining, "rig inbox respond --run <id> --request <id> --answer key=value [--answer key=value]");
138
514
  if (!run.value || !request.value || answers.length === 0) {
139
515
  throw new CliError2("respond requires --run, --request, and at least one --answer.");
140
516
  }
517
+ if (isRemoteConnectionSelected(context.projectRoot)) {
518
+ throw new CliError2("Remote input responses are not available from this CLI yet; use the server UI/API or switch to local state for direct JSONL edits.", 2);
519
+ }
141
520
  const parsedAnswers = Object.fromEntries(answers.map((entry) => {
142
521
  const [key, ...restValue] = entry.split("=");
143
522
  return [key, restValue.join("=")];
144
523
  }));
145
- const requestsPath = resolve(resolveAuthorityRunDir(context.projectRoot, run.value), "user-input.jsonl");
524
+ const requestsPath = resolve3(resolveAuthorityRunDir(context.projectRoot, run.value), "user-input.jsonl");
146
525
  const requests = readJsonlFile(requestsPath);
147
526
  const resolvedAt = new Date().toISOString();
148
527
  const next = requests.map((entry) => entry.requestId === request.value || entry.id === request.value ? { ...entry, status: "resolved", answers: parsedAnswers, respondedAt: resolvedAt, resolvedAt } : entry);
149
- writeFileSync(requestsPath, `${next.map((entry) => JSON.stringify(entry)).join(`
528
+ writeFileSync2(requestsPath, `${next.map((entry) => JSON.stringify(entry)).join(`
150
529
  `)}
151
530
  `, "utf8");
152
531
  return { ok: true, group: "inbox", command, details: { runId: run.value, requestId: request.value, answers: parsedAnswers } };