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

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 (49) hide show
  1. package/dist/bin/rig.js +4072 -1204
  2. package/dist/src/commands/_cli-format.js +369 -0
  3. package/dist/src/commands/_connection-state.js +12 -6
  4. package/dist/src/commands/_doctor-checks.js +65 -34
  5. package/dist/src/commands/_help-catalog.js +445 -0
  6. package/dist/src/commands/_operator-surface.js +220 -0
  7. package/dist/src/commands/_operator-view.js +1109 -63
  8. package/dist/src/commands/_parsers.js +0 -2
  9. package/dist/src/commands/_pi-frontend.js +1066 -0
  10. package/dist/src/commands/_pi-install.js +4 -3
  11. package/dist/src/commands/_pi-remote-session.js +757 -0
  12. package/dist/src/commands/_pi-worker-bridge-extension.js +820 -0
  13. package/dist/src/commands/_policy.js +0 -2
  14. package/dist/src/commands/_preflight.js +84 -116
  15. package/dist/src/commands/_run-driver-helpers.js +2 -2
  16. package/dist/src/commands/_server-client.js +211 -48
  17. package/dist/src/commands/_snapshot-upload.js +60 -30
  18. package/dist/src/commands/_spinner.js +63 -0
  19. package/dist/src/commands/_task-picker.js +44 -16
  20. package/dist/src/commands/agent.js +8 -9
  21. package/dist/src/commands/browser.js +4 -6
  22. package/dist/src/commands/connect.js +134 -26
  23. package/dist/src/commands/dist.js +4 -6
  24. package/dist/src/commands/doctor.js +65 -34
  25. package/dist/src/commands/github.js +62 -32
  26. package/dist/src/commands/inbox.js +396 -31
  27. package/dist/src/commands/init.js +342 -88
  28. package/dist/src/commands/inspect.js +282 -23
  29. package/dist/src/commands/inspector.js +2 -4
  30. package/dist/src/commands/pi.js +168 -0
  31. package/dist/src/commands/plugin.js +81 -22
  32. package/dist/src/commands/profile-and-review.js +8 -10
  33. package/dist/src/commands/queue.js +2 -3
  34. package/dist/src/commands/remote.js +18 -20
  35. package/dist/src/commands/repo-git-harness.js +6 -8
  36. package/dist/src/commands/run.js +1407 -130
  37. package/dist/src/commands/server.js +266 -40
  38. package/dist/src/commands/setup.js +69 -44
  39. package/dist/src/commands/task-report-bug.js +5 -7
  40. package/dist/src/commands/task-run-driver.js +662 -70
  41. package/dist/src/commands/task.js +1846 -259
  42. package/dist/src/commands/test.js +3 -5
  43. package/dist/src/commands/workspace.js +4 -6
  44. package/dist/src/commands.js +4054 -1180
  45. package/dist/src/index.js +4065 -1200
  46. package/dist/src/launcher.js +5 -3
  47. package/dist/src/report-bug.js +3 -3
  48. package/dist/src/runner.js +5 -19
  49. 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,379 @@ 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
