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