@h-rig/cli 0.0.6-alpha.3 → 0.0.6-alpha.30
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 +3606 -1172
- package/dist/src/commands/_authority-runs.js +1 -0
- package/dist/src/commands/_cli-format.js +369 -0
- package/dist/src/commands/_connection-state.js +1 -3
- package/dist/src/commands/_doctor-checks.js +13 -27
- package/dist/src/commands/_help-catalog.js +388 -0
- package/dist/src/commands/_operator-surface.js +204 -0
- package/dist/src/commands/_operator-view.js +861 -56
- package/dist/src/commands/_parsers.js +0 -2
- package/dist/src/commands/_pi-frontend.js +841 -0
- package/dist/src/commands/_pi-install.js +4 -3
- package/dist/src/commands/_pi-worker-bridge-extension.js +759 -0
- package/dist/src/commands/_policy.js +0 -2
- package/dist/src/commands/_preflight.js +32 -109
- package/dist/src/commands/_run-driver-helpers.js +0 -2
- package/dist/src/commands/_server-client.js +161 -31
- package/dist/src/commands/_snapshot-upload.js +8 -23
- package/dist/src/commands/_task-picker.js +44 -16
- package/dist/src/commands/agent.js +9 -9
- package/dist/src/commands/browser.js +4 -6
- package/dist/src/commands/connect.js +132 -25
- package/dist/src/commands/dist.js +4 -6
- package/dist/src/commands/doctor.js +13 -27
- package/dist/src/commands/github.js +10 -25
- package/dist/src/commands/inbox.js +351 -31
- package/dist/src/commands/init.js +298 -71
- package/dist/src/commands/inspect.js +10 -12
- package/dist/src/commands/inspector.js +2 -4
- package/dist/src/commands/plugin.js +76 -22
- package/dist/src/commands/profile-and-review.js +8 -10
- package/dist/src/commands/queue.js +2 -3
- package/dist/src/commands/remote.js +18 -20
- package/dist/src/commands/repo-git-harness.js +6 -8
- package/dist/src/commands/run.js +1157 -122
- package/dist/src/commands/server.js +217 -33
- package/dist/src/commands/setup.js +17 -37
- package/dist/src/commands/task-report-bug.js +5 -7
- package/dist/src/commands/task-run-driver.js +660 -73
- package/dist/src/commands/task.js +1542 -252
- package/dist/src/commands/test.js +3 -5
- package/dist/src/commands/workspace.js +4 -6
- package/dist/src/commands.js +3599 -1159
- package/dist/src/index.js +3646 -1215
- 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,184 @@ 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
|
+
}
|
|
829
|
+
}
|
|
830
|
+
},
|
|
831
|
+
renderLogs(entries) {
|
|
832
|
+
for (const [index, entry] of entries.entries()) {
|
|
833
|
+
const id = entryId(entry, `log:${index}:${String(entry.createdAt ?? "")}:${String(entry.title ?? "")}`);
|
|
834
|
+
if (seenLogs.has(id))
|
|
835
|
+
continue;
|
|
836
|
+
seenLogs.add(id);
|
|
837
|
+
const title = String(entry.title ?? "");
|
|
838
|
+
if (CANONICAL_STAGES.some((stage) => stage.toLowerCase() === title.toLowerCase()))
|
|
839
|
+
continue;
|
|
840
|
+
const detail = logDetail(entry);
|
|
841
|
+
if (!detail)
|
|
842
|
+
continue;
|
|
843
|
+
const protocolRecord = parseProviderProtocolLog(title, detail);
|
|
844
|
+
if (protocolRecord) {
|
|
845
|
+
const protocolLine = renderProviderProtocolLog(protocolRecord);
|
|
846
|
+
if (protocolLine)
|
|
847
|
+
writeLine(protocolLine);
|
|
848
|
+
continue;
|
|
849
|
+
}
|
|
850
|
+
writeLine(`[${title || "Rig log"}] ${detail}`);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
function createOperatorSurface(options = {}) {
|
|
856
|
+
const input = options.input ?? process.stdin;
|
|
857
|
+
const output = options.output ?? process.stdout;
|
|
858
|
+
const errorOutput = options.errorOutput ?? process.stderr;
|
|
859
|
+
const renderer = createPiRunStreamRenderer(output);
|
|
860
|
+
const writeLine = (line) => output.write(`${line}
|
|
861
|
+
`);
|
|
862
|
+
return {
|
|
863
|
+
mode: "pi-compatible-text",
|
|
864
|
+
...renderer,
|
|
865
|
+
info: writeLine,
|
|
866
|
+
error: (message2) => errorOutput.write(`${message2}
|
|
867
|
+
`),
|
|
868
|
+
attachCommandInput(handler) {
|
|
869
|
+
if (options.interactive === false || !input.isTTY)
|
|
870
|
+
return null;
|
|
871
|
+
const rl = createInterface({ input, output: process.stdout, terminal: false });
|
|
872
|
+
rl.on("line", (line) => {
|
|
873
|
+
Promise.resolve(handler(line)).catch((error) => writeLine(`Operator command failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
874
|
+
});
|
|
875
|
+
return { close: () => rl.close() };
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
}
|
|
710
879
|
function taskId(task) {
|
|
711
880
|
return typeof task.id === "string" && task.id.trim() ? task.id : "<unknown>";
|
|
712
881
|
}
|
|
@@ -719,6 +888,19 @@ function taskStatus(task) {
|
|
|
719
888
|
function renderTaskPickerRows(tasks) {
|
|
720
889
|
return tasks.map((task, index) => `${index + 1}. ${taskId(task)} \xB7 ${taskStatus(task)} \xB7 ${taskTitle(task)}`);
|
|
721
890
|
}
|
|
891
|
+
async function promptForTaskSelection(question) {
|
|
892
|
+
const rl = createPromptInterface({ input: process.stdin, output: process.stdout });
|
|
893
|
+
try {
|
|
894
|
+
return await rl.question(question);
|
|
895
|
+
} finally {
|
|
896
|
+
rl.close();
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// packages/cli/src/commands/_task-picker.ts
|
|
901
|
+
function taskId2(task) {
|
|
902
|
+
return typeof task.id === "string" && task.id.trim() ? task.id : "<unknown>";
|
|
903
|
+
}
|
|
722
904
|
async function selectTaskWithTextPicker(tasks, io = {}) {
|
|
723
905
|
if (tasks.length === 0)
|
|
724
906
|
return null;
|
|
@@ -728,56 +910,626 @@ async function selectTaskWithTextPicker(tasks, io = {}) {
|
|
|
728
910
|
if (!isTty) {
|
|
729
911
|
throw new Error("task run requires an interactive terminal to pick a task; pass --task <id>, --next, or --detach with a task id.");
|
|
730
912
|
}
|
|
731
|
-
|
|
732
|
-
const
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
913
|
+
if (io.prompt || io.renderer) {
|
|
914
|
+
const prompt = io.prompt ?? promptForTaskSelection;
|
|
915
|
+
const renderer = io.renderer ?? { writeLine: (line) => process.stdout.write(`${line}
|
|
916
|
+
`) };
|
|
917
|
+
renderer.writeLine("Select Rig task:");
|
|
918
|
+
for (const row of renderTaskPickerRows(tasks))
|
|
919
|
+
renderer.writeLine(` ${row}`);
|
|
920
|
+
const answer2 = (await prompt(`Task [1-${tasks.length}] or id: `)).trim();
|
|
921
|
+
if (!answer2)
|
|
922
|
+
return null;
|
|
923
|
+
if (/^\d+$/.test(answer2)) {
|
|
924
|
+
const index2 = Number.parseInt(answer2, 10) - 1;
|
|
925
|
+
return tasks[index2] ?? null;
|
|
737
926
|
}
|
|
927
|
+
return tasks.find((task) => taskId2(task) === answer2) ?? null;
|
|
928
|
+
}
|
|
929
|
+
const options = tasks.map((task, index2) => ({
|
|
930
|
+
value: `${index2}`,
|
|
931
|
+
label: `${taskId2(task)} \xB7 ${typeof task.title === "string" && task.title.trim() ? task.title.trim() : "Untitled task"}`,
|
|
932
|
+
hint: typeof task.status === "string" && task.status.trim() ? task.status.trim() : undefined
|
|
933
|
+
}));
|
|
934
|
+
const answer = await select({
|
|
935
|
+
message: "Select Rig task",
|
|
936
|
+
options
|
|
738
937
|
});
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
console.log(` ${row}`);
|
|
742
|
-
const answer = (await prompt(`Task [1-${tasks.length}] or id: `)).trim();
|
|
743
|
-
if (!answer)
|
|
938
|
+
if (isCancel(answer)) {
|
|
939
|
+
cancel("No task selected.");
|
|
744
940
|
return null;
|
|
745
|
-
if (/^\d+$/.test(answer)) {
|
|
746
|
-
const index = Number.parseInt(answer, 10) - 1;
|
|
747
|
-
return tasks[index] ?? null;
|
|
748
941
|
}
|
|
749
|
-
|
|
942
|
+
const index = Number.parseInt(String(answer), 10);
|
|
943
|
+
return Number.isFinite(index) ? tasks[index] ?? null : null;
|
|
750
944
|
}
|
|
751
945
|
|
|
752
|
-
// packages/cli/src/commands/
|
|
753
|
-
import {
|
|
946
|
+
// packages/cli/src/commands/_pi-frontend.ts
|
|
947
|
+
import { mkdtempSync, rmSync } from "fs";
|
|
948
|
+
import { tmpdir } from "os";
|
|
949
|
+
import { join } from "path";
|
|
950
|
+
import { main as runPiMain } from "@earendil-works/pi-coding-agent";
|
|
951
|
+
|
|
952
|
+
// packages/cli/src/commands/_pi-worker-bridge-extension.ts
|
|
754
953
|
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
|
-
|
|
954
|
+
var MAX_TRANSCRIPT_LINES = 120;
|
|
955
|
+
function recordOf(value) {
|
|
956
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
957
|
+
}
|
|
958
|
+
function asText(value) {
|
|
959
|
+
if (typeof value === "string")
|
|
960
|
+
return value;
|
|
961
|
+
if (value === null || value === undefined)
|
|
962
|
+
return "";
|
|
963
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
964
|
+
return String(value);
|
|
965
|
+
try {
|
|
966
|
+
return JSON.stringify(value);
|
|
967
|
+
} catch {
|
|
968
|
+
return String(value);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
function textFromContent(content) {
|
|
972
|
+
if (typeof content === "string")
|
|
973
|
+
return content;
|
|
974
|
+
if (!Array.isArray(content))
|
|
975
|
+
return asText(content);
|
|
976
|
+
return content.flatMap((part) => {
|
|
977
|
+
const item = recordOf(part);
|
|
978
|
+
if (!item)
|
|
979
|
+
return [];
|
|
980
|
+
if (typeof item.text === "string")
|
|
981
|
+
return [item.text];
|
|
982
|
+
if (typeof item.content === "string")
|
|
983
|
+
return [item.content];
|
|
984
|
+
if (item.type === "toolCall")
|
|
985
|
+
return [`\u23FA ${String(item.name ?? "tool")} ${asText(item.arguments ?? "")}`.trim()];
|
|
986
|
+
if (item.type === "toolResult")
|
|
987
|
+
return [`\u21B3 ${asText(item.content ?? item.result ?? "")}`.trim()];
|
|
988
|
+
return [];
|
|
989
|
+
}).join(`
|
|
779
990
|
`);
|
|
780
991
|
}
|
|
992
|
+
function appendTranscript(state, label, text) {
|
|
993
|
+
const trimmed = text.trimEnd();
|
|
994
|
+
if (!trimmed)
|
|
995
|
+
return;
|
|
996
|
+
const lines = trimmed.split(/\r?\n/);
|
|
997
|
+
state.transcript.push(`${label}: ${lines[0] ?? ""}`);
|
|
998
|
+
for (const line of lines.slice(1))
|
|
999
|
+
state.transcript.push(` ${line}`);
|
|
1000
|
+
if (state.transcript.length > MAX_TRANSCRIPT_LINES) {
|
|
1001
|
+
state.transcript.splice(0, state.transcript.length - MAX_TRANSCRIPT_LINES);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
function nativePiUi(ctx) {
|
|
1005
|
+
const ui = ctx.ui;
|
|
1006
|
+
return typeof ui.emitSessionEvent === "function" && typeof ui.appendSessionMessages === "function" ? ui : null;
|
|
1007
|
+
}
|
|
1008
|
+
function syncNativeDisplayCwd(ctx, state) {
|
|
1009
|
+
const ui = nativePiUi(ctx);
|
|
1010
|
+
if (ui?.setDisplayCwd && state.cwd)
|
|
1011
|
+
ui.setDisplayCwd(state.cwd);
|
|
1012
|
+
}
|
|
1013
|
+
function parseExtensionUiRequest(value) {
|
|
1014
|
+
const request = recordOf(value) ?? {};
|
|
1015
|
+
const requestId = String(request.requestId ?? request.id ?? `ui-${Date.now()}`);
|
|
1016
|
+
const method = String(request.method ?? request.type ?? "input");
|
|
1017
|
+
const prompt = asText(request.prompt ?? request.message ?? request.title ?? method);
|
|
1018
|
+
const rawOptions = Array.isArray(request.options) ? request.options : Array.isArray(request.items) ? request.items : [];
|
|
1019
|
+
const options = rawOptions.map((option) => {
|
|
1020
|
+
const record = recordOf(option);
|
|
1021
|
+
return record ? asText(record.label ?? record.value ?? record.name ?? option) : asText(option);
|
|
1022
|
+
}).filter(Boolean);
|
|
1023
|
+
return { requestId, method, prompt, options };
|
|
1024
|
+
}
|
|
1025
|
+
function renderBridgeWidget(state) {
|
|
1026
|
+
const statusParts = [
|
|
1027
|
+
state.wsConnected ? "live WS" : "WS pending",
|
|
1028
|
+
state.status,
|
|
1029
|
+
state.model,
|
|
1030
|
+
state.cwd
|
|
1031
|
+
].filter(Boolean);
|
|
1032
|
+
const lines = [`Worker Pi daemon bridge \xB7 ${statusParts.join(" \xB7 ")}`];
|
|
1033
|
+
if (state.activity)
|
|
1034
|
+
lines.push(state.activity);
|
|
1035
|
+
if (state.commands.length > 0) {
|
|
1036
|
+
lines.push(`Worker commands: ${state.commands.slice(0, 10).join(", ")}${state.commands.length > 10 ? ", \u2026" : ""}`);
|
|
1037
|
+
}
|
|
1038
|
+
lines.push("");
|
|
1039
|
+
if (state.transcript.length > 0) {
|
|
1040
|
+
lines.push(...state.transcript.slice(-MAX_TRANSCRIPT_LINES));
|
|
1041
|
+
} else {
|
|
1042
|
+
lines.push("Waiting for worker Pi daemon transcript\u2026");
|
|
1043
|
+
}
|
|
1044
|
+
if (state.pendingUi) {
|
|
1045
|
+
lines.push("");
|
|
1046
|
+
lines.push(`Extension UI request \xB7 ${state.pendingUi.method}`);
|
|
1047
|
+
lines.push(state.pendingUi.prompt);
|
|
1048
|
+
state.pendingUi.options.forEach((option, index) => lines.push(`${index + 1}. ${option}`));
|
|
1049
|
+
lines.push("Reply in the Pi editor. /cancel cancels this request.");
|
|
1050
|
+
}
|
|
1051
|
+
return lines;
|
|
1052
|
+
}
|
|
1053
|
+
function updatePiUi(ctx, state) {
|
|
1054
|
+
ctx.ui.setTitle("Pi \xB7 Rig worker daemon");
|
|
1055
|
+
ctx.ui.setStatus("rig-worker-pi", state.wsConnected ? "worker Pi WS live" : state.status);
|
|
1056
|
+
syncNativeDisplayCwd(ctx, state);
|
|
1057
|
+
if (state.nativeStream && nativePiUi(ctx)) {
|
|
1058
|
+
ctx.ui.setWidget("rig-worker-pi-transcript", undefined);
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
ctx.ui.setWorkingVisible(false);
|
|
1062
|
+
ctx.ui.setWidget("rig-worker-pi-transcript", [`Worker Pi daemon bridge \xB7 degraded widget transcript`, ...renderBridgeWidget(state)], { placement: "aboveEditor" });
|
|
1063
|
+
}
|
|
1064
|
+
function applyStatus(state, payload) {
|
|
1065
|
+
const status = recordOf(payload.status) ?? payload;
|
|
1066
|
+
state.streaming = status.isStreaming === true || status.isCompacting === true || status.isBashRunning === true;
|
|
1067
|
+
state.cwd = typeof status.cwd === "string" ? status.cwd : state.cwd;
|
|
1068
|
+
state.model = typeof status.model === "string" ? status.model : state.model;
|
|
1069
|
+
const pending = typeof status.pendingMessageCount === "number" ? status.pendingMessageCount : 0;
|
|
1070
|
+
state.status = `${state.streaming ? "streaming" : "idle"}${pending ? ` \xB7 ${pending} queued` : ""}`;
|
|
1071
|
+
}
|
|
1072
|
+
function applyMessage(state, message2) {
|
|
1073
|
+
const record = recordOf(message2);
|
|
1074
|
+
if (!record)
|
|
1075
|
+
return;
|
|
1076
|
+
const role = String(record.role ?? "system");
|
|
1077
|
+
const label = role === "assistant" ? "Pi" : role === "user" ? "You" : role === "tool" || role === "toolResult" ? "Tool" : "System";
|
|
1078
|
+
appendTranscript(state, label, textFromContent(record.content ?? record.message ?? record.text ?? ""));
|
|
1079
|
+
}
|
|
1080
|
+
function applyPiEvent(ctx, state, eventValue) {
|
|
1081
|
+
const event = recordOf(eventValue);
|
|
1082
|
+
if (!event)
|
|
1083
|
+
return;
|
|
1084
|
+
const type = String(event.type ?? "event");
|
|
1085
|
+
if (type === "agent_start") {
|
|
1086
|
+
state.streaming = true;
|
|
1087
|
+
state.status = "streaming";
|
|
1088
|
+
} else if (type === "agent_end") {
|
|
1089
|
+
state.streaming = false;
|
|
1090
|
+
state.status = "idle";
|
|
1091
|
+
} else if (type === "queue_update") {
|
|
1092
|
+
const steering = Array.isArray(event.steering) ? event.steering.length : 0;
|
|
1093
|
+
const followUp = Array.isArray(event.followUp) ? event.followUp.length : 0;
|
|
1094
|
+
state.status = `queued \xB7 steer ${steering} \xB7 follow-up ${followUp}`;
|
|
1095
|
+
}
|
|
1096
|
+
const native = nativePiUi(ctx);
|
|
1097
|
+
if (state.nativeStream && native?.emitSessionEvent) {
|
|
1098
|
+
native.emitSessionEvent(eventValue);
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
if (type === "agent_end") {
|
|
1102
|
+
appendTranscript(state, "System", "Agent turn complete.");
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
if (type === "message_start" || type === "message_end" || type === "turn_end") {
|
|
1106
|
+
applyMessage(state, event.message);
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
if (type === "message_update") {
|
|
1110
|
+
const assistantEvent = recordOf(event.assistantMessageEvent);
|
|
1111
|
+
const delta = typeof assistantEvent?.delta === "string" ? assistantEvent.delta : typeof assistantEvent?.text === "string" ? assistantEvent.text : "";
|
|
1112
|
+
if (delta)
|
|
1113
|
+
appendTranscript(state, assistantEvent?.type === "thinking_delta" ? "Thinking" : "Pi", delta);
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
if (type === "tool_execution_start") {
|
|
1117
|
+
appendTranscript(state, "Tool", `${String(event.toolName ?? "tool")} ${asText(event.args ?? "")}`.trim());
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
if (type === "tool_execution_update") {
|
|
1121
|
+
appendTranscript(state, "Tool", asText(event.partialResult ?? ""));
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
if (type === "tool_execution_end") {
|
|
1125
|
+
appendTranscript(state, event.isError === true ? "Error" : "Tool", asText(event.result ?? `${String(event.toolName ?? "tool")} complete`));
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
function firstPendingShell(state) {
|
|
1129
|
+
return state.pendingShells[0];
|
|
1130
|
+
}
|
|
1131
|
+
function finishPendingShell(state, shell, result) {
|
|
1132
|
+
const index = state.pendingShells.indexOf(shell);
|
|
1133
|
+
if (index !== -1)
|
|
1134
|
+
state.pendingShells.splice(index, 1);
|
|
1135
|
+
shell.resolve(result);
|
|
1136
|
+
}
|
|
1137
|
+
function failPendingShell(state, shell, error) {
|
|
1138
|
+
const index = state.pendingShells.indexOf(shell);
|
|
1139
|
+
if (index !== -1)
|
|
1140
|
+
state.pendingShells.splice(index, 1);
|
|
1141
|
+
shell.reject(error);
|
|
1142
|
+
}
|
|
1143
|
+
function applyUiEvent(state, value) {
|
|
1144
|
+
const event = recordOf(value);
|
|
1145
|
+
if (!event)
|
|
1146
|
+
return;
|
|
1147
|
+
const type = String(event.type ?? "ui");
|
|
1148
|
+
if (type === "shell.chunk") {
|
|
1149
|
+
const pending = firstPendingShell(state);
|
|
1150
|
+
const chunk = asText(event.chunk);
|
|
1151
|
+
if (pending) {
|
|
1152
|
+
pending.sawChunk = true;
|
|
1153
|
+
pending.onData(Buffer.from(chunk));
|
|
1154
|
+
} else {
|
|
1155
|
+
appendTranscript(state, "Tool", chunk);
|
|
1156
|
+
}
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
if (type === "shell.end") {
|
|
1160
|
+
const pending = firstPendingShell(state);
|
|
1161
|
+
const output = asText(event.output ?? "");
|
|
1162
|
+
const exitCode = typeof event.exitCode === "number" ? event.exitCode : event.isError === true ? 1 : 0;
|
|
1163
|
+
if (pending) {
|
|
1164
|
+
if (output && !pending.sawChunk)
|
|
1165
|
+
pending.onData(Buffer.from(output));
|
|
1166
|
+
finishPendingShell(state, pending, { exitCode });
|
|
1167
|
+
} else {
|
|
1168
|
+
appendTranscript(state, event.isError === true ? "Error" : "Tool", output || `exit ${String(exitCode)}`);
|
|
1169
|
+
}
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
if (type === "shell.start") {
|
|
1173
|
+
if (!firstPendingShell(state))
|
|
1174
|
+
appendTranscript(state, "Tool", `$ ${asText(event.command)}`);
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
appendTranscript(state, "System", `${type}: ${asText(event)}`);
|
|
1178
|
+
}
|
|
1179
|
+
function applyEnvelope(ctx, state, envelopeValue) {
|
|
1180
|
+
const envelope = recordOf(envelopeValue);
|
|
1181
|
+
if (!envelope)
|
|
1182
|
+
return;
|
|
1183
|
+
const type = String(envelope.type ?? "");
|
|
1184
|
+
if (type === "ready") {
|
|
1185
|
+
const metadata = recordOf(envelope.metadata);
|
|
1186
|
+
state.cwd = typeof metadata?.cwd === "string" ? metadata.cwd : state.cwd;
|
|
1187
|
+
state.status = "worker Pi daemon ready";
|
|
1188
|
+
if (!state.nativeStream)
|
|
1189
|
+
appendTranscript(state, "System", "Connected to worker Pi daemon.");
|
|
1190
|
+
} else if (type === "status.update") {
|
|
1191
|
+
applyStatus(state, envelope);
|
|
1192
|
+
} else if (type === "activity.update") {
|
|
1193
|
+
const activity = recordOf(envelope.activity);
|
|
1194
|
+
state.activity = [activity?.label, activity?.detail].map(asText).filter(Boolean).join(" \u2014 ");
|
|
1195
|
+
} else if (type === "extension_ui_request") {
|
|
1196
|
+
state.pendingUi = parseExtensionUiRequest(envelope.request);
|
|
1197
|
+
appendTranscript(state, "System", `Extension UI request: ${state.pendingUi.prompt}`);
|
|
1198
|
+
} else if (type === "pi.ui_event") {
|
|
1199
|
+
applyUiEvent(state, envelope.event);
|
|
1200
|
+
} else if (type === "pi.event") {
|
|
1201
|
+
applyPiEvent(ctx, state, envelope.event);
|
|
1202
|
+
} else if (type === "error") {
|
|
1203
|
+
appendTranscript(state, "Error", asText(envelope.message ?? envelope.detail ?? "unknown error"));
|
|
1204
|
+
}
|
|
1205
|
+
syncNativeDisplayCwd(ctx, state);
|
|
1206
|
+
}
|
|
1207
|
+
async function waitForWorkerReady(options, ctx, state) {
|
|
1208
|
+
while (true) {
|
|
1209
|
+
const session = await getRunPiSessionViaServer(options.context, options.runId).catch((error) => ({
|
|
1210
|
+
ready: false,
|
|
1211
|
+
status: error instanceof Error ? error.message : String(error),
|
|
1212
|
+
retryAfterMs: 1000
|
|
1213
|
+
}));
|
|
1214
|
+
if (session.ready === false) {
|
|
1215
|
+
const status = String(session.status ?? "starting");
|
|
1216
|
+
state.status = `waiting for worker Pi daemon \xB7 ${status}`;
|
|
1217
|
+
updatePiUi(ctx, state);
|
|
1218
|
+
if (TERMINAL_RUN_STATUSES.has(status.toLowerCase())) {
|
|
1219
|
+
appendTranscript(state, "Error", `Run ended before worker Pi daemon became ready: ${status}`);
|
|
1220
|
+
return false;
|
|
1221
|
+
}
|
|
1222
|
+
await Bun.sleep(typeof session.retryAfterMs === "number" ? session.retryAfterMs : 750);
|
|
1223
|
+
continue;
|
|
1224
|
+
}
|
|
1225
|
+
const sessionRecord = recordOf(session) ?? {};
|
|
1226
|
+
applyEnvelope(ctx, state, { type: "ready", metadata: sessionRecord.metadata ?? sessionRecord });
|
|
1227
|
+
updatePiUi(ctx, state);
|
|
1228
|
+
return true;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
function parseWsPayload(message2) {
|
|
1232
|
+
if (typeof message2.data === "string")
|
|
1233
|
+
return JSON.parse(message2.data);
|
|
1234
|
+
return JSON.parse(Buffer.from(message2.data).toString("utf8"));
|
|
1235
|
+
}
|
|
1236
|
+
async function connectWorkerStream(options, ctx, state) {
|
|
1237
|
+
const ready = await waitForWorkerReady(options, ctx, state);
|
|
1238
|
+
if (!ready)
|
|
1239
|
+
return;
|
|
1240
|
+
let catchupDone = false;
|
|
1241
|
+
const buffered = [];
|
|
1242
|
+
const wsUrl = await buildRunPiEventsWebSocketUrl(options.context, options.runId);
|
|
1243
|
+
const socket = new WebSocket(wsUrl);
|
|
1244
|
+
const closePromise = new Promise((resolve3) => {
|
|
1245
|
+
socket.onopen = () => {
|
|
1246
|
+
state.wsConnected = true;
|
|
1247
|
+
state.status = "live worker Pi WebSocket connected";
|
|
1248
|
+
updatePiUi(ctx, state);
|
|
1249
|
+
};
|
|
1250
|
+
socket.onmessage = (message2) => {
|
|
1251
|
+
try {
|
|
1252
|
+
const payload = parseWsPayload(message2);
|
|
1253
|
+
if (!catchupDone)
|
|
1254
|
+
buffered.push(payload);
|
|
1255
|
+
else {
|
|
1256
|
+
applyEnvelope(ctx, state, payload);
|
|
1257
|
+
updatePiUi(ctx, state);
|
|
1258
|
+
}
|
|
1259
|
+
} catch (error) {
|
|
1260
|
+
appendTranscript(state, "Error", `Unparseable worker Pi event: ${error instanceof Error ? error.message : String(error)}`);
|
|
1261
|
+
updatePiUi(ctx, state);
|
|
1262
|
+
}
|
|
1263
|
+
};
|
|
1264
|
+
socket.onerror = () => socket.close();
|
|
1265
|
+
socket.onclose = () => {
|
|
1266
|
+
state.wsConnected = false;
|
|
1267
|
+
state.status = "worker Pi WebSocket disconnected";
|
|
1268
|
+
updatePiUi(ctx, state);
|
|
1269
|
+
resolve3();
|
|
1270
|
+
};
|
|
1271
|
+
});
|
|
1272
|
+
try {
|
|
1273
|
+
const [messagesPayload, statusPayload, commandsPayload] = await Promise.all([
|
|
1274
|
+
getRunPiMessagesViaServer(options.context, options.runId),
|
|
1275
|
+
getRunPiStatusViaServer(options.context, options.runId),
|
|
1276
|
+
getRunPiCommandsViaServer(options.context, options.runId)
|
|
1277
|
+
]);
|
|
1278
|
+
const messages = Array.isArray(messagesPayload.messages) ? messagesPayload.messages : [];
|
|
1279
|
+
const native = nativePiUi(ctx);
|
|
1280
|
+
if (state.nativeStream && native?.appendSessionMessages)
|
|
1281
|
+
native.appendSessionMessages(messages);
|
|
1282
|
+
else
|
|
1283
|
+
for (const message2 of messages)
|
|
1284
|
+
applyMessage(state, message2);
|
|
1285
|
+
applyStatus(state, statusPayload);
|
|
1286
|
+
const commands = Array.isArray(commandsPayload.commands) ? commandsPayload.commands : [];
|
|
1287
|
+
state.commands = commands.flatMap((command) => {
|
|
1288
|
+
const record = recordOf(command);
|
|
1289
|
+
return typeof record?.name === "string" ? [`/${record.name}`] : [];
|
|
1290
|
+
});
|
|
1291
|
+
catchupDone = true;
|
|
1292
|
+
for (const payload of buffered.splice(0))
|
|
1293
|
+
applyEnvelope(ctx, state, payload);
|
|
1294
|
+
updatePiUi(ctx, state);
|
|
1295
|
+
} catch (error) {
|
|
1296
|
+
appendTranscript(state, "Error", `Worker Pi catch-up failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1297
|
+
catchupDone = true;
|
|
1298
|
+
updatePiUi(ctx, state);
|
|
1299
|
+
}
|
|
1300
|
+
await closePromise;
|
|
1301
|
+
}
|
|
1302
|
+
function createRemoteBashOperations(options, state, excludeFromContext) {
|
|
1303
|
+
return {
|
|
1304
|
+
exec(command, _cwd, execOptions) {
|
|
1305
|
+
return new Promise((resolve3, reject) => {
|
|
1306
|
+
const pending = {
|
|
1307
|
+
command,
|
|
1308
|
+
onData: execOptions.onData,
|
|
1309
|
+
resolve: resolve3,
|
|
1310
|
+
reject,
|
|
1311
|
+
sawChunk: false
|
|
1312
|
+
};
|
|
1313
|
+
const cleanup = () => {
|
|
1314
|
+
execOptions.signal?.removeEventListener("abort", onAbort);
|
|
1315
|
+
if (timer)
|
|
1316
|
+
clearTimeout(timer);
|
|
1317
|
+
};
|
|
1318
|
+
const onAbort = () => {
|
|
1319
|
+
cleanup();
|
|
1320
|
+
failPendingShell(state, pending, new Error("Remote worker shell command aborted locally."));
|
|
1321
|
+
};
|
|
1322
|
+
const timeoutMs = typeof execOptions.timeout === "number" && execOptions.timeout > 0 ? execOptions.timeout : 0;
|
|
1323
|
+
const timer = timeoutMs > 0 ? setTimeout(() => {
|
|
1324
|
+
cleanup();
|
|
1325
|
+
failPendingShell(state, pending, new Error(`Remote worker shell command timed out after ${timeoutMs}ms.`));
|
|
1326
|
+
}, timeoutMs) : null;
|
|
1327
|
+
const wrappedResolve = pending.resolve;
|
|
1328
|
+
const wrappedReject = pending.reject;
|
|
1329
|
+
pending.resolve = (result) => {
|
|
1330
|
+
cleanup();
|
|
1331
|
+
wrappedResolve(result);
|
|
1332
|
+
};
|
|
1333
|
+
pending.reject = (error) => {
|
|
1334
|
+
cleanup();
|
|
1335
|
+
wrappedReject(error);
|
|
1336
|
+
};
|
|
1337
|
+
execOptions.signal?.addEventListener("abort", onAbort, { once: true });
|
|
1338
|
+
state.pendingShells.push(pending);
|
|
1339
|
+
sendRunPiShellViaServer(options.context, options.runId, `${excludeFromContext ? "!!" : "!"}${command}`).catch((error) => {
|
|
1340
|
+
cleanup();
|
|
1341
|
+
failPendingShell(state, pending, error instanceof Error ? error : new Error(String(error)));
|
|
1342
|
+
});
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
async function answerPendingUi(options, state, line) {
|
|
1348
|
+
const pending = state.pendingUi;
|
|
1349
|
+
if (!pending)
|
|
1350
|
+
return false;
|
|
1351
|
+
if (line === "/cancel") {
|
|
1352
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, pending.requestId, { cancelled: true });
|
|
1353
|
+
} else if (pending.method === "confirm") {
|
|
1354
|
+
const confirmed = /^(y|yes|true|1)$/i.test(line);
|
|
1355
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, pending.requestId, { value: confirmed, confirmed });
|
|
1356
|
+
} else if (pending.options.length > 0 && /^\d+$/.test(line)) {
|
|
1357
|
+
const selected = pending.options[Math.max(0, Number(line) - 1)] ?? line;
|
|
1358
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, pending.requestId, { value: selected });
|
|
1359
|
+
} else {
|
|
1360
|
+
await respondRunPiExtensionUiViaServer(options.context, options.runId, pending.requestId, { value: line });
|
|
1361
|
+
}
|
|
1362
|
+
appendTranscript(state, "System", `Responded to extension UI request ${pending.requestId}.`);
|
|
1363
|
+
state.pendingUi = null;
|
|
1364
|
+
return true;
|
|
1365
|
+
}
|
|
1366
|
+
async function routeInput(options, ctx, state, line) {
|
|
1367
|
+
const text = line.trim();
|
|
1368
|
+
if (!text)
|
|
1369
|
+
return;
|
|
1370
|
+
if (await answerPendingUi(options, state, text)) {
|
|
1371
|
+
updatePiUi(ctx, state);
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
if (text === "/detach" || text === "/quit" || text === "/q") {
|
|
1375
|
+
appendTranscript(state, "System", "Detached locally; worker Pi daemon continues.");
|
|
1376
|
+
updatePiUi(ctx, state);
|
|
1377
|
+
ctx.shutdown();
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1380
|
+
if (text === "/stop") {
|
|
1381
|
+
await abortRunPiViaServer(options.context, options.runId);
|
|
1382
|
+
appendTranscript(state, "System", "Stop requested for worker Pi daemon.");
|
|
1383
|
+
updatePiUi(ctx, state);
|
|
1384
|
+
ctx.shutdown();
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
if (text.startsWith("!")) {
|
|
1388
|
+
appendTranscript(state, "You", text);
|
|
1389
|
+
await sendRunPiShellViaServer(options.context, options.runId, text);
|
|
1390
|
+
} else if (text.startsWith("/")) {
|
|
1391
|
+
appendTranscript(state, "You", text);
|
|
1392
|
+
const result = await runRunPiCommandViaServer(options.context, options.runId, text);
|
|
1393
|
+
const message2 = typeof result.message === "string" ? result.message : "worker command accepted";
|
|
1394
|
+
appendTranscript(state, "System", message2);
|
|
1395
|
+
} else {
|
|
1396
|
+
appendTranscript(state, "You", text);
|
|
1397
|
+
await sendRunPiPromptViaServer(options.context, options.runId, text, state.streaming ? "steer" : undefined);
|
|
1398
|
+
}
|
|
1399
|
+
updatePiUi(ctx, state);
|
|
1400
|
+
}
|
|
1401
|
+
function createRigWorkerPiBridgeExtension(options) {
|
|
1402
|
+
return (pi) => {
|
|
1403
|
+
const state = {
|
|
1404
|
+
transcript: [],
|
|
1405
|
+
status: "starting worker Pi daemon bridge",
|
|
1406
|
+
activity: "",
|
|
1407
|
+
cwd: "",
|
|
1408
|
+
model: "",
|
|
1409
|
+
commands: [],
|
|
1410
|
+
streaming: false,
|
|
1411
|
+
pendingUi: null,
|
|
1412
|
+
pendingShells: [],
|
|
1413
|
+
wsConnected: false,
|
|
1414
|
+
nativeStream: false
|
|
1415
|
+
};
|
|
1416
|
+
if (options.initialMessageSent)
|
|
1417
|
+
appendTranscript(state, "System", "Initial message sent to worker Pi daemon.");
|
|
1418
|
+
let nativePiUiContextAvailable = false;
|
|
1419
|
+
pi.on("user_bash", (event) => {
|
|
1420
|
+
state.nativeStream = Boolean(state.nativeStream || nativePiUiContextAvailable);
|
|
1421
|
+
return { operations: createRemoteBashOperations(options, state, event.excludeFromContext === true) };
|
|
1422
|
+
});
|
|
1423
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
1424
|
+
nativePiUiContextAvailable = Boolean(nativePiUi(ctx));
|
|
1425
|
+
state.nativeStream = nativePiUiContextAvailable;
|
|
1426
|
+
updatePiUi(ctx, state);
|
|
1427
|
+
ctx.ui.notify(nativePiUiContextAvailable ? "Rig worker Pi native stream bridge loaded" : "Rig worker Pi bridge extension loaded (degraded widget fallback)", "info");
|
|
1428
|
+
ctx.ui.onTerminalInput((data) => {
|
|
1429
|
+
if (data.includes("\x04")) {
|
|
1430
|
+
ctx.shutdown();
|
|
1431
|
+
return { consume: true };
|
|
1432
|
+
}
|
|
1433
|
+
if (!data.includes("\r") && !data.includes(`
|
|
1434
|
+
`))
|
|
1435
|
+
return;
|
|
1436
|
+
const inlineText = data.replace(/[\r\n]+/g, "").trim();
|
|
1437
|
+
const editorText = ctx.ui.getEditorText().trim();
|
|
1438
|
+
const text = [editorText, inlineText].filter(Boolean).join(" ").trim();
|
|
1439
|
+
if (!text)
|
|
1440
|
+
return;
|
|
1441
|
+
if (text.startsWith("!"))
|
|
1442
|
+
return;
|
|
1443
|
+
ctx.ui.setEditorText("");
|
|
1444
|
+
routeInput(options, ctx, state, text).catch((error) => {
|
|
1445
|
+
appendTranscript(state, "Error", error instanceof Error ? error.message : String(error));
|
|
1446
|
+
updatePiUi(ctx, state);
|
|
1447
|
+
});
|
|
1448
|
+
return { consume: true };
|
|
1449
|
+
});
|
|
1450
|
+
connectWorkerStream(options, ctx, state).catch((error) => {
|
|
1451
|
+
appendTranscript(state, "Error", error instanceof Error ? error.message : String(error));
|
|
1452
|
+
updatePiUi(ctx, state);
|
|
1453
|
+
});
|
|
1454
|
+
});
|
|
1455
|
+
pi.on("session_shutdown", () => {});
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
// packages/cli/src/commands/_pi-frontend.ts
|
|
1460
|
+
function setTemporaryEnv(updates) {
|
|
1461
|
+
const previous = new Map;
|
|
1462
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
1463
|
+
previous.set(key, process.env[key]);
|
|
1464
|
+
process.env[key] = value;
|
|
1465
|
+
}
|
|
1466
|
+
return () => {
|
|
1467
|
+
for (const [key, value] of previous) {
|
|
1468
|
+
if (value === undefined)
|
|
1469
|
+
delete process.env[key];
|
|
1470
|
+
else
|
|
1471
|
+
process.env[key] = value;
|
|
1472
|
+
}
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
async function attachRunBundledPiFrontend(context, input) {
|
|
1476
|
+
const tempRoot = mkdtempSync(join(tmpdir(), "rig-pi-frontend-"));
|
|
1477
|
+
const cwd = join(tempRoot, "workspace");
|
|
1478
|
+
const agentDir = join(tempRoot, "agent");
|
|
1479
|
+
const sessionDir = join(tempRoot, "sessions");
|
|
1480
|
+
const previousCwd = process.cwd();
|
|
1481
|
+
const restoreEnv = setTemporaryEnv({
|
|
1482
|
+
PI_CODING_AGENT_DIR: agentDir,
|
|
1483
|
+
PI_CODING_AGENT_SESSION_DIR: sessionDir,
|
|
1484
|
+
PI_OFFLINE: "1",
|
|
1485
|
+
PI_SKIP_VERSION_CHECK: "1"
|
|
1486
|
+
});
|
|
1487
|
+
let detached = false;
|
|
1488
|
+
try {
|
|
1489
|
+
await Bun.$`mkdir -p ${cwd} ${agentDir} ${sessionDir}`.quiet();
|
|
1490
|
+
process.chdir(cwd);
|
|
1491
|
+
await runPiMain([
|
|
1492
|
+
"--offline",
|
|
1493
|
+
"--no-session",
|
|
1494
|
+
"--no-tools",
|
|
1495
|
+
"--no-builtin-tools",
|
|
1496
|
+
"--no-skills",
|
|
1497
|
+
"--no-prompt-templates",
|
|
1498
|
+
"--no-themes",
|
|
1499
|
+
"--no-context-files",
|
|
1500
|
+
"--no-approve"
|
|
1501
|
+
], {
|
|
1502
|
+
extensionFactories: [
|
|
1503
|
+
createRigWorkerPiBridgeExtension({
|
|
1504
|
+
context,
|
|
1505
|
+
runId: input.runId,
|
|
1506
|
+
initialMessageSent: input.steered === true
|
|
1507
|
+
})
|
|
1508
|
+
]
|
|
1509
|
+
});
|
|
1510
|
+
detached = true;
|
|
1511
|
+
} finally {
|
|
1512
|
+
process.chdir(previousCwd);
|
|
1513
|
+
restoreEnv();
|
|
1514
|
+
rmSync(tempRoot, { recursive: true, force: true });
|
|
1515
|
+
}
|
|
1516
|
+
let run = { runId: input.runId, status: "unknown" };
|
|
1517
|
+
try {
|
|
1518
|
+
run = await getRunDetailsViaServer(context, input.runId);
|
|
1519
|
+
} catch {}
|
|
1520
|
+
return {
|
|
1521
|
+
run,
|
|
1522
|
+
logs: [],
|
|
1523
|
+
timeline: [],
|
|
1524
|
+
timelineCursor: null,
|
|
1525
|
+
steered: input.steered === true,
|
|
1526
|
+
detached,
|
|
1527
|
+
rendered: "actual bundled Pi frontend hosted Rig worker Pi bridge extension"
|
|
1528
|
+
};
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
// packages/cli/src/commands/_operator-view.ts
|
|
1532
|
+
var TERMINAL_RUN_STATUSES2 = new Set(["completed", "failed", "stopped", "cancelled", "canceled", "closed", "merged", "needs_attention", "needs-attention"]);
|
|
781
1533
|
function runStatusFromPayload(payload) {
|
|
782
1534
|
const run = payload.run && typeof payload.run === "object" && !Array.isArray(payload.run) ? payload.run : payload;
|
|
783
1535
|
return String(run.status ?? "unknown").toLowerCase();
|
|
@@ -799,56 +1551,584 @@ async function applyOperatorCommand(context, input, deps = {}) {
|
|
|
799
1551
|
await (deps.steer ?? steerRunViaServer)(context, input.runId, userMessage);
|
|
800
1552
|
return { action: "continue", message: "Steering message queued." };
|
|
801
1553
|
}
|
|
802
|
-
async function readOperatorSnapshot(context, runId) {
|
|
1554
|
+
async function readOperatorSnapshot(context, runId, options = {}) {
|
|
803
1555
|
const run = await getRunDetailsViaServer(context, runId);
|
|
804
1556
|
const logsPage = await getRunLogsViaServer(context, runId, { limit: 100 });
|
|
805
|
-
const
|
|
806
|
-
|
|
1557
|
+
const timelinePage = await getRunTimelineViaServer(context, runId, { limit: 200, ...options.timelineCursor ? { cursor: options.timelineCursor } : {} }).catch((error) => ({
|
|
1558
|
+
entries: [{
|
|
1559
|
+
id: `timeline-unavailable:${runId}`,
|
|
1560
|
+
type: "timeline_warning",
|
|
1561
|
+
detail: `Selected Rig server did not provide run timeline events: ${error instanceof Error ? error.message : String(error)}`,
|
|
1562
|
+
createdAt: new Date().toISOString()
|
|
1563
|
+
}],
|
|
1564
|
+
nextCursor: options.timelineCursor ?? null
|
|
1565
|
+
}));
|
|
1566
|
+
const logs = Array.isArray(logsPage.entries) ? logsPage.entries.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry))).toReversed() : [];
|
|
1567
|
+
const timeline = Array.isArray(timelinePage.entries) ? timelinePage.entries.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry))) : [];
|
|
1568
|
+
const timelineCursor = typeof timelinePage.nextCursor === "string" ? timelinePage.nextCursor : options.timelineCursor ?? null;
|
|
1569
|
+
return { run, logs, timeline, timelineCursor, rendered: renderOperatorSnapshot({ run, logs, timeline }) };
|
|
807
1570
|
}
|
|
808
1571
|
async function attachRunOperatorView(context, input) {
|
|
809
1572
|
let steered = false;
|
|
810
1573
|
if (input.message?.trim()) {
|
|
811
|
-
await steerRunViaServer(context, input.runId, input.message.trim());
|
|
1574
|
+
await sendRunPiPromptViaServer(context, input.runId, input.message.trim(), "steer").catch(() => steerRunViaServer(context, input.runId, input.message.trim()));
|
|
812
1575
|
steered = true;
|
|
813
1576
|
}
|
|
1577
|
+
if (input.follow && !input.once && input.interactive !== false && context.outputMode === "text" && Boolean(process.stdin.isTTY && process.stdout.isTTY)) {
|
|
1578
|
+
return attachRunBundledPiFrontend(context, {
|
|
1579
|
+
runId: input.runId,
|
|
1580
|
+
steered
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
const surface = createOperatorSurface({ interactive: input.interactive !== false });
|
|
814
1584
|
let snapshot = await readOperatorSnapshot(context, input.runId);
|
|
815
1585
|
if (context.outputMode === "text") {
|
|
816
|
-
|
|
1586
|
+
surface.renderSnapshot(snapshot);
|
|
1587
|
+
surface.renderTimeline(snapshot.timeline);
|
|
1588
|
+
surface.renderLogs(snapshot.logs);
|
|
817
1589
|
if (steered)
|
|
818
|
-
|
|
1590
|
+
surface.info("Message submitted to worker Pi.");
|
|
819
1591
|
}
|
|
820
1592
|
let detached = false;
|
|
821
|
-
let
|
|
1593
|
+
let commandInput = null;
|
|
822
1594
|
if (input.follow && !input.once && context.outputMode === "text") {
|
|
823
1595
|
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)}`));
|
|
1596
|
+
surface.info("Controls: /user <message>, /stop, /detach");
|
|
1597
|
+
commandInput = surface.attachCommandInput(async (line) => {
|
|
1598
|
+
const result = await applyOperatorCommand(context, { runId: input.runId, line });
|
|
1599
|
+
if (result.message)
|
|
1600
|
+
surface.info(result.message);
|
|
1601
|
+
if (result.action === "detach" || result.action === "stopped") {
|
|
1602
|
+
detached = true;
|
|
1603
|
+
commandInput?.close();
|
|
1604
|
+
}
|
|
835
1605
|
});
|
|
836
1606
|
}
|
|
837
|
-
let lastRendered = snapshot.rendered;
|
|
838
1607
|
const pollMs = Math.max(250, Math.trunc(input.pollMs ?? 2000));
|
|
839
|
-
|
|
1608
|
+
let timelineCursor = snapshot.timelineCursor;
|
|
1609
|
+
while (!detached && !TERMINAL_RUN_STATUSES2.has(runStatusFromPayload(snapshot.run))) {
|
|
840
1610
|
await Bun.sleep(pollMs);
|
|
841
|
-
snapshot = await readOperatorSnapshot(context, input.runId);
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
1611
|
+
snapshot = await readOperatorSnapshot(context, input.runId, { timelineCursor });
|
|
1612
|
+
timelineCursor = snapshot.timelineCursor;
|
|
1613
|
+
surface.renderSnapshot(snapshot);
|
|
1614
|
+
surface.renderTimeline(snapshot.timeline);
|
|
1615
|
+
surface.renderLogs(snapshot.logs);
|
|
846
1616
|
}
|
|
847
|
-
|
|
1617
|
+
commandInput?.close();
|
|
848
1618
|
}
|
|
849
1619
|
return { ...snapshot, steered, detached };
|
|
850
1620
|
}
|
|
851
1621
|
|
|
1622
|
+
// packages/cli/src/commands/_cli-format.ts
|
|
1623
|
+
import { log, note } from "@clack/prompts";
|
|
1624
|
+
import pc from "picocolors";
|
|
1625
|
+
function stringField(record, key, fallback = "") {
|
|
1626
|
+
const value = record[key];
|
|
1627
|
+
return typeof value === "string" && value.trim() ? value.trim() : fallback;
|
|
1628
|
+
}
|
|
1629
|
+
function numberField(record, key) {
|
|
1630
|
+
const value = record[key];
|
|
1631
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
1632
|
+
}
|
|
1633
|
+
function arrayField(record, key) {
|
|
1634
|
+
const value = record[key];
|
|
1635
|
+
return Array.isArray(value) ? value.flatMap((entry) => typeof entry === "string" && entry.trim() ? [entry.trim()] : []) : [];
|
|
1636
|
+
}
|
|
1637
|
+
function rawObject(record) {
|
|
1638
|
+
const raw = record.raw;
|
|
1639
|
+
return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
1640
|
+
}
|
|
1641
|
+
function truncate(value, width) {
|
|
1642
|
+
if (value.length <= width)
|
|
1643
|
+
return value;
|
|
1644
|
+
if (width <= 1)
|
|
1645
|
+
return "\u2026";
|
|
1646
|
+
return `${value.slice(0, width - 1)}\u2026`;
|
|
1647
|
+
}
|
|
1648
|
+
function pad(value, width) {
|
|
1649
|
+
return value.length >= width ? value : `${value}${" ".repeat(width - value.length)}`;
|
|
1650
|
+
}
|
|
1651
|
+
function statusColor(status) {
|
|
1652
|
+
const normalized = status.toLowerCase();
|
|
1653
|
+
if (["completed", "merged", "closed", "done", "accepted", "pass", "selected", "approved"].includes(normalized))
|
|
1654
|
+
return pc.green;
|
|
1655
|
+
if (["failed", "needs_attention", "needs-attention", "blocked", "error", "rejected"].includes(normalized))
|
|
1656
|
+
return pc.red;
|
|
1657
|
+
if (["running", "reviewing", "validating", "in_progress", "in-progress", "remote"].includes(normalized))
|
|
1658
|
+
return pc.cyan;
|
|
1659
|
+
if (["ready", "open", "queued", "created", "preparing", "local", "pending"].includes(normalized))
|
|
1660
|
+
return pc.yellow;
|
|
1661
|
+
return pc.dim;
|
|
1662
|
+
}
|
|
1663
|
+
function compactValue(value) {
|
|
1664
|
+
if (value === null || value === undefined)
|
|
1665
|
+
return "";
|
|
1666
|
+
if (typeof value === "string")
|
|
1667
|
+
return value;
|
|
1668
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
1669
|
+
return String(value);
|
|
1670
|
+
if (Array.isArray(value))
|
|
1671
|
+
return value.map(compactValue).filter(Boolean).join(", ");
|
|
1672
|
+
return JSON.stringify(value);
|
|
1673
|
+
}
|
|
1674
|
+
function shouldUseClackOutput() {
|
|
1675
|
+
return Boolean(process.stdout.isTTY) && process.env.RIG_CLI_PLAIN_HELP !== "1";
|
|
1676
|
+
}
|
|
1677
|
+
function printFormattedOutput(message2, options = {}) {
|
|
1678
|
+
if (!shouldUseClackOutput()) {
|
|
1679
|
+
console.log(message2);
|
|
1680
|
+
return;
|
|
1681
|
+
}
|
|
1682
|
+
if (options.title)
|
|
1683
|
+
note(message2, options.title);
|
|
1684
|
+
else
|
|
1685
|
+
log.message(message2);
|
|
1686
|
+
}
|
|
1687
|
+
function formatStatusPill(status) {
|
|
1688
|
+
const label = status || "unknown";
|
|
1689
|
+
return statusColor(label)(`\u25CF ${label}`);
|
|
1690
|
+
}
|
|
1691
|
+
function formatSection(title, subtitle) {
|
|
1692
|
+
return `${pc.bold(pc.cyan("\u25C6"))} ${pc.bold(title)}${subtitle ? pc.dim(` \u2014 ${subtitle}`) : ""}`;
|
|
1693
|
+
}
|
|
1694
|
+
function formatSuccessCard(title, rows = []) {
|
|
1695
|
+
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}`);
|
|
1696
|
+
return [formatSection(title), ...body].join(`
|
|
1697
|
+
`);
|
|
1698
|
+
}
|
|
1699
|
+
function formatNextSteps(steps) {
|
|
1700
|
+
if (steps.length === 0)
|
|
1701
|
+
return [];
|
|
1702
|
+
return [pc.bold("Next"), ...steps.map((step) => `${pc.dim("\u203A")} ${step}`)];
|
|
1703
|
+
}
|
|
1704
|
+
function formatTaskList(tasks, options = {}) {
|
|
1705
|
+
if (options.raw)
|
|
1706
|
+
return tasks.map((task) => JSON.stringify(task)).join(`
|
|
1707
|
+
`);
|
|
1708
|
+
if (tasks.length === 0)
|
|
1709
|
+
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(`
|
|
1710
|
+
`);
|
|
1711
|
+
const rows = tasks.map((task) => {
|
|
1712
|
+
const raw = rawObject(task);
|
|
1713
|
+
const id = stringField(task, "id", "<unknown>");
|
|
1714
|
+
const status = stringField(task, "status", "unknown");
|
|
1715
|
+
const title = stringField(task, "title", "Untitled task");
|
|
1716
|
+
const source = stringField(task, "source", stringField(raw, "source", ""));
|
|
1717
|
+
const labels = arrayField(task, "labels").length > 0 ? arrayField(task, "labels") : arrayField(raw, "labels");
|
|
1718
|
+
return { id, status, title, source, labels };
|
|
1719
|
+
});
|
|
1720
|
+
const idWidth = Math.min(18, Math.max(4, ...rows.map((row) => row.id.length)));
|
|
1721
|
+
const statusWidth = Math.min(16, Math.max(6, ...rows.map((row) => row.status.length)));
|
|
1722
|
+
const header = `${pc.bold(pad("TASK", idWidth))} ${pc.bold(pad("STATUS", statusWidth))} ${pc.bold("TITLE")}`;
|
|
1723
|
+
const body = rows.map((row) => {
|
|
1724
|
+
const labels = row.labels.length > 0 ? pc.dim(` ${row.labels.slice(0, 4).map((label) => `#${label}`).join(" ")}`) : "";
|
|
1725
|
+
const source = row.source ? pc.dim(` ${row.source}`) : "";
|
|
1726
|
+
return [
|
|
1727
|
+
pc.bold(pad(truncate(row.id, idWidth), idWidth)),
|
|
1728
|
+
statusColor(row.status)(pad(truncate(row.status, statusWidth), statusWidth)),
|
|
1729
|
+
`${row.title}${labels}${source}`
|
|
1730
|
+
].join(" ");
|
|
1731
|
+
});
|
|
1732
|
+
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(`
|
|
1733
|
+
`);
|
|
1734
|
+
}
|
|
1735
|
+
function formatTaskCard(task, options = {}) {
|
|
1736
|
+
const raw = rawObject(task);
|
|
1737
|
+
const id = stringField(task, "id", stringField(raw, "id", "<unknown>"));
|
|
1738
|
+
const status = stringField(task, "status", stringField(raw, "status", "unknown"));
|
|
1739
|
+
const title = stringField(task, "title", stringField(raw, "title", "Untitled task"));
|
|
1740
|
+
const source = stringField(task, "source", stringField(raw, "source", ""));
|
|
1741
|
+
const url = stringField(task, "url", stringField(raw, "url", ""));
|
|
1742
|
+
const number = numberField(task, "number") ?? numberField(raw, "number");
|
|
1743
|
+
const labels = arrayField(task, "labels").length > 0 ? arrayField(task, "labels") : arrayField(raw, "labels");
|
|
1744
|
+
const assignees = arrayField(task, "assignees").length > 0 ? arrayField(task, "assignees") : arrayField(raw, "assignees");
|
|
1745
|
+
const readiness = compactValue(task.readiness ?? raw.readiness);
|
|
1746
|
+
const validators = compactValue(task.validators ?? raw.validators ?? task.validation ?? raw.validation);
|
|
1747
|
+
const rows = [
|
|
1748
|
+
["task", pc.bold(id)],
|
|
1749
|
+
["status", formatStatusPill(status)],
|
|
1750
|
+
["title", title],
|
|
1751
|
+
["source", source],
|
|
1752
|
+
["number", number],
|
|
1753
|
+
["labels", labels.length ? labels.map((label) => `#${label}`).join(" ") : ""],
|
|
1754
|
+
["assignees", assignees.join(", ")],
|
|
1755
|
+
["readiness", readiness],
|
|
1756
|
+
["validators", validators],
|
|
1757
|
+
["url", url]
|
|
1758
|
+
];
|
|
1759
|
+
return [
|
|
1760
|
+
formatSuccessCard(options.title ?? (options.selected ? "Selected task" : "Task"), rows),
|
|
1761
|
+
"",
|
|
1762
|
+
...formatNextSteps([`Start: \`rig task run ${id}\``, `Details: \`rig task show ${id} --raw\``])
|
|
1763
|
+
].join(`
|
|
1764
|
+
`);
|
|
1765
|
+
}
|
|
1766
|
+
function formatTaskDetails(task) {
|
|
1767
|
+
return formatTaskCard(task, { title: "Task details" });
|
|
1768
|
+
}
|
|
1769
|
+
function formatSubmittedRun(input) {
|
|
1770
|
+
const rows = [["run", pc.bold(input.runId)]];
|
|
1771
|
+
if (input.task) {
|
|
1772
|
+
const id = stringField(input.task, "id", "<unknown>");
|
|
1773
|
+
const status = stringField(input.task, "status", "unknown");
|
|
1774
|
+
const title = stringField(input.task, "title", "Untitled task");
|
|
1775
|
+
rows.push(["task", `${pc.bold(id)} ${formatStatusPill(status)} ${title}`]);
|
|
1776
|
+
}
|
|
1777
|
+
const runtime = [input.runtimeAdapter || "pi", input.runtimeMode || "full-access", input.interactionMode || "default"].filter(Boolean).join(" \xB7 ");
|
|
1778
|
+
rows.push(["runtime", runtime]);
|
|
1779
|
+
return [
|
|
1780
|
+
formatSuccessCard("Run submitted", rows),
|
|
1781
|
+
"",
|
|
1782
|
+
...formatNextSteps([
|
|
1783
|
+
`Attach: \`rig run attach ${input.runId} --follow\``,
|
|
1784
|
+
`Inspect: \`rig run show ${input.runId}\``,
|
|
1785
|
+
input.detached ? "Submitted detached; attach when you are ready." : "Interactive mode opens the native bundled Pi frontend."
|
|
1786
|
+
])
|
|
1787
|
+
].join(`
|
|
1788
|
+
`);
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
// packages/cli/src/commands/_help-catalog.ts
|
|
1792
|
+
import { intro, log as log2, note as note2, outro } from "@clack/prompts";
|
|
1793
|
+
import pc2 from "picocolors";
|
|
1794
|
+
var TOP_LEVEL_SECTIONS = [
|
|
1795
|
+
{
|
|
1796
|
+
title: "Server",
|
|
1797
|
+
subtitle: "choose the local or remote Rig server that owns this repo",
|
|
1798
|
+
commands: [
|
|
1799
|
+
{ command: "rig server status", description: "Show the selected local/remote server for this repo." },
|
|
1800
|
+
{ command: "rig server use local", description: "Switch this repo back to the local Rig server." },
|
|
1801
|
+
{ command: "rig server add <alias> <url>", description: "Save a remote Rig server alias." },
|
|
1802
|
+
{ command: "rig server use <alias>", description: "Switch this repo to a saved remote server." },
|
|
1803
|
+
{ command: "rig server list", description: "Show saved server aliases, including local." }
|
|
1804
|
+
]
|
|
1805
|
+
},
|
|
1806
|
+
{
|
|
1807
|
+
title: "Tasks",
|
|
1808
|
+
subtitle: "find work, inspect it, and submit Pi-backed workers",
|
|
1809
|
+
commands: [
|
|
1810
|
+
{ command: "rig task list", description: "List tasks from the selected task source/server." },
|
|
1811
|
+
{ command: "rig task next", description: "Show the next matching task as a selected-task card." },
|
|
1812
|
+
{ command: "rig task show <id>", description: "Show a human task summary; add --raw or --json for the full payload." },
|
|
1813
|
+
{ command: "rig task run <id|--next> [--detach]", description: "Submit a task run; interactive mode follows with bundled Pi." }
|
|
1814
|
+
]
|
|
1815
|
+
},
|
|
1816
|
+
{
|
|
1817
|
+
title: "Runs",
|
|
1818
|
+
subtitle: "observe, attach to, and stop live or recent runs",
|
|
1819
|
+
commands: [
|
|
1820
|
+
{ command: "rig run list", description: "List recent runs from the selected server or local state." },
|
|
1821
|
+
{ command: "rig run show <id>", description: "Show a human run summary; add --raw or --json for the full payload." },
|
|
1822
|
+
{ command: "rig run attach <id> --follow", description: "Open the native bundled Pi live view for a worker run." },
|
|
1823
|
+
{ command: "rig run stop <id>", description: "Request cancellation for a running worker." }
|
|
1824
|
+
]
|
|
1825
|
+
},
|
|
1826
|
+
{
|
|
1827
|
+
title: "Review / inbox",
|
|
1828
|
+
subtitle: "clear blocked runs and configure completion review",
|
|
1829
|
+
commands: [
|
|
1830
|
+
{ command: "rig inbox approvals", description: "List pending approval requests from local/server run state." },
|
|
1831
|
+
{ command: "rig inbox inputs", description: "List pending user-input requests from local/server run state." },
|
|
1832
|
+
{ command: "rig review show|set", description: "Inspect or change the review gate policy." }
|
|
1833
|
+
]
|
|
1834
|
+
},
|
|
1835
|
+
{
|
|
1836
|
+
title: "Health / setup",
|
|
1837
|
+
subtitle: "bootstrap and diagnose the repo/server/GitHub/Pi path",
|
|
1838
|
+
commands: [
|
|
1839
|
+
{ command: "rig init", description: "Interactive setup: config, GitHub auth, task source, server, checkout, Pi." },
|
|
1840
|
+
{ command: "rig doctor", description: "Diagnose project/server/GitHub/task/Pi wiring." },
|
|
1841
|
+
{ command: "rig github auth status", description: "Show GitHub auth state on the selected Rig server." }
|
|
1842
|
+
]
|
|
1843
|
+
}
|
|
1844
|
+
];
|
|
1845
|
+
var PRIMARY_GROUPS = [
|
|
1846
|
+
{
|
|
1847
|
+
name: "server",
|
|
1848
|
+
summary: "Choose, inspect, and start the Rig server that owns tasks and runs.",
|
|
1849
|
+
usage: ["rig server <status|list|add|use|start> [options]"],
|
|
1850
|
+
commands: [
|
|
1851
|
+
{ command: "status", description: "Show the selected server for this repo.", primary: true },
|
|
1852
|
+
{ command: "use local", description: "Switch this repo to the local Rig server.", primary: true },
|
|
1853
|
+
{ command: "add <alias> <url>", description: "Save a remote Rig server URL.", primary: true },
|
|
1854
|
+
{ command: "use <alias>", description: "Select a saved remote server alias.", primary: true },
|
|
1855
|
+
{ command: "list", description: "List saved local/remote server aliases.", primary: true },
|
|
1856
|
+
{ command: "start [--host <host>] [--port <n>]", description: "Start a local rig-server process." }
|
|
1857
|
+
],
|
|
1858
|
+
examples: [
|
|
1859
|
+
"rig server status",
|
|
1860
|
+
"rig server add prod https://where.rig-does.work",
|
|
1861
|
+
"rig server use prod",
|
|
1862
|
+
"rig server use local",
|
|
1863
|
+
"rig server start --port 3773"
|
|
1864
|
+
],
|
|
1865
|
+
next: ["Use `rig task list` to see server-owned work.", "Use `rig run list` or `rig run attach <id> --follow` to monitor runs."],
|
|
1866
|
+
advanced: ["Compatibility alias: `rig connect ...` remains callable."]
|
|
1867
|
+
},
|
|
1868
|
+
{
|
|
1869
|
+
name: "task",
|
|
1870
|
+
summary: "Find work, start Pi-backed runs, and validate task results.",
|
|
1871
|
+
usage: ["rig task <list|next|show|run> [options]"],
|
|
1872
|
+
commands: [
|
|
1873
|
+
{ command: "list [--assignee <login|@me>] [--state open|closed]", description: "List tasks from the selected server/source.", primary: true },
|
|
1874
|
+
{ command: "next [filters]", description: "Render the next matching task as a selected-task card.", primary: true },
|
|
1875
|
+
{ command: "show <id>|--task <id> [--raw]", description: "Show a human task summary; --raw prints the full payload.", primary: true },
|
|
1876
|
+
{ command: "run [#<issue>|<task-id>|--next|--task <id>]", description: "Submit a task run; interactive follows with bundled Pi.", primary: true },
|
|
1877
|
+
{ command: "validate|verify [--task <id>]", description: "Run configured task checks/review gates." },
|
|
1878
|
+
{ command: "details --task <id>", description: "Show full task info from the configured source." },
|
|
1879
|
+
{ command: "reopen [--task <id> | --all] [--reason <text>]", description: "Reopen closed task(s) in the configured source." },
|
|
1880
|
+
{ command: "reset --task <id>", description: "Compatibility spelling of `reopen --task <id>`." },
|
|
1881
|
+
{ command: "artifacts|artifact-dir|artifact-write", description: "Inspect or write task artifacts." },
|
|
1882
|
+
{ command: "report-bug", description: "Create a structured bug report/task." }
|
|
1883
|
+
],
|
|
1884
|
+
examples: [
|
|
1885
|
+
"rig task list --assignee @me --limit 20",
|
|
1886
|
+
"rig task next",
|
|
1887
|
+
"rig task show 123 --raw",
|
|
1888
|
+
"rig task run --next",
|
|
1889
|
+
"rig task run #123 --runtime-adapter pi",
|
|
1890
|
+
"rig task run --title 'Investigate deploy drift' --initial-prompt 'Check server health'"
|
|
1891
|
+
],
|
|
1892
|
+
next: ["Use `--detach` to submit without attaching.", "Use `rig run attach <run-id> --follow` to rejoin a live run."]
|
|
1893
|
+
},
|
|
1894
|
+
{
|
|
1895
|
+
name: "run",
|
|
1896
|
+
summary: "Observe, attach to, and control Rig runs.",
|
|
1897
|
+
usage: ["rig run <list|status|show|attach|stop> [options]"],
|
|
1898
|
+
commands: [
|
|
1899
|
+
{ command: "list", description: "List recent runs from the selected server or local state.", primary: true },
|
|
1900
|
+
{ command: "status", description: "Render active and recent run groups.", primary: true },
|
|
1901
|
+
{ command: "show <id>|--run <id> [--raw]", description: "Show a human run summary; --raw prints the full payload.", primary: true },
|
|
1902
|
+
{ command: "attach <run-id>|--run <id> [--follow]", description: "Attach to the run; --follow launches native bundled Pi for live Pi runs.", primary: true },
|
|
1903
|
+
{ command: "stop [<run-id>|--run <id>]", description: "Request stop for one run or local active runs.", primary: true },
|
|
1904
|
+
{ command: "timeline --run <id> [--follow]", description: "Stream raw run timeline events." },
|
|
1905
|
+
{ command: "resume", description: "Resume the most recent interrupted local run." },
|
|
1906
|
+
{ command: "restart", description: "Restart the most recent local run from a clean runtime." },
|
|
1907
|
+
{ command: "delete|cleanup", description: "Remove completed run records/artifacts." }
|
|
1908
|
+
],
|
|
1909
|
+
examples: [
|
|
1910
|
+
"rig run list",
|
|
1911
|
+
"rig run status",
|
|
1912
|
+
"rig run show <run-id>",
|
|
1913
|
+
"rig run attach <run-id> --follow",
|
|
1914
|
+
"rig run stop <run-id>"
|
|
1915
|
+
],
|
|
1916
|
+
next: ["Use `rig task run --next` to create a new run.", "Use `--json` when scripts need the full structured record."]
|
|
1917
|
+
},
|
|
1918
|
+
{
|
|
1919
|
+
name: "inbox",
|
|
1920
|
+
summary: "Review approval and user-input requests that block worker runs.",
|
|
1921
|
+
usage: ["rig inbox <approvals|approve|inputs|respond> [options]"],
|
|
1922
|
+
commands: [
|
|
1923
|
+
{ command: "approvals [--run <id>] [--task <id>]", description: "List pending approvals.", primary: true },
|
|
1924
|
+
{ command: "inputs [--run <id>] [--task <id>]", description: "List pending user-input requests.", primary: true },
|
|
1925
|
+
{ command: "approve --run <id> --request <id> --decision approve|reject", description: "Resolve an approval request." },
|
|
1926
|
+
{ command: "respond --run <id> --request <id> --answer key=value", description: "Answer a user-input request." }
|
|
1927
|
+
],
|
|
1928
|
+
examples: [
|
|
1929
|
+
"rig inbox approvals",
|
|
1930
|
+
"rig inbox inputs --run <run-id>",
|
|
1931
|
+
"rig inbox approve --run <run-id> --request <request-id> --decision approve"
|
|
1932
|
+
],
|
|
1933
|
+
next: ["Rejoin the run after resolving a block: `rig run attach <run-id> --follow`."]
|
|
1934
|
+
},
|
|
1935
|
+
{
|
|
1936
|
+
name: "review",
|
|
1937
|
+
summary: "Inspect or change completion review gate policy.",
|
|
1938
|
+
usage: ["rig review <show|set>"],
|
|
1939
|
+
commands: [
|
|
1940
|
+
{ command: "show", description: "Show current review gate settings.", primary: true },
|
|
1941
|
+
{ command: "set <off|advisory|required> [--provider greptile]", description: "Change review strictness/provider.", primary: true }
|
|
1942
|
+
],
|
|
1943
|
+
examples: ["rig review show", "rig review set required --provider greptile"],
|
|
1944
|
+
next: ["Use `rig inbox approvals` for blocked run handoffs."]
|
|
1945
|
+
},
|
|
1946
|
+
{
|
|
1947
|
+
name: "init",
|
|
1948
|
+
summary: "Set up Rig for this repo: server, GitHub auth, checkout strategy, task source, and Pi wiring.",
|
|
1949
|
+
usage: ["rig init [--yes] [--server local|remote] [--repo owner/repo] [--remote-url <url>]"],
|
|
1950
|
+
commands: [
|
|
1951
|
+
{ command: "init", description: "Interactive setup wizard for a new or existing Rig repo.", primary: true },
|
|
1952
|
+
{ command: "init --yes", description: "Non-interactive setup using detected/default settings.", primary: true },
|
|
1953
|
+
{ command: "init --server remote --remote-url <url>", description: "Link this repo to a remote Rig server.", primary: true },
|
|
1954
|
+
{ command: "init --repair", description: "Repair missing private state without replacing project config." }
|
|
1955
|
+
],
|
|
1956
|
+
examples: [
|
|
1957
|
+
"rig init",
|
|
1958
|
+
"rig init --yes --repo humanity-org/humanwork",
|
|
1959
|
+
"rig init --server remote --remote-url https://where.rig-does.work --repo owner/repo"
|
|
1960
|
+
],
|
|
1961
|
+
next: ["After init, run `rig server status`.", "Then use `rig task list` and `rig task run --next` for day-to-day work."]
|
|
1962
|
+
},
|
|
1963
|
+
{
|
|
1964
|
+
name: "doctor",
|
|
1965
|
+
summary: "Diagnostics for project/server/GitHub/Pi state.",
|
|
1966
|
+
usage: ["rig doctor"],
|
|
1967
|
+
commands: [
|
|
1968
|
+
{ command: "doctor", description: "Run setup and runtime diagnostics.", primary: true },
|
|
1969
|
+
{ command: "check", description: "Compatibility spelling for diagnostics." }
|
|
1970
|
+
],
|
|
1971
|
+
examples: ["rig doctor", "rig doctor --json"],
|
|
1972
|
+
next: ["Use `rig server status` and `rig github auth status` to inspect common failure points."]
|
|
1973
|
+
},
|
|
1974
|
+
{
|
|
1975
|
+
name: "github",
|
|
1976
|
+
summary: "GitHub auth helpers for the selected Rig server.",
|
|
1977
|
+
usage: ["rig github auth <status|import-gh|token>"],
|
|
1978
|
+
commands: [
|
|
1979
|
+
{ command: "auth status", description: "Show GitHub auth state.", primary: true },
|
|
1980
|
+
{ command: "auth import-gh", description: "Import the current `gh` token into the selected server." },
|
|
1981
|
+
{ command: "auth token --token <token>", description: "Store a token on the selected server." }
|
|
1982
|
+
],
|
|
1983
|
+
examples: ["rig github auth status", "rig github auth import-gh"],
|
|
1984
|
+
next: ["After auth is valid, use `rig task run --next`."]
|
|
1985
|
+
}
|
|
1986
|
+
];
|
|
1987
|
+
var ADVANCED_GROUPS = [
|
|
1988
|
+
{ 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." }] },
|
|
1989
|
+
{ name: "setup", summary: "Bootstrap/check local setup.", usage: ["rig setup <bootstrap|check|preflight>"], commands: [{ command: "bootstrap|check|preflight", description: "Setup helpers." }] },
|
|
1990
|
+
{ name: "inspect", summary: "Inspect logs, artifacts, graphs, failures.", usage: ["rig inspect <logs|artifacts|failures|graph|audit|diff>"], commands: [{ command: "logs --task <id>", description: "Inspect task logs." }] },
|
|
1991
|
+
{ name: "repo", summary: "Repository sync/baseline helpers.", usage: ["rig repo <sync|reset-baseline>"], commands: [{ command: "sync", description: "Sync project repository state." }] },
|
|
1992
|
+
{ name: "profile", summary: "Runtime profile/model defaults.", usage: ["rig profile <show|set>"], commands: [{ command: "show", description: "Show active profile." }] },
|
|
1993
|
+
{
|
|
1994
|
+
name: "browser",
|
|
1995
|
+
summary: "Browser/app diagnostics for browser-required tasks.",
|
|
1996
|
+
usage: ["rig browser <help|explain|demo|app|hp-next> [options]"],
|
|
1997
|
+
commands: [
|
|
1998
|
+
{ command: "help", description: "Rich browser command help (canonical: `rig browser help`)." },
|
|
1999
|
+
{ command: "explain", description: "Explain the browser-required task contract." },
|
|
2000
|
+
{ command: "demo", description: "Run browser demo flows against a local page." },
|
|
2001
|
+
{ command: "app", description: "Launch the Rig Browser workstation app." },
|
|
2002
|
+
{ command: "hp-next <dev|check|e2e|reset>", description: "Drive the hp-next browser test harness." }
|
|
2003
|
+
]
|
|
2004
|
+
},
|
|
2005
|
+
{
|
|
2006
|
+
name: "plugin",
|
|
2007
|
+
summary: "Plugin listing, validation, and plugin-contributed commands.",
|
|
2008
|
+
usage: ["rig plugin <list|validate|run> [options]"],
|
|
2009
|
+
commands: [
|
|
2010
|
+
{ command: "list", description: "List plugins declared in rig.config.ts and their contributions." },
|
|
2011
|
+
{ command: "validate --task <id>", description: "Run plugin-contributed validators for a task." },
|
|
2012
|
+
{ command: "run <command-id> [args...]", description: "Execute a plugin-contributed CLI command (also callable as `rig <command-id>`)." }
|
|
2013
|
+
]
|
|
2014
|
+
},
|
|
2015
|
+
{ name: "queue", summary: "Run task queues locally.", usage: ["rig queue run [options]"], commands: [{ command: "run", description: "Process queue work." }] },
|
|
2016
|
+
{ name: "agent", summary: "Runtime agent workspace helpers.", usage: ["rig agent <list|prepare|run|cleanup>"], commands: [{ command: "list", description: "List prepared agents." }] },
|
|
2017
|
+
{ name: "inspector", summary: "Event stream and drift scanners.", usage: ["rig inspector <stream|scan-upstream-drift>"], commands: [{ command: "stream", description: "Stream events." }] },
|
|
2018
|
+
{ name: "dist", summary: "Build/install packaged Rig CLI.", usage: ["rig dist <build|install|doctor>"], commands: [{ command: "build", description: "Build distribution." }] },
|
|
2019
|
+
{ name: "workspace", summary: "Workspace topology/service helpers.", usage: ["rig workspace <summary|topology|remote-hosts>"], commands: [{ command: "summary", description: "Show workspace summary." }] },
|
|
2020
|
+
{ name: "remote", summary: "Compatibility remote orchestration controls.", usage: ["rig remote <status|watch|pause|resume|...>"], commands: [{ command: "status", description: "Show remote state." }] },
|
|
2021
|
+
{ name: "git", summary: "Pass through to Rig git-flow helper.", usage: ["rig git <args...>"], commands: [{ command: "<args...>", description: "Advanced git flow operations." }] },
|
|
2022
|
+
{ name: "harness", summary: "Pass through to runtime harness CLI.", usage: ["rig harness <args...>"], commands: [{ command: "<args...>", description: "Advanced harness operations." }] },
|
|
2023
|
+
{ name: "test", summary: "Project test wrappers.", usage: ["rig test <unit|e2e|all>"], commands: [{ command: "all", description: "Run configured project tests." }] }
|
|
2024
|
+
];
|
|
2025
|
+
var ALL_GROUPS = [...PRIMARY_GROUPS, ...ADVANCED_GROUPS];
|
|
2026
|
+
function heading(title) {
|
|
2027
|
+
return pc2.bold(pc2.cyan(title));
|
|
2028
|
+
}
|
|
2029
|
+
function commandLine(command, description) {
|
|
2030
|
+
const commandColumn = command.length >= 38 ? `${command} ` : command.padEnd(38);
|
|
2031
|
+
return `${pc2.dim("\u2502")} ${pc2.bold(commandColumn)} ${description}`;
|
|
2032
|
+
}
|
|
2033
|
+
function renderCommandBlock(commands) {
|
|
2034
|
+
return commands.map((entry) => commandLine(entry.command, entry.description)).join(`
|
|
2035
|
+
`);
|
|
2036
|
+
}
|
|
2037
|
+
function renderGroup(group) {
|
|
2038
|
+
const lines = [
|
|
2039
|
+
`${heading(`rig ${group.name}`)} \u2014 ${group.summary}`,
|
|
2040
|
+
"",
|
|
2041
|
+
pc2.bold("Usage"),
|
|
2042
|
+
...group.usage.map((line) => ` ${line}`),
|
|
2043
|
+
"",
|
|
2044
|
+
pc2.bold("Commands"),
|
|
2045
|
+
...group.commands.map((entry) => commandLine(entry.command, entry.description))
|
|
2046
|
+
];
|
|
2047
|
+
if (group.examples?.length) {
|
|
2048
|
+
lines.push("", pc2.bold("Examples"), ...group.examples.map((line) => ` ${pc2.dim("$")} ${line}`));
|
|
2049
|
+
}
|
|
2050
|
+
if (group.next?.length) {
|
|
2051
|
+
lines.push("", pc2.bold("Next steps"), ...group.next.map((line) => ` ${pc2.dim("\u203A")} ${line}`));
|
|
2052
|
+
}
|
|
2053
|
+
if (group.advanced?.length) {
|
|
2054
|
+
lines.push("", pc2.bold("Compatibility / advanced"), ...group.advanced.map((line) => ` ${pc2.dim("\u203A")} ${line}`));
|
|
2055
|
+
}
|
|
2056
|
+
return lines.join(`
|
|
2057
|
+
`);
|
|
2058
|
+
}
|
|
2059
|
+
function renderTopLevelHelp() {
|
|
2060
|
+
return [
|
|
2061
|
+
`${heading("rig")} ${pc2.dim("\u2014 server-owned task/run control plane for Pi-backed engineering work")}`,
|
|
2062
|
+
pc2.dim("Current path: select a server, choose a task, submit a run, attach with native Pi, clear inbox/review gates."),
|
|
2063
|
+
"",
|
|
2064
|
+
...TOP_LEVEL_SECTIONS.flatMap((section) => [
|
|
2065
|
+
`${pc2.bold(pc2.magenta(`\u25C7 ${section.title}`))} \u2014 ${pc2.dim(section.subtitle)}`,
|
|
2066
|
+
renderCommandBlock(section.commands),
|
|
2067
|
+
""
|
|
2068
|
+
]),
|
|
2069
|
+
pc2.dim("More: `rig help --advanced` for dev/compatibility commands; `rig <group> --help` for rich per-group help; `rig --version` for the installed version."),
|
|
2070
|
+
"",
|
|
2071
|
+
pc2.bold("Global options"),
|
|
2072
|
+
commandLine("--project <path>", "Use a project root instead of auto-discovery."),
|
|
2073
|
+
commandLine("--json", "Emit structured output for scripts/agents."),
|
|
2074
|
+
commandLine("--dry-run", "Print the command plan without mutating state.")
|
|
2075
|
+
].join(`
|
|
2076
|
+
`).trimEnd();
|
|
2077
|
+
}
|
|
2078
|
+
function renderGroupHelp(groupName) {
|
|
2079
|
+
const group = ALL_GROUPS.find((candidate) => candidate.name === groupName);
|
|
2080
|
+
return group ? renderGroup(group) : null;
|
|
2081
|
+
}
|
|
2082
|
+
function shouldUseClackOutput2() {
|
|
2083
|
+
return Boolean(process.stdout.isTTY) && process.env.RIG_CLI_PLAIN_HELP !== "1";
|
|
2084
|
+
}
|
|
2085
|
+
function printTopLevelHelp() {
|
|
2086
|
+
if (!shouldUseClackOutput2()) {
|
|
2087
|
+
console.log(renderTopLevelHelp());
|
|
2088
|
+
return;
|
|
2089
|
+
}
|
|
2090
|
+
intro("rig");
|
|
2091
|
+
for (const section of TOP_LEVEL_SECTIONS) {
|
|
2092
|
+
note2(renderCommandBlock(section.commands), `${section.title} \u2014 ${section.subtitle}`);
|
|
2093
|
+
}
|
|
2094
|
+
log2.info("More: rig help --advanced \xB7 rig <group> --help \xB7 rig --version");
|
|
2095
|
+
note2([
|
|
2096
|
+
commandLine("--project <path>", "Use a project root instead of auto-discovery."),
|
|
2097
|
+
commandLine("--json", "Emit structured output for scripts/agents."),
|
|
2098
|
+
commandLine("--dry-run", "Print the command plan without mutating state.")
|
|
2099
|
+
].join(`
|
|
2100
|
+
`), "Global options");
|
|
2101
|
+
outro("Server \u2192 task \u2192 run \u2192 inbox/review.");
|
|
2102
|
+
}
|
|
2103
|
+
function printGroupHelpDocument(groupName) {
|
|
2104
|
+
const rendered = renderGroupHelp(groupName) ?? renderTopLevelHelp();
|
|
2105
|
+
if (!shouldUseClackOutput2()) {
|
|
2106
|
+
console.log(rendered);
|
|
2107
|
+
return;
|
|
2108
|
+
}
|
|
2109
|
+
const group = ALL_GROUPS.find((candidate) => candidate.name === groupName);
|
|
2110
|
+
if (!group) {
|
|
2111
|
+
printTopLevelHelp();
|
|
2112
|
+
return;
|
|
2113
|
+
}
|
|
2114
|
+
intro(`rig ${group.name}`);
|
|
2115
|
+
note2(group.summary, "Purpose");
|
|
2116
|
+
note2(group.usage.join(`
|
|
2117
|
+
`), "Usage");
|
|
2118
|
+
note2(group.commands.map((entry) => commandLine(entry.command, entry.description)).join(`
|
|
2119
|
+
`), "Commands");
|
|
2120
|
+
if (group.examples?.length)
|
|
2121
|
+
note2(group.examples.map((line) => `$ ${line}`).join(`
|
|
2122
|
+
`), "Examples");
|
|
2123
|
+
if (group.next?.length)
|
|
2124
|
+
note2(group.next.map((line) => `\u203A ${line}`).join(`
|
|
2125
|
+
`), "Next steps");
|
|
2126
|
+
if (group.advanced?.length)
|
|
2127
|
+
log2.info(group.advanced.join(`
|
|
2128
|
+
`));
|
|
2129
|
+
outro("Run with --json when scripts need structured output.");
|
|
2130
|
+
}
|
|
2131
|
+
|
|
852
2132
|
// packages/cli/src/commands/task.ts
|
|
853
2133
|
import { buildPluginHostContext } from "@rig/runtime/control-plane/plugin-host-context";
|
|
854
2134
|
import { loadConfig } from "@rig/core/load-config";
|
|
@@ -924,7 +2204,7 @@ function normalizePrMode(value) {
|
|
|
924
2204
|
throw new CliError2("--pr must be auto, ask, or off.", 2);
|
|
925
2205
|
}
|
|
926
2206
|
function detectLocalDirtyState(projectRoot) {
|
|
927
|
-
const result =
|
|
2207
|
+
const result = spawnSync("git", ["-C", projectRoot, "status", "--porcelain"], { encoding: "utf8", timeout: 5000 });
|
|
928
2208
|
if (result.status !== 0)
|
|
929
2209
|
return { dirty: false, modified: 0, untracked: 0, lines: [] };
|
|
930
2210
|
const lines = result.stdout.split(/\r?\n/).map((line) => line.trimEnd()).filter(Boolean);
|
|
@@ -958,13 +2238,15 @@ async function resolveDirtyBaselineForTaskRun(context, explicit) {
|
|
|
958
2238
|
if (explicit)
|
|
959
2239
|
return { mode: explicit, state };
|
|
960
2240
|
if (context.outputMode === "text" && process.stdin.isTTY && process.stdout.isTTY) {
|
|
961
|
-
const
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
2241
|
+
const answer = await confirm({
|
|
2242
|
+
message: "Include current uncommitted changes in run baseline?",
|
|
2243
|
+
initialValue: false
|
|
2244
|
+
});
|
|
2245
|
+
if (isCancel2(answer)) {
|
|
2246
|
+
cancel2("Run cancelled.");
|
|
2247
|
+
throw new CliError2("Run cancelled by user.", 1);
|
|
967
2248
|
}
|
|
2249
|
+
return { mode: answer ? "dirty-snapshot" : "head", state };
|
|
968
2250
|
}
|
|
969
2251
|
return { mode: "head", state };
|
|
970
2252
|
}
|
|
@@ -998,38 +2280,30 @@ function summarizeTask(task, options = {}) {
|
|
|
998
2280
|
...options.raw ? { raw: raw ?? task } : {}
|
|
999
2281
|
};
|
|
1000
2282
|
}
|
|
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
2283
|
async function validatorRegistryForTaskCommands(projectRoot) {
|
|
1008
2284
|
return buildPluginHostContext(projectRoot).then((ctx) => ctx?.validatorRegistry ?? undefined).catch(() => {
|
|
1009
2285
|
return;
|
|
1010
2286
|
});
|
|
1011
2287
|
}
|
|
1012
2288
|
async function executeTask(context, args, options) {
|
|
1013
|
-
|
|
2289
|
+
if (args.length === 0) {
|
|
2290
|
+
if (context.outputMode === "text") {
|
|
2291
|
+
printGroupHelpDocument("task");
|
|
2292
|
+
}
|
|
2293
|
+
return { ok: true, group: "task", command: "help" };
|
|
2294
|
+
}
|
|
2295
|
+
const [command = "help", ...rest] = args;
|
|
1014
2296
|
switch (command) {
|
|
1015
2297
|
case "list": {
|
|
1016
2298
|
let pending = rest;
|
|
1017
2299
|
const rawResult = takeFlag(pending, "--raw");
|
|
1018
2300
|
pending = rawResult.rest;
|
|
1019
2301
|
const { filters, rest: remaining } = parseTaskFilters(pending);
|
|
1020
|
-
requireNoExtraArgs(remaining, "
|
|
2302
|
+
requireNoExtraArgs(remaining, "rig task list [--raw] [--assignee <login|@me>] [--assigned-to <login|me|@me>] [--state open|closed] [--status <status>] [--limit <n>]");
|
|
1021
2303
|
const tasks = await listWorkspaceTasksViaServer(context, filters);
|
|
1022
2304
|
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
|
-
}
|
|
2305
|
+
const renderedTasks = rawResult.value ? tasks.map((task) => summarizeTask(task, { raw: true })) : tasks.map((task) => summarizeTask(task));
|
|
2306
|
+
printFormattedOutput(formatTaskList(renderedTasks, { raw: rawResult.value }));
|
|
1033
2307
|
}
|
|
1034
2308
|
return {
|
|
1035
2309
|
ok: true,
|
|
@@ -1039,30 +2313,34 @@ async function executeTask(context, args, options) {
|
|
|
1039
2313
|
};
|
|
1040
2314
|
}
|
|
1041
2315
|
case "show": {
|
|
1042
|
-
|
|
2316
|
+
let pending = rest;
|
|
2317
|
+
const rawResult = takeFlag(pending, "--raw");
|
|
2318
|
+
pending = rawResult.rest;
|
|
2319
|
+
const taskOption = takeOption(pending, "--task");
|
|
1043
2320
|
const positional = taskOption.rest.length > 0 && taskOption.rest[0] && !taskOption.rest[0].startsWith("-") ? taskOption.rest[0] : undefined;
|
|
1044
2321
|
const remaining = positional ? taskOption.rest.slice(1) : taskOption.rest;
|
|
1045
|
-
requireNoExtraArgs(remaining, "
|
|
1046
|
-
const
|
|
1047
|
-
if (!
|
|
2322
|
+
requireNoExtraArgs(remaining, "rig task show <id>|--task <id> [--raw]");
|
|
2323
|
+
const taskId3 = normalizeTaskRunTaskId(taskOption.value ?? positional);
|
|
2324
|
+
if (!taskId3)
|
|
1048
2325
|
throw new CliError2("task show requires a task id.", 2);
|
|
1049
|
-
const task = await getWorkspaceTaskViaServer(context,
|
|
2326
|
+
const task = await getWorkspaceTaskViaServer(context, taskId3);
|
|
1050
2327
|
if (!task)
|
|
1051
|
-
throw new CliError2(`Task not found: ${
|
|
2328
|
+
throw new CliError2(`Task not found: ${taskId3}`, 3);
|
|
1052
2329
|
const summary = summarizeTask(task, { raw: true });
|
|
1053
|
-
if (context.outputMode === "text")
|
|
1054
|
-
|
|
1055
|
-
|
|
2330
|
+
if (context.outputMode === "text") {
|
|
2331
|
+
printFormattedOutput(rawResult.value ? JSON.stringify(summary, null, 2) : formatTaskDetails(summary));
|
|
2332
|
+
}
|
|
2333
|
+
return { ok: true, group: "task", command, details: { task: summary, raw: rawResult.value } };
|
|
1056
2334
|
}
|
|
1057
2335
|
case "next": {
|
|
1058
2336
|
const { filters, rest: remaining } = parseTaskFilters(rest);
|
|
1059
|
-
requireNoExtraArgs(remaining, "
|
|
2337
|
+
requireNoExtraArgs(remaining, "rig task next [--assignee <login|@me>] [--assigned-to <login|me|@me>] [--state open|closed] [--status <status>] [--limit <n>]");
|
|
1060
2338
|
const selected = await selectNextWorkspaceTaskViaServer(context, filters);
|
|
1061
2339
|
if (context.outputMode === "text") {
|
|
1062
2340
|
if (selected.task) {
|
|
1063
|
-
|
|
2341
|
+
printFormattedOutput(formatTaskCard(summarizeTask(selected.task, { raw: true }), { title: "Selected task", selected: true }));
|
|
1064
2342
|
} else {
|
|
1065
|
-
|
|
2343
|
+
printFormattedOutput("No matching tasks.\n\nNext\n\u203A Try `rig task list` to inspect available work.\n\u203A Check server: `rig server status`");
|
|
1066
2344
|
}
|
|
1067
2345
|
}
|
|
1068
2346
|
return {
|
|
@@ -1078,31 +2356,31 @@ async function executeTask(context, args, options) {
|
|
|
1078
2356
|
}
|
|
1079
2357
|
case "info": {
|
|
1080
2358
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1081
|
-
requireNoExtraArgs(remaining, "
|
|
2359
|
+
requireNoExtraArgs(remaining, "rig task info [--task <task-id>]");
|
|
1082
2360
|
await withMutedConsole(context.outputMode === "json", () => taskInfo(context.projectRoot, task || undefined));
|
|
1083
2361
|
return { ok: true, group: "task", command, details: { task: task || null } };
|
|
1084
2362
|
}
|
|
1085
2363
|
case "scope": {
|
|
1086
2364
|
const filesFlag = takeFlag(rest, "--files");
|
|
1087
2365
|
const { value: task, rest: remaining } = takeOption(filesFlag.rest, "--task");
|
|
1088
|
-
requireNoExtraArgs(remaining, "
|
|
2366
|
+
requireNoExtraArgs(remaining, "rig task scope [--task <id>] [--files]");
|
|
1089
2367
|
await withMutedConsole(context.outputMode === "json", () => taskScope(context.projectRoot, filesFlag.value, task || undefined));
|
|
1090
2368
|
return { ok: true, group: "task", command, details: { files: filesFlag.value, task: task || null } };
|
|
1091
2369
|
}
|
|
1092
2370
|
case "deps":
|
|
1093
|
-
requireNoExtraArgs(rest, "
|
|
2371
|
+
requireNoExtraArgs(rest, "rig task deps");
|
|
1094
2372
|
await withMutedConsole(context.outputMode === "json", () => taskDeps(context.projectRoot));
|
|
1095
2373
|
return { ok: true, group: "task", command };
|
|
1096
2374
|
case "status":
|
|
1097
|
-
requireNoExtraArgs(rest, "
|
|
2375
|
+
requireNoExtraArgs(rest, "rig task status");
|
|
1098
2376
|
withMutedConsole(context.outputMode === "json", () => taskStatus2(context.projectRoot));
|
|
1099
2377
|
return { ok: true, group: "task", command };
|
|
1100
2378
|
case "artifacts":
|
|
1101
|
-
requireNoExtraArgs(rest, "
|
|
2379
|
+
requireNoExtraArgs(rest, "rig task artifacts");
|
|
1102
2380
|
withMutedConsole(context.outputMode === "json", () => taskArtifacts(context.projectRoot));
|
|
1103
2381
|
return { ok: true, group: "task", command };
|
|
1104
2382
|
case "artifact-dir": {
|
|
1105
|
-
requireNoExtraArgs(rest, "
|
|
2383
|
+
requireNoExtraArgs(rest, "rig task artifact-dir");
|
|
1106
2384
|
const path = taskArtifactDir(context.projectRoot);
|
|
1107
2385
|
if (context.outputMode === "text") {
|
|
1108
2386
|
console.log(path);
|
|
@@ -1111,7 +2389,7 @@ async function executeTask(context, args, options) {
|
|
|
1111
2389
|
}
|
|
1112
2390
|
case "artifact-write": {
|
|
1113
2391
|
if (rest.length < 1) {
|
|
1114
|
-
throw new CliError2(`Usage:
|
|
2392
|
+
throw new CliError2(`Usage: rig task artifact-write <filename> [--file <path>]
|
|
1115
2393
|
` + ` Reads content from stdin (or --file), writes to the active task artifact dir.
|
|
1116
2394
|
` + " Example: echo '...' | rig task artifact-write collection-audit.md");
|
|
1117
2395
|
}
|
|
@@ -1119,12 +2397,12 @@ async function executeTask(context, args, options) {
|
|
|
1119
2397
|
const fileFlag = takeOption(rest.slice(1), "--file");
|
|
1120
2398
|
let content;
|
|
1121
2399
|
if (fileFlag.value) {
|
|
1122
|
-
content =
|
|
2400
|
+
content = readFileSync3(resolve3(context.projectRoot, fileFlag.value), "utf-8");
|
|
1123
2401
|
} else {
|
|
1124
2402
|
content = await readStdin();
|
|
1125
2403
|
}
|
|
1126
2404
|
if (!artifactFilename) {
|
|
1127
|
-
throw new CliError2("Usage:
|
|
2405
|
+
throw new CliError2("Usage: rig task artifact-write <filename> [--file path]");
|
|
1128
2406
|
}
|
|
1129
2407
|
withMutedConsole(context.outputMode === "json", () => taskArtifactWrite(context.projectRoot, artifactFilename, content));
|
|
1130
2408
|
return { ok: true, group: "task", command, details: { filename: artifactFilename } };
|
|
@@ -1133,11 +2411,11 @@ async function executeTask(context, args, options) {
|
|
|
1133
2411
|
return options.executeTaskReportBug(context, rest);
|
|
1134
2412
|
case "lookup": {
|
|
1135
2413
|
if (rest.length !== 1) {
|
|
1136
|
-
throw new CliError2("Usage:
|
|
2414
|
+
throw new CliError2("Usage: rig task lookup <task-id>");
|
|
1137
2415
|
}
|
|
1138
2416
|
const lookupId = rest[0];
|
|
1139
2417
|
if (!lookupId) {
|
|
1140
|
-
throw new CliError2("Usage:
|
|
2418
|
+
throw new CliError2("Usage: rig task lookup <task-id>");
|
|
1141
2419
|
}
|
|
1142
2420
|
const result = taskLookup(context.projectRoot, lookupId);
|
|
1143
2421
|
if (context.outputMode === "text") {
|
|
@@ -1147,17 +2425,17 @@ async function executeTask(context, args, options) {
|
|
|
1147
2425
|
}
|
|
1148
2426
|
case "record": {
|
|
1149
2427
|
if (rest.length < 2) {
|
|
1150
|
-
throw new CliError2("Usage:
|
|
2428
|
+
throw new CliError2("Usage: rig task record <decision|failure> <text>");
|
|
1151
2429
|
}
|
|
1152
2430
|
const type = rest[0];
|
|
1153
2431
|
if (type !== "decision" && type !== "failure") {
|
|
1154
|
-
throw new CliError2("Usage:
|
|
2432
|
+
throw new CliError2("Usage: rig task record <decision|failure> <text>");
|
|
1155
2433
|
}
|
|
1156
2434
|
withMutedConsole(context.outputMode === "json", () => taskRecord(context.projectRoot, type, rest.slice(1).join(" ")));
|
|
1157
2435
|
return { ok: true, group: "task", command, details: { type: rest[0] } };
|
|
1158
2436
|
}
|
|
1159
2437
|
case "ready":
|
|
1160
|
-
requireNoExtraArgs(rest, "
|
|
2438
|
+
requireNoExtraArgs(rest, "rig task ready");
|
|
1161
2439
|
await withMutedConsole(context.outputMode === "json", () => taskReady(context.projectRoot));
|
|
1162
2440
|
return { ok: true, group: "task", command };
|
|
1163
2441
|
case "run": {
|
|
@@ -1194,7 +2472,7 @@ async function executeTask(context, args, options) {
|
|
|
1194
2472
|
if (positionalTaskId) {
|
|
1195
2473
|
pending = pending.slice(1);
|
|
1196
2474
|
}
|
|
1197
|
-
requireNoExtraArgs(pending, "
|
|
2475
|
+
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
2476
|
if (nextResult.value && (taskResult.value || positionalTaskId)) {
|
|
1199
2477
|
throw new CliError2("task run cannot combine --next with an explicit task id.", 2);
|
|
1200
2478
|
}
|
|
@@ -1248,16 +2526,24 @@ async function executeTask(context, args, options) {
|
|
|
1248
2526
|
});
|
|
1249
2527
|
let attachDetails = null;
|
|
1250
2528
|
if (!detachResult.value && context.outputMode === "text") {
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
2529
|
+
printFormattedOutput(formatSubmittedRun({
|
|
2530
|
+
runId: submitted.runId,
|
|
2531
|
+
task: selectedTask ? summarizeTask(selectedTask) : null,
|
|
2532
|
+
runtimeAdapter,
|
|
2533
|
+
runtimeMode: runtimeModeResult.value || projectDefaults.runtimeMode || "full-access",
|
|
2534
|
+
interactionMode: interactionModeResult.value || "default",
|
|
2535
|
+
detached: false
|
|
2536
|
+
}));
|
|
1255
2537
|
attachDetails = await attachRunOperatorView(context, { runId: submitted.runId, follow: true });
|
|
1256
2538
|
} else if (context.outputMode === "text") {
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
2539
|
+
printFormattedOutput(formatSubmittedRun({
|
|
2540
|
+
runId: submitted.runId,
|
|
2541
|
+
task: selectedTask ? summarizeTask(selectedTask) : null,
|
|
2542
|
+
runtimeAdapter,
|
|
2543
|
+
runtimeMode: runtimeModeResult.value || projectDefaults.runtimeMode || "full-access",
|
|
2544
|
+
interactionMode: interactionModeResult.value || "default",
|
|
2545
|
+
detached: true
|
|
2546
|
+
}));
|
|
1261
2547
|
}
|
|
1262
2548
|
return {
|
|
1263
2549
|
ok: true,
|
|
@@ -1281,7 +2567,7 @@ async function executeTask(context, args, options) {
|
|
|
1281
2567
|
}
|
|
1282
2568
|
case "validate": {
|
|
1283
2569
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1284
|
-
requireNoExtraArgs(remaining, "
|
|
2570
|
+
requireNoExtraArgs(remaining, "rig task validate [--task <task-id>]");
|
|
1285
2571
|
if (context.dryRun) {
|
|
1286
2572
|
await context.runCommand(["rig", "task", "validate", ...task ? ["--task", task] : []]);
|
|
1287
2573
|
return { ok: true, group: "task", command, details: { task: task || "active" } };
|
|
@@ -1294,12 +2580,12 @@ async function executeTask(context, args, options) {
|
|
|
1294
2580
|
}
|
|
1295
2581
|
case "verify": {
|
|
1296
2582
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1297
|
-
requireNoExtraArgs(remaining, "
|
|
2583
|
+
requireNoExtraArgs(remaining, "rig task verify [--task <task-id>]");
|
|
1298
2584
|
if (context.dryRun) {
|
|
1299
2585
|
await context.runCommand(["rig", "task", "verify", ...task ? ["--task", task] : []]);
|
|
1300
2586
|
return { ok: true, group: "task", command, details: { task: task || "active" } };
|
|
1301
2587
|
}
|
|
1302
|
-
const ok = await withMutedConsole(context.outputMode === "json", () => taskVerify(context.projectRoot,
|
|
2588
|
+
const ok = await withMutedConsole(context.outputMode === "json", () => taskVerify(context.projectRoot, task || undefined));
|
|
1303
2589
|
if (!ok) {
|
|
1304
2590
|
throw new CliError2(`Verification rejected for ${task || "active task"}.`, 2);
|
|
1305
2591
|
}
|
|
@@ -1307,15 +2593,19 @@ async function executeTask(context, args, options) {
|
|
|
1307
2593
|
}
|
|
1308
2594
|
case "reset": {
|
|
1309
2595
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1310
|
-
requireNoExtraArgs(remaining, "
|
|
1311
|
-
const requiredTask = requireTask(task, "
|
|
1312
|
-
|
|
1313
|
-
|
|
2596
|
+
requireNoExtraArgs(remaining, "rig task reset --task <task-id>");
|
|
2597
|
+
const requiredTask = requireTask(task, "rig task reset --task <task-id>");
|
|
2598
|
+
const summary = withMutedConsole(context.outputMode === "json", () => taskReopen(context.projectRoot, {
|
|
2599
|
+
all: false,
|
|
2600
|
+
taskId: requiredTask,
|
|
2601
|
+
dryRun: false
|
|
2602
|
+
}));
|
|
2603
|
+
return { ok: true, group: "task", command, details: summary };
|
|
1314
2604
|
}
|
|
1315
2605
|
case "details": {
|
|
1316
2606
|
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
1317
|
-
requireNoExtraArgs(remaining, "
|
|
1318
|
-
const requiredTask = requireTask(task, "
|
|
2607
|
+
requireNoExtraArgs(remaining, "rig task details --task <task-id>");
|
|
2608
|
+
const requiredTask = requireTask(task, "rig task details --task <task-id>");
|
|
1319
2609
|
await withMutedConsole(context.outputMode === "json", () => taskInfo(context.projectRoot, requiredTask));
|
|
1320
2610
|
return { ok: true, group: "task", command, details: { task: requiredTask } };
|
|
1321
2611
|
}
|
|
@@ -1323,9 +2613,9 @@ async function executeTask(context, args, options) {
|
|
|
1323
2613
|
const { value: task, rest: rest1 } = takeOption(rest, "--task");
|
|
1324
2614
|
const allFlag = takeFlag(rest1, "--all");
|
|
1325
2615
|
const { rest: remaining } = takeOption(allFlag.rest, "--reason");
|
|
1326
|
-
requireNoExtraArgs(remaining, "
|
|
2616
|
+
requireNoExtraArgs(remaining, "rig task reopen [--task <id> | --all] [--reason <text>]");
|
|
1327
2617
|
if (!allFlag.value && !task) {
|
|
1328
|
-
throw new CliError2("Usage:
|
|
2618
|
+
throw new CliError2("Usage: rig task reopen [--task <id> | --all] [--reason <text>]");
|
|
1329
2619
|
}
|
|
1330
2620
|
const summary = withMutedConsole(context.outputMode === "json", () => taskReopen(context.projectRoot, {
|
|
1331
2621
|
all: allFlag.value,
|