@h-rig/cli 0.0.6-alpha.4 → 0.0.6-alpha.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/rig.js +3905 -1193
- package/dist/src/commands/_cli-format.js +369 -0
- package/dist/src/commands/_connection-state.js +1 -3
- package/dist/src/commands/_doctor-checks.js +13 -27
- package/dist/src/commands/_help-catalog.js +445 -0
- package/dist/src/commands/_operator-surface.js +220 -0
- package/dist/src/commands/_operator-view.js +916 -56
- package/dist/src/commands/_parsers.js +0 -2
- package/dist/src/commands/_pi-frontend.js +880 -0
- package/dist/src/commands/_pi-install.js +4 -3
- package/dist/src/commands/_pi-remote-session.js +665 -0
- package/dist/src/commands/_pi-worker-bridge-extension.js +676 -0
- package/dist/src/commands/_policy.js +0 -2
- package/dist/src/commands/_preflight.js +32 -109
- package/dist/src/commands/_run-driver-helpers.js +2 -2
- package/dist/src/commands/_server-client.js +152 -31
- package/dist/src/commands/_snapshot-upload.js +8 -23
- package/dist/src/commands/_task-picker.js +44 -16
- package/dist/src/commands/agent.js +8 -9
- package/dist/src/commands/browser.js +4 -6
- package/dist/src/commands/connect.js +132 -25
- package/dist/src/commands/dist.js +4 -6
- package/dist/src/commands/doctor.js +13 -27
- package/dist/src/commands/github.js +10 -25
- package/dist/src/commands/inbox.js +351 -31
- package/dist/src/commands/init.js +298 -71
- package/dist/src/commands/inspect.js +237 -23
- package/dist/src/commands/inspector.js +2 -4
- package/dist/src/commands/pi.js +168 -0
- package/dist/src/commands/plugin.js +81 -22
- package/dist/src/commands/profile-and-review.js +8 -10
- package/dist/src/commands/queue.js +2 -3
- package/dist/src/commands/remote.js +18 -20
- package/dist/src/commands/repo-git-harness.js +6 -8
- package/dist/src/commands/run.js +1214 -123
- package/dist/src/commands/server.js +222 -33
- package/dist/src/commands/setup.js +17 -37
- package/dist/src/commands/task-report-bug.js +5 -7
- package/dist/src/commands/task-run-driver.js +630 -71
- package/dist/src/commands/task.js +1653 -252
- package/dist/src/commands/test.js +3 -5
- package/dist/src/commands/workspace.js +4 -6
- package/dist/src/commands.js +3884 -1166
- package/dist/src/index.js +3898 -1189
- package/dist/src/launcher.js +5 -3
- package/dist/src/report-bug.js +3 -3
- package/dist/src/runner.js +5 -19
- package/package.json +6 -4
|
@@ -1,16 +1,14 @@
|
|
|
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
10
|
import { CliError } 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
|
import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
|
|
16
14
|
function takeFlag(args, flag) {
|
|
@@ -182,17 +180,16 @@ function resolveSelectedConnection(projectRoot, options = {}) {
|
|
|
182
180
|
const global = readGlobalConnections(options);
|
|
183
181
|
const connection = global.connections[repo.selected];
|
|
184
182
|
if (!connection) {
|
|
185
|
-
throw new CliError2(`Selected Rig
|
|
183
|
+
throw new CliError2(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
186
184
|
}
|
|
187
185
|
return { alias: repo.selected, connection };
|
|
188
186
|
}
|
|
189
187
|
|
|
190
188
|
// packages/cli/src/commands/_server-client.ts
|
|
191
|
-
import { spawnSync } from "child_process";
|
|
192
189
|
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
193
190
|
import { resolve as resolve2 } from "path";
|
|
194
191
|
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
195
|
-
var
|
|
192
|
+
var scopedGitHubBearerTokens = new Map;
|
|
196
193
|
function cleanToken(value) {
|
|
197
194
|
const trimmed = value?.trim();
|
|
198
195
|
return trimmed ? trimmed : null;
|
|
@@ -209,25 +206,13 @@ function readPrivateRemoteSessionToken(projectRoot) {
|
|
|
209
206
|
}
|
|
210
207
|
}
|
|
211
208
|
function readGitHubBearerTokenForRemote(projectRoot) {
|
|
212
|
-
|
|
213
|
-
|
|
209
|
+
const scopedKey = resolve2(projectRoot);
|
|
210
|
+
if (scopedGitHubBearerTokens.has(scopedKey))
|
|
211
|
+
return scopedGitHubBearerTokens.get(scopedKey) ?? null;
|
|
214
212
|
const privateSession = readPrivateRemoteSessionToken(projectRoot);
|
|
215
|
-
if (privateSession)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
const envToken = cleanToken(process.env.RIG_GITHUB_TOKEN) ?? cleanToken(process.env.GITHUB_TOKEN) ?? cleanToken(process.env.GH_TOKEN);
|
|
220
|
-
if (envToken) {
|
|
221
|
-
cachedGitHubBearerToken = envToken;
|
|
222
|
-
return cachedGitHubBearerToken;
|
|
223
|
-
}
|
|
224
|
-
const result = spawnSync("gh", ["auth", "token"], {
|
|
225
|
-
encoding: "utf8",
|
|
226
|
-
timeout: 5000,
|
|
227
|
-
stdio: ["ignore", "pipe", "ignore"]
|
|
228
|
-
});
|
|
229
|
-
cachedGitHubBearerToken = result.status === 0 ? cleanToken(result.stdout) : null;
|
|
230
|
-
return cachedGitHubBearerToken;
|
|
213
|
+
if (privateSession)
|
|
214
|
+
return privateSession;
|
|
215
|
+
return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
231
216
|
}
|
|
232
217
|
async function ensureServerForCli(projectRoot) {
|
|
233
218
|
try {
|
|
@@ -347,6 +332,15 @@ async function getRunLogsViaServer(context, runId, options = {}) {
|
|
|
347
332
|
const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
|
|
348
333
|
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { entries: [] };
|
|
349
334
|
}
|
|
335
|
+
async function getRunTimelineViaServer(context, runId, options = {}) {
|
|
336
|
+
const url = new URL(`http://rig.local/api/runs/${encodeURIComponent(runId)}/timeline`);
|
|
337
|
+
if (options.limit !== undefined)
|
|
338
|
+
url.searchParams.set("limit", String(options.limit));
|
|
339
|
+
if (options.cursor)
|
|
340
|
+
url.searchParams.set("cursor", options.cursor);
|
|
341
|
+
const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
|
|
342
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { entries: [] };
|
|
343
|
+
}
|
|
350
344
|
async function stopRunViaServer(context, runId) {
|
|
351
345
|
const payload = await requestServerJson(context, "/api/runs/stop", {
|
|
352
346
|
method: "POST",
|
|
@@ -363,6 +357,66 @@ async function steerRunViaServer(context, runId, message) {
|
|
|
363
357
|
});
|
|
364
358
|
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { ok: true };
|
|
365
359
|
}
|
|
360
|
+
async function getRunPiSessionViaServer(context, runId) {
|
|
361
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi`);
|
|
362
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
363
|
+
}
|
|
364
|
+
async function getRunPiMessagesViaServer(context, runId) {
|
|
365
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/messages`);
|
|
366
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { messages: [] };
|
|
367
|
+
}
|
|
368
|
+
async function getRunPiStatusViaServer(context, runId) {
|
|
369
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/status`);
|
|
370
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
371
|
+
}
|
|
372
|
+
async function getRunPiCommandsViaServer(context, runId) {
|
|
373
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/commands`);
|
|
374
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { commands: [] };
|
|
375
|
+
}
|
|
376
|
+
async function sendRunPiPromptViaServer(context, runId, text, streamingBehavior) {
|
|
377
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/prompt`, {
|
|
378
|
+
method: "POST",
|
|
379
|
+
headers: { "content-type": "application/json" },
|
|
380
|
+
body: JSON.stringify({ text, streamingBehavior })
|
|
381
|
+
});
|
|
382
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
|
|
383
|
+
}
|
|
384
|
+
async function sendRunPiShellViaServer(context, runId, text) {
|
|
385
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/shell`, {
|
|
386
|
+
method: "POST",
|
|
387
|
+
headers: { "content-type": "application/json" },
|
|
388
|
+
body: JSON.stringify({ text })
|
|
389
|
+
});
|
|
390
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
|
|
391
|
+
}
|
|
392
|
+
async function runRunPiCommandViaServer(context, runId, text) {
|
|
393
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/commands/run`, {
|
|
394
|
+
method: "POST",
|
|
395
|
+
headers: { "content-type": "application/json" },
|
|
396
|
+
body: JSON.stringify({ text })
|
|
397
|
+
});
|
|
398
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { type: "done" };
|
|
399
|
+
}
|
|
400
|
+
async function respondRunPiExtensionUiViaServer(context, runId, requestId, valueOrCancel) {
|
|
401
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/extension-ui/respond`, {
|
|
402
|
+
method: "POST",
|
|
403
|
+
headers: { "content-type": "application/json" },
|
|
404
|
+
body: JSON.stringify({ requestId, ...valueOrCancel })
|
|
405
|
+
});
|
|
406
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
|
|
407
|
+
}
|
|
408
|
+
async function abortRunPiViaServer(context, runId) {
|
|
409
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/abort`, { method: "POST" });
|
|
410
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { aborted: true };
|
|
411
|
+
}
|
|
412
|
+
async function buildRunPiEventsWebSocketUrl(context, runId) {
|
|
413
|
+
const server = await ensureServerForCli(context.projectRoot);
|
|
414
|
+
const url = new URL(`${server.baseUrl.replace(/\/+$/, "")}/api/runs/${encodeURIComponent(runId)}/pi/events`);
|
|
415
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
416
|
+
if (server.authToken)
|
|
417
|
+
url.searchParams.set("token", server.authToken);
|
|
418
|
+
return url.toString();
|
|
419
|
+
}
|
|
366
420
|
async function submitTaskRunViaServer(context, input) {
|
|
367
421
|
const isTaskRun = Boolean(input.taskId);
|
|
368
422
|
const endpoint = isTaskRun ? "/api/runs/task" : "/api/runs/adhoc";
|
|
@@ -395,78 +449,6 @@ async function submitTaskRunViaServer(context, input) {
|
|
|
395
449
|
return { runId };
|
|
396
450
|
}
|
|
397
451
|
|
|
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
452
|
// packages/cli/src/commands/_preflight.ts
|
|
471
453
|
function preflightCheck(id, label, status, detail, remediation) {
|
|
472
454
|
return {
|
|
@@ -522,6 +504,9 @@ function permissionAllowsPr(payload) {
|
|
|
522
504
|
}
|
|
523
505
|
return null;
|
|
524
506
|
}
|
|
507
|
+
function isNotFoundError(error) {
|
|
508
|
+
return /\b(404|not found)\b/i.test(message(error));
|
|
509
|
+
}
|
|
525
510
|
function projectCheckoutReady(payload) {
|
|
526
511
|
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
527
512
|
return null;
|
|
@@ -554,19 +539,33 @@ async function runFastTaskRunPreflight(context, options = {}) {
|
|
|
554
539
|
const checks = [];
|
|
555
540
|
const request = options.requestJson ?? ((pathname, init) => requestServerJson(context, pathname, init));
|
|
556
541
|
const taskId = options.taskId?.trim() || null;
|
|
542
|
+
const requiresCurrentRunApi = Boolean(taskId);
|
|
543
|
+
const selectedServer = options.requestJson ? null : await ensureServerForCli(context.projectRoot).catch(() => null);
|
|
544
|
+
const allowLocalLegacyTaskRunCompatibility = selectedServer?.connectionKind === "local";
|
|
545
|
+
let legacyServerCompatibility = false;
|
|
557
546
|
try {
|
|
558
547
|
await request("/api/server/status");
|
|
559
548
|
checks.push(preflightCheck("server", "Rig server reachable", "pass"));
|
|
560
549
|
} catch (error) {
|
|
561
|
-
|
|
550
|
+
if (isNotFoundError(error)) {
|
|
551
|
+
try {
|
|
552
|
+
await request("/health");
|
|
553
|
+
legacyServerCompatibility = !requiresCurrentRunApi || allowLocalLegacyTaskRunCompatibility;
|
|
554
|
+
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"));
|
|
555
|
+
} catch (healthError) {
|
|
556
|
+
checks.push(preflightCheck("server", "Rig server reachable", "fail", message(healthError), "Start or select a reachable Rig server."));
|
|
557
|
+
}
|
|
558
|
+
} else {
|
|
559
|
+
checks.push(preflightCheck("server", "Rig server reachable", "fail", message(error), "Start or select a reachable Rig server."));
|
|
560
|
+
}
|
|
562
561
|
}
|
|
563
562
|
const repo = readRepoConnection(context.projectRoot);
|
|
564
|
-
checks.push(repo ? preflightCheck("project-link", "project linked to Rig
|
|
563
|
+
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
564
|
try {
|
|
566
565
|
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>`."));
|
|
566
|
+
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
567
|
} catch (error) {
|
|
569
|
-
checks.push(preflightCheck("github-auth", "GitHub auth valid", "fail", message(error), "Fix GitHub auth on the selected Rig server."));
|
|
568
|
+
checks.push(preflightCheck("github-auth", "GitHub auth valid", legacyServerCompatibility ? "warn" : "fail", message(error), "Fix GitHub auth on the selected Rig server."));
|
|
570
569
|
}
|
|
571
570
|
try {
|
|
572
571
|
const projection = await request("/api/workspace/task-projection");
|
|
@@ -594,9 +593,9 @@ async function runFastTaskRunPreflight(context, options = {}) {
|
|
|
594
593
|
try {
|
|
595
594
|
const tasks = await request(`/api/workspace/tasks?limit=200&refresh=1`);
|
|
596
595
|
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."));
|
|
596
|
+
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
597
|
} catch (error) {
|
|
599
|
-
checks.push(preflightCheck("issue", "task/issue accessible", "fail", message(error), "Fix the task source before launching a run."));
|
|
598
|
+
checks.push(preflightCheck("issue", "task/issue accessible", legacyServerCompatibility ? "warn" : "fail", message(error), "Fix the task source before launching a run."));
|
|
600
599
|
}
|
|
601
600
|
try {
|
|
602
601
|
const runs = await request("/api/runs?limit=200");
|
|
@@ -607,14 +606,7 @@ async function runFastTaskRunPreflight(context, options = {}) {
|
|
|
607
606
|
}
|
|
608
607
|
}
|
|
609
608
|
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
|
-
}
|
|
609
|
+
checks.push(preflightCheck("runtime", "worker Pi SDK session daemon", "pass", selectedServer?.connectionKind === "remote" ? "remote worker-owned runtime" : "bundled server-owned runtime"));
|
|
618
610
|
} else {
|
|
619
611
|
checks.push(preflightCheck("runtime", "runtime adapter", "pass", options.runtimeAdapter));
|
|
620
612
|
}
|
|
@@ -706,7 +698,200 @@ function withMutedConsole(mute, fn) {
|
|
|
706
698
|
}
|
|
707
699
|
|
|
708
700
|
// packages/cli/src/commands/_task-picker.ts
|
|
709
|
-
import {
|
|
701
|
+
import { cancel, isCancel, select } from "@clack/prompts";
|
|
702
|
+
|
|
703
|
+
// packages/cli/src/commands/_operator-surface.ts
|
|
704
|
+
import { createInterface } from "readline";
|
|
705
|
+
import { createInterface as createPromptInterface } from "readline/promises";
|
|
706
|
+
var CANONICAL_STAGES = [
|
|
707
|
+
"Connect",
|
|
708
|
+
"GitHub/task sync",
|
|
709
|
+
"Prepare workspace",
|
|
710
|
+
"Launch Pi",
|
|
711
|
+
"Plan",
|
|
712
|
+
"Implement",
|
|
713
|
+
"Validate",
|
|
714
|
+
"Commit",
|
|
715
|
+
"Open PR",
|
|
716
|
+
"Review/CI",
|
|
717
|
+
"Merge",
|
|
718
|
+
"Complete"
|
|
719
|
+
];
|
|
720
|
+
function logDetail(log) {
|
|
721
|
+
return typeof log.detail === "string" ? log.detail.trim() : "";
|
|
722
|
+
}
|
|
723
|
+
function parseProviderProtocolLog(title, detail) {
|
|
724
|
+
if (title.trim().toLowerCase() !== "agent output")
|
|
725
|
+
return null;
|
|
726
|
+
if (!detail.startsWith("{") || !detail.endsWith("}"))
|
|
727
|
+
return null;
|
|
728
|
+
try {
|
|
729
|
+
const record = JSON.parse(detail);
|
|
730
|
+
if (!record || typeof record !== "object" || Array.isArray(record))
|
|
731
|
+
return null;
|
|
732
|
+
const type = record.type;
|
|
733
|
+
return typeof type === "string" && [
|
|
734
|
+
"assistant",
|
|
735
|
+
"message_start",
|
|
736
|
+
"message_update",
|
|
737
|
+
"message_end",
|
|
738
|
+
"stream_event",
|
|
739
|
+
"tool_result",
|
|
740
|
+
"tool_execution_start",
|
|
741
|
+
"tool_execution_update",
|
|
742
|
+
"tool_execution_end",
|
|
743
|
+
"turn_start",
|
|
744
|
+
"turn_end"
|
|
745
|
+
].includes(type) ? record : null;
|
|
746
|
+
} catch {
|
|
747
|
+
return null;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
function renderProviderProtocolLog(record) {
|
|
751
|
+
const type = typeof record.type === "string" ? record.type : "";
|
|
752
|
+
if (type === "tool_execution_start" || type === "tool_execution_update" || type === "tool_execution_end") {
|
|
753
|
+
const toolName = String(record.toolName ?? record.name ?? "tool");
|
|
754
|
+
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";
|
|
755
|
+
return `[Pi tool] ${toolName} ${status}`;
|
|
756
|
+
}
|
|
757
|
+
return null;
|
|
758
|
+
}
|
|
759
|
+
function entryId(entry, fallback) {
|
|
760
|
+
return typeof entry.id === "string" && entry.id.trim() ? entry.id : fallback;
|
|
761
|
+
}
|
|
762
|
+
function renderOperatorSnapshot(snapshot) {
|
|
763
|
+
const run = snapshot.run.run && typeof snapshot.run.run === "object" ? snapshot.run.run : snapshot.run;
|
|
764
|
+
const runId = String(run.runId ?? run.id ?? "run");
|
|
765
|
+
const status = String(run.status ?? "unknown");
|
|
766
|
+
const logs = snapshot.logs ?? [];
|
|
767
|
+
const latestByStage = new Map;
|
|
768
|
+
for (const log of logs) {
|
|
769
|
+
const title = String(log.title ?? "").toLowerCase();
|
|
770
|
+
const stageName = String(log.stage ?? "").toLowerCase();
|
|
771
|
+
const stage = CANONICAL_STAGES.find((candidate) => candidate.toLowerCase() === title || candidate.toLowerCase() === stageName);
|
|
772
|
+
if (stage)
|
|
773
|
+
latestByStage.set(stage, log);
|
|
774
|
+
}
|
|
775
|
+
const stageLines = CANONICAL_STAGES.flatMap((stage) => {
|
|
776
|
+
const match = latestByStage.get(stage);
|
|
777
|
+
return match ? [`${stage}: ${String(match.status ?? status)}${logDetail(match) ? ` \u2014 ${logDetail(match)}` : ""}`] : [];
|
|
778
|
+
});
|
|
779
|
+
return [`Rig run ${runId}: ${status}`, ...stageLines].join(`
|
|
780
|
+
`);
|
|
781
|
+
}
|
|
782
|
+
function createPiRunStreamRenderer(output = process.stdout) {
|
|
783
|
+
let lastSnapshot = "";
|
|
784
|
+
const assistantTextById = new Map;
|
|
785
|
+
const seenTimeline = new Set;
|
|
786
|
+
const seenLogs = new Set;
|
|
787
|
+
const writeLine = (line) => output.write(`${line}
|
|
788
|
+
`);
|
|
789
|
+
return {
|
|
790
|
+
renderSnapshot(snapshot) {
|
|
791
|
+
const rendered = renderOperatorSnapshot(snapshot);
|
|
792
|
+
if (rendered && rendered !== lastSnapshot) {
|
|
793
|
+
writeLine(rendered);
|
|
794
|
+
lastSnapshot = rendered;
|
|
795
|
+
}
|
|
796
|
+
},
|
|
797
|
+
renderTimeline(entries) {
|
|
798
|
+
for (const [index, entry] of entries.entries()) {
|
|
799
|
+
const id = entryId(entry, `timeline:${index}:${String(entry.cursor ?? "")}`);
|
|
800
|
+
if (entry.type === "assistant_message" && typeof entry.text === "string") {
|
|
801
|
+
const text = entry.text;
|
|
802
|
+
const previousText = assistantTextById.get(id) ?? "";
|
|
803
|
+
if (!previousText && text.trim()) {
|
|
804
|
+
writeLine("[Pi assistant]");
|
|
805
|
+
}
|
|
806
|
+
if (text.startsWith(previousText)) {
|
|
807
|
+
const delta = text.slice(previousText.length);
|
|
808
|
+
if (delta)
|
|
809
|
+
output.write(delta);
|
|
810
|
+
} else if (text.trim() && text !== previousText) {
|
|
811
|
+
if (previousText)
|
|
812
|
+
writeLine(`
|
|
813
|
+
[Pi assistant]`);
|
|
814
|
+
output.write(text);
|
|
815
|
+
}
|
|
816
|
+
assistantTextById.set(id, text);
|
|
817
|
+
continue;
|
|
818
|
+
}
|
|
819
|
+
if (seenTimeline.has(id))
|
|
820
|
+
continue;
|
|
821
|
+
seenTimeline.add(id);
|
|
822
|
+
if (entry.type === "tool_execution_start" || entry.type === "tool_execution_update" || entry.type === "tool_execution_end" || entry.type === "mcp_tool_call") {
|
|
823
|
+
writeLine(`[Pi tool] ${String(entry.toolName ?? entry.name ?? entry.title ?? entry.type)} ${String(entry.status ?? entry.state ?? "")}`.trim());
|
|
824
|
+
continue;
|
|
825
|
+
}
|
|
826
|
+
if (entry.type === "timeline_warning") {
|
|
827
|
+
writeLine(`[Rig timeline] ${String(entry.detail ?? entry.message ?? "timeline unavailable")}`);
|
|
828
|
+
continue;
|
|
829
|
+
}
|
|
830
|
+
if (entry.type === "action") {
|
|
831
|
+
const text = String(entry.detail ?? entry.message ?? entry.title ?? "").trim();
|
|
832
|
+
if (text)
|
|
833
|
+
writeLine(`[Rig action] ${text}`);
|
|
834
|
+
continue;
|
|
835
|
+
}
|
|
836
|
+
if (entry.type === "user_message") {
|
|
837
|
+
const text = String(entry.text ?? entry.message ?? entry.detail ?? "").trim();
|
|
838
|
+
if (text)
|
|
839
|
+
writeLine(`[Operator] ${text}`);
|
|
840
|
+
continue;
|
|
841
|
+
}
|
|
842
|
+
const fallback = String(entry.detail ?? entry.message ?? entry.text ?? entry.title ?? "").trim();
|
|
843
|
+
if (fallback)
|
|
844
|
+
writeLine(`[${String(entry.type ?? "timeline")}] ${fallback}`);
|
|
845
|
+
}
|
|
846
|
+
},
|
|
847
|
+
renderLogs(entries) {
|
|
848
|
+
for (const [index, entry] of entries.entries()) {
|
|
849
|
+
const id = entryId(entry, `log:${index}:${String(entry.createdAt ?? "")}:${String(entry.title ?? "")}`);
|
|
850
|
+
if (seenLogs.has(id))
|
|
851
|
+
continue;
|
|
852
|
+
seenLogs.add(id);
|
|
853
|
+
const title = String(entry.title ?? "");
|
|
854
|
+
if (CANONICAL_STAGES.some((stage) => stage.toLowerCase() === title.toLowerCase()))
|
|
855
|
+
continue;
|
|
856
|
+
const detail = logDetail(entry);
|
|
857
|
+
if (!detail)
|
|
858
|
+
continue;
|
|
859
|
+
const protocolRecord = parseProviderProtocolLog(title, detail);
|
|
860
|
+
if (protocolRecord) {
|
|
861
|
+
const protocolLine = renderProviderProtocolLog(protocolRecord);
|
|
862
|
+
if (protocolLine)
|
|
863
|
+
writeLine(protocolLine);
|
|
864
|
+
continue;
|
|
865
|
+
}
|
|
866
|
+
writeLine(`[${title || "Rig log"}] ${detail}`);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
function createOperatorSurface(options = {}) {
|
|
872
|
+
const input = options.input ?? process.stdin;
|
|
873
|
+
const output = options.output ?? process.stdout;
|
|
874
|
+
const errorOutput = options.errorOutput ?? process.stderr;
|
|
875
|
+
const renderer = createPiRunStreamRenderer(output);
|
|
876
|
+
const writeLine = (line) => output.write(`${line}
|
|
877
|
+
`);
|
|
878
|
+
return {
|
|
879
|
+
mode: "pi-compatible-text",
|
|
880
|
+
...renderer,
|
|
881
|
+
info: writeLine,
|
|
882
|
+
error: (message2) => errorOutput.write(`${message2}
|
|
883
|
+
`),
|
|
884
|
+
attachCommandInput(handler) {
|
|
885
|
+
if (options.interactive === false || !input.isTTY)
|
|
886
|
+
return null;
|
|
887
|
+
const rl = createInterface({ input, output: process.stdout, terminal: false });
|
|
888
|
+
rl.on("line", (line) => {
|
|
889
|
+
Promise.resolve(handler(line)).catch((error) => writeLine(`Operator command failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
890
|
+
});
|
|
891
|
+
return { close: () => rl.close() };
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
}
|
|
710
895
|
function taskId(task) {
|
|
711
896
|
return typeof task.id === "string" && task.id.trim() ? task.id : "<unknown>";
|
|
712
897
|
}
|
|
@@ -719,6 +904,19 @@ function taskStatus(task) {
|
|
|
719
904
|
function renderTaskPickerRows(tasks) {
|
|
720
905
|
return tasks.map((task, index) => `${index + 1}. ${taskId(task)} \xB7 ${taskStatus(task)} \xB7 ${taskTitle(task)}`);
|
|
721
906
|
}
|
|
907
|
+
async function promptForTaskSelection(question) {
|
|
908
|
+
const rl = createPromptInterface({ input: process.stdin, output: process.stdout });
|
|
909
|
+
try {
|
|
910
|
+
return await rl.question(question);
|
|
911
|
+
} finally {
|
|
912
|
+
rl.close();
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
// packages/cli/src/commands/_task-picker.ts
|
|
917
|
+
function taskId2(task) {
|
|
918
|
+
return typeof task.id === "string" && task.id.trim() ? task.id : "<unknown>";
|
|
919
|
+
}
|
|
722
920
|
async function selectTaskWithTextPicker(tasks, io = {}) {
|
|
723
921
|
if (tasks.length === 0)
|
|
724
922
|
return null;
|
|
@@ -728,56 +926,665 @@ async function selectTaskWithTextPicker(tasks, io = {}) {
|
|
|
728
926
|
if (!isTty) {
|
|
729
927
|
throw new Error("task run requires an interactive terminal to pick a task; pass --task <id>, --next, or --detach with a task id.");
|
|
730
928
|
}
|
|
731
|
-
|
|
732
|
-
const
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
929
|
+
if (io.prompt || io.renderer) {
|
|
930
|
+
const prompt = io.prompt ?? promptForTaskSelection;
|
|
931
|
+
const renderer = io.renderer ?? { writeLine: (line) => process.stdout.write(`${line}
|
|
932
|
+
`) };
|
|
933
|
+
renderer.writeLine("Select Rig task:");
|
|
934
|
+
for (const row of renderTaskPickerRows(tasks))
|
|
935
|
+
renderer.writeLine(` ${row}`);
|
|
936
|
+
const answer2 = (await prompt(`Task [1-${tasks.length}] or id: `)).trim();
|
|
937
|
+
if (!answer2)
|
|
938
|
+
return null;
|
|
939
|
+
if (/^\d+$/.test(answer2)) {
|
|
940
|
+
const index2 = Number.parseInt(answer2, 10) - 1;
|
|
941
|
+
return tasks[index2] ?? null;
|
|
737
942
|
}
|
|
943
|
+
return tasks.find((task) => taskId2(task) === answer2) ?? null;
|
|
944
|
+
}
|
|
945
|
+
const options = tasks.map((task, index2) => ({
|
|
946
|
+
value: `${index2}`,
|
|
947
|
+
label: `${taskId2(task)} \xB7 ${typeof task.title === "string" && task.title.trim() ? task.title.trim() : "Untitled task"}`,
|
|
948
|
+
hint: typeof task.status === "string" && task.status.trim() ? task.status.trim() : undefined
|
|
949
|
+
}));
|
|
950
|
+
const answer = await select({
|
|
951
|
+
message: "Select Rig task",
|
|
952
|
+
options
|
|
738
953
|
});
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
console.log(` ${row}`);
|
|
742
|
-
const answer = (await prompt(`Task [1-${tasks.length}] or id: `)).trim();
|
|
743
|
-
if (!answer)
|
|
954
|
+
if (isCancel(answer)) {
|
|
955
|
+
cancel("No task selected.");
|
|
744
956
|
return null;
|
|
745
|
-
if (/^\d+$/.test(answer)) {
|
|
746
|
-
const index = Number.parseInt(answer, 10) - 1;
|
|
747
|
-
return tasks[index] ?? null;
|
|
748
957
|
}
|
|
749
|
-
|
|
958
|
+
const index = Number.parseInt(String(answer), 10);
|
|
959
|
+
return Number.isFinite(index) ? tasks[index] ?? null : null;
|
|
750
960
|
}
|
|
751
961
|
|
|
752
|
-
// packages/cli/src/commands/
|
|
753
|
-
import {
|
|
962
|
+
// packages/cli/src/commands/_pi-frontend.ts
|
|
963
|
+
import { mkdtempSync, rmSync } from "fs";
|
|
964
|
+
import { tmpdir } from "os";
|
|
965
|
+
import { join } from "path";
|
|
966
|
+
import {
|
|
967
|
+
createAgentSessionFromServices,
|
|
968
|
+
createAgentSessionServices,
|
|
969
|
+
main as runPiMain
|
|
970
|
+
} from "@earendil-works/pi-coding-agent";
|
|
971
|
+
|
|
972
|
+
// packages/cli/src/commands/_pi-remote-session.ts
|
|
973
|
+
import { AgentSession as PiAgentSession } from "@earendil-works/pi-coding-agent";
|
|
754
974
|
var TERMINAL_RUN_STATUSES = new Set(["completed", "failed", "stopped", "cancelled", "canceled", "closed", "merged", "needs_attention", "needs-attention"]);
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
975
|
+
function defaultTransport() {
|
|
976
|
+
return {
|
|
977
|
+
getSession: getRunPiSessionViaServer,
|
|
978
|
+
getMessages: getRunPiMessagesViaServer,
|
|
979
|
+
getStatus: getRunPiStatusViaServer,
|
|
980
|
+
getCommands: getRunPiCommandsViaServer,
|
|
981
|
+
sendPrompt: sendRunPiPromptViaServer,
|
|
982
|
+
sendShell: sendRunPiShellViaServer,
|
|
983
|
+
runCommand: runRunPiCommandViaServer,
|
|
984
|
+
abort: abortRunPiViaServer,
|
|
985
|
+
buildEventsWebSocketUrl: buildRunPiEventsWebSocketUrl
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
function recordOf(value) {
|
|
989
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
990
|
+
}
|
|
991
|
+
function emptyRemoteStatus() {
|
|
992
|
+
return {
|
|
993
|
+
isStreaming: false,
|
|
994
|
+
isCompacting: false,
|
|
995
|
+
isBashRunning: false,
|
|
996
|
+
pendingMessageCount: 0,
|
|
997
|
+
steeringMessages: [],
|
|
998
|
+
followUpMessages: [],
|
|
999
|
+
model: null,
|
|
1000
|
+
thinkingLevel: null,
|
|
1001
|
+
sessionName: null,
|
|
1002
|
+
cwd: null,
|
|
1003
|
+
stats: null,
|
|
1004
|
+
contextUsage: null
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
function resolveAttachReadyTimeoutMs() {
|
|
1008
|
+
const raw = Number.parseInt(process.env.RIG_PI_ATTACH_TIMEOUT_MS ?? "", 10);
|
|
1009
|
+
return Number.isFinite(raw) && raw > 0 ? raw : 10 * 60000;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
class RigRemoteSessionController {
|
|
1013
|
+
context;
|
|
1014
|
+
runId;
|
|
1015
|
+
status = emptyRemoteStatus();
|
|
1016
|
+
transport;
|
|
1017
|
+
hooks = {};
|
|
1018
|
+
session = null;
|
|
1019
|
+
socket = null;
|
|
1020
|
+
closed = false;
|
|
1021
|
+
pendingShells = [];
|
|
1022
|
+
pendingCompactions = [];
|
|
1023
|
+
constructor(input) {
|
|
1024
|
+
this.context = input.context;
|
|
1025
|
+
this.runId = input.runId;
|
|
1026
|
+
this.transport = input.transport ?? defaultTransport();
|
|
1027
|
+
}
|
|
1028
|
+
ingestEnvelope(envelopeValue) {
|
|
1029
|
+
this.applyEnvelope(envelopeValue);
|
|
1030
|
+
}
|
|
1031
|
+
bindSession(session) {
|
|
1032
|
+
this.session = session;
|
|
1033
|
+
}
|
|
1034
|
+
setUiHooks(hooks) {
|
|
1035
|
+
this.hooks = hooks;
|
|
1036
|
+
}
|
|
1037
|
+
async connect() {
|
|
1038
|
+
const ready = await this.waitForReady();
|
|
1039
|
+
if (!ready || this.closed)
|
|
1040
|
+
return;
|
|
1041
|
+
let catchupDone = false;
|
|
1042
|
+
const buffered = [];
|
|
1043
|
+
const wsUrl = await this.transport.buildEventsWebSocketUrl(this.context, this.runId);
|
|
1044
|
+
const socket = new WebSocket(wsUrl);
|
|
1045
|
+
this.socket = socket;
|
|
1046
|
+
socket.onopen = () => {
|
|
1047
|
+
this.hooks.onConnectionChange?.(true);
|
|
1048
|
+
this.hooks.onStatusText?.("worker session live");
|
|
1049
|
+
};
|
|
1050
|
+
socket.onmessage = (message2) => {
|
|
1051
|
+
try {
|
|
1052
|
+
const payload = typeof message2.data === "string" ? JSON.parse(message2.data) : JSON.parse(Buffer.from(message2.data).toString("utf8"));
|
|
1053
|
+
if (!catchupDone)
|
|
1054
|
+
buffered.push(payload);
|
|
1055
|
+
else
|
|
1056
|
+
this.applyEnvelope(payload);
|
|
1057
|
+
} catch (error) {
|
|
1058
|
+
this.hooks.onError?.(`Unparseable worker Pi event: ${error instanceof Error ? error.message : String(error)}`);
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
socket.onerror = () => socket.close();
|
|
1062
|
+
socket.onclose = () => {
|
|
1063
|
+
this.hooks.onConnectionChange?.(false);
|
|
1064
|
+
if (!this.closed)
|
|
1065
|
+
this.hooks.onStatusText?.("worker Pi WebSocket disconnected");
|
|
1066
|
+
};
|
|
1067
|
+
try {
|
|
1068
|
+
const [messagesPayload, statusPayload, commandsPayload] = await Promise.all([
|
|
1069
|
+
this.transport.getMessages(this.context, this.runId),
|
|
1070
|
+
this.transport.getStatus(this.context, this.runId),
|
|
1071
|
+
this.transport.getCommands(this.context, this.runId)
|
|
1072
|
+
]);
|
|
1073
|
+
const messages = Array.isArray(messagesPayload.messages) ? messagesPayload.messages : [];
|
|
1074
|
+
this.applyStatusPayload(statusPayload);
|
|
1075
|
+
this.session?.replaceRemoteMessages(messages);
|
|
1076
|
+
const commands = Array.isArray(commandsPayload.commands) ? commandsPayload.commands : [];
|
|
1077
|
+
this.hooks.onCatchUp?.(messages, commands);
|
|
1078
|
+
catchupDone = true;
|
|
1079
|
+
for (const payload of buffered.splice(0))
|
|
1080
|
+
this.applyEnvelope(payload);
|
|
1081
|
+
} catch (error) {
|
|
1082
|
+
catchupDone = true;
|
|
1083
|
+
this.hooks.onError?.(`Worker Pi catch-up failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
close() {
|
|
1087
|
+
this.closed = true;
|
|
1088
|
+
this.socket?.close();
|
|
1089
|
+
for (const shell of this.pendingShells.splice(0))
|
|
1090
|
+
shell.reject(new Error("Remote session closed."));
|
|
1091
|
+
for (const compaction of this.pendingCompactions.splice(0))
|
|
1092
|
+
compaction.reject(new Error("Remote session closed."));
|
|
1093
|
+
}
|
|
1094
|
+
async sendPrompt(text, streamingBehavior) {
|
|
1095
|
+
await this.transport.sendPrompt(this.context, this.runId, text, streamingBehavior);
|
|
1096
|
+
}
|
|
1097
|
+
async sendCommand(text) {
|
|
1098
|
+
const result = await this.transport.runCommand(this.context, this.runId, text);
|
|
1099
|
+
return typeof result.message === "string" ? result.message : "worker command accepted";
|
|
1100
|
+
}
|
|
1101
|
+
async sendShell(text) {
|
|
1102
|
+
await this.transport.sendShell(this.context, this.runId, text);
|
|
1103
|
+
}
|
|
1104
|
+
async abort() {
|
|
1105
|
+
await this.transport.abort(this.context, this.runId);
|
|
1106
|
+
}
|
|
1107
|
+
registerPendingShell(shell) {
|
|
1108
|
+
this.pendingShells.push(shell);
|
|
1109
|
+
}
|
|
1110
|
+
failPendingShell(shell, error) {
|
|
1111
|
+
const index = this.pendingShells.indexOf(shell);
|
|
1112
|
+
if (index !== -1)
|
|
1113
|
+
this.pendingShells.splice(index, 1);
|
|
1114
|
+
shell.reject(error);
|
|
1115
|
+
}
|
|
1116
|
+
registerPendingCompaction(pending) {
|
|
1117
|
+
this.pendingCompactions.push(pending);
|
|
1118
|
+
}
|
|
1119
|
+
async waitForReady() {
|
|
1120
|
+
const startedAt = Date.now();
|
|
1121
|
+
const deadline = startedAt + resolveAttachReadyTimeoutMs();
|
|
1122
|
+
let consecutiveFailures = 0;
|
|
1123
|
+
while (!this.closed) {
|
|
1124
|
+
let requestFailed = false;
|
|
1125
|
+
const session = await this.transport.getSession(this.context, this.runId).catch((error) => {
|
|
1126
|
+
requestFailed = true;
|
|
1127
|
+
return { ready: false, status: error instanceof Error ? error.message : String(error), retryAfterMs: 1000 };
|
|
1128
|
+
});
|
|
1129
|
+
if (session.ready !== false)
|
|
1130
|
+
return true;
|
|
1131
|
+
consecutiveFailures = requestFailed ? consecutiveFailures + 1 : 0;
|
|
1132
|
+
const status = String(session.status ?? "starting");
|
|
1133
|
+
if (TERMINAL_RUN_STATUSES.has(status.toLowerCase())) {
|
|
1134
|
+
this.hooks.onError?.(`Run ended before the worker Pi daemon became ready: ${status}. Inspect with \`rig run show ${this.runId}\`.`);
|
|
1135
|
+
return false;
|
|
1136
|
+
}
|
|
1137
|
+
this.hooks.onStatusText?.(consecutiveFailures >= 5 ? "Rig server unreachable \xB7 retrying \xB7 /detach to exit" : `waiting for worker Pi daemon \xB7 ${status} \xB7 /detach to exit`);
|
|
1138
|
+
if (Date.now() >= deadline) {
|
|
1139
|
+
this.hooks.onError?.(`Worker Pi daemon did not become ready (last status: ${status}). Set RIG_PI_ATTACH_TIMEOUT_MS to wait longer.`);
|
|
1140
|
+
return false;
|
|
1141
|
+
}
|
|
1142
|
+
await Bun.sleep(typeof session.retryAfterMs === "number" ? session.retryAfterMs : 750);
|
|
1143
|
+
}
|
|
1144
|
+
return false;
|
|
1145
|
+
}
|
|
1146
|
+
applyEnvelope(envelopeValue) {
|
|
1147
|
+
const envelope = recordOf(envelopeValue);
|
|
1148
|
+
if (!envelope)
|
|
1149
|
+
return;
|
|
1150
|
+
const type = String(envelope.type ?? "");
|
|
1151
|
+
if (type === "status.update") {
|
|
1152
|
+
this.applyStatusPayload(envelope);
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
if (type === "activity.update") {
|
|
1156
|
+
const activity = recordOf(envelope.activity);
|
|
1157
|
+
this.hooks.onActivity?.(String(activity?.label ?? ""), activity?.detail ? String(activity.detail) : undefined);
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
if (type === "extension_ui_request") {
|
|
1161
|
+
const request = recordOf(envelope.request);
|
|
1162
|
+
if (request)
|
|
1163
|
+
this.hooks.onExtensionUiRequest?.(request);
|
|
1164
|
+
return;
|
|
1165
|
+
}
|
|
1166
|
+
if (type === "pi.ui_event") {
|
|
1167
|
+
this.applyShellUiEvent(envelope.event);
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
if (type === "pi.event") {
|
|
1171
|
+
this.session?.handleRemoteSessionEvent(envelope.event);
|
|
1172
|
+
this.settlePendingCompaction(envelope.event);
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
if (type === "error") {
|
|
1176
|
+
this.hooks.onError?.(String(envelope.message ?? envelope.detail ?? "unknown worker error"));
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
applyStatusPayload(payload) {
|
|
1180
|
+
const status = recordOf(payload.status) ?? payload;
|
|
1181
|
+
const next = this.status;
|
|
1182
|
+
next.isStreaming = status.isStreaming === true;
|
|
1183
|
+
next.isCompacting = status.isCompacting === true;
|
|
1184
|
+
next.isBashRunning = status.isBashRunning === true;
|
|
1185
|
+
next.pendingMessageCount = typeof status.pendingMessageCount === "number" ? status.pendingMessageCount : 0;
|
|
1186
|
+
next.steeringMessages = Array.isArray(status.steeringMessages) ? status.steeringMessages.map(String) : [];
|
|
1187
|
+
next.followUpMessages = Array.isArray(status.followUpMessages) ? status.followUpMessages.map(String) : [];
|
|
1188
|
+
next.model = recordOf(status.model) ?? next.model;
|
|
1189
|
+
next.thinkingLevel = typeof status.thinkingLevel === "string" ? status.thinkingLevel : next.thinkingLevel;
|
|
1190
|
+
next.sessionName = typeof status.sessionName === "string" ? status.sessionName : next.sessionName;
|
|
1191
|
+
next.cwd = typeof status.cwd === "string" ? status.cwd : next.cwd;
|
|
1192
|
+
next.stats = recordOf(status.stats) ?? next.stats;
|
|
1193
|
+
next.contextUsage = recordOf(status.contextUsage) ?? next.contextUsage;
|
|
1194
|
+
}
|
|
1195
|
+
applyShellUiEvent(value) {
|
|
1196
|
+
const event = recordOf(value);
|
|
1197
|
+
if (!event)
|
|
1198
|
+
return;
|
|
1199
|
+
const type = String(event.type ?? "");
|
|
1200
|
+
const pending = this.pendingShells[0];
|
|
1201
|
+
if (type === "shell.chunk" && pending) {
|
|
1202
|
+
pending.sawChunk = true;
|
|
1203
|
+
pending.onData(Buffer.from(String(event.chunk ?? "")));
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
if (type === "shell.end" && pending) {
|
|
1207
|
+
const output = String(event.output ?? "");
|
|
1208
|
+
if (output && !pending.sawChunk)
|
|
1209
|
+
pending.onData(Buffer.from(output));
|
|
1210
|
+
const index = this.pendingShells.indexOf(pending);
|
|
1211
|
+
if (index !== -1)
|
|
1212
|
+
this.pendingShells.splice(index, 1);
|
|
1213
|
+
pending.resolve({ exitCode: typeof event.exitCode === "number" ? event.exitCode : event.isError === true ? 1 : 0 });
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
settlePendingCompaction(eventValue) {
|
|
1217
|
+
const event = recordOf(eventValue);
|
|
1218
|
+
if (!event)
|
|
1219
|
+
return;
|
|
1220
|
+
const type = String(event.type ?? "");
|
|
1221
|
+
if (type !== "compaction_end" || this.pendingCompactions.length === 0)
|
|
1222
|
+
return;
|
|
1223
|
+
const pending = this.pendingCompactions.shift();
|
|
1224
|
+
const result = recordOf(event.result);
|
|
1225
|
+
if (result)
|
|
1226
|
+
pending.resolve(result);
|
|
1227
|
+
else if (event.aborted === true)
|
|
1228
|
+
pending.reject(new Error("Compaction aborted on the worker."));
|
|
1229
|
+
else
|
|
1230
|
+
pending.resolve({});
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
class RigRemoteAgentSession extends PiAgentSession {
|
|
1235
|
+
remote;
|
|
1236
|
+
constructor(config, remote) {
|
|
1237
|
+
super(config);
|
|
1238
|
+
this.remote = remote;
|
|
1239
|
+
remote.bindSession(this);
|
|
1240
|
+
}
|
|
1241
|
+
handleRemoteSessionEvent(eventValue) {
|
|
1242
|
+
const event = recordOf(eventValue);
|
|
1243
|
+
if (!event)
|
|
1244
|
+
return;
|
|
1245
|
+
const type = String(event.type ?? "");
|
|
1246
|
+
if ((type === "message_end" || type === "turn_end") && recordOf(event.message)) {
|
|
1247
|
+
this.agent.state.messages = [...this.agent.state.messages, event.message];
|
|
1248
|
+
}
|
|
1249
|
+
this._emit(eventValue);
|
|
1250
|
+
}
|
|
1251
|
+
replaceRemoteMessages(messages) {
|
|
1252
|
+
this.agent.state.messages = messages;
|
|
1253
|
+
}
|
|
1254
|
+
async prompt(text, options) {
|
|
1255
|
+
const trimmed = text.trim();
|
|
1256
|
+
if (!trimmed)
|
|
1257
|
+
return;
|
|
1258
|
+
if (trimmed.startsWith("/")) {
|
|
1259
|
+
if (await this._tryExecuteExtensionCommand(trimmed))
|
|
1260
|
+
return;
|
|
1261
|
+
await this.remote.sendCommand(trimmed);
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
if (trimmed.startsWith("!")) {
|
|
1265
|
+
await this.remote.sendShell(trimmed);
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1268
|
+
const behavior = options?.streamingBehavior ?? (this.isStreaming || this.isCompacting ? "steer" : undefined);
|
|
1269
|
+
options?.preflightResult?.(true);
|
|
1270
|
+
await this.remote.sendPrompt(trimmed, behavior);
|
|
1271
|
+
}
|
|
1272
|
+
async steer(text) {
|
|
1273
|
+
await this.remote.sendPrompt(text, "steer");
|
|
1274
|
+
}
|
|
1275
|
+
async followUp(text) {
|
|
1276
|
+
await this.remote.sendPrompt(text, "followUp");
|
|
1277
|
+
}
|
|
1278
|
+
async abort() {
|
|
1279
|
+
await this.remote.abort();
|
|
1280
|
+
}
|
|
1281
|
+
async compact(customInstructions) {
|
|
1282
|
+
const pending = new Promise((resolve3, reject) => {
|
|
1283
|
+
this.remote.registerPendingCompaction({ resolve: resolve3, reject });
|
|
1284
|
+
});
|
|
1285
|
+
await this.remote.sendCommand(`/compact${customInstructions ? ` ${customInstructions}` : ""}`);
|
|
1286
|
+
return pending;
|
|
1287
|
+
}
|
|
1288
|
+
clearQueue() {
|
|
1289
|
+
const cleared = {
|
|
1290
|
+
steering: [...this.remote.status.steeringMessages],
|
|
1291
|
+
followUp: [...this.remote.status.followUpMessages]
|
|
1292
|
+
};
|
|
1293
|
+
this.remote.status.steeringMessages = [];
|
|
1294
|
+
this.remote.status.followUpMessages = [];
|
|
1295
|
+
this.remote.status.pendingMessageCount = 0;
|
|
1296
|
+
this.remote.sendCommand("/queue-clear").catch(() => {});
|
|
1297
|
+
return cleared;
|
|
1298
|
+
}
|
|
1299
|
+
get isStreaming() {
|
|
1300
|
+
return this.remote.status.isStreaming;
|
|
1301
|
+
}
|
|
1302
|
+
get isCompacting() {
|
|
1303
|
+
return this.remote.status.isCompacting;
|
|
1304
|
+
}
|
|
1305
|
+
get isBashRunning() {
|
|
1306
|
+
return this.remote.status.isBashRunning;
|
|
1307
|
+
}
|
|
1308
|
+
get pendingMessageCount() {
|
|
1309
|
+
return this.remote.status.pendingMessageCount;
|
|
1310
|
+
}
|
|
1311
|
+
getSteeringMessages() {
|
|
1312
|
+
return this.remote.status.steeringMessages;
|
|
1313
|
+
}
|
|
1314
|
+
getFollowUpMessages() {
|
|
1315
|
+
return this.remote.status.followUpMessages;
|
|
1316
|
+
}
|
|
1317
|
+
get model() {
|
|
1318
|
+
return this.remote.status.model ?? super.model;
|
|
1319
|
+
}
|
|
1320
|
+
async setModel(model) {
|
|
1321
|
+
await this.remote.sendCommand(`/model ${model.provider}/${model.id}`);
|
|
1322
|
+
this.remote.status.model = model;
|
|
1323
|
+
}
|
|
1324
|
+
get thinkingLevel() {
|
|
1325
|
+
return this.remote.status.thinkingLevel ?? super.thinkingLevel;
|
|
1326
|
+
}
|
|
1327
|
+
setThinkingLevel(level) {
|
|
1328
|
+
this.remote.status.thinkingLevel = level;
|
|
1329
|
+
this.remote.sendCommand(`/thinking ${level}`).catch(() => {});
|
|
1330
|
+
}
|
|
1331
|
+
get sessionName() {
|
|
1332
|
+
return this.remote.status.sessionName ?? super.sessionName;
|
|
1333
|
+
}
|
|
1334
|
+
setSessionName(name) {
|
|
1335
|
+
this.remote.status.sessionName = name;
|
|
1336
|
+
this.remote.sendCommand(`/name ${name}`).catch(() => {});
|
|
1337
|
+
}
|
|
1338
|
+
getSessionStats() {
|
|
1339
|
+
return this.remote.status.stats ?? super.getSessionStats();
|
|
1340
|
+
}
|
|
1341
|
+
getContextUsage() {
|
|
1342
|
+
return this.remote.status.contextUsage ?? super.getContextUsage();
|
|
1343
|
+
}
|
|
1344
|
+
dispose() {
|
|
1345
|
+
this.remote.close();
|
|
1346
|
+
super.dispose();
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
function createRemoteBashOperations(controller, excludeFromContext) {
|
|
1350
|
+
return {
|
|
1351
|
+
exec(command, _cwd, execOptions) {
|
|
1352
|
+
return new Promise((resolve3, reject) => {
|
|
1353
|
+
const pending = { onData: execOptions.onData, resolve: resolve3, reject, sawChunk: false };
|
|
1354
|
+
const cleanup = () => {
|
|
1355
|
+
execOptions.signal?.removeEventListener("abort", onAbort);
|
|
1356
|
+
if (timer)
|
|
1357
|
+
clearTimeout(timer);
|
|
1358
|
+
};
|
|
1359
|
+
const onAbort = () => {
|
|
1360
|
+
cleanup();
|
|
1361
|
+
controller.failPendingShell(pending, new Error("Remote worker shell command aborted locally."));
|
|
1362
|
+
};
|
|
1363
|
+
const timeoutMs = typeof execOptions.timeout === "number" && execOptions.timeout > 0 ? execOptions.timeout : 0;
|
|
1364
|
+
const timer = timeoutMs > 0 ? setTimeout(() => {
|
|
1365
|
+
cleanup();
|
|
1366
|
+
controller.failPendingShell(pending, new Error(`Remote worker shell command timed out after ${timeoutMs}ms.`));
|
|
1367
|
+
}, timeoutMs) : null;
|
|
1368
|
+
const wrappedResolve = pending.resolve;
|
|
1369
|
+
const wrappedReject = pending.reject;
|
|
1370
|
+
pending.resolve = (result) => {
|
|
1371
|
+
cleanup();
|
|
1372
|
+
wrappedResolve(result);
|
|
1373
|
+
};
|
|
1374
|
+
pending.reject = (error) => {
|
|
1375
|
+
cleanup();
|
|
1376
|
+
wrappedReject(error);
|
|
1377
|
+
};
|
|
1378
|
+
execOptions.signal?.addEventListener("abort", onAbort, { once: true });
|
|
1379
|
+
controller.registerPendingShell(pending);
|
|
1380
|
+
controller.sendShell(`${excludeFromContext ? "!!" : "!"}${command}`).catch((error) => {
|
|
1381
|
+
cleanup();
|
|
1382
|
+
controller.failPendingShell(pending, error instanceof Error ? error : new Error(String(error)));
|
|
1383
|
+
});
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
// packages/cli/src/commands/_pi-worker-bridge-extension.ts
|
|
1390
|
+
function recordOf2(value) {
|
|
1391
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
1392
|
+
}
|
|
1393
|
+
function asText(value) {
|
|
1394
|
+
if (typeof value === "string")
|
|
1395
|
+
return value;
|
|
1396
|
+
if (value === null || value === undefined)
|
|
1397
|
+
return "";
|
|
1398
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
1399
|
+
return String(value);
|
|
1400
|
+
try {
|
|
1401
|
+
return JSON.stringify(value);
|
|
1402
|
+
} catch {
|
|
1403
|
+
return String(value);
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
async function answerExtensionUiRequest(options, ctx, request) {
|
|
1407
|
+
const requestId = String(request.requestId ?? request.id ?? `ui-${Date.now()}`);
|
|
1408
|
+
const method = String(request.method ?? request.type ?? "input");
|
|
1409
|
+
const prompt = asText(request.prompt ?? request.message ?? request.title ?? method);
|
|
1410
|
+
const rawOptions = Array.isArray(request.options) ? request.options : Array.isArray(request.items) ? request.items : [];
|
|
1411
|
+
const choices = rawOptions.map((option) => {
|
|
1412
|
+
const record = recordOf2(option);
|
|
1413
|
+
return record ? asText(record.label ?? record.value ?? record.name ?? option) : asText(option);
|
|
1414
|
+
}).filter(Boolean);
|
|
1415
|
+
try {
|
|
1416
|
+
if (method === "confirm") {
|
|
1417
|
+
const confirmed = await ctx.ui.confirm("Worker request", prompt);
|
|
1418
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, requestId, { value: confirmed, confirmed });
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
if (choices.length > 0) {
|
|
1422
|
+
const selected = await ctx.ui.select(prompt, choices);
|
|
1423
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, requestId, selected === undefined ? { cancelled: true } : { value: selected });
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
const value = await ctx.ui.input("Worker request", prompt);
|
|
1427
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, requestId, value === undefined ? { cancelled: true } : { value });
|
|
1428
|
+
} catch (error) {
|
|
1429
|
+
ctx.ui.notify(`Failed to answer worker UI request: ${error instanceof Error ? error.message : String(error)}`, "error");
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
var LOCALLY_OWNED_COMMANDS = new Set(["detach", "quit", "q", "stop", "settings", "model", "thinking", "compact", "session", "name", "reload"]);
|
|
1433
|
+
function registerDaemonCommands(pi, options, ctx, commands, registered) {
|
|
1434
|
+
for (const command of commands) {
|
|
1435
|
+
const record = recordOf2(command);
|
|
1436
|
+
const name = typeof record?.name === "string" ? record.name : "";
|
|
1437
|
+
const source = typeof record?.source === "string" ? record.source : "worker";
|
|
1438
|
+
if (!name || source === "builtin" || registered.has(name) || LOCALLY_OWNED_COMMANDS.has(name))
|
|
1439
|
+
continue;
|
|
1440
|
+
registered.add(name);
|
|
1441
|
+
const description = typeof record?.description === "string" ? record.description : undefined;
|
|
1442
|
+
try {
|
|
1443
|
+
pi.registerCommand(name, {
|
|
1444
|
+
description: `[worker ${source}] ${description ?? ""}`.trim(),
|
|
1445
|
+
handler: async (args) => {
|
|
1446
|
+
try {
|
|
1447
|
+
const message2 = await options.controller.sendCommand(`/${name}${args ? ` ${args}` : ""}`);
|
|
1448
|
+
ctx.ui.notify(message2, "info");
|
|
1449
|
+
} catch (error) {
|
|
1450
|
+
ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
});
|
|
1454
|
+
} catch {}
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
function createRigWorkerPiBridgeExtension(options) {
|
|
1458
|
+
return (pi) => {
|
|
1459
|
+
const registeredDaemonCommands = new Set;
|
|
1460
|
+
pi.registerCommand("detach", {
|
|
1461
|
+
description: "Detach from this run; the worker keeps going",
|
|
1462
|
+
handler: async (_args, ctx) => {
|
|
1463
|
+
ctx.ui.notify("Detached locally; the worker Pi daemon continues.", "info");
|
|
1464
|
+
ctx.shutdown();
|
|
1465
|
+
}
|
|
1466
|
+
});
|
|
1467
|
+
pi.registerCommand("stop", {
|
|
1468
|
+
description: "Stop the worker Pi run and detach",
|
|
1469
|
+
handler: async (_args, ctx) => {
|
|
1470
|
+
await options.controller.abort();
|
|
1471
|
+
ctx.ui.notify("Stop requested for the worker Pi daemon.", "info");
|
|
1472
|
+
ctx.shutdown();
|
|
1473
|
+
}
|
|
1474
|
+
});
|
|
1475
|
+
pi.on("user_bash", (event) => ({
|
|
1476
|
+
operations: createRemoteBashOperations(options.controller, event.excludeFromContext === true)
|
|
1477
|
+
}));
|
|
1478
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
1479
|
+
ctx.ui.setTitle("Rig \xB7 worker session");
|
|
1480
|
+
ctx.ui.setStatus("rig-worker-pi", "connecting to worker session");
|
|
1481
|
+
ctx.ui.notify(`Attached to Rig run ${options.runId}. Native Pi, remote brain \u2014 /detach exits, /stop cancels the run.`, "info");
|
|
1482
|
+
if (options.initialMessageSent)
|
|
1483
|
+
ctx.ui.notify("Initial message sent to the worker Pi daemon.", "info");
|
|
1484
|
+
const nativeUi = ctx.ui;
|
|
1485
|
+
options.controller.setUiHooks({
|
|
1486
|
+
onStatusText: (text) => ctx.ui.setStatus("rig-worker-pi", text),
|
|
1487
|
+
onActivity: (label, detail) => ctx.ui.setStatus("rig-worker-pi", [label, detail].filter(Boolean).join(" \u2014 ")),
|
|
1488
|
+
onConnectionChange: (connected) => ctx.ui.setStatus("rig-worker-pi", connected ? "worker session live" : "worker session disconnected"),
|
|
1489
|
+
onError: (message2) => ctx.ui.notify(message2, "error"),
|
|
1490
|
+
onExtensionUiRequest: (request) => {
|
|
1491
|
+
answerExtensionUiRequest(options, ctx, request);
|
|
1492
|
+
},
|
|
1493
|
+
onCatchUp: (messages, commands) => {
|
|
1494
|
+
if (nativeUi.appendSessionMessages)
|
|
1495
|
+
nativeUi.appendSessionMessages(messages);
|
|
1496
|
+
const cwd = options.controller.status.cwd;
|
|
1497
|
+
if (nativeUi.setDisplayCwd && cwd)
|
|
1498
|
+
nativeUi.setDisplayCwd(cwd);
|
|
1499
|
+
registerDaemonCommands(pi, options, ctx, commands, registeredDaemonCommands);
|
|
1500
|
+
}
|
|
1501
|
+
});
|
|
1502
|
+
options.controller.connect().catch((error) => {
|
|
1503
|
+
ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
|
|
1504
|
+
});
|
|
1505
|
+
});
|
|
1506
|
+
pi.on("session_shutdown", () => {
|
|
1507
|
+
options.controller.close();
|
|
1508
|
+
});
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
// packages/cli/src/commands/_pi-frontend.ts
|
|
1513
|
+
function setTemporaryEnv(updates) {
|
|
1514
|
+
const previous = new Map;
|
|
1515
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
1516
|
+
previous.set(key, process.env[key]);
|
|
1517
|
+
process.env[key] = value;
|
|
1518
|
+
}
|
|
1519
|
+
return () => {
|
|
1520
|
+
for (const [key, value] of previous) {
|
|
1521
|
+
if (value === undefined)
|
|
1522
|
+
delete process.env[key];
|
|
1523
|
+
else
|
|
1524
|
+
process.env[key] = value;
|
|
1525
|
+
}
|
|
1526
|
+
};
|
|
1527
|
+
}
|
|
1528
|
+
async function attachRunBundledPiFrontend(context, input) {
|
|
1529
|
+
const tempSessionDir = mkdtempSync(join(tmpdir(), "rig-pi-frontend-sessions-"));
|
|
1530
|
+
const restoreEnv = setTemporaryEnv({
|
|
1531
|
+
PI_CODING_AGENT_SESSION_DIR: tempSessionDir,
|
|
1532
|
+
PI_SKIP_VERSION_CHECK: "1"
|
|
777
1533
|
});
|
|
778
|
-
|
|
779
|
-
|
|
1534
|
+
const controller = new RigRemoteSessionController({ context, runId: input.runId });
|
|
1535
|
+
const createRemoteRuntime = async ({ cwd, agentDir, sessionManager, sessionStartEvent }) => {
|
|
1536
|
+
const services = await createAgentSessionServices({
|
|
1537
|
+
cwd,
|
|
1538
|
+
agentDir,
|
|
1539
|
+
resourceLoaderOptions: {
|
|
1540
|
+
extensionFactories: [
|
|
1541
|
+
createRigWorkerPiBridgeExtension({
|
|
1542
|
+
context,
|
|
1543
|
+
controller,
|
|
1544
|
+
runId: input.runId,
|
|
1545
|
+
initialMessageSent: input.steered === true
|
|
1546
|
+
})
|
|
1547
|
+
],
|
|
1548
|
+
noContextFiles: true
|
|
1549
|
+
}
|
|
1550
|
+
});
|
|
1551
|
+
const created = await createAgentSessionFromServices({
|
|
1552
|
+
services,
|
|
1553
|
+
sessionManager,
|
|
1554
|
+
sessionStartEvent,
|
|
1555
|
+
noTools: "all",
|
|
1556
|
+
sessionFactory: (config) => new RigRemoteAgentSession(config, controller)
|
|
1557
|
+
});
|
|
1558
|
+
return { ...created, services, diagnostics: services.diagnostics };
|
|
1559
|
+
};
|
|
1560
|
+
let detached = false;
|
|
1561
|
+
try {
|
|
1562
|
+
await runPiMain([], {
|
|
1563
|
+
createRuntimeOverride: () => createRemoteRuntime
|
|
1564
|
+
});
|
|
1565
|
+
detached = true;
|
|
1566
|
+
} finally {
|
|
1567
|
+
restoreEnv();
|
|
1568
|
+
controller.close();
|
|
1569
|
+
rmSync(tempSessionDir, { recursive: true, force: true });
|
|
1570
|
+
}
|
|
1571
|
+
let run = { runId: input.runId, status: "unknown" };
|
|
1572
|
+
try {
|
|
1573
|
+
run = await getRunDetailsViaServer(context, input.runId);
|
|
1574
|
+
} catch {}
|
|
1575
|
+
return {
|
|
1576
|
+
run,
|
|
1577
|
+
logs: [],
|
|
1578
|
+
timeline: [],
|
|
1579
|
+
timelineCursor: null,
|
|
1580
|
+
steered: input.steered === true,
|
|
1581
|
+
detached,
|
|
1582
|
+
rendered: "native bundled Pi frontend with remote worker session runtime"
|
|
1583
|
+
};
|
|
780
1584
|
}
|
|
1585
|
+
|
|
1586
|
+
// packages/cli/src/commands/_operator-view.ts
|
|
1587
|
+
var TERMINAL_RUN_STATUSES2 = new Set(["completed", "failed", "stopped", "cancelled", "canceled", "closed", "merged", "needs_attention", "needs-attention"]);
|
|
781
1588
|
function runStatusFromPayload(payload) {
|
|
782
1589
|
const run = payload.run && typeof payload.run === "object" && !Array.isArray(payload.run) ? payload.run : payload;
|
|
783
1590
|
return String(run.status ?? "unknown").toLowerCase();
|
|
@@ -799,56 +1606,640 @@ async function applyOperatorCommand(context, input, deps = {}) {
|
|
|
799
1606
|
await (deps.steer ?? steerRunViaServer)(context, input.runId, userMessage);
|
|
800
1607
|
return { action: "continue", message: "Steering message queued." };
|
|
801
1608
|
}
|
|
802
|
-
async function readOperatorSnapshot(context, runId) {
|
|
1609
|
+
async function readOperatorSnapshot(context, runId, options = {}) {
|
|
803
1610
|
const run = await getRunDetailsViaServer(context, runId);
|
|
804
1611
|
const logsPage = await getRunLogsViaServer(context, runId, { limit: 100 });
|
|
805
|
-
const
|
|
806
|
-
|
|
1612
|
+
const timelinePage = await getRunTimelineViaServer(context, runId, { limit: 200, ...options.timelineCursor ? { cursor: options.timelineCursor } : {} }).catch((error) => ({
|
|
1613
|
+
entries: [{
|
|
1614
|
+
id: `timeline-unavailable:${runId}`,
|
|
1615
|
+
type: "timeline_warning",
|
|
1616
|
+
detail: `Selected Rig server did not provide run timeline events: ${error instanceof Error ? error.message : String(error)}`,
|
|
1617
|
+
createdAt: new Date().toISOString()
|
|
1618
|
+
}],
|
|
1619
|
+
nextCursor: options.timelineCursor ?? null
|
|
1620
|
+
}));
|
|
1621
|
+
const logs = Array.isArray(logsPage.entries) ? logsPage.entries.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry))).toReversed() : [];
|
|
1622
|
+
const timeline = Array.isArray(timelinePage.entries) ? timelinePage.entries.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry))) : [];
|
|
1623
|
+
const timelineCursor = typeof timelinePage.nextCursor === "string" ? timelinePage.nextCursor : options.timelineCursor ?? null;
|
|
1624
|
+
return { run, logs, timeline, timelineCursor, rendered: renderOperatorSnapshot({ run, logs, timeline }) };
|
|
807
1625
|
}
|
|
808
1626
|
async function attachRunOperatorView(context, input) {
|
|
809
1627
|
let steered = false;
|
|
810
1628
|
if (input.message?.trim()) {
|
|
811
|
-
await steerRunViaServer(context, input.runId, input.message.trim());
|
|
1629
|
+
await sendRunPiPromptViaServer(context, input.runId, input.message.trim(), "steer").catch(() => steerRunViaServer(context, input.runId, input.message.trim()));
|
|
812
1630
|
steered = true;
|
|
813
1631
|
}
|
|
1632
|
+
if (input.follow && !input.once && input.interactive !== false && context.outputMode === "text" && Boolean(process.stdin.isTTY && process.stdout.isTTY)) {
|
|
1633
|
+
return attachRunBundledPiFrontend(context, {
|
|
1634
|
+
runId: input.runId,
|
|
1635
|
+
steered
|
|
1636
|
+
});
|
|
1637
|
+
}
|
|
1638
|
+
const surface = createOperatorSurface({ interactive: input.interactive !== false });
|
|
814
1639
|
let snapshot = await readOperatorSnapshot(context, input.runId);
|
|
815
1640
|
if (context.outputMode === "text") {
|
|
816
|
-
|
|
1641
|
+
surface.renderSnapshot(snapshot);
|
|
1642
|
+
surface.renderTimeline(snapshot.timeline);
|
|
1643
|
+
surface.renderLogs(snapshot.logs);
|
|
817
1644
|
if (steered)
|
|
818
|
-
|
|
1645
|
+
surface.info("Message submitted to worker Pi.");
|
|
819
1646
|
}
|
|
820
1647
|
let detached = false;
|
|
821
|
-
let
|
|
1648
|
+
let commandInput = null;
|
|
822
1649
|
if (input.follow && !input.once && context.outputMode === "text") {
|
|
823
1650
|
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)}`));
|
|
1651
|
+
surface.info("Controls: /user <message>, /stop, /detach");
|
|
1652
|
+
commandInput = surface.attachCommandInput(async (line) => {
|
|
1653
|
+
const result = await applyOperatorCommand(context, { runId: input.runId, line });
|
|
1654
|
+
if (result.message)
|
|
1655
|
+
surface.info(result.message);
|
|
1656
|
+
if (result.action === "detach" || result.action === "stopped") {
|
|
1657
|
+
detached = true;
|
|
1658
|
+
commandInput?.close();
|
|
1659
|
+
}
|
|
835
1660
|
});
|
|
836
1661
|
}
|
|
837
|
-
let lastRendered = snapshot.rendered;
|
|
838
1662
|
const pollMs = Math.max(250, Math.trunc(input.pollMs ?? 2000));
|
|
839
|
-
|
|
1663
|
+
let timelineCursor = snapshot.timelineCursor;
|
|
1664
|
+
while (!detached && !TERMINAL_RUN_STATUSES2.has(runStatusFromPayload(snapshot.run))) {
|
|
840
1665
|
await Bun.sleep(pollMs);
|
|
841
|
-
snapshot = await readOperatorSnapshot(context, input.runId);
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
1666
|
+
snapshot = await readOperatorSnapshot(context, input.runId, { timelineCursor });
|
|
1667
|
+
timelineCursor = snapshot.timelineCursor;
|
|
1668
|
+
surface.renderSnapshot(snapshot);
|
|
1669
|
+
surface.renderTimeline(snapshot.timeline);
|
|
1670
|
+
surface.renderLogs(snapshot.logs);
|
|
846
1671
|
}
|
|
847
|
-
|
|
1672
|
+
commandInput?.close();
|
|
848
1673
|
}
|
|
849
1674
|
return { ...snapshot, steered, detached };
|
|
850
1675
|
}
|
|
851
1676
|
|
|
1677
|
+
// packages/cli/src/commands/_cli-format.ts
|
|
1678
|
+
import { log, note } from "@clack/prompts";
|
|
1679
|
+
import pc from "picocolors";
|
|
1680
|
+
function stringField(record, key, fallback = "") {
|
|
1681
|
+
const value = record[key];
|
|
1682
|
+
return typeof value === "string" && value.trim() ? value.trim() : fallback;
|
|
1683
|
+
}
|
|
1684
|
+
function numberField(record, key) {
|
|
1685
|
+
const value = record[key];
|
|
1686
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
1687
|
+
}
|
|
1688
|
+
function arrayField(record, key) {
|
|
1689
|
+
const value = record[key];
|
|
1690
|
+
return Array.isArray(value) ? value.flatMap((entry) => typeof entry === "string" && entry.trim() ? [entry.trim()] : []) : [];
|
|
1691
|
+
}
|
|
1692
|
+
function rawObject(record) {
|
|
1693
|
+
const raw = record.raw;
|
|
1694
|
+
return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
1695
|
+
}
|
|
1696
|
+
function truncate(value, width) {
|
|
1697
|
+
if (value.length <= width)
|
|
1698
|
+
return value;
|
|
1699
|
+
if (width <= 1)
|
|
1700
|
+
return "\u2026";
|
|
1701
|
+
return `${value.slice(0, width - 1)}\u2026`;
|
|
1702
|
+
}
|
|
1703
|
+
function pad(value, width) {
|
|
1704
|
+
return value.length >= width ? value : `${value}${" ".repeat(width - value.length)}`;
|
|
1705
|
+
}
|
|
1706
|
+
function statusColor(status) {
|
|
1707
|
+
const normalized = status.toLowerCase();
|
|
1708
|
+
if (["completed", "merged", "closed", "done", "accepted", "pass", "selected", "approved"].includes(normalized))
|
|
1709
|
+
return pc.green;
|
|
1710
|
+
if (["failed", "needs_attention", "needs-attention", "blocked", "error", "rejected"].includes(normalized))
|
|
1711
|
+
return pc.red;
|
|
1712
|
+
if (["running", "reviewing", "validating", "in_progress", "in-progress", "remote"].includes(normalized))
|
|
1713
|
+
return pc.cyan;
|
|
1714
|
+
if (["ready", "open", "queued", "created", "preparing", "local", "pending"].includes(normalized))
|
|
1715
|
+
return pc.yellow;
|
|
1716
|
+
return pc.dim;
|
|
1717
|
+
}
|
|
1718
|
+
function compactValue(value) {
|
|
1719
|
+
if (value === null || value === undefined)
|
|
1720
|
+
return "";
|
|
1721
|
+
if (typeof value === "string")
|
|
1722
|
+
return value;
|
|
1723
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
1724
|
+
return String(value);
|
|
1725
|
+
if (Array.isArray(value))
|
|
1726
|
+
return value.map(compactValue).filter(Boolean).join(", ");
|
|
1727
|
+
return JSON.stringify(value);
|
|
1728
|
+
}
|
|
1729
|
+
function shouldUseClackOutput() {
|
|
1730
|
+
return Boolean(process.stdout.isTTY) && process.env.RIG_CLI_PLAIN_HELP !== "1";
|
|
1731
|
+
}
|
|
1732
|
+
function printFormattedOutput(message2, options = {}) {
|
|
1733
|
+
if (!shouldUseClackOutput()) {
|
|
1734
|
+
console.log(message2);
|
|
1735
|
+
return;
|
|
1736
|
+
}
|
|
1737
|
+
if (options.title)
|
|
1738
|
+
note(message2, options.title);
|
|
1739
|
+
else
|
|
1740
|
+
log.message(message2);
|
|
1741
|
+
}
|
|
1742
|
+
function formatStatusPill(status) {
|
|
1743
|
+
const label = status || "unknown";
|
|
1744
|
+
return statusColor(label)(`\u25CF ${label}`);
|
|
1745
|
+
}
|
|
1746
|
+
function formatSection(title, subtitle) {
|
|
1747
|
+
return `${pc.bold(pc.cyan("\u25C6"))} ${pc.bold(title)}${subtitle ? pc.dim(` \u2014 ${subtitle}`) : ""}`;
|
|
1748
|
+
}
|
|
1749
|
+
function formatSuccessCard(title, rows = []) {
|
|
1750
|
+
const body = rows.filter(([, value]) => value !== undefined && value !== null && String(value).length > 0).map(([key, value]) => `${pc.dim("\u2502")} ${pc.dim(key.padEnd(12))} ${value}`);
|
|
1751
|
+
return [formatSection(title), ...body].join(`
|
|
1752
|
+
`);
|
|
1753
|
+
}
|
|
1754
|
+
function formatNextSteps(steps) {
|
|
1755
|
+
if (steps.length === 0)
|
|
1756
|
+
return [];
|
|
1757
|
+
return [pc.bold("Next"), ...steps.map((step) => `${pc.dim("\u203A")} ${step}`)];
|
|
1758
|
+
}
|
|
1759
|
+
function formatTaskList(tasks, options = {}) {
|
|
1760
|
+
if (options.raw)
|
|
1761
|
+
return tasks.map((task) => JSON.stringify(task)).join(`
|
|
1762
|
+
`);
|
|
1763
|
+
if (tasks.length === 0)
|
|
1764
|
+
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(`
|
|
1765
|
+
`);
|
|
1766
|
+
const rows = tasks.map((task) => {
|
|
1767
|
+
const raw = rawObject(task);
|
|
1768
|
+
const id = stringField(task, "id", "<unknown>");
|
|
1769
|
+
const status = stringField(task, "status", "unknown");
|
|
1770
|
+
const title = stringField(task, "title", "Untitled task");
|
|
1771
|
+
const source = stringField(task, "source", stringField(raw, "source", ""));
|
|
1772
|
+
const labels = arrayField(task, "labels").length > 0 ? arrayField(task, "labels") : arrayField(raw, "labels");
|
|
1773
|
+
return { id, status, title, source, labels };
|
|
1774
|
+
});
|
|
1775
|
+
const idWidth = Math.min(18, Math.max(4, ...rows.map((row) => row.id.length)));
|
|
1776
|
+
const statusWidth = Math.min(16, Math.max(6, ...rows.map((row) => row.status.length)));
|
|
1777
|
+
const header = `${pc.bold(pad("TASK", idWidth))} ${pc.bold(pad("STATUS", statusWidth))} ${pc.bold("TITLE")}`;
|
|
1778
|
+
const body = rows.map((row) => {
|
|
1779
|
+
const labels = row.labels.length > 0 ? pc.dim(` ${row.labels.slice(0, 4).map((label) => `#${label}`).join(" ")}`) : "";
|
|
1780
|
+
const source = row.source ? pc.dim(` ${row.source}`) : "";
|
|
1781
|
+
return [
|
|
1782
|
+
pc.bold(pad(truncate(row.id, idWidth), idWidth)),
|
|
1783
|
+
statusColor(row.status)(pad(truncate(row.status, statusWidth), statusWidth)),
|
|
1784
|
+
`${row.title}${labels}${source}`
|
|
1785
|
+
].join(" ");
|
|
1786
|
+
});
|
|
1787
|
+
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(`
|
|
1788
|
+
`);
|
|
1789
|
+
}
|
|
1790
|
+
function formatTaskCard(task, options = {}) {
|
|
1791
|
+
const raw = rawObject(task);
|
|
1792
|
+
const id = stringField(task, "id", stringField(raw, "id", "<unknown>"));
|
|
1793
|
+
const status = stringField(task, "status", stringField(raw, "status", "unknown"));
|
|
1794
|
+
const title = stringField(task, "title", stringField(raw, "title", "Untitled task"));
|
|
1795
|
+
const source = stringField(task, "source", stringField(raw, "source", ""));
|
|
1796
|
+
const url = stringField(task, "url", stringField(raw, "url", ""));
|
|
1797
|
+
const number = numberField(task, "number") ?? numberField(raw, "number");
|
|
1798
|
+
const labels = arrayField(task, "labels").length > 0 ? arrayField(task, "labels") : arrayField(raw, "labels");
|
|
1799
|
+
const assignees = arrayField(task, "assignees").length > 0 ? arrayField(task, "assignees") : arrayField(raw, "assignees");
|
|
1800
|
+
const readiness = compactValue(task.readiness ?? raw.readiness);
|
|
1801
|
+
const validators = compactValue(task.validators ?? raw.validators ?? task.validation ?? raw.validation);
|
|
1802
|
+
const rows = [
|
|
1803
|
+
["task", pc.bold(id)],
|
|
1804
|
+
["status", formatStatusPill(status)],
|
|
1805
|
+
["title", title],
|
|
1806
|
+
["source", source],
|
|
1807
|
+
["number", number],
|
|
1808
|
+
["labels", labels.length ? labels.map((label) => `#${label}`).join(" ") : ""],
|
|
1809
|
+
["assignees", assignees.join(", ")],
|
|
1810
|
+
["readiness", readiness],
|
|
1811
|
+
["validators", validators],
|
|
1812
|
+
["url", url]
|
|
1813
|
+
];
|
|
1814
|
+
return [
|
|
1815
|
+
formatSuccessCard(options.title ?? (options.selected ? "Selected task" : "Task"), rows),
|
|
1816
|
+
"",
|
|
1817
|
+
...formatNextSteps([`Start: \`rig task run ${id}\``, `Details: \`rig task show ${id} --raw\``])
|
|
1818
|
+
].join(`
|
|
1819
|
+
`);
|
|
1820
|
+
}
|
|
1821
|
+
function formatTaskDetails(task) {
|
|
1822
|
+
return formatTaskCard(task, { title: "Task details" });
|
|
1823
|
+
}
|
|
1824
|
+
function formatSubmittedRun(input) {
|
|
1825
|
+
const rows = [["run", pc.bold(input.runId)]];
|
|
1826
|
+
if (input.task) {
|
|
1827
|
+
const id = stringField(input.task, "id", "<unknown>");
|
|
1828
|
+
const status = stringField(input.task, "status", "unknown");
|
|
1829
|
+
const title = stringField(input.task, "title", "Untitled task");
|
|
1830
|
+
rows.push(["task", `${pc.bold(id)} ${formatStatusPill(status)} ${title}`]);
|
|
1831
|
+
}
|
|
1832
|
+
const runtime = [input.runtimeAdapter || "pi", input.runtimeMode || "full-access", input.interactionMode || "default"].filter(Boolean).join(" \xB7 ");
|
|
1833
|
+
rows.push(["runtime", runtime]);
|
|
1834
|
+
return [
|
|
1835
|
+
formatSuccessCard("Run submitted", rows),
|
|
1836
|
+
"",
|
|
1837
|
+
...formatNextSteps([
|
|
1838
|
+
`Attach: \`rig run attach ${input.runId} --follow\``,
|
|
1839
|
+
`Inspect: \`rig run show ${input.runId}\``,
|
|
1840
|
+
input.detached ? "Submitted detached; attach when you are ready." : "Interactive mode opens the native bundled Pi frontend."
|
|
1841
|
+
])
|
|
1842
|
+
].join(`
|
|
1843
|
+
`);
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
// packages/cli/src/commands/_help-catalog.ts
|
|
1847
|
+
import { intro, log as log2, note as note2, outro } from "@clack/prompts";
|
|
1848
|
+
import pc2 from "picocolors";
|
|
1849
|
+
var TOP_LEVEL_SECTIONS = [
|
|
1850
|
+
{
|
|
1851
|
+
title: "Start here",
|
|
1852
|
+
subtitle: "one-time setup for a repo",
|
|
1853
|
+
commands: [
|
|
1854
|
+
{ command: "rig init", description: "Wizard: config, GitHub auth, task source, server, Pi wiring." },
|
|
1855
|
+
{ command: "rig doctor", description: "Check every part of the wiring \u2014 run this when anything feels off." },
|
|
1856
|
+
{ command: "rig server use <alias|local>", description: "Pick which Rig server owns this repo (`rig server list` to see them)." }
|
|
1857
|
+
]
|
|
1858
|
+
},
|
|
1859
|
+
{
|
|
1860
|
+
title: "Work",
|
|
1861
|
+
subtitle: "find a task and put an agent on it",
|
|
1862
|
+
commands: [
|
|
1863
|
+
{ command: "rig task list", description: "What's on the board (from the selected source/server)." },
|
|
1864
|
+
{ command: "rig task next", description: "The next ready task, as a card." },
|
|
1865
|
+
{ command: "rig task run --next", description: "Dispatch an agent; interactive mode opens the native Pi session." },
|
|
1866
|
+
{ command: "rig task run <id> --detach", description: "Fire-and-forget a specific task." }
|
|
1867
|
+
]
|
|
1868
|
+
},
|
|
1869
|
+
{
|
|
1870
|
+
title: "Watch & steer",
|
|
1871
|
+
subtitle: "live runs are observable and steerable, attached or not",
|
|
1872
|
+
commands: [
|
|
1873
|
+
{ command: "rig run status", description: "Active and recent runs at a glance." },
|
|
1874
|
+
{ command: "rig run attach <id> --follow", description: "Join the live Pi session (worker keeps running if you /detach)." },
|
|
1875
|
+
{ command: "rig run steer <id> -m <text>", description: "Drop a message into a live worker without attaching." },
|
|
1876
|
+
{ command: "rig run stop <id>", description: "Cancel a running worker." }
|
|
1877
|
+
]
|
|
1878
|
+
},
|
|
1879
|
+
{
|
|
1880
|
+
title: "Unblock & gate",
|
|
1881
|
+
subtitle: "answer what workers ask; control what merges",
|
|
1882
|
+
commands: [
|
|
1883
|
+
{ command: "rig inbox approvals", description: "Approvals workers are waiting on (then `rig inbox approve \u2026`)." },
|
|
1884
|
+
{ command: "rig inbox inputs", description: "Questions workers asked (then `rig inbox respond \u2026`)." },
|
|
1885
|
+
{ command: "rig review show|set", description: "The completion review gate (Greptile is mandatory on merges)." }
|
|
1886
|
+
]
|
|
1887
|
+
},
|
|
1888
|
+
{
|
|
1889
|
+
title: "Extend",
|
|
1890
|
+
subtitle: "more Pi, more plugins",
|
|
1891
|
+
commands: [
|
|
1892
|
+
{ command: "rig pi search <term>", description: "Discover community Pi extensions on npm." },
|
|
1893
|
+
{ command: "rig pi add <pkg>", description: "Add a Pi extension to this project (workers pick it up too)." },
|
|
1894
|
+
{ command: "rig plugin list", description: "What the rig.config.ts plugins contribute." }
|
|
1895
|
+
]
|
|
1896
|
+
}
|
|
1897
|
+
];
|
|
1898
|
+
var PRIMARY_GROUPS = [
|
|
1899
|
+
{
|
|
1900
|
+
name: "server",
|
|
1901
|
+
summary: "Choose, inspect, and start the Rig server that owns tasks and runs.",
|
|
1902
|
+
usage: ["rig server <status|list|add|use|start> [options]"],
|
|
1903
|
+
commands: [
|
|
1904
|
+
{ command: "status", description: "Show the selected server for this repo.", primary: true },
|
|
1905
|
+
{ command: "use local", description: "Switch this repo to the local Rig server.", primary: true },
|
|
1906
|
+
{ command: "add <alias> <url>", description: "Save a remote Rig server URL.", primary: true },
|
|
1907
|
+
{ command: "use <alias>", description: "Select a saved remote server alias.", primary: true },
|
|
1908
|
+
{ command: "list", description: "List saved local/remote server aliases.", primary: true },
|
|
1909
|
+
{ command: "start [--host <host>] [--port <n>]", description: "Start a local rig-server process." }
|
|
1910
|
+
],
|
|
1911
|
+
examples: [
|
|
1912
|
+
"rig server status",
|
|
1913
|
+
"rig server add prod https://where.rig-does.work",
|
|
1914
|
+
"rig server use prod",
|
|
1915
|
+
"rig server use local",
|
|
1916
|
+
"rig server start --port 3773"
|
|
1917
|
+
],
|
|
1918
|
+
next: ["Use `rig task list` to see server-owned work.", "Use `rig run list` or `rig run attach <id> --follow` to monitor runs."],
|
|
1919
|
+
advanced: ["Compatibility alias: `rig connect ...` remains callable."]
|
|
1920
|
+
},
|
|
1921
|
+
{
|
|
1922
|
+
name: "task",
|
|
1923
|
+
summary: "Find work, start Pi-backed runs, and validate task results.",
|
|
1924
|
+
usage: ["rig task <list|next|show|run> [options]"],
|
|
1925
|
+
commands: [
|
|
1926
|
+
{ command: "list [--assignee <login|@me>] [--state open|closed]", description: "List tasks from the selected server/source.", primary: true },
|
|
1927
|
+
{ command: "next [filters]", description: "Render the next matching task as a selected-task card.", primary: true },
|
|
1928
|
+
{ command: "show <id>|--task <id> [--raw]", description: "Show a human task summary; --raw prints the full payload.", primary: true },
|
|
1929
|
+
{ command: "run [#<issue>|<task-id>|--next|--task <id>]", description: "Submit a task run; interactive follows with bundled Pi.", primary: true },
|
|
1930
|
+
{ command: "validate|verify [--task <id>]", description: "Run configured task checks/review gates." },
|
|
1931
|
+
{ command: "details --task <id>", description: "Show full task info from the configured source." },
|
|
1932
|
+
{ command: "reopen [--task <id> | --all] [--reason <text>]", description: "Reopen closed task(s) in the configured source." },
|
|
1933
|
+
{ command: "reset --task <id>", description: "Compatibility spelling of `reopen --task <id>`." },
|
|
1934
|
+
{ command: "artifacts|artifact-dir|artifact-write", description: "Inspect or write task artifacts." },
|
|
1935
|
+
{ command: "report-bug", description: "Create a structured bug report/task." }
|
|
1936
|
+
],
|
|
1937
|
+
examples: [
|
|
1938
|
+
"rig task list --assignee @me --limit 20",
|
|
1939
|
+
"rig task next",
|
|
1940
|
+
"rig task show 123 --raw",
|
|
1941
|
+
"rig task run --next",
|
|
1942
|
+
"rig task run #123 --runtime-adapter pi",
|
|
1943
|
+
"rig task run --title 'Investigate deploy drift' --initial-prompt 'Check server health'"
|
|
1944
|
+
],
|
|
1945
|
+
next: ["Use `--detach` to submit without attaching.", "Use `rig run attach <run-id> --follow` to rejoin a live run."]
|
|
1946
|
+
},
|
|
1947
|
+
{
|
|
1948
|
+
name: "run",
|
|
1949
|
+
summary: "Observe, attach to, and control Rig runs.",
|
|
1950
|
+
usage: ["rig run <list|status|show|attach|stop> [options]"],
|
|
1951
|
+
commands: [
|
|
1952
|
+
{ command: "list", description: "List recent runs from the selected server or local state.", primary: true },
|
|
1953
|
+
{ command: "status", description: "Render active and recent run groups.", primary: true },
|
|
1954
|
+
{ command: "show <id>|--run <id> [--raw]", description: "Show a human run summary; --raw prints the full payload.", primary: true },
|
|
1955
|
+
{ command: "attach <run-id>|--run <id> [--follow]", description: "Attach to the run; --follow launches native bundled Pi for live Pi runs.", primary: true },
|
|
1956
|
+
{ command: "stop [<run-id>|--run <id>]", description: "Request stop for one run or local active runs.", primary: true },
|
|
1957
|
+
{ command: "steer <run-id> --message <text>", description: "Queue a steering message into a live worker without attaching." },
|
|
1958
|
+
{ command: "timeline --run <id> [--follow]", description: "Stream raw run timeline events." },
|
|
1959
|
+
{ command: "resume", description: "Resume the most recent interrupted local run." },
|
|
1960
|
+
{ command: "restart", description: "Restart the most recent local run from a clean runtime." },
|
|
1961
|
+
{ command: "delete|cleanup", description: "Remove completed run records/artifacts." }
|
|
1962
|
+
],
|
|
1963
|
+
examples: [
|
|
1964
|
+
"rig run list",
|
|
1965
|
+
"rig run status",
|
|
1966
|
+
"rig run show <run-id>",
|
|
1967
|
+
"rig run attach <run-id> --follow",
|
|
1968
|
+
"rig run stop <run-id>"
|
|
1969
|
+
],
|
|
1970
|
+
next: ["Use `rig task run --next` to create a new run.", "Use `--json` when scripts need the full structured record."]
|
|
1971
|
+
},
|
|
1972
|
+
{
|
|
1973
|
+
name: "inbox",
|
|
1974
|
+
summary: "Review approval and user-input requests that block worker runs.",
|
|
1975
|
+
usage: ["rig inbox <approvals|approve|inputs|respond> [options]"],
|
|
1976
|
+
commands: [
|
|
1977
|
+
{ command: "approvals [--run <id>] [--task <id>]", description: "List pending approvals.", primary: true },
|
|
1978
|
+
{ command: "inputs [--run <id>] [--task <id>]", description: "List pending user-input requests.", primary: true },
|
|
1979
|
+
{ command: "approve --run <id> --request <id> --decision approve|reject", description: "Resolve an approval request." },
|
|
1980
|
+
{ command: "respond --run <id> --request <id> --answer key=value", description: "Answer a user-input request." }
|
|
1981
|
+
],
|
|
1982
|
+
examples: [
|
|
1983
|
+
"rig inbox approvals",
|
|
1984
|
+
"rig inbox inputs --run <run-id>",
|
|
1985
|
+
"rig inbox approve --run <run-id> --request <request-id> --decision approve"
|
|
1986
|
+
],
|
|
1987
|
+
next: ["Rejoin the run after resolving a block: `rig run attach <run-id> --follow`."]
|
|
1988
|
+
},
|
|
1989
|
+
{
|
|
1990
|
+
name: "review",
|
|
1991
|
+
summary: "Inspect or change completion review gate policy.",
|
|
1992
|
+
usage: ["rig review <show|set>"],
|
|
1993
|
+
commands: [
|
|
1994
|
+
{ command: "show", description: "Show current review gate settings.", primary: true },
|
|
1995
|
+
{ command: "set <off|advisory|required> [--provider greptile]", description: "Change review strictness/provider.", primary: true }
|
|
1996
|
+
],
|
|
1997
|
+
examples: ["rig review show", "rig review set required --provider greptile"],
|
|
1998
|
+
next: ["Use `rig inbox approvals` for blocked run handoffs."]
|
|
1999
|
+
},
|
|
2000
|
+
{
|
|
2001
|
+
name: "init",
|
|
2002
|
+
summary: "Set up Rig for this repo: server, GitHub auth, checkout strategy, task source, and Pi wiring.",
|
|
2003
|
+
usage: ["rig init [--yes] [--server local|remote] [--repo owner/repo] [--remote-url <url>]"],
|
|
2004
|
+
commands: [
|
|
2005
|
+
{ command: "init", description: "Interactive setup wizard for a new or existing Rig repo.", primary: true },
|
|
2006
|
+
{ command: "init --yes", description: "Non-interactive setup using detected/default settings.", primary: true },
|
|
2007
|
+
{ command: "init --server remote --remote-url <url>", description: "Link this repo to a remote Rig server.", primary: true },
|
|
2008
|
+
{ command: "init --repair", description: "Repair missing private state without replacing project config." }
|
|
2009
|
+
],
|
|
2010
|
+
examples: [
|
|
2011
|
+
"rig init",
|
|
2012
|
+
"rig init --yes --repo humanity-org/humanwork",
|
|
2013
|
+
"rig init --server remote --remote-url https://where.rig-does.work --repo owner/repo"
|
|
2014
|
+
],
|
|
2015
|
+
next: ["After init, run `rig server status`.", "Then use `rig task list` and `rig task run --next` for day-to-day work."]
|
|
2016
|
+
},
|
|
2017
|
+
{
|
|
2018
|
+
name: "doctor",
|
|
2019
|
+
summary: "Diagnostics for project/server/GitHub/Pi state.",
|
|
2020
|
+
usage: ["rig doctor"],
|
|
2021
|
+
commands: [
|
|
2022
|
+
{ command: "doctor", description: "Run setup and runtime diagnostics.", primary: true },
|
|
2023
|
+
{ command: "check", description: "Compatibility spelling for diagnostics." }
|
|
2024
|
+
],
|
|
2025
|
+
examples: ["rig doctor", "rig doctor --json"],
|
|
2026
|
+
next: ["Use `rig server status` and `rig github auth status` to inspect common failure points."]
|
|
2027
|
+
},
|
|
2028
|
+
{
|
|
2029
|
+
name: "github",
|
|
2030
|
+
summary: "GitHub auth helpers for the selected Rig server.",
|
|
2031
|
+
usage: ["rig github auth <status|import-gh|token>"],
|
|
2032
|
+
commands: [
|
|
2033
|
+
{ command: "auth status", description: "Show GitHub auth state.", primary: true },
|
|
2034
|
+
{ command: "auth import-gh", description: "Import the current `gh` token into the selected server." },
|
|
2035
|
+
{ command: "auth token --token <token>", description: "Store a token on the selected server." }
|
|
2036
|
+
],
|
|
2037
|
+
examples: ["rig github auth status", "rig github auth import-gh"],
|
|
2038
|
+
next: ["After auth is valid, use `rig task run --next`."]
|
|
2039
|
+
}
|
|
2040
|
+
];
|
|
2041
|
+
var ADVANCED_GROUPS = [
|
|
2042
|
+
{ name: "connect", summary: "Compatibility alias for `rig server` selection commands.", usage: ["rig connect <status|list|add|use>"], commands: [{ command: "status|list|add|use", description: "Use `rig server ...` for the primary UX." }] },
|
|
2043
|
+
{ name: "setup", summary: "Bootstrap/check local setup.", usage: ["rig setup <bootstrap|check|preflight>"], commands: [{ command: "bootstrap|check|preflight", description: "Setup helpers." }] },
|
|
2044
|
+
{
|
|
2045
|
+
name: "inspect",
|
|
2046
|
+
summary: "Inspect logs, artifacts, graphs, failures for a task.",
|
|
2047
|
+
usage: ["rig inspect <logs|artifacts|failures|graph|audit|diff> --task <id>"],
|
|
2048
|
+
commands: [
|
|
2049
|
+
{ command: "logs --task <id>", description: "Latest run log for a task (local or selected server)." },
|
|
2050
|
+
{ command: "artifacts --task <id>", description: "List the task's completion artifacts." },
|
|
2051
|
+
{ command: "failures --task <id>", description: "Recorded failures for a task." },
|
|
2052
|
+
{ command: "graph", description: "Task dependency graph." },
|
|
2053
|
+
{ command: "audit", description: "Controlled-command audit trail." },
|
|
2054
|
+
{ command: "diff --task <id>", description: "Changed files for a task." }
|
|
2055
|
+
]
|
|
2056
|
+
},
|
|
2057
|
+
{ name: "repo", summary: "Repository sync/baseline helpers.", usage: ["rig repo <sync|reset-baseline>"], commands: [{ command: "sync", description: "Sync project repository state." }] },
|
|
2058
|
+
{ name: "profile", summary: "Runtime profile/model defaults.", usage: ["rig profile <show|set>"], commands: [{ command: "show", description: "Show active profile." }] },
|
|
2059
|
+
{
|
|
2060
|
+
name: "browser",
|
|
2061
|
+
summary: "Browser/app diagnostics for browser-required tasks.",
|
|
2062
|
+
usage: ["rig browser <help|explain|demo|app|hp-next> [options]"],
|
|
2063
|
+
commands: [
|
|
2064
|
+
{ command: "help", description: "Rich browser command help (canonical: `rig browser help`)." },
|
|
2065
|
+
{ command: "explain", description: "Explain the browser-required task contract." },
|
|
2066
|
+
{ command: "demo", description: "Run browser demo flows against a local page." },
|
|
2067
|
+
{ command: "app", description: "Launch the Rig Browser workstation app." },
|
|
2068
|
+
{ command: "hp-next <dev|check|e2e|reset>", description: "Drive the hp-next browser test harness." }
|
|
2069
|
+
]
|
|
2070
|
+
},
|
|
2071
|
+
{
|
|
2072
|
+
name: "pi",
|
|
2073
|
+
summary: "Manage Pi extension packages for this project (community extensions from npm/git).",
|
|
2074
|
+
usage: ["rig pi <list|add|remove|search> [args]"],
|
|
2075
|
+
commands: [
|
|
2076
|
+
{ command: "list", description: "Show project and user Pi extension packages." },
|
|
2077
|
+
{ command: "add <source>", description: "Add an npm/git Pi extension to .pi/settings.json (auto-installs at next session)." },
|
|
2078
|
+
{ command: "remove <source>", description: "Remove an operator-added Pi extension." },
|
|
2079
|
+
{ command: "search [term]", description: "Discover Pi extension packages on the npm registry." }
|
|
2080
|
+
],
|
|
2081
|
+
examples: ["rig pi search subagents", "rig pi add pi-subagents", "rig pi list"],
|
|
2082
|
+
next: ["Config-managed extensions: declare `runtime: { pi: { packages: [...] } }` in rig.config.ts \u2014 workers pick them up automatically."]
|
|
2083
|
+
},
|
|
2084
|
+
{
|
|
2085
|
+
name: "plugin",
|
|
2086
|
+
summary: "Plugin listing, validation, and plugin-contributed commands.",
|
|
2087
|
+
usage: ["rig plugin <list|validate|run> [options]"],
|
|
2088
|
+
commands: [
|
|
2089
|
+
{ command: "list", description: "List plugins declared in rig.config.ts and their contributions." },
|
|
2090
|
+
{ command: "validate --task <id>", description: "Run plugin-contributed validators for a task." },
|
|
2091
|
+
{ command: "run <command-id> [args...]", description: "Execute a plugin-contributed CLI command (also callable as `rig <command-id>`)." }
|
|
2092
|
+
]
|
|
2093
|
+
},
|
|
2094
|
+
{ name: "queue", summary: "Run task queues locally.", usage: ["rig queue run [options]"], commands: [{ command: "run", description: "Process queue work." }] },
|
|
2095
|
+
{ name: "agent", summary: "Runtime agent workspace helpers.", usage: ["rig agent <list|prepare|run|cleanup>"], commands: [{ command: "list", description: "List prepared agents." }] },
|
|
2096
|
+
{ name: "inspector", summary: "Event stream and drift scanners.", usage: ["rig inspector <stream|scan-upstream-drift>"], commands: [{ command: "stream", description: "Stream events." }] },
|
|
2097
|
+
{ name: "dist", summary: "Build/install packaged Rig CLI.", usage: ["rig dist <build|install|doctor>"], commands: [{ command: "build", description: "Build distribution." }] },
|
|
2098
|
+
{ name: "workspace", summary: "Workspace topology/service helpers.", usage: ["rig workspace <summary|topology|remote-hosts>"], commands: [{ command: "summary", description: "Show workspace summary." }] },
|
|
2099
|
+
{ name: "remote", summary: "Compatibility remote orchestration controls.", usage: ["rig remote <status|watch|pause|resume|...>"], commands: [{ command: "status", description: "Show remote state." }] },
|
|
2100
|
+
{ name: "git", summary: "Pass through to Rig git-flow helper.", usage: ["rig git <args...>"], commands: [{ command: "<args...>", description: "Advanced git flow operations." }] },
|
|
2101
|
+
{ name: "harness", summary: "Pass through to runtime harness CLI.", usage: ["rig harness <args...>"], commands: [{ command: "<args...>", description: "Advanced harness operations." }] },
|
|
2102
|
+
{ name: "test", summary: "Project test wrappers.", usage: ["rig test <unit|e2e|all>"], commands: [{ command: "all", description: "Run configured project tests." }] }
|
|
2103
|
+
];
|
|
2104
|
+
var ALL_GROUPS = [...PRIMARY_GROUPS, ...ADVANCED_GROUPS];
|
|
2105
|
+
function heading(title) {
|
|
2106
|
+
return pc2.bold(pc2.cyan(title));
|
|
2107
|
+
}
|
|
2108
|
+
function renderRigBanner(version) {
|
|
2109
|
+
const m = (s) => pc2.bold(pc2.magenta(s));
|
|
2110
|
+
const c = (s) => pc2.bold(pc2.cyan(s));
|
|
2111
|
+
const y = (s) => pc2.yellow(s);
|
|
2112
|
+
const d = (s) => pc2.dim(s);
|
|
2113
|
+
const lines = [
|
|
2114
|
+
m(" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 ") + d(" \u2591\u2592\u2593\u2588 "),
|
|
2115
|
+
m(" \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D ") + d("\u2593\u2592\u2591"),
|
|
2116
|
+
c(" \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2557") + d(" \u2591\u2592"),
|
|
2117
|
+
c(" \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551") + d(" \u2588\u2593\u2591"),
|
|
2118
|
+
y(" \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D") + d(" \u2592\u2591"),
|
|
2119
|
+
y(" \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D "),
|
|
2120
|
+
"",
|
|
2121
|
+
` ${c("\u25E2\u25E4")} ${pc2.bold("the control rig for autonomous coding agents")} ${m("//")} ${d("you are the operator")}`,
|
|
2122
|
+
version ? ` ${d(`v${version} \xB7 jack in: rig task run --next`)}` : ` ${d("jack in: rig task run --next")}`
|
|
2123
|
+
];
|
|
2124
|
+
return lines.join(`
|
|
2125
|
+
`);
|
|
2126
|
+
}
|
|
2127
|
+
function commandLine(command, description) {
|
|
2128
|
+
const commandColumn = command.length >= 38 ? `${command} ` : command.padEnd(38);
|
|
2129
|
+
return `${pc2.dim("\u2502")} ${pc2.bold(commandColumn)} ${description}`;
|
|
2130
|
+
}
|
|
2131
|
+
function renderCommandBlock(commands) {
|
|
2132
|
+
return commands.map((entry) => commandLine(entry.command, entry.description)).join(`
|
|
2133
|
+
`);
|
|
2134
|
+
}
|
|
2135
|
+
function renderGroup(group) {
|
|
2136
|
+
const lines = [
|
|
2137
|
+
`${heading(`rig ${group.name}`)} \u2014 ${group.summary}`,
|
|
2138
|
+
"",
|
|
2139
|
+
pc2.bold("Usage"),
|
|
2140
|
+
...group.usage.map((line) => ` ${line}`),
|
|
2141
|
+
"",
|
|
2142
|
+
pc2.bold("Commands"),
|
|
2143
|
+
...group.commands.map((entry) => commandLine(entry.command, entry.description))
|
|
2144
|
+
];
|
|
2145
|
+
if (group.examples?.length) {
|
|
2146
|
+
lines.push("", pc2.bold("Examples"), ...group.examples.map((line) => ` ${pc2.dim("$")} ${line}`));
|
|
2147
|
+
}
|
|
2148
|
+
if (group.next?.length) {
|
|
2149
|
+
lines.push("", pc2.bold("Next steps"), ...group.next.map((line) => ` ${pc2.dim("\u203A")} ${line}`));
|
|
2150
|
+
}
|
|
2151
|
+
if (group.advanced?.length) {
|
|
2152
|
+
lines.push("", pc2.bold("Compatibility / advanced"), ...group.advanced.map((line) => ` ${pc2.dim("\u203A")} ${line}`));
|
|
2153
|
+
}
|
|
2154
|
+
return lines.join(`
|
|
2155
|
+
`);
|
|
2156
|
+
}
|
|
2157
|
+
function renderTopLevelHelp() {
|
|
2158
|
+
return [
|
|
2159
|
+
`${heading("rig")} ${pc2.dim("\u2014 server-owned task/run control plane for Pi-backed engineering work")}`,
|
|
2160
|
+
pc2.dim("Current path: select a server, choose a task, submit a run, attach with native Pi, clear inbox/review gates."),
|
|
2161
|
+
"",
|
|
2162
|
+
...TOP_LEVEL_SECTIONS.flatMap((section) => [
|
|
2163
|
+
`${pc2.bold(pc2.magenta(`\u25C7 ${section.title}`))} \u2014 ${pc2.dim(section.subtitle)}`,
|
|
2164
|
+
renderCommandBlock(section.commands),
|
|
2165
|
+
""
|
|
2166
|
+
]),
|
|
2167
|
+
pc2.dim("More: `rig help --advanced` for dev/compatibility commands; `rig <group> --help` for rich per-group help; `rig --version` for the installed version."),
|
|
2168
|
+
"",
|
|
2169
|
+
pc2.bold("Global options"),
|
|
2170
|
+
commandLine("--project <path>", "Use a project root instead of auto-discovery."),
|
|
2171
|
+
commandLine("--json", "Emit structured output for scripts/agents."),
|
|
2172
|
+
commandLine("--dry-run", "Print the command plan without mutating state.")
|
|
2173
|
+
].join(`
|
|
2174
|
+
`).trimEnd();
|
|
2175
|
+
}
|
|
2176
|
+
function renderGroupHelp(groupName) {
|
|
2177
|
+
const group = ALL_GROUPS.find((candidate) => candidate.name === groupName);
|
|
2178
|
+
return group ? renderGroup(group) : null;
|
|
2179
|
+
}
|
|
2180
|
+
function shouldUseClackOutput2() {
|
|
2181
|
+
return Boolean(process.stdout.isTTY) && process.env.RIG_CLI_PLAIN_HELP !== "1";
|
|
2182
|
+
}
|
|
2183
|
+
function printTopLevelHelp(state = {}) {
|
|
2184
|
+
if (!shouldUseClackOutput2()) {
|
|
2185
|
+
console.log(renderTopLevelHelp());
|
|
2186
|
+
return;
|
|
2187
|
+
}
|
|
2188
|
+
console.log(renderRigBanner(state.version));
|
|
2189
|
+
console.log("");
|
|
2190
|
+
if (state.projectInitialized === false) {
|
|
2191
|
+
intro("no rig project in this directory");
|
|
2192
|
+
note2([
|
|
2193
|
+
commandLine("rig init", "Set this repo up: config, GitHub auth, task source, server, Pi."),
|
|
2194
|
+
commandLine("rig init --yes", "Same, non-interactive, sensible defaults."),
|
|
2195
|
+
commandLine("rig doctor", "Already initialized somewhere else? Check the wiring.")
|
|
2196
|
+
].join(`
|
|
2197
|
+
`), "Get started");
|
|
2198
|
+
outro("After init: rig task run --next puts an agent on your next task.");
|
|
2199
|
+
return;
|
|
2200
|
+
}
|
|
2201
|
+
intro(state.selectedServer ? `server: ${state.selectedServer}` : "rig");
|
|
2202
|
+
for (const section of TOP_LEVEL_SECTIONS) {
|
|
2203
|
+
note2(renderCommandBlock(section.commands), `${section.title} \u2014 ${section.subtitle}`);
|
|
2204
|
+
}
|
|
2205
|
+
log2.info("More: rig help --advanced \xB7 rig <group> --help \xB7 rig --version");
|
|
2206
|
+
note2([
|
|
2207
|
+
commandLine("--project <path>", "Use a project root instead of auto-discovery."),
|
|
2208
|
+
commandLine("--json", "Emit structured output for scripts/agents."),
|
|
2209
|
+
commandLine("--dry-run", "Print the command plan without mutating state.")
|
|
2210
|
+
].join(`
|
|
2211
|
+
`), "Global options");
|
|
2212
|
+
outro("init \u2192 task run \u2192 watch/steer \u2192 inbox/review \u2192 merged.");
|
|
2213
|
+
}
|
|
2214
|
+
function printGroupHelpDocument(groupName) {
|
|
2215
|
+
const rendered = renderGroupHelp(groupName) ?? renderTopLevelHelp();
|
|
2216
|
+
if (!shouldUseClackOutput2()) {
|
|
2217
|
+
console.log(rendered);
|
|
2218
|
+
return;
|
|
2219
|
+
}
|
|
2220
|
+
const group = ALL_GROUPS.find((candidate) => candidate.name === groupName);
|
|
2221
|
+
if (!group) {
|
|
2222
|
+
printTopLevelHelp();
|
|
2223
|
+
return;
|
|
2224
|
+
}
|
|
2225
|
+
intro(`rig ${group.name}`);
|
|
2226
|
+
note2(group.summary, "Purpose");
|
|
2227
|
+
note2(group.usage.join(`
|
|
2228
|
+
`), "Usage");
|
|
2229
|
+
note2(group.commands.map((entry) => commandLine(entry.command, entry.description)).join(`
|
|
2230
|
+
`), "Commands");
|
|
2231
|
+
if (group.examples?.length)
|
|
2232
|
+
note2(group.examples.map((line) => `$ ${line}`).join(`
|
|
2233
|
+
`), "Examples");
|
|
2234
|
+
if (group.next?.length)
|
|
2235
|
+
note2(group.next.map((line) => `\u203A ${line}`).join(`
|
|
2236
|
+
`), "Next steps");
|
|
2237
|
+
if (group.advanced?.length)
|
|
2238
|
+
log2.info(group.advanced.join(`
|
|
2239
|
+
`));
|
|
2240
|
+
outro("Run with --json when scripts need structured output.");
|
|
2241
|
+
}
|
|
2242
|
+
|
|
852
2243
|
// packages/cli/src/commands/task.ts
|
|
853
2244
|
import { buildPluginHostContext } from "@rig/runtime/control-plane/plugin-host-context";
|
|
854
2245
|
import { loadConfig } from "@rig/core/load-config";
|
|
@@ -924,7 +2315,7 @@ function normalizePrMode(value) {
|
|
|
924
2315
|
throw new CliError2("--pr must be auto, ask, or off.", 2);
|
|
925
2316
|
}
|
|
926
2317
|
function detectLocalDirtyState(projectRoot) {
|
|
927
|
-
const result =
|
|
2318
|
+
const result = spawnSync("git", ["-C", projectRoot, "status", "--porcelain"], { encoding: "utf8", timeout: 5000 });
|
|
928
2319
|
if (result.status !== 0)
|
|
929
2320
|
return { dirty: false, modified: 0, untracked: 0, lines: [] };
|
|
930
2321
|
const lines = result.stdout.split(/\r?\n/).map((line) => line.trimEnd()).filter(Boolean);
|
|
@@ -958,13 +2349,15 @@ async function resolveDirtyBaselineForTaskRun(context, explicit) {
|
|
|
958
2349
|
if (explicit)
|
|
959
2350
|
return { mode: explicit, state };
|
|
960
2351
|
if (context.outputMode === "text" && process.stdin.isTTY && process.stdout.isTTY) {
|
|
961
|
-
const
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
2352
|
+
const answer = await confirm({
|
|
2353
|
+
message: "Include current uncommitted changes in run baseline?",
|
|
2354
|
+
initialValue: false
|
|
2355
|
+
});
|
|
2356
|
+
if (isCancel2(answer)) {
|
|
2357
|
+
cancel2("Run cancelled.");
|
|
2358
|
+
throw new CliError2("Run cancelled by user.", 1);
|
|
967
2359
|
}
|
|
2360
|
+
return { mode: answer ? "dirty-snapshot" : "head", state };
|
|
968
2361
|
}
|
|
969
2362
|
return { mode: "head", state };
|
|
970
2363
|
}
|
|
@@ -998,38 +2391,30 @@ function summarizeTask(task, options = {}) {
|
|
|
998
2391
|
...options.raw ? { raw: raw ?? task } : {}
|
|
999
2392
|
};
|
|
1000
2393
|
}
|
|
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
2394
|
async function validatorRegistryForTaskCommands(projectRoot) {
|
|
1008
2395
|
return buildPluginHostContext(projectRoot).then((ctx) => ctx?.validatorRegistry ?? undefined).catch(() => {
|
|
1009
2396
|
return;
|
|
1010
2397
|
});
|
|
1011
2398
|
}
|
|
1012
2399
|
async function executeTask(context, args, options) {
|
|
1013
|
-
|
|
2400
|
+
if (args.length === 0) {
|
|
2401
|
+
if (context.outputMode === "text") {
|
|
2402
|
+
printGroupHelpDocument("task");
|
|
2403
|
+
}
|
|
2404
|
+
return { ok: true, group: "task", command: "help" };
|
|
2405
|
+
}
|
|
2406
|
+
const [command = "help", ...rest] = args;
|
|
1014
2407
|
switch (command) {
|
|
1015
2408
|
case "list": {
|
|
1016
2409
|
let pending = rest;
|
|
1017
2410
|
const rawResult = takeFlag(pending, "--raw");
|
|
1018
2411
|
pending = rawResult.rest;
|
|
1019
2412
|
const { filters, rest: remaining } = parseTaskFilters(pending);
|
|
1020
|
-
requireNoExtraArgs(remaining, "
|
|
2413
|
+
requireNoExtraArgs(remaining, "rig task list [--raw] [--assignee <login|@me>] [--assigned-to <login|me|@me>] [--state open|closed] [--status <status>] [--limit <n>]");
|
|
1021
2414
|
const tasks = await listWorkspaceTasksViaServer(context, filters);
|
|
1022
2415
|
if (context.outputMode === "text") {
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
} else {
|
|
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
|
-
}
|
|
2416
|
+
const renderedTasks = rawResult.value ? tasks.map((task) => summarizeTask(task, { raw: true })) : tasks.map((task) => summarizeTask(task));
|
|
2417
|
+
printFormattedOutput(formatTaskList(renderedTasks, { raw: rawResult.value }));
|
|
1033
2418
|
}
|
|
1034
2419
|
return {
|
|
1035
2420
|
ok: true,
|
|
@@ -1039,30 +2424,34 @@ async function executeTask(context, args, options) {
|
|
|
1039
2424
|
};
|
|
1040
2425
|
}
|
|
1041
2426
|
case "show": {
|
|
1042
|
-
|
|
2427
|
+
let pending = rest;
|
|
2428
|
+
const rawResult = takeFlag(pending, "--raw");
|
|
2429
|
+
pending = rawResult.rest;
|
|
2430
|
+
const taskOption = takeOption(pending, "--task");
|
|
1043
2431
|
const positional = taskOption.rest.length > 0 && taskOption.rest[0] && !taskOption.rest[0].startsWith("-") ? taskOption.rest[0] : undefined;
|
|
1044
2432
|
const remaining = positional ? taskOption.rest.slice(1) : taskOption.rest;
|
|
1045
|
-
requireNoExtraArgs(remaining, "
|
|
1046
|
-
const
|
|
1047
|
-
if (!
|
|
2433
|
+
requireNoExtraArgs(remaining, "rig task show <id>|--task <id> [--raw]");
|
|
2434
|
+
const taskId3 = normalizeTaskRunTaskId(taskOption.value ?? positional);
|
|
2435
|
+
if (!taskId3)
|
|
1048
2436
|
throw new CliError2("task show requires a task id.", 2);
|
|
1049
|
-
const task = await getWorkspaceTaskViaServer(context,
|
|
2437
|
+
const task = await getWorkspaceTaskViaServer(context, taskId3);
|
|
1050
2438
|
if (!task)
|
|
1051
|
-
throw new CliError2(`Task not found: ${
|
|
2439
|
+
throw new CliError2(`Task not found: ${taskId3}`, 3);
|
|
1052
2440
|
const summary = summarizeTask(task, { raw: true });
|
|
1053
|
-
if (context.outputMode === "text")
|
|
1054
|
-
|
|
1055
|
-
|
|
2441
|
+
if (context.outputMode === "text") {
|
|
2442
|
+
printFormattedOutput(rawResult.value ? JSON.stringify(summary, null, 2) : formatTaskDetails(summary));
|
|
2443
|
+
}
|
|
2444
|
+
return { ok: true, group: "task", command, details: { task: summary, raw: rawResult.value } };
|
|
1056
2445
|
}
|
|
1057
2446
|
case "next": {
|
|
1058
2447
|
const { filters, rest: remaining } = parseTaskFilters(rest);
|
|
1059
|
-
requireNoExtraArgs(remaining, "
|
|
2448
|
+
requireNoExtraArgs(remaining, "rig task next [--assignee <login|@me>] [--assigned-to <login|me|@me>] [--state open|closed] [--status <status>] [--limit <n>]");
|
|
1060
2449
|
const selected = await selectNextWorkspaceTaskViaServer(context, filters);
|
|
1061
2450
|
if (context.outputMode === "text") {
|
|
1062
2451
|
if (selected.task) {
|
|
1063
|
-
|
|
2452
|
+
printFormattedOutput(formatTaskCard(summarizeTask(selected.task, { raw: true }), { title: "Selected task", selected: true }));
|
|
1064
2453
|
} else {
|
|
1065
|
-
|
|
2454
|
+
printFormattedOutput("No matching tasks.\n\nNext\n\u203A Try `rig task list` to inspect available work.\n\u203A Check server: `rig server status`");
|
|
1066
2455
|
}
|
|
1067
2456
|
}
|
|
1068
2457
|
return {
|
|
@@ -1078,31 +2467,31 @@ async function executeTask(context, args, options) {
|
|
|
1078
2467
|
}
|
|
1079
2468
|
case "info": {
|
|
1080
2469
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1081
|
-
requireNoExtraArgs(remaining, "
|
|
2470
|
+
requireNoExtraArgs(remaining, "rig task info [--task <task-id>]");
|
|
1082
2471
|
await withMutedConsole(context.outputMode === "json", () => taskInfo(context.projectRoot, task || undefined));
|
|
1083
2472
|
return { ok: true, group: "task", command, details: { task: task || null } };
|
|
1084
2473
|
}
|
|
1085
2474
|
case "scope": {
|
|
1086
2475
|
const filesFlag = takeFlag(rest, "--files");
|
|
1087
2476
|
const { value: task, rest: remaining } = takeOption(filesFlag.rest, "--task");
|
|
1088
|
-
requireNoExtraArgs(remaining, "
|
|
2477
|
+
requireNoExtraArgs(remaining, "rig task scope [--task <id>] [--files]");
|
|
1089
2478
|
await withMutedConsole(context.outputMode === "json", () => taskScope(context.projectRoot, filesFlag.value, task || undefined));
|
|
1090
2479
|
return { ok: true, group: "task", command, details: { files: filesFlag.value, task: task || null } };
|
|
1091
2480
|
}
|
|
1092
2481
|
case "deps":
|
|
1093
|
-
requireNoExtraArgs(rest, "
|
|
2482
|
+
requireNoExtraArgs(rest, "rig task deps");
|
|
1094
2483
|
await withMutedConsole(context.outputMode === "json", () => taskDeps(context.projectRoot));
|
|
1095
2484
|
return { ok: true, group: "task", command };
|
|
1096
2485
|
case "status":
|
|
1097
|
-
requireNoExtraArgs(rest, "
|
|
2486
|
+
requireNoExtraArgs(rest, "rig task status");
|
|
1098
2487
|
withMutedConsole(context.outputMode === "json", () => taskStatus2(context.projectRoot));
|
|
1099
2488
|
return { ok: true, group: "task", command };
|
|
1100
2489
|
case "artifacts":
|
|
1101
|
-
requireNoExtraArgs(rest, "
|
|
2490
|
+
requireNoExtraArgs(rest, "rig task artifacts");
|
|
1102
2491
|
withMutedConsole(context.outputMode === "json", () => taskArtifacts(context.projectRoot));
|
|
1103
2492
|
return { ok: true, group: "task", command };
|
|
1104
2493
|
case "artifact-dir": {
|
|
1105
|
-
requireNoExtraArgs(rest, "
|
|
2494
|
+
requireNoExtraArgs(rest, "rig task artifact-dir");
|
|
1106
2495
|
const path = taskArtifactDir(context.projectRoot);
|
|
1107
2496
|
if (context.outputMode === "text") {
|
|
1108
2497
|
console.log(path);
|
|
@@ -1111,7 +2500,7 @@ async function executeTask(context, args, options) {
|
|
|
1111
2500
|
}
|
|
1112
2501
|
case "artifact-write": {
|
|
1113
2502
|
if (rest.length < 1) {
|
|
1114
|
-
throw new CliError2(`Usage:
|
|
2503
|
+
throw new CliError2(`Usage: rig task artifact-write <filename> [--file <path>]
|
|
1115
2504
|
` + ` Reads content from stdin (or --file), writes to the active task artifact dir.
|
|
1116
2505
|
` + " Example: echo '...' | rig task artifact-write collection-audit.md");
|
|
1117
2506
|
}
|
|
@@ -1119,12 +2508,12 @@ async function executeTask(context, args, options) {
|
|
|
1119
2508
|
const fileFlag = takeOption(rest.slice(1), "--file");
|
|
1120
2509
|
let content;
|
|
1121
2510
|
if (fileFlag.value) {
|
|
1122
|
-
content =
|
|
2511
|
+
content = readFileSync3(resolve3(context.projectRoot, fileFlag.value), "utf-8");
|
|
1123
2512
|
} else {
|
|
1124
2513
|
content = await readStdin();
|
|
1125
2514
|
}
|
|
1126
2515
|
if (!artifactFilename) {
|
|
1127
|
-
throw new CliError2("Usage:
|
|
2516
|
+
throw new CliError2("Usage: rig task artifact-write <filename> [--file path]");
|
|
1128
2517
|
}
|
|
1129
2518
|
withMutedConsole(context.outputMode === "json", () => taskArtifactWrite(context.projectRoot, artifactFilename, content));
|
|
1130
2519
|
return { ok: true, group: "task", command, details: { filename: artifactFilename } };
|
|
@@ -1133,11 +2522,11 @@ async function executeTask(context, args, options) {
|
|
|
1133
2522
|
return options.executeTaskReportBug(context, rest);
|
|
1134
2523
|
case "lookup": {
|
|
1135
2524
|
if (rest.length !== 1) {
|
|
1136
|
-
throw new CliError2("Usage:
|
|
2525
|
+
throw new CliError2("Usage: rig task lookup <task-id>");
|
|
1137
2526
|
}
|
|
1138
2527
|
const lookupId = rest[0];
|
|
1139
2528
|
if (!lookupId) {
|
|
1140
|
-
throw new CliError2("Usage:
|
|
2529
|
+
throw new CliError2("Usage: rig task lookup <task-id>");
|
|
1141
2530
|
}
|
|
1142
2531
|
const result = taskLookup(context.projectRoot, lookupId);
|
|
1143
2532
|
if (context.outputMode === "text") {
|
|
@@ -1147,17 +2536,17 @@ async function executeTask(context, args, options) {
|
|
|
1147
2536
|
}
|
|
1148
2537
|
case "record": {
|
|
1149
2538
|
if (rest.length < 2) {
|
|
1150
|
-
throw new CliError2("Usage:
|
|
2539
|
+
throw new CliError2("Usage: rig task record <decision|failure> <text>");
|
|
1151
2540
|
}
|
|
1152
2541
|
const type = rest[0];
|
|
1153
2542
|
if (type !== "decision" && type !== "failure") {
|
|
1154
|
-
throw new CliError2("Usage:
|
|
2543
|
+
throw new CliError2("Usage: rig task record <decision|failure> <text>");
|
|
1155
2544
|
}
|
|
1156
2545
|
withMutedConsole(context.outputMode === "json", () => taskRecord(context.projectRoot, type, rest.slice(1).join(" ")));
|
|
1157
2546
|
return { ok: true, group: "task", command, details: { type: rest[0] } };
|
|
1158
2547
|
}
|
|
1159
2548
|
case "ready":
|
|
1160
|
-
requireNoExtraArgs(rest, "
|
|
2549
|
+
requireNoExtraArgs(rest, "rig task ready");
|
|
1161
2550
|
await withMutedConsole(context.outputMode === "json", () => taskReady(context.projectRoot));
|
|
1162
2551
|
return { ok: true, group: "task", command };
|
|
1163
2552
|
case "run": {
|
|
@@ -1194,7 +2583,7 @@ async function executeTask(context, args, options) {
|
|
|
1194
2583
|
if (positionalTaskId) {
|
|
1195
2584
|
pending = pending.slice(1);
|
|
1196
2585
|
}
|
|
1197
|
-
requireNoExtraArgs(pending, "
|
|
2586
|
+
requireNoExtraArgs(pending, "rig task run [#<issue>|<task-id>] [--next] [--task <id>] [--detach] [--assignee <login|@me>] [--assigned-to <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
2587
|
if (nextResult.value && (taskResult.value || positionalTaskId)) {
|
|
1199
2588
|
throw new CliError2("task run cannot combine --next with an explicit task id.", 2);
|
|
1200
2589
|
}
|
|
@@ -1248,16 +2637,24 @@ async function executeTask(context, args, options) {
|
|
|
1248
2637
|
});
|
|
1249
2638
|
let attachDetails = null;
|
|
1250
2639
|
if (!detachResult.value && context.outputMode === "text") {
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
2640
|
+
printFormattedOutput(formatSubmittedRun({
|
|
2641
|
+
runId: submitted.runId,
|
|
2642
|
+
task: selectedTask ? summarizeTask(selectedTask) : null,
|
|
2643
|
+
runtimeAdapter,
|
|
2644
|
+
runtimeMode: runtimeModeResult.value || projectDefaults.runtimeMode || "full-access",
|
|
2645
|
+
interactionMode: interactionModeResult.value || "default",
|
|
2646
|
+
detached: false
|
|
2647
|
+
}));
|
|
1255
2648
|
attachDetails = await attachRunOperatorView(context, { runId: submitted.runId, follow: true });
|
|
1256
2649
|
} else if (context.outputMode === "text") {
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
2650
|
+
printFormattedOutput(formatSubmittedRun({
|
|
2651
|
+
runId: submitted.runId,
|
|
2652
|
+
task: selectedTask ? summarizeTask(selectedTask) : null,
|
|
2653
|
+
runtimeAdapter,
|
|
2654
|
+
runtimeMode: runtimeModeResult.value || projectDefaults.runtimeMode || "full-access",
|
|
2655
|
+
interactionMode: interactionModeResult.value || "default",
|
|
2656
|
+
detached: true
|
|
2657
|
+
}));
|
|
1261
2658
|
}
|
|
1262
2659
|
return {
|
|
1263
2660
|
ok: true,
|
|
@@ -1281,7 +2678,7 @@ async function executeTask(context, args, options) {
|
|
|
1281
2678
|
}
|
|
1282
2679
|
case "validate": {
|
|
1283
2680
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1284
|
-
requireNoExtraArgs(remaining, "
|
|
2681
|
+
requireNoExtraArgs(remaining, "rig task validate [--task <task-id>]");
|
|
1285
2682
|
if (context.dryRun) {
|
|
1286
2683
|
await context.runCommand(["rig", "task", "validate", ...task ? ["--task", task] : []]);
|
|
1287
2684
|
return { ok: true, group: "task", command, details: { task: task || "active" } };
|
|
@@ -1294,12 +2691,12 @@ async function executeTask(context, args, options) {
|
|
|
1294
2691
|
}
|
|
1295
2692
|
case "verify": {
|
|
1296
2693
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1297
|
-
requireNoExtraArgs(remaining, "
|
|
2694
|
+
requireNoExtraArgs(remaining, "rig task verify [--task <task-id>]");
|
|
1298
2695
|
if (context.dryRun) {
|
|
1299
2696
|
await context.runCommand(["rig", "task", "verify", ...task ? ["--task", task] : []]);
|
|
1300
2697
|
return { ok: true, group: "task", command, details: { task: task || "active" } };
|
|
1301
2698
|
}
|
|
1302
|
-
const ok = await withMutedConsole(context.outputMode === "json", () => taskVerify(context.projectRoot,
|
|
2699
|
+
const ok = await withMutedConsole(context.outputMode === "json", () => taskVerify(context.projectRoot, task || undefined));
|
|
1303
2700
|
if (!ok) {
|
|
1304
2701
|
throw new CliError2(`Verification rejected for ${task || "active task"}.`, 2);
|
|
1305
2702
|
}
|
|
@@ -1307,15 +2704,19 @@ async function executeTask(context, args, options) {
|
|
|
1307
2704
|
}
|
|
1308
2705
|
case "reset": {
|
|
1309
2706
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1310
|
-
requireNoExtraArgs(remaining, "
|
|
1311
|
-
const requiredTask = requireTask(task, "
|
|
1312
|
-
|
|
1313
|
-
|
|
2707
|
+
requireNoExtraArgs(remaining, "rig task reset --task <task-id>");
|
|
2708
|
+
const requiredTask = requireTask(task, "rig task reset --task <task-id>");
|
|
2709
|
+
const summary = withMutedConsole(context.outputMode === "json", () => taskReopen(context.projectRoot, {
|
|
2710
|
+
all: false,
|
|
2711
|
+
taskId: requiredTask,
|
|
2712
|
+
dryRun: false
|
|
2713
|
+
}));
|
|
2714
|
+
return { ok: true, group: "task", command, details: summary };
|
|
1314
2715
|
}
|
|
1315
2716
|
case "details": {
|
|
1316
2717
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1317
|
-
requireNoExtraArgs(remaining, "
|
|
1318
|
-
const requiredTask = requireTask(task, "
|
|
2718
|
+
requireNoExtraArgs(remaining, "rig task details --task <task-id>");
|
|
2719
|
+
const requiredTask = requireTask(task, "rig task details --task <task-id>");
|
|
1319
2720
|
await withMutedConsole(context.outputMode === "json", () => taskInfo(context.projectRoot, requiredTask));
|
|
1320
2721
|
return { ok: true, group: "task", command, details: { task: requiredTask } };
|
|
1321
2722
|
}
|
|
@@ -1323,9 +2724,9 @@ async function executeTask(context, args, options) {
|
|
|
1323
2724
|
const { value: task, rest: rest1 } = takeOption(rest, "--task");
|
|
1324
2725
|
const allFlag = takeFlag(rest1, "--all");
|
|
1325
2726
|
const { rest: remaining } = takeOption(allFlag.rest, "--reason");
|
|
1326
|
-
requireNoExtraArgs(remaining, "
|
|
2727
|
+
requireNoExtraArgs(remaining, "rig task reopen [--task <id> | --all] [--reason <text>]");
|
|
1327
2728
|
if (!allFlag.value && !task) {
|
|
1328
|
-
throw new CliError2("Usage:
|
|
2729
|
+
throw new CliError2("Usage: rig task reopen [--task <id> | --all] [--reason <text>]");
|
|
1329
2730
|
}
|
|
1330
2731
|
const summary = withMutedConsole(context.outputMode === "json", () => taskReopen(context.projectRoot, {
|
|
1331
2732
|
all: allFlag.value,
|