@h-rig/cli 0.0.6-alpha.90 → 0.0.6-alpha.92
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 +18 -19
- package/dist/bin/build-rig-binaries.js +22 -10
- package/dist/bin/rig.d.ts +71 -1
- package/dist/bin/rig.js +15078 -11169
- package/dist/config/rig-default-config.yml +5 -0
- package/dist/src/app/drone-ui.d.ts +11 -14
- package/dist/src/app/drone-ui.js +70 -86
- package/dist/src/commands/_async-ui.d.ts +1 -4
- package/dist/src/commands/_async-ui.js +9 -111
- package/dist/src/commands/_cli-format.d.ts +16 -9
- package/dist/src/commands/_cli-format.js +167 -295
- package/dist/src/commands/_connection-state.d.ts +11 -1
- package/dist/src/commands/_connection-state.js +50 -5
- package/dist/src/commands/_doctor-checks.d.ts +0 -6
- package/dist/src/commands/_doctor-checks.js +79 -382
- package/dist/src/commands/_help-catalog.d.ts +1 -1
- package/dist/src/commands/_help-catalog.js +217 -157
- package/dist/src/commands/_inprocess-services.d.ts +33 -0
- package/dist/src/commands/_inprocess-services.js +102 -0
- package/dist/src/commands/_json-output.js +4 -0
- package/dist/src/commands/_lazy-reconcile.d.ts +34 -0
- package/dist/src/commands/_lazy-reconcile.js +102 -0
- package/dist/src/commands/_paths.js +1 -1
- package/dist/src/commands/_pi-frontend.d.ts +18 -10
- package/dist/src/commands/_pi-frontend.js +37 -715
- package/dist/src/commands/_pi-install.js +18 -36
- package/dist/src/commands/_policy.d.ts +1 -1
- package/dist/src/commands/_policy.js +56 -15
- package/dist/src/commands/_run-bridge.d.ts +114 -0
- package/dist/src/commands/_run-bridge.js +387 -0
- package/dist/src/commands/_run-diagnostics.d.ts +9 -0
- package/dist/src/commands/_run-diagnostics.js +51 -0
- package/dist/src/commands/_run-driver-helpers.d.ts +8 -81
- package/dist/src/commands/_run-driver-helpers.js +79 -283
- package/dist/src/commands/_run-projection.d.ts +50 -0
- package/dist/src/commands/_run-projection.js +349 -0
- package/dist/src/commands/_run-subcommands.d.ts +3 -0
- package/dist/src/commands/_run-subcommands.js +31 -0
- package/dist/src/commands/_spinner.js +1 -1
- package/dist/src/commands/agent.d.ts +1 -1
- package/dist/src/commands/agent.js +8559 -239
- package/dist/src/commands/dist.d.ts +1 -1
- package/dist/src/commands/dist.js +27 -19
- package/dist/src/commands/doctor.d.ts +1 -1
- package/dist/src/commands/doctor.js +93 -475
- package/dist/src/commands/github.d.ts +1 -1
- package/dist/src/commands/github.js +113 -387
- package/dist/src/commands/inbox.d.ts +22 -24
- package/dist/src/commands/inbox.js +420 -691
- package/dist/src/commands/init.d.ts +6 -16
- package/dist/src/commands/init.js +334 -971
- package/dist/src/commands/inspect.d.ts +19 -2
- package/dist/src/commands/inspect.js +644 -610
- package/dist/src/commands/pi.d.ts +1 -1
- package/dist/src/commands/plugin.d.ts +1 -1
- package/dist/src/commands/plugin.js +486 -7
- package/dist/src/commands/profile-and-review.d.ts +1 -1
- package/dist/src/commands/profile-and-review.js +94 -56
- package/dist/src/commands/queue.js +1 -21
- package/dist/src/commands/remote.d.ts +1 -1
- package/dist/src/commands/remote.js +837 -14
- package/dist/src/commands/repo-git-harness.d.ts +1 -1
- package/dist/src/commands/repo-git-harness.js +57 -14
- package/dist/src/commands/run.d.ts +20 -2
- package/dist/src/commands/run.js +17579 -1759
- package/dist/src/commands/server.d.ts +2 -6
- package/dist/src/commands/server.js +141 -723
- package/dist/src/commands/setup.d.ts +1 -1
- package/dist/src/commands/setup.js +102 -484
- package/dist/src/commands/stats.d.ts +13 -10
- package/dist/src/commands/stats.js +689 -761
- package/dist/src/commands/task-run-driver.d.ts +50 -88
- package/dist/src/commands/task-run-driver.js +116 -2717
- package/dist/src/commands/task.d.ts +34 -13
- package/dist/src/commands/task.js +668 -2523
- package/dist/src/commands/test.d.ts +1 -1
- package/dist/src/commands/triage.d.ts +11 -0
- package/dist/src/commands/triage.js +227 -0
- package/dist/src/commands/workspace.d.ts +1 -1
- package/dist/src/commands.d.ts +0 -16
- package/dist/src/commands.js +16657 -12250
- package/dist/src/index.js +16528 -12497
- package/dist/src/launcher.js +4 -0
- package/dist/src/operator-cli.d.ts +2 -0
- package/dist/src/operator-cli.js +17837 -0
- package/dist/src/operator-entry.d.ts +1 -0
- package/dist/src/operator-entry.js +3 -0
- package/package.json +18 -12
- package/dist/src/app/board.d.ts +0 -23
- package/dist/src/app/board.js +0 -1786
- package/dist/src/app/theme.d.ts +0 -47
- package/dist/src/app/theme.js +0 -150
- package/dist/src/commands/_authority-runs.d.ts +0 -22
- package/dist/src/commands/_authority-runs.js +0 -110
- package/dist/src/commands/_operator-surface.d.ts +0 -34
- package/dist/src/commands/_operator-surface.js +0 -220
- package/dist/src/commands/_operator-view.d.ts +0 -30
- package/dist/src/commands/_operator-view.js +0 -1070
- package/dist/src/commands/_preflight.d.ts +0 -22
- package/dist/src/commands/_preflight.js +0 -540
- package/dist/src/commands/_run-replay.d.ts +0 -24
- package/dist/src/commands/_run-replay.js +0 -142
- package/dist/src/commands/_server-client.d.ts +0 -186
- package/dist/src/commands/_server-client.js +0 -681
- package/dist/src/commands/_snapshot-upload.d.ts +0 -39
- package/dist/src/commands/_snapshot-upload.js +0 -455
- package/dist/src/commands/_task-picker.d.ts +0 -9
- package/dist/src/commands/_task-picker.js +0 -201
- package/dist/src/commands/browser.d.ts +0 -65
- package/dist/src/commands/browser.js +0 -1173
- package/dist/src/commands/connect.d.ts +0 -7
- package/dist/src/commands/connect.js +0 -419
- package/dist/src/commands/inspector.d.ts +0 -3
- package/dist/src/commands/inspector.js +0 -263
- package/dist/src/commands/task-report-bug.d.ts +0 -19
- package/dist/src/commands/task-report-bug.js +0 -1281
- package/dist/src/report-bug.d.ts +0 -44
- package/dist/src/report-bug.js +0 -260
|
@@ -42,174 +42,16 @@ Usage: ${usage}`);
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
// packages/cli/src/commands/server.ts
|
|
45
|
-
import { resolveRigServerCommand } from "@rig/runtime/local-server";
|
|
46
|
-
|
|
47
|
-
// packages/cli/src/commands/_authority-runs.ts
|
|
48
45
|
import {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// packages/cli/src/commands/_paths.ts
|
|
55
|
-
import { resolveMonorepoRoot } from "@rig/runtime/control-plane/native/utils";
|
|
56
|
-
|
|
57
|
-
// packages/cli/src/commands/_authority-runs.ts
|
|
58
|
-
function normalizeRuntimeAdapter(value) {
|
|
59
|
-
const normalized = value?.trim().toLowerCase();
|
|
60
|
-
if (!normalized) {
|
|
61
|
-
return "pi";
|
|
62
|
-
}
|
|
63
|
-
if (normalized === "codex" || normalized === "codex-cli" || normalized === "codex-app-server" || normalized === "gpt-codex") {
|
|
64
|
-
return "codex";
|
|
65
|
-
}
|
|
66
|
-
if (normalized === "pi" || normalized === "rig-pi" || normalized === "@rig/pi") {
|
|
67
|
-
return "pi";
|
|
68
|
-
}
|
|
69
|
-
return "claude-code";
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// packages/cli/src/app/drone-ui.ts
|
|
73
|
-
import { ProcessTerminal, TUI, Text, Input, SelectList, matchesKey } from "@earendil-works/pi-tui";
|
|
74
|
-
|
|
75
|
-
// packages/cli/src/app/theme.ts
|
|
76
|
-
var RIG_PALETTE = {
|
|
77
|
-
ink: "#f2f3f6",
|
|
78
|
-
ink2: "#aeb0ba",
|
|
79
|
-
ink3: "#6c6e79",
|
|
80
|
-
ink4: "#44464f",
|
|
81
|
-
accent: "#ccff4d",
|
|
82
|
-
accentDim: "#a9d63f",
|
|
83
|
-
cyan: "#56d8ff",
|
|
84
|
-
red: "#ff5d5d",
|
|
85
|
-
yellow: "#ffd24d"
|
|
86
|
-
};
|
|
87
|
-
function hexToRgb(hex) {
|
|
88
|
-
const value = hex.replace("#", "");
|
|
89
|
-
return [
|
|
90
|
-
Number.parseInt(value.slice(0, 2), 16),
|
|
91
|
-
Number.parseInt(value.slice(2, 4), 16),
|
|
92
|
-
Number.parseInt(value.slice(4, 6), 16)
|
|
93
|
-
];
|
|
94
|
-
}
|
|
95
|
-
function fg(hex) {
|
|
96
|
-
const [r, g, b] = hexToRgb(hex);
|
|
97
|
-
return (text) => `\x1B[38;2;${r};${g};${b}m${text}\x1B[39m`;
|
|
98
|
-
}
|
|
99
|
-
var ink = fg(RIG_PALETTE.ink);
|
|
100
|
-
var ink2 = fg(RIG_PALETTE.ink2);
|
|
101
|
-
var ink3 = fg(RIG_PALETTE.ink3);
|
|
102
|
-
var ink4 = fg(RIG_PALETTE.ink4);
|
|
103
|
-
var accent = fg(RIG_PALETTE.accent);
|
|
104
|
-
var accentDim = fg(RIG_PALETTE.accentDim);
|
|
105
|
-
var cyan = fg(RIG_PALETTE.cyan);
|
|
106
|
-
var red = fg(RIG_PALETTE.red);
|
|
107
|
-
var yellow = fg(RIG_PALETTE.yellow);
|
|
108
|
-
function bold(text) {
|
|
109
|
-
return `\x1B[1m${text}\x1B[22m`;
|
|
110
|
-
}
|
|
111
|
-
var DRONE_ART = [
|
|
112
|
-
" .-=-. .-=-. ",
|
|
113
|
-
" ( !!! ) ( !!! ) ",
|
|
114
|
-
" '-=-'._ _.'-=-' ",
|
|
115
|
-
" '._ _.' ",
|
|
116
|
-
" '=$$$$$$$=.' ",
|
|
117
|
-
" =$$$$$$$$$$$= ",
|
|
118
|
-
" $$$@@@@@@@@@@$$$ ",
|
|
119
|
-
" $$$@@ @@$$$ ",
|
|
120
|
-
" $$@ ? @$$$ ",
|
|
121
|
-
" $$$@ '-' @$$$ ",
|
|
122
|
-
" $$$@@ @@$$$ ",
|
|
123
|
-
" $$$@@@@@@@@@@$$$ ",
|
|
124
|
-
" =$$$$$$$$$$$= ",
|
|
125
|
-
" '=$$$$$$$=.' ",
|
|
126
|
-
" _.' '._ ",
|
|
127
|
-
" .-=-.' '.-=-. ",
|
|
128
|
-
" ( !!! ) ( !!! ) ",
|
|
129
|
-
" '-=-' '-=-' "
|
|
130
|
-
];
|
|
131
|
-
var EYE_FRAMES = ["@", "o", "."];
|
|
132
|
-
var DRONE_WIDTH = DRONE_ART[0].length;
|
|
133
|
-
var DRONE_HEIGHT = DRONE_ART.length;
|
|
134
|
-
var MICRO_BLADES = ["---", "\\\\\\", "|||", "///"];
|
|
135
|
-
function microDroneFrame(tick) {
|
|
136
|
-
const blade = MICRO_BLADES[tick % MICRO_BLADES.length];
|
|
137
|
-
const eye = EYE_FRAMES[Math.floor(tick / 2) % EYE_FRAMES.length];
|
|
138
|
-
return `(${blade})${eye}(${blade})`;
|
|
139
|
-
}
|
|
140
|
-
var MICRO_DRONE_FRAMES = Array.from({ length: 12 }, (_, index) => microDroneFrame(index));
|
|
141
|
-
|
|
142
|
-
// packages/cli/src/app/drone-ui.ts
|
|
143
|
-
var isTty = () => Boolean(process.stdout.isTTY);
|
|
144
|
-
function droneCancel(text) {
|
|
145
|
-
console.log(` ${red("\u2716")} ${ink3(text)}`);
|
|
146
|
-
}
|
|
147
|
-
var SELECT_THEME = {
|
|
148
|
-
selectedPrefix: (text) => accent(text),
|
|
149
|
-
selectedText: (text) => bold(ink(text)),
|
|
150
|
-
description: (text) => ink3(text),
|
|
151
|
-
scrollInfo: (text) => ink4(text),
|
|
152
|
-
noMatch: (text) => ink3(text)
|
|
153
|
-
};
|
|
154
|
-
async function runMiniTui(build) {
|
|
155
|
-
const terminal = new ProcessTerminal;
|
|
156
|
-
const tui = new TUI(terminal);
|
|
157
|
-
let settled = false;
|
|
158
|
-
return await new Promise((resolve) => {
|
|
159
|
-
const finish = (result) => {
|
|
160
|
-
if (settled)
|
|
161
|
-
return;
|
|
162
|
-
settled = true;
|
|
163
|
-
tui.stop();
|
|
164
|
-
resolve(result);
|
|
165
|
-
};
|
|
166
|
-
build(tui, finish);
|
|
167
|
-
tui.start();
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
async function droneSelect(input) {
|
|
171
|
-
if (!isTty() || input.options.length === 0) {
|
|
172
|
-
return input.initialValue ?? input.options[0]?.value ?? null;
|
|
173
|
-
}
|
|
174
|
-
return runMiniTui((tui, finish) => {
|
|
175
|
-
tui.addChild(new Text(` ${accent("\u258D")}${bold(ink(input.message))}`));
|
|
176
|
-
const items = input.options.map((option) => ({
|
|
177
|
-
value: option.value,
|
|
178
|
-
label: option.label,
|
|
179
|
-
...option.hint ? { description: option.hint } : {}
|
|
180
|
-
}));
|
|
181
|
-
const list = new SelectList(items, Math.min(items.length, 12), SELECT_THEME);
|
|
182
|
-
const initialIndex = input.initialValue ? items.findIndex((item) => item.value === input.initialValue) : -1;
|
|
183
|
-
if (initialIndex > 0)
|
|
184
|
-
list.setSelectedIndex(initialIndex);
|
|
185
|
-
list.onSelect = (item) => finish(item.value);
|
|
186
|
-
list.onCancel = () => finish(null);
|
|
187
|
-
tui.addChild(list);
|
|
188
|
-
tui.addChild(new Text(ink4(" \u2191\u2193 navigate \xB7 enter select \xB7 esc cancel")));
|
|
189
|
-
tui.setFocus(list);
|
|
190
|
-
tui.addInputListener((data) => {
|
|
191
|
-
if (matchesKey(data, "ctrl+c") || matchesKey(data, "escape")) {
|
|
192
|
-
finish(null);
|
|
193
|
-
return { consume: true };
|
|
194
|
-
}
|
|
195
|
-
return;
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
}
|
|
46
|
+
listManagedRemoteEndpoints,
|
|
47
|
+
removeManagedRemoteEndpoint,
|
|
48
|
+
resolveSelectedRemote as resolveSelectedRemote2,
|
|
49
|
+
upsertManagedRemoteEndpoint
|
|
50
|
+
} from "@rig/runtime/control-plane/remote";
|
|
199
51
|
|
|
200
52
|
// packages/cli/src/commands/_connection-state.ts
|
|
201
53
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
202
|
-
import { homedir } from "os";
|
|
203
54
|
import { dirname, resolve } from "path";
|
|
204
|
-
function resolveGlobalConnectionsPath(env = process.env) {
|
|
205
|
-
const explicit = env.RIG_CONNECTIONS_FILE?.trim();
|
|
206
|
-
if (explicit)
|
|
207
|
-
return resolve(explicit);
|
|
208
|
-
const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
|
|
209
|
-
if (stateDir)
|
|
210
|
-
return resolve(stateDir, "connections.json");
|
|
211
|
-
return resolve(homedir(), ".rig", "connections.json");
|
|
212
|
-
}
|
|
213
55
|
function resolveRepoConnectionPath(projectRoot) {
|
|
214
56
|
return resolve(projectRoot, ".rig", "state", "connection.json");
|
|
215
57
|
}
|
|
@@ -227,47 +69,6 @@ function writeJsonFile(path, value) {
|
|
|
227
69
|
writeFileSync(path, `${JSON.stringify(value, null, 2)}
|
|
228
70
|
`, "utf8");
|
|
229
71
|
}
|
|
230
|
-
function normalizeConnection(value) {
|
|
231
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
232
|
-
return null;
|
|
233
|
-
const record = value;
|
|
234
|
-
if (record.kind === "local")
|
|
235
|
-
return { kind: "local", mode: "auto" };
|
|
236
|
-
if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
|
|
237
|
-
const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
|
|
238
|
-
return { kind: "remote", baseUrl };
|
|
239
|
-
}
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
function readGlobalConnections(options = {}) {
|
|
243
|
-
const path = resolveGlobalConnectionsPath(options.env ?? process.env);
|
|
244
|
-
const payload = readJsonFile(path);
|
|
245
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
246
|
-
return { connections: {} };
|
|
247
|
-
}
|
|
248
|
-
const rawConnections = payload.connections;
|
|
249
|
-
const connections = {};
|
|
250
|
-
if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
|
|
251
|
-
for (const [alias, raw] of Object.entries(rawConnections)) {
|
|
252
|
-
const connection = normalizeConnection(raw);
|
|
253
|
-
if (connection)
|
|
254
|
-
connections[alias] = connection;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
return { connections };
|
|
258
|
-
}
|
|
259
|
-
function writeGlobalConnections(state, options = {}) {
|
|
260
|
-
writeJsonFile(resolveGlobalConnectionsPath(options.env ?? process.env), state);
|
|
261
|
-
}
|
|
262
|
-
function upsertGlobalConnection(alias, connection, options = {}) {
|
|
263
|
-
const cleanAlias = alias.trim();
|
|
264
|
-
if (!cleanAlias)
|
|
265
|
-
throw new CliError("Connection alias is required.", 1, { hint: "Save a server with `rig server add <alias> <url>`." });
|
|
266
|
-
const state = readGlobalConnections(options);
|
|
267
|
-
state.connections[cleanAlias] = connection;
|
|
268
|
-
writeGlobalConnections(state, options);
|
|
269
|
-
return state;
|
|
270
|
-
}
|
|
271
72
|
function readRepoConnection(projectRoot) {
|
|
272
73
|
const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
|
|
273
74
|
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
@@ -280,550 +81,167 @@ function readRepoConnection(projectRoot) {
|
|
|
280
81
|
selected,
|
|
281
82
|
project: typeof record.project === "string" ? record.project : undefined,
|
|
282
83
|
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
|
|
283
|
-
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
84
|
+
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined,
|
|
85
|
+
serverProjectRootAlias: typeof record.serverProjectRootAlias === "string" && record.serverProjectRootAlias.trim() ? record.serverProjectRootAlias.trim() : undefined,
|
|
86
|
+
serverProjectRootBaseUrl: typeof record.serverProjectRootBaseUrl === "string" && record.serverProjectRootBaseUrl.trim() ? record.serverProjectRootBaseUrl.trim().replace(/\/+$/, "") : undefined
|
|
284
87
|
};
|
|
285
88
|
}
|
|
286
89
|
function writeRepoConnection(projectRoot, state) {
|
|
287
90
|
writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
|
|
288
91
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
92
|
+
|
|
93
|
+
// packages/cli/src/commands/_run-bridge.ts
|
|
94
|
+
import { dirname as dirname2, resolve as resolve2 } from "path";
|
|
95
|
+
import { CUSTOM_TYPE_FOR, sessionIdFromSessionFile } from "@rig/contracts";
|
|
96
|
+
import { createPluginHost } from "@rig/core";
|
|
97
|
+
import { loadConfig } from "@rig/core/load-config";
|
|
98
|
+
import { resolveOwnerNamespaceKey, resolveRegistryBaseUrl, resolveRegistrySecret, resolveSelectedRemote } from "@rig/runtime/control-plane/remote";
|
|
99
|
+
import { listAgentRuntimes } from "@rig/runtime/control-plane/runtime/isolation";
|
|
100
|
+
import { createRegistryClient } from "@rig/relay-registry";
|
|
101
|
+
import {
|
|
102
|
+
listActiveCollabSessions as ompListActiveCollabSessions
|
|
103
|
+
} from "@oh-my-pi/pi-coding-agent/collab/api";
|
|
104
|
+
async function readSelectedTarget(projectRoot, env = process.env) {
|
|
105
|
+
const config = await loadConfig(resolve2(projectRoot));
|
|
106
|
+
const selected = resolveSelectedRemote(projectRoot, env);
|
|
107
|
+
return {
|
|
108
|
+
alias: selected?.alias ?? "local",
|
|
109
|
+
kind: selected ? "remote" : "local",
|
|
110
|
+
projectRoot,
|
|
111
|
+
status: "ready",
|
|
112
|
+
taskSource: config.taskSource.kind
|
|
113
|
+
};
|
|
307
114
|
}
|
|
308
115
|
|
|
309
116
|
// packages/cli/src/commands/_cli-format.ts
|
|
310
117
|
import pc from "picocolors";
|
|
311
|
-
var
|
|
312
|
-
var
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (width <= 1)
|
|
317
|
-
return "\u2026";
|
|
318
|
-
return `${value.slice(0, width - 1)}\u2026`;
|
|
319
|
-
}
|
|
320
|
-
function pad(value, width) {
|
|
321
|
-
return value.length >= width ? value : `${value}${" ".repeat(width - value.length)}`;
|
|
322
|
-
}
|
|
323
|
-
function statusColor(status) {
|
|
324
|
-
const normalized = status.toLowerCase();
|
|
325
|
-
if (["completed", "merged", "closed", "done", "accepted", "pass", "selected", "approved", "running"].includes(normalized))
|
|
326
|
-
return accent;
|
|
327
|
-
if (["failed", "needs_attention", "needs-attention", "blocked", "error", "rejected"].includes(normalized))
|
|
328
|
-
return red;
|
|
329
|
-
if (["reviewing", "validating", "in_progress", "in-progress", "remote", "preparing", "closing-out"].includes(normalized))
|
|
330
|
-
return cyan;
|
|
331
|
-
if (["ready", "open", "queued", "created", "local", "pending"].includes(normalized))
|
|
332
|
-
return yellow;
|
|
333
|
-
return themeDim;
|
|
334
|
-
}
|
|
335
|
-
function formatStatusPill(status) {
|
|
336
|
-
const label = status || "unknown";
|
|
337
|
-
return statusColor(label)(`\u25CF ${label}`);
|
|
338
|
-
}
|
|
339
|
-
function formatSection(title, subtitle) {
|
|
340
|
-
return `${pc.bold(accent("\u25C6"))} ${pc.bold(title)}${subtitle ? themeDim(` \u2014 ${subtitle}`) : ""}`;
|
|
341
|
-
}
|
|
342
|
-
function formatSuccessCard(title, rows = []) {
|
|
343
|
-
const body = rows.filter(([, value]) => value !== undefined && value !== null && String(value).length > 0).map(([key, value]) => `${themeFaint("\u2502")} ${themeDim(key.padEnd(12))} ${value}`);
|
|
344
|
-
return [formatSection(title), ...body].join(`
|
|
345
|
-
`);
|
|
346
|
-
}
|
|
347
|
-
function formatNextSteps(steps) {
|
|
348
|
-
if (steps.length === 0)
|
|
349
|
-
return [];
|
|
350
|
-
return [pc.bold("Next"), ...steps.map((step) => `${accent("\u203A")} ${step}`)];
|
|
351
|
-
}
|
|
352
|
-
function formatConnectionList(connections) {
|
|
353
|
-
const rows = [["local", { kind: "local", mode: "auto" }], ...Object.entries(connections)];
|
|
354
|
-
const aliasWidth = Math.min(24, Math.max(5, ...rows.map(([alias]) => alias.length)));
|
|
355
|
-
const lines = rows.map(([alias, connection]) => [
|
|
356
|
-
pc.bold(pad(truncate(alias, aliasWidth), aliasWidth)),
|
|
357
|
-
formatStatusPill(connection.kind),
|
|
358
|
-
connection.kind === "remote" ? connection.baseUrl ?? "" : connection.mode ?? "local"
|
|
359
|
-
].join(" "));
|
|
360
|
-
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(`
|
|
361
|
-
`);
|
|
362
|
-
}
|
|
363
|
-
function formatConnectionStatus(selected, connections) {
|
|
364
|
-
const connection = selected === "local" ? { kind: "local", mode: "auto" } : connections[selected];
|
|
365
|
-
const target = !connection ? "not configured" : connection.kind === "remote" ? connection.baseUrl : "local";
|
|
366
|
-
return [
|
|
367
|
-
formatSection("Rig server", "selected for this repo"),
|
|
368
|
-
`${themeFaint("\u2502")} ${themeDim("selected ")} ${pc.bold(selected)}`,
|
|
369
|
-
`${themeFaint("\u2502")} ${themeDim("kind ")} ${formatStatusPill(connection?.kind ?? "unknown")}`,
|
|
370
|
-
`${themeFaint("\u2502")} ${themeDim("target ")} ${target ?? "not configured"}`,
|
|
371
|
-
"",
|
|
372
|
-
...formatNextSteps(["Change: `rig server use <alias|local>`", "List saved servers: `rig server list`"])
|
|
373
|
-
].join(`
|
|
374
|
-
`);
|
|
118
|
+
var dim = pc.dim;
|
|
119
|
+
var faintBar = pc.dim("\u2502");
|
|
120
|
+
var accent = pc.cyan;
|
|
121
|
+
function printFormattedOutput(message) {
|
|
122
|
+
console.log(message);
|
|
375
123
|
}
|
|
376
124
|
|
|
377
|
-
// packages/cli/src/commands/
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
if (!value)
|
|
385
|
-
throw new CliError(`Missing remote server URL. Usage: ${usageName(options)} add <alias> <url>`, 1);
|
|
386
|
-
let parsed;
|
|
387
|
-
try {
|
|
388
|
-
parsed = new URL(value);
|
|
389
|
-
} catch {
|
|
390
|
-
throw new CliError(`Invalid Rig server URL: ${value}`, 1, { hint: "Pass a full http(s) URL, e.g. `rig server add prod https://rig.example.com`." });
|
|
391
|
-
}
|
|
392
|
-
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
|
|
393
|
-
throw new CliError("Rig remote server URL must be http(s).", 1, { hint: "Use an http:// or https:// URL, e.g. `rig server add prod https://rig.example.com`." });
|
|
394
|
-
}
|
|
395
|
-
return { kind: "remote", baseUrl: parsed.toString().replace(/\/+$/, "") };
|
|
396
|
-
}
|
|
397
|
-
function printJsonOrText(context, payload, text) {
|
|
398
|
-
if (context.outputMode === "json") {
|
|
399
|
-
console.log(JSON.stringify(payload, null, 2));
|
|
400
|
-
} else {
|
|
401
|
-
console.log(text);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
async function promptForConnectionAlias(context) {
|
|
405
|
-
const state = readGlobalConnections();
|
|
406
|
-
const repo = readRepoConnection(context.projectRoot);
|
|
407
|
-
const options = [
|
|
408
|
-
{ value: "local", label: "local", hint: "Use/start a local Rig server" },
|
|
409
|
-
...Object.entries(state.connections).map(([alias, connection]) => ({
|
|
410
|
-
value: alias,
|
|
411
|
-
label: alias,
|
|
412
|
-
hint: connection.kind === "remote" ? connection.baseUrl : "local"
|
|
413
|
-
}))
|
|
414
|
-
].filter((option, index, all) => all.findIndex((candidate) => candidate.value === option.value) === index);
|
|
415
|
-
const answer = await droneSelect({
|
|
416
|
-
message: "Select Rig server for this repo",
|
|
417
|
-
initialValue: repo?.selected ?? "local",
|
|
418
|
-
options
|
|
419
|
-
});
|
|
420
|
-
if (answer === null) {
|
|
421
|
-
droneCancel("No server selected.");
|
|
422
|
-
throw new CliError("No server selected.", 3);
|
|
423
|
-
}
|
|
424
|
-
return String(answer);
|
|
425
|
-
}
|
|
426
|
-
async function executeConnectionCommand(context, args, options) {
|
|
427
|
-
const [command, ...rest] = args;
|
|
428
|
-
switch (command ?? "status") {
|
|
429
|
-
case "list": {
|
|
430
|
-
requireNoExtraArgs(rest, `${usageName(options)} list`);
|
|
431
|
-
const state = readGlobalConnections();
|
|
432
|
-
printJsonOrText(context, state, formatConnectionList(state.connections));
|
|
433
|
-
return { ok: true, group: options.group, command: "list", details: state };
|
|
434
|
-
}
|
|
435
|
-
case "add": {
|
|
436
|
-
const [alias, url, ...extra] = rest;
|
|
437
|
-
if (!alias)
|
|
438
|
-
throw new CliError(`Missing alias. Usage: ${usageName(options)} add <alias> <url>`, 1);
|
|
439
|
-
requireNoExtraArgs(extra, `${usageName(options)} add <alias> <url>`);
|
|
440
|
-
const connection = parseConnection(alias, url, options);
|
|
441
|
-
const state = upsertGlobalConnection(alias, connection);
|
|
442
|
-
printJsonOrText(context, { alias, connection }, formatSuccessCard("Rig server saved", [
|
|
443
|
-
["alias", alias],
|
|
444
|
-
["target", connection.kind === "remote" ? connection.baseUrl : "local"],
|
|
445
|
-
["next", `${usageName(options)} use ${alias}`]
|
|
446
|
-
]));
|
|
447
|
-
return { ok: true, group: options.group, command: "add", details: { alias, connection, count: Object.keys(state.connections).length } };
|
|
448
|
-
}
|
|
449
|
-
case "use": {
|
|
450
|
-
let [alias, ...extra] = rest;
|
|
451
|
-
requireNoExtraArgs(extra, `${usageName(options)} use <alias|local>`);
|
|
452
|
-
if (!alias && options.interactiveUse && context.outputMode === "text" && process.stdin.isTTY) {
|
|
453
|
-
alias = await promptForConnectionAlias(context);
|
|
454
|
-
}
|
|
455
|
-
if (!alias)
|
|
456
|
-
throw new CliError(`Missing alias. Usage: ${usageName(options)} use <alias|local>`, 1);
|
|
457
|
-
if (alias !== "local") {
|
|
458
|
-
const state = readGlobalConnections();
|
|
459
|
-
if (!state.connections[alias])
|
|
460
|
-
throw new CliError(`Unknown Rig server: ${alias}`, 1, { hint: "Run `rig server list` to see saved aliases, or save one with `rig server add <alias> <url>`." });
|
|
461
|
-
}
|
|
462
|
-
const repoState = { selected: alias, linkedAt: new Date().toISOString() };
|
|
463
|
-
writeRepoConnection(context.projectRoot, repoState);
|
|
464
|
-
printJsonOrText(context, repoState, formatSuccessCard("Rig server selected", [
|
|
465
|
-
["selected", alias],
|
|
466
|
-
["scope", "this repo"],
|
|
467
|
-
["next", "rig task list"]
|
|
468
|
-
]));
|
|
469
|
-
return { ok: true, group: options.group, command: "use", details: repoState };
|
|
470
|
-
}
|
|
125
|
+
// packages/cli/src/commands/server.ts
|
|
126
|
+
var DEFAULT_REMOTE_PORT = 22;
|
|
127
|
+
async function executeServer(context, args) {
|
|
128
|
+
const [command = "status", ...rest] = args;
|
|
129
|
+
const text = context.outputMode === "text";
|
|
130
|
+
const projectRoot = context.projectRoot;
|
|
131
|
+
switch (command) {
|
|
471
132
|
case "status": {
|
|
472
|
-
requireNoExtraArgs(rest,
|
|
473
|
-
const
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
default:
|
|
480
|
-
throw new CliError(`Unknown ${options.group} command: ${String(command)}
|
|
481
|
-
Usage: ${usageName(options)} <list|add|use|status>`, 1);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
// packages/cli/src/commands/_server-client.ts
|
|
486
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
487
|
-
import { resolve as resolve2 } from "path";
|
|
488
|
-
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
489
|
-
var scopedGitHubBearerTokens = new Map;
|
|
490
|
-
var serverPhaseListener = null;
|
|
491
|
-
function reportServerPhase(label) {
|
|
492
|
-
serverPhaseListener?.(label);
|
|
493
|
-
}
|
|
494
|
-
function cleanToken(value) {
|
|
495
|
-
const trimmed = value?.trim();
|
|
496
|
-
return trimmed ? trimmed : null;
|
|
497
|
-
}
|
|
498
|
-
function readPrivateRemoteSessionToken(projectRoot) {
|
|
499
|
-
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
500
|
-
if (!existsSync2(path))
|
|
501
|
-
return null;
|
|
502
|
-
try {
|
|
503
|
-
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
504
|
-
return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
|
|
505
|
-
} catch {
|
|
506
|
-
return null;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
function readGitHubBearerTokenForRemote(projectRoot) {
|
|
510
|
-
const scopedKey = resolve2(projectRoot);
|
|
511
|
-
if (scopedGitHubBearerTokens.has(scopedKey))
|
|
512
|
-
return scopedGitHubBearerTokens.get(scopedKey) ?? null;
|
|
513
|
-
const privateSession = readPrivateRemoteSessionToken(projectRoot);
|
|
514
|
-
if (privateSession)
|
|
515
|
-
return privateSession;
|
|
516
|
-
return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
517
|
-
}
|
|
518
|
-
function readStoredGitHubAuthToken(projectRoot) {
|
|
519
|
-
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
520
|
-
if (!existsSync2(path))
|
|
521
|
-
return null;
|
|
522
|
-
try {
|
|
523
|
-
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
524
|
-
return cleanToken(typeof parsed.token === "string" ? parsed.token : undefined);
|
|
525
|
-
} catch {
|
|
526
|
-
return null;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
function readLocalConnectionFallbackToken(projectRoot) {
|
|
530
|
-
return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
|
|
531
|
-
}
|
|
532
|
-
async function ensureServerForCli(projectRoot) {
|
|
533
|
-
try {
|
|
534
|
-
const selected = resolveSelectedConnection(projectRoot);
|
|
535
|
-
if (selected?.connection.kind === "remote") {
|
|
536
|
-
reportServerPhase(`Connecting to ${selected.alias}\u2026`);
|
|
537
|
-
const authToken = readGitHubBearerTokenForRemote(projectRoot);
|
|
538
|
-
const serverProjectRoot = selected.serverProjectRoot ?? await backfillRemoteServerProjectRoot(projectRoot, selected.connection.baseUrl, authToken);
|
|
133
|
+
requireNoExtraArgs(rest, "rig server status");
|
|
134
|
+
const target = await readSelectedTarget(projectRoot);
|
|
135
|
+
const remote = resolveSelectedRemote2(projectRoot);
|
|
136
|
+
if (text) {
|
|
137
|
+
printFormattedOutput(target.kind === "local" ? "Placement: local (runs execute on this machine)." : `Placement: remote \u2192 ${target.alias}${remote ? ` (${remote.host}:${remote.port})` : ""}`);
|
|
138
|
+
printFormattedOutput(`Task source: ${target.taskSource}`);
|
|
139
|
+
}
|
|
539
140
|
return {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
141
|
+
ok: true,
|
|
142
|
+
group: "server",
|
|
143
|
+
command,
|
|
144
|
+
details: {
|
|
145
|
+
placement: target.kind,
|
|
146
|
+
alias: target.alias,
|
|
147
|
+
taskSource: target.taskSource,
|
|
148
|
+
...remote ? { host: remote.host, port: remote.port } : {}
|
|
149
|
+
}
|
|
544
150
|
};
|
|
545
151
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
|
|
562
|
-
const repo = readRepoConnection(projectRoot);
|
|
563
|
-
const slug = repo?.project?.trim();
|
|
564
|
-
if (!slug)
|
|
565
|
-
return null;
|
|
566
|
-
try {
|
|
567
|
-
const response = await fetch(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`, {
|
|
568
|
-
headers: mergeHeaders(undefined, authToken)
|
|
569
|
-
});
|
|
570
|
-
if (!response.ok)
|
|
571
|
-
return null;
|
|
572
|
-
const payload = await response.json();
|
|
573
|
-
const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
|
|
574
|
-
const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
|
|
575
|
-
const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
|
|
576
|
-
const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
|
|
577
|
-
if (path)
|
|
578
|
-
writeRepoServerProjectRoot(projectRoot, path);
|
|
579
|
-
return path;
|
|
580
|
-
} catch {
|
|
581
|
-
return null;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
function mergeHeaders(headers, authToken) {
|
|
585
|
-
const merged = new Headers(headers);
|
|
586
|
-
if (authToken) {
|
|
587
|
-
merged.set("authorization", `Bearer ${authToken}`);
|
|
588
|
-
}
|
|
589
|
-
return merged;
|
|
590
|
-
}
|
|
591
|
-
function diagnosticMessage(payload) {
|
|
592
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
593
|
-
return null;
|
|
594
|
-
const record = payload;
|
|
595
|
-
const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
|
|
596
|
-
const messages = diagnostics.flatMap((entry) => {
|
|
597
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
598
|
-
return [];
|
|
599
|
-
const diagnostic = entry;
|
|
600
|
-
const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
|
|
601
|
-
const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
|
|
602
|
-
return message ? [`${kind}: ${message}`] : [];
|
|
603
|
-
});
|
|
604
|
-
return messages.length > 0 ? messages.join("; ") : null;
|
|
605
|
-
}
|
|
606
|
-
var serverReachabilityCache = new Map;
|
|
607
|
-
async function probeServerReachability(baseUrl, authToken) {
|
|
608
|
-
try {
|
|
609
|
-
const response = await fetch(`${baseUrl.replace(/\/+$/, "")}/api/server/status`, {
|
|
610
|
-
headers: mergeHeaders(undefined, authToken),
|
|
611
|
-
signal: AbortSignal.timeout(1500)
|
|
612
|
-
});
|
|
613
|
-
return response.ok;
|
|
614
|
-
} catch {
|
|
615
|
-
return false;
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
function cachedServerReachability(projectRoot, baseUrl, authToken) {
|
|
619
|
-
const key = resolve2(projectRoot);
|
|
620
|
-
const cached = serverReachabilityCache.get(key);
|
|
621
|
-
if (cached)
|
|
622
|
-
return cached;
|
|
623
|
-
const probe = probeServerReachability(baseUrl, authToken);
|
|
624
|
-
serverReachabilityCache.set(key, probe);
|
|
625
|
-
return probe;
|
|
626
|
-
}
|
|
627
|
-
function describeSelectedServer(projectRoot, server) {
|
|
628
|
-
try {
|
|
629
|
-
const selected = resolveSelectedConnection(projectRoot);
|
|
630
|
-
if (selected) {
|
|
152
|
+
case "list": {
|
|
153
|
+
requireNoExtraArgs(rest, "rig server list");
|
|
154
|
+
const endpoints = listManagedRemoteEndpoints(undefined, projectRoot);
|
|
155
|
+
const selected = readRepoConnection(projectRoot)?.selected ?? "local";
|
|
156
|
+
if (text) {
|
|
157
|
+
printFormattedOutput(`${selected === "local" ? "* " : " "}local \u2014 runs execute on this machine`);
|
|
158
|
+
if (endpoints.length === 0) {
|
|
159
|
+
printFormattedOutput(" (no remote endpoints; add one with `rig server add --alias <a> --host <h>`)");
|
|
160
|
+
}
|
|
161
|
+
for (const endpoint of endpoints) {
|
|
162
|
+
printFormattedOutput(`${selected === endpoint.alias ? "* " : " "}${endpoint.alias} \u2014 ${endpoint.host}:${endpoint.port}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
631
165
|
return {
|
|
632
|
-
|
|
633
|
-
|
|
166
|
+
ok: true,
|
|
167
|
+
group: "server",
|
|
168
|
+
command,
|
|
169
|
+
details: { selected, endpoints: endpoints.map((e) => ({ alias: e.alias, host: e.host, port: e.port })) }
|
|
634
170
|
};
|
|
635
171
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const reachability = reachable ? "server is reachable" : "server is unreachable";
|
|
643
|
-
return {
|
|
644
|
-
contextLine: `Currently connected to: ${alias} at ${target} (${reachability}).`,
|
|
645
|
-
hint: "Check the selected server with `rig server status`, or switch with `rig server use <alias|local>`."
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
async function requestServerJson(context, pathname, init = {}) {
|
|
649
|
-
const server = await ensureServerForCli(context.projectRoot);
|
|
650
|
-
const headers = mergeHeaders(init.headers, server.authToken);
|
|
651
|
-
if (server.serverProjectRoot)
|
|
652
|
-
headers.set("x-rig-project-root", server.serverProjectRoot);
|
|
653
|
-
reportServerPhase(`${(init.method ?? "GET").toUpperCase()} ${pathname.split("?")[0]}\u2026`);
|
|
654
|
-
let response;
|
|
655
|
-
try {
|
|
656
|
-
response = await fetch(`${server.baseUrl}${pathname}`, {
|
|
657
|
-
...init,
|
|
658
|
-
headers
|
|
659
|
-
});
|
|
660
|
-
} catch (error) {
|
|
661
|
-
const failure = await buildServerFailureContext(context.projectRoot, server);
|
|
662
|
-
throw new CliError(`Rig server request failed: ${error instanceof Error ? error.message : String(error)}
|
|
663
|
-
${failure.contextLine}`, 1, { hint: failure.hint });
|
|
664
|
-
}
|
|
665
|
-
const text = await response.text();
|
|
666
|
-
const payload = text.trim().length > 0 ? (() => {
|
|
667
|
-
try {
|
|
668
|
-
return JSON.parse(text);
|
|
669
|
-
} catch {
|
|
670
|
-
return null;
|
|
671
|
-
}
|
|
672
|
-
})() : null;
|
|
673
|
-
if (!response.ok) {
|
|
674
|
-
const diagnostics = diagnosticMessage(payload);
|
|
675
|
-
const rawDetail = diagnostics ?? (text || response.statusText);
|
|
676
|
-
const detail = diagnostics ? rawDetail : rawDetail.split(`
|
|
677
|
-
`).map((line) => line.trim()).find((line) => line.length > 0)?.slice(0, 200) ?? response.statusText;
|
|
678
|
-
const failure = await buildServerFailureContext(context.projectRoot, server);
|
|
679
|
-
throw new CliError(`Rig server request failed (${response.status}): ${detail}
|
|
680
|
-
${failure.contextLine}`, 1, { hint: failure.hint });
|
|
681
|
-
}
|
|
682
|
-
return payload;
|
|
683
|
-
}
|
|
684
|
-
var RESUMABLE_RUN_STATUSES = new Set([
|
|
685
|
-
"created",
|
|
686
|
-
"preparing",
|
|
687
|
-
"running",
|
|
688
|
-
"validating",
|
|
689
|
-
"reviewing",
|
|
690
|
-
"stopped",
|
|
691
|
-
"failed",
|
|
692
|
-
"needs-attention",
|
|
693
|
-
"needs_attention"
|
|
694
|
-
]);
|
|
695
|
-
async function submitTaskRunViaServer(context, input) {
|
|
696
|
-
const isTaskRun = Boolean(input.taskId);
|
|
697
|
-
const endpoint = isTaskRun ? "/api/runs/task" : "/api/runs/adhoc";
|
|
698
|
-
const payload = await requestServerJson(context, endpoint, {
|
|
699
|
-
method: "POST",
|
|
700
|
-
headers: {
|
|
701
|
-
"content-type": "application/json"
|
|
702
|
-
},
|
|
703
|
-
body: JSON.stringify({
|
|
704
|
-
runId: input.runId,
|
|
705
|
-
taskId: input.taskId,
|
|
706
|
-
title: input.title,
|
|
707
|
-
runtimeAdapter: input.runtimeAdapter,
|
|
708
|
-
model: input.model,
|
|
709
|
-
runtimeMode: input.runtimeMode,
|
|
710
|
-
interactionMode: input.interactionMode,
|
|
711
|
-
initialPrompt: input.initialPrompt,
|
|
712
|
-
baselineMode: input.baselineMode,
|
|
713
|
-
prMode: input.prMode,
|
|
714
|
-
executionTarget: "local"
|
|
715
|
-
})
|
|
716
|
-
});
|
|
717
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
718
|
-
throw new CliError("Rig server returned an invalid run submission payload.", 1, { hint: "Check `rig server status` and retry; `rig run list` shows whether the run was created anyway." });
|
|
719
|
-
}
|
|
720
|
-
const runId = payload.runId;
|
|
721
|
-
if (typeof runId !== "string" || runId.trim().length === 0) {
|
|
722
|
-
throw new CliError("Rig server returned no runId for the submitted run.", 1, { hint: "Check `rig run list` \u2014 the run may still have been created; otherwise retry the submission." });
|
|
723
|
-
}
|
|
724
|
-
return { runId };
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
// packages/cli/src/commands/server.ts
|
|
728
|
-
async function executeServer(context, args, options) {
|
|
729
|
-
const [command = "status", ...rest] = args;
|
|
730
|
-
if (["status", "list", "add", "use"].includes(command)) {
|
|
731
|
-
return executeConnectionCommand(context, [command, ...rest], { group: "server", interactiveUse: true });
|
|
732
|
-
}
|
|
733
|
-
switch (command) {
|
|
734
|
-
case "start": {
|
|
735
|
-
let pending = rest;
|
|
736
|
-
const hostResult = takeOption(pending, "--host");
|
|
737
|
-
pending = hostResult.rest;
|
|
738
|
-
const portResult = takeOption(pending, "--port");
|
|
739
|
-
pending = portResult.rest;
|
|
740
|
-
const pollResult = takeOption(pending, "--poll-ms");
|
|
741
|
-
pending = pollResult.rest;
|
|
742
|
-
const authTokenResult = takeOption(pending, "--auth-token");
|
|
743
|
-
pending = authTokenResult.rest;
|
|
744
|
-
requireNoExtraArgs(pending, "rig server start [--host <host>] [--port <n>] [--poll-ms <n>] [--auth-token <token>]");
|
|
745
|
-
const serverCommand = resolveRigServerCommand(context.projectRoot);
|
|
746
|
-
const commandParts = [serverCommand.command, ...serverCommand.commandArgs, "start"];
|
|
747
|
-
if (hostResult.value) {
|
|
748
|
-
commandParts.push("--host", hostResult.value);
|
|
749
|
-
}
|
|
750
|
-
if (portResult.value) {
|
|
751
|
-
commandParts.push("--port", portResult.value);
|
|
752
|
-
}
|
|
753
|
-
if (pollResult.value) {
|
|
754
|
-
commandParts.push("--poll-ms", pollResult.value);
|
|
755
|
-
}
|
|
756
|
-
if (authTokenResult.value) {
|
|
757
|
-
commandParts.push("--auth-token", authTokenResult.value);
|
|
172
|
+
case "use": {
|
|
173
|
+
const [aliasArg, ...extra] = rest;
|
|
174
|
+
requireNoExtraArgs(extra, "rig server use <local|alias>");
|
|
175
|
+
const alias = (aliasArg ?? "").trim();
|
|
176
|
+
if (!alias) {
|
|
177
|
+
throw new CliError("rig server use requires a target.", 2, { hint: "rig server use local | rig server use <alias>" });
|
|
758
178
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
const eventResult = takeOption(pending, "--event");
|
|
767
|
-
pending = eventResult.rest;
|
|
768
|
-
requireNoExtraArgs(pending, "rig server notify-test [--event <type>]");
|
|
769
|
-
const serverCommand = resolveRigServerCommand(context.projectRoot);
|
|
770
|
-
const commandParts = [serverCommand.command, ...serverCommand.commandArgs, "notify-test"];
|
|
771
|
-
if (eventResult.value) {
|
|
772
|
-
commandParts.push("--event", eventResult.value);
|
|
179
|
+
if (alias !== "local") {
|
|
180
|
+
const known = listManagedRemoteEndpoints(undefined, projectRoot).some((endpoint) => endpoint.alias === alias);
|
|
181
|
+
if (!known) {
|
|
182
|
+
throw new CliError(`Unknown remote endpoint: ${alias}`, 2, {
|
|
183
|
+
hint: "Run `rig server list`, or add it with `rig server add --alias <a> --host <h>`."
|
|
184
|
+
});
|
|
185
|
+
}
|
|
773
186
|
}
|
|
774
|
-
|
|
775
|
-
|
|
187
|
+
if (context.dryRun)
|
|
188
|
+
return { ok: true, group: "server", command, details: { selected: alias, dryRun: true } };
|
|
189
|
+
const prev = readRepoConnection(projectRoot);
|
|
190
|
+
writeRepoConnection(projectRoot, { ...prev ?? { selected: "local" }, selected: alias });
|
|
191
|
+
if (text)
|
|
192
|
+
printFormattedOutput(alias === "local" ? "Placement set to local." : `Placement set to remote \u2192 ${alias}.`);
|
|
193
|
+
return { ok: true, group: "server", command, details: { selected: alias } };
|
|
776
194
|
}
|
|
777
|
-
case "
|
|
778
|
-
|
|
779
|
-
const
|
|
780
|
-
|
|
781
|
-
const
|
|
782
|
-
|
|
783
|
-
const
|
|
784
|
-
|
|
785
|
-
const
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
pending = interactionModeResult.rest;
|
|
791
|
-
const initialPromptResult = takeOption(pending, "--initial-prompt");
|
|
792
|
-
pending = initialPromptResult.rest;
|
|
793
|
-
const dirtyBaselineResult = takeOption(pending, "--dirty-baseline");
|
|
794
|
-
pending = dirtyBaselineResult.rest;
|
|
795
|
-
const prResult = takeOption(pending, "--pr");
|
|
796
|
-
pending = prResult.rest;
|
|
797
|
-
requireNoExtraArgs(pending, "rig --run-id <run-id> server task-run [--task <id>] [--title <text>] [--runtime-adapter claude-code|codex|pi] [--model <model>] [--runtime-mode <mode>] [--interaction-mode <mode>] [--initial-prompt <text>] [--dirty-baseline head|dirty-snapshot] [--pr auto|ask|off]");
|
|
798
|
-
if (!taskResult.value && !initialPromptResult.value && !titleResult.value) {
|
|
799
|
-
throw new CliError("server task-run requires either --task <id> or --initial-prompt/--title for an ad hoc run.", 2);
|
|
195
|
+
case "add": {
|
|
196
|
+
const aliasOpt = takeOption(rest, "--alias");
|
|
197
|
+
const hostOpt = takeOption(aliasOpt.rest, "--host");
|
|
198
|
+
const portOpt = takeOption(hostOpt.rest, "--port");
|
|
199
|
+
const tokenOpt = takeOption(portOpt.rest, "--token");
|
|
200
|
+
const positional = tokenOpt.rest.filter((arg) => !arg.startsWith("-"));
|
|
201
|
+
const alias = (aliasOpt.value ?? positional[0] ?? "").trim();
|
|
202
|
+
const host = (hostOpt.value ?? positional[1] ?? "").trim();
|
|
203
|
+
const portRaw = portOpt.value ?? positional[2];
|
|
204
|
+
if (!alias || !host) {
|
|
205
|
+
throw new CliError("rig server add requires --alias <a> and --host <h>.", 2, {
|
|
206
|
+
hint: "rig server add --alias prod --host prod.example.com --port 22"
|
|
207
|
+
});
|
|
800
208
|
}
|
|
801
|
-
const
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
initialPrompt: initialPromptResult.value ?? undefined,
|
|
810
|
-
baselineMode: dirtyBaselineResult.value === "dirty-snapshot" ? "dirty-snapshot" : "head",
|
|
811
|
-
prMode: prResult.value === "auto" || prResult.value === "ask" || prResult.value === "off" ? prResult.value : undefined
|
|
812
|
-
};
|
|
813
|
-
if (process.env.RIG_SERVER_INTERNAL_EXEC === "1") {
|
|
814
|
-
await options.executeRigOwnedTaskRun(context, input);
|
|
815
|
-
} else {
|
|
816
|
-
await submitTaskRunViaServer(context, input);
|
|
209
|
+
const port = portRaw ? Number(portRaw) : DEFAULT_REMOTE_PORT;
|
|
210
|
+
if (!Number.isFinite(port))
|
|
211
|
+
throw new CliError(`Invalid --port: ${portRaw}`, 2);
|
|
212
|
+
if (context.dryRun)
|
|
213
|
+
return { ok: true, group: "server", command, details: { alias, host, port, dryRun: true } };
|
|
214
|
+
const saved = upsertManagedRemoteEndpoint({ alias, host, port, ...tokenOpt.value ? { token: tokenOpt.value } : {} }, undefined, projectRoot);
|
|
215
|
+
if (text) {
|
|
216
|
+
printFormattedOutput(`Saved remote endpoint ${saved.alias} \u2192 ${saved.host}:${saved.port}. Select it with \`rig server use ${saved.alias}\`.`);
|
|
817
217
|
}
|
|
818
|
-
return {
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
218
|
+
return { ok: true, group: "server", command, details: { alias: saved.alias, host: saved.host, port: saved.port } };
|
|
219
|
+
}
|
|
220
|
+
case "remove": {
|
|
221
|
+
const [aliasArg, ...extra] = rest;
|
|
222
|
+
requireNoExtraArgs(extra, "rig server remove <alias>");
|
|
223
|
+
const alias = (aliasArg ?? "").trim();
|
|
224
|
+
if (!alias)
|
|
225
|
+
throw new CliError("rig server remove requires an alias.", 2);
|
|
226
|
+
if (context.dryRun)
|
|
227
|
+
return { ok: true, group: "server", command, details: { alias, dryRun: true } };
|
|
228
|
+
const removed = removeManagedRemoteEndpoint(alias, undefined, projectRoot);
|
|
229
|
+
if (text)
|
|
230
|
+
printFormattedOutput(removed ? `Removed remote endpoint ${alias}.` : `No remote endpoint named ${alias}.`);
|
|
231
|
+
return { ok: removed, group: "server", command, details: { alias, removed } };
|
|
824
232
|
}
|
|
233
|
+
case "start":
|
|
234
|
+
throw new CliError("rig server start is retired: there is no standalone Rig server process after the OMP migration.", 2, {
|
|
235
|
+
hint: "Runs execute locally (tmux) or on a selected remote \u2014 pick one with `rig server use local|<alias>`."
|
|
236
|
+
});
|
|
237
|
+
case "repair-link":
|
|
238
|
+
throw new CliError("rig server repair-link is retired with the standalone server.", 2, {
|
|
239
|
+
hint: "Select placement with `rig server use local|<alias>`."
|
|
240
|
+
});
|
|
825
241
|
default:
|
|
826
|
-
throw new CliError(`Unknown server command: ${command}`, 1, {
|
|
242
|
+
throw new CliError(`Unknown server command: ${command}`, 1, {
|
|
243
|
+
hint: "Run `rig server --help` \u2014 commands are status|list|use|add|remove."
|
|
244
|
+
});
|
|
827
245
|
}
|
|
828
246
|
}
|
|
829
247
|
export {
|