@h-rig/cli 0.0.6-alpha.4 → 0.0.6-alpha.40
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 +3947 -1190
- 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 +942 -56
- package/dist/src/commands/_parsers.js +0 -2
- package/dist/src/commands/_pi-frontend.js +906 -0
- package/dist/src/commands/_pi-install.js +4 -3
- package/dist/src/commands/_pi-worker-bridge-extension.js +826 -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 +21 -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 +1240 -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 +649 -71
- package/dist/src/commands/task.js +1679 -252
- package/dist/src/commands/test.js +3 -5
- package/dist/src/commands/workspace.js +4 -6
- package/dist/src/commands.js +3927 -1164
- package/dist/src/index.js +3940 -1186
- 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,691 @@ 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 { main as runPiMain } from "@earendil-works/pi-coding-agent";
|
|
967
|
+
|
|
968
|
+
// packages/cli/src/commands/_pi-worker-bridge-extension.ts
|
|
754
969
|
var TERMINAL_RUN_STATUSES = new Set(["completed", "failed", "stopped", "cancelled", "canceled", "closed", "merged", "needs_attention", "needs-attention"]);
|
|
755
|
-
var
|
|
756
|
-
|
|
757
|
-
"
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
"
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
"
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
return
|
|
777
|
-
|
|
778
|
-
|
|
970
|
+
var MAX_TRANSCRIPT_LINES = 120;
|
|
971
|
+
function recordOf(value) {
|
|
972
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
973
|
+
}
|
|
974
|
+
function asText(value) {
|
|
975
|
+
if (typeof value === "string")
|
|
976
|
+
return value;
|
|
977
|
+
if (value === null || value === undefined)
|
|
978
|
+
return "";
|
|
979
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
980
|
+
return String(value);
|
|
981
|
+
try {
|
|
982
|
+
return JSON.stringify(value);
|
|
983
|
+
} catch {
|
|
984
|
+
return String(value);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
function textFromContent(content) {
|
|
988
|
+
if (typeof content === "string")
|
|
989
|
+
return content;
|
|
990
|
+
if (!Array.isArray(content))
|
|
991
|
+
return asText(content);
|
|
992
|
+
return content.flatMap((part) => {
|
|
993
|
+
const item = recordOf(part);
|
|
994
|
+
if (!item)
|
|
995
|
+
return [];
|
|
996
|
+
if (typeof item.text === "string")
|
|
997
|
+
return [item.text];
|
|
998
|
+
if (typeof item.content === "string")
|
|
999
|
+
return [item.content];
|
|
1000
|
+
if (item.type === "toolCall")
|
|
1001
|
+
return [`\u23FA ${String(item.name ?? "tool")} ${asText(item.arguments ?? "")}`.trim()];
|
|
1002
|
+
if (item.type === "toolResult")
|
|
1003
|
+
return [`\u21B3 ${asText(item.content ?? item.result ?? "")}`.trim()];
|
|
1004
|
+
return [];
|
|
1005
|
+
}).join(`
|
|
779
1006
|
`);
|
|
780
1007
|
}
|
|
1008
|
+
function appendTranscript(state, label, text) {
|
|
1009
|
+
const trimmed = text.trimEnd();
|
|
1010
|
+
if (!trimmed)
|
|
1011
|
+
return;
|
|
1012
|
+
const lines = trimmed.split(/\r?\n/);
|
|
1013
|
+
state.transcript.push(`${label}: ${lines[0] ?? ""}`);
|
|
1014
|
+
for (const line of lines.slice(1))
|
|
1015
|
+
state.transcript.push(` ${line}`);
|
|
1016
|
+
if (state.transcript.length > MAX_TRANSCRIPT_LINES) {
|
|
1017
|
+
state.transcript.splice(0, state.transcript.length - MAX_TRANSCRIPT_LINES);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
function nativePiUi(ctx) {
|
|
1021
|
+
const ui = ctx.ui;
|
|
1022
|
+
return typeof ui.emitSessionEvent === "function" && typeof ui.appendSessionMessages === "function" ? ui : null;
|
|
1023
|
+
}
|
|
1024
|
+
function syncNativeDisplayCwd(ctx, state) {
|
|
1025
|
+
const ui = nativePiUi(ctx);
|
|
1026
|
+
if (ui?.setDisplayCwd && state.cwd)
|
|
1027
|
+
ui.setDisplayCwd(state.cwd);
|
|
1028
|
+
}
|
|
1029
|
+
function parseExtensionUiRequest(value) {
|
|
1030
|
+
const request = recordOf(value) ?? {};
|
|
1031
|
+
const requestId = String(request.requestId ?? request.id ?? `ui-${Date.now()}`);
|
|
1032
|
+
const method = String(request.method ?? request.type ?? "input");
|
|
1033
|
+
const prompt = asText(request.prompt ?? request.message ?? request.title ?? method);
|
|
1034
|
+
const rawOptions = Array.isArray(request.options) ? request.options : Array.isArray(request.items) ? request.items : [];
|
|
1035
|
+
const options = rawOptions.map((option) => {
|
|
1036
|
+
const record = recordOf(option);
|
|
1037
|
+
return record ? asText(record.label ?? record.value ?? record.name ?? option) : asText(option);
|
|
1038
|
+
}).filter(Boolean);
|
|
1039
|
+
return { requestId, method, prompt, options };
|
|
1040
|
+
}
|
|
1041
|
+
function renderBridgeWidget(state) {
|
|
1042
|
+
const statusParts = [
|
|
1043
|
+
state.wsConnected ? "live" : "connecting",
|
|
1044
|
+
state.status,
|
|
1045
|
+
state.model,
|
|
1046
|
+
state.cwd
|
|
1047
|
+
].filter(Boolean);
|
|
1048
|
+
const lines = [`Rig worker session \xB7 ${statusParts.join(" \xB7 ")}`];
|
|
1049
|
+
if (state.activity)
|
|
1050
|
+
lines.push(state.activity);
|
|
1051
|
+
if (state.commands.length > 0) {
|
|
1052
|
+
lines.push(`Worker commands: ${state.commands.slice(0, 10).join(", ")}${state.commands.length > 10 ? ", \u2026" : ""}`);
|
|
1053
|
+
}
|
|
1054
|
+
lines.push("");
|
|
1055
|
+
if (state.transcript.length > 0) {
|
|
1056
|
+
lines.push(...state.transcript.slice(-MAX_TRANSCRIPT_LINES));
|
|
1057
|
+
} else {
|
|
1058
|
+
lines.push("Waiting for the worker session transcript\u2026 (/detach exits and leaves the worker running)");
|
|
1059
|
+
}
|
|
1060
|
+
if (state.pendingUi) {
|
|
1061
|
+
lines.push("");
|
|
1062
|
+
lines.push(`Worker needs input \xB7 ${state.pendingUi.method}`);
|
|
1063
|
+
lines.push(state.pendingUi.prompt);
|
|
1064
|
+
state.pendingUi.options.forEach((option, index) => lines.push(`${index + 1}. ${option}`));
|
|
1065
|
+
lines.push("Reply in the editor below. /cancel dismisses this request.");
|
|
1066
|
+
}
|
|
1067
|
+
return lines;
|
|
1068
|
+
}
|
|
1069
|
+
function reportBridgeError(ctx, state, message2) {
|
|
1070
|
+
appendTranscript(state, "Error", message2);
|
|
1071
|
+
state.status = message2;
|
|
1072
|
+
try {
|
|
1073
|
+
ctx.ui.notify(message2, "error");
|
|
1074
|
+
} catch {}
|
|
1075
|
+
updatePiUi(ctx, state);
|
|
1076
|
+
}
|
|
1077
|
+
function updatePiUi(ctx, state) {
|
|
1078
|
+
ctx.ui.setTitle("Rig \xB7 worker session");
|
|
1079
|
+
ctx.ui.setStatus("rig-worker-pi", state.wsConnected ? "worker session live" : state.status);
|
|
1080
|
+
syncNativeDisplayCwd(ctx, state);
|
|
1081
|
+
if (state.nativeStream && nativePiUi(ctx)) {
|
|
1082
|
+
ctx.ui.setWidget("rig-worker-pi-transcript", undefined);
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
ctx.ui.setWorkingVisible(false);
|
|
1086
|
+
ctx.ui.setWidget("rig-worker-pi-transcript", renderBridgeWidget(state), { placement: "aboveEditor" });
|
|
1087
|
+
}
|
|
1088
|
+
function applyStatus(state, payload) {
|
|
1089
|
+
const status = recordOf(payload.status) ?? payload;
|
|
1090
|
+
state.streaming = status.isStreaming === true || status.isCompacting === true || status.isBashRunning === true;
|
|
1091
|
+
state.cwd = typeof status.cwd === "string" ? status.cwd : state.cwd;
|
|
1092
|
+
state.model = typeof status.model === "string" ? status.model : state.model;
|
|
1093
|
+
const pending = typeof status.pendingMessageCount === "number" ? status.pendingMessageCount : 0;
|
|
1094
|
+
state.status = `${state.streaming ? "streaming" : "idle"}${pending ? ` \xB7 ${pending} queued` : ""}`;
|
|
1095
|
+
}
|
|
1096
|
+
function applyMessage(state, message2) {
|
|
1097
|
+
const record = recordOf(message2);
|
|
1098
|
+
if (!record)
|
|
1099
|
+
return;
|
|
1100
|
+
const role = String(record.role ?? "system");
|
|
1101
|
+
const label = role === "assistant" ? "Pi" : role === "user" ? "You" : role === "tool" || role === "toolResult" ? "Tool" : "System";
|
|
1102
|
+
appendTranscript(state, label, textFromContent(record.content ?? record.message ?? record.text ?? ""));
|
|
1103
|
+
}
|
|
1104
|
+
function applyPiEvent(ctx, state, eventValue) {
|
|
1105
|
+
const event = recordOf(eventValue);
|
|
1106
|
+
if (!event)
|
|
1107
|
+
return;
|
|
1108
|
+
const type = String(event.type ?? "event");
|
|
1109
|
+
if (type === "agent_start") {
|
|
1110
|
+
state.streaming = true;
|
|
1111
|
+
state.status = "streaming";
|
|
1112
|
+
} else if (type === "agent_end") {
|
|
1113
|
+
state.streaming = false;
|
|
1114
|
+
state.status = "idle";
|
|
1115
|
+
} else if (type === "queue_update") {
|
|
1116
|
+
const steering = Array.isArray(event.steering) ? event.steering.length : 0;
|
|
1117
|
+
const followUp = Array.isArray(event.followUp) ? event.followUp.length : 0;
|
|
1118
|
+
state.status = `queued \xB7 steer ${steering} \xB7 follow-up ${followUp}`;
|
|
1119
|
+
}
|
|
1120
|
+
const native = nativePiUi(ctx);
|
|
1121
|
+
if (state.nativeStream && native?.emitSessionEvent) {
|
|
1122
|
+
native.emitSessionEvent(eventValue);
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
if (type === "agent_end") {
|
|
1126
|
+
appendTranscript(state, "System", "Agent turn complete.");
|
|
1127
|
+
return;
|
|
1128
|
+
}
|
|
1129
|
+
if (type === "message_start" || type === "message_end" || type === "turn_end") {
|
|
1130
|
+
applyMessage(state, event.message);
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
if (type === "message_update") {
|
|
1134
|
+
const assistantEvent = recordOf(event.assistantMessageEvent);
|
|
1135
|
+
const delta = typeof assistantEvent?.delta === "string" ? assistantEvent.delta : typeof assistantEvent?.text === "string" ? assistantEvent.text : "";
|
|
1136
|
+
if (delta)
|
|
1137
|
+
appendTranscript(state, assistantEvent?.type === "thinking_delta" ? "Thinking" : "Pi", delta);
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
if (type === "tool_execution_start") {
|
|
1141
|
+
appendTranscript(state, "Tool", `${String(event.toolName ?? "tool")} ${asText(event.args ?? "")}`.trim());
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1144
|
+
if (type === "tool_execution_update") {
|
|
1145
|
+
appendTranscript(state, "Tool", asText(event.partialResult ?? ""));
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
if (type === "tool_execution_end") {
|
|
1149
|
+
appendTranscript(state, event.isError === true ? "Error" : "Tool", asText(event.result ?? `${String(event.toolName ?? "tool")} complete`));
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
function firstPendingShell(state) {
|
|
1153
|
+
return state.pendingShells[0];
|
|
1154
|
+
}
|
|
1155
|
+
function finishPendingShell(state, shell, result) {
|
|
1156
|
+
const index = state.pendingShells.indexOf(shell);
|
|
1157
|
+
if (index !== -1)
|
|
1158
|
+
state.pendingShells.splice(index, 1);
|
|
1159
|
+
shell.resolve(result);
|
|
1160
|
+
}
|
|
1161
|
+
function failPendingShell(state, shell, error) {
|
|
1162
|
+
const index = state.pendingShells.indexOf(shell);
|
|
1163
|
+
if (index !== -1)
|
|
1164
|
+
state.pendingShells.splice(index, 1);
|
|
1165
|
+
shell.reject(error);
|
|
1166
|
+
}
|
|
1167
|
+
function applyUiEvent(state, value) {
|
|
1168
|
+
const event = recordOf(value);
|
|
1169
|
+
if (!event)
|
|
1170
|
+
return;
|
|
1171
|
+
const type = String(event.type ?? "ui");
|
|
1172
|
+
if (type === "shell.chunk") {
|
|
1173
|
+
const pending = firstPendingShell(state);
|
|
1174
|
+
const chunk = asText(event.chunk);
|
|
1175
|
+
if (pending) {
|
|
1176
|
+
pending.sawChunk = true;
|
|
1177
|
+
pending.onData(Buffer.from(chunk));
|
|
1178
|
+
} else {
|
|
1179
|
+
appendTranscript(state, "Tool", chunk);
|
|
1180
|
+
}
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
if (type === "shell.end") {
|
|
1184
|
+
const pending = firstPendingShell(state);
|
|
1185
|
+
const output = asText(event.output ?? "");
|
|
1186
|
+
const exitCode = typeof event.exitCode === "number" ? event.exitCode : event.isError === true ? 1 : 0;
|
|
1187
|
+
if (pending) {
|
|
1188
|
+
if (output && !pending.sawChunk)
|
|
1189
|
+
pending.onData(Buffer.from(output));
|
|
1190
|
+
finishPendingShell(state, pending, { exitCode });
|
|
1191
|
+
} else {
|
|
1192
|
+
appendTranscript(state, event.isError === true ? "Error" : "Tool", output || `exit ${String(exitCode)}`);
|
|
1193
|
+
}
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
if (type === "shell.start") {
|
|
1197
|
+
if (!firstPendingShell(state))
|
|
1198
|
+
appendTranscript(state, "Tool", `$ ${asText(event.command)}`);
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1201
|
+
appendTranscript(state, "System", `${type}: ${asText(event)}`);
|
|
1202
|
+
}
|
|
1203
|
+
function applyEnvelope(ctx, state, envelopeValue) {
|
|
1204
|
+
const envelope = recordOf(envelopeValue);
|
|
1205
|
+
if (!envelope)
|
|
1206
|
+
return;
|
|
1207
|
+
const type = String(envelope.type ?? "");
|
|
1208
|
+
if (type === "ready") {
|
|
1209
|
+
const metadata = recordOf(envelope.metadata);
|
|
1210
|
+
state.cwd = typeof metadata?.cwd === "string" ? metadata.cwd : state.cwd;
|
|
1211
|
+
state.status = "worker Pi daemon ready";
|
|
1212
|
+
if (!state.nativeStream)
|
|
1213
|
+
appendTranscript(state, "System", "Connected to worker Pi daemon.");
|
|
1214
|
+
} else if (type === "status.update") {
|
|
1215
|
+
applyStatus(state, envelope);
|
|
1216
|
+
} else if (type === "activity.update") {
|
|
1217
|
+
const activity = recordOf(envelope.activity);
|
|
1218
|
+
state.activity = [activity?.label, activity?.detail].map(asText).filter(Boolean).join(" \u2014 ");
|
|
1219
|
+
} else if (type === "extension_ui_request") {
|
|
1220
|
+
state.pendingUi = parseExtensionUiRequest(envelope.request);
|
|
1221
|
+
appendTranscript(state, "System", `Extension UI request: ${state.pendingUi.prompt}`);
|
|
1222
|
+
} else if (type === "pi.ui_event") {
|
|
1223
|
+
applyUiEvent(state, envelope.event);
|
|
1224
|
+
} else if (type === "pi.event") {
|
|
1225
|
+
applyPiEvent(ctx, state, envelope.event);
|
|
1226
|
+
} else if (type === "error") {
|
|
1227
|
+
appendTranscript(state, "Error", asText(envelope.message ?? envelope.detail ?? "unknown error"));
|
|
1228
|
+
}
|
|
1229
|
+
syncNativeDisplayCwd(ctx, state);
|
|
1230
|
+
}
|
|
1231
|
+
function resolveAttachReadyTimeoutMs() {
|
|
1232
|
+
const raw = Number.parseInt(process.env.RIG_PI_ATTACH_TIMEOUT_MS ?? "", 10);
|
|
1233
|
+
return Number.isFinite(raw) && raw > 0 ? raw : 10 * 60000;
|
|
1234
|
+
}
|
|
1235
|
+
function formatElapsed(sinceMs) {
|
|
1236
|
+
const totalSeconds = Math.floor((Date.now() - sinceMs) / 1000);
|
|
1237
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
1238
|
+
const seconds = totalSeconds % 60;
|
|
1239
|
+
return minutes > 0 ? `${minutes}m${String(seconds).padStart(2, "0")}s` : `${seconds}s`;
|
|
1240
|
+
}
|
|
1241
|
+
async function waitForWorkerReady(options, ctx, state) {
|
|
1242
|
+
const startedAt = Date.now();
|
|
1243
|
+
const deadline = startedAt + resolveAttachReadyTimeoutMs();
|
|
1244
|
+
let consecutiveFailures = 0;
|
|
1245
|
+
while (true) {
|
|
1246
|
+
let requestFailed = false;
|
|
1247
|
+
const session = await getRunPiSessionViaServer(options.context, options.runId).catch((error) => {
|
|
1248
|
+
requestFailed = true;
|
|
1249
|
+
return {
|
|
1250
|
+
ready: false,
|
|
1251
|
+
status: error instanceof Error ? error.message : String(error),
|
|
1252
|
+
retryAfterMs: 1000
|
|
1253
|
+
};
|
|
1254
|
+
});
|
|
1255
|
+
if (session.ready === false) {
|
|
1256
|
+
consecutiveFailures = requestFailed ? consecutiveFailures + 1 : 0;
|
|
1257
|
+
const status = String(session.status ?? "starting");
|
|
1258
|
+
if (TERMINAL_RUN_STATUSES.has(status.toLowerCase())) {
|
|
1259
|
+
reportBridgeError(ctx, state, `Run ended before worker Pi daemon became ready: ${status}. Inspect with \`rig run show ${options.runId}\`; restart with \`rig task run --task <id>\`.`);
|
|
1260
|
+
return false;
|
|
1261
|
+
}
|
|
1262
|
+
if (consecutiveFailures >= 5) {
|
|
1263
|
+
state.status = `Rig server unreachable \xB7 retrying (${formatElapsed(startedAt)}) \xB7 /detach to exit`;
|
|
1264
|
+
} else {
|
|
1265
|
+
state.status = `waiting for worker Pi daemon \xB7 ${status} \xB7 ${formatElapsed(startedAt)} \xB7 /detach to exit`;
|
|
1266
|
+
}
|
|
1267
|
+
updatePiUi(ctx, state);
|
|
1268
|
+
if (Date.now() >= deadline) {
|
|
1269
|
+
reportBridgeError(ctx, state, `Worker Pi daemon did not become ready within ${formatElapsed(startedAt)} (last status: ${status}). ` + `Check \`rig run show ${options.runId}\` and \`rig doctor\`; the run may have been restarted by a server deploy. ` + "Set RIG_PI_ATTACH_TIMEOUT_MS to wait longer.");
|
|
1270
|
+
return false;
|
|
1271
|
+
}
|
|
1272
|
+
await Bun.sleep(typeof session.retryAfterMs === "number" ? session.retryAfterMs : 750);
|
|
1273
|
+
continue;
|
|
1274
|
+
}
|
|
1275
|
+
const sessionRecord = recordOf(session) ?? {};
|
|
1276
|
+
applyEnvelope(ctx, state, { type: "ready", metadata: sessionRecord.metadata ?? sessionRecord });
|
|
1277
|
+
updatePiUi(ctx, state);
|
|
1278
|
+
return true;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
function parseWsPayload(message2) {
|
|
1282
|
+
if (typeof message2.data === "string")
|
|
1283
|
+
return JSON.parse(message2.data);
|
|
1284
|
+
return JSON.parse(Buffer.from(message2.data).toString("utf8"));
|
|
1285
|
+
}
|
|
1286
|
+
var BRIDGE_LOCAL_COMMANDS = new Set(["detach", "quit", "q", "stop"]);
|
|
1287
|
+
function registerDaemonCommandsNatively(pi, options, ctx, state, commands, registered) {
|
|
1288
|
+
for (const command of commands) {
|
|
1289
|
+
const record = recordOf(command);
|
|
1290
|
+
const name = typeof record?.name === "string" ? record.name : "";
|
|
1291
|
+
if (!name || registered.has(name) || BRIDGE_LOCAL_COMMANDS.has(name))
|
|
1292
|
+
continue;
|
|
1293
|
+
registered.add(name);
|
|
1294
|
+
const description = typeof record?.description === "string" ? record.description : undefined;
|
|
1295
|
+
const source = typeof record?.source === "string" ? record.source : "worker";
|
|
1296
|
+
try {
|
|
1297
|
+
pi.registerCommand(name, {
|
|
1298
|
+
description: `[worker ${source}] ${description ?? ""}`.trim(),
|
|
1299
|
+
handler: async (args) => {
|
|
1300
|
+
const text = `/${name}${args ? ` ${args}` : ""}`;
|
|
1301
|
+
appendTranscript(state, "You", text);
|
|
1302
|
+
try {
|
|
1303
|
+
const result = await runRunPiCommandViaServer(options.context, options.runId, text);
|
|
1304
|
+
const message2 = typeof result.message === "string" ? result.message : "worker command accepted";
|
|
1305
|
+
appendTranscript(state, "System", message2);
|
|
1306
|
+
if (state.nativeStream)
|
|
1307
|
+
ctx.ui.notify(message2, "info");
|
|
1308
|
+
} catch (error) {
|
|
1309
|
+
reportBridgeError(ctx, state, error instanceof Error ? error.message : String(error));
|
|
1310
|
+
}
|
|
1311
|
+
updatePiUi(ctx, state);
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
} catch {}
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
async function connectWorkerStream(options, pi, ctx, state, registeredDaemonCommands) {
|
|
1318
|
+
const ready = await waitForWorkerReady(options, ctx, state);
|
|
1319
|
+
if (!ready)
|
|
1320
|
+
return;
|
|
1321
|
+
let catchupDone = false;
|
|
1322
|
+
const buffered = [];
|
|
1323
|
+
const wsUrl = await buildRunPiEventsWebSocketUrl(options.context, options.runId);
|
|
1324
|
+
const socket = new WebSocket(wsUrl);
|
|
1325
|
+
const closePromise = new Promise((resolve3) => {
|
|
1326
|
+
socket.onopen = () => {
|
|
1327
|
+
state.wsConnected = true;
|
|
1328
|
+
state.status = "live worker Pi WebSocket connected";
|
|
1329
|
+
updatePiUi(ctx, state);
|
|
1330
|
+
};
|
|
1331
|
+
socket.onmessage = (message2) => {
|
|
1332
|
+
try {
|
|
1333
|
+
const payload = parseWsPayload(message2);
|
|
1334
|
+
if (!catchupDone)
|
|
1335
|
+
buffered.push(payload);
|
|
1336
|
+
else {
|
|
1337
|
+
applyEnvelope(ctx, state, payload);
|
|
1338
|
+
updatePiUi(ctx, state);
|
|
1339
|
+
}
|
|
1340
|
+
} catch (error) {
|
|
1341
|
+
appendTranscript(state, "Error", `Unparseable worker Pi event: ${error instanceof Error ? error.message : String(error)}`);
|
|
1342
|
+
updatePiUi(ctx, state);
|
|
1343
|
+
}
|
|
1344
|
+
};
|
|
1345
|
+
socket.onerror = () => socket.close();
|
|
1346
|
+
socket.onclose = () => {
|
|
1347
|
+
state.wsConnected = false;
|
|
1348
|
+
state.status = "worker Pi WebSocket disconnected";
|
|
1349
|
+
updatePiUi(ctx, state);
|
|
1350
|
+
resolve3();
|
|
1351
|
+
};
|
|
1352
|
+
});
|
|
1353
|
+
try {
|
|
1354
|
+
const [messagesPayload, statusPayload, commandsPayload] = await Promise.all([
|
|
1355
|
+
getRunPiMessagesViaServer(options.context, options.runId),
|
|
1356
|
+
getRunPiStatusViaServer(options.context, options.runId),
|
|
1357
|
+
getRunPiCommandsViaServer(options.context, options.runId)
|
|
1358
|
+
]);
|
|
1359
|
+
const messages = Array.isArray(messagesPayload.messages) ? messagesPayload.messages : [];
|
|
1360
|
+
const native = nativePiUi(ctx);
|
|
1361
|
+
if (state.nativeStream && native?.appendSessionMessages)
|
|
1362
|
+
native.appendSessionMessages(messages);
|
|
1363
|
+
else
|
|
1364
|
+
for (const message2 of messages)
|
|
1365
|
+
applyMessage(state, message2);
|
|
1366
|
+
applyStatus(state, statusPayload);
|
|
1367
|
+
const commands = Array.isArray(commandsPayload.commands) ? commandsPayload.commands : [];
|
|
1368
|
+
state.commands = commands.flatMap((command) => {
|
|
1369
|
+
const record = recordOf(command);
|
|
1370
|
+
return typeof record?.name === "string" ? [`/${record.name}`] : [];
|
|
1371
|
+
});
|
|
1372
|
+
registerDaemonCommandsNatively(pi, options, ctx, state, commands, registeredDaemonCommands);
|
|
1373
|
+
catchupDone = true;
|
|
1374
|
+
for (const payload of buffered.splice(0))
|
|
1375
|
+
applyEnvelope(ctx, state, payload);
|
|
1376
|
+
updatePiUi(ctx, state);
|
|
1377
|
+
} catch (error) {
|
|
1378
|
+
appendTranscript(state, "Error", `Worker Pi catch-up failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1379
|
+
catchupDone = true;
|
|
1380
|
+
updatePiUi(ctx, state);
|
|
1381
|
+
}
|
|
1382
|
+
await closePromise;
|
|
1383
|
+
}
|
|
1384
|
+
function createRemoteBashOperations(options, state, excludeFromContext) {
|
|
1385
|
+
return {
|
|
1386
|
+
exec(command, _cwd, execOptions) {
|
|
1387
|
+
return new Promise((resolve3, reject) => {
|
|
1388
|
+
const pending = {
|
|
1389
|
+
command,
|
|
1390
|
+
onData: execOptions.onData,
|
|
1391
|
+
resolve: resolve3,
|
|
1392
|
+
reject,
|
|
1393
|
+
sawChunk: false
|
|
1394
|
+
};
|
|
1395
|
+
const cleanup = () => {
|
|
1396
|
+
execOptions.signal?.removeEventListener("abort", onAbort);
|
|
1397
|
+
if (timer)
|
|
1398
|
+
clearTimeout(timer);
|
|
1399
|
+
};
|
|
1400
|
+
const onAbort = () => {
|
|
1401
|
+
cleanup();
|
|
1402
|
+
failPendingShell(state, pending, new Error("Remote worker shell command aborted locally."));
|
|
1403
|
+
};
|
|
1404
|
+
const timeoutMs = typeof execOptions.timeout === "number" && execOptions.timeout > 0 ? execOptions.timeout : 0;
|
|
1405
|
+
const timer = timeoutMs > 0 ? setTimeout(() => {
|
|
1406
|
+
cleanup();
|
|
1407
|
+
failPendingShell(state, pending, new Error(`Remote worker shell command timed out after ${timeoutMs}ms.`));
|
|
1408
|
+
}, timeoutMs) : null;
|
|
1409
|
+
const wrappedResolve = pending.resolve;
|
|
1410
|
+
const wrappedReject = pending.reject;
|
|
1411
|
+
pending.resolve = (result) => {
|
|
1412
|
+
cleanup();
|
|
1413
|
+
wrappedResolve(result);
|
|
1414
|
+
};
|
|
1415
|
+
pending.reject = (error) => {
|
|
1416
|
+
cleanup();
|
|
1417
|
+
wrappedReject(error);
|
|
1418
|
+
};
|
|
1419
|
+
execOptions.signal?.addEventListener("abort", onAbort, { once: true });
|
|
1420
|
+
state.pendingShells.push(pending);
|
|
1421
|
+
sendRunPiShellViaServer(options.context, options.runId, `${excludeFromContext ? "!!" : "!"}${command}`).catch((error) => {
|
|
1422
|
+
cleanup();
|
|
1423
|
+
failPendingShell(state, pending, error instanceof Error ? error : new Error(String(error)));
|
|
1424
|
+
});
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
async function answerPendingUi(options, state, line) {
|
|
1430
|
+
const pending = state.pendingUi;
|
|
1431
|
+
if (!pending)
|
|
1432
|
+
return false;
|
|
1433
|
+
if (line === "/cancel") {
|
|
1434
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, pending.requestId, { cancelled: true });
|
|
1435
|
+
} else if (pending.method === "confirm") {
|
|
1436
|
+
const confirmed = /^(y|yes|true|1)$/i.test(line);
|
|
1437
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, pending.requestId, { value: confirmed, confirmed });
|
|
1438
|
+
} else if (pending.options.length > 0 && /^\d+$/.test(line)) {
|
|
1439
|
+
const selected = pending.options[Math.max(0, Number(line) - 1)] ?? line;
|
|
1440
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, pending.requestId, { value: selected });
|
|
1441
|
+
} else {
|
|
1442
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, pending.requestId, { value: line });
|
|
1443
|
+
}
|
|
1444
|
+
appendTranscript(state, "System", `Responded to extension UI request ${pending.requestId}.`);
|
|
1445
|
+
state.pendingUi = null;
|
|
1446
|
+
return true;
|
|
1447
|
+
}
|
|
1448
|
+
async function routeInput(options, ctx, state, line) {
|
|
1449
|
+
const text = line.trim();
|
|
1450
|
+
if (!text)
|
|
1451
|
+
return;
|
|
1452
|
+
if (await answerPendingUi(options, state, text)) {
|
|
1453
|
+
updatePiUi(ctx, state);
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1456
|
+
if (text === "/detach" || text === "/quit" || text === "/q") {
|
|
1457
|
+
appendTranscript(state, "System", "Detached locally; worker Pi daemon continues.");
|
|
1458
|
+
updatePiUi(ctx, state);
|
|
1459
|
+
ctx.shutdown();
|
|
1460
|
+
return;
|
|
1461
|
+
}
|
|
1462
|
+
if (text === "/stop") {
|
|
1463
|
+
await abortRunPiViaServer(options.context, options.runId);
|
|
1464
|
+
appendTranscript(state, "System", "Stop requested for worker Pi daemon.");
|
|
1465
|
+
updatePiUi(ctx, state);
|
|
1466
|
+
ctx.shutdown();
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
if (text.startsWith("!")) {
|
|
1470
|
+
appendTranscript(state, "You", text);
|
|
1471
|
+
await sendRunPiShellViaServer(options.context, options.runId, text);
|
|
1472
|
+
} else if (text.startsWith("/")) {
|
|
1473
|
+
appendTranscript(state, "You", text);
|
|
1474
|
+
const result = await runRunPiCommandViaServer(options.context, options.runId, text);
|
|
1475
|
+
const message2 = typeof result.message === "string" ? result.message : "worker command accepted";
|
|
1476
|
+
appendTranscript(state, "System", message2);
|
|
1477
|
+
} else {
|
|
1478
|
+
appendTranscript(state, "You", text);
|
|
1479
|
+
await sendRunPiPromptViaServer(options.context, options.runId, text, state.streaming ? "steer" : undefined);
|
|
1480
|
+
}
|
|
1481
|
+
updatePiUi(ctx, state);
|
|
1482
|
+
}
|
|
1483
|
+
function createRigWorkerPiBridgeExtension(options) {
|
|
1484
|
+
return (pi) => {
|
|
1485
|
+
const state = {
|
|
1486
|
+
transcript: [],
|
|
1487
|
+
status: "starting worker Pi daemon bridge",
|
|
1488
|
+
activity: "",
|
|
1489
|
+
cwd: "",
|
|
1490
|
+
model: "",
|
|
1491
|
+
commands: [],
|
|
1492
|
+
streaming: false,
|
|
1493
|
+
pendingUi: null,
|
|
1494
|
+
pendingShells: [],
|
|
1495
|
+
wsConnected: false,
|
|
1496
|
+
nativeStream: false
|
|
1497
|
+
};
|
|
1498
|
+
if (options.initialMessageSent)
|
|
1499
|
+
appendTranscript(state, "System", "Initial message sent to worker Pi daemon.");
|
|
1500
|
+
const registeredDaemonCommands = new Set;
|
|
1501
|
+
let nativePiUiContextAvailable = false;
|
|
1502
|
+
pi.on("user_bash", (event) => {
|
|
1503
|
+
state.nativeStream = Boolean(state.nativeStream || nativePiUiContextAvailable);
|
|
1504
|
+
return { operations: createRemoteBashOperations(options, state, event.excludeFromContext === true) };
|
|
1505
|
+
});
|
|
1506
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
1507
|
+
nativePiUiContextAvailable = Boolean(nativePiUi(ctx));
|
|
1508
|
+
state.nativeStream = nativePiUiContextAvailable;
|
|
1509
|
+
updatePiUi(ctx, state);
|
|
1510
|
+
ctx.ui.notify(nativePiUiContextAvailable ? "Connected to the Rig worker session (native stream). /detach exits, /stop cancels the run." : "Connected to the Rig worker session (transcript view). /detach exits, /stop cancels the run.", "info");
|
|
1511
|
+
ctx.ui.onTerminalInput((data) => {
|
|
1512
|
+
if (data.includes("\x04")) {
|
|
1513
|
+
ctx.shutdown();
|
|
1514
|
+
return { consume: true };
|
|
1515
|
+
}
|
|
1516
|
+
if (!data.includes("\r") && !data.includes(`
|
|
1517
|
+
`))
|
|
1518
|
+
return;
|
|
1519
|
+
const inlineText = data.replace(/[\r\n]+/g, "").trim();
|
|
1520
|
+
const editorText = ctx.ui.getEditorText().trim();
|
|
1521
|
+
const text = [editorText, inlineText].filter(Boolean).join(" ").trim();
|
|
1522
|
+
if (!text)
|
|
1523
|
+
return;
|
|
1524
|
+
if (text.startsWith("!"))
|
|
1525
|
+
return;
|
|
1526
|
+
ctx.ui.setEditorText("");
|
|
1527
|
+
routeInput(options, ctx, state, text).catch((error) => {
|
|
1528
|
+
appendTranscript(state, "Error", error instanceof Error ? error.message : String(error));
|
|
1529
|
+
updatePiUi(ctx, state);
|
|
1530
|
+
});
|
|
1531
|
+
return { consume: true };
|
|
1532
|
+
});
|
|
1533
|
+
connectWorkerStream(options, pi, ctx, state, registeredDaemonCommands).catch((error) => {
|
|
1534
|
+
appendTranscript(state, "Error", error instanceof Error ? error.message : String(error));
|
|
1535
|
+
updatePiUi(ctx, state);
|
|
1536
|
+
});
|
|
1537
|
+
});
|
|
1538
|
+
pi.on("session_shutdown", () => {});
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
// packages/cli/src/commands/_pi-frontend.ts
|
|
1543
|
+
function setTemporaryEnv(updates) {
|
|
1544
|
+
const previous = new Map;
|
|
1545
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
1546
|
+
previous.set(key, process.env[key]);
|
|
1547
|
+
process.env[key] = value;
|
|
1548
|
+
}
|
|
1549
|
+
return () => {
|
|
1550
|
+
for (const [key, value] of previous) {
|
|
1551
|
+
if (value === undefined)
|
|
1552
|
+
delete process.env[key];
|
|
1553
|
+
else
|
|
1554
|
+
process.env[key] = value;
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
async function attachRunBundledPiFrontend(context, input) {
|
|
1559
|
+
const tempRoot = mkdtempSync(join(tmpdir(), "rig-pi-frontend-"));
|
|
1560
|
+
const cwd = join(tempRoot, "workspace");
|
|
1561
|
+
const agentDir = join(tempRoot, "agent");
|
|
1562
|
+
const sessionDir = join(tempRoot, "sessions");
|
|
1563
|
+
const previousCwd = process.cwd();
|
|
1564
|
+
const restoreEnv = setTemporaryEnv({
|
|
1565
|
+
PI_CODING_AGENT_DIR: agentDir,
|
|
1566
|
+
PI_CODING_AGENT_SESSION_DIR: sessionDir,
|
|
1567
|
+
PI_OFFLINE: "1",
|
|
1568
|
+
PI_SKIP_VERSION_CHECK: "1"
|
|
1569
|
+
});
|
|
1570
|
+
let detached = false;
|
|
1571
|
+
try {
|
|
1572
|
+
await Bun.$`mkdir -p ${cwd} ${agentDir} ${sessionDir}`.quiet();
|
|
1573
|
+
process.chdir(cwd);
|
|
1574
|
+
await runPiMain([
|
|
1575
|
+
"--offline",
|
|
1576
|
+
"--no-session",
|
|
1577
|
+
"--no-tools",
|
|
1578
|
+
"--no-builtin-tools",
|
|
1579
|
+
"--no-skills",
|
|
1580
|
+
"--no-context-files",
|
|
1581
|
+
"--no-approve"
|
|
1582
|
+
], {
|
|
1583
|
+
extensionFactories: [
|
|
1584
|
+
createRigWorkerPiBridgeExtension({
|
|
1585
|
+
context,
|
|
1586
|
+
runId: input.runId,
|
|
1587
|
+
initialMessageSent: input.steered === true
|
|
1588
|
+
})
|
|
1589
|
+
]
|
|
1590
|
+
});
|
|
1591
|
+
detached = true;
|
|
1592
|
+
} finally {
|
|
1593
|
+
process.chdir(previousCwd);
|
|
1594
|
+
restoreEnv();
|
|
1595
|
+
rmSync(tempRoot, { recursive: true, force: true });
|
|
1596
|
+
}
|
|
1597
|
+
let run = { runId: input.runId, status: "unknown" };
|
|
1598
|
+
try {
|
|
1599
|
+
run = await getRunDetailsViaServer(context, input.runId);
|
|
1600
|
+
} catch {}
|
|
1601
|
+
return {
|
|
1602
|
+
run,
|
|
1603
|
+
logs: [],
|
|
1604
|
+
timeline: [],
|
|
1605
|
+
timelineCursor: null,
|
|
1606
|
+
steered: input.steered === true,
|
|
1607
|
+
detached,
|
|
1608
|
+
rendered: "actual bundled Pi frontend hosted Rig worker Pi bridge extension"
|
|
1609
|
+
};
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
// packages/cli/src/commands/_operator-view.ts
|
|
1613
|
+
var TERMINAL_RUN_STATUSES2 = new Set(["completed", "failed", "stopped", "cancelled", "canceled", "closed", "merged", "needs_attention", "needs-attention"]);
|
|
781
1614
|
function runStatusFromPayload(payload) {
|
|
782
1615
|
const run = payload.run && typeof payload.run === "object" && !Array.isArray(payload.run) ? payload.run : payload;
|
|
783
1616
|
return String(run.status ?? "unknown").toLowerCase();
|
|
@@ -799,56 +1632,640 @@ async function applyOperatorCommand(context, input, deps = {}) {
|
|
|
799
1632
|
await (deps.steer ?? steerRunViaServer)(context, input.runId, userMessage);
|
|
800
1633
|
return { action: "continue", message: "Steering message queued." };
|
|
801
1634
|
}
|
|
802
|
-
async function readOperatorSnapshot(context, runId) {
|
|
1635
|
+
async function readOperatorSnapshot(context, runId, options = {}) {
|
|
803
1636
|
const run = await getRunDetailsViaServer(context, runId);
|
|
804
1637
|
const logsPage = await getRunLogsViaServer(context, runId, { limit: 100 });
|
|
805
|
-
const
|
|
806
|
-
|
|
1638
|
+
const timelinePage = await getRunTimelineViaServer(context, runId, { limit: 200, ...options.timelineCursor ? { cursor: options.timelineCursor } : {} }).catch((error) => ({
|
|
1639
|
+
entries: [{
|
|
1640
|
+
id: `timeline-unavailable:${runId}`,
|
|
1641
|
+
type: "timeline_warning",
|
|
1642
|
+
detail: `Selected Rig server did not provide run timeline events: ${error instanceof Error ? error.message : String(error)}`,
|
|
1643
|
+
createdAt: new Date().toISOString()
|
|
1644
|
+
}],
|
|
1645
|
+
nextCursor: options.timelineCursor ?? null
|
|
1646
|
+
}));
|
|
1647
|
+
const logs = Array.isArray(logsPage.entries) ? logsPage.entries.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry))).toReversed() : [];
|
|
1648
|
+
const timeline = Array.isArray(timelinePage.entries) ? timelinePage.entries.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry))) : [];
|
|
1649
|
+
const timelineCursor = typeof timelinePage.nextCursor === "string" ? timelinePage.nextCursor : options.timelineCursor ?? null;
|
|
1650
|
+
return { run, logs, timeline, timelineCursor, rendered: renderOperatorSnapshot({ run, logs, timeline }) };
|
|
807
1651
|
}
|
|
808
1652
|
async function attachRunOperatorView(context, input) {
|
|
809
1653
|
let steered = false;
|
|
810
1654
|
if (input.message?.trim()) {
|
|
811
|
-
await steerRunViaServer(context, input.runId, input.message.trim());
|
|
1655
|
+
await sendRunPiPromptViaServer(context, input.runId, input.message.trim(), "steer").catch(() => steerRunViaServer(context, input.runId, input.message.trim()));
|
|
812
1656
|
steered = true;
|
|
813
1657
|
}
|
|
1658
|
+
if (input.follow && !input.once && input.interactive !== false && context.outputMode === "text" && Boolean(process.stdin.isTTY && process.stdout.isTTY)) {
|
|
1659
|
+
return attachRunBundledPiFrontend(context, {
|
|
1660
|
+
runId: input.runId,
|
|
1661
|
+
steered
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
const surface = createOperatorSurface({ interactive: input.interactive !== false });
|
|
814
1665
|
let snapshot = await readOperatorSnapshot(context, input.runId);
|
|
815
1666
|
if (context.outputMode === "text") {
|
|
816
|
-
|
|
1667
|
+
surface.renderSnapshot(snapshot);
|
|
1668
|
+
surface.renderTimeline(snapshot.timeline);
|
|
1669
|
+
surface.renderLogs(snapshot.logs);
|
|
817
1670
|
if (steered)
|
|
818
|
-
|
|
1671
|
+
surface.info("Message submitted to worker Pi.");
|
|
819
1672
|
}
|
|
820
1673
|
let detached = false;
|
|
821
|
-
let
|
|
1674
|
+
let commandInput = null;
|
|
822
1675
|
if (input.follow && !input.once && context.outputMode === "text") {
|
|
823
1676
|
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)}`));
|
|
1677
|
+
surface.info("Controls: /user <message>, /stop, /detach");
|
|
1678
|
+
commandInput = surface.attachCommandInput(async (line) => {
|
|
1679
|
+
const result = await applyOperatorCommand(context, { runId: input.runId, line });
|
|
1680
|
+
if (result.message)
|
|
1681
|
+
surface.info(result.message);
|
|
1682
|
+
if (result.action === "detach" || result.action === "stopped") {
|
|
1683
|
+
detached = true;
|
|
1684
|
+
commandInput?.close();
|
|
1685
|
+
}
|
|
835
1686
|
});
|
|
836
1687
|
}
|
|
837
|
-
let lastRendered = snapshot.rendered;
|
|
838
1688
|
const pollMs = Math.max(250, Math.trunc(input.pollMs ?? 2000));
|
|
839
|
-
|
|
1689
|
+
let timelineCursor = snapshot.timelineCursor;
|
|
1690
|
+
while (!detached && !TERMINAL_RUN_STATUSES2.has(runStatusFromPayload(snapshot.run))) {
|
|
840
1691
|
await Bun.sleep(pollMs);
|
|
841
|
-
snapshot = await readOperatorSnapshot(context, input.runId);
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
1692
|
+
snapshot = await readOperatorSnapshot(context, input.runId, { timelineCursor });
|
|
1693
|
+
timelineCursor = snapshot.timelineCursor;
|
|
1694
|
+
surface.renderSnapshot(snapshot);
|
|
1695
|
+
surface.renderTimeline(snapshot.timeline);
|
|
1696
|
+
surface.renderLogs(snapshot.logs);
|
|
846
1697
|
}
|
|
847
|
-
|
|
1698
|
+
commandInput?.close();
|
|
848
1699
|
}
|
|
849
1700
|
return { ...snapshot, steered, detached };
|
|
850
1701
|
}
|
|
851
1702
|
|
|
1703
|
+
// packages/cli/src/commands/_cli-format.ts
|
|
1704
|
+
import { log, note } from "@clack/prompts";
|
|
1705
|
+
import pc from "picocolors";
|
|
1706
|
+
function stringField(record, key, fallback = "") {
|
|
1707
|
+
const value = record[key];
|
|
1708
|
+
return typeof value === "string" && value.trim() ? value.trim() : fallback;
|
|
1709
|
+
}
|
|
1710
|
+
function numberField(record, key) {
|
|
1711
|
+
const value = record[key];
|
|
1712
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
1713
|
+
}
|
|
1714
|
+
function arrayField(record, key) {
|
|
1715
|
+
const value = record[key];
|
|
1716
|
+
return Array.isArray(value) ? value.flatMap((entry) => typeof entry === "string" && entry.trim() ? [entry.trim()] : []) : [];
|
|
1717
|
+
}
|
|
1718
|
+
function rawObject(record) {
|
|
1719
|
+
const raw = record.raw;
|
|
1720
|
+
return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
1721
|
+
}
|
|
1722
|
+
function truncate(value, width) {
|
|
1723
|
+
if (value.length <= width)
|
|
1724
|
+
return value;
|
|
1725
|
+
if (width <= 1)
|
|
1726
|
+
return "\u2026";
|
|
1727
|
+
return `${value.slice(0, width - 1)}\u2026`;
|
|
1728
|
+
}
|
|
1729
|
+
function pad(value, width) {
|
|
1730
|
+
return value.length >= width ? value : `${value}${" ".repeat(width - value.length)}`;
|
|
1731
|
+
}
|
|
1732
|
+
function statusColor(status) {
|
|
1733
|
+
const normalized = status.toLowerCase();
|
|
1734
|
+
if (["completed", "merged", "closed", "done", "accepted", "pass", "selected", "approved"].includes(normalized))
|
|
1735
|
+
return pc.green;
|
|
1736
|
+
if (["failed", "needs_attention", "needs-attention", "blocked", "error", "rejected"].includes(normalized))
|
|
1737
|
+
return pc.red;
|
|
1738
|
+
if (["running", "reviewing", "validating", "in_progress", "in-progress", "remote"].includes(normalized))
|
|
1739
|
+
return pc.cyan;
|
|
1740
|
+
if (["ready", "open", "queued", "created", "preparing", "local", "pending"].includes(normalized))
|
|
1741
|
+
return pc.yellow;
|
|
1742
|
+
return pc.dim;
|
|
1743
|
+
}
|
|
1744
|
+
function compactValue(value) {
|
|
1745
|
+
if (value === null || value === undefined)
|
|
1746
|
+
return "";
|
|
1747
|
+
if (typeof value === "string")
|
|
1748
|
+
return value;
|
|
1749
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
1750
|
+
return String(value);
|
|
1751
|
+
if (Array.isArray(value))
|
|
1752
|
+
return value.map(compactValue).filter(Boolean).join(", ");
|
|
1753
|
+
return JSON.stringify(value);
|
|
1754
|
+
}
|
|
1755
|
+
function shouldUseClackOutput() {
|
|
1756
|
+
return Boolean(process.stdout.isTTY) && process.env.RIG_CLI_PLAIN_HELP !== "1";
|
|
1757
|
+
}
|
|
1758
|
+
function printFormattedOutput(message2, options = {}) {
|
|
1759
|
+
if (!shouldUseClackOutput()) {
|
|
1760
|
+
console.log(message2);
|
|
1761
|
+
return;
|
|
1762
|
+
}
|
|
1763
|
+
if (options.title)
|
|
1764
|
+
note(message2, options.title);
|
|
1765
|
+
else
|
|
1766
|
+
log.message(message2);
|
|
1767
|
+
}
|
|
1768
|
+
function formatStatusPill(status) {
|
|
1769
|
+
const label = status || "unknown";
|
|
1770
|
+
return statusColor(label)(`\u25CF ${label}`);
|
|
1771
|
+
}
|
|
1772
|
+
function formatSection(title, subtitle) {
|
|
1773
|
+
return `${pc.bold(pc.cyan("\u25C6"))} ${pc.bold(title)}${subtitle ? pc.dim(` \u2014 ${subtitle}`) : ""}`;
|
|
1774
|
+
}
|
|
1775
|
+
function formatSuccessCard(title, rows = []) {
|
|
1776
|
+
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}`);
|
|
1777
|
+
return [formatSection(title), ...body].join(`
|
|
1778
|
+
`);
|
|
1779
|
+
}
|
|
1780
|
+
function formatNextSteps(steps) {
|
|
1781
|
+
if (steps.length === 0)
|
|
1782
|
+
return [];
|
|
1783
|
+
return [pc.bold("Next"), ...steps.map((step) => `${pc.dim("\u203A")} ${step}`)];
|
|
1784
|
+
}
|
|
1785
|
+
function formatTaskList(tasks, options = {}) {
|
|
1786
|
+
if (options.raw)
|
|
1787
|
+
return tasks.map((task) => JSON.stringify(task)).join(`
|
|
1788
|
+
`);
|
|
1789
|
+
if (tasks.length === 0)
|
|
1790
|
+
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(`
|
|
1791
|
+
`);
|
|
1792
|
+
const rows = tasks.map((task) => {
|
|
1793
|
+
const raw = rawObject(task);
|
|
1794
|
+
const id = stringField(task, "id", "<unknown>");
|
|
1795
|
+
const status = stringField(task, "status", "unknown");
|
|
1796
|
+
const title = stringField(task, "title", "Untitled task");
|
|
1797
|
+
const source = stringField(task, "source", stringField(raw, "source", ""));
|
|
1798
|
+
const labels = arrayField(task, "labels").length > 0 ? arrayField(task, "labels") : arrayField(raw, "labels");
|
|
1799
|
+
return { id, status, title, source, labels };
|
|
1800
|
+
});
|
|
1801
|
+
const idWidth = Math.min(18, Math.max(4, ...rows.map((row) => row.id.length)));
|
|
1802
|
+
const statusWidth = Math.min(16, Math.max(6, ...rows.map((row) => row.status.length)));
|
|
1803
|
+
const header = `${pc.bold(pad("TASK", idWidth))} ${pc.bold(pad("STATUS", statusWidth))} ${pc.bold("TITLE")}`;
|
|
1804
|
+
const body = rows.map((row) => {
|
|
1805
|
+
const labels = row.labels.length > 0 ? pc.dim(` ${row.labels.slice(0, 4).map((label) => `#${label}`).join(" ")}`) : "";
|
|
1806
|
+
const source = row.source ? pc.dim(` ${row.source}`) : "";
|
|
1807
|
+
return [
|
|
1808
|
+
pc.bold(pad(truncate(row.id, idWidth), idWidth)),
|
|
1809
|
+
statusColor(row.status)(pad(truncate(row.status, statusWidth), statusWidth)),
|
|
1810
|
+
`${row.title}${labels}${source}`
|
|
1811
|
+
].join(" ");
|
|
1812
|
+
});
|
|
1813
|
+
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(`
|
|
1814
|
+
`);
|
|
1815
|
+
}
|
|
1816
|
+
function formatTaskCard(task, options = {}) {
|
|
1817
|
+
const raw = rawObject(task);
|
|
1818
|
+
const id = stringField(task, "id", stringField(raw, "id", "<unknown>"));
|
|
1819
|
+
const status = stringField(task, "status", stringField(raw, "status", "unknown"));
|
|
1820
|
+
const title = stringField(task, "title", stringField(raw, "title", "Untitled task"));
|
|
1821
|
+
const source = stringField(task, "source", stringField(raw, "source", ""));
|
|
1822
|
+
const url = stringField(task, "url", stringField(raw, "url", ""));
|
|
1823
|
+
const number = numberField(task, "number") ?? numberField(raw, "number");
|
|
1824
|
+
const labels = arrayField(task, "labels").length > 0 ? arrayField(task, "labels") : arrayField(raw, "labels");
|
|
1825
|
+
const assignees = arrayField(task, "assignees").length > 0 ? arrayField(task, "assignees") : arrayField(raw, "assignees");
|
|
1826
|
+
const readiness = compactValue(task.readiness ?? raw.readiness);
|
|
1827
|
+
const validators = compactValue(task.validators ?? raw.validators ?? task.validation ?? raw.validation);
|
|
1828
|
+
const rows = [
|
|
1829
|
+
["task", pc.bold(id)],
|
|
1830
|
+
["status", formatStatusPill(status)],
|
|
1831
|
+
["title", title],
|
|
1832
|
+
["source", source],
|
|
1833
|
+
["number", number],
|
|
1834
|
+
["labels", labels.length ? labels.map((label) => `#${label}`).join(" ") : ""],
|
|
1835
|
+
["assignees", assignees.join(", ")],
|
|
1836
|
+
["readiness", readiness],
|
|
1837
|
+
["validators", validators],
|
|
1838
|
+
["url", url]
|
|
1839
|
+
];
|
|
1840
|
+
return [
|
|
1841
|
+
formatSuccessCard(options.title ?? (options.selected ? "Selected task" : "Task"), rows),
|
|
1842
|
+
"",
|
|
1843
|
+
...formatNextSteps([`Start: \`rig task run ${id}\``, `Details: \`rig task show ${id} --raw\``])
|
|
1844
|
+
].join(`
|
|
1845
|
+
`);
|
|
1846
|
+
}
|
|
1847
|
+
function formatTaskDetails(task) {
|
|
1848
|
+
return formatTaskCard(task, { title: "Task details" });
|
|
1849
|
+
}
|
|
1850
|
+
function formatSubmittedRun(input) {
|
|
1851
|
+
const rows = [["run", pc.bold(input.runId)]];
|
|
1852
|
+
if (input.task) {
|
|
1853
|
+
const id = stringField(input.task, "id", "<unknown>");
|
|
1854
|
+
const status = stringField(input.task, "status", "unknown");
|
|
1855
|
+
const title = stringField(input.task, "title", "Untitled task");
|
|
1856
|
+
rows.push(["task", `${pc.bold(id)} ${formatStatusPill(status)} ${title}`]);
|
|
1857
|
+
}
|
|
1858
|
+
const runtime = [input.runtimeAdapter || "pi", input.runtimeMode || "full-access", input.interactionMode || "default"].filter(Boolean).join(" \xB7 ");
|
|
1859
|
+
rows.push(["runtime", runtime]);
|
|
1860
|
+
return [
|
|
1861
|
+
formatSuccessCard("Run submitted", rows),
|
|
1862
|
+
"",
|
|
1863
|
+
...formatNextSteps([
|
|
1864
|
+
`Attach: \`rig run attach ${input.runId} --follow\``,
|
|
1865
|
+
`Inspect: \`rig run show ${input.runId}\``,
|
|
1866
|
+
input.detached ? "Submitted detached; attach when you are ready." : "Interactive mode opens the native bundled Pi frontend."
|
|
1867
|
+
])
|
|
1868
|
+
].join(`
|
|
1869
|
+
`);
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
// packages/cli/src/commands/_help-catalog.ts
|
|
1873
|
+
import { intro, log as log2, note as note2, outro } from "@clack/prompts";
|
|
1874
|
+
import pc2 from "picocolors";
|
|
1875
|
+
var TOP_LEVEL_SECTIONS = [
|
|
1876
|
+
{
|
|
1877
|
+
title: "Start here",
|
|
1878
|
+
subtitle: "one-time setup for a repo",
|
|
1879
|
+
commands: [
|
|
1880
|
+
{ command: "rig init", description: "Wizard: config, GitHub auth, task source, server, Pi wiring." },
|
|
1881
|
+
{ command: "rig doctor", description: "Check every part of the wiring \u2014 run this when anything feels off." },
|
|
1882
|
+
{ command: "rig server use <alias|local>", description: "Pick which Rig server owns this repo (`rig server list` to see them)." }
|
|
1883
|
+
]
|
|
1884
|
+
},
|
|
1885
|
+
{
|
|
1886
|
+
title: "Work",
|
|
1887
|
+
subtitle: "find a task and put an agent on it",
|
|
1888
|
+
commands: [
|
|
1889
|
+
{ command: "rig task list", description: "What's on the board (from the selected source/server)." },
|
|
1890
|
+
{ command: "rig task next", description: "The next ready task, as a card." },
|
|
1891
|
+
{ command: "rig task run --next", description: "Dispatch an agent; interactive mode opens the native Pi session." },
|
|
1892
|
+
{ command: "rig task run <id> --detach", description: "Fire-and-forget a specific task." }
|
|
1893
|
+
]
|
|
1894
|
+
},
|
|
1895
|
+
{
|
|
1896
|
+
title: "Watch & steer",
|
|
1897
|
+
subtitle: "live runs are observable and steerable, attached or not",
|
|
1898
|
+
commands: [
|
|
1899
|
+
{ command: "rig run status", description: "Active and recent runs at a glance." },
|
|
1900
|
+
{ command: "rig run attach <id> --follow", description: "Join the live Pi session (worker keeps running if you /detach)." },
|
|
1901
|
+
{ command: "rig run steer <id> -m <text>", description: "Drop a message into a live worker without attaching." },
|
|
1902
|
+
{ command: "rig run stop <id>", description: "Cancel a running worker." }
|
|
1903
|
+
]
|
|
1904
|
+
},
|
|
1905
|
+
{
|
|
1906
|
+
title: "Unblock & gate",
|
|
1907
|
+
subtitle: "answer what workers ask; control what merges",
|
|
1908
|
+
commands: [
|
|
1909
|
+
{ command: "rig inbox approvals", description: "Approvals workers are waiting on (then `rig inbox approve \u2026`)." },
|
|
1910
|
+
{ command: "rig inbox inputs", description: "Questions workers asked (then `rig inbox respond \u2026`)." },
|
|
1911
|
+
{ command: "rig review show|set", description: "The completion review gate (Greptile is mandatory on merges)." }
|
|
1912
|
+
]
|
|
1913
|
+
},
|
|
1914
|
+
{
|
|
1915
|
+
title: "Extend",
|
|
1916
|
+
subtitle: "more Pi, more plugins",
|
|
1917
|
+
commands: [
|
|
1918
|
+
{ command: "rig pi search <term>", description: "Discover community Pi extensions on npm." },
|
|
1919
|
+
{ command: "rig pi add <pkg>", description: "Add a Pi extension to this project (workers pick it up too)." },
|
|
1920
|
+
{ command: "rig plugin list", description: "What the rig.config.ts plugins contribute." }
|
|
1921
|
+
]
|
|
1922
|
+
}
|
|
1923
|
+
];
|
|
1924
|
+
var PRIMARY_GROUPS = [
|
|
1925
|
+
{
|
|
1926
|
+
name: "server",
|
|
1927
|
+
summary: "Choose, inspect, and start the Rig server that owns tasks and runs.",
|
|
1928
|
+
usage: ["rig server <status|list|add|use|start> [options]"],
|
|
1929
|
+
commands: [
|
|
1930
|
+
{ command: "status", description: "Show the selected server for this repo.", primary: true },
|
|
1931
|
+
{ command: "use local", description: "Switch this repo to the local Rig server.", primary: true },
|
|
1932
|
+
{ command: "add <alias> <url>", description: "Save a remote Rig server URL.", primary: true },
|
|
1933
|
+
{ command: "use <alias>", description: "Select a saved remote server alias.", primary: true },
|
|
1934
|
+
{ command: "list", description: "List saved local/remote server aliases.", primary: true },
|
|
1935
|
+
{ command: "start [--host <host>] [--port <n>]", description: "Start a local rig-server process." }
|
|
1936
|
+
],
|
|
1937
|
+
examples: [
|
|
1938
|
+
"rig server status",
|
|
1939
|
+
"rig server add prod https://where.rig-does.work",
|
|
1940
|
+
"rig server use prod",
|
|
1941
|
+
"rig server use local",
|
|
1942
|
+
"rig server start --port 3773"
|
|
1943
|
+
],
|
|
1944
|
+
next: ["Use `rig task list` to see server-owned work.", "Use `rig run list` or `rig run attach <id> --follow` to monitor runs."],
|
|
1945
|
+
advanced: ["Compatibility alias: `rig connect ...` remains callable."]
|
|
1946
|
+
},
|
|
1947
|
+
{
|
|
1948
|
+
name: "task",
|
|
1949
|
+
summary: "Find work, start Pi-backed runs, and validate task results.",
|
|
1950
|
+
usage: ["rig task <list|next|show|run> [options]"],
|
|
1951
|
+
commands: [
|
|
1952
|
+
{ command: "list [--assignee <login|@me>] [--state open|closed]", description: "List tasks from the selected server/source.", primary: true },
|
|
1953
|
+
{ command: "next [filters]", description: "Render the next matching task as a selected-task card.", primary: true },
|
|
1954
|
+
{ command: "show <id>|--task <id> [--raw]", description: "Show a human task summary; --raw prints the full payload.", primary: true },
|
|
1955
|
+
{ command: "run [#<issue>|<task-id>|--next|--task <id>]", description: "Submit a task run; interactive follows with bundled Pi.", primary: true },
|
|
1956
|
+
{ command: "validate|verify [--task <id>]", description: "Run configured task checks/review gates." },
|
|
1957
|
+
{ command: "details --task <id>", description: "Show full task info from the configured source." },
|
|
1958
|
+
{ command: "reopen [--task <id> | --all] [--reason <text>]", description: "Reopen closed task(s) in the configured source." },
|
|
1959
|
+
{ command: "reset --task <id>", description: "Compatibility spelling of `reopen --task <id>`." },
|
|
1960
|
+
{ command: "artifacts|artifact-dir|artifact-write", description: "Inspect or write task artifacts." },
|
|
1961
|
+
{ command: "report-bug", description: "Create a structured bug report/task." }
|
|
1962
|
+
],
|
|
1963
|
+
examples: [
|
|
1964
|
+
"rig task list --assignee @me --limit 20",
|
|
1965
|
+
"rig task next",
|
|
1966
|
+
"rig task show 123 --raw",
|
|
1967
|
+
"rig task run --next",
|
|
1968
|
+
"rig task run #123 --runtime-adapter pi",
|
|
1969
|
+
"rig task run --title 'Investigate deploy drift' --initial-prompt 'Check server health'"
|
|
1970
|
+
],
|
|
1971
|
+
next: ["Use `--detach` to submit without attaching.", "Use `rig run attach <run-id> --follow` to rejoin a live run."]
|
|
1972
|
+
},
|
|
1973
|
+
{
|
|
1974
|
+
name: "run",
|
|
1975
|
+
summary: "Observe, attach to, and control Rig runs.",
|
|
1976
|
+
usage: ["rig run <list|status|show|attach|stop> [options]"],
|
|
1977
|
+
commands: [
|
|
1978
|
+
{ command: "list", description: "List recent runs from the selected server or local state.", primary: true },
|
|
1979
|
+
{ command: "status", description: "Render active and recent run groups.", primary: true },
|
|
1980
|
+
{ command: "show <id>|--run <id> [--raw]", description: "Show a human run summary; --raw prints the full payload.", primary: true },
|
|
1981
|
+
{ command: "attach <run-id>|--run <id> [--follow]", description: "Attach to the run; --follow launches native bundled Pi for live Pi runs.", primary: true },
|
|
1982
|
+
{ command: "stop [<run-id>|--run <id>]", description: "Request stop for one run or local active runs.", primary: true },
|
|
1983
|
+
{ command: "steer <run-id> --message <text>", description: "Queue a steering message into a live worker without attaching." },
|
|
1984
|
+
{ command: "timeline --run <id> [--follow]", description: "Stream raw run timeline events." },
|
|
1985
|
+
{ command: "resume", description: "Resume the most recent interrupted local run." },
|
|
1986
|
+
{ command: "restart", description: "Restart the most recent local run from a clean runtime." },
|
|
1987
|
+
{ command: "delete|cleanup", description: "Remove completed run records/artifacts." }
|
|
1988
|
+
],
|
|
1989
|
+
examples: [
|
|
1990
|
+
"rig run list",
|
|
1991
|
+
"rig run status",
|
|
1992
|
+
"rig run show <run-id>",
|
|
1993
|
+
"rig run attach <run-id> --follow",
|
|
1994
|
+
"rig run stop <run-id>"
|
|
1995
|
+
],
|
|
1996
|
+
next: ["Use `rig task run --next` to create a new run.", "Use `--json` when scripts need the full structured record."]
|
|
1997
|
+
},
|
|
1998
|
+
{
|
|
1999
|
+
name: "inbox",
|
|
2000
|
+
summary: "Review approval and user-input requests that block worker runs.",
|
|
2001
|
+
usage: ["rig inbox <approvals|approve|inputs|respond> [options]"],
|
|
2002
|
+
commands: [
|
|
2003
|
+
{ command: "approvals [--run <id>] [--task <id>]", description: "List pending approvals.", primary: true },
|
|
2004
|
+
{ command: "inputs [--run <id>] [--task <id>]", description: "List pending user-input requests.", primary: true },
|
|
2005
|
+
{ command: "approve --run <id> --request <id> --decision approve|reject", description: "Resolve an approval request." },
|
|
2006
|
+
{ command: "respond --run <id> --request <id> --answer key=value", description: "Answer a user-input request." }
|
|
2007
|
+
],
|
|
2008
|
+
examples: [
|
|
2009
|
+
"rig inbox approvals",
|
|
2010
|
+
"rig inbox inputs --run <run-id>",
|
|
2011
|
+
"rig inbox approve --run <run-id> --request <request-id> --decision approve"
|
|
2012
|
+
],
|
|
2013
|
+
next: ["Rejoin the run after resolving a block: `rig run attach <run-id> --follow`."]
|
|
2014
|
+
},
|
|
2015
|
+
{
|
|
2016
|
+
name: "review",
|
|
2017
|
+
summary: "Inspect or change completion review gate policy.",
|
|
2018
|
+
usage: ["rig review <show|set>"],
|
|
2019
|
+
commands: [
|
|
2020
|
+
{ command: "show", description: "Show current review gate settings.", primary: true },
|
|
2021
|
+
{ command: "set <off|advisory|required> [--provider greptile]", description: "Change review strictness/provider.", primary: true }
|
|
2022
|
+
],
|
|
2023
|
+
examples: ["rig review show", "rig review set required --provider greptile"],
|
|
2024
|
+
next: ["Use `rig inbox approvals` for blocked run handoffs."]
|
|
2025
|
+
},
|
|
2026
|
+
{
|
|
2027
|
+
name: "init",
|
|
2028
|
+
summary: "Set up Rig for this repo: server, GitHub auth, checkout strategy, task source, and Pi wiring.",
|
|
2029
|
+
usage: ["rig init [--yes] [--server local|remote] [--repo owner/repo] [--remote-url <url>]"],
|
|
2030
|
+
commands: [
|
|
2031
|
+
{ command: "init", description: "Interactive setup wizard for a new or existing Rig repo.", primary: true },
|
|
2032
|
+
{ command: "init --yes", description: "Non-interactive setup using detected/default settings.", primary: true },
|
|
2033
|
+
{ command: "init --server remote --remote-url <url>", description: "Link this repo to a remote Rig server.", primary: true },
|
|
2034
|
+
{ command: "init --repair", description: "Repair missing private state without replacing project config." }
|
|
2035
|
+
],
|
|
2036
|
+
examples: [
|
|
2037
|
+
"rig init",
|
|
2038
|
+
"rig init --yes --repo humanity-org/humanwork",
|
|
2039
|
+
"rig init --server remote --remote-url https://where.rig-does.work --repo owner/repo"
|
|
2040
|
+
],
|
|
2041
|
+
next: ["After init, run `rig server status`.", "Then use `rig task list` and `rig task run --next` for day-to-day work."]
|
|
2042
|
+
},
|
|
2043
|
+
{
|
|
2044
|
+
name: "doctor",
|
|
2045
|
+
summary: "Diagnostics for project/server/GitHub/Pi state.",
|
|
2046
|
+
usage: ["rig doctor"],
|
|
2047
|
+
commands: [
|
|
2048
|
+
{ command: "doctor", description: "Run setup and runtime diagnostics.", primary: true },
|
|
2049
|
+
{ command: "check", description: "Compatibility spelling for diagnostics." }
|
|
2050
|
+
],
|
|
2051
|
+
examples: ["rig doctor", "rig doctor --json"],
|
|
2052
|
+
next: ["Use `rig server status` and `rig github auth status` to inspect common failure points."]
|
|
2053
|
+
},
|
|
2054
|
+
{
|
|
2055
|
+
name: "github",
|
|
2056
|
+
summary: "GitHub auth helpers for the selected Rig server.",
|
|
2057
|
+
usage: ["rig github auth <status|import-gh|token>"],
|
|
2058
|
+
commands: [
|
|
2059
|
+
{ command: "auth status", description: "Show GitHub auth state.", primary: true },
|
|
2060
|
+
{ command: "auth import-gh", description: "Import the current `gh` token into the selected server." },
|
|
2061
|
+
{ command: "auth token --token <token>", description: "Store a token on the selected server." }
|
|
2062
|
+
],
|
|
2063
|
+
examples: ["rig github auth status", "rig github auth import-gh"],
|
|
2064
|
+
next: ["After auth is valid, use `rig task run --next`."]
|
|
2065
|
+
}
|
|
2066
|
+
];
|
|
2067
|
+
var ADVANCED_GROUPS = [
|
|
2068
|
+
{ 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." }] },
|
|
2069
|
+
{ name: "setup", summary: "Bootstrap/check local setup.", usage: ["rig setup <bootstrap|check|preflight>"], commands: [{ command: "bootstrap|check|preflight", description: "Setup helpers." }] },
|
|
2070
|
+
{
|
|
2071
|
+
name: "inspect",
|
|
2072
|
+
summary: "Inspect logs, artifacts, graphs, failures for a task.",
|
|
2073
|
+
usage: ["rig inspect <logs|artifacts|failures|graph|audit|diff> --task <id>"],
|
|
2074
|
+
commands: [
|
|
2075
|
+
{ command: "logs --task <id>", description: "Latest run log for a task (local or selected server)." },
|
|
2076
|
+
{ command: "artifacts --task <id>", description: "List the task's completion artifacts." },
|
|
2077
|
+
{ command: "failures --task <id>", description: "Recorded failures for a task." },
|
|
2078
|
+
{ command: "graph", description: "Task dependency graph." },
|
|
2079
|
+
{ command: "audit", description: "Controlled-command audit trail." },
|
|
2080
|
+
{ command: "diff --task <id>", description: "Changed files for a task." }
|
|
2081
|
+
]
|
|
2082
|
+
},
|
|
2083
|
+
{ name: "repo", summary: "Repository sync/baseline helpers.", usage: ["rig repo <sync|reset-baseline>"], commands: [{ command: "sync", description: "Sync project repository state." }] },
|
|
2084
|
+
{ name: "profile", summary: "Runtime profile/model defaults.", usage: ["rig profile <show|set>"], commands: [{ command: "show", description: "Show active profile." }] },
|
|
2085
|
+
{
|
|
2086
|
+
name: "browser",
|
|
2087
|
+
summary: "Browser/app diagnostics for browser-required tasks.",
|
|
2088
|
+
usage: ["rig browser <help|explain|demo|app|hp-next> [options]"],
|
|
2089
|
+
commands: [
|
|
2090
|
+
{ command: "help", description: "Rich browser command help (canonical: `rig browser help`)." },
|
|
2091
|
+
{ command: "explain", description: "Explain the browser-required task contract." },
|
|
2092
|
+
{ command: "demo", description: "Run browser demo flows against a local page." },
|
|
2093
|
+
{ command: "app", description: "Launch the Rig Browser workstation app." },
|
|
2094
|
+
{ command: "hp-next <dev|check|e2e|reset>", description: "Drive the hp-next browser test harness." }
|
|
2095
|
+
]
|
|
2096
|
+
},
|
|
2097
|
+
{
|
|
2098
|
+
name: "pi",
|
|
2099
|
+
summary: "Manage Pi extension packages for this project (community extensions from npm/git).",
|
|
2100
|
+
usage: ["rig pi <list|add|remove|search> [args]"],
|
|
2101
|
+
commands: [
|
|
2102
|
+
{ command: "list", description: "Show project and user Pi extension packages." },
|
|
2103
|
+
{ command: "add <source>", description: "Add an npm/git Pi extension to .pi/settings.json (auto-installs at next session)." },
|
|
2104
|
+
{ command: "remove <source>", description: "Remove an operator-added Pi extension." },
|
|
2105
|
+
{ command: "search [term]", description: "Discover Pi extension packages on the npm registry." }
|
|
2106
|
+
],
|
|
2107
|
+
examples: ["rig pi search subagents", "rig pi add pi-subagents", "rig pi list"],
|
|
2108
|
+
next: ["Config-managed extensions: declare `runtime: { pi: { packages: [...] } }` in rig.config.ts \u2014 workers pick them up automatically."]
|
|
2109
|
+
},
|
|
2110
|
+
{
|
|
2111
|
+
name: "plugin",
|
|
2112
|
+
summary: "Plugin listing, validation, and plugin-contributed commands.",
|
|
2113
|
+
usage: ["rig plugin <list|validate|run> [options]"],
|
|
2114
|
+
commands: [
|
|
2115
|
+
{ command: "list", description: "List plugins declared in rig.config.ts and their contributions." },
|
|
2116
|
+
{ command: "validate --task <id>", description: "Run plugin-contributed validators for a task." },
|
|
2117
|
+
{ command: "run <command-id> [args...]", description: "Execute a plugin-contributed CLI command (also callable as `rig <command-id>`)." }
|
|
2118
|
+
]
|
|
2119
|
+
},
|
|
2120
|
+
{ name: "queue", summary: "Run task queues locally.", usage: ["rig queue run [options]"], commands: [{ command: "run", description: "Process queue work." }] },
|
|
2121
|
+
{ name: "agent", summary: "Runtime agent workspace helpers.", usage: ["rig agent <list|prepare|run|cleanup>"], commands: [{ command: "list", description: "List prepared agents." }] },
|
|
2122
|
+
{ name: "inspector", summary: "Event stream and drift scanners.", usage: ["rig inspector <stream|scan-upstream-drift>"], commands: [{ command: "stream", description: "Stream events." }] },
|
|
2123
|
+
{ name: "dist", summary: "Build/install packaged Rig CLI.", usage: ["rig dist <build|install|doctor>"], commands: [{ command: "build", description: "Build distribution." }] },
|
|
2124
|
+
{ name: "workspace", summary: "Workspace topology/service helpers.", usage: ["rig workspace <summary|topology|remote-hosts>"], commands: [{ command: "summary", description: "Show workspace summary." }] },
|
|
2125
|
+
{ name: "remote", summary: "Compatibility remote orchestration controls.", usage: ["rig remote <status|watch|pause|resume|...>"], commands: [{ command: "status", description: "Show remote state." }] },
|
|
2126
|
+
{ name: "git", summary: "Pass through to Rig git-flow helper.", usage: ["rig git <args...>"], commands: [{ command: "<args...>", description: "Advanced git flow operations." }] },
|
|
2127
|
+
{ name: "harness", summary: "Pass through to runtime harness CLI.", usage: ["rig harness <args...>"], commands: [{ command: "<args...>", description: "Advanced harness operations." }] },
|
|
2128
|
+
{ name: "test", summary: "Project test wrappers.", usage: ["rig test <unit|e2e|all>"], commands: [{ command: "all", description: "Run configured project tests." }] }
|
|
2129
|
+
];
|
|
2130
|
+
var ALL_GROUPS = [...PRIMARY_GROUPS, ...ADVANCED_GROUPS];
|
|
2131
|
+
function heading(title) {
|
|
2132
|
+
return pc2.bold(pc2.cyan(title));
|
|
2133
|
+
}
|
|
2134
|
+
function renderRigBanner(version) {
|
|
2135
|
+
const m = (s) => pc2.bold(pc2.magenta(s));
|
|
2136
|
+
const c = (s) => pc2.bold(pc2.cyan(s));
|
|
2137
|
+
const y = (s) => pc2.yellow(s);
|
|
2138
|
+
const d = (s) => pc2.dim(s);
|
|
2139
|
+
const lines = [
|
|
2140
|
+
m(" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 ") + d(" \u2591\u2592\u2593\u2588 "),
|
|
2141
|
+
m(" \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D ") + d("\u2593\u2592\u2591"),
|
|
2142
|
+
c(" \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2557") + d(" \u2591\u2592"),
|
|
2143
|
+
c(" \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551") + d(" \u2588\u2593\u2591"),
|
|
2144
|
+
y(" \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D") + d(" \u2592\u2591"),
|
|
2145
|
+
y(" \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D "),
|
|
2146
|
+
"",
|
|
2147
|
+
` ${c("\u25E2\u25E4")} ${pc2.bold("the control rig for autonomous coding agents")} ${m("//")} ${d("you are the operator")}`,
|
|
2148
|
+
version ? ` ${d(`v${version} \xB7 jack in: rig task run --next`)}` : ` ${d("jack in: rig task run --next")}`
|
|
2149
|
+
];
|
|
2150
|
+
return lines.join(`
|
|
2151
|
+
`);
|
|
2152
|
+
}
|
|
2153
|
+
function commandLine(command, description) {
|
|
2154
|
+
const commandColumn = command.length >= 38 ? `${command} ` : command.padEnd(38);
|
|
2155
|
+
return `${pc2.dim("\u2502")} ${pc2.bold(commandColumn)} ${description}`;
|
|
2156
|
+
}
|
|
2157
|
+
function renderCommandBlock(commands) {
|
|
2158
|
+
return commands.map((entry) => commandLine(entry.command, entry.description)).join(`
|
|
2159
|
+
`);
|
|
2160
|
+
}
|
|
2161
|
+
function renderGroup(group) {
|
|
2162
|
+
const lines = [
|
|
2163
|
+
`${heading(`rig ${group.name}`)} \u2014 ${group.summary}`,
|
|
2164
|
+
"",
|
|
2165
|
+
pc2.bold("Usage"),
|
|
2166
|
+
...group.usage.map((line) => ` ${line}`),
|
|
2167
|
+
"",
|
|
2168
|
+
pc2.bold("Commands"),
|
|
2169
|
+
...group.commands.map((entry) => commandLine(entry.command, entry.description))
|
|
2170
|
+
];
|
|
2171
|
+
if (group.examples?.length) {
|
|
2172
|
+
lines.push("", pc2.bold("Examples"), ...group.examples.map((line) => ` ${pc2.dim("$")} ${line}`));
|
|
2173
|
+
}
|
|
2174
|
+
if (group.next?.length) {
|
|
2175
|
+
lines.push("", pc2.bold("Next steps"), ...group.next.map((line) => ` ${pc2.dim("\u203A")} ${line}`));
|
|
2176
|
+
}
|
|
2177
|
+
if (group.advanced?.length) {
|
|
2178
|
+
lines.push("", pc2.bold("Compatibility / advanced"), ...group.advanced.map((line) => ` ${pc2.dim("\u203A")} ${line}`));
|
|
2179
|
+
}
|
|
2180
|
+
return lines.join(`
|
|
2181
|
+
`);
|
|
2182
|
+
}
|
|
2183
|
+
function renderTopLevelHelp() {
|
|
2184
|
+
return [
|
|
2185
|
+
`${heading("rig")} ${pc2.dim("\u2014 server-owned task/run control plane for Pi-backed engineering work")}`,
|
|
2186
|
+
pc2.dim("Current path: select a server, choose a task, submit a run, attach with native Pi, clear inbox/review gates."),
|
|
2187
|
+
"",
|
|
2188
|
+
...TOP_LEVEL_SECTIONS.flatMap((section) => [
|
|
2189
|
+
`${pc2.bold(pc2.magenta(`\u25C7 ${section.title}`))} \u2014 ${pc2.dim(section.subtitle)}`,
|
|
2190
|
+
renderCommandBlock(section.commands),
|
|
2191
|
+
""
|
|
2192
|
+
]),
|
|
2193
|
+
pc2.dim("More: `rig help --advanced` for dev/compatibility commands; `rig <group> --help` for rich per-group help; `rig --version` for the installed version."),
|
|
2194
|
+
"",
|
|
2195
|
+
pc2.bold("Global options"),
|
|
2196
|
+
commandLine("--project <path>", "Use a project root instead of auto-discovery."),
|
|
2197
|
+
commandLine("--json", "Emit structured output for scripts/agents."),
|
|
2198
|
+
commandLine("--dry-run", "Print the command plan without mutating state.")
|
|
2199
|
+
].join(`
|
|
2200
|
+
`).trimEnd();
|
|
2201
|
+
}
|
|
2202
|
+
function renderGroupHelp(groupName) {
|
|
2203
|
+
const group = ALL_GROUPS.find((candidate) => candidate.name === groupName);
|
|
2204
|
+
return group ? renderGroup(group) : null;
|
|
2205
|
+
}
|
|
2206
|
+
function shouldUseClackOutput2() {
|
|
2207
|
+
return Boolean(process.stdout.isTTY) && process.env.RIG_CLI_PLAIN_HELP !== "1";
|
|
2208
|
+
}
|
|
2209
|
+
function printTopLevelHelp(state = {}) {
|
|
2210
|
+
if (!shouldUseClackOutput2()) {
|
|
2211
|
+
console.log(renderTopLevelHelp());
|
|
2212
|
+
return;
|
|
2213
|
+
}
|
|
2214
|
+
console.log(renderRigBanner(state.version));
|
|
2215
|
+
console.log("");
|
|
2216
|
+
if (state.projectInitialized === false) {
|
|
2217
|
+
intro("no rig project in this directory");
|
|
2218
|
+
note2([
|
|
2219
|
+
commandLine("rig init", "Set this repo up: config, GitHub auth, task source, server, Pi."),
|
|
2220
|
+
commandLine("rig init --yes", "Same, non-interactive, sensible defaults."),
|
|
2221
|
+
commandLine("rig doctor", "Already initialized somewhere else? Check the wiring.")
|
|
2222
|
+
].join(`
|
|
2223
|
+
`), "Get started");
|
|
2224
|
+
outro("After init: rig task run --next puts an agent on your next task.");
|
|
2225
|
+
return;
|
|
2226
|
+
}
|
|
2227
|
+
intro(state.selectedServer ? `server: ${state.selectedServer}` : "rig");
|
|
2228
|
+
for (const section of TOP_LEVEL_SECTIONS) {
|
|
2229
|
+
note2(renderCommandBlock(section.commands), `${section.title} \u2014 ${section.subtitle}`);
|
|
2230
|
+
}
|
|
2231
|
+
log2.info("More: rig help --advanced \xB7 rig <group> --help \xB7 rig --version");
|
|
2232
|
+
note2([
|
|
2233
|
+
commandLine("--project <path>", "Use a project root instead of auto-discovery."),
|
|
2234
|
+
commandLine("--json", "Emit structured output for scripts/agents."),
|
|
2235
|
+
commandLine("--dry-run", "Print the command plan without mutating state.")
|
|
2236
|
+
].join(`
|
|
2237
|
+
`), "Global options");
|
|
2238
|
+
outro("init \u2192 task run \u2192 watch/steer \u2192 inbox/review \u2192 merged.");
|
|
2239
|
+
}
|
|
2240
|
+
function printGroupHelpDocument(groupName) {
|
|
2241
|
+
const rendered = renderGroupHelp(groupName) ?? renderTopLevelHelp();
|
|
2242
|
+
if (!shouldUseClackOutput2()) {
|
|
2243
|
+
console.log(rendered);
|
|
2244
|
+
return;
|
|
2245
|
+
}
|
|
2246
|
+
const group = ALL_GROUPS.find((candidate) => candidate.name === groupName);
|
|
2247
|
+
if (!group) {
|
|
2248
|
+
printTopLevelHelp();
|
|
2249
|
+
return;
|
|
2250
|
+
}
|
|
2251
|
+
intro(`rig ${group.name}`);
|
|
2252
|
+
note2(group.summary, "Purpose");
|
|
2253
|
+
note2(group.usage.join(`
|
|
2254
|
+
`), "Usage");
|
|
2255
|
+
note2(group.commands.map((entry) => commandLine(entry.command, entry.description)).join(`
|
|
2256
|
+
`), "Commands");
|
|
2257
|
+
if (group.examples?.length)
|
|
2258
|
+
note2(group.examples.map((line) => `$ ${line}`).join(`
|
|
2259
|
+
`), "Examples");
|
|
2260
|
+
if (group.next?.length)
|
|
2261
|
+
note2(group.next.map((line) => `\u203A ${line}`).join(`
|
|
2262
|
+
`), "Next steps");
|
|
2263
|
+
if (group.advanced?.length)
|
|
2264
|
+
log2.info(group.advanced.join(`
|
|
2265
|
+
`));
|
|
2266
|
+
outro("Run with --json when scripts need structured output.");
|
|
2267
|
+
}
|
|
2268
|
+
|
|
852
2269
|
// packages/cli/src/commands/task.ts
|
|
853
2270
|
import { buildPluginHostContext } from "@rig/runtime/control-plane/plugin-host-context";
|
|
854
2271
|
import { loadConfig } from "@rig/core/load-config";
|
|
@@ -924,7 +2341,7 @@ function normalizePrMode(value) {
|
|
|
924
2341
|
throw new CliError2("--pr must be auto, ask, or off.", 2);
|
|
925
2342
|
}
|
|
926
2343
|
function detectLocalDirtyState(projectRoot) {
|
|
927
|
-
const result =
|
|
2344
|
+
const result = spawnSync("git", ["-C", projectRoot, "status", "--porcelain"], { encoding: "utf8", timeout: 5000 });
|
|
928
2345
|
if (result.status !== 0)
|
|
929
2346
|
return { dirty: false, modified: 0, untracked: 0, lines: [] };
|
|
930
2347
|
const lines = result.stdout.split(/\r?\n/).map((line) => line.trimEnd()).filter(Boolean);
|
|
@@ -958,13 +2375,15 @@ async function resolveDirtyBaselineForTaskRun(context, explicit) {
|
|
|
958
2375
|
if (explicit)
|
|
959
2376
|
return { mode: explicit, state };
|
|
960
2377
|
if (context.outputMode === "text" && process.stdin.isTTY && process.stdout.isTTY) {
|
|
961
|
-
const
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
2378
|
+
const answer = await confirm({
|
|
2379
|
+
message: "Include current uncommitted changes in run baseline?",
|
|
2380
|
+
initialValue: false
|
|
2381
|
+
});
|
|
2382
|
+
if (isCancel2(answer)) {
|
|
2383
|
+
cancel2("Run cancelled.");
|
|
2384
|
+
throw new CliError2("Run cancelled by user.", 1);
|
|
967
2385
|
}
|
|
2386
|
+
return { mode: answer ? "dirty-snapshot" : "head", state };
|
|
968
2387
|
}
|
|
969
2388
|
return { mode: "head", state };
|
|
970
2389
|
}
|
|
@@ -998,38 +2417,30 @@ function summarizeTask(task, options = {}) {
|
|
|
998
2417
|
...options.raw ? { raw: raw ?? task } : {}
|
|
999
2418
|
};
|
|
1000
2419
|
}
|
|
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
2420
|
async function validatorRegistryForTaskCommands(projectRoot) {
|
|
1008
2421
|
return buildPluginHostContext(projectRoot).then((ctx) => ctx?.validatorRegistry ?? undefined).catch(() => {
|
|
1009
2422
|
return;
|
|
1010
2423
|
});
|
|
1011
2424
|
}
|
|
1012
2425
|
async function executeTask(context, args, options) {
|
|
1013
|
-
|
|
2426
|
+
if (args.length === 0) {
|
|
2427
|
+
if (context.outputMode === "text") {
|
|
2428
|
+
printGroupHelpDocument("task");
|
|
2429
|
+
}
|
|
2430
|
+
return { ok: true, group: "task", command: "help" };
|
|
2431
|
+
}
|
|
2432
|
+
const [command = "help", ...rest] = args;
|
|
1014
2433
|
switch (command) {
|
|
1015
2434
|
case "list": {
|
|
1016
2435
|
let pending = rest;
|
|
1017
2436
|
const rawResult = takeFlag(pending, "--raw");
|
|
1018
2437
|
pending = rawResult.rest;
|
|
1019
2438
|
const { filters, rest: remaining } = parseTaskFilters(pending);
|
|
1020
|
-
requireNoExtraArgs(remaining, "
|
|
2439
|
+
requireNoExtraArgs(remaining, "rig task list [--raw] [--assignee <login|@me>] [--assigned-to <login|me|@me>] [--state open|closed] [--status <status>] [--limit <n>]");
|
|
1021
2440
|
const tasks = await listWorkspaceTasksViaServer(context, filters);
|
|
1022
2441
|
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
|
-
}
|
|
2442
|
+
const renderedTasks = rawResult.value ? tasks.map((task) => summarizeTask(task, { raw: true })) : tasks.map((task) => summarizeTask(task));
|
|
2443
|
+
printFormattedOutput(formatTaskList(renderedTasks, { raw: rawResult.value }));
|
|
1033
2444
|
}
|
|
1034
2445
|
return {
|
|
1035
2446
|
ok: true,
|
|
@@ -1039,30 +2450,34 @@ async function executeTask(context, args, options) {
|
|
|
1039
2450
|
};
|
|
1040
2451
|
}
|
|
1041
2452
|
case "show": {
|
|
1042
|
-
|
|
2453
|
+
let pending = rest;
|
|
2454
|
+
const rawResult = takeFlag(pending, "--raw");
|
|
2455
|
+
pending = rawResult.rest;
|
|
2456
|
+
const taskOption = takeOption(pending, "--task");
|
|
1043
2457
|
const positional = taskOption.rest.length > 0 && taskOption.rest[0] && !taskOption.rest[0].startsWith("-") ? taskOption.rest[0] : undefined;
|
|
1044
2458
|
const remaining = positional ? taskOption.rest.slice(1) : taskOption.rest;
|
|
1045
|
-
requireNoExtraArgs(remaining, "
|
|
1046
|
-
const
|
|
1047
|
-
if (!
|
|
2459
|
+
requireNoExtraArgs(remaining, "rig task show <id>|--task <id> [--raw]");
|
|
2460
|
+
const taskId3 = normalizeTaskRunTaskId(taskOption.value ?? positional);
|
|
2461
|
+
if (!taskId3)
|
|
1048
2462
|
throw new CliError2("task show requires a task id.", 2);
|
|
1049
|
-
const task = await getWorkspaceTaskViaServer(context,
|
|
2463
|
+
const task = await getWorkspaceTaskViaServer(context, taskId3);
|
|
1050
2464
|
if (!task)
|
|
1051
|
-
throw new CliError2(`Task not found: ${
|
|
2465
|
+
throw new CliError2(`Task not found: ${taskId3}`, 3);
|
|
1052
2466
|
const summary = summarizeTask(task, { raw: true });
|
|
1053
|
-
if (context.outputMode === "text")
|
|
1054
|
-
|
|
1055
|
-
|
|
2467
|
+
if (context.outputMode === "text") {
|
|
2468
|
+
printFormattedOutput(rawResult.value ? JSON.stringify(summary, null, 2) : formatTaskDetails(summary));
|
|
2469
|
+
}
|
|
2470
|
+
return { ok: true, group: "task", command, details: { task: summary, raw: rawResult.value } };
|
|
1056
2471
|
}
|
|
1057
2472
|
case "next": {
|
|
1058
2473
|
const { filters, rest: remaining } = parseTaskFilters(rest);
|
|
1059
|
-
requireNoExtraArgs(remaining, "
|
|
2474
|
+
requireNoExtraArgs(remaining, "rig task next [--assignee <login|@me>] [--assigned-to <login|me|@me>] [--state open|closed] [--status <status>] [--limit <n>]");
|
|
1060
2475
|
const selected = await selectNextWorkspaceTaskViaServer(context, filters);
|
|
1061
2476
|
if (context.outputMode === "text") {
|
|
1062
2477
|
if (selected.task) {
|
|
1063
|
-
|
|
2478
|
+
printFormattedOutput(formatTaskCard(summarizeTask(selected.task, { raw: true }), { title: "Selected task", selected: true }));
|
|
1064
2479
|
} else {
|
|
1065
|
-
|
|
2480
|
+
printFormattedOutput("No matching tasks.\n\nNext\n\u203A Try `rig task list` to inspect available work.\n\u203A Check server: `rig server status`");
|
|
1066
2481
|
}
|
|
1067
2482
|
}
|
|
1068
2483
|
return {
|
|
@@ -1078,31 +2493,31 @@ async function executeTask(context, args, options) {
|
|
|
1078
2493
|
}
|
|
1079
2494
|
case "info": {
|
|
1080
2495
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1081
|
-
requireNoExtraArgs(remaining, "
|
|
2496
|
+
requireNoExtraArgs(remaining, "rig task info [--task <task-id>]");
|
|
1082
2497
|
await withMutedConsole(context.outputMode === "json", () => taskInfo(context.projectRoot, task || undefined));
|
|
1083
2498
|
return { ok: true, group: "task", command, details: { task: task || null } };
|
|
1084
2499
|
}
|
|
1085
2500
|
case "scope": {
|
|
1086
2501
|
const filesFlag = takeFlag(rest, "--files");
|
|
1087
2502
|
const { value: task, rest: remaining } = takeOption(filesFlag.rest, "--task");
|
|
1088
|
-
requireNoExtraArgs(remaining, "
|
|
2503
|
+
requireNoExtraArgs(remaining, "rig task scope [--task <id>] [--files]");
|
|
1089
2504
|
await withMutedConsole(context.outputMode === "json", () => taskScope(context.projectRoot, filesFlag.value, task || undefined));
|
|
1090
2505
|
return { ok: true, group: "task", command, details: { files: filesFlag.value, task: task || null } };
|
|
1091
2506
|
}
|
|
1092
2507
|
case "deps":
|
|
1093
|
-
requireNoExtraArgs(rest, "
|
|
2508
|
+
requireNoExtraArgs(rest, "rig task deps");
|
|
1094
2509
|
await withMutedConsole(context.outputMode === "json", () => taskDeps(context.projectRoot));
|
|
1095
2510
|
return { ok: true, group: "task", command };
|
|
1096
2511
|
case "status":
|
|
1097
|
-
requireNoExtraArgs(rest, "
|
|
2512
|
+
requireNoExtraArgs(rest, "rig task status");
|
|
1098
2513
|
withMutedConsole(context.outputMode === "json", () => taskStatus2(context.projectRoot));
|
|
1099
2514
|
return { ok: true, group: "task", command };
|
|
1100
2515
|
case "artifacts":
|
|
1101
|
-
requireNoExtraArgs(rest, "
|
|
2516
|
+
requireNoExtraArgs(rest, "rig task artifacts");
|
|
1102
2517
|
withMutedConsole(context.outputMode === "json", () => taskArtifacts(context.projectRoot));
|
|
1103
2518
|
return { ok: true, group: "task", command };
|
|
1104
2519
|
case "artifact-dir": {
|
|
1105
|
-
requireNoExtraArgs(rest, "
|
|
2520
|
+
requireNoExtraArgs(rest, "rig task artifact-dir");
|
|
1106
2521
|
const path = taskArtifactDir(context.projectRoot);
|
|
1107
2522
|
if (context.outputMode === "text") {
|
|
1108
2523
|
console.log(path);
|
|
@@ -1111,7 +2526,7 @@ async function executeTask(context, args, options) {
|
|
|
1111
2526
|
}
|
|
1112
2527
|
case "artifact-write": {
|
|
1113
2528
|
if (rest.length < 1) {
|
|
1114
|
-
throw new CliError2(`Usage:
|
|
2529
|
+
throw new CliError2(`Usage: rig task artifact-write <filename> [--file <path>]
|
|
1115
2530
|
` + ` Reads content from stdin (or --file), writes to the active task artifact dir.
|
|
1116
2531
|
` + " Example: echo '...' | rig task artifact-write collection-audit.md");
|
|
1117
2532
|
}
|
|
@@ -1119,12 +2534,12 @@ async function executeTask(context, args, options) {
|
|
|
1119
2534
|
const fileFlag = takeOption(rest.slice(1), "--file");
|
|
1120
2535
|
let content;
|
|
1121
2536
|
if (fileFlag.value) {
|
|
1122
|
-
content =
|
|
2537
|
+
content = readFileSync3(resolve3(context.projectRoot, fileFlag.value), "utf-8");
|
|
1123
2538
|
} else {
|
|
1124
2539
|
content = await readStdin();
|
|
1125
2540
|
}
|
|
1126
2541
|
if (!artifactFilename) {
|
|
1127
|
-
throw new CliError2("Usage:
|
|
2542
|
+
throw new CliError2("Usage: rig task artifact-write <filename> [--file path]");
|
|
1128
2543
|
}
|
|
1129
2544
|
withMutedConsole(context.outputMode === "json", () => taskArtifactWrite(context.projectRoot, artifactFilename, content));
|
|
1130
2545
|
return { ok: true, group: "task", command, details: { filename: artifactFilename } };
|
|
@@ -1133,11 +2548,11 @@ async function executeTask(context, args, options) {
|
|
|
1133
2548
|
return options.executeTaskReportBug(context, rest);
|
|
1134
2549
|
case "lookup": {
|
|
1135
2550
|
if (rest.length !== 1) {
|
|
1136
|
-
throw new CliError2("Usage:
|
|
2551
|
+
throw new CliError2("Usage: rig task lookup <task-id>");
|
|
1137
2552
|
}
|
|
1138
2553
|
const lookupId = rest[0];
|
|
1139
2554
|
if (!lookupId) {
|
|
1140
|
-
throw new CliError2("Usage:
|
|
2555
|
+
throw new CliError2("Usage: rig task lookup <task-id>");
|
|
1141
2556
|
}
|
|
1142
2557
|
const result = taskLookup(context.projectRoot, lookupId);
|
|
1143
2558
|
if (context.outputMode === "text") {
|
|
@@ -1147,17 +2562,17 @@ async function executeTask(context, args, options) {
|
|
|
1147
2562
|
}
|
|
1148
2563
|
case "record": {
|
|
1149
2564
|
if (rest.length < 2) {
|
|
1150
|
-
throw new CliError2("Usage:
|
|
2565
|
+
throw new CliError2("Usage: rig task record <decision|failure> <text>");
|
|
1151
2566
|
}
|
|
1152
2567
|
const type = rest[0];
|
|
1153
2568
|
if (type !== "decision" && type !== "failure") {
|
|
1154
|
-
throw new CliError2("Usage:
|
|
2569
|
+
throw new CliError2("Usage: rig task record <decision|failure> <text>");
|
|
1155
2570
|
}
|
|
1156
2571
|
withMutedConsole(context.outputMode === "json", () => taskRecord(context.projectRoot, type, rest.slice(1).join(" ")));
|
|
1157
2572
|
return { ok: true, group: "task", command, details: { type: rest[0] } };
|
|
1158
2573
|
}
|
|
1159
2574
|
case "ready":
|
|
1160
|
-
requireNoExtraArgs(rest, "
|
|
2575
|
+
requireNoExtraArgs(rest, "rig task ready");
|
|
1161
2576
|
await withMutedConsole(context.outputMode === "json", () => taskReady(context.projectRoot));
|
|
1162
2577
|
return { ok: true, group: "task", command };
|
|
1163
2578
|
case "run": {
|
|
@@ -1194,7 +2609,7 @@ async function executeTask(context, args, options) {
|
|
|
1194
2609
|
if (positionalTaskId) {
|
|
1195
2610
|
pending = pending.slice(1);
|
|
1196
2611
|
}
|
|
1197
|
-
requireNoExtraArgs(pending, "
|
|
2612
|
+
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
2613
|
if (nextResult.value && (taskResult.value || positionalTaskId)) {
|
|
1199
2614
|
throw new CliError2("task run cannot combine --next with an explicit task id.", 2);
|
|
1200
2615
|
}
|
|
@@ -1248,16 +2663,24 @@ async function executeTask(context, args, options) {
|
|
|
1248
2663
|
});
|
|
1249
2664
|
let attachDetails = null;
|
|
1250
2665
|
if (!detachResult.value && context.outputMode === "text") {
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
2666
|
+
printFormattedOutput(formatSubmittedRun({
|
|
2667
|
+
runId: submitted.runId,
|
|
2668
|
+
task: selectedTask ? summarizeTask(selectedTask) : null,
|
|
2669
|
+
runtimeAdapter,
|
|
2670
|
+
runtimeMode: runtimeModeResult.value || projectDefaults.runtimeMode || "full-access",
|
|
2671
|
+
interactionMode: interactionModeResult.value || "default",
|
|
2672
|
+
detached: false
|
|
2673
|
+
}));
|
|
1255
2674
|
attachDetails = await attachRunOperatorView(context, { runId: submitted.runId, follow: true });
|
|
1256
2675
|
} else if (context.outputMode === "text") {
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
2676
|
+
printFormattedOutput(formatSubmittedRun({
|
|
2677
|
+
runId: submitted.runId,
|
|
2678
|
+
task: selectedTask ? summarizeTask(selectedTask) : null,
|
|
2679
|
+
runtimeAdapter,
|
|
2680
|
+
runtimeMode: runtimeModeResult.value || projectDefaults.runtimeMode || "full-access",
|
|
2681
|
+
interactionMode: interactionModeResult.value || "default",
|
|
2682
|
+
detached: true
|
|
2683
|
+
}));
|
|
1261
2684
|
}
|
|
1262
2685
|
return {
|
|
1263
2686
|
ok: true,
|
|
@@ -1281,7 +2704,7 @@ async function executeTask(context, args, options) {
|
|
|
1281
2704
|
}
|
|
1282
2705
|
case "validate": {
|
|
1283
2706
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1284
|
-
requireNoExtraArgs(remaining, "
|
|
2707
|
+
requireNoExtraArgs(remaining, "rig task validate [--task <task-id>]");
|
|
1285
2708
|
if (context.dryRun) {
|
|
1286
2709
|
await context.runCommand(["rig", "task", "validate", ...task ? ["--task", task] : []]);
|
|
1287
2710
|
return { ok: true, group: "task", command, details: { task: task || "active" } };
|
|
@@ -1294,12 +2717,12 @@ async function executeTask(context, args, options) {
|
|
|
1294
2717
|
}
|
|
1295
2718
|
case "verify": {
|
|
1296
2719
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1297
|
-
requireNoExtraArgs(remaining, "
|
|
2720
|
+
requireNoExtraArgs(remaining, "rig task verify [--task <task-id>]");
|
|
1298
2721
|
if (context.dryRun) {
|
|
1299
2722
|
await context.runCommand(["rig", "task", "verify", ...task ? ["--task", task] : []]);
|
|
1300
2723
|
return { ok: true, group: "task", command, details: { task: task || "active" } };
|
|
1301
2724
|
}
|
|
1302
|
-
const ok = await withMutedConsole(context.outputMode === "json", () => taskVerify(context.projectRoot,
|
|
2725
|
+
const ok = await withMutedConsole(context.outputMode === "json", () => taskVerify(context.projectRoot, task || undefined));
|
|
1303
2726
|
if (!ok) {
|
|
1304
2727
|
throw new CliError2(`Verification rejected for ${task || "active task"}.`, 2);
|
|
1305
2728
|
}
|
|
@@ -1307,15 +2730,19 @@ async function executeTask(context, args, options) {
|
|
|
1307
2730
|
}
|
|
1308
2731
|
case "reset": {
|
|
1309
2732
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1310
|
-
requireNoExtraArgs(remaining, "
|
|
1311
|
-
const requiredTask = requireTask(task, "
|
|
1312
|
-
|
|
1313
|
-
|
|
2733
|
+
requireNoExtraArgs(remaining, "rig task reset --task <task-id>");
|
|
2734
|
+
const requiredTask = requireTask(task, "rig task reset --task <task-id>");
|
|
2735
|
+
const summary = withMutedConsole(context.outputMode === "json", () => taskReopen(context.projectRoot, {
|
|
2736
|
+
all: false,
|
|
2737
|
+
taskId: requiredTask,
|
|
2738
|
+
dryRun: false
|
|
2739
|
+
}));
|
|
2740
|
+
return { ok: true, group: "task", command, details: summary };
|
|
1314
2741
|
}
|
|
1315
2742
|
case "details": {
|
|
1316
2743
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1317
|
-
requireNoExtraArgs(remaining, "
|
|
1318
|
-
const requiredTask = requireTask(task, "
|
|
2744
|
+
requireNoExtraArgs(remaining, "rig task details --task <task-id>");
|
|
2745
|
+
const requiredTask = requireTask(task, "rig task details --task <task-id>");
|
|
1319
2746
|
await withMutedConsole(context.outputMode === "json", () => taskInfo(context.projectRoot, requiredTask));
|
|
1320
2747
|
return { ok: true, group: "task", command, details: { task: requiredTask } };
|
|
1321
2748
|
}
|
|
@@ -1323,9 +2750,9 @@ async function executeTask(context, args, options) {
|
|
|
1323
2750
|
const { value: task, rest: rest1 } = takeOption(rest, "--task");
|
|
1324
2751
|
const allFlag = takeFlag(rest1, "--all");
|
|
1325
2752
|
const { rest: remaining } = takeOption(allFlag.rest, "--reason");
|
|
1326
|
-
requireNoExtraArgs(remaining, "
|
|
2753
|
+
requireNoExtraArgs(remaining, "rig task reopen [--task <id> | --all] [--reason <text>]");
|
|
1327
2754
|
if (!allFlag.value && !task) {
|
|
1328
|
-
throw new CliError2("Usage:
|
|
2755
|
+
throw new CliError2("Usage: rig task reopen [--task <id> | --all] [--reason <text>]");
|
|
1329
2756
|
}
|
|
1330
2757
|
const summary = withMutedConsole(context.outputMode === "json", () => taskReopen(context.projectRoot, {
|
|
1331
2758
|
all: allFlag.value,
|