@h-rig/cli 0.0.6-alpha.9 → 0.0.6-alpha.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/bin/build-rig-binaries.d.ts +2 -0
- package/dist/bin/rig.d.ts +2 -0
- package/dist/bin/rig.js +11052 -6668
- package/dist/src/app/board.d.ts +23 -0
- package/dist/src/app/board.js +1786 -0
- package/dist/src/app/drone-ui.d.ts +37 -0
- package/dist/src/app/drone-ui.js +294 -0
- package/dist/src/app/theme.d.ts +47 -0
- package/dist/src/app/theme.js +150 -0
- package/dist/src/commands/_async-ui.d.ts +13 -0
- package/dist/src/commands/_async-ui.js +223 -0
- package/dist/src/commands/_authority-runs.d.ts +22 -0
- package/dist/src/commands/_authority-runs.js +2 -3
- package/dist/src/commands/_cli-format.d.ts +49 -0
- package/dist/src/commands/_cli-format.js +447 -0
- package/dist/src/commands/_connection-state.d.ts +44 -0
- package/dist/src/commands/_connection-state.js +30 -11
- package/dist/src/commands/_doctor-checks.d.ts +52 -0
- package/dist/src/commands/_doctor-checks.js +180 -44
- package/dist/src/commands/_help-catalog.d.ts +51 -0
- package/dist/src/commands/_help-catalog.js +442 -0
- package/dist/src/commands/_json-output.d.ts +11 -0
- package/dist/src/commands/_json-output.js +56 -0
- package/dist/src/commands/_operator-surface.d.ts +34 -0
- package/dist/src/commands/_operator-surface.js +220 -0
- package/dist/src/commands/_operator-view.d.ts +30 -0
- package/dist/src/commands/_operator-view.js +803 -73
- package/dist/src/commands/_parsers.d.ts +15 -0
- package/dist/src/commands/_parsers.js +18 -11
- package/dist/src/commands/_paths.d.ts +11 -0
- package/dist/src/commands/_pi-frontend.d.ts +27 -0
- package/dist/src/commands/_pi-frontend.js +742 -0
- package/dist/src/commands/_pi-install.d.ts +42 -0
- package/dist/src/commands/_pi-install.js +5 -4
- package/dist/src/commands/_policy.d.ts +8 -0
- package/dist/src/commands/_policy.js +12 -5
- package/dist/src/commands/_preflight.d.ts +22 -0
- package/dist/src/commands/_preflight.js +190 -128
- package/dist/src/commands/_probes.d.ts +1 -0
- package/dist/src/commands/_run-driver-helpers.d.ts +99 -0
- package/dist/src/commands/_run-driver-helpers.js +75 -22
- package/dist/src/commands/_run-replay.d.ts +24 -0
- package/dist/src/commands/_run-replay.js +142 -0
- package/dist/src/commands/_server-client.d.ts +186 -0
- package/dist/src/commands/_server-client.js +360 -61
- package/dist/src/commands/_snapshot-upload.d.ts +39 -0
- package/dist/src/commands/_snapshot-upload.js +163 -39
- package/dist/src/commands/_spinner.d.ts +25 -0
- package/dist/src/commands/_spinner.js +65 -0
- package/dist/src/commands/_task-picker.d.ts +9 -0
- package/dist/src/commands/_task-picker.js +172 -19
- package/dist/src/commands/agent.d.ts +3 -0
- package/dist/src/commands/agent.js +39 -20
- package/dist/src/commands/browser.d.ts +65 -0
- package/dist/src/commands/browser.js +334 -51
- package/dist/src/commands/connect.d.ts +7 -0
- package/dist/src/commands/connect.js +272 -33
- package/dist/src/commands/dist.d.ts +28 -0
- package/dist/src/commands/dist.js +19 -12
- package/dist/src/commands/doctor.d.ts +3 -0
- package/dist/src/commands/doctor.js +378 -45
- package/dist/src/commands/github.d.ts +3 -0
- package/dist/src/commands/github.js +375 -53
- package/dist/src/commands/inbox.d.ts +30 -0
- package/dist/src/commands/inbox.js +760 -70
- package/dist/src/commands/init.d.ts +74 -0
- package/dist/src/commands/init.js +963 -119
- package/dist/src/commands/inspect.d.ts +3 -0
- package/dist/src/commands/inspect.js +588 -32
- package/dist/src/commands/inspector.d.ts +3 -0
- package/dist/src/commands/inspector.js +20 -13
- package/dist/src/commands/pi.d.ts +3 -0
- package/dist/src/commands/pi.js +177 -0
- package/dist/src/commands/plugin.d.ts +16 -0
- package/dist/src/commands/plugin.js +95 -27
- package/dist/src/commands/profile-and-review.d.ts +4 -0
- package/dist/src/commands/profile-and-review.js +26 -19
- package/dist/src/commands/queue.d.ts +3 -0
- package/dist/src/commands/queue.js +32 -12
- package/dist/src/commands/remote.d.ts +3 -0
- package/dist/src/commands/remote.js +43 -36
- package/dist/src/commands/repo-git-harness.d.ts +5 -0
- package/dist/src/commands/repo-git-harness.js +22 -15
- package/dist/src/commands/run.d.ts +3 -0
- package/dist/src/commands/run.js +1379 -159
- package/dist/src/commands/server.d.ts +7 -0
- package/dist/src/commands/server.js +502 -57
- package/dist/src/commands/setup.d.ts +16 -0
- package/dist/src/commands/setup.js +390 -63
- package/dist/src/commands/stats.d.ts +12 -0
- package/dist/src/commands/stats.js +1051 -0
- package/dist/src/commands/task-report-bug.d.ts +19 -0
- package/dist/src/commands/task-report-bug.js +260 -62
- package/dist/src/commands/task-run-driver.d.ts +132 -0
- package/dist/src/commands/task-run-driver.js +886 -130
- package/dist/src/commands/task.d.ts +14 -0
- package/dist/src/commands/task.js +1644 -314
- package/dist/src/commands/test.d.ts +3 -0
- package/dist/src/commands/test.js +15 -8
- package/dist/src/commands/workspace.d.ts +3 -0
- package/dist/src/commands/workspace.js +18 -11
- package/dist/src/commands.d.ts +29 -0
- package/dist/src/commands.js +10967 -6637
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +10168 -5787
- package/dist/src/launcher.d.ts +61 -0
- package/dist/src/launcher.js +77 -13
- package/dist/src/report-bug.d.ts +44 -0
- package/dist/src/report-bug.js +3 -3
- package/dist/src/runner.d.ts +47 -0
- package/dist/src/runner.js +16 -22
- package/dist/src/withMutedConsole.d.ts +2 -0
- package/package.json +13 -6
|
@@ -0,0 +1,1051 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/cli/src/commands/stats.ts
|
|
3
|
+
import pc4 from "picocolors";
|
|
4
|
+
|
|
5
|
+
// packages/cli/src/runner.ts
|
|
6
|
+
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
7
|
+
import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
|
|
8
|
+
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
9
|
+
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
10
|
+
|
|
11
|
+
class CliError extends RuntimeCliError {
|
|
12
|
+
hint;
|
|
13
|
+
constructor(message, exitCode = 1, options = {}) {
|
|
14
|
+
super(message, exitCode);
|
|
15
|
+
if (options.hint?.trim()) {
|
|
16
|
+
this.hint = options.hint.trim();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function takeOption(args, option) {
|
|
21
|
+
const rest = [];
|
|
22
|
+
let value;
|
|
23
|
+
for (let index = 0;index < args.length; index += 1) {
|
|
24
|
+
const current = args[index];
|
|
25
|
+
if (current === option) {
|
|
26
|
+
const next = args[index + 1];
|
|
27
|
+
if (!next || next.startsWith("-")) {
|
|
28
|
+
throw new CliError(`Missing value for ${option}`, 1, { hint: `Provide a value after ${option}, e.g. \`${option} <value>\`.` });
|
|
29
|
+
}
|
|
30
|
+
value = next;
|
|
31
|
+
index += 1;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (current !== undefined) {
|
|
35
|
+
rest.push(current);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { value, rest };
|
|
39
|
+
}
|
|
40
|
+
function requireNoExtraArgs(args, usage) {
|
|
41
|
+
if (args.length > 0) {
|
|
42
|
+
throw new CliError(`Unexpected arguments: ${args.join(" ")}
|
|
43
|
+
Usage: ${usage}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// packages/cli/src/commands/stats.ts
|
|
48
|
+
import { computeRigStats } from "@rig/runtime/control-plane/native/run-stats";
|
|
49
|
+
|
|
50
|
+
// packages/cli/src/commands/_connection-state.ts
|
|
51
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
52
|
+
import { homedir } from "os";
|
|
53
|
+
import { dirname, resolve } from "path";
|
|
54
|
+
function resolveGlobalConnectionsPath(env = process.env) {
|
|
55
|
+
const explicit = env.RIG_CONNECTIONS_FILE?.trim();
|
|
56
|
+
if (explicit)
|
|
57
|
+
return resolve(explicit);
|
|
58
|
+
const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
|
|
59
|
+
if (stateDir)
|
|
60
|
+
return resolve(stateDir, "connections.json");
|
|
61
|
+
return resolve(homedir(), ".rig", "connections.json");
|
|
62
|
+
}
|
|
63
|
+
function resolveRepoConnectionPath(projectRoot) {
|
|
64
|
+
return resolve(projectRoot, ".rig", "state", "connection.json");
|
|
65
|
+
}
|
|
66
|
+
function readJsonFile(path) {
|
|
67
|
+
if (!existsSync(path))
|
|
68
|
+
return null;
|
|
69
|
+
try {
|
|
70
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
71
|
+
} catch (error) {
|
|
72
|
+
throw new CliError(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1, { hint: "Fix or delete that file, then re-select a server with `rig server use <alias|local>`." });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function writeJsonFile(path, value) {
|
|
76
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
77
|
+
writeFileSync(path, `${JSON.stringify(value, null, 2)}
|
|
78
|
+
`, "utf8");
|
|
79
|
+
}
|
|
80
|
+
function normalizeConnection(value) {
|
|
81
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
82
|
+
return null;
|
|
83
|
+
const record = value;
|
|
84
|
+
if (record.kind === "local")
|
|
85
|
+
return { kind: "local", mode: "auto" };
|
|
86
|
+
if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
|
|
87
|
+
const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
|
|
88
|
+
return { kind: "remote", baseUrl };
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
function readGlobalConnections(options = {}) {
|
|
93
|
+
const path = resolveGlobalConnectionsPath(options.env ?? process.env);
|
|
94
|
+
const payload = readJsonFile(path);
|
|
95
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
96
|
+
return { connections: {} };
|
|
97
|
+
}
|
|
98
|
+
const rawConnections = payload.connections;
|
|
99
|
+
const connections = {};
|
|
100
|
+
if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
|
|
101
|
+
for (const [alias, raw] of Object.entries(rawConnections)) {
|
|
102
|
+
const connection = normalizeConnection(raw);
|
|
103
|
+
if (connection)
|
|
104
|
+
connections[alias] = connection;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return { connections };
|
|
108
|
+
}
|
|
109
|
+
function readRepoConnection(projectRoot) {
|
|
110
|
+
const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
|
|
111
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
112
|
+
return null;
|
|
113
|
+
const record = payload;
|
|
114
|
+
const selected = typeof record.selected === "string" ? record.selected.trim() : "";
|
|
115
|
+
if (!selected)
|
|
116
|
+
return null;
|
|
117
|
+
return {
|
|
118
|
+
selected,
|
|
119
|
+
project: typeof record.project === "string" ? record.project : undefined,
|
|
120
|
+
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
|
|
121
|
+
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function writeRepoConnection(projectRoot, state) {
|
|
125
|
+
writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
|
|
126
|
+
}
|
|
127
|
+
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
128
|
+
const repo = readRepoConnection(projectRoot);
|
|
129
|
+
if (!repo)
|
|
130
|
+
return null;
|
|
131
|
+
if (repo.selected === "local")
|
|
132
|
+
return { alias: "local", connection: { kind: "local", mode: "auto" }, serverProjectRoot: repo.serverProjectRoot };
|
|
133
|
+
const global = readGlobalConnections(options);
|
|
134
|
+
const connection = global.connections[repo.selected];
|
|
135
|
+
if (!connection) {
|
|
136
|
+
throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
137
|
+
}
|
|
138
|
+
return { alias: repo.selected, connection, serverProjectRoot: repo.serverProjectRoot };
|
|
139
|
+
}
|
|
140
|
+
function writeRepoServerProjectRoot(projectRoot, serverProjectRoot) {
|
|
141
|
+
const repo = readRepoConnection(projectRoot);
|
|
142
|
+
if (!repo)
|
|
143
|
+
return;
|
|
144
|
+
writeRepoConnection(projectRoot, { ...repo, serverProjectRoot });
|
|
145
|
+
}
|
|
146
|
+
function isRemoteConnectionSelected(projectRoot) {
|
|
147
|
+
return resolveSelectedConnection(projectRoot)?.connection.kind === "remote";
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// packages/cli/src/commands/_server-client.ts
|
|
151
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
152
|
+
import { resolve as resolve2 } from "path";
|
|
153
|
+
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
154
|
+
var scopedGitHubBearerTokens = new Map;
|
|
155
|
+
var serverPhaseListener = null;
|
|
156
|
+
function setServerPhaseListener(listener) {
|
|
157
|
+
const previous = serverPhaseListener;
|
|
158
|
+
serverPhaseListener = listener;
|
|
159
|
+
return previous;
|
|
160
|
+
}
|
|
161
|
+
function reportServerPhase(label) {
|
|
162
|
+
serverPhaseListener?.(label);
|
|
163
|
+
}
|
|
164
|
+
function cleanToken(value) {
|
|
165
|
+
const trimmed = value?.trim();
|
|
166
|
+
return trimmed ? trimmed : null;
|
|
167
|
+
}
|
|
168
|
+
function readPrivateRemoteSessionToken(projectRoot) {
|
|
169
|
+
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
170
|
+
if (!existsSync2(path))
|
|
171
|
+
return null;
|
|
172
|
+
try {
|
|
173
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
174
|
+
return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
|
|
175
|
+
} catch {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function readGitHubBearerTokenForRemote(projectRoot) {
|
|
180
|
+
const scopedKey = resolve2(projectRoot);
|
|
181
|
+
if (scopedGitHubBearerTokens.has(scopedKey))
|
|
182
|
+
return scopedGitHubBearerTokens.get(scopedKey) ?? null;
|
|
183
|
+
const privateSession = readPrivateRemoteSessionToken(projectRoot);
|
|
184
|
+
if (privateSession)
|
|
185
|
+
return privateSession;
|
|
186
|
+
return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
187
|
+
}
|
|
188
|
+
function readStoredGitHubAuthToken(projectRoot) {
|
|
189
|
+
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
190
|
+
if (!existsSync2(path))
|
|
191
|
+
return null;
|
|
192
|
+
try {
|
|
193
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
194
|
+
return cleanToken(typeof parsed.token === "string" ? parsed.token : undefined);
|
|
195
|
+
} catch {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function readLocalConnectionFallbackToken(projectRoot) {
|
|
200
|
+
return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
|
|
201
|
+
}
|
|
202
|
+
async function ensureServerForCli(projectRoot) {
|
|
203
|
+
try {
|
|
204
|
+
const selected = resolveSelectedConnection(projectRoot);
|
|
205
|
+
if (selected?.connection.kind === "remote") {
|
|
206
|
+
reportServerPhase(`Connecting to ${selected.alias}\u2026`);
|
|
207
|
+
const authToken = readGitHubBearerTokenForRemote(projectRoot);
|
|
208
|
+
const serverProjectRoot = selected.serverProjectRoot ?? await backfillRemoteServerProjectRoot(projectRoot, selected.connection.baseUrl, authToken);
|
|
209
|
+
return {
|
|
210
|
+
baseUrl: selected.connection.baseUrl,
|
|
211
|
+
authToken,
|
|
212
|
+
connectionKind: "remote",
|
|
213
|
+
serverProjectRoot
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
reportServerPhase("Starting local Rig server\u2026");
|
|
217
|
+
const connection = await ensureLocalRigServerConnection(projectRoot);
|
|
218
|
+
return {
|
|
219
|
+
baseUrl: connection.baseUrl,
|
|
220
|
+
authToken: connection.authToken ?? readLocalConnectionFallbackToken(projectRoot),
|
|
221
|
+
connectionKind: "local",
|
|
222
|
+
serverProjectRoot: resolve2(projectRoot)
|
|
223
|
+
};
|
|
224
|
+
} catch (error) {
|
|
225
|
+
if (error instanceof Error) {
|
|
226
|
+
throw new CliError(error.message, 1);
|
|
227
|
+
}
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
|
|
232
|
+
const repo = readRepoConnection(projectRoot);
|
|
233
|
+
const slug = repo?.project?.trim();
|
|
234
|
+
if (!slug)
|
|
235
|
+
return null;
|
|
236
|
+
try {
|
|
237
|
+
const response = await fetch(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`, {
|
|
238
|
+
headers: mergeHeaders(undefined, authToken)
|
|
239
|
+
});
|
|
240
|
+
if (!response.ok)
|
|
241
|
+
return null;
|
|
242
|
+
const payload = await response.json();
|
|
243
|
+
const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
|
|
244
|
+
const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
|
|
245
|
+
const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
|
|
246
|
+
const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
|
|
247
|
+
if (path)
|
|
248
|
+
writeRepoServerProjectRoot(projectRoot, path);
|
|
249
|
+
return path;
|
|
250
|
+
} catch {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function mergeHeaders(headers, authToken) {
|
|
255
|
+
const merged = new Headers(headers);
|
|
256
|
+
if (authToken) {
|
|
257
|
+
merged.set("authorization", `Bearer ${authToken}`);
|
|
258
|
+
}
|
|
259
|
+
return merged;
|
|
260
|
+
}
|
|
261
|
+
function diagnosticMessage(payload) {
|
|
262
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
263
|
+
return null;
|
|
264
|
+
const record = payload;
|
|
265
|
+
const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
|
|
266
|
+
const messages = diagnostics.flatMap((entry) => {
|
|
267
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
268
|
+
return [];
|
|
269
|
+
const diagnostic = entry;
|
|
270
|
+
const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
|
|
271
|
+
const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
|
|
272
|
+
return message ? [`${kind}: ${message}`] : [];
|
|
273
|
+
});
|
|
274
|
+
return messages.length > 0 ? messages.join("; ") : null;
|
|
275
|
+
}
|
|
276
|
+
var serverReachabilityCache = new Map;
|
|
277
|
+
async function probeServerReachability(baseUrl, authToken) {
|
|
278
|
+
try {
|
|
279
|
+
const response = await fetch(`${baseUrl.replace(/\/+$/, "")}/api/server/status`, {
|
|
280
|
+
headers: mergeHeaders(undefined, authToken),
|
|
281
|
+
signal: AbortSignal.timeout(1500)
|
|
282
|
+
});
|
|
283
|
+
return response.ok;
|
|
284
|
+
} catch {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function cachedServerReachability(projectRoot, baseUrl, authToken) {
|
|
289
|
+
const key = resolve2(projectRoot);
|
|
290
|
+
const cached = serverReachabilityCache.get(key);
|
|
291
|
+
if (cached)
|
|
292
|
+
return cached;
|
|
293
|
+
const probe = probeServerReachability(baseUrl, authToken);
|
|
294
|
+
serverReachabilityCache.set(key, probe);
|
|
295
|
+
return probe;
|
|
296
|
+
}
|
|
297
|
+
function describeSelectedServer(projectRoot, server) {
|
|
298
|
+
try {
|
|
299
|
+
const selected = resolveSelectedConnection(projectRoot);
|
|
300
|
+
if (selected) {
|
|
301
|
+
return {
|
|
302
|
+
alias: selected.alias,
|
|
303
|
+
target: selected.connection.kind === "remote" ? selected.connection.baseUrl : server.baseUrl
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
} catch {}
|
|
307
|
+
return { alias: server.connectionKind === "remote" ? "remote" : "local", target: server.baseUrl };
|
|
308
|
+
}
|
|
309
|
+
async function buildServerFailureContext(projectRoot, server) {
|
|
310
|
+
const { alias, target } = describeSelectedServer(projectRoot, server);
|
|
311
|
+
const reachable = await cachedServerReachability(projectRoot, server.baseUrl, server.authToken);
|
|
312
|
+
const reachability = reachable ? "server is reachable" : "server is unreachable";
|
|
313
|
+
return {
|
|
314
|
+
contextLine: `Currently connected to: ${alias} at ${target} (${reachability}).`,
|
|
315
|
+
hint: "Check the selected server with `rig server status`, or switch with `rig server use <alias|local>`."
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
async function requestServerJson(context, pathname, init = {}) {
|
|
319
|
+
const server = await ensureServerForCli(context.projectRoot);
|
|
320
|
+
const headers = mergeHeaders(init.headers, server.authToken);
|
|
321
|
+
if (server.serverProjectRoot)
|
|
322
|
+
headers.set("x-rig-project-root", server.serverProjectRoot);
|
|
323
|
+
reportServerPhase(`${(init.method ?? "GET").toUpperCase()} ${pathname.split("?")[0]}\u2026`);
|
|
324
|
+
let response;
|
|
325
|
+
try {
|
|
326
|
+
response = await fetch(`${server.baseUrl}${pathname}`, {
|
|
327
|
+
...init,
|
|
328
|
+
headers
|
|
329
|
+
});
|
|
330
|
+
} catch (error) {
|
|
331
|
+
const failure = await buildServerFailureContext(context.projectRoot, server);
|
|
332
|
+
throw new CliError(`Rig server request failed: ${error instanceof Error ? error.message : String(error)}
|
|
333
|
+
${failure.contextLine}`, 1, { hint: failure.hint });
|
|
334
|
+
}
|
|
335
|
+
const text = await response.text();
|
|
336
|
+
const payload = text.trim().length > 0 ? (() => {
|
|
337
|
+
try {
|
|
338
|
+
return JSON.parse(text);
|
|
339
|
+
} catch {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
})() : null;
|
|
343
|
+
if (!response.ok) {
|
|
344
|
+
const diagnostics = diagnosticMessage(payload);
|
|
345
|
+
const rawDetail = diagnostics ?? (text || response.statusText);
|
|
346
|
+
const detail = diagnostics ? rawDetail : rawDetail.split(`
|
|
347
|
+
`).map((line) => line.trim()).find((line) => line.length > 0)?.slice(0, 200) ?? response.statusText;
|
|
348
|
+
const failure = await buildServerFailureContext(context.projectRoot, server);
|
|
349
|
+
throw new CliError(`Rig server request failed (${response.status}): ${detail}
|
|
350
|
+
${failure.contextLine}`, 1, { hint: failure.hint });
|
|
351
|
+
}
|
|
352
|
+
return payload;
|
|
353
|
+
}
|
|
354
|
+
var RESUMABLE_RUN_STATUSES = new Set([
|
|
355
|
+
"created",
|
|
356
|
+
"preparing",
|
|
357
|
+
"running",
|
|
358
|
+
"validating",
|
|
359
|
+
"reviewing",
|
|
360
|
+
"stopped",
|
|
361
|
+
"failed",
|
|
362
|
+
"needs-attention",
|
|
363
|
+
"needs_attention"
|
|
364
|
+
]);
|
|
365
|
+
|
|
366
|
+
// packages/cli/src/app/drone-ui.ts
|
|
367
|
+
import { ProcessTerminal, TUI, Text, Input, SelectList, matchesKey } from "@earendil-works/pi-tui";
|
|
368
|
+
|
|
369
|
+
// packages/cli/src/app/theme.ts
|
|
370
|
+
var RIG_PALETTE = {
|
|
371
|
+
ink: "#f2f3f6",
|
|
372
|
+
ink2: "#aeb0ba",
|
|
373
|
+
ink3: "#6c6e79",
|
|
374
|
+
ink4: "#44464f",
|
|
375
|
+
accent: "#ccff4d",
|
|
376
|
+
accentDim: "#a9d63f",
|
|
377
|
+
cyan: "#56d8ff",
|
|
378
|
+
red: "#ff5d5d",
|
|
379
|
+
yellow: "#ffd24d"
|
|
380
|
+
};
|
|
381
|
+
function hexToRgb(hex) {
|
|
382
|
+
const value = hex.replace("#", "");
|
|
383
|
+
return [
|
|
384
|
+
Number.parseInt(value.slice(0, 2), 16),
|
|
385
|
+
Number.parseInt(value.slice(2, 4), 16),
|
|
386
|
+
Number.parseInt(value.slice(4, 6), 16)
|
|
387
|
+
];
|
|
388
|
+
}
|
|
389
|
+
function fg(hex) {
|
|
390
|
+
const [r, g, b] = hexToRgb(hex);
|
|
391
|
+
return (text) => `\x1B[38;2;${r};${g};${b}m${text}\x1B[39m`;
|
|
392
|
+
}
|
|
393
|
+
var ink = fg(RIG_PALETTE.ink);
|
|
394
|
+
var ink2 = fg(RIG_PALETTE.ink2);
|
|
395
|
+
var ink3 = fg(RIG_PALETTE.ink3);
|
|
396
|
+
var ink4 = fg(RIG_PALETTE.ink4);
|
|
397
|
+
var accent = fg(RIG_PALETTE.accent);
|
|
398
|
+
var accentDim = fg(RIG_PALETTE.accentDim);
|
|
399
|
+
var cyan = fg(RIG_PALETTE.cyan);
|
|
400
|
+
var red = fg(RIG_PALETTE.red);
|
|
401
|
+
var yellow = fg(RIG_PALETTE.yellow);
|
|
402
|
+
function bold(text) {
|
|
403
|
+
return `\x1B[1m${text}\x1B[22m`;
|
|
404
|
+
}
|
|
405
|
+
var DRONE_ART = [
|
|
406
|
+
" .-=-. .-=-. ",
|
|
407
|
+
" ( !!! ) ( !!! ) ",
|
|
408
|
+
" '-=-'._ _.'-=-' ",
|
|
409
|
+
" '._ _.' ",
|
|
410
|
+
" '=$$$$$$$=.' ",
|
|
411
|
+
" =$$$$$$$$$$$= ",
|
|
412
|
+
" $$$@@@@@@@@@@$$$ ",
|
|
413
|
+
" $$$@@ @@$$$ ",
|
|
414
|
+
" $$@ ? @$$$ ",
|
|
415
|
+
" $$$@ '-' @$$$ ",
|
|
416
|
+
" $$$@@ @@$$$ ",
|
|
417
|
+
" $$$@@@@@@@@@@$$$ ",
|
|
418
|
+
" =$$$$$$$$$$$= ",
|
|
419
|
+
" '=$$$$$$$=.' ",
|
|
420
|
+
" _.' '._ ",
|
|
421
|
+
" .-=-.' '.-=-. ",
|
|
422
|
+
" ( !!! ) ( !!! ) ",
|
|
423
|
+
" '-=-' '-=-' "
|
|
424
|
+
];
|
|
425
|
+
var EYE_FRAMES = ["@", "o", "."];
|
|
426
|
+
var DRONE_WIDTH = DRONE_ART[0].length;
|
|
427
|
+
var DRONE_HEIGHT = DRONE_ART.length;
|
|
428
|
+
var MICRO_BLADES = ["---", "\\\\\\", "|||", "///"];
|
|
429
|
+
function microDroneFrame(tick) {
|
|
430
|
+
const blade = MICRO_BLADES[tick % MICRO_BLADES.length];
|
|
431
|
+
const eye = EYE_FRAMES[Math.floor(tick / 2) % EYE_FRAMES.length];
|
|
432
|
+
return `(${blade})${eye}(${blade})`;
|
|
433
|
+
}
|
|
434
|
+
var MICRO_DRONE_FRAMES = Array.from({ length: 12 }, (_, index) => microDroneFrame(index));
|
|
435
|
+
function renderMicroDroneFrame(tick) {
|
|
436
|
+
const blade = MICRO_BLADES[tick % MICRO_BLADES.length];
|
|
437
|
+
const eye = EYE_FRAMES[Math.floor(tick / 2) % EYE_FRAMES.length];
|
|
438
|
+
return `${ink4("(")}${cyan(blade)}${ink4(")")}${bold(accent(eye))}${ink4("(")}${cyan(blade)}${ink4(")")}`;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// packages/cli/src/commands/_spinner.ts
|
|
442
|
+
var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
443
|
+
function createTtySpinner(input) {
|
|
444
|
+
const output = input.output ?? process.stdout;
|
|
445
|
+
const isTty = output.isTTY === true;
|
|
446
|
+
const frames = input.frames && input.frames.length > 0 ? input.frames : SPINNER_FRAMES;
|
|
447
|
+
let label = input.label;
|
|
448
|
+
let frame = 0;
|
|
449
|
+
let paused = false;
|
|
450
|
+
let stopped = false;
|
|
451
|
+
let lastPrintedLabel = "";
|
|
452
|
+
const render = () => {
|
|
453
|
+
if (stopped || paused)
|
|
454
|
+
return;
|
|
455
|
+
if (!isTty) {
|
|
456
|
+
if (label !== lastPrintedLabel) {
|
|
457
|
+
output.write(`${label}
|
|
458
|
+
`);
|
|
459
|
+
lastPrintedLabel = label;
|
|
460
|
+
}
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
frame = (frame + 1) % frames.length;
|
|
464
|
+
const glyph = frames[frame] ?? frames[0] ?? "";
|
|
465
|
+
output.write(`\r\x1B[2K${input.styleFrame ? input.styleFrame(glyph) : glyph} ${label}`);
|
|
466
|
+
};
|
|
467
|
+
const clearLine = () => {
|
|
468
|
+
if (isTty)
|
|
469
|
+
output.write("\r\x1B[2K");
|
|
470
|
+
};
|
|
471
|
+
render();
|
|
472
|
+
const timer = isTty ? setInterval(render, input.intervalMs ?? 120) : null;
|
|
473
|
+
return {
|
|
474
|
+
setLabel(next) {
|
|
475
|
+
label = next;
|
|
476
|
+
render();
|
|
477
|
+
},
|
|
478
|
+
pause() {
|
|
479
|
+
paused = true;
|
|
480
|
+
clearLine();
|
|
481
|
+
},
|
|
482
|
+
resume() {
|
|
483
|
+
if (stopped)
|
|
484
|
+
return;
|
|
485
|
+
paused = false;
|
|
486
|
+
render();
|
|
487
|
+
},
|
|
488
|
+
stop(finalLine) {
|
|
489
|
+
if (stopped)
|
|
490
|
+
return;
|
|
491
|
+
stopped = true;
|
|
492
|
+
if (timer)
|
|
493
|
+
clearInterval(timer);
|
|
494
|
+
clearLine();
|
|
495
|
+
if (finalLine)
|
|
496
|
+
output.write(`${finalLine}
|
|
497
|
+
`);
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// packages/cli/src/app/drone-ui.ts
|
|
503
|
+
function droneNote(message, title) {
|
|
504
|
+
if (title)
|
|
505
|
+
console.log(` ${accentDim("\u25C7")} ${bold(ink2(title))}`);
|
|
506
|
+
for (const line of message.split(`
|
|
507
|
+
`)) {
|
|
508
|
+
console.log(` ${ink4("\u2502")} ${line}`);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// packages/cli/src/commands/_cli-format.ts
|
|
513
|
+
import pc from "picocolors";
|
|
514
|
+
var themeDim = (value) => ink3(value);
|
|
515
|
+
function shouldUseClackOutput() {
|
|
516
|
+
return Boolean(process.stdout.isTTY) && process.env.RIG_CLI_PLAIN_HELP !== "1";
|
|
517
|
+
}
|
|
518
|
+
function printFormattedOutput(message, options = {}) {
|
|
519
|
+
if (!shouldUseClackOutput()) {
|
|
520
|
+
console.log(message);
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
droneNote(message, options.title);
|
|
524
|
+
}
|
|
525
|
+
function formatSection(title, subtitle) {
|
|
526
|
+
return `${pc.bold(accent("\u25C6"))} ${pc.bold(title)}${subtitle ? themeDim(` \u2014 ${subtitle}`) : ""}`;
|
|
527
|
+
}
|
|
528
|
+
function formatNextSteps(steps) {
|
|
529
|
+
if (steps.length === 0)
|
|
530
|
+
return [];
|
|
531
|
+
return [pc.bold("Next"), ...steps.map((step) => `${accent("\u203A")} ${step}`)];
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// packages/cli/src/commands/_async-ui.ts
|
|
535
|
+
import pc2 from "picocolors";
|
|
536
|
+
var DONE_SYMBOL = pc2.green("\u25C7");
|
|
537
|
+
var FAIL_SYMBOL = pc2.red("\u25A0");
|
|
538
|
+
var activeUpdate = null;
|
|
539
|
+
async function withSpinner(label, work, options = {}) {
|
|
540
|
+
if (options.outputMode === "json") {
|
|
541
|
+
return work(() => {});
|
|
542
|
+
}
|
|
543
|
+
if (activeUpdate) {
|
|
544
|
+
const outer = activeUpdate;
|
|
545
|
+
outer(label);
|
|
546
|
+
return work(outer);
|
|
547
|
+
}
|
|
548
|
+
const output = options.output ?? process.stderr;
|
|
549
|
+
const isTty = output.isTTY === true;
|
|
550
|
+
let lastLabel = label;
|
|
551
|
+
if (!isTty) {
|
|
552
|
+
output.write(`${label}
|
|
553
|
+
`);
|
|
554
|
+
const update2 = (next) => {
|
|
555
|
+
lastLabel = next;
|
|
556
|
+
};
|
|
557
|
+
activeUpdate = update2;
|
|
558
|
+
const previousListener2 = setServerPhaseListener(update2);
|
|
559
|
+
try {
|
|
560
|
+
return await work(update2);
|
|
561
|
+
} finally {
|
|
562
|
+
activeUpdate = null;
|
|
563
|
+
setServerPhaseListener(previousListener2);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
const spinner = createTtySpinner({
|
|
567
|
+
label,
|
|
568
|
+
output,
|
|
569
|
+
frames: MICRO_DRONE_FRAMES,
|
|
570
|
+
styleFrame: (frame) => renderMicroDroneFrame(Math.max(0, MICRO_DRONE_FRAMES.indexOf(frame)))
|
|
571
|
+
});
|
|
572
|
+
const update = (next) => {
|
|
573
|
+
lastLabel = next;
|
|
574
|
+
spinner.setLabel(next);
|
|
575
|
+
};
|
|
576
|
+
activeUpdate = update;
|
|
577
|
+
const previousListener = setServerPhaseListener(update);
|
|
578
|
+
try {
|
|
579
|
+
const result = await work(update);
|
|
580
|
+
spinner.stop(options.doneLabel ? `${DONE_SYMBOL} ${options.doneLabel}` : undefined);
|
|
581
|
+
return result;
|
|
582
|
+
} catch (error) {
|
|
583
|
+
spinner.stop(`${FAIL_SYMBOL} ${lastLabel}`);
|
|
584
|
+
throw error;
|
|
585
|
+
} finally {
|
|
586
|
+
activeUpdate = null;
|
|
587
|
+
setServerPhaseListener(previousListener);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// packages/cli/src/commands/_help-catalog.ts
|
|
592
|
+
import pc3 from "picocolors";
|
|
593
|
+
var TOP_LEVEL_SECTIONS = [
|
|
594
|
+
{
|
|
595
|
+
title: "Pi console",
|
|
596
|
+
subtitle: "the operator surface \u2014 every attach opens the run's FULL Pi session",
|
|
597
|
+
commands: [
|
|
598
|
+
{ command: "rig run attach <run-id>", description: "Open the run's Pi console: complete transcript (live AND finished runs), worker turns streaming in live." },
|
|
599
|
+
{ command: "type a message", description: "Inside the console, plain text steers the worker mid-turn \u2014 it lands in the agent's context, not a local model." },
|
|
600
|
+
{ command: "!<command>", description: "Inside the console, runs shell in the WORKER's workspace; output streams back into the transcript." },
|
|
601
|
+
{ command: "/<command>", description: "The palette includes the WORKER session's slash commands ([worker]-tagged) next to /rig." },
|
|
602
|
+
{ command: "/rig abort | /rig stop", description: "Abort the worker's current turn, or stop the whole run, from inside the console." },
|
|
603
|
+
{ command: "rig run steer <id> --message <text>", description: "Steer without attaching \u2014 queue a message; the worker picks it up within seconds." }
|
|
604
|
+
]
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
title: "Start here",
|
|
608
|
+
subtitle: "one-time setup, pick a server",
|
|
609
|
+
commands: [
|
|
610
|
+
{ command: "rig init", description: "Wizard: config, GitHub auth, task source, server, Pi wiring." },
|
|
611
|
+
{ command: "rig server use <alias|local>", description: "Pick which Rig server owns this repo (`rig server list` to see them)." },
|
|
612
|
+
{ command: "rig server status", description: "Show the selected server for this repo." }
|
|
613
|
+
]
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
title: "Work",
|
|
617
|
+
subtitle: "find a task, put an agent on it, answer what it asks",
|
|
618
|
+
commands: [
|
|
619
|
+
{ command: "rig task list", description: "What's on the board (from the selected source/server)." },
|
|
620
|
+
{ command: "rig task run --next", description: "Dispatch an agent on the next ready task; interactive mode drops you into its Pi console." },
|
|
621
|
+
{ command: "rig run status", description: "Active and recent runs at a glance." },
|
|
622
|
+
{ command: "rig run attach <id> --follow", description: "Same as plain attach \u2014 the Pi console is always the interactive surface." },
|
|
623
|
+
{ command: "rig inbox approvals", description: "Approvals workers are waiting on (then `rig inbox approve \u2026`)." }
|
|
624
|
+
]
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
title: "Watch",
|
|
628
|
+
subtitle: "fleet metrics and per-task forensics",
|
|
629
|
+
commands: [
|
|
630
|
+
{ command: "rig stats [--since 7d]", description: "Fleet metrics: completion/failure rates, median run time, steering, stalls." },
|
|
631
|
+
{ command: "rig inspect logs --task <id>", description: "Latest run log for a task." },
|
|
632
|
+
{ command: "rig inspect diff --task <id>", description: "Changed files for a task." }
|
|
633
|
+
]
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
title: "Unblock",
|
|
637
|
+
subtitle: "diagnose wiring, fix auth",
|
|
638
|
+
commands: [
|
|
639
|
+
{ command: "rig doctor", description: "Check every part of the wiring \u2014 run this when anything feels off." },
|
|
640
|
+
{ command: "rig github auth status", description: "GitHub auth state on the selected server." }
|
|
641
|
+
]
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
title: "Extend",
|
|
645
|
+
subtitle: "plugins contribute validators, hooks, task sources, commands",
|
|
646
|
+
commands: [
|
|
647
|
+
{ command: "rig plugin list", description: "What the rig.config.ts plugins contribute." },
|
|
648
|
+
{ command: "rig plugin run <command-id>", description: "Execute a plugin-contributed CLI command." }
|
|
649
|
+
]
|
|
650
|
+
}
|
|
651
|
+
];
|
|
652
|
+
var PRIMARY_GROUPS = [
|
|
653
|
+
{
|
|
654
|
+
name: "server",
|
|
655
|
+
summary: "Choose, inspect, and start the Rig server that owns tasks and runs.",
|
|
656
|
+
usage: ["rig server <status|list|add|use|start> [options]"],
|
|
657
|
+
commands: [
|
|
658
|
+
{ command: "status", description: "Show the selected server for this repo.", primary: true },
|
|
659
|
+
{ command: "use local", description: "Switch this repo to the local Rig server.", primary: true },
|
|
660
|
+
{ command: "add <alias> <url>", description: "Save a remote Rig server URL.", primary: true },
|
|
661
|
+
{ command: "use <alias>", description: "Select a saved remote server alias.", primary: true },
|
|
662
|
+
{ command: "list", description: "List saved local/remote server aliases.", primary: true },
|
|
663
|
+
{ command: "start [--host <host>] [--port <n>]", description: "Start a local rig-server process." }
|
|
664
|
+
],
|
|
665
|
+
examples: [
|
|
666
|
+
"rig server status",
|
|
667
|
+
"rig server add prod https://where.rig-does.work",
|
|
668
|
+
"rig server use prod",
|
|
669
|
+
"rig server use local",
|
|
670
|
+
"rig server start --port 3773"
|
|
671
|
+
],
|
|
672
|
+
next: ["Use `rig task list` to see server-owned work.", "Use `rig run list` or `rig run attach <id> --follow` to monitor runs."]
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
name: "task",
|
|
676
|
+
summary: "Find work, start Pi-backed runs, and validate task results.",
|
|
677
|
+
usage: ["rig task <list|next|show|run> [options]"],
|
|
678
|
+
commands: [
|
|
679
|
+
{ command: "list [--assignee <login|me|@me>] [--state open|closed]", description: "List tasks from the selected server/source.", primary: true },
|
|
680
|
+
{ command: "next [filters]", description: "Render the next matching task as a selected-task card.", primary: true },
|
|
681
|
+
{ command: "show <id>|--task <id> [--raw]", description: "Show a human task summary; --raw prints the full payload.", primary: true },
|
|
682
|
+
{ command: "run [#<issue>|<task-id>|--next|--task <id>]", description: "Submit a task run; interactive follows with bundled Pi.", primary: true },
|
|
683
|
+
{ command: "ready", description: "List task IDs that are runnable now." },
|
|
684
|
+
{ command: "validate|verify [--task <id>]", description: "Run configured task checks/review gates." },
|
|
685
|
+
{ command: "details --task <id>", description: "Show full task info from the configured source." },
|
|
686
|
+
{ command: "reopen [--task <id> | --all] [--reason <text>]", description: "Reopen closed task(s) in the configured source." },
|
|
687
|
+
{ command: "artifacts|artifact-dir|artifact-write", description: "Inspect or write task artifacts." },
|
|
688
|
+
{ command: "report-bug", description: "Create a structured bug report/task." }
|
|
689
|
+
],
|
|
690
|
+
examples: [
|
|
691
|
+
"rig task list --assignee @me --limit 20",
|
|
692
|
+
"rig task next",
|
|
693
|
+
"rig task show 123 --raw",
|
|
694
|
+
"rig task run --next",
|
|
695
|
+
"rig task run #123 --runtime-adapter pi",
|
|
696
|
+
"rig task run --title 'Investigate deploy drift' --initial-prompt 'Check server health'"
|
|
697
|
+
],
|
|
698
|
+
next: ["Use `--detach` to submit without attaching.", "Use `rig run attach <run-id> --follow` to rejoin a live run."]
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
name: "run",
|
|
702
|
+
summary: "Observe, attach to, and control Rig runs. `attach` opens the Pi console \u2014 the full worker session, live.",
|
|
703
|
+
usage: ["rig run <list|status|show|attach|steer|stop|resume|restart> [options]"],
|
|
704
|
+
commands: [
|
|
705
|
+
{ command: "list", description: "List recent runs from the selected server or local state.", primary: true },
|
|
706
|
+
{ command: "status", description: "Render active and recent run groups.", primary: true },
|
|
707
|
+
{ command: "show <id>|--run <id> [--raw]", description: "Show a human run summary; --raw prints the full payload.", primary: true },
|
|
708
|
+
{ command: "attach <run-id>|--run <id>", description: "Open the run's Pi console \u2014 see 'Inside the console' below. Works on live AND finished runs.", primary: true },
|
|
709
|
+
{ command: "steer <run-id> --message <text>", description: "Queue a steering message into a live worker without attaching \u2014 delivered into the agent's context within seconds.", primary: true },
|
|
710
|
+
{ command: "stop [<run-id>|--run <id>]", description: "Request stop for one run or local active runs.", primary: true },
|
|
711
|
+
{ command: "resume [<run-id>]", description: "Resume an interrupted run on the selected server (defaults to the most recent resumable)." },
|
|
712
|
+
{ command: "restart [<run-id>]", description: "Re-dispatch a run from a clean runtime, reopening its Pi session where possible." },
|
|
713
|
+
{ command: "timeline --run <id> [--follow]", description: "Stream raw run timeline events (scripts; humans should attach)." },
|
|
714
|
+
{ command: "replay <run-id>|--run <id> [--with-session]", description: "Print the run's consolidated run.jsonl as a merged timeline; --with-session interleaves the Pi session log." },
|
|
715
|
+
{ command: "delete|cleanup", description: "Remove completed run records/artifacts." }
|
|
716
|
+
],
|
|
717
|
+
examples: [
|
|
718
|
+
"rig run attach <run-id> # full session console \u2014 live mirror, steering, worker shell",
|
|
719
|
+
"rig run steer <run-id> --message 'focus on the failing test first'",
|
|
720
|
+
"rig run list",
|
|
721
|
+
"rig run show <run-id>",
|
|
722
|
+
"rig run stop <run-id>"
|
|
723
|
+
],
|
|
724
|
+
next: [
|
|
725
|
+
"Inside the console: the run's COMPLETE transcript loads on open (finished runs too), and new worker turns stream in live.",
|
|
726
|
+
"Inside the console: plain text = steering into the worker's context \xB7 !<cmd> = shell in the WORKER workspace \xB7 /<cmd> includes the worker session's commands \xB7 /rig abort stops the current turn.",
|
|
727
|
+
"The console is read-write but remote-only: nothing runs on your machine; the worker keeps running when you exit.",
|
|
728
|
+
"Use `rig task run --next` to create a new run; interactive mode drops you straight into its console.",
|
|
729
|
+
"Use `--json` when scripts need the full structured record."
|
|
730
|
+
]
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
name: "inbox",
|
|
734
|
+
summary: "Review approval and user-input requests that block worker runs.",
|
|
735
|
+
usage: ["rig inbox <approvals|approve|inputs|respond> [options]"],
|
|
736
|
+
commands: [
|
|
737
|
+
{ command: "approvals [--run <id>] [--task <id>]", description: "List pending approvals.", primary: true },
|
|
738
|
+
{ command: "inputs [--run <id>] [--task <id>]", description: "List pending user-input requests.", primary: true },
|
|
739
|
+
{ command: "approve --run <id> --request <id> --decision approve|reject", description: "Resolve an approval request." },
|
|
740
|
+
{ command: "respond --run <id> --request <id> --answer key=value", description: "Answer a user-input request." }
|
|
741
|
+
],
|
|
742
|
+
examples: [
|
|
743
|
+
"rig inbox approvals",
|
|
744
|
+
"rig inbox inputs --run <run-id>",
|
|
745
|
+
"rig inbox approve --run <run-id> --request <request-id> --decision approve"
|
|
746
|
+
],
|
|
747
|
+
next: ["Rejoin the run after resolving a block: `rig run attach <run-id> --follow`."]
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
name: "stats",
|
|
751
|
+
summary: "Fleet metrics computed from on-disk run journals (no server required).",
|
|
752
|
+
usage: ["rig stats [show] [--since <7d|30d|ISO date>]"],
|
|
753
|
+
commands: [
|
|
754
|
+
{ command: "show [--since <window>]", description: "Total runs, completion/failure/needs-attention rates, median run time, steering, stalls, approvals.", primary: true }
|
|
755
|
+
],
|
|
756
|
+
examples: [
|
|
757
|
+
"rig stats",
|
|
758
|
+
"rig stats --since 7d",
|
|
759
|
+
"rig stats --since 2026-06-01 --json"
|
|
760
|
+
],
|
|
761
|
+
next: ["Inspect outliers with `rig run list` and `rig run show <run-id>`.", "Use `--json` for the schema'd envelope (see docs/cli-json.md)."]
|
|
762
|
+
},
|
|
763
|
+
{
|
|
764
|
+
name: "inspect",
|
|
765
|
+
summary: "Inspect logs, artifacts, graphs, failures for a task.",
|
|
766
|
+
usage: ["rig inspect <logs|artifacts|failures|graph|audit|diff> --task <id>"],
|
|
767
|
+
commands: [
|
|
768
|
+
{ command: "logs --task <id>", description: "Latest run log for a task (local or selected server).", primary: true },
|
|
769
|
+
{ command: "artifacts --task <id>", description: "List the task's completion artifacts.", primary: true },
|
|
770
|
+
{ command: "failures --task <id>", description: "Recorded failures for a task.", primary: true },
|
|
771
|
+
{ command: "diff --task <id>", description: "Changed files for a task.", primary: true },
|
|
772
|
+
{ command: "graph", description: "Task dependency graph." },
|
|
773
|
+
{ command: "audit", description: "Controlled-command audit trail." }
|
|
774
|
+
],
|
|
775
|
+
examples: ["rig inspect logs --task <id>", "rig inspect diff --task <id>"],
|
|
776
|
+
next: ["Use `rig stats` for fleet-level metrics across runs."]
|
|
777
|
+
},
|
|
778
|
+
{
|
|
779
|
+
name: "repo",
|
|
780
|
+
summary: "Repository sync/baseline helpers for the Rig-managed checkout.",
|
|
781
|
+
usage: ["rig repo <sync|reset-baseline>"],
|
|
782
|
+
commands: [
|
|
783
|
+
{ command: "sync", description: "Sync project repository state.", primary: true },
|
|
784
|
+
{ command: "reset-baseline", description: "Reset the managed baseline for the repo." }
|
|
785
|
+
],
|
|
786
|
+
examples: ["rig repo sync"]
|
|
787
|
+
},
|
|
788
|
+
{
|
|
789
|
+
name: "plugin",
|
|
790
|
+
summary: "Plugin listing, validation, and plugin-contributed commands.",
|
|
791
|
+
usage: ["rig plugin <list|validate|run> [options]"],
|
|
792
|
+
commands: [
|
|
793
|
+
{ command: "list", description: "List plugins declared in rig.config.ts and their contributions.", primary: true },
|
|
794
|
+
{ command: "validate --task <id>", description: "Run plugin-contributed validators for a task.", primary: true },
|
|
795
|
+
{ command: "run <command-id> [args...]", description: "Execute a plugin-contributed CLI command (also callable as `rig <command-id>`)." }
|
|
796
|
+
],
|
|
797
|
+
examples: ["rig plugin list", "rig plugin run <command-id>"]
|
|
798
|
+
},
|
|
799
|
+
{
|
|
800
|
+
name: "init",
|
|
801
|
+
summary: "Set up Rig for this repo: server, GitHub auth, checkout strategy, task source, and Pi wiring.",
|
|
802
|
+
usage: ["rig init [--yes] [--server local|remote] [--repo owner/repo] [--remote-url <url>]"],
|
|
803
|
+
commands: [
|
|
804
|
+
{ command: "init", description: "Interactive setup wizard for a new or existing Rig repo.", primary: true },
|
|
805
|
+
{ command: "init --demo", description: "Offline demo project: files task source + 3 sample tasks, zero GitHub.", primary: true },
|
|
806
|
+
{ command: "init --yes", description: "Non-interactive setup using detected/default settings.", primary: true },
|
|
807
|
+
{ command: "init --server remote --remote-url <url>", description: "Link this repo to a remote Rig server.", primary: true },
|
|
808
|
+
{ command: "init --repair", description: "Repair missing private state without replacing project config." }
|
|
809
|
+
],
|
|
810
|
+
examples: [
|
|
811
|
+
"rig init",
|
|
812
|
+
"rig init --demo",
|
|
813
|
+
"rig init --yes --repo humanity-org/humanwork",
|
|
814
|
+
"rig init --server remote --remote-url https://where.rig-does.work --repo owner/repo"
|
|
815
|
+
],
|
|
816
|
+
next: ["After init, run `rig server status`.", "Then use `rig task list` and `rig task run --next` for day-to-day work."]
|
|
817
|
+
},
|
|
818
|
+
{
|
|
819
|
+
name: "doctor",
|
|
820
|
+
summary: "Diagnostics for project/server/GitHub/Pi state.",
|
|
821
|
+
usage: ["rig doctor"],
|
|
822
|
+
commands: [
|
|
823
|
+
{ command: "doctor", description: "Run setup and runtime diagnostics.", primary: true },
|
|
824
|
+
{ command: "check", description: "Compatibility spelling for diagnostics." }
|
|
825
|
+
],
|
|
826
|
+
examples: ["rig doctor", "rig doctor --json"],
|
|
827
|
+
next: ["Use `rig server status` and `rig github auth status` to inspect common failure points."]
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
name: "github",
|
|
831
|
+
summary: "GitHub auth helpers for the selected Rig server.",
|
|
832
|
+
usage: ["rig github auth <status|import-gh|token>"],
|
|
833
|
+
commands: [
|
|
834
|
+
{ command: "auth status", description: "Show GitHub auth state.", primary: true },
|
|
835
|
+
{ command: "auth import-gh", description: "Import the current `gh` token into the selected server." },
|
|
836
|
+
{ command: "auth token --token <token>", description: "Store a token on the selected server." }
|
|
837
|
+
],
|
|
838
|
+
examples: ["rig github auth status", "rig github auth import-gh"],
|
|
839
|
+
next: ["After auth is valid, use `rig task run --next`."]
|
|
840
|
+
}
|
|
841
|
+
];
|
|
842
|
+
var ADVANCED_GROUPS = [
|
|
843
|
+
{ name: "setup", summary: "Bootstrap/check local setup.", usage: ["rig setup <bootstrap|check|preflight>"], commands: [{ command: "bootstrap|check|preflight", description: "Setup helpers." }] },
|
|
844
|
+
{ name: "profile", summary: "Runtime profile/model defaults.", usage: ["rig profile <show|set>"], commands: [{ command: "show", description: "Show active profile." }] },
|
|
845
|
+
{
|
|
846
|
+
name: "review",
|
|
847
|
+
summary: "Inspect or change completion review gate policy.",
|
|
848
|
+
usage: ["rig review <show|set>"],
|
|
849
|
+
commands: [
|
|
850
|
+
{ command: "show", description: "Show current review gate settings." },
|
|
851
|
+
{ command: "set <off|advisory|required> [--provider greptile]", description: "Change review strictness/provider." }
|
|
852
|
+
],
|
|
853
|
+
examples: ["rig review show", "rig review set required --provider greptile"],
|
|
854
|
+
next: ["Use `rig inbox approvals` for blocked run handoffs."]
|
|
855
|
+
},
|
|
856
|
+
{
|
|
857
|
+
name: "browser",
|
|
858
|
+
summary: "Browser/app diagnostics for browser-required tasks.",
|
|
859
|
+
usage: ["rig browser <help|explain|demo|app|hp-next> [options]"],
|
|
860
|
+
commands: [
|
|
861
|
+
{ command: "help", description: "Rich browser command help (canonical: `rig browser help`)." },
|
|
862
|
+
{ command: "explain", description: "Explain the browser-required task contract." },
|
|
863
|
+
{ command: "demo", description: "Run browser demo flows against a local page." },
|
|
864
|
+
{ command: "app", description: "Launch the Rig Browser workstation app." },
|
|
865
|
+
{ command: "hp-next <dev|check|e2e|reset>", description: "Drive the hp-next browser test harness." }
|
|
866
|
+
]
|
|
867
|
+
},
|
|
868
|
+
{
|
|
869
|
+
name: "pi",
|
|
870
|
+
summary: "Manage Pi extension packages for this project (community extensions from npm/git).",
|
|
871
|
+
usage: ["rig pi <list|add|remove|search> [args]"],
|
|
872
|
+
commands: [
|
|
873
|
+
{ command: "list", description: "Show project and user Pi extension packages." },
|
|
874
|
+
{ command: "add <source>", description: "Add an npm/git Pi extension to .pi/settings.json (auto-installs at next session)." },
|
|
875
|
+
{ command: "remove <source>", description: "Remove an operator-added Pi extension." },
|
|
876
|
+
{ command: "search [term]", description: "Discover Pi extension packages on the npm registry." }
|
|
877
|
+
],
|
|
878
|
+
examples: ["rig pi search subagents", "rig pi add pi-subagents", "rig pi list"],
|
|
879
|
+
next: ["Config-managed extensions: declare `runtime: { pi: { packages: [...] } }` in rig.config.ts \u2014 workers pick them up automatically."]
|
|
880
|
+
},
|
|
881
|
+
{ name: "queue", summary: "Run task queues locally.", usage: ["rig queue run [options]"], commands: [{ command: "run", description: "Process queue work." }] },
|
|
882
|
+
{ name: "agent", summary: "Runtime agent workspace helpers.", usage: ["rig agent <list|prepare|run|cleanup>"], commands: [{ command: "list", description: "List prepared agents." }] },
|
|
883
|
+
{ name: "inspector", summary: "Event stream and drift scanners.", usage: ["rig inspector <stream|scan-upstream-drift>"], commands: [{ command: "stream", description: "Stream events." }] },
|
|
884
|
+
{ name: "dist", summary: "Build/install packaged Rig CLI.", usage: ["rig dist <build|install|doctor>"], commands: [{ command: "build", description: "Build distribution." }] },
|
|
885
|
+
{ name: "workspace", summary: "Workspace topology/service helpers.", usage: ["rig workspace <summary|topology|remote-hosts>"], commands: [{ command: "summary", description: "Show workspace summary." }] },
|
|
886
|
+
{ name: "remote", summary: "Compatibility remote orchestration controls.", usage: ["rig remote <status|watch|pause|resume|...>"], commands: [{ command: "status", description: "Show remote state." }] },
|
|
887
|
+
{ name: "git", summary: "Pass through to Rig git-flow helper.", usage: ["rig git <args...>"], commands: [{ command: "<args...>", description: "Advanced git flow operations." }] },
|
|
888
|
+
{ name: "harness", summary: "Pass through to runtime harness CLI.", usage: ["rig harness <args...>"], commands: [{ command: "<args...>", description: "Advanced harness operations." }] },
|
|
889
|
+
{ name: "test", summary: "Project test wrappers.", usage: ["rig test <unit|e2e|all>"], commands: [{ command: "all", description: "Run configured project tests." }] }
|
|
890
|
+
];
|
|
891
|
+
var ALL_GROUPS = [...PRIMARY_GROUPS, ...ADVANCED_GROUPS];
|
|
892
|
+
function heading(title) {
|
|
893
|
+
return pc3.bold(pc3.cyan(title));
|
|
894
|
+
}
|
|
895
|
+
function commandLine(command, description) {
|
|
896
|
+
const commandColumn = command.length >= 38 ? `${command} ` : command.padEnd(38);
|
|
897
|
+
return `${pc3.dim("\u2502")} ${pc3.bold(commandColumn)} ${description}`;
|
|
898
|
+
}
|
|
899
|
+
function renderCommandBlock(commands) {
|
|
900
|
+
return commands.map((entry) => commandLine(entry.command, entry.description)).join(`
|
|
901
|
+
`);
|
|
902
|
+
}
|
|
903
|
+
function renderGroup(group) {
|
|
904
|
+
const lines = [
|
|
905
|
+
`${heading(`rig ${group.name}`)} \u2014 ${group.summary}`,
|
|
906
|
+
"",
|
|
907
|
+
pc3.bold("Usage"),
|
|
908
|
+
...group.usage.map((line) => ` ${line}`),
|
|
909
|
+
"",
|
|
910
|
+
pc3.bold("Commands"),
|
|
911
|
+
...group.commands.map((entry) => commandLine(entry.command, entry.description))
|
|
912
|
+
];
|
|
913
|
+
if (group.examples?.length) {
|
|
914
|
+
lines.push("", pc3.bold("Examples"), ...group.examples.map((line) => ` ${pc3.dim("$")} ${line}`));
|
|
915
|
+
}
|
|
916
|
+
if (group.next?.length) {
|
|
917
|
+
lines.push("", pc3.bold("Next steps"), ...group.next.map((line) => ` ${pc3.dim("\u203A")} ${line}`));
|
|
918
|
+
}
|
|
919
|
+
if (group.advanced?.length) {
|
|
920
|
+
lines.push("", pc3.bold("Compatibility / advanced"), ...group.advanced.map((line) => ` ${pc3.dim("\u203A")} ${line}`));
|
|
921
|
+
}
|
|
922
|
+
return lines.join(`
|
|
923
|
+
`);
|
|
924
|
+
}
|
|
925
|
+
function renderTopLevelHelp() {
|
|
926
|
+
return [
|
|
927
|
+
`${heading("rig")} ${pc3.dim("\u2014 server-owned task/run control plane for Pi-backed engineering work")}`,
|
|
928
|
+
pc3.dim("The loop: pick a task, dispatch an agent, open its Pi console (`rig run attach <id>`) to watch and steer it live, clear inbox gates, merge."),
|
|
929
|
+
"",
|
|
930
|
+
...TOP_LEVEL_SECTIONS.flatMap((section) => [
|
|
931
|
+
`${pc3.bold(pc3.magenta(`\u25C7 ${section.title}`))} \u2014 ${pc3.dim(section.subtitle)}`,
|
|
932
|
+
renderCommandBlock(section.commands),
|
|
933
|
+
""
|
|
934
|
+
]),
|
|
935
|
+
pc3.dim("More: `rig help --advanced` for dev/compatibility commands; `rig <group> --help` for rich per-group help; `rig --version` for the installed version."),
|
|
936
|
+
"",
|
|
937
|
+
pc3.bold("Global options"),
|
|
938
|
+
commandLine("--project <path>", "Use a project root instead of auto-discovery."),
|
|
939
|
+
commandLine("--json", "Emit structured output for scripts/agents."),
|
|
940
|
+
commandLine("--dry-run", "Print the command plan without mutating state.")
|
|
941
|
+
].join(`
|
|
942
|
+
`).trimEnd();
|
|
943
|
+
}
|
|
944
|
+
function renderGroupHelp(groupName) {
|
|
945
|
+
const group = ALL_GROUPS.find((candidate) => candidate.name === groupName);
|
|
946
|
+
return group ? renderGroup(group) : null;
|
|
947
|
+
}
|
|
948
|
+
function printGroupHelpDocument(groupName) {
|
|
949
|
+
console.log(renderGroupHelp(groupName) ?? renderTopLevelHelp());
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
// packages/cli/src/commands/stats.ts
|
|
953
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
954
|
+
function parseSinceOption(value, now = new Date) {
|
|
955
|
+
if (!value?.trim())
|
|
956
|
+
return null;
|
|
957
|
+
const trimmed = value.trim();
|
|
958
|
+
const relative = trimmed.match(/^(\d+)d$/i);
|
|
959
|
+
if (relative?.[1]) {
|
|
960
|
+
return new Date(now.getTime() - Number.parseInt(relative[1], 10) * DAY_MS);
|
|
961
|
+
}
|
|
962
|
+
const parsed = Date.parse(trimmed);
|
|
963
|
+
if (!Number.isFinite(parsed)) {
|
|
964
|
+
throw new CliError(`Invalid --since value: ${trimmed}. Use <n>d (e.g. 7d, 30d) or an ISO date (e.g. 2026-06-01).`, 2, { hint: "Re-run with a valid window, e.g. `rig stats --since 7d` or `rig stats --since 2026-06-01`." });
|
|
965
|
+
}
|
|
966
|
+
return new Date(parsed);
|
|
967
|
+
}
|
|
968
|
+
function formatPercent(value) {
|
|
969
|
+
if (value === null)
|
|
970
|
+
return "\u2014";
|
|
971
|
+
return `${(value * 100).toFixed(1)}%`;
|
|
972
|
+
}
|
|
973
|
+
function formatDuration(ms) {
|
|
974
|
+
if (ms === null)
|
|
975
|
+
return "\u2014";
|
|
976
|
+
if (ms < 1000)
|
|
977
|
+
return `${Math.round(ms)}ms`;
|
|
978
|
+
const seconds = ms / 1000;
|
|
979
|
+
if (seconds < 60)
|
|
980
|
+
return `${seconds.toFixed(0)}s`;
|
|
981
|
+
const minutes = seconds / 60;
|
|
982
|
+
if (minutes < 60)
|
|
983
|
+
return `${Math.floor(minutes)}m ${Math.round(seconds % 60)}s`;
|
|
984
|
+
const hours = Math.floor(minutes / 60);
|
|
985
|
+
return `${hours}h ${Math.round(minutes % 60)}m`;
|
|
986
|
+
}
|
|
987
|
+
function formatStatsReport(stats) {
|
|
988
|
+
const window = stats.since ? `since ${stats.since}` : "all time";
|
|
989
|
+
const rows = [
|
|
990
|
+
["runs", String(stats.totalRuns)],
|
|
991
|
+
["completed", `${stats.completedRuns} (${formatPercent(stats.completionRate)})`],
|
|
992
|
+
["failed", `${stats.failedRuns} (${formatPercent(stats.failureRate)})`],
|
|
993
|
+
["needs attn", `${stats.needsAttentionRuns} (${formatPercent(stats.needsAttentionRate)})`],
|
|
994
|
+
["median time", formatDuration(stats.medianCompletionMs)],
|
|
995
|
+
["steering", `${stats.steeringTotal} total \xB7 ${stats.steeringPerRun === null ? "\u2014" : stats.steeringPerRun.toFixed(2)}/run`],
|
|
996
|
+
["stalls", String(stats.stallTotal)],
|
|
997
|
+
["approvals", `${stats.approvalsRequested} requested \xB7 ${stats.approvalsApproved} approved \xB7 ${stats.approvalsRejected} rejected \xB7 ${stats.approvalsPending} pending`]
|
|
998
|
+
];
|
|
999
|
+
const keyWidth = Math.max(...rows.map(([key]) => key.length));
|
|
1000
|
+
const lines = [
|
|
1001
|
+
formatSection("Fleet stats", window),
|
|
1002
|
+
...rows.map(([key, value]) => `${pc4.dim("\u2502")} ${pc4.dim(key.padEnd(keyWidth + 2))} ${value}`)
|
|
1003
|
+
];
|
|
1004
|
+
const otherStatuses = Object.entries(stats.statusCounts).filter(([status]) => !["completed", "failed", "needs-attention"].includes(status)).sort(([, left], [, right]) => right - left);
|
|
1005
|
+
if (otherStatuses.length > 0) {
|
|
1006
|
+
lines.push(`${pc4.dim("\u2502")} ${pc4.dim("other".padEnd(keyWidth + 2))} ${otherStatuses.map(([status, count]) => `${status}:${count}`).join(" ")}`);
|
|
1007
|
+
}
|
|
1008
|
+
lines.push("", ...formatNextSteps([
|
|
1009
|
+
"Inspect a run: `rig run list` then `rig run show <run-id>`",
|
|
1010
|
+
"Narrow the window: `rig stats --since 7d`"
|
|
1011
|
+
]));
|
|
1012
|
+
return lines.join(`
|
|
1013
|
+
`);
|
|
1014
|
+
}
|
|
1015
|
+
async function executeStats(context, args) {
|
|
1016
|
+
const [first, ...rest] = args;
|
|
1017
|
+
const isImplicitShow = first === undefined || first.startsWith("-");
|
|
1018
|
+
const command = isImplicitShow ? "show" : first;
|
|
1019
|
+
const pending = isImplicitShow ? args : rest;
|
|
1020
|
+
switch (command) {
|
|
1021
|
+
case "show": {
|
|
1022
|
+
const sinceResult = takeOption(pending, "--since");
|
|
1023
|
+
requireNoExtraArgs(sinceResult.rest, "rig stats [show] [--since <7d|30d|ISO date>]");
|
|
1024
|
+
const since = parseSinceOption(sinceResult.value);
|
|
1025
|
+
const remoteStats = isRemoteConnectionSelected(context.projectRoot);
|
|
1026
|
+
const stats = await withSpinner(remoteStats ? "Computing fleet stats on the server\u2026" : "Scanning local run state\u2026", async () => remoteStats ? await requestServerJson(context, `/api/stats${since ? `?since=${encodeURIComponent(since.toISOString())}` : ""}`) : computeRigStats(context.projectRoot, { since }), { outputMode: context.outputMode });
|
|
1027
|
+
if (context.outputMode === "text") {
|
|
1028
|
+
printFormattedOutput(formatStatsReport(stats));
|
|
1029
|
+
}
|
|
1030
|
+
return {
|
|
1031
|
+
ok: true,
|
|
1032
|
+
group: "stats",
|
|
1033
|
+
command: "show",
|
|
1034
|
+
details: stats
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
case "help": {
|
|
1038
|
+
if (context.outputMode === "text")
|
|
1039
|
+
printGroupHelpDocument("stats");
|
|
1040
|
+
return { ok: true, group: "stats", command: "help" };
|
|
1041
|
+
}
|
|
1042
|
+
default:
|
|
1043
|
+
throw new CliError(`Unknown stats command: ${command}. Use \`rig stats\` or \`rig stats show [--since <7d|30d|ISO date>]\`.`, 2, { hint: "Run `rig stats --since 7d` for the last week, or `rig stats --help` for usage." });
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
export {
|
|
1047
|
+
parseSinceOption,
|
|
1048
|
+
formatStatsReport,
|
|
1049
|
+
executeStats,
|
|
1050
|
+
computeRigStats
|
|
1051
|
+
};
|