@h-rig/cli 0.0.6-alpha.27 → 0.0.6-alpha.28
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 +1038 -620
- package/dist/src/commands/_cli-format.js +211 -6
- package/dist/src/commands/_connection-state.js +1 -1
- package/dist/src/commands/_doctor-checks.js +3 -3
- package/dist/src/commands/_help-catalog.js +225 -64
- package/dist/src/commands/_operator-view.js +1 -1
- package/dist/src/commands/_pi-frontend.js +1 -1
- package/dist/src/commands/_pi-worker-bridge-extension.js +1 -1
- package/dist/src/commands/_preflight.js +2 -2
- package/dist/src/commands/_server-client.js +1 -1
- package/dist/src/commands/_snapshot-upload.js +1 -1
- package/dist/src/commands/agent.js +7 -7
- package/dist/src/commands/browser.js +4 -4
- package/dist/src/commands/connect.js +5 -4
- package/dist/src/commands/dist.js +4 -4
- package/dist/src/commands/doctor.js +3 -3
- package/dist/src/commands/github.js +1 -1
- package/dist/src/commands/inbox.js +351 -29
- package/dist/src/commands/init.js +3 -3
- package/dist/src/commands/inspect.js +10 -10
- package/dist/src/commands/inspector.js +2 -2
- package/dist/src/commands/plugin.js +3 -3
- package/dist/src/commands/profile-and-review.js +8 -8
- package/dist/src/commands/queue.js +1 -1
- package/dist/src/commands/remote.js +18 -18
- package/dist/src/commands/repo-git-harness.js +4 -4
- package/dist/src/commands/run.js +157 -37
- package/dist/src/commands/server.js +6 -5
- package/dist/src/commands/setup.js +8 -8
- package/dist/src/commands/task-report-bug.js +5 -5
- package/dist/src/commands/task-run-driver.js +1 -1
- package/dist/src/commands/task.js +451 -45
- package/dist/src/commands/test.js +3 -3
- package/dist/src/commands/workspace.js +4 -4
- package/dist/src/commands.js +1038 -620
- package/dist/src/index.js +1038 -620
- package/dist/src/report-bug.js +3 -3
- package/package.json +6 -6
|
@@ -98,7 +98,7 @@ function resolveSelectedConnection(projectRoot, options = {}) {
|
|
|
98
98
|
const global = readGlobalConnections(options);
|
|
99
99
|
const connection = global.connections[repo.selected];
|
|
100
100
|
if (!connection) {
|
|
101
|
-
throw new CliError2(`Selected Rig
|
|
101
|
+
throw new CliError2(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
102
102
|
}
|
|
103
103
|
return { alias: repo.selected, connection };
|
|
104
104
|
}
|
|
@@ -409,7 +409,7 @@ async function runRigDoctorChecks(options) {
|
|
|
409
409
|
const taskSourceKind = config?.taskSource?.kind;
|
|
410
410
|
checks.push(taskSourceKind ? check("task-source", "task source configured", "pass", taskSourceKind) : check("task-source", "task source configured", "fail", "missing taskSource", "Configure taskSource in rig.config.ts."));
|
|
411
411
|
const repo = readRepoConnection(projectRoot);
|
|
412
|
-
checks.push(repo ? check("project-link", "repo selected Rig
|
|
412
|
+
checks.push(repo ? check("project-link", "repo selected Rig server", repo.project ? "pass" : "warn", `${repo.selected}${repo.project ? ` -> ${repo.project}` : ""}`, "Run `rig init --yes --repo owner/repo` to link this checkout to a GitHub repo slug.") : check("project-link", "repo selected Rig server", "fail", "missing .rig/state/connection.json", "Run `rig init` or `rig server use <alias|local>`."));
|
|
413
413
|
const selected = (() => {
|
|
414
414
|
try {
|
|
415
415
|
return resolveSelectedConnection(projectRoot);
|
|
@@ -417,7 +417,7 @@ async function runRigDoctorChecks(options) {
|
|
|
417
417
|
return null;
|
|
418
418
|
}
|
|
419
419
|
})();
|
|
420
|
-
checks.push(selected ? check("connection", "selected server connection", "pass", selected.connection.kind === "remote" ? selected.connection.baseUrl : "local auto") : check("connection", "selected server
|
|
420
|
+
checks.push(selected ? check("connection", "selected server connection", "pass", selected.connection.kind === "remote" ? selected.connection.baseUrl : "local auto") : check("connection", "selected server", repo ? "fail" : "warn", repo ? "selected alias is missing" : "will auto-start local server", repo ? "Run `rig server list` and `rig server use <alias|local>`." : undefined));
|
|
421
421
|
let server = null;
|
|
422
422
|
try {
|
|
423
423
|
server = await (options.resolveServer ?? ensureServerForCli)(projectRoot);
|
|
@@ -113,7 +113,7 @@ function resolveSelectedConnection(projectRoot, options = {}) {
|
|
|
113
113
|
const global = readGlobalConnections(options);
|
|
114
114
|
const connection = global.connections[repo.selected];
|
|
115
115
|
if (!connection) {
|
|
116
|
-
throw new CliError2(`Selected Rig
|
|
116
|
+
throw new CliError2(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
117
117
|
}
|
|
118
118
|
return { alias: repo.selected, connection };
|
|
119
119
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
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";
|
|
@@ -44,6 +44,334 @@ import {
|
|
|
44
44
|
readJsonlFile,
|
|
45
45
|
resolveAuthorityRunDir
|
|
46
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
|
+
}
|
|
47
375
|
async function executeInbox(context, args) {
|
|
48
376
|
const [command = "approvals", ...rest] = args;
|
|
49
377
|
switch (command) {
|
|
@@ -53,16 +381,10 @@ async function executeInbox(context, args) {
|
|
|
53
381
|
pending = run.rest;
|
|
54
382
|
const task = takeOption(pending, "--task");
|
|
55
383
|
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
|
-
})));
|
|
384
|
+
requireNoExtraArgs(pending, "rig inbox approvals [--run <id>] [--task <id>]");
|
|
385
|
+
const approvals = await listInboxRecords(context, "approvals", { run: run.value, task: task.value });
|
|
62
386
|
if (context.outputMode === "text") {
|
|
63
|
-
|
|
64
|
-
console.log(JSON.stringify(approval));
|
|
65
|
-
}
|
|
387
|
+
printFormattedOutput(formatInboxList("approvals", approvals));
|
|
66
388
|
}
|
|
67
389
|
return { ok: true, group: "inbox", command, details: { approvals } };
|
|
68
390
|
}
|
|
@@ -74,20 +396,23 @@ async function executeInbox(context, args) {
|
|
|
74
396
|
pending = request.rest;
|
|
75
397
|
const decision = takeOption(pending, "--decision");
|
|
76
398
|
pending = decision.rest;
|
|
77
|
-
const
|
|
78
|
-
pending =
|
|
79
|
-
requireNoExtraArgs(pending, "
|
|
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>]");
|
|
80
402
|
if (!run.value || !request.value || !decision.value) {
|
|
81
403
|
throw new CliError2("approve requires --run, --request, and --decision.");
|
|
82
404
|
}
|
|
83
405
|
if (decision.value !== "approve" && decision.value !== "reject") {
|
|
84
406
|
throw new CliError2("decision must be approve or reject.");
|
|
85
407
|
}
|
|
86
|
-
|
|
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");
|
|
87
412
|
const approvals = readJsonlFile(approvalsPath);
|
|
88
413
|
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
|
-
|
|
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(`
|
|
91
416
|
`)}
|
|
92
417
|
`, "utf8");
|
|
93
418
|
return { ok: true, group: "inbox", command, details: { runId: run.value, requestId: request.value, decision: decision.value } };
|
|
@@ -98,16 +423,10 @@ async function executeInbox(context, args) {
|
|
|
98
423
|
pending = run.rest;
|
|
99
424
|
const task = takeOption(pending, "--task");
|
|
100
425
|
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
|
-
})));
|
|
426
|
+
requireNoExtraArgs(pending, "rig inbox inputs [--run <id>] [--task <id>]");
|
|
427
|
+
const requests = await listInboxRecords(context, "inputs", { run: run.value, task: task.value });
|
|
107
428
|
if (context.outputMode === "text") {
|
|
108
|
-
|
|
109
|
-
console.log(JSON.stringify(request));
|
|
110
|
-
}
|
|
429
|
+
printFormattedOutput(formatInboxList("inputs", requests));
|
|
111
430
|
}
|
|
112
431
|
return { ok: true, group: "inbox", command, details: { requests } };
|
|
113
432
|
}
|
|
@@ -134,19 +453,22 @@ async function executeInbox(context, args) {
|
|
|
134
453
|
remaining.push(current);
|
|
135
454
|
}
|
|
136
455
|
}
|
|
137
|
-
requireNoExtraArgs(remaining, "
|
|
456
|
+
requireNoExtraArgs(remaining, "rig inbox respond --run <id> --request <id> --answer key=value [--answer key=value]");
|
|
138
457
|
if (!run.value || !request.value || answers.length === 0) {
|
|
139
458
|
throw new CliError2("respond requires --run, --request, and at least one --answer.");
|
|
140
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
|
+
}
|
|
141
463
|
const parsedAnswers = Object.fromEntries(answers.map((entry) => {
|
|
142
464
|
const [key, ...restValue] = entry.split("=");
|
|
143
465
|
return [key, restValue.join("=")];
|
|
144
466
|
}));
|
|
145
|
-
const requestsPath =
|
|
467
|
+
const requestsPath = resolve3(resolveAuthorityRunDir(context.projectRoot, run.value), "user-input.jsonl");
|
|
146
468
|
const requests = readJsonlFile(requestsPath);
|
|
147
469
|
const resolvedAt = new Date().toISOString();
|
|
148
470
|
const next = requests.map((entry) => entry.requestId === request.value || entry.id === request.value ? { ...entry, status: "resolved", answers: parsedAnswers, respondedAt: resolvedAt, resolvedAt } : entry);
|
|
149
|
-
|
|
471
|
+
writeFileSync2(requestsPath, `${next.map((entry) => JSON.stringify(entry)).join(`
|
|
150
472
|
`)}
|
|
151
473
|
`, "utf8");
|
|
152
474
|
return { ok: true, group: "inbox", command, details: { runId: run.value, requestId: request.value, answers: parsedAnswers } };
|
|
@@ -148,7 +148,7 @@ function resolveSelectedConnection(projectRoot, options = {}) {
|
|
|
148
148
|
const global = readGlobalConnections(options);
|
|
149
149
|
const connection = global.connections[repo.selected];
|
|
150
150
|
if (!connection) {
|
|
151
|
-
throw new CliError2(`Selected Rig
|
|
151
|
+
throw new CliError2(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
152
152
|
}
|
|
153
153
|
return { alias: repo.selected, connection };
|
|
154
154
|
}
|
|
@@ -751,7 +751,7 @@ async function runRigDoctorChecks(options) {
|
|
|
751
751
|
const taskSourceKind = config?.taskSource?.kind;
|
|
752
752
|
checks.push(taskSourceKind ? check("task-source", "task source configured", "pass", taskSourceKind) : check("task-source", "task source configured", "fail", "missing taskSource", "Configure taskSource in rig.config.ts."));
|
|
753
753
|
const repo = readRepoConnection(projectRoot);
|
|
754
|
-
checks.push(repo ? check("project-link", "repo selected Rig
|
|
754
|
+
checks.push(repo ? check("project-link", "repo selected Rig server", repo.project ? "pass" : "warn", `${repo.selected}${repo.project ? ` -> ${repo.project}` : ""}`, "Run `rig init --yes --repo owner/repo` to link this checkout to a GitHub repo slug.") : check("project-link", "repo selected Rig server", "fail", "missing .rig/state/connection.json", "Run `rig init` or `rig server use <alias|local>`."));
|
|
755
755
|
const selected = (() => {
|
|
756
756
|
try {
|
|
757
757
|
return resolveSelectedConnection(projectRoot);
|
|
@@ -759,7 +759,7 @@ async function runRigDoctorChecks(options) {
|
|
|
759
759
|
return null;
|
|
760
760
|
}
|
|
761
761
|
})();
|
|
762
|
-
checks.push(selected ? check("connection", "selected server connection", "pass", selected.connection.kind === "remote" ? selected.connection.baseUrl : "local auto") : check("connection", "selected server
|
|
762
|
+
checks.push(selected ? check("connection", "selected server connection", "pass", selected.connection.kind === "remote" ? selected.connection.baseUrl : "local auto") : check("connection", "selected server", repo ? "fail" : "warn", repo ? "selected alias is missing" : "will auto-start local server", repo ? "Run `rig server list` and `rig server use <alias|local>`." : undefined));
|
|
763
763
|
let server = null;
|
|
764
764
|
try {
|
|
765
765
|
server = await (options.resolveServer ?? ensureServerForCli)(projectRoot);
|
|
@@ -60,8 +60,8 @@ async function executeInspect(context, args) {
|
|
|
60
60
|
switch (command) {
|
|
61
61
|
case "logs": {
|
|
62
62
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
63
|
-
requireNoExtraArgs(remaining, "
|
|
64
|
-
const requiredTask = requireTask(task, "
|
|
63
|
+
requireNoExtraArgs(remaining, "rig inspect logs --task <task-id>");
|
|
64
|
+
const requiredTask = requireTask(task, "rig inspect logs --task <task-id>");
|
|
65
65
|
const latestRun = listAuthorityRuns(context.projectRoot).map((entry) => readAuthorityRun(context.projectRoot, entry.runId)).filter((run) => Boolean(run)).filter((run) => run.taskId === requiredTask).sort((left, right) => String(right.updatedAt ?? "").localeCompare(String(left.updatedAt ?? "")))[0];
|
|
66
66
|
if (!latestRun) {
|
|
67
67
|
throw new CliError2(`No runs found for ${requiredTask}.`);
|
|
@@ -75,8 +75,8 @@ async function executeInspect(context, args) {
|
|
|
75
75
|
}
|
|
76
76
|
case "artifacts": {
|
|
77
77
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
78
|
-
requireNoExtraArgs(remaining, "
|
|
79
|
-
const requiredTask = requireTask(task, "
|
|
78
|
+
requireNoExtraArgs(remaining, "rig inspect artifacts --task <task-id>");
|
|
79
|
+
const requiredTask = requireTask(task, "rig inspect artifacts --task <task-id>");
|
|
80
80
|
const artifactRoot = resolveTaskArtifactDirs(context.projectRoot, requiredTask).find((path) => existsSync(path));
|
|
81
81
|
if (!artifactRoot) {
|
|
82
82
|
throw new CliError2(`No artifacts found for ${requiredTask}.`);
|
|
@@ -90,8 +90,8 @@ async function executeInspect(context, args) {
|
|
|
90
90
|
previewPending = task.rest;
|
|
91
91
|
const file = takeOption(previewPending, "--file");
|
|
92
92
|
previewPending = file.rest;
|
|
93
|
-
requireNoExtraArgs(previewPending, "
|
|
94
|
-
const requiredTask = requireTask(task.value, "
|
|
93
|
+
requireNoExtraArgs(previewPending, "rig inspect artifact --task <task-id> --file <name>");
|
|
94
|
+
const requiredTask = requireTask(task.value, "rig inspect artifact --task <task-id> --file <name>");
|
|
95
95
|
if (!file.value) {
|
|
96
96
|
throw new CliError2("Missing --file for rig inspect artifact.");
|
|
97
97
|
}
|
|
@@ -120,7 +120,7 @@ async function executeInspect(context, args) {
|
|
|
120
120
|
}
|
|
121
121
|
case "diff": {
|
|
122
122
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
123
|
-
requireNoExtraArgs(remaining, "
|
|
123
|
+
requireNoExtraArgs(remaining, "rig inspect diff [--task <task-id>]");
|
|
124
124
|
if (task) {
|
|
125
125
|
const files = changedFilesForTask(context.projectRoot, task, false);
|
|
126
126
|
for (const file of files) {
|
|
@@ -132,7 +132,7 @@ async function executeInspect(context, args) {
|
|
|
132
132
|
return { ok: true, group: "inspect", command, details: { task: task || null } };
|
|
133
133
|
}
|
|
134
134
|
case "failures": {
|
|
135
|
-
requireNoExtraArgs(rest, "
|
|
135
|
+
requireNoExtraArgs(rest, "rig inspect failures");
|
|
136
136
|
const failed = resolveHarnessPaths(context.projectRoot).failedApproachesPath;
|
|
137
137
|
if (!existsSync(failed)) {
|
|
138
138
|
console.log("No failures recorded.");
|
|
@@ -142,7 +142,7 @@ async function executeInspect(context, args) {
|
|
|
142
142
|
return { ok: true, group: "inspect", command };
|
|
143
143
|
}
|
|
144
144
|
case "graph":
|
|
145
|
-
requireNoExtraArgs(rest, "
|
|
145
|
+
requireNoExtraArgs(rest, "rig inspect graph");
|
|
146
146
|
{
|
|
147
147
|
const monorepoRoot = resolveMonorepoRoot(context.projectRoot);
|
|
148
148
|
const result = runCapture(["br", "--no-db", "list", "--pretty"], monorepoRoot);
|
|
@@ -153,7 +153,7 @@ async function executeInspect(context, args) {
|
|
|
153
153
|
}
|
|
154
154
|
return { ok: true, group: "inspect", command };
|
|
155
155
|
case "audit": {
|
|
156
|
-
requireNoExtraArgs(rest, "
|
|
156
|
+
requireNoExtraArgs(rest, "rig inspect audit");
|
|
157
157
|
const auditPath = resolve(resolveHarnessPaths(context.projectRoot).logsDir, "audit.jsonl");
|
|
158
158
|
if (!existsSync(auditPath)) {
|
|
159
159
|
console.log("No audit log found.");
|
|
@@ -104,7 +104,7 @@ async function executeInspector(context, args) {
|
|
|
104
104
|
pending = secondsResult.rest;
|
|
105
105
|
const pollMsResult = takeOption(pending, "--poll-ms");
|
|
106
106
|
pending = pollMsResult.rest;
|
|
107
|
-
requireNoExtraArgs(pending, "
|
|
107
|
+
requireNoExtraArgs(pending, "rig inspector stream [--once] [--seconds <n>] [--poll-ms <n>]");
|
|
108
108
|
const seconds = secondsResult.value ? parseRequiredPositiveInt(secondsResult.value, "--seconds") : null;
|
|
109
109
|
const pollMs = pollMsResult.value ? parseRequiredPositiveInt(pollMsResult.value, "--poll-ms") : null;
|
|
110
110
|
if (context.outputMode === "json" && !onceResult.value && !seconds) {
|
|
@@ -198,7 +198,7 @@ async function executeInspector(context, args) {
|
|
|
198
198
|
let pending = rest;
|
|
199
199
|
const scanIdResult = takeOption(pending, "--scan-id");
|
|
200
200
|
pending = scanIdResult.rest;
|
|
201
|
-
requireNoExtraArgs(pending, "
|
|
201
|
+
requireNoExtraArgs(pending, "rig inspector scan-upstream-drift [--scan-id <id>]");
|
|
202
202
|
const connection = await ensureLocalRigServerConnection(context.projectRoot);
|
|
203
203
|
const response = await fetch(new URL("/api/inspector/tools/invoke", connection.baseUrl), {
|
|
204
204
|
method: "POST",
|
|
@@ -58,7 +58,7 @@ async function executePlugin(context, args) {
|
|
|
58
58
|
const [command = "list", ...rest] = args;
|
|
59
59
|
switch (command) {
|
|
60
60
|
case "list": {
|
|
61
|
-
requireNoExtraArgs(rest, "
|
|
61
|
+
requireNoExtraArgs(rest, "rig plugin list");
|
|
62
62
|
const legacyPlugins = context.plugins.list();
|
|
63
63
|
const declarative = [];
|
|
64
64
|
const config = await loadRigConfigOrNull(context.projectRoot);
|
|
@@ -125,8 +125,8 @@ async function executePlugin(context, args) {
|
|
|
125
125
|
}
|
|
126
126
|
case "validate": {
|
|
127
127
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
128
|
-
requireNoExtraArgs(remaining, "
|
|
129
|
-
const taskId = requireTask(task, "
|
|
128
|
+
requireNoExtraArgs(remaining, "rig plugin validate --task <task-id>");
|
|
129
|
+
const taskId = requireTask(task, "rig plugin validate --task <task-id>");
|
|
130
130
|
const results = await context.plugins.runValidators(taskId);
|
|
131
131
|
const passed = results.filter((result) => result.passed).length;
|
|
132
132
|
const failed = results.length - passed;
|