@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,447 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/cli/src/app/drone-ui.ts
|
|
3
|
+
import { ProcessTerminal, TUI, Text, Input, SelectList, matchesKey } from "@earendil-works/pi-tui";
|
|
4
|
+
|
|
5
|
+
// packages/cli/src/app/theme.ts
|
|
6
|
+
var RIG_PALETTE = {
|
|
7
|
+
ink: "#f2f3f6",
|
|
8
|
+
ink2: "#aeb0ba",
|
|
9
|
+
ink3: "#6c6e79",
|
|
10
|
+
ink4: "#44464f",
|
|
11
|
+
accent: "#ccff4d",
|
|
12
|
+
accentDim: "#a9d63f",
|
|
13
|
+
cyan: "#56d8ff",
|
|
14
|
+
red: "#ff5d5d",
|
|
15
|
+
yellow: "#ffd24d"
|
|
16
|
+
};
|
|
17
|
+
function hexToRgb(hex) {
|
|
18
|
+
const value = hex.replace("#", "");
|
|
19
|
+
return [
|
|
20
|
+
Number.parseInt(value.slice(0, 2), 16),
|
|
21
|
+
Number.parseInt(value.slice(2, 4), 16),
|
|
22
|
+
Number.parseInt(value.slice(4, 6), 16)
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
function fg(hex) {
|
|
26
|
+
const [r, g, b] = hexToRgb(hex);
|
|
27
|
+
return (text) => `\x1B[38;2;${r};${g};${b}m${text}\x1B[39m`;
|
|
28
|
+
}
|
|
29
|
+
var ink = fg(RIG_PALETTE.ink);
|
|
30
|
+
var ink2 = fg(RIG_PALETTE.ink2);
|
|
31
|
+
var ink3 = fg(RIG_PALETTE.ink3);
|
|
32
|
+
var ink4 = fg(RIG_PALETTE.ink4);
|
|
33
|
+
var accent = fg(RIG_PALETTE.accent);
|
|
34
|
+
var accentDim = fg(RIG_PALETTE.accentDim);
|
|
35
|
+
var cyan = fg(RIG_PALETTE.cyan);
|
|
36
|
+
var red = fg(RIG_PALETTE.red);
|
|
37
|
+
var yellow = fg(RIG_PALETTE.yellow);
|
|
38
|
+
function bold(text) {
|
|
39
|
+
return `\x1B[1m${text}\x1B[22m`;
|
|
40
|
+
}
|
|
41
|
+
var DRONE_ART = [
|
|
42
|
+
" .-=-. .-=-. ",
|
|
43
|
+
" ( !!! ) ( !!! ) ",
|
|
44
|
+
" '-=-'._ _.'-=-' ",
|
|
45
|
+
" '._ _.' ",
|
|
46
|
+
" '=$$$$$$$=.' ",
|
|
47
|
+
" =$$$$$$$$$$$= ",
|
|
48
|
+
" $$$@@@@@@@@@@$$$ ",
|
|
49
|
+
" $$$@@ @@$$$ ",
|
|
50
|
+
" $$@ ? @$$$ ",
|
|
51
|
+
" $$$@ '-' @$$$ ",
|
|
52
|
+
" $$$@@ @@$$$ ",
|
|
53
|
+
" $$$@@@@@@@@@@$$$ ",
|
|
54
|
+
" =$$$$$$$$$$$= ",
|
|
55
|
+
" '=$$$$$$$=.' ",
|
|
56
|
+
" _.' '._ ",
|
|
57
|
+
" .-=-.' '.-=-. ",
|
|
58
|
+
" ( !!! ) ( !!! ) ",
|
|
59
|
+
" '-=-' '-=-' "
|
|
60
|
+
];
|
|
61
|
+
var EYE_FRAMES = ["@", "o", "."];
|
|
62
|
+
var DRONE_WIDTH = DRONE_ART[0].length;
|
|
63
|
+
var DRONE_HEIGHT = DRONE_ART.length;
|
|
64
|
+
var MICRO_BLADES = ["---", "\\\\\\", "|||", "///"];
|
|
65
|
+
function microDroneFrame(tick) {
|
|
66
|
+
const blade = MICRO_BLADES[tick % MICRO_BLADES.length];
|
|
67
|
+
const eye = EYE_FRAMES[Math.floor(tick / 2) % EYE_FRAMES.length];
|
|
68
|
+
return `(${blade})${eye}(${blade})`;
|
|
69
|
+
}
|
|
70
|
+
var MICRO_DRONE_FRAMES = Array.from({ length: 12 }, (_, index) => microDroneFrame(index));
|
|
71
|
+
|
|
72
|
+
// packages/cli/src/app/drone-ui.ts
|
|
73
|
+
function droneNote(message, title) {
|
|
74
|
+
if (title)
|
|
75
|
+
console.log(` ${accentDim("\u25C7")} ${bold(ink2(title))}`);
|
|
76
|
+
for (const line of message.split(`
|
|
77
|
+
`)) {
|
|
78
|
+
console.log(` ${ink4("\u2502")} ${line}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// packages/cli/src/commands/_cli-format.ts
|
|
83
|
+
import pc from "picocolors";
|
|
84
|
+
var themeDim = (value) => ink3(value);
|
|
85
|
+
var themeFaint = (value) => ink4(value);
|
|
86
|
+
function stringField(record, key, fallback = "") {
|
|
87
|
+
const value = record[key];
|
|
88
|
+
return typeof value === "string" && value.trim() ? value.trim() : fallback;
|
|
89
|
+
}
|
|
90
|
+
function numberField(record, key) {
|
|
91
|
+
const value = record[key];
|
|
92
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
93
|
+
}
|
|
94
|
+
function arrayField(record, key) {
|
|
95
|
+
const value = record[key];
|
|
96
|
+
return Array.isArray(value) ? value.flatMap((entry) => typeof entry === "string" && entry.trim() ? [entry.trim()] : []) : [];
|
|
97
|
+
}
|
|
98
|
+
function rawObject(record) {
|
|
99
|
+
const raw = record.raw;
|
|
100
|
+
return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
101
|
+
}
|
|
102
|
+
function truncate(value, width) {
|
|
103
|
+
if (value.length <= width)
|
|
104
|
+
return value;
|
|
105
|
+
if (width <= 1)
|
|
106
|
+
return "\u2026";
|
|
107
|
+
return `${value.slice(0, width - 1)}\u2026`;
|
|
108
|
+
}
|
|
109
|
+
function pad(value, width) {
|
|
110
|
+
return value.length >= width ? value : `${value}${" ".repeat(width - value.length)}`;
|
|
111
|
+
}
|
|
112
|
+
function statusColor(status) {
|
|
113
|
+
const normalized = status.toLowerCase();
|
|
114
|
+
if (["completed", "merged", "closed", "done", "accepted", "pass", "selected", "approved", "running"].includes(normalized))
|
|
115
|
+
return accent;
|
|
116
|
+
if (["failed", "needs_attention", "needs-attention", "blocked", "error", "rejected"].includes(normalized))
|
|
117
|
+
return red;
|
|
118
|
+
if (["reviewing", "validating", "in_progress", "in-progress", "remote", "preparing", "closing-out"].includes(normalized))
|
|
119
|
+
return cyan;
|
|
120
|
+
if (["ready", "open", "queued", "created", "local", "pending"].includes(normalized))
|
|
121
|
+
return yellow;
|
|
122
|
+
return themeDim;
|
|
123
|
+
}
|
|
124
|
+
function compactDate(value) {
|
|
125
|
+
if (!value.trim())
|
|
126
|
+
return "";
|
|
127
|
+
const parsed = Date.parse(value);
|
|
128
|
+
if (!Number.isFinite(parsed))
|
|
129
|
+
return value;
|
|
130
|
+
return new Date(parsed).toISOString().replace("T", " ").replace(/\.\d{3}Z$/, "Z");
|
|
131
|
+
}
|
|
132
|
+
function compactValue(value) {
|
|
133
|
+
if (value === null || value === undefined)
|
|
134
|
+
return "";
|
|
135
|
+
if (typeof value === "string")
|
|
136
|
+
return value;
|
|
137
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
138
|
+
return String(value);
|
|
139
|
+
if (Array.isArray(value))
|
|
140
|
+
return value.map(compactValue).filter(Boolean).join(", ");
|
|
141
|
+
return JSON.stringify(value);
|
|
142
|
+
}
|
|
143
|
+
function firstString(record, keys, fallback = "") {
|
|
144
|
+
for (const key of keys) {
|
|
145
|
+
const value = stringField(record, key);
|
|
146
|
+
if (value)
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
return fallback;
|
|
150
|
+
}
|
|
151
|
+
function runIdOf(run) {
|
|
152
|
+
return firstString(run, ["runId", "id"], "(unknown-run)");
|
|
153
|
+
}
|
|
154
|
+
function taskIdOf(run) {
|
|
155
|
+
return firstString(run, ["taskId", "task", "task_id"]);
|
|
156
|
+
}
|
|
157
|
+
function runTitleOf(run) {
|
|
158
|
+
return firstString(run, ["title", "summary", "name"], taskIdOf(run) || "(untitled)");
|
|
159
|
+
}
|
|
160
|
+
function requestIdOf(entry) {
|
|
161
|
+
return firstString(entry, ["requestId", "id", "approvalId", "inputId"], "(unknown-request)");
|
|
162
|
+
}
|
|
163
|
+
function shouldUseClackOutput() {
|
|
164
|
+
return Boolean(process.stdout.isTTY) && process.env.RIG_CLI_PLAIN_HELP !== "1";
|
|
165
|
+
}
|
|
166
|
+
function printFormattedOutput(message, options = {}) {
|
|
167
|
+
if (!shouldUseClackOutput()) {
|
|
168
|
+
console.log(message);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
droneNote(message, options.title);
|
|
172
|
+
}
|
|
173
|
+
function formatStatusPill(status) {
|
|
174
|
+
const label = status || "unknown";
|
|
175
|
+
return statusColor(label)(`\u25CF ${label}`);
|
|
176
|
+
}
|
|
177
|
+
function formatSection(title, subtitle) {
|
|
178
|
+
return `${pc.bold(accent("\u25C6"))} ${pc.bold(title)}${subtitle ? themeDim(` \u2014 ${subtitle}`) : ""}`;
|
|
179
|
+
}
|
|
180
|
+
function formatSuccessCard(title, rows = []) {
|
|
181
|
+
const body = rows.filter(([, value]) => value !== undefined && value !== null && String(value).length > 0).map(([key, value]) => `${themeFaint("\u2502")} ${themeDim(key.padEnd(12))} ${value}`);
|
|
182
|
+
return [formatSection(title), ...body].join(`
|
|
183
|
+
`);
|
|
184
|
+
}
|
|
185
|
+
function formatNextSteps(steps) {
|
|
186
|
+
if (steps.length === 0)
|
|
187
|
+
return [];
|
|
188
|
+
return [pc.bold("Next"), ...steps.map((step) => `${accent("\u203A")} ${step}`)];
|
|
189
|
+
}
|
|
190
|
+
function formatTaskList(tasks, options = {}) {
|
|
191
|
+
if (options.raw)
|
|
192
|
+
return tasks.map((task) => JSON.stringify(task)).join(`
|
|
193
|
+
`);
|
|
194
|
+
if (tasks.length === 0)
|
|
195
|
+
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(`
|
|
196
|
+
`);
|
|
197
|
+
const rows = tasks.map((task) => {
|
|
198
|
+
const raw = rawObject(task);
|
|
199
|
+
const id = stringField(task, "id", "<unknown>");
|
|
200
|
+
const status = stringField(task, "status", "unknown");
|
|
201
|
+
const title = stringField(task, "title", "Untitled task");
|
|
202
|
+
const source = stringField(task, "source", stringField(raw, "source", ""));
|
|
203
|
+
const labels = arrayField(task, "labels").length > 0 ? arrayField(task, "labels") : arrayField(raw, "labels");
|
|
204
|
+
return { id, status, title, source, labels };
|
|
205
|
+
});
|
|
206
|
+
const idWidth = Math.min(18, Math.max(4, ...rows.map((row) => row.id.length)));
|
|
207
|
+
const statusWidth = Math.min(16, Math.max(6, ...rows.map((row) => row.status.length)));
|
|
208
|
+
const header = `${pc.bold(pad("TASK", idWidth))} ${pc.bold(pad("STATUS", statusWidth))} ${pc.bold("TITLE")}`;
|
|
209
|
+
const body = rows.map((row) => {
|
|
210
|
+
const labels = row.labels.length > 0 ? themeDim(` ${row.labels.slice(0, 4).map((label) => `#${label}`).join(" ")}`) : "";
|
|
211
|
+
const source = row.source ? themeDim(` ${row.source}`) : "";
|
|
212
|
+
return [
|
|
213
|
+
pc.bold(pad(truncate(row.id, idWidth), idWidth)),
|
|
214
|
+
statusColor(row.status)(pad(truncate(row.status, statusWidth), statusWidth)),
|
|
215
|
+
`${row.title}${labels}${source}`
|
|
216
|
+
].join(" ");
|
|
217
|
+
});
|
|
218
|
+
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(`
|
|
219
|
+
`);
|
|
220
|
+
}
|
|
221
|
+
function formatTaskCard(task, options = {}) {
|
|
222
|
+
const raw = rawObject(task);
|
|
223
|
+
const id = stringField(task, "id", stringField(raw, "id", "<unknown>"));
|
|
224
|
+
const status = stringField(task, "status", stringField(raw, "status", "unknown"));
|
|
225
|
+
const title = stringField(task, "title", stringField(raw, "title", "Untitled task"));
|
|
226
|
+
const source = stringField(task, "source", stringField(raw, "source", ""));
|
|
227
|
+
const url = stringField(task, "url", stringField(raw, "url", ""));
|
|
228
|
+
const number = numberField(task, "number") ?? numberField(raw, "number");
|
|
229
|
+
const labels = arrayField(task, "labels").length > 0 ? arrayField(task, "labels") : arrayField(raw, "labels");
|
|
230
|
+
const assignees = arrayField(task, "assignees").length > 0 ? arrayField(task, "assignees") : arrayField(raw, "assignees");
|
|
231
|
+
const readiness = compactValue(task.readiness ?? raw.readiness);
|
|
232
|
+
const validators = compactValue(task.validators ?? raw.validators ?? task.validation ?? raw.validation);
|
|
233
|
+
const rows = [
|
|
234
|
+
["task", pc.bold(id)],
|
|
235
|
+
["status", formatStatusPill(status)],
|
|
236
|
+
["title", title],
|
|
237
|
+
["source", source],
|
|
238
|
+
["number", number],
|
|
239
|
+
["labels", labels.length ? labels.map((label) => `#${label}`).join(" ") : ""],
|
|
240
|
+
["assignees", assignees.join(", ")],
|
|
241
|
+
["readiness", readiness],
|
|
242
|
+
["validators", validators],
|
|
243
|
+
["url", url]
|
|
244
|
+
];
|
|
245
|
+
return [
|
|
246
|
+
formatSuccessCard(options.title ?? (options.selected ? "Selected task" : "Task"), rows),
|
|
247
|
+
"",
|
|
248
|
+
...formatNextSteps([`Start: \`rig task run ${id}\``, `Details: \`rig task show ${id} --raw\``])
|
|
249
|
+
].join(`
|
|
250
|
+
`);
|
|
251
|
+
}
|
|
252
|
+
function formatTaskDetails(task) {
|
|
253
|
+
return formatTaskCard(task, { title: "Task details" });
|
|
254
|
+
}
|
|
255
|
+
function formatRunList(runs, options = {}) {
|
|
256
|
+
if (runs.length === 0) {
|
|
257
|
+
return [
|
|
258
|
+
formatSection("Runs", "none recorded"),
|
|
259
|
+
options.source === "server" ? themeDim("No runs recorded on the selected Rig server.") : themeDim("No runs recorded in .rig/runs."),
|
|
260
|
+
"",
|
|
261
|
+
...formatNextSteps(["Start one: `rig task run --next`", "Check server: `rig server status`"])
|
|
262
|
+
].join(`
|
|
263
|
+
`);
|
|
264
|
+
}
|
|
265
|
+
const rows = runs.map((run) => {
|
|
266
|
+
const runId = stringField(run, "runId", stringField(run, "id", "(unknown-run)"));
|
|
267
|
+
const status = stringField(run, "status", "unknown");
|
|
268
|
+
const taskId = stringField(run, "taskId", "");
|
|
269
|
+
const title = stringField(run, "title", taskId || "(untitled)");
|
|
270
|
+
const runtime = stringField(run, "runtimeAdapter", "");
|
|
271
|
+
return { runId, status, title, runtime };
|
|
272
|
+
});
|
|
273
|
+
const idWidth = Math.min(36, Math.max(6, ...rows.map((row) => row.runId.length)));
|
|
274
|
+
const statusWidth = Math.min(16, Math.max(6, ...rows.map((row) => row.status.length)));
|
|
275
|
+
const header = `${pc.bold(pad("RUN", idWidth))} ${pc.bold(pad("STATUS", statusWidth))} ${pc.bold("TITLE")}`;
|
|
276
|
+
const body = rows.map((row) => [
|
|
277
|
+
pc.bold(pad(truncate(row.runId, idWidth), idWidth)),
|
|
278
|
+
statusColor(row.status)(pad(truncate(row.status, statusWidth), statusWidth)),
|
|
279
|
+
`${row.title}${row.runtime ? themeDim(` ${row.runtime}`) : ""}`
|
|
280
|
+
].join(" "));
|
|
281
|
+
return [formatSection("Runs", options.source === "server" ? "selected server" : "local state"), header, ...body, "", ...formatNextSteps(["Follow live: `rig run attach <run-id> --follow`", "Details: `rig run show <run-id>`"])].join(`
|
|
282
|
+
`);
|
|
283
|
+
}
|
|
284
|
+
function formatSubmittedRun(input) {
|
|
285
|
+
const rows = [["run", pc.bold(input.runId)]];
|
|
286
|
+
if (input.task) {
|
|
287
|
+
const id = stringField(input.task, "id", "<unknown>");
|
|
288
|
+
const status = stringField(input.task, "status", "unknown");
|
|
289
|
+
const title = stringField(input.task, "title", "Untitled task");
|
|
290
|
+
rows.push(["task", `${pc.bold(id)} ${formatStatusPill(status)} ${title}`]);
|
|
291
|
+
}
|
|
292
|
+
const runtime = [input.runtimeAdapter || "pi", input.runtimeMode || "full-access", input.interactionMode || "default"].filter(Boolean).join(" \xB7 ");
|
|
293
|
+
rows.push(["runtime", runtime]);
|
|
294
|
+
return [
|
|
295
|
+
formatSuccessCard("Run submitted", rows),
|
|
296
|
+
"",
|
|
297
|
+
...formatNextSteps([
|
|
298
|
+
`Attach: \`rig run attach ${input.runId} --follow\``,
|
|
299
|
+
`Inspect: \`rig run show ${input.runId}\``,
|
|
300
|
+
input.detached ? "Submitted detached; attach when you are ready." : "Interactive mode opens the enriched bundled Pi (native UI + Rig layers, worker brain)."
|
|
301
|
+
])
|
|
302
|
+
].join(`
|
|
303
|
+
`);
|
|
304
|
+
}
|
|
305
|
+
function formatRunCard(run, options = {}) {
|
|
306
|
+
const raw = rawObject(run);
|
|
307
|
+
const merged = { ...raw, ...run };
|
|
308
|
+
const runId = runIdOf(merged);
|
|
309
|
+
const status = firstString(merged, ["status"], "unknown");
|
|
310
|
+
const taskId = taskIdOf(merged);
|
|
311
|
+
const title = runTitleOf(merged);
|
|
312
|
+
const runtime = firstString(merged, ["runtimeAdapter", "runtime", "adapter"]);
|
|
313
|
+
const mode = firstString(merged, ["runtimeMode", "mode"]);
|
|
314
|
+
const interaction = firstString(merged, ["interactionMode"]);
|
|
315
|
+
const created = compactDate(firstString(merged, ["createdAt"]));
|
|
316
|
+
const started = compactDate(firstString(merged, ["startedAt"]));
|
|
317
|
+
const updated = compactDate(firstString(merged, ["updatedAt"]));
|
|
318
|
+
const completed = compactDate(firstString(merged, ["completedAt", "finishedAt"]));
|
|
319
|
+
const worktree = firstString(merged, ["worktreePath", "cwd", "projectRoot"]);
|
|
320
|
+
const piSession = merged.piSession && typeof merged.piSession === "object" && !Array.isArray(merged.piSession) ? firstString(merged.piSession, ["sessionId", "id"]) : "";
|
|
321
|
+
const timeline = Array.isArray(merged.timeline) ? merged.timeline.length : null;
|
|
322
|
+
const approvals = Array.isArray(merged.approvals) ? merged.approvals.length : null;
|
|
323
|
+
const inputs = Array.isArray(merged.userInputs) ? merged.userInputs.length : null;
|
|
324
|
+
const rows = [
|
|
325
|
+
["run", pc.bold(runId)],
|
|
326
|
+
["status", formatStatusPill(status)],
|
|
327
|
+
["task", taskId],
|
|
328
|
+
["title", title],
|
|
329
|
+
["runtime", [runtime, mode, interaction].filter(Boolean).join(" \xB7 ")],
|
|
330
|
+
["created", created],
|
|
331
|
+
["started", started],
|
|
332
|
+
["updated", updated],
|
|
333
|
+
["completed", completed],
|
|
334
|
+
["worktree", worktree],
|
|
335
|
+
["pi", piSession],
|
|
336
|
+
["timeline", timeline],
|
|
337
|
+
["approvals", approvals],
|
|
338
|
+
["inputs", inputs]
|
|
339
|
+
];
|
|
340
|
+
return [
|
|
341
|
+
formatSuccessCard(options.title ?? "Run details", rows),
|
|
342
|
+
"",
|
|
343
|
+
...formatNextSteps([`Follow live: \`rig run attach ${runId} --follow\``, `Raw payload: \`rig run show ${runId} --raw\``])
|
|
344
|
+
].join(`
|
|
345
|
+
`);
|
|
346
|
+
}
|
|
347
|
+
function formatRunStatus(summary, options = {}) {
|
|
348
|
+
const activeRuns = summary.activeRuns ?? [];
|
|
349
|
+
const recentRuns = summary.recentRuns ?? [];
|
|
350
|
+
const lines = [formatSection("Run status", options.source === "server" ? "selected server" : "local state")];
|
|
351
|
+
lines.push("", pc.bold(`Active runs (${activeRuns.length})`));
|
|
352
|
+
if (activeRuns.length === 0) {
|
|
353
|
+
lines.push(themeDim("No active runs."));
|
|
354
|
+
} else {
|
|
355
|
+
for (const run of activeRuns) {
|
|
356
|
+
lines.push(formatRunSummaryLine(run));
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
lines.push("", pc.bold(`Recent runs (${recentRuns.length})`));
|
|
360
|
+
if (recentRuns.length === 0) {
|
|
361
|
+
lines.push(themeDim("No recent terminal runs."));
|
|
362
|
+
} else {
|
|
363
|
+
for (const run of recentRuns.slice(0, 10)) {
|
|
364
|
+
lines.push(formatRunSummaryLine(run));
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
lines.push("", ...formatNextSteps(["Start work: `rig task run --next`", "Attach: `rig run attach <run-id> --follow`", "Details: `rig run show <run-id>`"]));
|
|
368
|
+
return lines.join(`
|
|
369
|
+
`);
|
|
370
|
+
}
|
|
371
|
+
function formatRunSummaryLine(run) {
|
|
372
|
+
const record = run;
|
|
373
|
+
const runId = runIdOf(record);
|
|
374
|
+
const status = firstString(record, ["status"], "unknown");
|
|
375
|
+
const taskId = taskIdOf(record);
|
|
376
|
+
const title = runTitleOf(record);
|
|
377
|
+
const runtime = firstString(record, ["runtimeAdapter", "runtime", "adapter"]);
|
|
378
|
+
const descriptor = [taskId, title].filter(Boolean).join(" \xB7 ");
|
|
379
|
+
return `${themeFaint("\u2502")} ${pc.bold(runId)} ${formatStatusPill(status)} ${descriptor}${runtime ? themeDim(` ${runtime}`) : ""}`;
|
|
380
|
+
}
|
|
381
|
+
function formatInboxList(kind, entries) {
|
|
382
|
+
const title = kind === "approvals" ? "Approval inbox" : "Input inbox";
|
|
383
|
+
if (entries.length === 0) {
|
|
384
|
+
return [
|
|
385
|
+
formatSection(title, "empty"),
|
|
386
|
+
themeDim(kind === "approvals" ? "No pending approvals." : "No pending user-input requests."),
|
|
387
|
+
"",
|
|
388
|
+
...formatNextSteps(["Check runs: `rig run status`", "Start work: `rig task run --next`"])
|
|
389
|
+
].join(`
|
|
390
|
+
`);
|
|
391
|
+
}
|
|
392
|
+
const lines = [formatSection(title, `${entries.length} pending`)];
|
|
393
|
+
for (const entry of entries) {
|
|
394
|
+
const record = entry.record && typeof entry.record === "object" && !Array.isArray(entry.record) ? entry.record : entry;
|
|
395
|
+
const runId = firstString(entry, ["runId"], firstString(record, ["runId"]));
|
|
396
|
+
const taskId = firstString(entry, ["taskId"], firstString(record, ["taskId", "task"]));
|
|
397
|
+
const requestId = requestIdOf(record);
|
|
398
|
+
const status = firstString(record, ["status", "state"], "pending");
|
|
399
|
+
const prompt = firstString(record, ["prompt", "message", "reason", "title", "summary"], kind === "approvals" ? "Approval requested" : "Input requested");
|
|
400
|
+
lines.push(`${themeFaint("\u2502")} ${pc.bold(requestId)} ${formatStatusPill(status)} ${prompt}`);
|
|
401
|
+
lines.push(`${themeFaint("\u2502")} ${themeDim("run ")} ${runId || "(unknown-run)"}${taskId ? themeDim(` task ${taskId}`) : ""}`);
|
|
402
|
+
}
|
|
403
|
+
lines.push("", ...formatNextSteps(kind === "approvals" ? ["Resolve: `rig inbox approve --run <run-id> --request <request-id> --decision approve|reject`", "Rejoin: `rig run attach <run-id> --follow`"] : ["Respond: `rig inbox respond --run <run-id> --request <request-id> --answer key=value`", "Rejoin: `rig run attach <run-id> --follow`"]));
|
|
404
|
+
return lines.join(`
|
|
405
|
+
`);
|
|
406
|
+
}
|
|
407
|
+
function formatConnectionList(connections) {
|
|
408
|
+
const rows = [["local", { kind: "local", mode: "auto" }], ...Object.entries(connections)];
|
|
409
|
+
const aliasWidth = Math.min(24, Math.max(5, ...rows.map(([alias]) => alias.length)));
|
|
410
|
+
const lines = rows.map(([alias, connection]) => [
|
|
411
|
+
pc.bold(pad(truncate(alias, aliasWidth), aliasWidth)),
|
|
412
|
+
formatStatusPill(connection.kind),
|
|
413
|
+
connection.kind === "remote" ? connection.baseUrl ?? "" : connection.mode ?? "local"
|
|
414
|
+
].join(" "));
|
|
415
|
+
return [formatSection("Rig servers", `${rows.length} available`), `${pc.bold(pad("ALIAS", aliasWidth))} ${pc.bold("KIND")} ${pc.bold("TARGET")}`, ...lines, "", ...formatNextSteps(["Select one: `rig server use <alias|local>`"])].join(`
|
|
416
|
+
`);
|
|
417
|
+
}
|
|
418
|
+
function formatConnectionStatus(selected, connections) {
|
|
419
|
+
const connection = selected === "local" ? { kind: "local", mode: "auto" } : connections[selected];
|
|
420
|
+
const target = !connection ? "not configured" : connection.kind === "remote" ? connection.baseUrl : "local";
|
|
421
|
+
return [
|
|
422
|
+
formatSection("Rig server", "selected for this repo"),
|
|
423
|
+
`${themeFaint("\u2502")} ${themeDim("selected ")} ${pc.bold(selected)}`,
|
|
424
|
+
`${themeFaint("\u2502")} ${themeDim("kind ")} ${formatStatusPill(connection?.kind ?? "unknown")}`,
|
|
425
|
+
`${themeFaint("\u2502")} ${themeDim("target ")} ${target ?? "not configured"}`,
|
|
426
|
+
"",
|
|
427
|
+
...formatNextSteps(["Change: `rig server use <alias|local>`", "List saved servers: `rig server list`"])
|
|
428
|
+
].join(`
|
|
429
|
+
`);
|
|
430
|
+
}
|
|
431
|
+
export {
|
|
432
|
+
printFormattedOutput,
|
|
433
|
+
formatTaskList,
|
|
434
|
+
formatTaskDetails,
|
|
435
|
+
formatTaskCard,
|
|
436
|
+
formatSuccessCard,
|
|
437
|
+
formatSubmittedRun,
|
|
438
|
+
formatStatusPill,
|
|
439
|
+
formatSection,
|
|
440
|
+
formatRunStatus,
|
|
441
|
+
formatRunList,
|
|
442
|
+
formatRunCard,
|
|
443
|
+
formatNextSteps,
|
|
444
|
+
formatInboxList,
|
|
445
|
+
formatConnectionStatus,
|
|
446
|
+
formatConnectionList
|
|
447
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type RigConnection = {
|
|
2
|
+
kind: "local";
|
|
3
|
+
mode: "auto";
|
|
4
|
+
} | {
|
|
5
|
+
kind: "remote";
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
};
|
|
8
|
+
export type GlobalConnectionState = {
|
|
9
|
+
connections: Record<string, RigConnection>;
|
|
10
|
+
};
|
|
11
|
+
export type RepoConnectionState = {
|
|
12
|
+
selected: string;
|
|
13
|
+
project?: string;
|
|
14
|
+
linkedAt?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The server-host project root this repo scopes to (multi-root serving).
|
|
17
|
+
* Sent as the x-rig-project-root header on every remote request.
|
|
18
|
+
*/
|
|
19
|
+
serverProjectRoot?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function resolveGlobalConnectionsPath(env?: NodeJS.ProcessEnv): string;
|
|
22
|
+
export declare function resolveRepoConnectionPath(projectRoot: string): string;
|
|
23
|
+
export declare function readGlobalConnections(options?: {
|
|
24
|
+
env?: NodeJS.ProcessEnv;
|
|
25
|
+
}): GlobalConnectionState;
|
|
26
|
+
export declare function writeGlobalConnections(state: GlobalConnectionState, options?: {
|
|
27
|
+
env?: NodeJS.ProcessEnv;
|
|
28
|
+
}): void;
|
|
29
|
+
export declare function upsertGlobalConnection(alias: string, connection: RigConnection, options?: {
|
|
30
|
+
env?: NodeJS.ProcessEnv;
|
|
31
|
+
}): GlobalConnectionState;
|
|
32
|
+
export declare function readRepoConnection(projectRoot: string): RepoConnectionState | null;
|
|
33
|
+
export declare function writeRepoConnection(projectRoot: string, state: RepoConnectionState): void;
|
|
34
|
+
export declare function resolveSelectedConnection(projectRoot: string, options?: {
|
|
35
|
+
env?: NodeJS.ProcessEnv;
|
|
36
|
+
}): {
|
|
37
|
+
alias: string;
|
|
38
|
+
connection: RigConnection;
|
|
39
|
+
serverProjectRoot?: string;
|
|
40
|
+
} | null;
|
|
41
|
+
/** Persist the server-host project root this repo scopes to (multi-root serving). */
|
|
42
|
+
export declare function writeRepoServerProjectRoot(projectRoot: string, serverProjectRoot: string): void;
|
|
43
|
+
/** Whether this repo's selected connection targets a remote Rig server. */
|
|
44
|
+
export declare function isRemoteConnectionSelected(projectRoot: string): boolean;
|
|
@@ -6,12 +6,19 @@ import { dirname, resolve } from "path";
|
|
|
6
6
|
|
|
7
7
|
// packages/cli/src/runner.ts
|
|
8
8
|
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
9
|
-
import { CliError } from "@rig/runtime/control-plane/errors";
|
|
9
|
+
import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
|
|
10
10
|
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
11
|
-
import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
|
|
12
|
-
import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
|
|
13
11
|
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
14
|
-
|
|
12
|
+
|
|
13
|
+
class CliError extends RuntimeCliError {
|
|
14
|
+
hint;
|
|
15
|
+
constructor(message, exitCode = 1, options = {}) {
|
|
16
|
+
super(message, exitCode);
|
|
17
|
+
if (options.hint?.trim()) {
|
|
18
|
+
this.hint = options.hint.trim();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
15
22
|
|
|
16
23
|
// packages/cli/src/commands/_connection-state.ts
|
|
17
24
|
function resolveGlobalConnectionsPath(env = process.env) {
|
|
@@ -32,7 +39,7 @@ function readJsonFile(path) {
|
|
|
32
39
|
try {
|
|
33
40
|
return JSON.parse(readFileSync(path, "utf8"));
|
|
34
41
|
} catch (error) {
|
|
35
|
-
throw new
|
|
42
|
+
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>`." });
|
|
36
43
|
}
|
|
37
44
|
}
|
|
38
45
|
function writeJsonFile(path, value) {
|
|
@@ -75,7 +82,7 @@ function writeGlobalConnections(state, options = {}) {
|
|
|
75
82
|
function upsertGlobalConnection(alias, connection, options = {}) {
|
|
76
83
|
const cleanAlias = alias.trim();
|
|
77
84
|
if (!cleanAlias)
|
|
78
|
-
throw new
|
|
85
|
+
throw new CliError("Connection alias is required.", 1, { hint: "Save a server with `rig server add <alias> <url>`." });
|
|
79
86
|
const state = readGlobalConnections(options);
|
|
80
87
|
state.connections[cleanAlias] = connection;
|
|
81
88
|
writeGlobalConnections(state, options);
|
|
@@ -92,7 +99,8 @@ function readRepoConnection(projectRoot) {
|
|
|
92
99
|
return {
|
|
93
100
|
selected,
|
|
94
101
|
project: typeof record.project === "string" ? record.project : undefined,
|
|
95
|
-
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
|
|
102
|
+
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
|
|
103
|
+
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
96
104
|
};
|
|
97
105
|
}
|
|
98
106
|
function writeRepoConnection(projectRoot, state) {
|
|
@@ -103,15 +111,25 @@ function resolveSelectedConnection(projectRoot, options = {}) {
|
|
|
103
111
|
if (!repo)
|
|
104
112
|
return null;
|
|
105
113
|
if (repo.selected === "local")
|
|
106
|
-
return { alias: "local", connection: { kind: "local", mode: "auto" } };
|
|
114
|
+
return { alias: "local", connection: { kind: "local", mode: "auto" }, serverProjectRoot: repo.serverProjectRoot };
|
|
107
115
|
const global = readGlobalConnections(options);
|
|
108
116
|
const connection = global.connections[repo.selected];
|
|
109
117
|
if (!connection) {
|
|
110
|
-
throw new
|
|
118
|
+
throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
111
119
|
}
|
|
112
|
-
return { alias: repo.selected, connection };
|
|
120
|
+
return { alias: repo.selected, connection, serverProjectRoot: repo.serverProjectRoot };
|
|
121
|
+
}
|
|
122
|
+
function writeRepoServerProjectRoot(projectRoot, serverProjectRoot) {
|
|
123
|
+
const repo = readRepoConnection(projectRoot);
|
|
124
|
+
if (!repo)
|
|
125
|
+
return;
|
|
126
|
+
writeRepoConnection(projectRoot, { ...repo, serverProjectRoot });
|
|
127
|
+
}
|
|
128
|
+
function isRemoteConnectionSelected(projectRoot) {
|
|
129
|
+
return resolveSelectedConnection(projectRoot)?.connection.kind === "remote";
|
|
113
130
|
}
|
|
114
131
|
export {
|
|
132
|
+
writeRepoServerProjectRoot,
|
|
115
133
|
writeRepoConnection,
|
|
116
134
|
writeGlobalConnections,
|
|
117
135
|
upsertGlobalConnection,
|
|
@@ -119,5 +137,6 @@ export {
|
|
|
119
137
|
resolveRepoConnectionPath,
|
|
120
138
|
resolveGlobalConnectionsPath,
|
|
121
139
|
readRepoConnection,
|
|
122
|
-
readGlobalConnections
|
|
140
|
+
readGlobalConnections,
|
|
141
|
+
isRemoteConnectionSelected
|
|
123
142
|
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
type DoctorConfig = {
|
|
2
|
+
readonly project?: Record<string, unknown>;
|
|
3
|
+
readonly taskSource?: {
|
|
4
|
+
readonly kind?: string;
|
|
5
|
+
readonly owner?: string;
|
|
6
|
+
readonly repo?: string;
|
|
7
|
+
};
|
|
8
|
+
readonly github?: {
|
|
9
|
+
readonly projects?: {
|
|
10
|
+
readonly enabled?: boolean;
|
|
11
|
+
readonly projectId?: string;
|
|
12
|
+
readonly statusFieldId?: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
readonly pr?: {
|
|
16
|
+
readonly mode?: string;
|
|
17
|
+
};
|
|
18
|
+
readonly merge?: {
|
|
19
|
+
readonly mode?: string;
|
|
20
|
+
readonly method?: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
import { type PiInstallCheck } from "./_pi-install";
|
|
24
|
+
export type DoctorStatus = "pass" | "warn" | "fail";
|
|
25
|
+
export type RigDoctorCheck = {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly label: string;
|
|
28
|
+
readonly status: DoctorStatus;
|
|
29
|
+
readonly detail?: string;
|
|
30
|
+
readonly remediation?: string;
|
|
31
|
+
};
|
|
32
|
+
export type RigDoctorServer = {
|
|
33
|
+
readonly baseUrl: string;
|
|
34
|
+
readonly authToken: string | null;
|
|
35
|
+
readonly connectionKind: "local" | "remote";
|
|
36
|
+
};
|
|
37
|
+
export type RunRigDoctorChecksOptions = {
|
|
38
|
+
readonly projectRoot: string;
|
|
39
|
+
readonly resolveServer?: (projectRoot: string) => Promise<RigDoctorServer>;
|
|
40
|
+
readonly requestJson?: (pathname: string, init?: RequestInit) => Promise<unknown>;
|
|
41
|
+
readonly piChecks?: () => Promise<readonly PiInstallCheck[]>;
|
|
42
|
+
readonly which?: (binary: string) => string | null;
|
|
43
|
+
readonly bunVersion?: string;
|
|
44
|
+
readonly loadConfig?: (projectRoot: string) => Promise<DoctorConfig | null>;
|
|
45
|
+
/** Per-check status narration ("Checking GitHub auth…") for wait spinners. */
|
|
46
|
+
readonly onProgress?: (label: string) => void;
|
|
47
|
+
};
|
|
48
|
+
export declare function runRigDoctorChecks(options: RunRigDoctorChecksOptions): Promise<RigDoctorCheck[]>;
|
|
49
|
+
export declare function formatDoctorChecks(checks: readonly RigDoctorCheck[]): string;
|
|
50
|
+
export declare function countDoctorFailures(checks: readonly RigDoctorCheck[]): number;
|
|
51
|
+
export declare function throwIfDoctorFailed(checks: readonly RigDoctorCheck[]): void;
|
|
52
|
+
export {};
|