+ async function ensureServerForCli(projectRoot) {
255
+ try {
256
+ const selected = resolveSelectedConnection(projectRoot);
257
+ if (selected?.connection.kind === "remote") {
258
+ const authToken = readGitHubBearerTokenForRemote(projectRoot);
259
+ const serverProjectRoot = selected.serverProjectRoot ?? await backfillRemoteServerProjectRoot(projectRoot, selected.connection.baseUrl, authToken);
260
+ return {
261
+ baseUrl: selected.connection.baseUrl,
262
+ authToken,
263
+ connectionKind: "remote",
264
+ serverProjectRoot
265
+ };
266
+ }
267
+ const connection = await ensureLocalRigServerConnection(projectRoot);
268
+ return {
269
+ baseUrl: connection.baseUrl,
270
+ authToken: connection.authToken,
271
+ connectionKind: "local",
272
+ serverProjectRoot: resolve2(projectRoot)
273
+ };
274
+ } catch (error) {
275
+ if (error instanceof Error) {
276
+ throw new CliError2(error.message, 1);
277
+ }
278
+ throw error;
279
+ }
280
+ }
281
+ async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
282
+ const repo = readRepoConnection(projectRoot);
283
+ const slug = repo?.project?.trim();
284
+ if (!slug)
285
+ return null;
286
+ try {
287
+ const response = await fetch(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`, {
288
+ headers: mergeHeaders(undefined, authToken)
289
+ });
290
+ if (!response.ok)
291
+ return null;
292
+ const payload = await response.json();
293
+ const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
294
+ const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
295
+ const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
296
+ const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
297
+ if (path)
298
+ writeRepoServerProjectRoot(projectRoot, path);
299
+ return path;
300
+ } catch {
301
+ return null;
302
+ }
303
+ }
304
+ function mergeHeaders(headers, authToken) {
305
+ const merged = new Headers(headers);
306
+ if (authToken) {
307
+ merged.set("authorization", `Bearer ${authToken}`);
308
+ }
309
+ return merged;
310
+ }
311
+ function diagnosticMessage(payload) {
312
+ if (!payload || typeof payload !== "object" || Array.isArray(payload))
313
+ return null;
314
+ const record = payload;
315
+ const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
316
+ const messages = diagnostics.flatMap((entry) => {
317
+ if (!entry || typeof entry !== "object" || Array.isArray(entry))
318
+ return [];
319
+ const diagnostic = entry;
320
+ const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
321
+ const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
322
+ return message ? [`${kind}: ${message}`] : [];
323
+ });
324
+ return messages.length > 0 ? messages.join("; ") : null;
325
+ }
326
+ async function requestServerJson(context, pathname, init = {}) {
327
+ const server = await ensureServerForCli(context.projectRoot);
328
+ const headers = mergeHeaders(init.headers, server.authToken);
329
+ if (server.serverProjectRoot)
330
+ headers.set("x-rig-project-root", server.serverProjectRoot);
331
+ const response = await fetch(`${server.baseUrl}${pathname}`, {
332
+ ...init,
333
+ headers
334
+ });
335
+ const text = await response.text();
336
+ const payload = text.trim().length > 0 ? (() => {
337
+ try {
338
+ return JSON.parse(text);
339
+ } catch {
340
+ return null;
341
+ }
342
+ })() : null;
343
+ if (!response.ok) {
344
+ const diagnostics = diagnosticMessage(payload);
345
+ const detail = diagnostics ?? (text || response.statusText);
346
+ throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
347
+ }
348
+ return payload;
349
+ }
350
+ async function listRunsViaServer(context, options = {}) {
351
+ const url = new URL("http://rig.local/api/runs");
352
+ if (options.limit !== undefined)
353
+ url.searchParams.set("limit", String(options.limit));
354
+ const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
355
+ const runs = Array.isArray(payload) ? payload : payload && typeof payload === "object" && !Array.isArray(payload) && Array.isArray(payload.runs) ? payload.runs : [];
356
+ return runs.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry)));
357
+ }
358
+ async function getRunDetailsViaServer(context, runId) {
359
+ const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}`);
360
+ return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
361
+ }
362
+
363
+ // packages/cli/src/commands/inbox.ts
364
+ function isRemoteConnectionSelected(projectRoot) {
365
+ return resolveSelectedConnection(projectRoot)?.connection.kind === "remote";
366
+ }
367
+ function runMatches(entry, filters) {
368
+ const runId = typeof entry.runId === "string" ? entry.runId : typeof entry.id === "string" ? entry.id : "";
369
+ const taskId = typeof entry.taskId === "string" ? entry.taskId : "";
370
+ return (!filters.run || runId === filters.run) && (!filters.task || taskId === filters.task);
371
+ }
372
+ function normalizeRemoteRunDetails(payload) {
373
+ const run = payload.run;
374
+ if (run && typeof run === "object" && !Array.isArray(run)) {
375
+ return {
376
+ ...run,
377
+ ...Array.isArray(payload.timeline) ? { timeline: payload.timeline } : {},
378
+ ...Array.isArray(payload.approvals) ? { approvals: payload.approvals } : {},
379
+ ...Array.isArray(payload.userInputs) ? { userInputs: payload.userInputs } : {}
380
+ };
381
+ }
382
+ return payload;
383
+ }
384
+ function remoteRecordsFromRun(run, kind) {
385
+ const key = kind === "approvals" ? "approvals" : "userInputs";
386
+ const direct = run[key];
387
+ if (!Array.isArray(direct))
388
+ return [];
389
+ const runId = typeof run.runId === "string" ? run.runId : typeof run.id === "string" ? run.id : "";
390
+ const taskId = typeof run.taskId === "string" ? run.taskId : "";
391
+ return direct.filter((record) => Boolean(record && typeof record === "object" && !Array.isArray(record))).map((record) => ({ runId, taskId, record }));
392
+ }
393
+ async function listRemoteInboxRecords(context, kind, filters) {
394
+ const runs = (await listRunsViaServer(context, { limit: 100 })).filter((entry) => runMatches(entry, filters));
395
+ const records = [];
396
+ for (const run of runs) {
397
+ const runId = typeof run.runId === "string" ? run.runId : typeof run.id === "string" ? run.id : "";
398
+ const detailed = runId ? normalizeRemoteRunDetails(await getRunDetailsViaServer(context, runId).catch(() => run)) : run;
399
+ records.push(...remoteRecordsFromRun(detailed, kind));
400
+ }
401
+ return records;
402
+ }
403
+ function listLocalInboxRecords(context, kind, filters) {
404
+ const fileName = kind === "approvals" ? "approvals.jsonl" : "user-input.jsonl";
405
+ const runs = listAuthorityRuns(context.projectRoot).filter((entry) => (!filters.run || entry.runId === filters.run) && (!filters.task || entry.taskId === filters.task));
406
+ return runs.flatMap((entry) => readJsonlFile(resolve3(resolveAuthorityRunDir(context.projectRoot, entry.runId), fileName)).map((record) => ({
407
+ runId: entry.runId,
408
+ taskId: entry.taskId ?? undefined,
409
+ record
410
+ })));
411
+ }
412
+ async function listInboxRecords(context, kind, filters) {
413
+ if (isRemoteConnectionSelected(context.projectRoot)) {
414
+ return listRemoteInboxRecords(context, kind, filters);
415
+ }
416
+ return listLocalInboxRecords(context, kind, filters);
417
+ }
47
418
  async function executeInbox(context, args) {
48
419
  const [command = "approvals", ...rest] = args;
49
420
  switch (command) {
@@ -53,16 +424,10 @@ async function executeInbox(context, args) {
53
424
  pending = run.rest;
54
425
  const task = takeOption(pending, "--task");
55
426
  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
- })));
427
+ requireNoExtraArgs(pending, "rig inbox approvals [--run <id>] [--task <id>]");
428
+ const approvals = await listInboxRecords(context, "approvals", { run: run.value, task: task.value });
62
429
  if (context.outputMode === "text") {
63
- for (const approval of approvals) {
64
- console.log(JSON.stringify(approval));
65
- }
430
+ printFormattedOutput(formatInboxList("approvals", approvals));
66
431
  }
