@h-rig/cli 0.0.6-alpha.3 → 0.0.6-alpha.31
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.
- package/dist/bin/rig.js +3562 -1125
- package/dist/src/commands/_authority-runs.js +1 -0
- package/dist/src/commands/_cli-format.js +369 -0
- package/dist/src/commands/_connection-state.js +1 -3
- package/dist/src/commands/_doctor-checks.js +13 -27
- package/dist/src/commands/_help-catalog.js +388 -0
- package/dist/src/commands/_operator-surface.js +204 -0
- package/dist/src/commands/_operator-view.js +861 -56
- package/dist/src/commands/_parsers.js +0 -2
- package/dist/src/commands/_pi-frontend.js +841 -0
- package/dist/src/commands/_pi-install.js +4 -3
- package/dist/src/commands/_pi-worker-bridge-extension.js +759 -0
- package/dist/src/commands/_policy.js +0 -2
- package/dist/src/commands/_preflight.js +32 -109
- package/dist/src/commands/_run-driver-helpers.js +0 -2
- package/dist/src/commands/_server-client.js +161 -31
- package/dist/src/commands/_snapshot-upload.js +8 -23
- package/dist/src/commands/_task-picker.js +44 -16
- package/dist/src/commands/agent.js +9 -9
- package/dist/src/commands/browser.js +4 -6
- package/dist/src/commands/connect.js +132 -25
- package/dist/src/commands/dist.js +4 -6
- package/dist/src/commands/doctor.js +13 -27
- package/dist/src/commands/github.js +10 -25
- package/dist/src/commands/inbox.js +351 -31
- package/dist/src/commands/init.js +298 -71
- package/dist/src/commands/inspect.js +10 -12
- package/dist/src/commands/inspector.js +2 -4
- package/dist/src/commands/plugin.js +81 -22
- package/dist/src/commands/profile-and-review.js +8 -10
- package/dist/src/commands/queue.js +2 -3
- package/dist/src/commands/remote.js +18 -20
- package/dist/src/commands/repo-git-harness.js +6 -8
- package/dist/src/commands/run.js +1157 -122
- package/dist/src/commands/server.js +217 -33
- package/dist/src/commands/setup.js +17 -37
- package/dist/src/commands/task-report-bug.js +5 -7
- package/dist/src/commands/task-run-driver.js +660 -73
- package/dist/src/commands/task.js +1542 -252
- package/dist/src/commands/test.js +3 -5
- package/dist/src/commands/workspace.js +4 -6
- package/dist/src/commands.js +3548 -1105
- package/dist/src/index.js +3562 -1128
- package/dist/src/launcher.js +5 -3
- package/dist/src/report-bug.js +3 -3
- package/dist/src/runner.js +5 -19
- package/package.json +6 -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,334 @@ 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 normalizeConnection(value) {
|
|
154
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
155
|
+
return null;
|
|
156
|
+
const record = value;
|
|
157
|
+
if (record.kind === "local")
|
|
158
|
+
return { kind: "local", mode: "auto" };
|
|
159
|
+
if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
|
|
160
|
+
const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
|
|
161
|
+
return { kind: "remote", baseUrl };
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
function readGlobalConnections(options = {}) {
|
|
166
|
+
const path = resolveGlobalConnectionsPath(options.env ?? process.env);
|
|
167
|
+
const payload = readJsonFile(path);
|
|
168
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
169
|
+
return { connections: {} };
|
|
170
|
+
}
|
|
171
|
+
const rawConnections = payload.connections;
|
|
172
|
+
const connections = {};
|
|
173
|
+
if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
|
|
174
|
+
for (const [alias, raw] of Object.entries(rawConnections)) {
|
|
175
|
+
const connection = normalizeConnection(raw);
|
|
176
|
+
if (connection)
|
|
177
|
+
connections[alias] = connection;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return { connections };
|
|
181
|
+
}
|
|
182
|
+
function readRepoConnection(projectRoot) {
|
|
183
|
+
const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
|
|
184
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
185
|
+
return null;
|
|
186
|
+
const record = payload;
|
|
187
|
+
const selected = typeof record.selected === "string" ? record.selected.trim() : "";
|
|
188
|
+
if (!selected)
|
|
189
|
+
return null;
|
|
190
|
+
return {
|
|
191
|
+
selected,
|
|
192
|
+
project: typeof record.project === "string" ? record.project : undefined,
|
|
193
|
+
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
197
|
+
const repo = readRepoConnection(projectRoot);
|
|
198
|
+
if (!repo)
|
|
199
|
+
return null;
|
|
200
|
+
if (repo.selected === "local")
|
|
201
|
+
return { alias: "local", connection: { kind: "local", mode: "auto" } };
|
|
202
|
+
const global = readGlobalConnections(options);
|
|
203
|
+
const connection = global.connections[repo.selected];
|
|
204
|
+
if (!connection) {
|
|
205
|
+
throw new CliError2(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
206
|
+
}
|
|
207
|
+
return { alias: repo.selected, connection };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// packages/cli/src/commands/_server-client.ts
|
|
211
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
212
|
+
import { resolve as resolve2 } from "path";
|
|
213
|
+
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
214
|
+
var scopedGitHubBearerTokens = new Map;
|
|
215
|
+
function cleanToken(value) {
|
|
216
|
+
const trimmed = value?.trim();
|
|
217
|
+
return trimmed ? trimmed : null;
|
|
218
|
+
}
|
|
219
|
+
function readPrivateRemoteSessionToken(projectRoot) {
|
|
220
|
+
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
221
|
+
if (!existsSync2(path))
|
|
222
|
+
return null;
|
|
223
|
+
try {
|
|
224
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
225
|
+
return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
|
|
226
|
+
} catch {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function readGitHubBearerTokenForRemote(projectRoot) {
|
|
231
|
+
const scopedKey = resolve2(projectRoot);
|
|
232
|
+
if (scopedGitHubBearerTokens.has(scopedKey))
|
|
233
|
+
return scopedGitHubBearerTokens.get(scopedKey) ?? null;
|
|
234
|
+
const privateSession = readPrivateRemoteSessionToken(projectRoot);
|
|
235
|
+
if (privateSession)
|
|
236
|
+
return privateSession;
|
|
237
|
+
return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
238
|
+
}
|
|
239
|
+
async function ensureServerForCli(projectRoot) {
|
|
240
|
+
try {
|
|
241
|
+
const selected = resolveSelectedConnection(projectRoot);
|
|
242
|
+
if (selected?.connection.kind === "remote") {
|
|
243
|
+
return {
|
|
244
|
+
baseUrl: selected.connection.baseUrl,
|
|
245
|
+
authToken: readGitHubBearerTokenForRemote(projectRoot),
|
|
246
|
+
connectionKind: "remote"
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
const connection = await ensureLocalRigServerConnection(projectRoot);
|
|
250
|
+
return {
|
|
251
|
+
baseUrl: connection.baseUrl,
|
|
252
|
+
authToken: connection.authToken,
|
|
253
|
+
connectionKind: "local"
|
|
254
|
+
};
|
|
255
|
+
} catch (error) {
|
|
256
|
+
if (error instanceof Error) {
|
|
257
|
+
throw new CliError2(error.message, 1);
|
|
258
|
+
}
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function mergeHeaders(headers, authToken) {
|
|
263
|
+
const merged = new Headers(headers);
|
|
264
|
+
if (authToken) {
|
|
265
|
+
merged.set("authorization", `Bearer ${authToken}`);
|
|
266
|
+
}
|
|
267
|
+
return merged;
|
|
268
|
+
}
|
|
269
|
+
function diagnosticMessage(payload) {
|
|
270
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
271
|
+
return null;
|
|
272
|
+
const record = payload;
|
|
273
|
+
const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
|
|
274
|
+
const messages = diagnostics.flatMap((entry) => {
|
|
275
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
276
|
+
return [];
|
|
277
|
+
const diagnostic = entry;
|
|
278
|
+
const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
|
|
279
|
+
const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
|
|
280
|
+
return message ? [`${kind}: ${message}`] : [];
|
|
281
|
+
});
|
|
282
|
+
return messages.length > 0 ? messages.join("; ") : null;
|
|
283
|
+
}
|
|
284
|
+
async function requestServerJson(context, pathname, init = {}) {
|
|
285
|
+
const server = await ensureServerForCli(context.projectRoot);
|
|
286
|
+
const response = await fetch(`${server.baseUrl}${pathname}`, {
|
|
287
|
+
...init,
|
|
288
|
+
headers: mergeHeaders(init.headers, server.authToken)
|
|
289
|
+
});
|
|
290
|
+
const text = await response.text();
|
|
291
|
+
const payload = text.trim().length > 0 ? (() => {
|
|
292
|
+
try {
|
|
293
|
+
return JSON.parse(text);
|
|
294
|
+
} catch {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
})() : null;
|
|
298
|
+
if (!response.ok) {
|
|
299
|
+
const diagnostics = diagnosticMessage(payload);
|
|
300
|
+
const detail = diagnostics ?? (text || response.statusText);
|
|
301
|
+
throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
|
|
302
|
+
}
|
|
303
|
+
return payload;
|
|
304
|
+
}
|
|
305
|
+
async function listRunsViaServer(context, options = {}) {
|
|
306
|
+
const url = new URL("http://rig.local/api/runs");
|
|
307
|
+
if (options.limit !== undefined)
|
|
308
|
+
url.searchParams.set("limit", String(options.limit));
|
|
309
|
+
const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
|
|
310
|
+
const runs = Array.isArray(payload) ? payload : payload && typeof payload === "object" && !Array.isArray(payload) && Array.isArray(payload.runs) ? payload.runs : [];
|
|
311
|
+
return runs.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry)));
|
|
312
|
+
}
|
|
313
|
+
async function getRunDetailsViaServer(context, runId) {
|
|
314
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}`);
|
|
315
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// packages/cli/src/commands/inbox.ts
|
|
319
|
+
function isRemoteConnectionSelected(projectRoot) {
|
|
320
|
+
return resolveSelectedConnection(projectRoot)?.connection.kind === "remote";
|
|
321
|
+
}
|
|
322
|
+
function runMatches(entry, filters) {
|
|
323
|
+
const runId = typeof entry.runId === "string" ? entry.runId : typeof entry.id === "string" ? entry.id : "";
|
|
324
|
+
const taskId = typeof entry.taskId === "string" ? entry.taskId : "";
|
|
325
|
+
return (!filters.run || runId === filters.run) && (!filters.task || taskId === filters.task);
|
|
326
|
+
}
|
|
327
|
+
function normalizeRemoteRunDetails(payload) {
|
|
328
|
+
const run = payload.run;
|
|
329
|
+
if (run && typeof run === "object" && !Array.isArray(run)) {
|
|
330
|
+
return {
|
|
331
|
+
...run,
|
|
332
|
+
...Array.isArray(payload.timeline) ? { timeline: payload.timeline } : {},
|
|
333
|
+
...Array.isArray(payload.approvals) ? { approvals: payload.approvals } : {},
|
|
334
|
+
...Array.isArray(payload.userInputs) ? { userInputs: payload.userInputs } : {}
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
return payload;
|
|
338
|
+
}
|
|
339
|
+
function remoteRecordsFromRun(run, kind) {
|
|
340
|
+
const key = kind === "approvals" ? "approvals" : "userInputs";
|
|
341
|
+
const direct = run[key];
|
|
342
|
+
if (!Array.isArray(direct))
|
|
343
|
+
return [];
|
|
344
|
+
const runId = typeof run.runId === "string" ? run.runId : typeof run.id === "string" ? run.id : "";
|
|
345
|
+
const taskId = typeof run.taskId === "string" ? run.taskId : "";
|
|
346
|
+
return direct.filter((record) => Boolean(record && typeof record === "object" && !Array.isArray(record))).map((record) => ({ runId, taskId, record }));
|
|
347
|
+
}
|
|
348
|
+
async function listRemoteInboxRecords(context, kind, filters) {
|
|
349
|
+
const runs = (await listRunsViaServer(context, { limit: 100 })).filter((entry) => runMatches(entry, filters));
|
|
350
|
+
const records = [];
|
|
351
|
+
for (const run of runs) {
|
|
352
|
+
const runId = typeof run.runId === "string" ? run.runId : typeof run.id === "string" ? run.id : "";
|
|
353
|
+
const detailed = runId ? normalizeRemoteRunDetails(await getRunDetailsViaServer(context, runId).catch(() => run)) : run;
|
|
354
|
+
records.push(...remoteRecordsFromRun(detailed, kind));
|
|
355
|
+
}
|
|
356
|
+
return records;
|
|
357
|
+
}
|
|
358
|
+
function listLocalInboxRecords(context, kind, filters) {
|
|
359
|
+
const fileName = kind === "approvals" ? "approvals.jsonl" : "user-input.jsonl";
|
|
360
|
+
const runs = listAuthorityRuns(context.projectRoot).filter((entry) => (!filters.run || entry.runId === filters.run) && (!filters.task || entry.taskId === filters.task));
|
|
361
|
+
return runs.flatMap((entry) => readJsonlFile(resolve3(resolveAuthorityRunDir(context.projectRoot, entry.runId), fileName)).map((record) => ({
|
|
362
|
+
runId: entry.runId,
|
|
363
|
+
taskId: entry.taskId ?? undefined,
|
|
364
|
+
record
|
|
365
|
+
})));
|
|
366
|
+
}
|
|
367
|
+
async function listInboxRecords(context, kind, filters) {
|
|
368
|
+
if (isRemoteConnectionSelected(context.projectRoot)) {
|
|
369
|
+
return listRemoteInboxRecords(context, kind, filters);
|
|
370
|
+
}
|
|
371
|
+
return listLocalInboxRecords(context, kind, filters);
|
|
372
|
+
}
|
|
47
373
|
async function executeInbox(context, args) {
|
|
48
374
|
const [command = "approvals", ...rest] = args;
|
|
49
375
|
switch (command) {
|
|
@@ -53,16 +379,10 @@ async function executeInbox(context, args) {
|
|
|
53
379
|
pending = run.rest;
|
|
54
380
|
const task = takeOption(pending, "--task");
|
|
55
381
|
pending = task.rest;
|
|
56
|
-
requireNoExtraArgs(pending, "
|
|
57
|
-
const
|
|
58
|
-
const approvals = runs.flatMap((entry) => readJsonlFile(resolve(resolveAuthorityRunDir(context.projectRoot, entry.runId), "approvals.jsonl")).map((record) => ({
|
|
59
|
-
runId: entry.runId,
|
|
60
|
-
record
|
|
61
|
-
})));
|
|
382
|
+
requireNoExtraArgs(pending, "rig inbox approvals [--run <id>] [--task <id>]");
|
|
383
|
+
const approvals = await listInboxRecords(context, "approvals", { run: run.value, task: task.value });
|
|
62
384
|
if (context.outputMode === "text") {
|
|
63
|
-
|
|
64
|
-
console.log(JSON.stringify(approval));
|
|
65
|
-
}
|
|
385
|
+
printFormattedOutput(formatInboxList("approvals", approvals));
|
|
66
386
|
}
|
|
67
387
|
return { ok: true, group: "inbox", command, details: { approvals } };
|
|
68
388
|
}
|
|
@@ -74,20 +394,23 @@ async function executeInbox(context, args) {
|
|
|
74
394
|
pending = request.rest;
|
|
75
395
|
const decision = takeOption(pending, "--decision");
|
|
76
396
|
pending = decision.rest;
|
|
77
|
-
const
|
|
78
|
-
pending =
|
|
79
|
-
requireNoExtraArgs(pending, "
|
|
397
|
+
const note2 = takeOption(pending, "--note");
|
|
398
|
+
pending = note2.rest;
|
|
399
|
+
requireNoExtraArgs(pending, "rig inbox approve --run <id> --request <id> --decision approve|reject [--note <text>]");
|
|
80
400
|
if (!run.value || !request.value || !decision.value) {
|
|
81
401
|
throw new CliError2("approve requires --run, --request, and --decision.");
|
|
82
402
|
}
|
|
83
403
|
if (decision.value !== "approve" && decision.value !== "reject") {
|
|
84
404
|
throw new CliError2("decision must be approve or reject.");
|
|
85
405
|
}
|
|
86
|
-
|
|
406
|
+
if (isRemoteConnectionSelected(context.projectRoot)) {
|
|
407
|
+
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);
|
|
408
|
+
}
|
|
409
|
+
const approvalsPath = resolve3(resolveAuthorityRunDir(context.projectRoot, run.value), "approvals.jsonl");
|
|
87
410
|
const approvals = readJsonlFile(approvalsPath);
|
|
88
411
|
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:
|
|
90
|
-
|
|
412
|
+
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);
|
|
413
|
+
writeFileSync2(approvalsPath, `${next.map((entry) => JSON.stringify(entry)).join(`
|
|
91
414
|
`)}
|
|
92
415
|
`, "utf8");
|
|
93
416
|
return { ok: true, group: "inbox", command, details: { runId: run.value, requestId: request.value, decision: decision.value } };
|
|
@@ -98,16 +421,10 @@ async function executeInbox(context, args) {
|
|
|
98
421
|
pending = run.rest;
|
|
99
422
|
const task = takeOption(pending, "--task");
|
|
100
423
|
pending = task.rest;
|
|
101
|
-
requireNoExtraArgs(pending, "
|
|
102
|
-
const
|
|
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
|
-
})));
|
|
424
|
+
requireNoExtraArgs(pending, "rig inbox inputs [--run <id>] [--task <id>]");
|
|
425
|
+
const requests = await listInboxRecords(context, "inputs", { run: run.value, task: task.value });
|
|
107
426
|
if (context.outputMode === "text") {
|
|
108
|
-
|
|
109
|
-
console.log(JSON.stringify(request));
|
|
110
|
-
}
|
|
427
|
+
printFormattedOutput(formatInboxList("inputs", requests));
|
|
111
428
|
}
|
|
112
429
|
return { ok: true, group: "inbox", command, details: { requests } };
|
|
113
430
|
}
|
|
@@ -134,19 +451,22 @@ async function executeInbox(context, args) {
|
|
|
134
451
|
remaining.push(current);
|
|
135
452
|
}
|
|
136
453
|
}
|
|
137
|
-
requireNoExtraArgs(remaining, "
|
|
454
|
+
requireNoExtraArgs(remaining, "rig inbox respond --run <id> --request <id> --answer key=value [--answer key=value]");
|
|
138
455
|
if (!run.value || !request.value || answers.length === 0) {
|
|
139
456
|
throw new CliError2("respond requires --run, --request, and at least one --answer.");
|
|
140
457
|
}
|
|
458
|
+
if (isRemoteConnectionSelected(context.projectRoot)) {
|
|
459
|
+
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);
|
|
460
|
+
}
|
|
141
461
|
const parsedAnswers = Object.fromEntries(answers.map((entry) => {
|
|
142
462
|
const [key, ...restValue] = entry.split("=");
|
|
143
463
|
return [key, restValue.join("=")];
|
|
144
464
|
}));
|
|
145
|
-
const requestsPath =
|
|
465
|
+
const requestsPath = resolve3(resolveAuthorityRunDir(context.projectRoot, run.value), "user-input.jsonl");
|
|
146
466
|
const requests = readJsonlFile(requestsPath);
|
|
147
467
|
const resolvedAt = new Date().toISOString();
|
|
148
468
|
const next = requests.map((entry) => entry.requestId === request.value || entry.id === request.value ? { ...entry, status: "resolved", answers: parsedAnswers, respondedAt: resolvedAt, resolvedAt } : entry);
|
|
149
|
-
|
|
469
|
+
writeFileSync2(requestsPath, `${next.map((entry) => JSON.stringify(entry)).join(`
|
|
150
470
|
`)}
|
|
151
471
|
`, "utf8");
|
|
152
472
|
return { ok: true, group: "inbox", command, details: { runId: run.value, requestId: request.value, answers: parsedAnswers } };
|