@h-rig/cli 0.0.6-alpha.7 → 0.0.6-alpha.70
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/README.md +1 -1
- package/dist/bin/rig.js +4507 -1506
- package/dist/src/commands/_async-ui.js +152 -0
- package/dist/src/commands/_authority-runs.js +2 -3
- package/dist/src/commands/_cli-format.js +369 -0
- package/dist/src/commands/_connection-state.js +30 -11
- package/dist/src/commands/_doctor-checks.js +177 -43
- package/dist/src/commands/_help-catalog.js +485 -0
- package/dist/src/commands/_json-output.js +56 -0
- package/dist/src/commands/_operator-surface.js +220 -0
- package/dist/src/commands/_operator-view.js +595 -72
- package/dist/src/commands/_parsers.js +18 -11
- package/dist/src/commands/_pi-frontend.js +411 -0
- package/dist/src/commands/_pi-install.js +4 -3
- package/dist/src/commands/_policy.js +12 -5
- package/dist/src/commands/_preflight.js +187 -127
- package/dist/src/commands/_run-driver-helpers.js +75 -22
- package/dist/src/commands/_run-replay.js +142 -0
- package/dist/src/commands/_server-client.js +343 -60
- package/dist/src/commands/_snapshot-upload.js +160 -38
- package/dist/src/commands/_spinner.js +65 -0
- package/dist/src/commands/_task-picker.js +44 -16
- package/dist/src/commands/agent.js +39 -20
- package/dist/src/commands/browser.js +28 -21
- package/dist/src/commands/connect.js +146 -33
- package/dist/src/commands/dist.js +19 -12
- package/dist/src/commands/doctor.js +304 -44
- package/dist/src/commands/github.js +301 -52
- package/dist/src/commands/inbox.js +679 -72
- package/dist/src/commands/init.js +622 -118
- package/dist/src/commands/inspect.js +515 -32
- package/dist/src/commands/inspector.js +20 -13
- package/dist/src/commands/pi.js +177 -0
- package/dist/src/commands/plugin.js +95 -27
- package/dist/src/commands/profile-and-review.js +26 -19
- package/dist/src/commands/queue.js +32 -12
- package/dist/src/commands/remote.js +43 -36
- package/dist/src/commands/repo-git-harness.js +22 -15
- package/dist/src/commands/run.js +1162 -158
- package/dist/src/commands/server.js +373 -56
- package/dist/src/commands/setup.js +316 -62
- package/dist/src/commands/stats.js +1030 -0
- package/dist/src/commands/task-report-bug.js +29 -22
- package/dist/src/commands/task-run-driver.js +862 -129
- package/dist/src/commands/task.js +1423 -311
- package/dist/src/commands/test.js +15 -8
- package/dist/src/commands/workspace.js +18 -11
- package/dist/src/commands.js +4446 -1499
- package/dist/src/index.js +4502 -1504
- package/dist/src/launcher.js +77 -13
- package/dist/src/report-bug.js +3 -3
- package/dist/src/runner.js +16 -22
- package/package.json +10 -5
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/cli/src/commands/task.ts
|
|
3
|
-
import { readFileSync as
|
|
4
|
-
import { spawnSync
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
4
|
+
import { spawnSync } from "child_process";
|
|
5
|
+
import { resolve as resolve3 } from "path";
|
|
6
|
+
import { cancel as cancel2, confirm, isCancel as isCancel2 } from "@clack/prompts";
|
|
7
7
|
|
|
8
8
|
// packages/cli/src/runner.ts
|
|
9
9
|
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
10
|
-
import { CliError } from "@rig/runtime/control-plane/errors";
|
|
10
|
+
import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
|
|
11
11
|
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
12
|
-
import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
|
|
13
|
-
import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
|
|
14
12
|
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
15
|
-
|
|
13
|
+
|
|
14
|
+
class CliError extends RuntimeCliError {
|
|
15
|
+
hint;
|
|
16
|
+
constructor(message, exitCode = 1, options = {}) {
|
|
17
|
+
super(message, exitCode);
|
|
18
|
+
if (options.hint?.trim()) {
|
|
19
|
+
this.hint = options.hint.trim();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
16
23
|
function takeFlag(args, flag) {
|
|
17
24
|
const rest = [];
|
|
18
25
|
let value = false;
|
|
@@ -33,7 +40,7 @@ function takeOption(args, option) {
|
|
|
33
40
|
if (current === option) {
|
|
34
41
|
const next = args[index + 1];
|
|
35
42
|
if (!next || next.startsWith("-")) {
|
|
36
|
-
throw new CliError(`Missing value for ${option}`);
|
|
43
|
+
throw new CliError(`Missing value for ${option}`, 1, { hint: `Provide a value after ${option}, e.g. \`${option} <value>\`.` });
|
|
37
44
|
}
|
|
38
45
|
value = next;
|
|
39
46
|
index += 1;
|
|
@@ -80,8 +87,7 @@ import {
|
|
|
80
87
|
import {
|
|
81
88
|
readAuthorityRun,
|
|
82
89
|
readJsonlFile,
|
|
83
|
-
|
|
84
|
-
writeJsonFile
|
|
90
|
+
writeAuthorityRunRecord
|
|
85
91
|
} from "@rig/runtime/control-plane/authority-files";
|
|
86
92
|
|
|
87
93
|
// packages/cli/src/commands/_paths.ts
|
|
@@ -127,9 +133,14 @@ function readJsonFile(path) {
|
|
|
127
133
|
try {
|
|
128
134
|
return JSON.parse(readFileSync(path, "utf8"));
|
|
129
135
|
} catch (error) {
|
|
130
|
-
throw new
|
|
136
|
+
throw new CliError(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1, { hint: "Fix or delete that file, then re-select a server with `rig server use <alias|local>`." });
|
|
131
137
|
}
|
|
132
138
|
}
|
|
139
|
+
function writeJsonFile(path, value) {
|
|
140
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
141
|
+
writeFileSync(path, `${JSON.stringify(value, null, 2)}
|
|
142
|
+
`, "utf8");
|
|
143
|
+
}
|
|
133
144
|
function normalizeConnection(value) {
|
|
134
145
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
135
146
|
return null;
|
|
@@ -170,29 +181,47 @@ function readRepoConnection(projectRoot) {
|
|
|
170
181
|
return {
|
|
171
182
|
selected,
|
|
172
183
|
project: typeof record.project === "string" ? record.project : undefined,
|
|
173
|
-
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
|
|
184
|
+
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
|
|
185
|
+
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
174
186
|
};
|
|
175
187
|
}
|
|
188
|
+
function writeRepoConnection(projectRoot, state) {
|
|
189
|
+
writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
|
|
190
|
+
}
|
|
176
191
|
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
177
192
|
const repo = readRepoConnection(projectRoot);
|
|
178
193
|
if (!repo)
|
|
179
194
|
return null;
|
|
180
195
|
if (repo.selected === "local")
|
|
181
|
-
return { alias: "local", connection: { kind: "local", mode: "auto" } };
|
|
196
|
+
return { alias: "local", connection: { kind: "local", mode: "auto" }, serverProjectRoot: repo.serverProjectRoot };
|
|
182
197
|
const global = readGlobalConnections(options);
|
|
183
198
|
const connection = global.connections[repo.selected];
|
|
184
199
|
if (!connection) {
|
|
185
|
-
throw new
|
|
200
|
+
throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
186
201
|
}
|
|
187
|
-
return { alias: repo.selected, connection };
|
|
202
|
+
return { alias: repo.selected, connection, serverProjectRoot: repo.serverProjectRoot };
|
|
203
|
+
}
|
|
204
|
+
function writeRepoServerProjectRoot(projectRoot, serverProjectRoot) {
|
|
205
|
+
const repo = readRepoConnection(projectRoot);
|
|
206
|
+
if (!repo)
|
|
207
|
+
return;
|
|
208
|
+
writeRepoConnection(projectRoot, { ...repo, serverProjectRoot });
|
|
188
209
|
}
|
|
189
210
|
|
|
190
211
|
// packages/cli/src/commands/_server-client.ts
|
|
191
|
-
import { spawnSync } from "child_process";
|
|
192
212
|
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
193
213
|
import { resolve as resolve2 } from "path";
|
|
194
214
|
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
195
|
-
var
|
|
215
|
+
var scopedGitHubBearerTokens = new Map;
|
|
216
|
+
var serverPhaseListener = null;
|
|
217
|
+
function setServerPhaseListener(listener) {
|
|
218
|
+
const previous = serverPhaseListener;
|
|
219
|
+
serverPhaseListener = listener;
|
|
220
|
+
return previous;
|
|
221
|
+
}
|
|
222
|
+
function reportServerPhase(label) {
|
|
223
|
+
serverPhaseListener?.(label);
|
|
224
|
+
}
|
|
196
225
|
function cleanToken(value) {
|
|
197
226
|
const trimmed = value?.trim();
|
|
198
227
|
return trimmed ? trimmed : null;
|
|
@@ -209,49 +238,80 @@ function readPrivateRemoteSessionToken(projectRoot) {
|
|
|
209
238
|
}
|
|
210
239
|
}
|
|
211
240
|
function readGitHubBearerTokenForRemote(projectRoot) {
|
|
212
|
-
|
|
213
|
-
|
|
241
|
+
const scopedKey = resolve2(projectRoot);
|
|
242
|
+
if (scopedGitHubBearerTokens.has(scopedKey))
|
|
243
|
+
return scopedGitHubBearerTokens.get(scopedKey) ?? null;
|
|
214
244
|
const privateSession = readPrivateRemoteSessionToken(projectRoot);
|
|
215
|
-
if (privateSession)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
245
|
+
if (privateSession)
|
|
246
|
+
return privateSession;
|
|
247
|
+
return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
248
|
+
}
|
|
249
|
+
function readStoredGitHubAuthToken(projectRoot) {
|
|
250
|
+
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
251
|
+
if (!existsSync2(path))
|
|
252
|
+
return null;
|
|
253
|
+
try {
|
|
254
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
255
|
+
return cleanToken(typeof parsed.token === "string" ? parsed.token : undefined);
|
|
256
|
+
} catch {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function readLocalConnectionFallbackToken(projectRoot) {
|
|
261
|
+
return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
|
|
231
262
|
}
|
|
232
263
|
async function ensureServerForCli(projectRoot) {
|
|
233
264
|
try {
|
|
234
265
|
const selected = resolveSelectedConnection(projectRoot);
|
|
235
266
|
if (selected?.connection.kind === "remote") {
|
|
267
|
+
reportServerPhase(`Connecting to ${selected.alias}\u2026`);
|
|
268
|
+
const authToken = readGitHubBearerTokenForRemote(projectRoot);
|
|
269
|
+
const serverProjectRoot = selected.serverProjectRoot ?? await backfillRemoteServerProjectRoot(projectRoot, selected.connection.baseUrl, authToken);
|
|
236
270
|
return {
|
|
237
271
|
baseUrl: selected.connection.baseUrl,
|
|
238
|
-
authToken
|
|
239
|
-
connectionKind: "remote"
|
|
272
|
+
authToken,
|
|
273
|
+
connectionKind: "remote",
|
|
274
|
+
serverProjectRoot
|
|
240
275
|
};
|
|
241
276
|
}
|
|
277
|
+
reportServerPhase("Starting local Rig server\u2026");
|
|
242
278
|
const connection = await ensureLocalRigServerConnection(projectRoot);
|
|
243
279
|
return {
|
|
244
280
|
baseUrl: connection.baseUrl,
|
|
245
|
-
authToken: connection.authToken,
|
|
246
|
-
connectionKind: "local"
|
|
281
|
+
authToken: connection.authToken ?? readLocalConnectionFallbackToken(projectRoot),
|
|
282
|
+
connectionKind: "local",
|
|
283
|
+
serverProjectRoot: resolve2(projectRoot)
|
|
247
284
|
};
|
|
248
285
|
} catch (error) {
|
|
249
286
|
if (error instanceof Error) {
|
|
250
|
-
throw new
|
|
287
|
+
throw new CliError(error.message, 1);
|
|
251
288
|
}
|
|
252
289
|
throw error;
|
|
253
290
|
}
|
|
254
291
|
}
|
|
292
|
+
async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
|
|
293
|
+
const repo = readRepoConnection(projectRoot);
|
|
294
|
+
const slug = repo?.project?.trim();
|
|
295
|
+
if (!slug)
|
|
296
|
+
return null;
|
|
297
|
+
try {
|
|
298
|
+
const response = await fetch(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`, {
|
|
299
|
+
headers: mergeHeaders(undefined, authToken)
|
|
300
|
+
});
|
|
301
|
+
if (!response.ok)
|
|
302
|
+
return null;
|
|
303
|
+
const payload = await response.json();
|
|
304
|
+
const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
|
|
305
|
+
const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
|
|
306
|
+
const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
|
|
307
|
+
const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
|
|
308
|
+
if (path)
|
|
309
|
+
writeRepoServerProjectRoot(projectRoot, path);
|
|
310
|
+
return path;
|
|
311
|
+
} catch {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
255
315
|
function appendTaskFilterParams(url, filters) {
|
|
256
316
|
if (filters.assignee)
|
|
257
317
|
url.searchParams.set("assignee", filters.assignee);
|
|
@@ -284,12 +344,65 @@ function diagnosticMessage(payload) {
|
|
|
284
344
|
});
|
|
285
345
|
return messages.length > 0 ? messages.join("; ") : null;
|
|
286
346
|
}
|
|
347
|
+
var serverReachabilityCache = new Map;
|
|
348
|
+
async function probeServerReachability(baseUrl, authToken) {
|
|
349
|
+
try {
|
|
350
|
+
const response = await fetch(`${baseUrl.replace(/\/+$/, "")}/api/server/status`, {
|
|
351
|
+
headers: mergeHeaders(undefined, authToken),
|
|
352
|
+
signal: AbortSignal.timeout(1500)
|
|
353
|
+
});
|
|
354
|
+
return response.ok;
|
|
355
|
+
} catch {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
function cachedServerReachability(projectRoot, baseUrl, authToken) {
|
|
360
|
+
const key = resolve2(projectRoot);
|
|
361
|
+
const cached = serverReachabilityCache.get(key);
|
|
362
|
+
if (cached)
|
|
363
|
+
return cached;
|
|
364
|
+
const probe = probeServerReachability(baseUrl, authToken);
|
|
365
|
+
serverReachabilityCache.set(key, probe);
|
|
366
|
+
return probe;
|
|
367
|
+
}
|
|
368
|
+
function describeSelectedServer(projectRoot, server) {
|
|
369
|
+
try {
|
|
370
|
+
const selected = resolveSelectedConnection(projectRoot);
|
|
371
|
+
if (selected) {
|
|
372
|
+
return {
|
|
373
|
+
alias: selected.alias,
|
|
374
|
+
target: selected.connection.kind === "remote" ? selected.connection.baseUrl : server.baseUrl
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
} catch {}
|
|
378
|
+
return { alias: server.connectionKind === "remote" ? "remote" : "local", target: server.baseUrl };
|
|
379
|
+
}
|
|
380
|
+
async function buildServerFailureContext(projectRoot, server) {
|
|
381
|
+
const { alias, target } = describeSelectedServer(projectRoot, server);
|
|
382
|
+
const reachable = await cachedServerReachability(projectRoot, server.baseUrl, server.authToken);
|
|
383
|
+
const reachability = reachable ? "server is reachable" : "server is unreachable";
|
|
384
|
+
return {
|
|
385
|
+
contextLine: `Currently connected to: ${alias} at ${target} (${reachability}).`,
|
|
386
|
+
hint: "Check the selected server with `rig server status`, or switch with `rig server use <alias|local>`."
|
|
387
|
+
};
|
|
388
|
+
}
|
|
287
389
|
async function requestServerJson(context, pathname, init = {}) {
|
|
288
390
|
const server = await ensureServerForCli(context.projectRoot);
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
headers
|
|
292
|
-
});
|
|
391
|
+
const headers = mergeHeaders(init.headers, server.authToken);
|
|
392
|
+
if (server.serverProjectRoot)
|
|
393
|
+
headers.set("x-rig-project-root", server.serverProjectRoot);
|
|
394
|
+
reportServerPhase(`${(init.method ?? "GET").toUpperCase()} ${pathname.split("?")[0]}\u2026`);
|
|
395
|
+
let response;
|
|
396
|
+
try {
|
|
397
|
+
response = await fetch(`${server.baseUrl}${pathname}`, {
|
|
398
|
+
...init,
|
|
399
|
+
headers
|
|
400
|
+
});
|
|
401
|
+
} catch (error) {
|
|
402
|
+
const failure = await buildServerFailureContext(context.projectRoot, server);
|
|
403
|
+
throw new CliError(`Rig server request failed: ${error instanceof Error ? error.message : String(error)}
|
|
404
|
+
${failure.contextLine}`, 1, { hint: failure.hint });
|
|
405
|
+
}
|
|
293
406
|
const text = await response.text();
|
|
294
407
|
const payload = text.trim().length > 0 ? (() => {
|
|
295
408
|
try {
|
|
@@ -301,7 +414,9 @@ async function requestServerJson(context, pathname, init = {}) {
|
|
|
301
414
|
if (!response.ok) {
|
|
302
415
|
const diagnostics = diagnosticMessage(payload);
|
|
303
416
|
const detail = diagnostics ?? (text || response.statusText);
|
|
304
|
-
|
|
417
|
+
const failure = await buildServerFailureContext(context.projectRoot, server);
|
|
418
|
+
throw new CliError(`Rig server request failed (${response.status}): ${detail}
|
|
419
|
+
${failure.contextLine}`, 1, { hint: failure.hint });
|
|
305
420
|
}
|
|
306
421
|
return payload;
|
|
307
422
|
}
|
|
@@ -310,7 +425,7 @@ async function listWorkspaceTasksViaServer(context, filters = {}) {
|
|
|
310
425
|
appendTaskFilterParams(url, filters);
|
|
311
426
|
const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
|
|
312
427
|
if (!Array.isArray(payload)) {
|
|
313
|
-
throw new
|
|
428
|
+
throw new CliError("Rig server returned an invalid task list payload.", 1, { hint: "Check the selected server with `rig server status`; mixed CLI/server versions can mismatch \u2014 try `rig doctor`." });
|
|
314
429
|
}
|
|
315
430
|
return payload.flatMap((entry) => entry && typeof entry === "object" && !Array.isArray(entry) ? [entry] : []);
|
|
316
431
|
}
|
|
@@ -326,7 +441,7 @@ async function selectNextWorkspaceTaskViaServer(context, filters = {}) {
|
|
|
326
441
|
appendTaskFilterParams(url, filters);
|
|
327
442
|
const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
|
|
328
443
|
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
329
|
-
throw new
|
|
444
|
+
throw new CliError("Rig server returned an invalid next-task payload.", 1, { hint: "Check the selected server with `rig server status`; try `rig task list` to see the raw task set." });
|
|
330
445
|
}
|
|
331
446
|
const record = payload;
|
|
332
447
|
const rawTask = record.task;
|
|
@@ -347,6 +462,26 @@ async function getRunLogsViaServer(context, runId, options = {}) {
|
|
|
347
462
|
const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
|
|
348
463
|
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { entries: [] };
|
|
349
464
|
}
|
|
465
|
+
async function getRunTimelineViaServer(context, runId, options = {}) {
|
|
466
|
+
const url = new URL(`http://rig.local/api/runs/${encodeURIComponent(runId)}/timeline`);
|
|
467
|
+
if (options.limit !== undefined)
|
|
468
|
+
url.searchParams.set("limit", String(options.limit));
|
|
469
|
+
if (options.cursor)
|
|
470
|
+
url.searchParams.set("cursor", options.cursor);
|
|
471
|
+
const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
|
|
472
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { entries: [] };
|
|
473
|
+
}
|
|
474
|
+
var RESUMABLE_RUN_STATUSES = new Set([
|
|
475
|
+
"created",
|
|
476
|
+
"preparing",
|
|
477
|
+
"running",
|
|
478
|
+
"validating",
|
|
479
|
+
"reviewing",
|
|
480
|
+
"stopped",
|
|
481
|
+
"failed",
|
|
482
|
+
"needs-attention",
|
|
483
|
+
"needs_attention"
|
|
484
|
+
]);
|
|
350
485
|
async function stopRunViaServer(context, runId) {
|
|
351
486
|
const payload = await requestServerJson(context, "/api/runs/stop", {
|
|
352
487
|
method: "POST",
|
|
@@ -363,6 +498,14 @@ async function steerRunViaServer(context, runId, message) {
|
|
|
363
498
|
});
|
|
364
499
|
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { ok: true };
|
|
365
500
|
}
|
|
501
|
+
async function sendRunPiPromptViaServer(context, runId, text, streamingBehavior) {
|
|
502
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/prompt`, {
|
|
503
|
+
method: "POST",
|
|
504
|
+
headers: { "content-type": "application/json" },
|
|
505
|
+
body: JSON.stringify({ text, streamingBehavior })
|
|
506
|
+
});
|
|
507
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
|
|
508
|
+
}
|
|
366
509
|
async function submitTaskRunViaServer(context, input) {
|
|
367
510
|
const isTaskRun = Boolean(input.taskId);
|
|
368
511
|
const endpoint = isTaskRun ? "/api/runs/task" : "/api/runs/adhoc";
|
|
@@ -386,87 +529,15 @@ async function submitTaskRunViaServer(context, input) {
|
|
|
386
529
|
})
|
|
387
530
|
});
|
|
388
531
|
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
389
|
-
throw new
|
|
532
|
+
throw new CliError("Rig server returned an invalid run submission payload.", 1, { hint: "Check `rig server status` and retry; `rig run list` shows whether the run was created anyway." });
|
|
390
533
|
}
|
|
391
534
|
const runId = payload.runId;
|
|
392
535
|
if (typeof runId !== "string" || runId.trim().length === 0) {
|
|
393
|
-
throw new
|
|
536
|
+
throw new CliError("Rig server returned no runId for the submitted run.", 1, { hint: "Check `rig run list` \u2014 the run may still have been created; otherwise retry the submission." });
|
|
394
537
|
}
|
|
395
538
|
return { runId };
|
|
396
539
|
}
|
|
397
540
|
|
|
398
|
-
// packages/cli/src/commands/_pi-install.ts
|
|
399
|
-
import { existsSync as existsSync3, readFileSync as readFileSync3, rmSync } from "fs";
|
|
400
|
-
import { homedir as homedir2 } from "os";
|
|
401
|
-
import { resolve as resolve3 } from "path";
|
|
402
|
-
var PI_RIG_PACKAGE_NAME = "@rig/pi-rig";
|
|
403
|
-
async function defaultCommandRunner(command, options = {}) {
|
|
404
|
-
const proc = Bun.spawn(command, { cwd: options.cwd, stdout: "pipe", stderr: "pipe" });
|
|
405
|
-
const [stdout, stderr, exitCode] = await Promise.all([
|
|
406
|
-
new Response(proc.stdout).text(),
|
|
407
|
-
new Response(proc.stderr).text(),
|
|
408
|
-
proc.exited
|
|
409
|
-
]);
|
|
410
|
-
return { exitCode, stdout, stderr };
|
|
411
|
-
}
|
|
412
|
-
function resolvePiRigExtensionPath(homeDir) {
|
|
413
|
-
return resolve3(homeDir, ".pi", "agent", "extensions", "pi-rig");
|
|
414
|
-
}
|
|
415
|
-
function resolvePiHomeDir(inputHomeDir) {
|
|
416
|
-
return inputHomeDir ?? process.env.RIG_PI_HOME_DIR?.trim() ?? homedir2();
|
|
417
|
-
}
|
|
418
|
-
function piListContainsPiRig(output) {
|
|
419
|
-
return output.split(/\r?\n/).some((line) => {
|
|
420
|
-
const normalized = line.trim();
|
|
421
|
-
return normalized.includes(PI_RIG_PACKAGE_NAME) || /(?:^|[\\/])packages[\\/]pi-rig(?:$|\s)/.test(normalized);
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
async function safeRun(runner, command, options) {
|
|
425
|
-
try {
|
|
426
|
-
return await runner(command, options);
|
|
427
|
-
} catch (error) {
|
|
428
|
-
return { exitCode: 1, stdout: "", stderr: error instanceof Error ? error.message : String(error) };
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
async function checkPiRigInstall(input = {}) {
|
|
432
|
-
const home = resolvePiHomeDir(input.homeDir);
|
|
433
|
-
const extensionPath = resolvePiRigExtensionPath(home);
|
|
434
|
-
if (process.env.RIG_TEST_FAKE_PI_INSTALL === "1") {
|
|
435
|
-
return {
|
|
436
|
-
extensionPath,
|
|
437
|
-
pi: { ok: true, label: "pi", detail: "fake-pi" },
|
|
438
|
-
piRig: { ok: true, label: "pi-rig global extension", detail: extensionPath }
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
const exists = input.exists ?? existsSync3;
|
|
442
|
-
const runner = input.commandRunner ?? defaultCommandRunner;
|
|
443
|
-
const piResult = await safeRun(runner, ["pi", "--version"]);
|
|
444
|
-
const piListResult = piResult.exitCode === 0 ? await safeRun(runner, ["pi", "list"]) : { exitCode: 1, stdout: "", stderr: "" };
|
|
445
|
-
const listedPiRig = piListResult.exitCode === 0 && piListContainsPiRig(`${piListResult.stdout}
|
|
446
|
-
${piListResult.stderr}`);
|
|
447
|
-
const legacyBridge = exists(resolve3(extensionPath, "index.ts"));
|
|
448
|
-
const hasPiRig = listedPiRig;
|
|
449
|
-
return {
|
|
450
|
-
extensionPath,
|
|
451
|
-
pi: {
|
|
452
|
-
ok: piResult.exitCode === 0,
|
|
453
|
-
label: "pi",
|
|
454
|
-
detail: (piResult.stdout || piResult.stderr).trim() || undefined,
|
|
455
|
-
hint: piResult.exitCode === 0 ? undefined : "Install Pi or run `rig init --yes` to install/update the Pi runtime."
|
|
456
|
-
},
|
|
457
|
-
piRig: {
|
|
458
|
-
ok: hasPiRig,
|
|
459
|
-
label: "pi-rig global extension",
|
|
460
|
-
detail: hasPiRig ? piListResult.stdout.trim() || PI_RIG_PACKAGE_NAME : legacyBridge ? `${extensionPath} (legacy bridge; reinstall required)` : undefined,
|
|
461
|
-
hint: hasPiRig ? undefined : "Run `rig init --yes` to install/enable the global pi-rig package with `pi install`."
|
|
462
|
-
}
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
async function buildPiSetupChecks(input = {}) {
|
|
466
|
-
const status = await checkPiRigInstall(input);
|
|
467
|
-
return [status.pi, status.piRig];
|
|
468
|
-
}
|
|
469
|
-
|
|
470
541
|
// packages/cli/src/commands/_preflight.ts
|
|
471
542
|
function preflightCheck(id, label, status, detail, remediation) {
|
|
472
543
|
return {
|
|
@@ -522,6 +593,9 @@ function permissionAllowsPr(payload) {
|
|
|
522
593
|
}
|
|
523
594
|
return null;
|
|
524
595
|
}
|
|
596
|
+
function isNotFoundError(error) {
|
|
597
|
+
return /\b(404|not found)\b/i.test(message(error));
|
|
598
|
+
}
|
|
525
599
|
function projectCheckoutReady(payload) {
|
|
526
600
|
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
527
601
|
return null;
|
|
@@ -554,19 +628,33 @@ async function runFastTaskRunPreflight(context, options = {}) {
|
|
|
554
628
|
const checks = [];
|
|
555
629
|
const request = options.requestJson ?? ((pathname, init) => requestServerJson(context, pathname, init));
|
|
556
630
|
const taskId = options.taskId?.trim() || null;
|
|
631
|
+
const requiresCurrentRunApi = Boolean(taskId);
|
|
632
|
+
const selectedServer = options.requestJson ? null : await ensureServerForCli(context.projectRoot).catch(() => null);
|
|
633
|
+
const allowLocalLegacyTaskRunCompatibility = selectedServer?.connectionKind === "local";
|
|
634
|
+
let legacyServerCompatibility = false;
|
|
557
635
|
try {
|
|
558
636
|
await request("/api/server/status");
|
|
559
637
|
checks.push(preflightCheck("server", "Rig server reachable", "pass"));
|
|
560
638
|
} catch (error) {
|
|
561
|
-
|
|
639
|
+
if (isNotFoundError(error)) {
|
|
640
|
+
try {
|
|
641
|
+
await request("/health");
|
|
642
|
+
legacyServerCompatibility = !requiresCurrentRunApi || allowLocalLegacyTaskRunCompatibility;
|
|
643
|
+
checks.push(requiresCurrentRunApi && !allowLocalLegacyTaskRunCompatibility ? preflightCheck("server", "Rig server reachable", "fail", "legacy /health endpoint only; current task-run APIs are required", "Upgrade/select the Rig server before launching a task run.") : preflightCheck("server", "Rig server reachable", "pass", allowLocalLegacyTaskRunCompatibility ? "local legacy /health endpoint; submit endpoint will be authoritative" : "legacy /health endpoint"));
|
|
644
|
+
} catch (healthError) {
|
|
645
|
+
checks.push(preflightCheck("server", "Rig server reachable", "fail", message(healthError), "Start or select a reachable Rig server."));
|
|
646
|
+
}
|
|
647
|
+
} else {
|
|
648
|
+
checks.push(preflightCheck("server", "Rig server reachable", "fail", message(error), "Start or select a reachable Rig server."));
|
|
649
|
+
}
|
|
562
650
|
}
|
|
563
651
|
const repo = readRepoConnection(context.projectRoot);
|
|
564
|
-
checks.push(repo ? preflightCheck("project-link", "project linked to Rig
|
|
652
|
+
checks.push(repo ? preflightCheck("project-link", "project linked to Rig server", repo.project ? "pass" : "warn", `${repo.selected}${repo.project ? ` -> ${repo.project}` : ""}`, "Run `rig init --yes --repo owner/repo` to record the GitHub repo slug.") : preflightCheck("project-link", "project linked to Rig server", legacyServerCompatibility ? "warn" : "fail", "missing .rig/state/connection.json", "Run `rig init` or `rig server use <alias|local>`."));
|
|
565
653
|
try {
|
|
566
654
|
const auth = await request("/api/github/auth/status");
|
|
567
|
-
checks.push(isAuthenticated(auth) ? preflightCheck("github-auth", "GitHub auth valid", "pass") : preflightCheck("github-auth", "GitHub auth valid", "fail", "not authenticated", "Run `rig github auth import-gh` or `rig github auth token --token <token>`."));
|
|
655
|
+
checks.push(isAuthenticated(auth) ? preflightCheck("github-auth", "GitHub auth valid", "pass") : preflightCheck("github-auth", "GitHub auth valid", legacyServerCompatibility ? "warn" : "fail", "not authenticated", "Run `rig github auth import-gh` or `rig github auth token --token <token>`."));
|
|
568
656
|
} catch (error) {
|
|
569
|
-
checks.push(preflightCheck("github-auth", "GitHub auth valid", "fail", message(error), "Fix GitHub auth on the selected Rig server."));
|
|
657
|
+
checks.push(preflightCheck("github-auth", "GitHub auth valid", legacyServerCompatibility ? "warn" : "fail", message(error), "Fix GitHub auth on the selected Rig server."));
|
|
570
658
|
}
|
|
571
659
|
try {
|
|
572
660
|
const projection = await request("/api/workspace/task-projection");
|
|
@@ -594,9 +682,9 @@ async function runFastTaskRunPreflight(context, options = {}) {
|
|
|
594
682
|
try {
|
|
595
683
|
const tasks = await request(`/api/workspace/tasks?limit=200&refresh=1`);
|
|
596
684
|
const found = Array.isArray(tasks) && tasks.some((task) => taskMatchesId(task, taskId));
|
|
597
|
-
checks.push(found ? preflightCheck("issue", "task/issue accessible", "pass", taskId) : preflightCheck("issue", "task/issue accessible", "fail", taskId, "Confirm the issue exists and matches the configured task filters."));
|
|
685
|
+
checks.push(found ? preflightCheck("issue", "task/issue accessible", "pass", taskId) : preflightCheck("issue", "task/issue accessible", legacyServerCompatibility ? "warn" : "fail", taskId, "Confirm the issue exists and matches the configured task filters."));
|
|
598
686
|
} catch (error) {
|
|
599
|
-
checks.push(preflightCheck("issue", "task/issue accessible", "fail", message(error), "Fix the task source before launching a run."));
|
|
687
|
+
checks.push(preflightCheck("issue", "task/issue accessible", legacyServerCompatibility ? "warn" : "fail", message(error), "Fix the task source before launching a run."));
|
|
600
688
|
}
|
|
601
689
|
try {
|
|
602
690
|
const runs = await request("/api/runs?limit=200");
|
|
@@ -607,14 +695,7 @@ async function runFastTaskRunPreflight(context, options = {}) {
|
|
|
607
695
|
}
|
|
608
696
|
}
|
|
609
697
|
if ((options.runtimeAdapter ?? "pi") === "pi") {
|
|
610
|
-
|
|
611
|
-
ok: false,
|
|
612
|
-
label: "pi/pi-rig checks",
|
|
613
|
-
hint: message(error)
|
|
614
|
-
}]);
|
|
615
|
-
for (const pi of piChecks) {
|
|
616
|
-
checks.push(preflightCheck(pi.label === "pi" ? "pi" : "pi-rig", pi.label, pi.ok ? "pass" : "fail", pi.detail, pi.hint ?? (pi.ok ? undefined : "Run `rig init --yes` to install/update Pi and enable pi-rig.")));
|
|
617
|
-
}
|
|
698
|
+
checks.push(preflightCheck("runtime", "worker Pi SDK session daemon", "pass", selectedServer?.connectionKind === "remote" ? "remote worker-owned runtime" : "bundled server-owned runtime"));
|
|
618
699
|
} else {
|
|
619
700
|
checks.push(preflightCheck("runtime", "runtime adapter", "pass", options.runtimeAdapter));
|
|
620
701
|
}
|
|
@@ -622,9 +703,9 @@ async function runFastTaskRunPreflight(context, options = {}) {
|
|
|
622
703
|
if (failures.length > 0) {
|
|
623
704
|
const summary = failures.map((check) => `${check.label}${check.detail ? `: ${check.detail}` : ""}`).join("; ");
|
|
624
705
|
if (failures.some((check) => check.id === "duplicate-active-run") && taskId) {
|
|
625
|
-
throw new
|
|
706
|
+
throw new CliError(`Task ${taskId} already has an active Rig run. ${summary}`, 1, { hint: `Attach to it with \`rig run attach <run-id> --follow\`, or stop it first with \`rig run stop <run-id>\`.` });
|
|
626
707
|
}
|
|
627
|
-
throw new
|
|
708
|
+
throw new CliError(`Task run preflight failed: ${summary}`, 1, { hint: "Run `rig doctor` to diagnose, then retry `rig task run`." });
|
|
628
709
|
}
|
|
629
710
|
return { ok: true, checks };
|
|
630
711
|
}
|
|
@@ -641,7 +722,7 @@ async function runProjectMainSyncPreflight(context, options) {
|
|
|
641
722
|
runBootstrap: async () => {
|
|
642
723
|
const bootstrap = await context.runCommand(["bun", "run", "bootstrap"]);
|
|
643
724
|
if (bootstrap.exitCode !== 0) {
|
|
644
|
-
throw new
|
|
725
|
+
throw new CliError(bootstrap.stderr || bootstrap.stdout || "bun run bootstrap failed during project pre-run sync", bootstrap.exitCode || 1);
|
|
645
726
|
}
|
|
646
727
|
}
|
|
647
728
|
});
|
|
@@ -706,7 +787,200 @@ function withMutedConsole(mute, fn) {
|
|
|
706
787
|
}
|
|
707
788
|
|
|
708
789
|
// packages/cli/src/commands/_task-picker.ts
|
|
709
|
-
import {
|
|
790
|
+
import { cancel, isCancel, select } from "@clack/prompts";
|
|
791
|
+
|
|
792
|
+
// packages/cli/src/commands/_operator-surface.ts
|
|
793
|
+
import { createInterface } from "readline";
|
|
794
|
+
import { createInterface as createPromptInterface } from "readline/promises";
|
|
795
|
+
var CANONICAL_STAGES = [
|
|
796
|
+
"Connect",
|
|
797
|
+
"GitHub/task sync",
|
|
798
|
+
"Prepare workspace",
|
|
799
|
+
"Launch Pi",
|
|
800
|
+
"Plan",
|
|
801
|
+
"Implement",
|
|
802
|
+
"Validate",
|
|
803
|
+
"Commit",
|
|
804
|
+
"Open PR",
|
|
805
|
+
"Review/CI",
|
|
806
|
+
"Merge",
|
|
807
|
+
"Complete"
|
|
808
|
+
];
|
|
809
|
+
function logDetail(log) {
|
|
810
|
+
return typeof log.detail === "string" ? log.detail.trim() : "";
|
|
811
|
+
}
|
|
812
|
+
function parseProviderProtocolLog(title, detail) {
|
|
813
|
+
if (title.trim().toLowerCase() !== "agent output")
|
|
814
|
+
return null;
|
|
815
|
+
if (!detail.startsWith("{") || !detail.endsWith("}"))
|
|
816
|
+
return null;
|
|
817
|
+
try {
|
|
818
|
+
const record = JSON.parse(detail);
|
|
819
|
+
if (!record || typeof record !== "object" || Array.isArray(record))
|
|
820
|
+
return null;
|
|
821
|
+
const type = record.type;
|
|
822
|
+
return typeof type === "string" && [
|
|
823
|
+
"assistant",
|
|
824
|
+
"message_start",
|
|
825
|
+
"message_update",
|
|
826
|
+
"message_end",
|
|
827
|
+
"stream_event",
|
|
828
|
+
"tool_result",
|
|
829
|
+
"tool_execution_start",
|
|
830
|
+
"tool_execution_update",
|
|
831
|
+
"tool_execution_end",
|
|
832
|
+
"turn_start",
|
|
833
|
+
"turn_end"
|
|
834
|
+
].includes(type) ? record : null;
|
|
835
|
+
} catch {
|
|
836
|
+
return null;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
function renderProviderProtocolLog(record) {
|
|
840
|
+
const type = typeof record.type === "string" ? record.type : "";
|
|
841
|
+
if (type === "tool_execution_start" || type === "tool_execution_update" || type === "tool_execution_end") {
|
|
842
|
+
const toolName = String(record.toolName ?? record.name ?? "tool");
|
|
843
|
+
const status = type === "tool_execution_start" ? "started" : type === "tool_execution_end" ? record.isError === true || record.result && typeof record.result === "object" && !Array.isArray(record.result) && record.result.isError === true ? "failed" : "completed" : "running";
|
|
844
|
+
return `[Pi tool] ${toolName} ${status}`;
|
|
845
|
+
}
|
|
846
|
+
return null;
|
|
847
|
+
}
|
|
848
|
+
function entryId(entry, fallback) {
|
|
849
|
+
return typeof entry.id === "string" && entry.id.trim() ? entry.id : fallback;
|
|
850
|
+
}
|
|
851
|
+
function renderOperatorSnapshot(snapshot) {
|
|
852
|
+
const run = snapshot.run.run && typeof snapshot.run.run === "object" ? snapshot.run.run : snapshot.run;
|
|
853
|
+
const runId = String(run.runId ?? run.id ?? "run");
|
|
854
|
+
const status = String(run.status ?? "unknown");
|
|
855
|
+
const logs = snapshot.logs ?? [];
|
|
856
|
+
const latestByStage = new Map;
|
|
857
|
+
for (const log of logs) {
|
|
858
|
+
const title = String(log.title ?? "").toLowerCase();
|
|
859
|
+
const stageName = String(log.stage ?? "").toLowerCase();
|
|
860
|
+
const stage = CANONICAL_STAGES.find((candidate) => candidate.toLowerCase() === title || candidate.toLowerCase() === stageName);
|
|
861
|
+
if (stage)
|
|
862
|
+
latestByStage.set(stage, log);
|
|
863
|
+
}
|
|
864
|
+
const stageLines = CANONICAL_STAGES.flatMap((stage) => {
|
|
865
|
+
const match = latestByStage.get(stage);
|
|
866
|
+
return match ? [`${stage}: ${String(match.status ?? status)}${logDetail(match) ? ` \u2014 ${logDetail(match)}` : ""}`] : [];
|
|
867
|
+
});
|
|
868
|
+
return [`Rig run ${runId}: ${status}`, ...stageLines].join(`
|
|
869
|
+
`);
|
|
870
|
+
}
|
|
871
|
+
function createPiRunStreamRenderer(output = process.stdout) {
|
|
872
|
+
let lastSnapshot = "";
|
|
873
|
+
const assistantTextById = new Map;
|
|
874
|
+
const seenTimeline = new Set;
|
|
875
|
+
const seenLogs = new Set;
|
|
876
|
+
const writeLine = (line) => output.write(`${line}
|
|
877
|
+
`);
|
|
878
|
+
return {
|
|
879
|
+
renderSnapshot(snapshot) {
|
|
880
|
+
const rendered = renderOperatorSnapshot(snapshot);
|
|
881
|
+
if (rendered && rendered !== lastSnapshot) {
|
|
882
|
+
writeLine(rendered);
|
|
883
|
+
lastSnapshot = rendered;
|
|
884
|
+
}
|
|
885
|
+
},
|
|
886
|
+
renderTimeline(entries) {
|
|
887
|
+
for (const [index, entry] of entries.entries()) {
|
|
888
|
+
const id = entryId(entry, `timeline:${index}:${String(entry.cursor ?? "")}`);
|
|
889
|
+
if (entry.type === "assistant_message" && typeof entry.text === "string") {
|
|
890
|
+
const text = entry.text;
|
|
891
|
+
const previousText = assistantTextById.get(id) ?? "";
|
|
892
|
+
if (!previousText && text.trim()) {
|
|
893
|
+
writeLine("[Pi assistant]");
|
|
894
|
+
}
|
|
895
|
+
if (text.startsWith(previousText)) {
|
|
896
|
+
const delta = text.slice(previousText.length);
|
|
897
|
+
if (delta)
|
|
898
|
+
output.write(delta);
|
|
899
|
+
} else if (text.trim() && text !== previousText) {
|
|
900
|
+
if (previousText)
|
|
901
|
+
writeLine(`
|
|
902
|
+
[Pi assistant]`);
|
|
903
|
+
output.write(text);
|
|
904
|
+
}
|
|
905
|
+
assistantTextById.set(id, text);
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
if (seenTimeline.has(id))
|
|
909
|
+
continue;
|
|
910
|
+
seenTimeline.add(id);
|
|
911
|
+
if (entry.type === "tool_execution_start" || entry.type === "tool_execution_update" || entry.type === "tool_execution_end" || entry.type === "mcp_tool_call") {
|
|
912
|
+
writeLine(`[Pi tool] ${String(entry.toolName ?? entry.name ?? entry.title ?? entry.type)} ${String(entry.status ?? entry.state ?? "")}`.trim());
|
|
913
|
+
continue;
|
|
914
|
+
}
|
|
915
|
+
if (entry.type === "timeline_warning") {
|
|
916
|
+
writeLine(`[Rig timeline] ${String(entry.detail ?? entry.message ?? "timeline unavailable")}`);
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
if (entry.type === "action") {
|
|
920
|
+
const text = String(entry.detail ?? entry.message ?? entry.title ?? "").trim();
|
|
921
|
+
if (text)
|
|
922
|
+
writeLine(`[Rig action] ${text}`);
|
|
923
|
+
continue;
|
|
924
|
+
}
|
|
925
|
+
if (entry.type === "user_message") {
|
|
926
|
+
const text = String(entry.text ?? entry.message ?? entry.detail ?? "").trim();
|
|
927
|
+
if (text)
|
|
928
|
+
writeLine(`[Operator] ${text}`);
|
|
929
|
+
continue;
|
|
930
|
+
}
|
|
931
|
+
const fallback = String(entry.detail ?? entry.message ?? entry.text ?? entry.title ?? "").trim();
|
|
932
|
+
if (fallback)
|
|
933
|
+
writeLine(`[${String(entry.type ?? "timeline")}] ${fallback}`);
|
|
934
|
+
}
|
|
935
|
+
},
|
|
936
|
+
renderLogs(entries) {
|
|
937
|
+
for (const [index, entry] of entries.entries()) {
|
|
938
|
+
const id = entryId(entry, `log:${index}:${String(entry.createdAt ?? "")}:${String(entry.title ?? "")}`);
|
|
939
|
+
if (seenLogs.has(id))
|
|
940
|
+
continue;
|
|
941
|
+
seenLogs.add(id);
|
|
942
|
+
const title = String(entry.title ?? "");
|
|
943
|
+
if (CANONICAL_STAGES.some((stage) => stage.toLowerCase() === title.toLowerCase()))
|
|
944
|
+
continue;
|
|
945
|
+
const detail = logDetail(entry);
|
|
946
|
+
if (!detail)
|
|
947
|
+
continue;
|
|
948
|
+
const protocolRecord = parseProviderProtocolLog(title, detail);
|
|
949
|
+
if (protocolRecord) {
|
|
950
|
+
const protocolLine = renderProviderProtocolLog(protocolRecord);
|
|
951
|
+
if (protocolLine)
|
|
952
|
+
writeLine(protocolLine);
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
955
|
+
writeLine(`[${title || "Rig log"}] ${detail}`);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
function createOperatorSurface(options = {}) {
|
|
961
|
+
const input = options.input ?? process.stdin;
|
|
962
|
+
const output = options.output ?? process.stdout;
|
|
963
|
+
const errorOutput = options.errorOutput ?? process.stderr;
|
|
964
|
+
const renderer = createPiRunStreamRenderer(output);
|
|
965
|
+
const writeLine = (line) => output.write(`${line}
|
|
966
|
+
`);
|
|
967
|
+
return {
|
|
968
|
+
mode: "pi-compatible-text",
|
|
969
|
+
...renderer,
|
|
970
|
+
info: writeLine,
|
|
971
|
+
error: (message2) => errorOutput.write(`${message2}
|
|
972
|
+
`),
|
|
973
|
+
attachCommandInput(handler) {
|
|
974
|
+
if (options.interactive === false || !input.isTTY)
|
|
975
|
+
return null;
|
|
976
|
+
const rl = createInterface({ input, output: process.stdout, terminal: false });
|
|
977
|
+
rl.on("line", (line) => {
|
|
978
|
+
Promise.resolve(handler(line)).catch((error) => writeLine(`Operator command failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
979
|
+
});
|
|
980
|
+
return { close: () => rl.close() };
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
}
|
|
710
984
|
function taskId(task) {
|
|
711
985
|
return typeof task.id === "string" && task.id.trim() ? task.id : "<unknown>";
|
|
712
986
|
}
|
|
@@ -719,6 +993,19 @@ function taskStatus(task) {
|
|
|
719
993
|
function renderTaskPickerRows(tasks) {
|
|
720
994
|
return tasks.map((task, index) => `${index + 1}. ${taskId(task)} \xB7 ${taskStatus(task)} \xB7 ${taskTitle(task)}`);
|
|
721
995
|
}
|
|
996
|
+
async function promptForTaskSelection(question) {
|
|
997
|
+
const rl = createPromptInterface({ input: process.stdin, output: process.stdout });
|
|
998
|
+
try {
|
|
999
|
+
return await rl.question(question);
|
|
1000
|
+
} finally {
|
|
1001
|
+
rl.close();
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
// packages/cli/src/commands/_task-picker.ts
|
|
1006
|
+
function taskId2(task) {
|
|
1007
|
+
return typeof task.id === "string" && task.id.trim() ? task.id : "<unknown>";
|
|
1008
|
+
}
|
|
722
1009
|
async function selectTaskWithTextPicker(tasks, io = {}) {
|
|
723
1010
|
if (tasks.length === 0)
|
|
724
1011
|
return null;
|
|
@@ -728,56 +1015,237 @@ async function selectTaskWithTextPicker(tasks, io = {}) {
|
|
|
728
1015
|
if (!isTty) {
|
|
729
1016
|
throw new Error("task run requires an interactive terminal to pick a task; pass --task <id>, --next, or --detach with a task id.");
|
|
730
1017
|
}
|
|
731
|
-
|
|
732
|
-
const
|
|
1018
|
+
if (io.prompt || io.renderer) {
|
|
1019
|
+
const prompt = io.prompt ?? promptForTaskSelection;
|
|
1020
|
+
const renderer = io.renderer ?? { writeLine: (line) => process.stdout.write(`${line}
|
|
1021
|
+
`) };
|
|
1022
|
+
renderer.writeLine("Select Rig task:");
|
|
1023
|
+
for (const row of renderTaskPickerRows(tasks))
|
|
1024
|
+
renderer.writeLine(` ${row}`);
|
|
1025
|
+
const answer2 = (await prompt(`Task [1-${tasks.length}] or id: `)).trim();
|
|
1026
|
+
if (!answer2)
|
|
1027
|
+
return null;
|
|
1028
|
+
if (/^\d+$/.test(answer2)) {
|
|
1029
|
+
const index2 = Number.parseInt(answer2, 10) - 1;
|
|
1030
|
+
return tasks[index2] ?? null;
|
|
1031
|
+
}
|
|
1032
|
+
return tasks.find((task) => taskId2(task) === answer2) ?? null;
|
|
1033
|
+
}
|
|
1034
|
+
const options = tasks.map((task, index2) => ({
|
|
1035
|
+
value: `${index2}`,
|
|
1036
|
+
label: `${taskId2(task)} \xB7 ${typeof task.title === "string" && task.title.trim() ? task.title.trim() : "Untitled task"}`,
|
|
1037
|
+
hint: typeof task.status === "string" && task.status.trim() ? task.status.trim() : undefined
|
|
1038
|
+
}));
|
|
1039
|
+
const answer = await select({
|
|
1040
|
+
message: "Select Rig task",
|
|
1041
|
+
options
|
|
1042
|
+
});
|
|
1043
|
+
if (isCancel(answer)) {
|
|
1044
|
+
cancel("No task selected.");
|
|
1045
|
+
return null;
|
|
1046
|
+
}
|
|
1047
|
+
const index = Number.parseInt(String(answer), 10);
|
|
1048
|
+
return Number.isFinite(index) ? tasks[index] ?? null : null;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
// packages/cli/src/commands/_async-ui.ts
|
|
1052
|
+
import pc from "picocolors";
|
|
1053
|
+
|
|
1054
|
+
// packages/cli/src/commands/_spinner.ts
|
|
1055
|
+
var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1056
|
+
function createTtySpinner(input) {
|
|
1057
|
+
const output = input.output ?? process.stdout;
|
|
1058
|
+
const isTty = output.isTTY === true;
|
|
1059
|
+
const frames = input.frames && input.frames.length > 0 ? input.frames : SPINNER_FRAMES;
|
|
1060
|
+
let label = input.label;
|
|
1061
|
+
let frame = 0;
|
|
1062
|
+
let paused = false;
|
|
1063
|
+
let stopped = false;
|
|
1064
|
+
let lastPrintedLabel = "";
|
|
1065
|
+
const render = () => {
|
|
1066
|
+
if (stopped || paused)
|
|
1067
|
+
return;
|
|
1068
|
+
if (!isTty) {
|
|
1069
|
+
if (label !== lastPrintedLabel) {
|
|
1070
|
+
output.write(`${label}
|
|
1071
|
+
`);
|
|
1072
|
+
lastPrintedLabel = label;
|
|
1073
|
+
}
|
|
1074
|
+
return;
|
|
1075
|
+
}
|
|
1076
|
+
frame = (frame + 1) % frames.length;
|
|
1077
|
+
const glyph = frames[frame] ?? frames[0] ?? "";
|
|
1078
|
+
output.write(`\r\x1B[2K${input.styleFrame ? input.styleFrame(glyph) : glyph} ${label}`);
|
|
1079
|
+
};
|
|
1080
|
+
const clearLine = () => {
|
|
1081
|
+
if (isTty)
|
|
1082
|
+
output.write("\r\x1B[2K");
|
|
1083
|
+
};
|
|
1084
|
+
render();
|
|
1085
|
+
const timer = isTty ? setInterval(render, input.intervalMs ?? 120) : null;
|
|
1086
|
+
return {
|
|
1087
|
+
setLabel(next) {
|
|
1088
|
+
label = next;
|
|
1089
|
+
render();
|
|
1090
|
+
},
|
|
1091
|
+
pause() {
|
|
1092
|
+
paused = true;
|
|
1093
|
+
clearLine();
|
|
1094
|
+
},
|
|
1095
|
+
resume() {
|
|
1096
|
+
if (stopped)
|
|
1097
|
+
return;
|
|
1098
|
+
paused = false;
|
|
1099
|
+
render();
|
|
1100
|
+
},
|
|
1101
|
+
stop(finalLine) {
|
|
1102
|
+
if (stopped)
|
|
1103
|
+
return;
|
|
1104
|
+
stopped = true;
|
|
1105
|
+
if (timer)
|
|
1106
|
+
clearInterval(timer);
|
|
1107
|
+
clearLine();
|
|
1108
|
+
if (finalLine)
|
|
1109
|
+
output.write(`${finalLine}
|
|
1110
|
+
`);
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
// packages/cli/src/commands/_async-ui.ts
|
|
1116
|
+
var CLACK_SPINNER_FRAMES = ["\u25D2", "\u25D0", "\u25D3", "\u25D1"];
|
|
1117
|
+
var DONE_SYMBOL = pc.green("\u25C7");
|
|
1118
|
+
var FAIL_SYMBOL = pc.red("\u25A0");
|
|
1119
|
+
var activeUpdate = null;
|
|
1120
|
+
async function withSpinner(label, work, options = {}) {
|
|
1121
|
+
if (options.outputMode === "json") {
|
|
1122
|
+
return work(() => {});
|
|
1123
|
+
}
|
|
1124
|
+
if (activeUpdate) {
|
|
1125
|
+
const outer = activeUpdate;
|
|
1126
|
+
outer(label);
|
|
1127
|
+
return work(outer);
|
|
1128
|
+
}
|
|
1129
|
+
const output = options.output ?? process.stderr;
|
|
1130
|
+
const isTty = output.isTTY === true;
|
|
1131
|
+
let lastLabel = label;
|
|
1132
|
+
if (!isTty) {
|
|
1133
|
+
output.write(`${label}
|
|
1134
|
+
`);
|
|
1135
|
+
const update2 = (next) => {
|
|
1136
|
+
lastLabel = next;
|
|
1137
|
+
};
|
|
1138
|
+
activeUpdate = update2;
|
|
1139
|
+
const previousListener2 = setServerPhaseListener(update2);
|
|
733
1140
|
try {
|
|
734
|
-
return await
|
|
1141
|
+
return await work(update2);
|
|
735
1142
|
} finally {
|
|
736
|
-
|
|
1143
|
+
activeUpdate = null;
|
|
1144
|
+
setServerPhaseListener(previousListener2);
|
|
737
1145
|
}
|
|
1146
|
+
}
|
|
1147
|
+
const spinner = createTtySpinner({
|
|
1148
|
+
label,
|
|
1149
|
+
output,
|
|
1150
|
+
frames: CLACK_SPINNER_FRAMES,
|
|
1151
|
+
styleFrame: (frame) => pc.magenta(frame)
|
|
738
1152
|
});
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
const
|
|
747
|
-
|
|
1153
|
+
const update = (next) => {
|
|
1154
|
+
lastLabel = next;
|
|
1155
|
+
spinner.setLabel(next);
|
|
1156
|
+
};
|
|
1157
|
+
activeUpdate = update;
|
|
1158
|
+
const previousListener = setServerPhaseListener(update);
|
|
1159
|
+
try {
|
|
1160
|
+
const result = await work(update);
|
|
1161
|
+
spinner.stop(options.doneLabel ? `${DONE_SYMBOL} ${options.doneLabel}` : undefined);
|
|
1162
|
+
return result;
|
|
1163
|
+
} catch (error) {
|
|
1164
|
+
spinner.stop(`${FAIL_SYMBOL} ${lastLabel}`);
|
|
1165
|
+
throw error;
|
|
1166
|
+
} finally {
|
|
1167
|
+
activeUpdate = null;
|
|
1168
|
+
setServerPhaseListener(previousListener);
|
|
748
1169
|
}
|
|
749
|
-
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
// packages/cli/src/commands/_pi-frontend.ts
|
|
1173
|
+
import { mkdtempSync, rmSync } from "fs";
|
|
1174
|
+
import { tmpdir } from "os";
|
|
1175
|
+
import { join } from "path";
|
|
1176
|
+
import { main as runPiMain } from "@earendil-works/pi-coding-agent";
|
|
1177
|
+
import createPiRigExtension from "@rig/pi-rig";
|
|
1178
|
+
function setTemporaryEnv(updates) {
|
|
1179
|
+
const previous = new Map;
|
|
1180
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
1181
|
+
previous.set(key, process.env[key]);
|
|
1182
|
+
process.env[key] = value;
|
|
1183
|
+
}
|
|
1184
|
+
return () => {
|
|
1185
|
+
for (const [key, value] of previous) {
|
|
1186
|
+
if (value === undefined)
|
|
1187
|
+
delete process.env[key];
|
|
1188
|
+
else
|
|
1189
|
+
process.env[key] = value;
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
function buildOperatorPiEnv(input) {
|
|
1194
|
+
return {
|
|
1195
|
+
PI_CODING_AGENT_SESSION_DIR: input.sessionDir,
|
|
1196
|
+
PI_SKIP_VERSION_CHECK: "1",
|
|
1197
|
+
RIG_PI_OPERATOR_SESSION: "1",
|
|
1198
|
+
RIG_RUN_ID: input.runId,
|
|
1199
|
+
RIG_SERVER_URL: input.serverUrl,
|
|
1200
|
+
...input.authToken ? { RIG_AUTH_TOKEN: input.authToken } : {},
|
|
1201
|
+
...input.serverProjectRoot ? { RIG_PROJECT_ROOT: input.serverProjectRoot } : {}
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
async function attachRunBundledPiFrontend(context, input) {
|
|
1205
|
+
const tempSessionDir = mkdtempSync(join(tmpdir(), "rig-pi-frontend-sessions-"));
|
|
1206
|
+
const server = await ensureServerForCli(context.projectRoot);
|
|
1207
|
+
const restoreEnv = setTemporaryEnv(buildOperatorPiEnv({
|
|
1208
|
+
runId: input.runId,
|
|
1209
|
+
serverUrl: server.baseUrl,
|
|
1210
|
+
authToken: server.authToken,
|
|
1211
|
+
serverProjectRoot: server.serverProjectRoot,
|
|
1212
|
+
sessionDir: tempSessionDir
|
|
1213
|
+
}));
|
|
1214
|
+
const piRigExtensionFactory = (pi) => {
|
|
1215
|
+
createPiRigExtension(pi);
|
|
1216
|
+
};
|
|
1217
|
+
let detached = false;
|
|
1218
|
+
try {
|
|
1219
|
+
await runPiMain([
|
|
1220
|
+
"--no-extensions",
|
|
1221
|
+
"--no-skills",
|
|
1222
|
+
"--no-prompt-templates",
|
|
1223
|
+
"--no-context-files"
|
|
1224
|
+
], {
|
|
1225
|
+
extensionFactories: [piRigExtensionFactory]
|
|
1226
|
+
});
|
|
1227
|
+
detached = true;
|
|
1228
|
+
} finally {
|
|
1229
|
+
restoreEnv();
|
|
1230
|
+
rmSync(tempSessionDir, { recursive: true, force: true });
|
|
1231
|
+
}
|
|
1232
|
+
let run = { runId: input.runId, status: "unknown" };
|
|
1233
|
+
try {
|
|
1234
|
+
run = await getRunDetailsViaServer(context, input.runId);
|
|
1235
|
+
} catch {}
|
|
1236
|
+
return {
|
|
1237
|
+
run,
|
|
1238
|
+
logs: [],
|
|
1239
|
+
timeline: [],
|
|
1240
|
+
timelineCursor: null,
|
|
1241
|
+
steered: input.steered === true,
|
|
1242
|
+
detached,
|
|
1243
|
+
rendered: "stock Pi operator console with the pi-rig extension"
|
|
1244
|
+
};
|
|
750
1245
|
}
|
|
751
1246
|
|
|
752
1247
|
// packages/cli/src/commands/_operator-view.ts
|
|
753
|
-
import { createInterface as createInterface2 } from "readline";
|
|
754
1248
|
var TERMINAL_RUN_STATUSES = new Set(["completed", "failed", "stopped", "cancelled", "canceled", "closed", "merged", "needs_attention", "needs-attention"]);
|
|
755
|
-
var CANONICAL_STAGES = [
|
|
756
|
-
"Connect",
|
|
757
|
-
"GitHub/task sync",
|
|
758
|
-
"Prepare workspace",
|
|
759
|
-
"Launch Pi",
|
|
760
|
-
"Plan",
|
|
761
|
-
"Implement",
|
|
762
|
-
"Validate",
|
|
763
|
-
"Commit",
|
|
764
|
-
"Open PR",
|
|
765
|
-
"Review/CI",
|
|
766
|
-
"Merge",
|
|
767
|
-
"Complete"
|
|
768
|
-
];
|
|
769
|
-
function renderOperatorSnapshot(snapshot) {
|
|
770
|
-
const run = snapshot.run.run && typeof snapshot.run.run === "object" ? snapshot.run.run : snapshot.run;
|
|
771
|
-
const runId = String(run.runId ?? run.id ?? "run");
|
|
772
|
-
const status = String(run.status ?? "unknown");
|
|
773
|
-
const logs = snapshot.logs ?? [];
|
|
774
|
-
const stageLines = CANONICAL_STAGES.flatMap((stage) => {
|
|
775
|
-
const match = logs.find((log) => String(log.title ?? "").toLowerCase() === stage.toLowerCase() || String(log.stage ?? "").toLowerCase() === stage.toLowerCase());
|
|
776
|
-
return match ? [`${stage}: ${String(match.status ?? status)}`] : [];
|
|
777
|
-
});
|
|
778
|
-
return [`Rig run ${runId}: ${status}`, ...stageLines].join(`
|
|
779
|
-
`);
|
|
780
|
-
}
|
|
781
1249
|
function runStatusFromPayload(payload) {
|
|
782
1250
|
const run = payload.run && typeof payload.run === "object" && !Array.isArray(payload.run) ? payload.run : payload;
|
|
783
1251
|
return String(run.status ?? "unknown").toLowerCase();
|
|
@@ -799,56 +1267,703 @@ async function applyOperatorCommand(context, input, deps = {}) {
|
|
|
799
1267
|
await (deps.steer ?? steerRunViaServer)(context, input.runId, userMessage);
|
|
800
1268
|
return { action: "continue", message: "Steering message queued." };
|
|
801
1269
|
}
|
|
802
|
-
async function readOperatorSnapshot(context, runId) {
|
|
1270
|
+
async function readOperatorSnapshot(context, runId, options = {}) {
|
|
803
1271
|
const run = await getRunDetailsViaServer(context, runId);
|
|
804
1272
|
const logsPage = await getRunLogsViaServer(context, runId, { limit: 100 });
|
|
805
|
-
const
|
|
806
|
-
|
|
1273
|
+
const timelinePage = await getRunTimelineViaServer(context, runId, { limit: 200, ...options.timelineCursor ? { cursor: options.timelineCursor } : {} }).catch((error) => ({
|
|
1274
|
+
entries: [{
|
|
1275
|
+
id: `timeline-unavailable:${runId}`,
|
|
1276
|
+
type: "timeline_warning",
|
|
1277
|
+
detail: `Selected Rig server did not provide run timeline events: ${error instanceof Error ? error.message : String(error)}`,
|
|
1278
|
+
createdAt: new Date().toISOString()
|
|
1279
|
+
}],
|
|
1280
|
+
nextCursor: options.timelineCursor ?? null
|
|
1281
|
+
}));
|
|
1282
|
+
const logs = Array.isArray(logsPage.entries) ? logsPage.entries.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry))).toReversed() : [];
|
|
1283
|
+
const timeline = Array.isArray(timelinePage.entries) ? timelinePage.entries.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry))) : [];
|
|
1284
|
+
const timelineCursor = typeof timelinePage.nextCursor === "string" ? timelinePage.nextCursor : options.timelineCursor ?? null;
|
|
1285
|
+
return { run, logs, timeline, timelineCursor, rendered: renderOperatorSnapshot({ run, logs, timeline }) };
|
|
807
1286
|
}
|
|
808
1287
|
async function attachRunOperatorView(context, input) {
|
|
809
1288
|
let steered = false;
|
|
810
|
-
|
|
811
|
-
|
|
1289
|
+
const attachMessage = input.message?.trim();
|
|
1290
|
+
if (attachMessage) {
|
|
1291
|
+
await withSpinner("Queueing steering message\u2026", () => sendRunPiPromptViaServer(context, input.runId, attachMessage, "steer").catch(() => steerRunViaServer(context, input.runId, attachMessage)), { outputMode: context.outputMode });
|
|
812
1292
|
steered = true;
|
|
813
1293
|
}
|
|
814
|
-
|
|
1294
|
+
if (input.follow && !input.once && input.interactive !== false && context.outputMode === "text" && Boolean(process.stdin.isTTY && process.stdout.isTTY)) {
|
|
1295
|
+
return attachRunBundledPiFrontend(context, {
|
|
1296
|
+
runId: input.runId,
|
|
1297
|
+
steered
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
const surface = createOperatorSurface({ interactive: input.interactive !== false });
|
|
1301
|
+
let snapshot = await withSpinner(`Connecting to run ${input.runId}\u2026`, () => readOperatorSnapshot(context, input.runId), { outputMode: context.outputMode });
|
|
815
1302
|
if (context.outputMode === "text") {
|
|
816
|
-
|
|
1303
|
+
surface.renderSnapshot(snapshot);
|
|
1304
|
+
surface.renderTimeline(snapshot.timeline);
|
|
1305
|
+
surface.renderLogs(snapshot.logs);
|
|
817
1306
|
if (steered)
|
|
818
|
-
|
|
1307
|
+
surface.info("Message submitted to worker Pi.");
|
|
819
1308
|
}
|
|
820
1309
|
let detached = false;
|
|
821
|
-
let
|
|
1310
|
+
let commandInput = null;
|
|
822
1311
|
if (input.follow && !input.once && context.outputMode === "text") {
|
|
823
1312
|
if (input.interactive !== false && process.stdin.isTTY) {
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
}
|
|
834
|
-
}).catch((error) => console.log(`Operator command failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
1313
|
+
surface.info("Controls: /user <message>, /stop, /detach");
|
|
1314
|
+
commandInput = surface.attachCommandInput(async (line) => {
|
|
1315
|
+
const result = await applyOperatorCommand(context, { runId: input.runId, line });
|
|
1316
|
+
if (result.message)
|
|
1317
|
+
surface.info(result.message);
|
|
1318
|
+
if (result.action === "detach" || result.action === "stopped") {
|
|
1319
|
+
detached = true;
|
|
1320
|
+
commandInput?.close();
|
|
1321
|
+
}
|
|
835
1322
|
});
|
|
836
1323
|
}
|
|
837
|
-
let lastRendered = snapshot.rendered;
|
|
838
1324
|
const pollMs = Math.max(250, Math.trunc(input.pollMs ?? 2000));
|
|
1325
|
+
let timelineCursor = snapshot.timelineCursor;
|
|
839
1326
|
while (!detached && !TERMINAL_RUN_STATUSES.has(runStatusFromPayload(snapshot.run))) {
|
|
840
1327
|
await Bun.sleep(pollMs);
|
|
841
|
-
snapshot = await readOperatorSnapshot(context, input.runId);
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
1328
|
+
snapshot = await readOperatorSnapshot(context, input.runId, { timelineCursor });
|
|
1329
|
+
timelineCursor = snapshot.timelineCursor;
|
|
1330
|
+
surface.renderSnapshot(snapshot);
|
|
1331
|
+
surface.renderTimeline(snapshot.timeline);
|
|
1332
|
+
surface.renderLogs(snapshot.logs);
|
|
846
1333
|
}
|
|
847
|
-
|
|
1334
|
+
commandInput?.close();
|
|
848
1335
|
}
|
|
849
1336
|
return { ...snapshot, steered, detached };
|
|
850
1337
|
}
|
|
851
1338
|
|
|
1339
|
+
// packages/cli/src/commands/_cli-format.ts
|
|
1340
|
+
import { log, note } from "@clack/prompts";
|
|
1341
|
+
import pc2 from "picocolors";
|
|
1342
|
+
function stringField(record, key, fallback = "") {
|
|
1343
|
+
const value = record[key];
|
|
1344
|
+
return typeof value === "string" && value.trim() ? value.trim() : fallback;
|
|
1345
|
+
}
|
|
1346
|
+
function numberField(record, key) {
|
|
1347
|
+
const value = record[key];
|
|
1348
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
1349
|
+
}
|
|
1350
|
+
function arrayField(record, key) {
|
|
1351
|
+
const value = record[key];
|
|
1352
|
+
return Array.isArray(value) ? value.flatMap((entry) => typeof entry === "string" && entry.trim() ? [entry.trim()] : []) : [];
|
|
1353
|
+
}
|
|
1354
|
+
function rawObject(record) {
|
|
1355
|
+
const raw = record.raw;
|
|
1356
|
+
return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
1357
|
+
}
|
|
1358
|
+
function truncate(value, width) {
|
|
1359
|
+
if (value.length <= width)
|
|
1360
|
+
return value;
|
|
1361
|
+
if (width <= 1)
|
|
1362
|
+
return "\u2026";
|
|
1363
|
+
return `${value.slice(0, width - 1)}\u2026`;
|
|
1364
|
+
}
|
|
1365
|
+
function pad(value, width) {
|
|
1366
|
+
return value.length >= width ? value : `${value}${" ".repeat(width - value.length)}`;
|
|
1367
|
+
}
|
|
1368
|
+
function statusColor(status) {
|
|
1369
|
+
const normalized = status.toLowerCase();
|
|
1370
|
+
if (["completed", "merged", "closed", "done", "accepted", "pass", "selected", "approved"].includes(normalized))
|
|
1371
|
+
return pc2.green;
|
|
1372
|
+
if (["failed", "needs_attention", "needs-attention", "blocked", "error", "rejected"].includes(normalized))
|
|
1373
|
+
return pc2.red;
|
|
1374
|
+
if (["running", "reviewing", "validating", "in_progress", "in-progress", "remote"].includes(normalized))
|
|
1375
|
+
return pc2.cyan;
|
|
1376
|
+
if (["ready", "open", "queued", "created", "preparing", "local", "pending"].includes(normalized))
|
|
1377
|
+
return pc2.yellow;
|
|
1378
|
+
return pc2.dim;
|
|
1379
|
+
}
|
|
1380
|
+
function compactValue(value) {
|
|
1381
|
+
if (value === null || value === undefined)
|
|
1382
|
+
return "";
|
|
1383
|
+
if (typeof value === "string")
|
|
1384
|
+
return value;
|
|
1385
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
1386
|
+
return String(value);
|
|
1387
|
+
if (Array.isArray(value))
|
|
1388
|
+
return value.map(compactValue).filter(Boolean).join(", ");
|
|
1389
|
+
return JSON.stringify(value);
|
|
1390
|
+
}
|
|
1391
|
+
function shouldUseClackOutput() {
|
|
1392
|
+
return Boolean(process.stdout.isTTY) && process.env.RIG_CLI_PLAIN_HELP !== "1";
|
|
1393
|
+
}
|
|
1394
|
+
function printFormattedOutput(message2, options = {}) {
|
|
1395
|
+
if (!shouldUseClackOutput()) {
|
|
1396
|
+
console.log(message2);
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1399
|
+
if (options.title)
|
|
1400
|
+
note(message2, options.title);
|
|
1401
|
+
else
|
|
1402
|
+
log.message(message2);
|
|
1403
|
+
}
|
|
1404
|
+
function formatStatusPill(status) {
|
|
1405
|
+
const label = status || "unknown";
|
|
1406
|
+
return statusColor(label)(`\u25CF ${label}`);
|
|
1407
|
+
}
|
|
1408
|
+
function formatSection(title, subtitle) {
|
|
1409
|
+
return `${pc2.bold(pc2.cyan("\u25C6"))} ${pc2.bold(title)}${subtitle ? pc2.dim(` \u2014 ${subtitle}`) : ""}`;
|
|
1410
|
+
}
|
|
1411
|
+
function formatSuccessCard(title, rows = []) {
|
|
1412
|
+
const body = rows.filter(([, value]) => value !== undefined && value !== null && String(value).length > 0).map(([key, value]) => `${pc2.dim("\u2502")} ${pc2.dim(key.padEnd(12))} ${value}`);
|
|
1413
|
+
return [formatSection(title), ...body].join(`
|
|
1414
|
+
`);
|
|
1415
|
+
}
|
|
1416
|
+
function formatNextSteps(steps) {
|
|
1417
|
+
if (steps.length === 0)
|
|
1418
|
+
return [];
|
|
1419
|
+
return [pc2.bold("Next"), ...steps.map((step) => `${pc2.dim("\u203A")} ${step}`)];
|
|
1420
|
+
}
|
|
1421
|
+
function formatTaskList(tasks, options = {}) {
|
|
1422
|
+
if (options.raw)
|
|
1423
|
+
return tasks.map((task) => JSON.stringify(task)).join(`
|
|
1424
|
+
`);
|
|
1425
|
+
if (tasks.length === 0)
|
|
1426
|
+
return [formatSection("Tasks", "none found"), ...formatNextSteps(["Try `rig server status` to confirm the selected server.", "Relax filters or run `rig task run --title ... --initial-prompt ...` for ad hoc work."])].join(`
|
|
1427
|
+
`);
|
|
1428
|
+
const rows = tasks.map((task) => {
|
|
1429
|
+
const raw = rawObject(task);
|
|
1430
|
+
const id = stringField(task, "id", "<unknown>");
|
|
1431
|
+
const status = stringField(task, "status", "unknown");
|
|
1432
|
+
const title = stringField(task, "title", "Untitled task");
|
|
1433
|
+
const source = stringField(task, "source", stringField(raw, "source", ""));
|
|
1434
|
+
const labels = arrayField(task, "labels").length > 0 ? arrayField(task, "labels") : arrayField(raw, "labels");
|
|
1435
|
+
return { id, status, title, source, labels };
|
|
1436
|
+
});
|
|
1437
|
+
const idWidth = Math.min(18, Math.max(4, ...rows.map((row) => row.id.length)));
|
|
1438
|
+
const statusWidth = Math.min(16, Math.max(6, ...rows.map((row) => row.status.length)));
|
|
1439
|
+
const header = `${pc2.bold(pad("TASK", idWidth))} ${pc2.bold(pad("STATUS", statusWidth))} ${pc2.bold("TITLE")}`;
|
|
1440
|
+
const body = rows.map((row) => {
|
|
1441
|
+
const labels = row.labels.length > 0 ? pc2.dim(` ${row.labels.slice(0, 4).map((label) => `#${label}`).join(" ")}`) : "";
|
|
1442
|
+
const source = row.source ? pc2.dim(` ${row.source}`) : "";
|
|
1443
|
+
return [
|
|
1444
|
+
pc2.bold(pad(truncate(row.id, idWidth), idWidth)),
|
|
1445
|
+
statusColor(row.status)(pad(truncate(row.status, statusWidth), statusWidth)),
|
|
1446
|
+
`${row.title}${labels}${source}`
|
|
1447
|
+
].join(" ");
|
|
1448
|
+
});
|
|
1449
|
+
return [formatSection("Tasks", `${rows.length} shown`), header, ...body, "", ...formatNextSteps(["Run one: `rig task run <id>` or `rig task run --next`", "Attach later: `rig run attach <run-id> --follow`"])].join(`
|
|
1450
|
+
`);
|
|
1451
|
+
}
|
|
1452
|
+
function formatTaskCard(task, options = {}) {
|
|
1453
|
+
const raw = rawObject(task);
|
|
1454
|
+
const id = stringField(task, "id", stringField(raw, "id", "<unknown>"));
|
|
1455
|
+
const status = stringField(task, "status", stringField(raw, "status", "unknown"));
|
|
1456
|
+
const title = stringField(task, "title", stringField(raw, "title", "Untitled task"));
|
|
1457
|
+
const source = stringField(task, "source", stringField(raw, "source", ""));
|
|
1458
|
+
const url = stringField(task, "url", stringField(raw, "url", ""));
|
|
1459
|
+
const number = numberField(task, "number") ?? numberField(raw, "number");
|
|
1460
|
+
const labels = arrayField(task, "labels").length > 0 ? arrayField(task, "labels") : arrayField(raw, "labels");
|
|
1461
|
+
const assignees = arrayField(task, "assignees").length > 0 ? arrayField(task, "assignees") : arrayField(raw, "assignees");
|
|
1462
|
+
const readiness = compactValue(task.readiness ?? raw.readiness);
|
|
1463
|
+
const validators = compactValue(task.validators ?? raw.validators ?? task.validation ?? raw.validation);
|
|
1464
|
+
const rows = [
|
|
1465
|
+
["task", pc2.bold(id)],
|
|
1466
|
+
["status", formatStatusPill(status)],
|
|
1467
|
+
["title", title],
|
|
1468
|
+
["source", source],
|
|
1469
|
+
["number", number],
|
|
1470
|
+
["labels", labels.length ? labels.map((label) => `#${label}`).join(" ") : ""],
|
|
1471
|
+
["assignees", assignees.join(", ")],
|
|
1472
|
+
["readiness", readiness],
|
|
1473
|
+
["validators", validators],
|
|
1474
|
+
["url", url]
|
|
1475
|
+
];
|
|
1476
|
+
return [
|
|
1477
|
+
formatSuccessCard(options.title ?? (options.selected ? "Selected task" : "Task"), rows),
|
|
1478
|
+
"",
|
|
1479
|
+
...formatNextSteps([`Start: \`rig task run ${id}\``, `Details: \`rig task show ${id} --raw\``])
|
|
1480
|
+
].join(`
|
|
1481
|
+
`);
|
|
1482
|
+
}
|
|
1483
|
+
function formatTaskDetails(task) {
|
|
1484
|
+
return formatTaskCard(task, { title: "Task details" });
|
|
1485
|
+
}
|
|
1486
|
+
function formatSubmittedRun(input) {
|
|
1487
|
+
const rows = [["run", pc2.bold(input.runId)]];
|
|
1488
|
+
if (input.task) {
|
|
1489
|
+
const id = stringField(input.task, "id", "<unknown>");
|
|
1490
|
+
const status = stringField(input.task, "status", "unknown");
|
|
1491
|
+
const title = stringField(input.task, "title", "Untitled task");
|
|
1492
|
+
rows.push(["task", `${pc2.bold(id)} ${formatStatusPill(status)} ${title}`]);
|
|
1493
|
+
}
|
|
1494
|
+
const runtime = [input.runtimeAdapter || "pi", input.runtimeMode || "full-access", input.interactionMode || "default"].filter(Boolean).join(" \xB7 ");
|
|
1495
|
+
rows.push(["runtime", runtime]);
|
|
1496
|
+
return [
|
|
1497
|
+
formatSuccessCard("Run submitted", rows),
|
|
1498
|
+
"",
|
|
1499
|
+
...formatNextSteps([
|
|
1500
|
+
`Attach: \`rig run attach ${input.runId} --follow\``,
|
|
1501
|
+
`Inspect: \`rig run show ${input.runId}\``,
|
|
1502
|
+
input.detached ? "Submitted detached; attach when you are ready." : "Interactive mode opens the enriched bundled Pi (native UI + Rig layers, worker brain)."
|
|
1503
|
+
])
|
|
1504
|
+
].join(`
|
|
1505
|
+
`);
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
// packages/cli/src/commands/inbox.ts
|
|
1509
|
+
async function listInboxRecords(context, kind, filters) {
|
|
1510
|
+
const params = new URLSearchParams;
|
|
1511
|
+
if (filters.run)
|
|
1512
|
+
params.set("runId", filters.run);
|
|
1513
|
+
if (filters.task)
|
|
1514
|
+
params.set("taskId", filters.task);
|
|
1515
|
+
const query = params.size > 0 ? `?${params.toString()}` : "";
|
|
1516
|
+
const payload = await requestServerJson(context, `/api/inbox/${kind}${query}`);
|
|
1517
|
+
const records = Array.isArray(payload) ? payload : [];
|
|
1518
|
+
return filters.pendingOnly ? records.filter((entry) => (entry.status ?? "pending") !== "resolved") : records;
|
|
1519
|
+
}
|
|
1520
|
+
async function readPendingInboxCounts(context) {
|
|
1521
|
+
try {
|
|
1522
|
+
const [approvals, inputs] = await Promise.all([
|
|
1523
|
+
listInboxRecords(context, "approvals", { pendingOnly: true }),
|
|
1524
|
+
listInboxRecords(context, "inputs", { pendingOnly: true })
|
|
1525
|
+
]);
|
|
1526
|
+
return { approvals: approvals.length, inputs: inputs.length };
|
|
1527
|
+
} catch {
|
|
1528
|
+
return null;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
async function printPendingInboxFooter(context) {
|
|
1532
|
+
if (context.outputMode !== "text")
|
|
1533
|
+
return;
|
|
1534
|
+
const counts = await readPendingInboxCounts(context);
|
|
1535
|
+
if (!counts || counts.approvals === 0 && counts.inputs === 0)
|
|
1536
|
+
return;
|
|
1537
|
+
const parts = [];
|
|
1538
|
+
if (counts.approvals > 0)
|
|
1539
|
+
parts.push(`${counts.approvals} approval${counts.approvals === 1 ? "" : "s"}`);
|
|
1540
|
+
if (counts.inputs > 0)
|
|
1541
|
+
parts.push(`${counts.inputs} input request${counts.inputs === 1 ? "" : "s"}`);
|
|
1542
|
+
console.log(`
|
|
1543
|
+
\u26A0 ${parts.join(" and ")} pending \u2014 run \`rig inbox\` to review.`);
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
// packages/cli/src/commands/_help-catalog.ts
|
|
1547
|
+
import { intro, log as log2, note as note2, outro } from "@clack/prompts";
|
|
1548
|
+
import pc3 from "picocolors";
|
|
1549
|
+
var TOP_LEVEL_SECTIONS = [
|
|
1550
|
+
{
|
|
1551
|
+
title: "Start here",
|
|
1552
|
+
subtitle: "one-time setup, pick a server",
|
|
1553
|
+
commands: [
|
|
1554
|
+
{ command: "rig init", description: "Wizard: config, GitHub auth, task source, server, Pi wiring." },
|
|
1555
|
+
{ command: "rig server use <alias|local>", description: "Pick which Rig server owns this repo (`rig server list` to see them)." },
|
|
1556
|
+
{ command: "rig server status", description: "Show the selected server for this repo." }
|
|
1557
|
+
]
|
|
1558
|
+
},
|
|
1559
|
+
{
|
|
1560
|
+
title: "Work",
|
|
1561
|
+
subtitle: "find a task, put an agent on it, answer what it asks",
|
|
1562
|
+
commands: [
|
|
1563
|
+
{ command: "rig task list", description: "What's on the board (from the selected source/server)." },
|
|
1564
|
+
{ command: "rig task run --next", description: "Dispatch an agent; interactive mode opens the native Pi session." },
|
|
1565
|
+
{ command: "rig run status", description: "Active and recent runs at a glance." },
|
|
1566
|
+
{ command: "rig run attach <id> --follow", description: "Join the live Pi session (worker keeps running if you /detach)." },
|
|
1567
|
+
{ command: "rig inbox approvals", description: "Approvals workers are waiting on (then `rig inbox approve \u2026`)." }
|
|
1568
|
+
]
|
|
1569
|
+
},
|
|
1570
|
+
{
|
|
1571
|
+
title: "Watch",
|
|
1572
|
+
subtitle: "fleet metrics and per-task forensics",
|
|
1573
|
+
commands: [
|
|
1574
|
+
{ command: "rig stats [--since 7d]", description: "Fleet metrics: completion/failure rates, median run time, steering, stalls." },
|
|
1575
|
+
{ command: "rig inspect logs --task <id>", description: "Latest run log for a task." },
|
|
1576
|
+
{ command: "rig inspect diff --task <id>", description: "Changed files for a task." }
|
|
1577
|
+
]
|
|
1578
|
+
},
|
|
1579
|
+
{
|
|
1580
|
+
title: "Unblock",
|
|
1581
|
+
subtitle: "diagnose wiring, fix auth",
|
|
1582
|
+
commands: [
|
|
1583
|
+
{ command: "rig doctor", description: "Check every part of the wiring \u2014 run this when anything feels off." },
|
|
1584
|
+
{ command: "rig github auth status", description: "GitHub auth state on the selected server." }
|
|
1585
|
+
]
|
|
1586
|
+
},
|
|
1587
|
+
{
|
|
1588
|
+
title: "Extend",
|
|
1589
|
+
subtitle: "plugins contribute validators, hooks, task sources, commands",
|
|
1590
|
+
commands: [
|
|
1591
|
+
{ command: "rig plugin list", description: "What the rig.config.ts plugins contribute." },
|
|
1592
|
+
{ command: "rig plugin run <command-id>", description: "Execute a plugin-contributed CLI command." }
|
|
1593
|
+
]
|
|
1594
|
+
}
|
|
1595
|
+
];
|
|
1596
|
+
var PRIMARY_GROUPS = [
|
|
1597
|
+
{
|
|
1598
|
+
name: "server",
|
|
1599
|
+
summary: "Choose, inspect, and start the Rig server that owns tasks and runs.",
|
|
1600
|
+
usage: ["rig server <status|list|add|use|start> [options]"],
|
|
1601
|
+
commands: [
|
|
1602
|
+
{ command: "status", description: "Show the selected server for this repo.", primary: true },
|
|
1603
|
+
{ command: "use local", description: "Switch this repo to the local Rig server.", primary: true },
|
|
1604
|
+
{ command: "add <alias> <url>", description: "Save a remote Rig server URL.", primary: true },
|
|
1605
|
+
{ command: "use <alias>", description: "Select a saved remote server alias.", primary: true },
|
|
1606
|
+
{ command: "list", description: "List saved local/remote server aliases.", primary: true },
|
|
1607
|
+
{ command: "start [--host <host>] [--port <n>]", description: "Start a local rig-server process." }
|
|
1608
|
+
],
|
|
1609
|
+
examples: [
|
|
1610
|
+
"rig server status",
|
|
1611
|
+
"rig server add prod https://where.rig-does.work",
|
|
1612
|
+
"rig server use prod",
|
|
1613
|
+
"rig server use local",
|
|
1614
|
+
"rig server start --port 3773"
|
|
1615
|
+
],
|
|
1616
|
+
next: ["Use `rig task list` to see server-owned work.", "Use `rig run list` or `rig run attach <id> --follow` to monitor runs."]
|
|
1617
|
+
},
|
|
1618
|
+
{
|
|
1619
|
+
name: "task",
|
|
1620
|
+
summary: "Find work, start Pi-backed runs, and validate task results.",
|
|
1621
|
+
usage: ["rig task <list|next|show|run> [options]"],
|
|
1622
|
+
commands: [
|
|
1623
|
+
{ command: "list [--assignee <login|me|@me>] [--state open|closed]", description: "List tasks from the selected server/source.", primary: true },
|
|
1624
|
+
{ command: "next [filters]", description: "Render the next matching task as a selected-task card.", primary: true },
|
|
1625
|
+
{ command: "show <id>|--task <id> [--raw]", description: "Show a human task summary; --raw prints the full payload.", primary: true },
|
|
1626
|
+
{ command: "run [#<issue>|<task-id>|--next|--task <id>]", description: "Submit a task run; interactive follows with bundled Pi.", primary: true },
|
|
1627
|
+
{ command: "validate|verify [--task <id>]", description: "Run configured task checks/review gates." },
|
|
1628
|
+
{ command: "details --task <id>", description: "Show full task info from the configured source." },
|
|
1629
|
+
{ command: "reopen [--task <id> | --all] [--reason <text>]", description: "Reopen closed task(s) in the configured source." },
|
|
1630
|
+
{ command: "artifacts|artifact-dir|artifact-write", description: "Inspect or write task artifacts." },
|
|
1631
|
+
{ command: "report-bug", description: "Create a structured bug report/task." }
|
|
1632
|
+
],
|
|
1633
|
+
examples: [
|
|
1634
|
+
"rig task list --assignee @me --limit 20",
|
|
1635
|
+
"rig task next",
|
|
1636
|
+
"rig task show 123 --raw",
|
|
1637
|
+
"rig task run --next",
|
|
1638
|
+
"rig task run #123 --runtime-adapter pi",
|
|
1639
|
+
"rig task run --title 'Investigate deploy drift' --initial-prompt 'Check server health'"
|
|
1640
|
+
],
|
|
1641
|
+
next: ["Use `--detach` to submit without attaching.", "Use `rig run attach <run-id> --follow` to rejoin a live run."]
|
|
1642
|
+
},
|
|
1643
|
+
{
|
|
1644
|
+
name: "run",
|
|
1645
|
+
summary: "Observe, attach to, and control Rig runs.",
|
|
1646
|
+
usage: ["rig run <list|status|show|attach|stop> [options]"],
|
|
1647
|
+
commands: [
|
|
1648
|
+
{ command: "list", description: "List recent runs from the selected server or local state.", primary: true },
|
|
1649
|
+
{ command: "status", description: "Render active and recent run groups.", primary: true },
|
|
1650
|
+
{ command: "show <id>|--run <id> [--raw]", description: "Show a human run summary; --raw prints the full payload.", primary: true },
|
|
1651
|
+
{ command: "attach <run-id>|--run <id> [--follow]", description: "Attach to the run; --follow opens the enriched bundled Pi (worker brain).", primary: true },
|
|
1652
|
+
{ command: "stop [<run-id>|--run <id>]", description: "Request stop for one run or local active runs.", primary: true },
|
|
1653
|
+
{ command: "steer <run-id> --message <text>", description: "Queue a steering message into a live worker without attaching." },
|
|
1654
|
+
{ command: "timeline --run <id> [--follow]", description: "Stream raw run timeline events." },
|
|
1655
|
+
{ command: "replay <run-id>|--run <id> [--with-session]", description: "Print the run's consolidated run.jsonl as a merged timeline; --with-session interleaves the Pi session log." },
|
|
1656
|
+
{ command: "resume", description: "Resume the most recent interrupted local run." },
|
|
1657
|
+
{ command: "restart", description: "Restart the most recent local run from a clean runtime." },
|
|
1658
|
+
{ command: "delete|cleanup", description: "Remove completed run records/artifacts." }
|
|
1659
|
+
],
|
|
1660
|
+
examples: [
|
|
1661
|
+
"rig run list",
|
|
1662
|
+
"rig run status",
|
|
1663
|
+
"rig run show <run-id>",
|
|
1664
|
+
"rig run attach <run-id> --follow",
|
|
1665
|
+
"rig run stop <run-id>"
|
|
1666
|
+
],
|
|
1667
|
+
next: ["Use `rig task run --next` to create a new run.", "Use `--json` when scripts need the full structured record."]
|
|
1668
|
+
},
|
|
1669
|
+
{
|
|
1670
|
+
name: "inbox",
|
|
1671
|
+
summary: "Review approval and user-input requests that block worker runs.",
|
|
1672
|
+
usage: ["rig inbox <approvals|approve|inputs|respond> [options]"],
|
|
1673
|
+
commands: [
|
|
1674
|
+
{ command: "approvals [--run <id>] [--task <id>]", description: "List pending approvals.", primary: true },
|
|
1675
|
+
{ command: "inputs [--run <id>] [--task <id>]", description: "List pending user-input requests.", primary: true },
|
|
1676
|
+
{ command: "approve --run <id> --request <id> --decision approve|reject", description: "Resolve an approval request." },
|
|
1677
|
+
{ command: "respond --run <id> --request <id> --answer key=value", description: "Answer a user-input request." }
|
|
1678
|
+
],
|
|
1679
|
+
examples: [
|
|
1680
|
+
"rig inbox approvals",
|
|
1681
|
+
"rig inbox inputs --run <run-id>",
|
|
1682
|
+
"rig inbox approve --run <run-id> --request <request-id> --decision approve"
|
|
1683
|
+
],
|
|
1684
|
+
next: ["Rejoin the run after resolving a block: `rig run attach <run-id> --follow`."]
|
|
1685
|
+
},
|
|
1686
|
+
{
|
|
1687
|
+
name: "stats",
|
|
1688
|
+
summary: "Fleet metrics computed from on-disk run journals (no server required).",
|
|
1689
|
+
usage: ["rig stats [show] [--since <7d|30d|ISO date>]"],
|
|
1690
|
+
commands: [
|
|
1691
|
+
{ command: "show [--since <window>]", description: "Total runs, completion/failure/needs-attention rates, median run time, steering, stalls, approvals.", primary: true }
|
|
1692
|
+
],
|
|
1693
|
+
examples: [
|
|
1694
|
+
"rig stats",
|
|
1695
|
+
"rig stats --since 7d",
|
|
1696
|
+
"rig stats --since 2026-06-01 --json"
|
|
1697
|
+
],
|
|
1698
|
+
next: ["Inspect outliers with `rig run list` and `rig run show <run-id>`.", "Use `--json` for the schema'd envelope (see docs/cli-json.md)."]
|
|
1699
|
+
},
|
|
1700
|
+
{
|
|
1701
|
+
name: "inspect",
|
|
1702
|
+
summary: "Inspect logs, artifacts, graphs, failures for a task.",
|
|
1703
|
+
usage: ["rig inspect <logs|artifacts|failures|graph|audit|diff> --task <id>"],
|
|
1704
|
+
commands: [
|
|
1705
|
+
{ command: "logs --task <id>", description: "Latest run log for a task (local or selected server).", primary: true },
|
|
1706
|
+
{ command: "artifacts --task <id>", description: "List the task's completion artifacts.", primary: true },
|
|
1707
|
+
{ command: "failures --task <id>", description: "Recorded failures for a task.", primary: true },
|
|
1708
|
+
{ command: "diff --task <id>", description: "Changed files for a task.", primary: true },
|
|
1709
|
+
{ command: "graph", description: "Task dependency graph." },
|
|
1710
|
+
{ command: "audit", description: "Controlled-command audit trail." }
|
|
1711
|
+
],
|
|
1712
|
+
examples: ["rig inspect logs --task <id>", "rig inspect diff --task <id>"],
|
|
1713
|
+
next: ["Use `rig stats` for fleet-level metrics across runs."]
|
|
1714
|
+
},
|
|
1715
|
+
{
|
|
1716
|
+
name: "repo",
|
|
1717
|
+
summary: "Repository sync/baseline helpers for the Rig-managed checkout.",
|
|
1718
|
+
usage: ["rig repo <sync|reset-baseline>"],
|
|
1719
|
+
commands: [
|
|
1720
|
+
{ command: "sync", description: "Sync project repository state.", primary: true },
|
|
1721
|
+
{ command: "reset-baseline", description: "Reset the managed baseline for the repo." }
|
|
1722
|
+
],
|
|
1723
|
+
examples: ["rig repo sync"]
|
|
1724
|
+
},
|
|
1725
|
+
{
|
|
1726
|
+
name: "plugin",
|
|
1727
|
+
summary: "Plugin listing, validation, and plugin-contributed commands.",
|
|
1728
|
+
usage: ["rig plugin <list|validate|run> [options]"],
|
|
1729
|
+
commands: [
|
|
1730
|
+
{ command: "list", description: "List plugins declared in rig.config.ts and their contributions.", primary: true },
|
|
1731
|
+
{ command: "validate --task <id>", description: "Run plugin-contributed validators for a task.", primary: true },
|
|
1732
|
+
{ command: "run <command-id> [args...]", description: "Execute a plugin-contributed CLI command (also callable as `rig <command-id>`)." }
|
|
1733
|
+
],
|
|
1734
|
+
examples: ["rig plugin list", "rig plugin run <command-id>"]
|
|
1735
|
+
},
|
|
1736
|
+
{
|
|
1737
|
+
name: "init",
|
|
1738
|
+
summary: "Set up Rig for this repo: server, GitHub auth, checkout strategy, task source, and Pi wiring.",
|
|
1739
|
+
usage: ["rig init [--yes] [--server local|remote] [--repo owner/repo] [--remote-url <url>]"],
|
|
1740
|
+
commands: [
|
|
1741
|
+
{ command: "init", description: "Interactive setup wizard for a new or existing Rig repo.", primary: true },
|
|
1742
|
+
{ command: "init --demo", description: "Offline demo project: files task source + 3 sample tasks, zero GitHub.", primary: true },
|
|
1743
|
+
{ command: "init --yes", description: "Non-interactive setup using detected/default settings.", primary: true },
|
|
1744
|
+
{ command: "init --server remote --remote-url <url>", description: "Link this repo to a remote Rig server.", primary: true },
|
|
1745
|
+
{ command: "init --repair", description: "Repair missing private state without replacing project config." }
|
|
1746
|
+
],
|
|
1747
|
+
examples: [
|
|
1748
|
+
"rig init",
|
|
1749
|
+
"rig init --demo",
|
|
1750
|
+
"rig init --yes --repo humanity-org/humanwork",
|
|
1751
|
+
"rig init --server remote --remote-url https://where.rig-does.work --repo owner/repo"
|
|
1752
|
+
],
|
|
1753
|
+
next: ["After init, run `rig server status`.", "Then use `rig task list` and `rig task run --next` for day-to-day work."]
|
|
1754
|
+
},
|
|
1755
|
+
{
|
|
1756
|
+
name: "doctor",
|
|
1757
|
+
summary: "Diagnostics for project/server/GitHub/Pi state.",
|
|
1758
|
+
usage: ["rig doctor"],
|
|
1759
|
+
commands: [
|
|
1760
|
+
{ command: "doctor", description: "Run setup and runtime diagnostics.", primary: true },
|
|
1761
|
+
{ command: "check", description: "Compatibility spelling for diagnostics." }
|
|
1762
|
+
],
|
|
1763
|
+
examples: ["rig doctor", "rig doctor --json"],
|
|
1764
|
+
next: ["Use `rig server status` and `rig github auth status` to inspect common failure points."]
|
|
1765
|
+
},
|
|
1766
|
+
{
|
|
1767
|
+
name: "github",
|
|
1768
|
+
summary: "GitHub auth helpers for the selected Rig server.",
|
|
1769
|
+
usage: ["rig github auth <status|import-gh|token>"],
|
|
1770
|
+
commands: [
|
|
1771
|
+
{ command: "auth status", description: "Show GitHub auth state.", primary: true },
|
|
1772
|
+
{ command: "auth import-gh", description: "Import the current `gh` token into the selected server." },
|
|
1773
|
+
{ command: "auth token --token <token>", description: "Store a token on the selected server." }
|
|
1774
|
+
],
|
|
1775
|
+
examples: ["rig github auth status", "rig github auth import-gh"],
|
|
1776
|
+
next: ["After auth is valid, use `rig task run --next`."]
|
|
1777
|
+
}
|
|
1778
|
+
];
|
|
1779
|
+
var ADVANCED_GROUPS = [
|
|
1780
|
+
{ name: "setup", summary: "Bootstrap/check local setup.", usage: ["rig setup <bootstrap|check|preflight>"], commands: [{ command: "bootstrap|check|preflight", description: "Setup helpers." }] },
|
|
1781
|
+
{ name: "profile", summary: "Runtime profile/model defaults.", usage: ["rig profile <show|set>"], commands: [{ command: "show", description: "Show active profile." }] },
|
|
1782
|
+
{
|
|
1783
|
+
name: "review",
|
|
1784
|
+
summary: "Inspect or change completion review gate policy.",
|
|
1785
|
+
usage: ["rig review <show|set>"],
|
|
1786
|
+
commands: [
|
|
1787
|
+
{ command: "show", description: "Show current review gate settings." },
|
|
1788
|
+
{ command: "set <off|advisory|required> [--provider greptile]", description: "Change review strictness/provider." }
|
|
1789
|
+
],
|
|
1790
|
+
examples: ["rig review show", "rig review set required --provider greptile"],
|
|
1791
|
+
next: ["Use `rig inbox approvals` for blocked run handoffs."]
|
|
1792
|
+
},
|
|
1793
|
+
{
|
|
1794
|
+
name: "browser",
|
|
1795
|
+
summary: "Browser/app diagnostics for browser-required tasks.",
|
|
1796
|
+
usage: ["rig browser <help|explain|demo|app|hp-next> [options]"],
|
|
1797
|
+
commands: [
|
|
1798
|
+
{ command: "help", description: "Rich browser command help (canonical: `rig browser help`)." },
|
|
1799
|
+
{ command: "explain", description: "Explain the browser-required task contract." },
|
|
1800
|
+
{ command: "demo", description: "Run browser demo flows against a local page." },
|
|
1801
|
+
{ command: "app", description: "Launch the Rig Browser workstation app." },
|
|
1802
|
+
{ command: "hp-next <dev|check|e2e|reset>", description: "Drive the hp-next browser test harness." }
|
|
1803
|
+
]
|
|
1804
|
+
},
|
|
1805
|
+
{
|
|
1806
|
+
name: "pi",
|
|
1807
|
+
summary: "Manage Pi extension packages for this project (community extensions from npm/git).",
|
|
1808
|
+
usage: ["rig pi <list|add|remove|search> [args]"],
|
|
1809
|
+
commands: [
|
|
1810
|
+
{ command: "list", description: "Show project and user Pi extension packages." },
|
|
1811
|
+
{ command: "add <source>", description: "Add an npm/git Pi extension to .pi/settings.json (auto-installs at next session)." },
|
|
1812
|
+
{ command: "remove <source>", description: "Remove an operator-added Pi extension." },
|
|
1813
|
+
{ command: "search [term]", description: "Discover Pi extension packages on the npm registry." }
|
|
1814
|
+
],
|
|
1815
|
+
examples: ["rig pi search subagents", "rig pi add pi-subagents", "rig pi list"],
|
|
1816
|
+
next: ["Config-managed extensions: declare `runtime: { pi: { packages: [...] } }` in rig.config.ts \u2014 workers pick them up automatically."]
|
|
1817
|
+
},
|
|
1818
|
+
{ name: "queue", summary: "Run task queues locally.", usage: ["rig queue run [options]"], commands: [{ command: "run", description: "Process queue work." }] },
|
|
1819
|
+
{ name: "agent", summary: "Runtime agent workspace helpers.", usage: ["rig agent <list|prepare|run|cleanup>"], commands: [{ command: "list", description: "List prepared agents." }] },
|
|
1820
|
+
{ name: "inspector", summary: "Event stream and drift scanners.", usage: ["rig inspector <stream|scan-upstream-drift>"], commands: [{ command: "stream", description: "Stream events." }] },
|
|
1821
|
+
{ name: "dist", summary: "Build/install packaged Rig CLI.", usage: ["rig dist <build|install|doctor>"], commands: [{ command: "build", description: "Build distribution." }] },
|
|
1822
|
+
{ name: "workspace", summary: "Workspace topology/service helpers.", usage: ["rig workspace <summary|topology|remote-hosts>"], commands: [{ command: "summary", description: "Show workspace summary." }] },
|
|
1823
|
+
{ name: "remote", summary: "Compatibility remote orchestration controls.", usage: ["rig remote <status|watch|pause|resume|...>"], commands: [{ command: "status", description: "Show remote state." }] },
|
|
1824
|
+
{ name: "git", summary: "Pass through to Rig git-flow helper.", usage: ["rig git <args...>"], commands: [{ command: "<args...>", description: "Advanced git flow operations." }] },
|
|
1825
|
+
{ name: "harness", summary: "Pass through to runtime harness CLI.", usage: ["rig harness <args...>"], commands: [{ command: "<args...>", description: "Advanced harness operations." }] },
|
|
1826
|
+
{ name: "test", summary: "Project test wrappers.", usage: ["rig test <unit|e2e|all>"], commands: [{ command: "all", description: "Run configured project tests." }] }
|
|
1827
|
+
];
|
|
1828
|
+
var ALL_GROUPS = [...PRIMARY_GROUPS, ...ADVANCED_GROUPS];
|
|
1829
|
+
function heading(title) {
|
|
1830
|
+
return pc3.bold(pc3.cyan(title));
|
|
1831
|
+
}
|
|
1832
|
+
function renderRigBanner(version) {
|
|
1833
|
+
const m = (s) => pc3.bold(pc3.magenta(s));
|
|
1834
|
+
const c = (s) => pc3.bold(pc3.cyan(s));
|
|
1835
|
+
const y = (s) => pc3.yellow(s);
|
|
1836
|
+
const d = (s) => pc3.dim(s);
|
|
1837
|
+
const lines = [
|
|
1838
|
+
m(" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 ") + d(" \u2591\u2592\u2593\u2588 "),
|
|
1839
|
+
m(" \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D ") + d("\u2593\u2592\u2591"),
|
|
1840
|
+
c(" \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2557") + d(" \u2591\u2592"),
|
|
1841
|
+
c(" \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551") + d(" \u2588\u2593\u2591"),
|
|
1842
|
+
y(" \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D") + d(" \u2592\u2591"),
|
|
1843
|
+
y(" \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D "),
|
|
1844
|
+
"",
|
|
1845
|
+
` ${c("\u25E2\u25E4")} ${pc3.bold("the control rig for autonomous coding agents")} ${m("//")} ${d("you are the operator")}`,
|
|
1846
|
+
version ? ` ${d(`v${version} \xB7 jack in: rig task run --next`)}` : ` ${d("jack in: rig task run --next")}`
|
|
1847
|
+
];
|
|
1848
|
+
return lines.join(`
|
|
1849
|
+
`);
|
|
1850
|
+
}
|
|
1851
|
+
function commandLine(command, description) {
|
|
1852
|
+
const commandColumn = command.length >= 38 ? `${command} ` : command.padEnd(38);
|
|
1853
|
+
return `${pc3.dim("\u2502")} ${pc3.bold(commandColumn)} ${description}`;
|
|
1854
|
+
}
|
|
1855
|
+
function renderCommandBlock(commands) {
|
|
1856
|
+
return commands.map((entry) => commandLine(entry.command, entry.description)).join(`
|
|
1857
|
+
`);
|
|
1858
|
+
}
|
|
1859
|
+
function renderGroup(group) {
|
|
1860
|
+
const lines = [
|
|
1861
|
+
`${heading(`rig ${group.name}`)} \u2014 ${group.summary}`,
|
|
1862
|
+
"",
|
|
1863
|
+
pc3.bold("Usage"),
|
|
1864
|
+
...group.usage.map((line) => ` ${line}`),
|
|
1865
|
+
"",
|
|
1866
|
+
pc3.bold("Commands"),
|
|
1867
|
+
...group.commands.map((entry) => commandLine(entry.command, entry.description))
|
|
1868
|
+
];
|
|
1869
|
+
if (group.examples?.length) {
|
|
1870
|
+
lines.push("", pc3.bold("Examples"), ...group.examples.map((line) => ` ${pc3.dim("$")} ${line}`));
|
|
1871
|
+
}
|
|
1872
|
+
if (group.next?.length) {
|
|
1873
|
+
lines.push("", pc3.bold("Next steps"), ...group.next.map((line) => ` ${pc3.dim("\u203A")} ${line}`));
|
|
1874
|
+
}
|
|
1875
|
+
if (group.advanced?.length) {
|
|
1876
|
+
lines.push("", pc3.bold("Compatibility / advanced"), ...group.advanced.map((line) => ` ${pc3.dim("\u203A")} ${line}`));
|
|
1877
|
+
}
|
|
1878
|
+
return lines.join(`
|
|
1879
|
+
`);
|
|
1880
|
+
}
|
|
1881
|
+
function renderTopLevelHelp() {
|
|
1882
|
+
return [
|
|
1883
|
+
`${heading("rig")} ${pc3.dim("\u2014 server-owned task/run control plane for Pi-backed engineering work")}`,
|
|
1884
|
+
pc3.dim("Current path: select a server, choose a task, submit a run, attach with native Pi, clear inbox gates."),
|
|
1885
|
+
"",
|
|
1886
|
+
...TOP_LEVEL_SECTIONS.flatMap((section) => [
|
|
1887
|
+
`${pc3.bold(pc3.magenta(`\u25C7 ${section.title}`))} \u2014 ${pc3.dim(section.subtitle)}`,
|
|
1888
|
+
renderCommandBlock(section.commands),
|
|
1889
|
+
""
|
|
1890
|
+
]),
|
|
1891
|
+
pc3.dim("More: `rig help --advanced` for dev/compatibility commands; `rig <group> --help` for rich per-group help; `rig --version` for the installed version."),
|
|
1892
|
+
"",
|
|
1893
|
+
pc3.bold("Global options"),
|
|
1894
|
+
commandLine("--project <path>", "Use a project root instead of auto-discovery."),
|
|
1895
|
+
commandLine("--json", "Emit structured output for scripts/agents."),
|
|
1896
|
+
commandLine("--dry-run", "Print the command plan without mutating state.")
|
|
1897
|
+
].join(`
|
|
1898
|
+
`).trimEnd();
|
|
1899
|
+
}
|
|
1900
|
+
function renderGroupHelp(groupName) {
|
|
1901
|
+
const group = ALL_GROUPS.find((candidate) => candidate.name === groupName);
|
|
1902
|
+
return group ? renderGroup(group) : null;
|
|
1903
|
+
}
|
|
1904
|
+
function shouldUseClackOutput2() {
|
|
1905
|
+
return Boolean(process.stdout.isTTY) && process.env.RIG_CLI_PLAIN_HELP !== "1";
|
|
1906
|
+
}
|
|
1907
|
+
function printTopLevelHelp(state = {}) {
|
|
1908
|
+
if (!shouldUseClackOutput2()) {
|
|
1909
|
+
console.log(renderTopLevelHelp());
|
|
1910
|
+
return;
|
|
1911
|
+
}
|
|
1912
|
+
console.log(renderRigBanner(state.version));
|
|
1913
|
+
console.log("");
|
|
1914
|
+
if (state.projectInitialized === false) {
|
|
1915
|
+
intro("no rig project in this directory");
|
|
1916
|
+
note2([
|
|
1917
|
+
commandLine("rig init", "Set this repo up: config, GitHub auth, task source, server, Pi."),
|
|
1918
|
+
commandLine("rig init --yes", "Same, non-interactive, sensible defaults."),
|
|
1919
|
+
commandLine("rig doctor", "Already initialized somewhere else? Check the wiring.")
|
|
1920
|
+
].join(`
|
|
1921
|
+
`), "Get started");
|
|
1922
|
+
outro("After init: rig task run --next puts an agent on your next task.");
|
|
1923
|
+
return;
|
|
1924
|
+
}
|
|
1925
|
+
intro(state.selectedServer ? `server: ${state.selectedServer}` : "rig");
|
|
1926
|
+
for (const section of TOP_LEVEL_SECTIONS) {
|
|
1927
|
+
note2(renderCommandBlock(section.commands), `${section.title} \u2014 ${section.subtitle}`);
|
|
1928
|
+
}
|
|
1929
|
+
log2.info("More: rig help --advanced \xB7 rig <group> --help \xB7 rig --version");
|
|
1930
|
+
note2([
|
|
1931
|
+
commandLine("--project <path>", "Use a project root instead of auto-discovery."),
|
|
1932
|
+
commandLine("--json", "Emit structured output for scripts/agents."),
|
|
1933
|
+
commandLine("--dry-run", "Print the command plan without mutating state.")
|
|
1934
|
+
].join(`
|
|
1935
|
+
`), "Global options");
|
|
1936
|
+
outro("init \u2192 task run \u2192 watch \u2192 inbox \u2192 merged.");
|
|
1937
|
+
}
|
|
1938
|
+
function printGroupHelpDocument(groupName) {
|
|
1939
|
+
const rendered = renderGroupHelp(groupName) ?? renderTopLevelHelp();
|
|
1940
|
+
if (!shouldUseClackOutput2()) {
|
|
1941
|
+
console.log(rendered);
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
const group = ALL_GROUPS.find((candidate) => candidate.name === groupName);
|
|
1945
|
+
if (!group) {
|
|
1946
|
+
printTopLevelHelp();
|
|
1947
|
+
return;
|
|
1948
|
+
}
|
|
1949
|
+
intro(`rig ${group.name}`);
|
|
1950
|
+
note2(group.summary, "Purpose");
|
|
1951
|
+
note2(group.usage.join(`
|
|
1952
|
+
`), "Usage");
|
|
1953
|
+
note2(group.commands.map((entry) => commandLine(entry.command, entry.description)).join(`
|
|
1954
|
+
`), "Commands");
|
|
1955
|
+
if (group.examples?.length)
|
|
1956
|
+
note2(group.examples.map((line) => `$ ${line}`).join(`
|
|
1957
|
+
`), "Examples");
|
|
1958
|
+
if (group.next?.length)
|
|
1959
|
+
note2(group.next.map((line) => `\u203A ${line}`).join(`
|
|
1960
|
+
`), "Next steps");
|
|
1961
|
+
if (group.advanced?.length)
|
|
1962
|
+
log2.info(group.advanced.join(`
|
|
1963
|
+
`));
|
|
1964
|
+
outro("Run with --json when scripts need structured output.");
|
|
1965
|
+
}
|
|
1966
|
+
|
|
852
1967
|
// packages/cli/src/commands/task.ts
|
|
853
1968
|
import { buildPluginHostContext } from "@rig/runtime/control-plane/plugin-host-context";
|
|
854
1969
|
import { loadConfig } from "@rig/core/load-config";
|
|
@@ -859,7 +1974,7 @@ async function readStdin() {
|
|
|
859
1974
|
}
|
|
860
1975
|
return Buffer.concat(chunks).toString("utf-8");
|
|
861
1976
|
}
|
|
862
|
-
function
|
|
1977
|
+
function normalizeAssigneeAlias(value) {
|
|
863
1978
|
if (!value)
|
|
864
1979
|
return;
|
|
865
1980
|
return value.trim().toLowerCase() === "me" ? "@me" : value;
|
|
@@ -868,25 +1983,19 @@ function parseTaskFilters(args) {
|
|
|
868
1983
|
let pending = args;
|
|
869
1984
|
const assigneeResult = takeOption(pending, "--assignee");
|
|
870
1985
|
pending = assigneeResult.rest;
|
|
871
|
-
const assignedToResult = takeOption(pending, "--assigned-to");
|
|
872
|
-
pending = assignedToResult.rest;
|
|
873
1986
|
const stateResult = takeOption(pending, "--state");
|
|
874
1987
|
pending = stateResult.rest;
|
|
875
1988
|
const statusResult = takeOption(pending, "--status");
|
|
876
1989
|
pending = statusResult.rest;
|
|
877
1990
|
const limitResult = takeOption(pending, "--limit");
|
|
878
1991
|
pending = limitResult.rest;
|
|
879
|
-
const
|
|
880
|
-
if (assigneeResult.value && normalizedAssignedTo && assigneeResult.value !== normalizedAssignedTo) {
|
|
881
|
-
throw new CliError2("--assignee and --assigned-to cannot specify different assignees.", 2);
|
|
882
|
-
}
|
|
883
|
-
const assignee = normalizedAssignedTo ?? assigneeResult.value;
|
|
1992
|
+
const assignee = normalizeAssigneeAlias(assigneeResult.value);
|
|
884
1993
|
const limit = (() => {
|
|
885
1994
|
if (!limitResult.value)
|
|
886
1995
|
return;
|
|
887
1996
|
const parsed = Number.parseInt(limitResult.value, 10);
|
|
888
1997
|
if (!Number.isFinite(parsed) || parsed < 1) {
|
|
889
|
-
throw new
|
|
1998
|
+
throw new CliError("--limit must be a positive integer.", 2, { hint: "Re-run with a positive number, e.g. `rig task list --limit 20`." });
|
|
890
1999
|
}
|
|
891
2000
|
return parsed;
|
|
892
2001
|
})();
|
|
@@ -921,10 +2030,10 @@ function normalizePrMode(value) {
|
|
|
921
2030
|
return;
|
|
922
2031
|
if (value === "auto" || value === "ask" || value === "off")
|
|
923
2032
|
return value;
|
|
924
|
-
throw new
|
|
2033
|
+
throw new CliError("--pr must be auto, ask, or off.", 2, { hint: "Re-run with `--pr auto|ask|off`, or pass `--no-pr` to disable the PR." });
|
|
925
2034
|
}
|
|
926
2035
|
function detectLocalDirtyState(projectRoot) {
|
|
927
|
-
const result =
|
|
2036
|
+
const result = spawnSync("git", ["-C", projectRoot, "status", "--porcelain"], { encoding: "utf8", timeout: 5000 });
|
|
928
2037
|
if (result.status !== 0)
|
|
929
2038
|
return { dirty: false, modified: 0, untracked: 0, lines: [] };
|
|
930
2039
|
const lines = result.stdout.split(/\r?\n/).map((line) => line.trimEnd()).filter(Boolean);
|
|
@@ -944,7 +2053,7 @@ function selectedServerKind(projectRoot) {
|
|
|
944
2053
|
}
|
|
945
2054
|
async function resolveDirtyBaselineForTaskRun(context, explicit) {
|
|
946
2055
|
if (explicit && explicit !== "head" && explicit !== "dirty-snapshot") {
|
|
947
|
-
throw new
|
|
2056
|
+
throw new CliError("--dirty-baseline must be head or dirty-snapshot.", 2, { hint: "Re-run with `--dirty-baseline head` or `--dirty-baseline dirty-snapshot`." });
|
|
948
2057
|
}
|
|
949
2058
|
if (selectedServerKind(context.projectRoot) !== "local") {
|
|
950
2059
|
return { mode: explicit === "dirty-snapshot" ? "dirty-snapshot" : "head", state: null };
|
|
@@ -958,13 +2067,15 @@ async function resolveDirtyBaselineForTaskRun(context, explicit) {
|
|
|
958
2067
|
if (explicit)
|
|
959
2068
|
return { mode: explicit, state };
|
|
960
2069
|
if (context.outputMode === "text" && process.stdin.isTTY && process.stdout.isTTY) {
|
|
961
|
-
const
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
2070
|
+
const answer = await confirm({
|
|
2071
|
+
message: "Include current uncommitted changes in run baseline?",
|
|
2072
|
+
initialValue: false
|
|
2073
|
+
});
|
|
2074
|
+
if (isCancel2(answer)) {
|
|
2075
|
+
cancel2("Run cancelled.");
|
|
2076
|
+
throw new CliError("Run cancelled by user.", 1);
|
|
967
2077
|
}
|
|
2078
|
+
return { mode: answer ? "dirty-snapshot" : "head", state };
|
|
968
2079
|
}
|
|
969
2080
|
return { mode: "head", state };
|
|
970
2081
|
}
|
|
@@ -998,38 +2109,31 @@ function summarizeTask(task, options = {}) {
|
|
|
998
2109
|
...options.raw ? { raw: raw ?? task } : {}
|
|
999
2110
|
};
|
|
1000
2111
|
}
|
|
1001
|
-
function printTaskSummary(task) {
|
|
1002
|
-
const id = readTaskId(task) ?? "<unknown>";
|
|
1003
|
-
const title = readTaskString(task, "title") ?? "Untitled task";
|
|
1004
|
-
const status = readTaskString(task, "status") ?? "unknown";
|
|
1005
|
-
console.log(`- ${id} \xB7 ${status} \xB7 ${title}`);
|
|
1006
|
-
}
|
|
1007
2112
|
async function validatorRegistryForTaskCommands(projectRoot) {
|
|
1008
2113
|
return buildPluginHostContext(projectRoot).then((ctx) => ctx?.validatorRegistry ?? undefined).catch(() => {
|
|
1009
2114
|
return;
|
|
1010
2115
|
});
|
|
1011
2116
|
}
|
|
1012
2117
|
async function executeTask(context, args, options) {
|
|
1013
|
-
|
|
2118
|
+
if (args.length === 0) {
|
|
2119
|
+
if (context.outputMode === "text") {
|
|
2120
|
+
printGroupHelpDocument("task");
|
|
2121
|
+
}
|
|
2122
|
+
return { ok: true, group: "task", command: "help" };
|
|
2123
|
+
}
|
|
2124
|
+
const [command = "help", ...rest] = args;
|
|
1014
2125
|
switch (command) {
|
|
1015
2126
|
case "list": {
|
|
1016
2127
|
let pending = rest;
|
|
1017
2128
|
const rawResult = takeFlag(pending, "--raw");
|
|
1018
2129
|
pending = rawResult.rest;
|
|
1019
2130
|
const { filters, rest: remaining } = parseTaskFilters(pending);
|
|
1020
|
-
requireNoExtraArgs(remaining, "
|
|
1021
|
-
const tasks = await listWorkspaceTasksViaServer(context, filters);
|
|
2131
|
+
requireNoExtraArgs(remaining, "rig task list [--raw] [--assignee <login|me|@me>] [--state open|closed] [--status <status>] [--limit <n>]");
|
|
2132
|
+
const tasks = await withSpinner("Reading tasks from server\u2026", () => listWorkspaceTasksViaServer(context, filters), { outputMode: context.outputMode });
|
|
1022
2133
|
if (context.outputMode === "text") {
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
for (const task of tasks) {
|
|
1027
|
-
if (rawResult.value)
|
|
1028
|
-
console.log(JSON.stringify(summarizeTask(task, { raw: true })));
|
|
1029
|
-
else
|
|
1030
|
-
printTaskSummary(task);
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
2134
|
+
const renderedTasks = rawResult.value ? tasks.map((task) => summarizeTask(task, { raw: true })) : tasks.map((task) => summarizeTask(task));
|
|
2135
|
+
printFormattedOutput(formatTaskList(renderedTasks, { raw: rawResult.value }));
|
|
2136
|
+
await printPendingInboxFooter(context);
|
|
1033
2137
|
}
|
|
1034
2138
|
return {
|
|
1035
2139
|
ok: true,
|
|
@@ -1039,30 +2143,34 @@ async function executeTask(context, args, options) {
|
|
|
1039
2143
|
};
|
|
1040
2144
|
}
|
|
1041
2145
|
case "show": {
|
|
1042
|
-
|
|
2146
|
+
let pending = rest;
|
|
2147
|
+
const rawResult = takeFlag(pending, "--raw");
|
|
2148
|
+
pending = rawResult.rest;
|
|
2149
|
+
const taskOption = takeOption(pending, "--task");
|
|
1043
2150
|
const positional = taskOption.rest.length > 0 && taskOption.rest[0] && !taskOption.rest[0].startsWith("-") ? taskOption.rest[0] : undefined;
|
|
1044
2151
|
const remaining = positional ? taskOption.rest.slice(1) : taskOption.rest;
|
|
1045
|
-
requireNoExtraArgs(remaining, "
|
|
1046
|
-
const
|
|
1047
|
-
if (!
|
|
1048
|
-
throw new
|
|
1049
|
-
const task = await getWorkspaceTaskViaServer(context,
|
|
2152
|
+
requireNoExtraArgs(remaining, "rig task show <id>|--task <id> [--raw]");
|
|
2153
|
+
const taskId3 = normalizeTaskRunTaskId(taskOption.value ?? positional);
|
|
2154
|
+
if (!taskId3)
|
|
2155
|
+
throw new CliError("task show requires a task id.", 2, { hint: "Run `rig task list` to find ids, then `rig task show <id>`." });
|
|
2156
|
+
const task = await withSpinner(`Reading task ${taskId3} from server\u2026`, () => getWorkspaceTaskViaServer(context, taskId3), { outputMode: context.outputMode });
|
|
1050
2157
|
if (!task)
|
|
1051
|
-
throw new
|
|
2158
|
+
throw new CliError(`Task not found: ${taskId3}`, 3, { hint: "Run `rig task list` to see available tasks." });
|
|
1052
2159
|
const summary = summarizeTask(task, { raw: true });
|
|
1053
|
-
if (context.outputMode === "text")
|
|
1054
|
-
|
|
1055
|
-
|
|
2160
|
+
if (context.outputMode === "text") {
|
|
2161
|
+
printFormattedOutput(rawResult.value ? JSON.stringify(summary, null, 2) : formatTaskDetails(summary));
|
|
2162
|
+
}
|
|
2163
|
+
return { ok: true, group: "task", command, details: { task: summary, raw: rawResult.value } };
|
|
1056
2164
|
}
|
|
1057
2165
|
case "next": {
|
|
1058
2166
|
const { filters, rest: remaining } = parseTaskFilters(rest);
|
|
1059
|
-
requireNoExtraArgs(remaining, "
|
|
1060
|
-
const selected = await selectNextWorkspaceTaskViaServer(context, filters);
|
|
2167
|
+
requireNoExtraArgs(remaining, "rig task next [--assignee <login|me|@me>] [--state open|closed] [--status <status>] [--limit <n>]");
|
|
2168
|
+
const selected = await withSpinner("Selecting next ready task\u2026", () => selectNextWorkspaceTaskViaServer(context, filters), { outputMode: context.outputMode });
|
|
1061
2169
|
if (context.outputMode === "text") {
|
|
1062
2170
|
if (selected.task) {
|
|
1063
|
-
|
|
2171
|
+
printFormattedOutput(formatTaskCard(summarizeTask(selected.task, { raw: true }), { title: "Selected task", selected: true }));
|
|
1064
2172
|
} else {
|
|
1065
|
-
|
|
2173
|
+
printFormattedOutput("No matching tasks.\n\nNext\n\u203A Try `rig task list` to inspect available work.\n\u203A Check server: `rig server status`");
|
|
1066
2174
|
}
|
|
1067
2175
|
}
|
|
1068
2176
|
return {
|
|
@@ -1078,31 +2186,31 @@ async function executeTask(context, args, options) {
|
|
|
1078
2186
|
}
|
|
1079
2187
|
case "info": {
|
|
1080
2188
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1081
|
-
requireNoExtraArgs(remaining, "
|
|
2189
|
+
requireNoExtraArgs(remaining, "rig task info [--task <task-id>]");
|
|
1082
2190
|
await withMutedConsole(context.outputMode === "json", () => taskInfo(context.projectRoot, task || undefined));
|
|
1083
2191
|
return { ok: true, group: "task", command, details: { task: task || null } };
|
|
1084
2192
|
}
|
|
1085
2193
|
case "scope": {
|
|
1086
2194
|
const filesFlag = takeFlag(rest, "--files");
|
|
1087
2195
|
const { value: task, rest: remaining } = takeOption(filesFlag.rest, "--task");
|
|
1088
|
-
requireNoExtraArgs(remaining, "
|
|
2196
|
+
requireNoExtraArgs(remaining, "rig task scope [--task <id>] [--files]");
|
|
1089
2197
|
await withMutedConsole(context.outputMode === "json", () => taskScope(context.projectRoot, filesFlag.value, task || undefined));
|
|
1090
2198
|
return { ok: true, group: "task", command, details: { files: filesFlag.value, task: task || null } };
|
|
1091
2199
|
}
|
|
1092
2200
|
case "deps":
|
|
1093
|
-
requireNoExtraArgs(rest, "
|
|
2201
|
+
requireNoExtraArgs(rest, "rig task deps");
|
|
1094
2202
|
await withMutedConsole(context.outputMode === "json", () => taskDeps(context.projectRoot));
|
|
1095
2203
|
return { ok: true, group: "task", command };
|
|
1096
2204
|
case "status":
|
|
1097
|
-
requireNoExtraArgs(rest, "
|
|
2205
|
+
requireNoExtraArgs(rest, "rig task status");
|
|
1098
2206
|
withMutedConsole(context.outputMode === "json", () => taskStatus2(context.projectRoot));
|
|
1099
2207
|
return { ok: true, group: "task", command };
|
|
1100
2208
|
case "artifacts":
|
|
1101
|
-
requireNoExtraArgs(rest, "
|
|
2209
|
+
requireNoExtraArgs(rest, "rig task artifacts");
|
|
1102
2210
|
withMutedConsole(context.outputMode === "json", () => taskArtifacts(context.projectRoot));
|
|
1103
2211
|
return { ok: true, group: "task", command };
|
|
1104
2212
|
case "artifact-dir": {
|
|
1105
|
-
requireNoExtraArgs(rest, "
|
|
2213
|
+
requireNoExtraArgs(rest, "rig task artifact-dir");
|
|
1106
2214
|
const path = taskArtifactDir(context.projectRoot);
|
|
1107
2215
|
if (context.outputMode === "text") {
|
|
1108
2216
|
console.log(path);
|
|
@@ -1111,7 +2219,7 @@ async function executeTask(context, args, options) {
|
|
|
1111
2219
|
}
|
|
1112
2220
|
case "artifact-write": {
|
|
1113
2221
|
if (rest.length < 1) {
|
|
1114
|
-
throw new
|
|
2222
|
+
throw new CliError(`Usage: rig task artifact-write <filename> [--file <path>]
|
|
1115
2223
|
` + ` Reads content from stdin (or --file), writes to the active task artifact dir.
|
|
1116
2224
|
` + " Example: echo '...' | rig task artifact-write collection-audit.md");
|
|
1117
2225
|
}
|
|
@@ -1119,12 +2227,12 @@ async function executeTask(context, args, options) {
|
|
|
1119
2227
|
const fileFlag = takeOption(rest.slice(1), "--file");
|
|
1120
2228
|
let content;
|
|
1121
2229
|
if (fileFlag.value) {
|
|
1122
|
-
content =
|
|
2230
|
+
content = readFileSync3(resolve3(context.projectRoot, fileFlag.value), "utf-8");
|
|
1123
2231
|
} else {
|
|
1124
2232
|
content = await readStdin();
|
|
1125
2233
|
}
|
|
1126
2234
|
if (!artifactFilename) {
|
|
1127
|
-
throw new
|
|
2235
|
+
throw new CliError("Usage: rig task artifact-write <filename> [--file path]");
|
|
1128
2236
|
}
|
|
1129
2237
|
withMutedConsole(context.outputMode === "json", () => taskArtifactWrite(context.projectRoot, artifactFilename, content));
|
|
1130
2238
|
return { ok: true, group: "task", command, details: { filename: artifactFilename } };
|
|
@@ -1133,11 +2241,11 @@ async function executeTask(context, args, options) {
|
|
|
1133
2241
|
return options.executeTaskReportBug(context, rest);
|
|
1134
2242
|
case "lookup": {
|
|
1135
2243
|
if (rest.length !== 1) {
|
|
1136
|
-
throw new
|
|
2244
|
+
throw new CliError("Usage: rig task lookup <task-id>");
|
|
1137
2245
|
}
|
|
1138
2246
|
const lookupId = rest[0];
|
|
1139
2247
|
if (!lookupId) {
|
|
1140
|
-
throw new
|
|
2248
|
+
throw new CliError("Usage: rig task lookup <task-id>");
|
|
1141
2249
|
}
|
|
1142
2250
|
const result = taskLookup(context.projectRoot, lookupId);
|
|
1143
2251
|
if (context.outputMode === "text") {
|
|
@@ -1147,17 +2255,17 @@ async function executeTask(context, args, options) {
|
|
|
1147
2255
|
}
|
|
1148
2256
|
case "record": {
|
|
1149
2257
|
if (rest.length < 2) {
|
|
1150
|
-
throw new
|
|
2258
|
+
throw new CliError("Usage: rig task record <decision|failure> <text>");
|
|
1151
2259
|
}
|
|
1152
2260
|
const type = rest[0];
|
|
1153
2261
|
if (type !== "decision" && type !== "failure") {
|
|
1154
|
-
throw new
|
|
2262
|
+
throw new CliError("Usage: rig task record <decision|failure> <text>");
|
|
1155
2263
|
}
|
|
1156
2264
|
withMutedConsole(context.outputMode === "json", () => taskRecord(context.projectRoot, type, rest.slice(1).join(" ")));
|
|
1157
2265
|
return { ok: true, group: "task", command, details: { type: rest[0] } };
|
|
1158
2266
|
}
|
|
1159
2267
|
case "ready":
|
|
1160
|
-
requireNoExtraArgs(rest, "
|
|
2268
|
+
requireNoExtraArgs(rest, "rig task ready");
|
|
1161
2269
|
await withMutedConsole(context.outputMode === "json", () => taskReady(context.projectRoot));
|
|
1162
2270
|
return { ok: true, group: "task", command };
|
|
1163
2271
|
case "run": {
|
|
@@ -1194,47 +2302,47 @@ async function executeTask(context, args, options) {
|
|
|
1194
2302
|
if (positionalTaskId) {
|
|
1195
2303
|
pending = pending.slice(1);
|
|
1196
2304
|
}
|
|
1197
|
-
requireNoExtraArgs(pending, "
|
|
2305
|
+
requireNoExtraArgs(pending, "rig task run [#<issue>|<task-id>] [--next] [--task <id>] [--detach] [--assignee <login|me|@me>] [--state open|closed] [--status <status>] [--limit <n>] [--title <text>] [--runtime-adapter claude-code|codex|pi] [--model <model>] [--runtime-mode <mode>] [--interaction-mode <mode>] [--initial-prompt <text>] [--pr auto|ask|off] [--no-pr] [--dirty-baseline head|dirty-snapshot] [--skip-project-sync]");
|
|
1198
2306
|
if (nextResult.value && (taskResult.value || positionalTaskId)) {
|
|
1199
|
-
throw new
|
|
2307
|
+
throw new CliError("task run cannot combine --next with an explicit task id.", 2, { hint: "Use either `rig task run --next` or `rig task run <id>`." });
|
|
1200
2308
|
}
|
|
1201
2309
|
if (taskResult.value && positionalTaskId) {
|
|
1202
|
-
throw new
|
|
2310
|
+
throw new CliError("task run cannot combine positional task id with --task <id>.", 2, { hint: "Pass the id once, e.g. `rig task run <id>`." });
|
|
1203
2311
|
}
|
|
1204
2312
|
if (prResult.value && noPrResult.value) {
|
|
1205
|
-
throw new
|
|
2313
|
+
throw new CliError("task run cannot combine --pr with --no-pr.", 2, { hint: "Use `--pr auto|ask|off` or `--no-pr`, not both." });
|
|
1206
2314
|
}
|
|
1207
2315
|
let selectedTask = null;
|
|
1208
2316
|
let selectedTaskId = normalizeTaskRunTaskId(taskResult.value) ?? positionalTaskId;
|
|
1209
2317
|
if (nextResult.value) {
|
|
1210
|
-
const selected = await selectNextWorkspaceTaskViaServer(context, filterResult.filters);
|
|
2318
|
+
const selected = await withSpinner("Selecting next ready task\u2026", () => selectNextWorkspaceTaskViaServer(context, filterResult.filters), { outputMode: context.outputMode });
|
|
1211
2319
|
selectedTask = selected.task;
|
|
1212
2320
|
selectedTaskId = selected.task ? readTaskId(selected.task) : null;
|
|
1213
2321
|
if (!selectedTaskId) {
|
|
1214
|
-
throw new
|
|
2322
|
+
throw new CliError("No matching task found for task run --next.", 3, { hint: "Run `rig task list` to inspect available work, or relax the filters." });
|
|
1215
2323
|
}
|
|
1216
2324
|
}
|
|
1217
2325
|
if (!selectedTaskId && !initialPromptResult.value && !titleResult.value) {
|
|
1218
2326
|
if (context.outputMode !== "text" || !process.stdin.isTTY || !process.stdout.isTTY) {
|
|
1219
|
-
throw new
|
|
2327
|
+
throw new CliError("task run requires an interactive terminal to pick a task; pass --next, --task <id>, or --initial-prompt/--title for an ad hoc run.", 2);
|
|
1220
2328
|
}
|
|
1221
|
-
const tasks = await listWorkspaceTasksViaServer(context, filterResult.filters);
|
|
2329
|
+
const tasks = await withSpinner("Reading tasks from server\u2026", () => listWorkspaceTasksViaServer(context, filterResult.filters), { outputMode: context.outputMode });
|
|
1222
2330
|
selectedTask = await selectTaskWithTextPicker(tasks);
|
|
1223
2331
|
selectedTaskId = selectedTask ? readTaskId(selectedTask) : null;
|
|
1224
2332
|
if (!selectedTaskId) {
|
|
1225
|
-
throw new
|
|
2333
|
+
throw new CliError("No task selected.", 3, { hint: "Run `rig task run --next` for the next ready task, or `rig task run --task <id>`." });
|
|
1226
2334
|
}
|
|
1227
2335
|
}
|
|
1228
2336
|
await runProjectMainSyncPreflight(context, { disabled: skipProjectSyncResult.value });
|
|
1229
2337
|
const projectDefaults = await loadTaskRunProjectDefaults(context.projectRoot);
|
|
1230
2338
|
const runtimeAdapter = normalizeRuntimeAdapter(runtimeAdapterResult.value ?? projectDefaults.runtimeAdapter);
|
|
1231
|
-
await runFastTaskRunPreflight(context, {
|
|
2339
|
+
await withSpinner("Running task-run preflight\u2026", () => runFastTaskRunPreflight(context, {
|
|
1232
2340
|
taskId: selectedTaskId,
|
|
1233
2341
|
runtimeAdapter
|
|
1234
|
-
});
|
|
2342
|
+
}), { outputMode: context.outputMode });
|
|
1235
2343
|
const dirtyBaseline = await resolveDirtyBaselineForTaskRun(context, dirtyBaselineResult.value);
|
|
1236
2344
|
const prMode = noPrResult.value ? "off" : normalizePrMode(prResult.value) ?? projectDefaults.prMode;
|
|
1237
|
-
const submitted = await submitTaskRunViaServer(context, {
|
|
2345
|
+
const submitted = await withSpinner("Dispatching run\u2026", () => submitTaskRunViaServer(context, {
|
|
1238
2346
|
runId: context.runId,
|
|
1239
2347
|
taskId: selectedTaskId ?? undefined,
|
|
1240
2348
|
title: titleResult.value ?? undefined,
|
|
@@ -1245,19 +2353,27 @@ async function executeTask(context, args, options) {
|
|
|
1245
2353
|
initialPrompt: initialPromptResult.value ?? undefined,
|
|
1246
2354
|
baselineMode: dirtyBaseline.mode,
|
|
1247
2355
|
prMode
|
|
1248
|
-
});
|
|
2356
|
+
}), { outputMode: context.outputMode });
|
|
1249
2357
|
let attachDetails = null;
|
|
1250
2358
|
if (!detachResult.value && context.outputMode === "text") {
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
2359
|
+
printFormattedOutput(formatSubmittedRun({
|
|
2360
|
+
runId: submitted.runId,
|
|
2361
|
+
task: selectedTask ? summarizeTask(selectedTask) : null,
|
|
2362
|
+
runtimeAdapter,
|
|
2363
|
+
runtimeMode: runtimeModeResult.value || projectDefaults.runtimeMode || "full-access",
|
|
2364
|
+
interactionMode: interactionModeResult.value || "default",
|
|
2365
|
+
detached: false
|
|
2366
|
+
}));
|
|
1255
2367
|
attachDetails = await attachRunOperatorView(context, { runId: submitted.runId, follow: true });
|
|
1256
2368
|
} else if (context.outputMode === "text") {
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
2369
|
+
printFormattedOutput(formatSubmittedRun({
|
|
2370
|
+
runId: submitted.runId,
|
|
2371
|
+
task: selectedTask ? summarizeTask(selectedTask) : null,
|
|
2372
|
+
runtimeAdapter,
|
|
2373
|
+
runtimeMode: runtimeModeResult.value || projectDefaults.runtimeMode || "full-access",
|
|
2374
|
+
interactionMode: interactionModeResult.value || "default",
|
|
2375
|
+
detached: true
|
|
2376
|
+
}));
|
|
1261
2377
|
}
|
|
1262
2378
|
return {
|
|
1263
2379
|
ok: true,
|
|
@@ -1281,41 +2397,34 @@ async function executeTask(context, args, options) {
|
|
|
1281
2397
|
}
|
|
1282
2398
|
case "validate": {
|
|
1283
2399
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1284
|
-
requireNoExtraArgs(remaining, "
|
|
2400
|
+
requireNoExtraArgs(remaining, "rig task validate [--task <task-id>]");
|
|
1285
2401
|
if (context.dryRun) {
|
|
1286
2402
|
await context.runCommand(["rig", "task", "validate", ...task ? ["--task", task] : []]);
|
|
1287
2403
|
return { ok: true, group: "task", command, details: { task: task || "active" } };
|
|
1288
2404
|
}
|
|
1289
2405
|
const ok = await withMutedConsole(context.outputMode === "json", async () => taskValidate(context.projectRoot, task || undefined, await validatorRegistryForTaskCommands(context.projectRoot)));
|
|
1290
2406
|
if (!ok) {
|
|
1291
|
-
throw new
|
|
2407
|
+
throw new CliError(`Validation failed for ${task || "active task"}.`, 2, { hint: "Inspect failures with `rig inspect failures --task <id>`, fix, then re-run `rig task validate --task <id>`." });
|
|
1292
2408
|
}
|
|
1293
2409
|
return { ok: true, group: "task", command, details: { task: task || "active" } };
|
|
1294
2410
|
}
|
|
1295
2411
|
case "verify": {
|
|
1296
2412
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1297
|
-
requireNoExtraArgs(remaining, "
|
|
2413
|
+
requireNoExtraArgs(remaining, "rig task verify [--task <task-id>]");
|
|
1298
2414
|
if (context.dryRun) {
|
|
1299
2415
|
await context.runCommand(["rig", "task", "verify", ...task ? ["--task", task] : []]);
|
|
1300
2416
|
return { ok: true, group: "task", command, details: { task: task || "active" } };
|
|
1301
2417
|
}
|
|
1302
|
-
const ok = await withMutedConsole(context.outputMode === "json", () => taskVerify(context.projectRoot,
|
|
2418
|
+
const ok = await withMutedConsole(context.outputMode === "json", () => taskVerify(context.projectRoot, task || undefined));
|
|
1303
2419
|
if (!ok) {
|
|
1304
|
-
throw new
|
|
2420
|
+
throw new CliError(`Verification rejected for ${task || "active task"}.`, 2, { hint: "Check `rig inspect logs --task <id>`, address the rejection, then re-run `rig task verify --task <id>`." });
|
|
1305
2421
|
}
|
|
1306
2422
|
return { ok: true, group: "task", command, details: { task: task || "active" } };
|
|
1307
2423
|
}
|
|
1308
|
-
case "reset": {
|
|
1309
|
-
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1310
|
-
requireNoExtraArgs(remaining, "bun run rig task reset --task <beads-id>");
|
|
1311
|
-
const requiredTask = requireTask(task, "bun run rig task reset --task <beads-id>");
|
|
1312
|
-
await context.runCommand(["br", "--no-db", "update", requiredTask, "--status", "open"]);
|
|
1313
|
-
return { ok: true, group: "task", command, details: { task: requiredTask } };
|
|
1314
|
-
}
|
|
1315
2424
|
case "details": {
|
|
1316
2425
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1317
|
-
requireNoExtraArgs(remaining, "
|
|
1318
|
-
const requiredTask = requireTask(task, "
|
|
2426
|
+
requireNoExtraArgs(remaining, "rig task details --task <task-id>");
|
|
2427
|
+
const requiredTask = requireTask(task, "rig task details --task <task-id>");
|
|
1319
2428
|
await withMutedConsole(context.outputMode === "json", () => taskInfo(context.projectRoot, requiredTask));
|
|
1320
2429
|
return { ok: true, group: "task", command, details: { task: requiredTask } };
|
|
1321
2430
|
}
|
|
@@ -1323,9 +2432,9 @@ async function executeTask(context, args, options) {
|
|
|
1323
2432
|
const { value: task, rest: rest1 } = takeOption(rest, "--task");
|
|
1324
2433
|
const allFlag = takeFlag(rest1, "--all");
|
|
1325
2434
|
const { rest: remaining } = takeOption(allFlag.rest, "--reason");
|
|
1326
|
-
requireNoExtraArgs(remaining, "
|
|
2435
|
+
requireNoExtraArgs(remaining, "rig task reopen [--task <id> | --all] [--reason <text>]");
|
|
1327
2436
|
if (!allFlag.value && !task) {
|
|
1328
|
-
throw new
|
|
2437
|
+
throw new CliError("Usage: rig task reopen [--task <id> | --all] [--reason <text>]");
|
|
1329
2438
|
}
|
|
1330
2439
|
const summary = withMutedConsole(context.outputMode === "json", () => taskReopen(context.projectRoot, {
|
|
1331
2440
|
all: allFlag.value,
|
|
@@ -1335,7 +2444,10 @@ async function executeTask(context, args, options) {
|
|
|
1335
2444
|
return { ok: true, group: "task", command, details: summary };
|
|
1336
2445
|
}
|
|
1337
2446
|
default:
|
|
1338
|
-
|
|
2447
|
+
if (command === "reset") {
|
|
2448
|
+
throw new CliError("Unknown task command: reset", 1, { hint: "Use `rig task reopen --task <id>`." });
|
|
2449
|
+
}
|
|
2450
|
+
throw new CliError(`Unknown task command: ${command}`, 1, { hint: "Run `rig task --help` to list available task commands." });
|
|
1339
2451
|
}
|
|
1340
2452
|
}
|
|
1341
2453
|
export {
|