67
432
  return { ok: true, group: "inbox", command, details: { approvals } };
68
433
  }
@@ -74,20 +439,23 @@ async function executeInbox(context, args) {
74
439
  pending = request.rest;
75
440
  const decision = takeOption(pending, "--decision");
76
441
  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>]");
442
+ const note2 = takeOption(pending, "--note");
443
+ pending = note2.rest;
444
+ requireNoExtraArgs(pending, "rig inbox approve --run <id> --request <id> --decision approve|reject [--note <text>]");
80
445
  if (!run.value || !request.value || !decision.value) {
81
446
  throw new CliError2("approve requires --run, --request, and --decision.");
82
447
  }
83
448
  if (decision.value !== "approve" && decision.value !== "reject") {
84
449
  throw new CliError2("decision must be approve or reject.");
85
450
  }
86
- const approvalsPath = resolve(resolveAuthorityRunDir(context.projectRoot, run.value), "approvals.jsonl");
451
+ if (isRemoteConnectionSelected(context.projectRoot)) {
452
+ 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);
453
+ }
454
+ const approvalsPath = resolve3(resolveAuthorityRunDir(context.projectRoot, run.value), "approvals.jsonl");
87
455
  const approvals = readJsonlFile(approvalsPath);
88
456
  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(`
457
+ 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);
458
+ writeFileSync2(approvalsPath, `${next.map((entry) => JSON.stringify(entry)).join(`
91
459
  `)}
92
460
  `, "utf8");
93
461
  return { ok: true, group: "inbox", command, details: { runId: run.value, requestId: request.value, decision: decision.value } };
@@ -98,16 +466,10 @@ async function executeInbox(context, args) {
98
466
  pending = run.rest;
99
467
  const task = takeOption(pending, "--task");
100
468
  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
- })));
469
+ requireNoExtraArgs(pending, "rig inbox inputs [--run <id>] [--task <id>]");
470
+ const requests = await listInboxRecords(context, "inputs", { run: run.value, task: task.value });
107
471
  if (context.outputMode === "text") {
108
- for (const request of requests) {
109
- console.log(JSON.stringify(request));
110
- }
472
+ printFormattedOutput(formatInboxList("inputs", requests));
111
473
  }
112
474
  return { ok: true, group: "inbox", command, details: { requests } };
113
475
  }
@@ -134,19 +496,22 @@ async function executeInbox(context, args) {
134
496
  remaining.push(current);
135
497
  }
136
498
  }
137
- requireNoExtraArgs(remaining, "bun run rig inbox respond --run <id> --request <id> --answer key=value [--answer key=value]");
499
+ requireNoExtraArgs(remaining, "rig inbox respond --run <id> --request <id> --answer key=value [--answer key=value]");
138
500
  if (!run.value || !request.value || answers.length === 0) {
139
501
  throw new CliError2("respond requires --run, --request, and at least one --answer.");
140
502
  }
503
+ if (isRemoteConnectionSelected(context.projectRoot)) {
504
+ 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);
505
+ }
141
506
  const parsedAnswers = Object.fromEntries(answers.map((entry) => {
142
507
  const [key, ...restValue] = entry.split("=");
143
508
  return [key, restValue.join("=")];
144
509
  }));
145
- const requestsPath = resolve(resolveAuthorityRunDir(context.projectRoot, run.value), "user-input.jsonl");
510
+ const requestsPath = resolve3(resolveAuthorityRunDir(context.projectRoot, run.value), "user-input.jsonl");
146
511
  const requests = readJsonlFile(requestsPath);
147
512
  const resolvedAt = new Date().toISOString();
148
513
  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(`
514
+ writeFileSync2(requestsPath, `${next.map((entry) => JSON.stringify(entry)).join(`
150
515
  `)}
151
516
  `, "utf8");
152
517
  return { ok: true, group: "inbox", command, details: { runId: run.value, requestId: request.value, answers: parsedAnswers } };