@h-rig/cli 0.0.6-alpha.89 → 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/dist/bin/build-rig-binaries.js +8 -40
- package/dist/bin/rig.js +12519 -26675
- package/dist/src/app/board.js +74 -693
- package/dist/src/app/drone-ui.js +1 -1
- package/dist/src/app/theme.js +0 -1
- package/dist/src/commands/_async-ui.js +1 -1
- package/dist/src/commands/_authority-runs.d.ts +1 -1
- package/dist/src/commands/_authority-runs.js +12 -2
- package/dist/src/commands/_cli-format.d.ts +1 -10
- package/dist/src/commands/_cli-format.js +2 -5
- package/dist/src/commands/_connection-state.d.ts +1 -11
- package/dist/src/commands/_connection-state.js +5 -50
- package/dist/src/commands/_doctor-checks.js +40 -501
- package/dist/src/commands/_help-catalog.js +17 -99
- package/dist/src/commands/_json-output.js +0 -4
- package/dist/src/commands/_operator-view.js +54 -575
- package/dist/src/commands/_pi-frontend.d.ts +0 -27
- package/dist/src/commands/_pi-frontend.js +52 -576
- package/dist/src/commands/_preflight.js +66 -553
- package/dist/src/commands/_server-client.d.ts +0 -33
- package/dist/src/commands/_server-client.js +46 -541
- package/dist/src/commands/_snapshot-upload.js +42 -503
- package/dist/src/commands/_spinner.js +1 -1
- package/dist/src/commands/agent.js +12 -2
- package/dist/src/commands/browser.js +1 -1
- package/dist/src/commands/connect.js +15 -626
- package/dist/src/commands/doctor.js +41 -502
- package/dist/src/commands/github.js +51 -584
- package/dist/src/commands/inbox.js +41 -502
- package/dist/src/commands/init.js +74 -561
- package/dist/src/commands/inspect.js +41 -502
- package/dist/src/commands/run.js +54 -578
- package/dist/src/commands/server.js +163 -692
- package/dist/src/commands/setup.js +46 -507
- package/dist/src/commands/stats.js +58 -601
- package/dist/src/commands/task-run-driver.js +58 -509
- package/dist/src/commands/task.js +110 -729
- package/dist/src/commands.js +237 -1112
- package/dist/src/index.js +244 -1123
- package/dist/src/launcher.js +0 -4
- package/package.json +9 -13
- package/dist/src/app-opentui/adapters/command.d.ts +0 -2
- package/dist/src/app-opentui/adapters/command.js +0 -329
- package/dist/src/app-opentui/adapters/common.d.ts +0 -56
- package/dist/src/app-opentui/adapters/common.js +0 -153
- package/dist/src/app-opentui/adapters/doctor.d.ts +0 -9
- package/dist/src/app-opentui/adapters/doctor.js +0 -1217
- package/dist/src/app-opentui/adapters/family.d.ts +0 -62
- package/dist/src/app-opentui/adapters/family.js +0 -14855
- package/dist/src/app-opentui/adapters/fleet.d.ts +0 -14
- package/dist/src/app-opentui/adapters/fleet.js +0 -1335
- package/dist/src/app-opentui/adapters/inbox.d.ts +0 -43
- package/dist/src/app-opentui/adapters/inbox.js +0 -1944
- package/dist/src/app-opentui/adapters/init.d.ts +0 -11
- package/dist/src/app-opentui/adapters/init.js +0 -2818
- package/dist/src/app-opentui/adapters/inspect.d.ts +0 -52
- package/dist/src/app-opentui/adapters/inspect.js +0 -1455
- package/dist/src/app-opentui/adapters/pi-attach.d.ts +0 -32
- package/dist/src/app-opentui/adapters/pi-attach.js +0 -2101
- package/dist/src/app-opentui/adapters/pi.d.ts +0 -23
- package/dist/src/app-opentui/adapters/pi.js +0 -363
- package/dist/src/app-opentui/adapters/plugin.d.ts +0 -84
- package/dist/src/app-opentui/adapters/plugin.js +0 -544
- package/dist/src/app-opentui/adapters/repo.d.ts +0 -37
- package/dist/src/app-opentui/adapters/repo.js +0 -186
- package/dist/src/app-opentui/adapters/run-detail.d.ts +0 -27
- package/dist/src/app-opentui/adapters/run-detail.js +0 -1441
- package/dist/src/app-opentui/adapters/server.d.ts +0 -48
- package/dist/src/app-opentui/adapters/server.js +0 -1561
- package/dist/src/app-opentui/adapters/tasks.d.ts +0 -64
- package/dist/src/app-opentui/adapters/tasks.js +0 -4524
- package/dist/src/app-opentui/adapters/workspace.d.ts +0 -49
- package/dist/src/app-opentui/adapters/workspace.js +0 -333
- package/dist/src/app-opentui/autocomplete.d.ts +0 -20
- package/dist/src/app-opentui/autocomplete.js +0 -578
- package/dist/src/app-opentui/bootstrap.d.ts +0 -11
- package/dist/src/app-opentui/bootstrap.js +0 -27833
- package/dist/src/app-opentui/command-palette.d.ts +0 -3
- package/dist/src/app-opentui/command-palette.js +0 -1038
- package/dist/src/app-opentui/command-pty-host.d.ts +0 -62
- package/dist/src/app-opentui/command-pty-host.js +0 -248
- package/dist/src/app-opentui/drone.d.ts +0 -12
- package/dist/src/app-opentui/drone.js +0 -230
- package/dist/src/app-opentui/events.d.ts +0 -7
- package/dist/src/app-opentui/events.js +0 -28
- package/dist/src/app-opentui/fleet-stats.d.ts +0 -32
- package/dist/src/app-opentui/fleet-stats.js +0 -114
- package/dist/src/app-opentui/focus-manager.d.ts +0 -14
- package/dist/src/app-opentui/focus-manager.js +0 -24
- package/dist/src/app-opentui/index.d.ts +0 -8
- package/dist/src/app-opentui/index.js +0 -5260
- package/dist/src/app-opentui/intent.d.ts +0 -3
- package/dist/src/app-opentui/intent.js +0 -365
- package/dist/src/app-opentui/keymap.d.ts +0 -21
- package/dist/src/app-opentui/keymap.js +0 -1377
- package/dist/src/app-opentui/launch-routing.d.ts +0 -16
- package/dist/src/app-opentui/launch-routing.js +0 -55
- package/dist/src/app-opentui/layout.d.ts +0 -22
- package/dist/src/app-opentui/layout.js +0 -51
- package/dist/src/app-opentui/list-search.d.ts +0 -36
- package/dist/src/app-opentui/list-search.js +0 -130
- package/dist/src/app-opentui/pi-host-child.d.ts +0 -2
- package/dist/src/app-opentui/pi-host-child.js +0 -1299
- package/dist/src/app-opentui/pi-pty-host.d.ts +0 -28
- package/dist/src/app-opentui/pi-pty-host.js +0 -10
- package/dist/src/app-opentui/react/App.d.ts +0 -9
- package/dist/src/app-opentui/react/App.js +0 -3866
- package/dist/src/app-opentui/react/Backdrop.d.ts +0 -5
- package/dist/src/app-opentui/react/Backdrop.js +0 -823
- package/dist/src/app-opentui/react/ChromeHost.d.ts +0 -5
- package/dist/src/app-opentui/react/ChromeHost.js +0 -1539
- package/dist/src/app-opentui/react/SceneFrameView.d.ts +0 -7
- package/dist/src/app-opentui/react/SceneFrameView.js +0 -579
- package/dist/src/app-opentui/react/context.d.ts +0 -17
- package/dist/src/app-opentui/react/context.js +0 -37
- package/dist/src/app-opentui/react/launch.d.ts +0 -2
- package/dist/src/app-opentui/react/launch.js +0 -4897
- package/dist/src/app-opentui/react/nav.d.ts +0 -18
- package/dist/src/app-opentui/react/nav.js +0 -54
- package/dist/src/app-opentui/react/scroll.d.ts +0 -12
- package/dist/src/app-opentui/react/scroll.js +0 -21
- package/dist/src/app-opentui/react/syntax.d.ts +0 -2
- package/dist/src/app-opentui/react/syntax.js +0 -65
- package/dist/src/app-opentui/registry.d.ts +0 -4
- package/dist/src/app-opentui/registry.js +0 -22876
- package/dist/src/app-opentui/remote-link.d.ts +0 -10
- package/dist/src/app-opentui/remote-link.js +0 -47
- package/dist/src/app-opentui/render/ascii-fleet.d.ts +0 -15
- package/dist/src/app-opentui/render/ascii-fleet.js +0 -82
- package/dist/src/app-opentui/render/constants.d.ts +0 -30
- package/dist/src/app-opentui/render/constants.js +0 -64
- package/dist/src/app-opentui/render/graphics.d.ts +0 -40
- package/dist/src/app-opentui/render/graphics.js +0 -713
- package/dist/src/app-opentui/render/hover.d.ts +0 -11
- package/dist/src/app-opentui/render/hover.js +0 -34
- package/dist/src/app-opentui/render/native-host.d.ts +0 -37
- package/dist/src/app-opentui/render/native-host.js +0 -180
- package/dist/src/app-opentui/render/panel-layout.d.ts +0 -38
- package/dist/src/app-opentui/render/panel-layout.js +0 -48
- package/dist/src/app-opentui/render/panels.d.ts +0 -12
- package/dist/src/app-opentui/render/panels.js +0 -288
- package/dist/src/app-opentui/render/preloader.d.ts +0 -10
- package/dist/src/app-opentui/render/preloader.js +0 -166
- package/dist/src/app-opentui/render/scene.d.ts +0 -68
- package/dist/src/app-opentui/render/scene.js +0 -300
- package/dist/src/app-opentui/render/terminal-handoff.d.ts +0 -16
- package/dist/src/app-opentui/render/terminal-handoff.js +0 -14
- package/dist/src/app-opentui/render/text.d.ts +0 -29
- package/dist/src/app-opentui/render/text.js +0 -177
- package/dist/src/app-opentui/render/type-bar.d.ts +0 -15
- package/dist/src/app-opentui/render/type-bar.js +0 -212
- package/dist/src/app-opentui/runtime-resources.d.ts +0 -16
- package/dist/src/app-opentui/runtime-resources.js +0 -62
- package/dist/src/app-opentui/runtime.d.ts +0 -45
- package/dist/src/app-opentui/runtime.js +0 -5232
- package/dist/src/app-opentui/scenes/command.d.ts +0 -3
- package/dist/src/app-opentui/scenes/command.js +0 -118
- package/dist/src/app-opentui/scenes/doctor.d.ts +0 -3
- package/dist/src/app-opentui/scenes/doctor.js +0 -296
- package/dist/src/app-opentui/scenes/error.d.ts +0 -2
- package/dist/src/app-opentui/scenes/error.js +0 -277
- package/dist/src/app-opentui/scenes/family-domains/agent.d.ts +0 -2
- package/dist/src/app-opentui/scenes/family-domains/agent.js +0 -349
- package/dist/src/app-opentui/scenes/family-domains/browser.d.ts +0 -2
- package/dist/src/app-opentui/scenes/family-domains/browser.js +0 -196
- package/dist/src/app-opentui/scenes/family-domains/dist.d.ts +0 -2
- package/dist/src/app-opentui/scenes/family-domains/dist.js +0 -244
- package/dist/src/app-opentui/scenes/family-domains/git.d.ts +0 -2
- package/dist/src/app-opentui/scenes/family-domains/git.js +0 -196
- package/dist/src/app-opentui/scenes/family-domains/github.d.ts +0 -2
- package/dist/src/app-opentui/scenes/family-domains/github.js +0 -275
- package/dist/src/app-opentui/scenes/family-domains/harness.d.ts +0 -2
- package/dist/src/app-opentui/scenes/family-domains/harness.js +0 -153
- package/dist/src/app-opentui/scenes/family-domains/index.d.ts +0 -4
- package/dist/src/app-opentui/scenes/family-domains/index.js +0 -1680
- package/dist/src/app-opentui/scenes/family-domains/kit.d.ts +0 -76
- package/dist/src/app-opentui/scenes/family-domains/kit.js +0 -306
- package/dist/src/app-opentui/scenes/family-domains/profile.d.ts +0 -2
- package/dist/src/app-opentui/scenes/family-domains/profile.js +0 -213
- package/dist/src/app-opentui/scenes/family-domains/queue.d.ts +0 -2
- package/dist/src/app-opentui/scenes/family-domains/queue.js +0 -147
- package/dist/src/app-opentui/scenes/family-domains/remote.d.ts +0 -2
- package/dist/src/app-opentui/scenes/family-domains/remote.js +0 -519
- package/dist/src/app-opentui/scenes/family-domains/review.d.ts +0 -2
- package/dist/src/app-opentui/scenes/family-domains/review.js +0 -281
- package/dist/src/app-opentui/scenes/family-domains/setup.d.ts +0 -2
- package/dist/src/app-opentui/scenes/family-domains/setup.js +0 -268
- package/dist/src/app-opentui/scenes/family-domains/stats.d.ts +0 -2
- package/dist/src/app-opentui/scenes/family-domains/stats.js +0 -371
- package/dist/src/app-opentui/scenes/family.d.ts +0 -3
- package/dist/src/app-opentui/scenes/family.js +0 -2199
- package/dist/src/app-opentui/scenes/fleet.d.ts +0 -3
- package/dist/src/app-opentui/scenes/fleet.js +0 -766
- package/dist/src/app-opentui/scenes/handoff.d.ts +0 -2
- package/dist/src/app-opentui/scenes/handoff.js +0 -455
- package/dist/src/app-opentui/scenes/help.d.ts +0 -3
- package/dist/src/app-opentui/scenes/help.js +0 -725
- package/dist/src/app-opentui/scenes/inbox.d.ts +0 -3
- package/dist/src/app-opentui/scenes/inbox.js +0 -427
- package/dist/src/app-opentui/scenes/init.d.ts +0 -3
- package/dist/src/app-opentui/scenes/init.js +0 -181
- package/dist/src/app-opentui/scenes/inspect.d.ts +0 -3
- package/dist/src/app-opentui/scenes/inspect.js +0 -794
- package/dist/src/app-opentui/scenes/main.d.ts +0 -3
- package/dist/src/app-opentui/scenes/main.js +0 -332
- package/dist/src/app-opentui/scenes/pi.d.ts +0 -3
- package/dist/src/app-opentui/scenes/pi.js +0 -509
- package/dist/src/app-opentui/scenes/plugin.d.ts +0 -3
- package/dist/src/app-opentui/scenes/plugin.js +0 -487
- package/dist/src/app-opentui/scenes/repo.d.ts +0 -3
- package/dist/src/app-opentui/scenes/repo.js +0 -425
- package/dist/src/app-opentui/scenes/run-detail.d.ts +0 -3
- package/dist/src/app-opentui/scenes/run-detail.js +0 -467
- package/dist/src/app-opentui/scenes/server.d.ts +0 -3
- package/dist/src/app-opentui/scenes/server.js +0 -378
- package/dist/src/app-opentui/scenes/tasks.d.ts +0 -3
- package/dist/src/app-opentui/scenes/tasks.js +0 -768
- package/dist/src/app-opentui/scenes/workspace.d.ts +0 -3
- package/dist/src/app-opentui/scenes/workspace.js +0 -427
- package/dist/src/app-opentui/selectable.d.ts +0 -19
- package/dist/src/app-opentui/selectable.js +0 -80
- package/dist/src/app-opentui/state.d.ts +0 -4
- package/dist/src/app-opentui/state.js +0 -399
- package/dist/src/app-opentui/surface-catalog.d.ts +0 -20
- package/dist/src/app-opentui/surface-catalog.js +0 -542
- package/dist/src/app-opentui/theme.d.ts +0 -59
- package/dist/src/app-opentui/theme.js +0 -142
- package/dist/src/app-opentui/types.d.ts +0 -313
- package/dist/src/app-opentui/types.js +0 -1
- package/dist/src/commands/_server-events.d.ts +0 -26
- package/dist/src/commands/_server-events.js +0 -715
|
@@ -55,8 +55,18 @@ import {
|
|
|
55
55
|
import { resolveMonorepoRoot } from "@rig/runtime/control-plane/native/utils";
|
|
56
56
|
|
|
57
57
|
// packages/cli/src/commands/_authority-runs.ts
|
|
58
|
-
function normalizeRuntimeAdapter(
|
|
59
|
-
|
|
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";
|
|
60
70
|
}
|
|
61
71
|
|
|
62
72
|
// packages/cli/src/app/drone-ui.ts
|
|
@@ -270,28 +280,12 @@ function readRepoConnection(projectRoot) {
|
|
|
270
280
|
selected,
|
|
271
281
|
project: typeof record.project === "string" ? record.project : undefined,
|
|
272
282
|
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
|
|
273
|
-
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
274
|
-
serverProjectRootAlias: typeof record.serverProjectRootAlias === "string" && record.serverProjectRootAlias.trim() ? record.serverProjectRootAlias.trim() : undefined,
|
|
275
|
-
serverProjectRootBaseUrl: typeof record.serverProjectRootBaseUrl === "string" && record.serverProjectRootBaseUrl.trim() ? record.serverProjectRootBaseUrl.trim().replace(/\/+$/, "") : undefined
|
|
283
|
+
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
276
284
|
};
|
|
277
285
|
}
|
|
278
286
|
function writeRepoConnection(projectRoot, state) {
|
|
279
287
|
writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
|
|
280
288
|
}
|
|
281
|
-
function rootAllowedForSelection(repo, connection) {
|
|
282
|
-
const root = repo.serverProjectRoot?.trim();
|
|
283
|
-
if (!root)
|
|
284
|
-
return;
|
|
285
|
-
if (connection.kind === "remote") {
|
|
286
|
-
if (repo.serverProjectRootAlias !== repo.selected)
|
|
287
|
-
return;
|
|
288
|
-
if (repo.serverProjectRootBaseUrl !== connection.baseUrl)
|
|
289
|
-
return;
|
|
290
|
-
} else if (repo.serverProjectRootAlias && repo.serverProjectRootAlias !== repo.selected) {
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
return root;
|
|
294
|
-
}
|
|
295
289
|
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
296
290
|
const repo = readRepoConnection(projectRoot);
|
|
297
291
|
if (!repo)
|
|
@@ -303,41 +297,13 @@ function resolveSelectedConnection(projectRoot, options = {}) {
|
|
|
303
297
|
if (!connection) {
|
|
304
298
|
throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
305
299
|
}
|
|
306
|
-
return { alias: repo.selected, connection, serverProjectRoot:
|
|
307
|
-
}
|
|
308
|
-
function writeRepoServerProjectRoot(projectRoot, serverProjectRoot, metadata = {}) {
|
|
309
|
-
const repo = readRepoConnection(projectRoot);
|
|
310
|
-
if (!repo)
|
|
311
|
-
return;
|
|
312
|
-
let inferred = metadata;
|
|
313
|
-
if (!inferred.alias || !inferred.baseUrl) {
|
|
314
|
-
try {
|
|
315
|
-
const selected = resolveSelectedConnection(projectRoot);
|
|
316
|
-
if (selected?.connection.kind === "remote") {
|
|
317
|
-
inferred = {
|
|
318
|
-
alias: inferred.alias ?? selected.alias,
|
|
319
|
-
baseUrl: inferred.baseUrl ?? selected.connection.baseUrl
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
} catch {}
|
|
323
|
-
}
|
|
324
|
-
writeRepoConnection(projectRoot, {
|
|
325
|
-
...repo,
|
|
326
|
-
...metadata.project ? { project: metadata.project } : {},
|
|
327
|
-
serverProjectRoot,
|
|
328
|
-
...inferred.alias ? { serverProjectRootAlias: inferred.alias } : {},
|
|
329
|
-
...inferred.baseUrl ? { serverProjectRootBaseUrl: inferred.baseUrl.replace(/\/+$/, "") } : {}
|
|
330
|
-
});
|
|
300
|
+
return { alias: repo.selected, connection, serverProjectRoot: repo.serverProjectRoot };
|
|
331
301
|
}
|
|
332
|
-
function
|
|
302
|
+
function writeRepoServerProjectRoot(projectRoot, serverProjectRoot) {
|
|
333
303
|
const repo = readRepoConnection(projectRoot);
|
|
334
304
|
if (!repo)
|
|
335
305
|
return;
|
|
336
|
-
writeRepoConnection(projectRoot, {
|
|
337
|
-
selected: repo.selected,
|
|
338
|
-
...repo.project ? { project: repo.project } : {},
|
|
339
|
-
...repo.linkedAt ? { linkedAt: repo.linkedAt } : {}
|
|
340
|
-
});
|
|
306
|
+
writeRepoConnection(projectRoot, { ...repo, serverProjectRoot });
|
|
341
307
|
}
|
|
342
308
|
|
|
343
309
|
// packages/cli/src/commands/_cli-format.ts
|
|
@@ -394,26 +360,131 @@ function formatConnectionList(connections) {
|
|
|
394
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(`
|
|
395
361
|
`);
|
|
396
362
|
}
|
|
397
|
-
function formatConnectionStatus(selected, connections
|
|
363
|
+
function formatConnectionStatus(selected, connections) {
|
|
398
364
|
const connection = selected === "local" ? { kind: "local", mode: "auto" } : connections[selected];
|
|
399
365
|
const target = !connection ? "not configured" : connection.kind === "remote" ? connection.baseUrl : "local";
|
|
400
|
-
const rootLabel = remoteProjectLink ? remoteProjectLink.ok ? `ready \xB7 ${remoteProjectLink.serverProjectRoot ?? repo?.serverProjectRoot ?? "linked"}` : `${remoteProjectLink.status ?? "needs repair"} \xB7 ${remoteProjectLink.hint ?? remoteProjectLink.message ?? "run rig server repair-link"}` : repo?.serverProjectRoot ? repo.serverProjectRoot : "not required";
|
|
401
366
|
return [
|
|
402
367
|
formatSection("Rig server", "selected for this repo"),
|
|
403
368
|
`${themeFaint("\u2502")} ${themeDim("selected ")} ${pc.bold(selected)}`,
|
|
404
369
|
`${themeFaint("\u2502")} ${themeDim("kind ")} ${formatStatusPill(connection?.kind ?? "unknown")}`,
|
|
405
370
|
`${themeFaint("\u2502")} ${themeDim("target ")} ${target ?? "not configured"}`,
|
|
406
|
-
...repo?.project ? [`${themeFaint("\u2502")} ${themeDim("project ")} ${repo.project}`] : [],
|
|
407
|
-
...connection?.kind === "remote" ? [`${themeFaint("\u2502")} ${themeDim("root ")} ${rootLabel}`] : [],
|
|
408
371
|
"",
|
|
409
|
-
...formatNextSteps(
|
|
372
|
+
...formatNextSteps(["Change: `rig server use <alias|local>`", "List saved servers: `rig server list`"])
|
|
410
373
|
].join(`
|
|
411
374
|
`);
|
|
412
375
|
}
|
|
413
376
|
|
|
377
|
+
// packages/cli/src/commands/connect.ts
|
|
378
|
+
function usageName(options) {
|
|
379
|
+
return `rig ${options.group}`;
|
|
380
|
+
}
|
|
381
|
+
function parseConnection(alias, value, options) {
|
|
382
|
+
if (alias === "local" && !value)
|
|
383
|
+
return { kind: "local", mode: "auto" };
|
|
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
|
+
}
|
|
471
|
+
case "status": {
|
|
472
|
+
requireNoExtraArgs(rest, `${usageName(options)} status`);
|
|
473
|
+
const repo = readRepoConnection(context.projectRoot);
|
|
474
|
+
const global = readGlobalConnections();
|
|
475
|
+
const details = { selected: repo?.selected ?? "local", repo, connections: global.connections };
|
|
476
|
+
printJsonOrText(context, details, formatConnectionStatus(details.selected, global.connections));
|
|
477
|
+
return { ok: true, group: options.group, command: "status", details };
|
|
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
|
+
|
|
414
485
|
// packages/cli/src/commands/_server-client.ts
|
|
415
|
-
import { existsSync as existsSync2,
|
|
416
|
-
import {
|
|
486
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
487
|
+
import { resolve as resolve2 } from "path";
|
|
417
488
|
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
418
489
|
var scopedGitHubBearerTokens = new Map;
|
|
419
490
|
var serverPhaseListener = null;
|
|
@@ -424,21 +495,17 @@ function cleanToken(value) {
|
|
|
424
495
|
const trimmed = value?.trim();
|
|
425
496
|
return trimmed ? trimmed : null;
|
|
426
497
|
}
|
|
427
|
-
function
|
|
498
|
+
function readPrivateRemoteSessionToken(projectRoot) {
|
|
428
499
|
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
429
500
|
if (!existsSync2(path))
|
|
430
501
|
return null;
|
|
431
502
|
try {
|
|
432
503
|
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
433
|
-
return
|
|
504
|
+
return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
|
|
434
505
|
} catch {
|
|
435
506
|
return null;
|
|
436
507
|
}
|
|
437
508
|
}
|
|
438
|
-
function readPrivateRemoteSessionToken(projectRoot) {
|
|
439
|
-
const parsed = readRemoteAuthState(projectRoot);
|
|
440
|
-
return parsed ? cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined) : null;
|
|
441
|
-
}
|
|
442
509
|
function readGitHubBearerTokenForRemote(projectRoot) {
|
|
443
510
|
const scopedKey = resolve2(projectRoot);
|
|
444
511
|
if (scopedGitHubBearerTokens.has(scopedKey))
|
|
@@ -449,421 +516,18 @@ function readGitHubBearerTokenForRemote(projectRoot) {
|
|
|
449
516
|
return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
450
517
|
}
|
|
451
518
|
function readStoredGitHubAuthToken(projectRoot) {
|
|
452
|
-
const
|
|
453
|
-
return parsed ? cleanToken(typeof parsed.token === "string" ? parsed.token : undefined) : null;
|
|
454
|
-
}
|
|
455
|
-
function inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug) {
|
|
456
|
-
if (!/^[^/]+\/[^/]+$/.test(repoSlug))
|
|
457
|
-
return null;
|
|
458
|
-
const repo = readRepoConnection(projectRoot);
|
|
459
|
-
const auth = readRemoteAuthState(projectRoot);
|
|
460
|
-
const authUpdatedAt = typeof auth?.updatedAt === "string" ? Date.parse(auth.updatedAt) : Number.NaN;
|
|
461
|
-
const repoLinkedAt = typeof repo?.linkedAt === "string" ? Date.parse(repo.linkedAt) : Number.NaN;
|
|
462
|
-
if (Number.isFinite(authUpdatedAt) && Number.isFinite(repoLinkedAt) && authUpdatedAt + 1000 < repoLinkedAt)
|
|
463
|
-
return null;
|
|
464
|
-
const checkoutBaseDir = typeof auth?.checkoutBaseDir === "string" && auth.checkoutBaseDir.trim() ? auth.checkoutBaseDir.trim() : null;
|
|
465
|
-
if (!checkoutBaseDir)
|
|
466
|
-
return null;
|
|
467
|
-
return `${checkoutBaseDir.replace(/\/+$/, "")}/${repoSlug}`;
|
|
468
|
-
}
|
|
469
|
-
function readLocalConnectionFallbackToken(projectRoot) {
|
|
470
|
-
return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
|
|
471
|
-
}
|
|
472
|
-
function normalizeRepoSlug(value) {
|
|
473
|
-
const slug = value?.trim();
|
|
474
|
-
return slug && /^[^/\s]+\/[^/\s]+$/.test(slug) ? slug : null;
|
|
475
|
-
}
|
|
476
|
-
function readProjectLinkSlug(projectRoot) {
|
|
477
|
-
const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
|
|
519
|
+
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
478
520
|
if (!existsSync2(path))
|
|
479
521
|
return null;
|
|
480
522
|
try {
|
|
481
523
|
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
482
|
-
|
|
483
|
-
return null;
|
|
484
|
-
return normalizeRepoSlug(typeof parsed.repoSlug === "string" ? String(parsed.repoSlug) : null);
|
|
524
|
+
return cleanToken(typeof parsed.token === "string" ? parsed.token : undefined);
|
|
485
525
|
} catch {
|
|
486
526
|
return null;
|
|
487
527
|
}
|
|
488
528
|
}
|
|
489
|
-
function
|
|
490
|
-
|
|
491
|
-
mkdirSync2(dirname2(path), { recursive: true });
|
|
492
|
-
writeFileSync2(path, `${JSON.stringify({ repoSlug, connection: alias, linkedAt: new Date().toISOString() }, null, 2)}
|
|
493
|
-
`, "utf8");
|
|
494
|
-
}
|
|
495
|
-
function remoteLinkRepairCommand(repoSlug) {
|
|
496
|
-
return repoSlug ? `rig server repair-link --repo ${repoSlug}` : "rig server repair-link --repo owner/repo";
|
|
497
|
-
}
|
|
498
|
-
function formatRemoteProjectLinkHint(resolution) {
|
|
499
|
-
const repair = remoteLinkRepairCommand(resolution.repoSlug);
|
|
500
|
-
if (resolution.status === "auth_required") {
|
|
501
|
-
return `Authenticate the selected remote${resolution.alias ? ` (${resolution.alias})` : ""}, then run \`${repair}\`. Use \`rig github auth import-gh\` or \`rig init --repair --server remote --github-auth device${resolution.repoSlug ? ` --repo ${resolution.repoSlug}` : ""}\`.`;
|
|
502
|
-
}
|
|
503
|
-
if (resolution.status === "missing_project") {
|
|
504
|
-
return `Record the repo slug, then run \`${repair}\` (or \`rig init --repo owner/repo --server remote --github-auth device\`).`;
|
|
505
|
-
}
|
|
506
|
-
if (resolution.status === "not_remote")
|
|
507
|
-
return "Select a remote server with `rig server use <alias>` before repairing a remote project link.";
|
|
508
|
-
return `Run \`${repair}\` to backfill or prepare a server-host checkout for the selected remote${resolution.alias ? ` (${resolution.alias})` : ""}.`;
|
|
509
|
-
}
|
|
510
|
-
function remoteProjectLinkFailure(input) {
|
|
511
|
-
const partial = {
|
|
512
|
-
status: input.status,
|
|
513
|
-
alias: input.alias,
|
|
514
|
-
baseUrl: input.baseUrl,
|
|
515
|
-
repoSlug: input.repoSlug
|
|
516
|
-
};
|
|
517
|
-
return {
|
|
518
|
-
ok: false,
|
|
519
|
-
...input,
|
|
520
|
-
hint: formatRemoteProjectLinkHint(partial),
|
|
521
|
-
next: remoteLinkRepairCommand(input.repoSlug)
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
function remoteProjectLinkSuccess(input) {
|
|
525
|
-
return {
|
|
526
|
-
ok: true,
|
|
527
|
-
status: input.status,
|
|
528
|
-
alias: input.alias,
|
|
529
|
-
baseUrl: input.baseUrl,
|
|
530
|
-
repoSlug: input.repoSlug,
|
|
531
|
-
serverProjectRoot: input.serverProjectRoot,
|
|
532
|
-
source: input.source,
|
|
533
|
-
prepared: input.prepared ?? input.status === "prepared",
|
|
534
|
-
validated: input.validated ?? false,
|
|
535
|
-
message: input.message ?? `Remote project link ready for ${input.repoSlug}.`,
|
|
536
|
-
hint: "Remote-scoped task/run/status requests will send x-rig-project-root for this server-host checkout.",
|
|
537
|
-
next: "rig task list"
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
function localCheckoutPathCandidate(projectRoot, candidate) {
|
|
541
|
-
try {
|
|
542
|
-
const local = resolve2(projectRoot);
|
|
543
|
-
const resolved = resolve2(candidate);
|
|
544
|
-
return resolved === local || resolved.startsWith(`${local}/`);
|
|
545
|
-
} catch {
|
|
546
|
-
return false;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
async function requestRemoteProjectLinkJson(baseUrl, pathname, authToken, init = {}) {
|
|
550
|
-
const requestUrl = new URL(`${baseUrl}${pathname}`);
|
|
551
|
-
if (authToken && queryAuthFallbackEnabled())
|
|
552
|
-
requestUrl.searchParams.set("rt", authToken);
|
|
553
|
-
const response = await fetch(requestUrl, {
|
|
554
|
-
...init,
|
|
555
|
-
headers: mergeHeaders(init.headers, authToken)
|
|
556
|
-
});
|
|
557
|
-
const text = await response.text();
|
|
558
|
-
const payload = text.trim().length > 0 ? (() => {
|
|
559
|
-
try {
|
|
560
|
-
return JSON.parse(text);
|
|
561
|
-
} catch {
|
|
562
|
-
return null;
|
|
563
|
-
}
|
|
564
|
-
})() : null;
|
|
565
|
-
return { ok: response.ok, status: response.status, payload, text };
|
|
566
|
-
}
|
|
567
|
-
function payloadError(payload, fallback) {
|
|
568
|
-
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
569
|
-
const record = payload;
|
|
570
|
-
const value = record.error ?? record.message ?? record.reason;
|
|
571
|
-
if (typeof value === "string" && value.trim())
|
|
572
|
-
return value.trim();
|
|
573
|
-
}
|
|
574
|
-
return fallback;
|
|
575
|
-
}
|
|
576
|
-
function checkoutPathsFromProjectPayload(payload) {
|
|
577
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
578
|
-
return [];
|
|
579
|
-
const project = payload.project;
|
|
580
|
-
if (!project || typeof project !== "object" || Array.isArray(project))
|
|
581
|
-
return [];
|
|
582
|
-
const checkouts = project.checkouts;
|
|
583
|
-
if (!Array.isArray(checkouts))
|
|
584
|
-
return [];
|
|
585
|
-
return [...checkouts].reverse().flatMap((entry) => {
|
|
586
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
587
|
-
return [];
|
|
588
|
-
const path = entry.path;
|
|
589
|
-
return typeof path === "string" && path.trim() ? [path.trim()] : [];
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
function checkoutPathFromPreparePayload(payload) {
|
|
593
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
594
|
-
return null;
|
|
595
|
-
const checkout = payload.checkout;
|
|
596
|
-
if (!checkout || typeof checkout !== "object" || Array.isArray(checkout))
|
|
597
|
-
return null;
|
|
598
|
-
const path = checkout.path;
|
|
599
|
-
return typeof path === "string" && path.trim() ? path.trim() : null;
|
|
600
|
-
}
|
|
601
|
-
async function validateAndPersistRemoteRoot(input) {
|
|
602
|
-
const candidate = input.candidate.trim();
|
|
603
|
-
if (!candidate || !isAbsolute(candidate)) {
|
|
604
|
-
return remoteProjectLinkFailure({
|
|
605
|
-
status: "invalid_root",
|
|
606
|
-
alias: input.alias,
|
|
607
|
-
baseUrl: input.baseUrl,
|
|
608
|
-
repoSlug: input.repoSlug,
|
|
609
|
-
message: `Remote project root candidate is not an absolute server-host path: ${candidate || "(empty)"}.`
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
|
-
if (localCheckoutPathCandidate(input.projectRoot, candidate)) {
|
|
613
|
-
return remoteProjectLinkFailure({
|
|
614
|
-
status: "invalid_root",
|
|
615
|
-
alias: input.alias,
|
|
616
|
-
baseUrl: input.baseUrl,
|
|
617
|
-
repoSlug: input.repoSlug,
|
|
618
|
-
message: `Refusing to use local checkout path ${candidate} as a remote server project root.`
|
|
619
|
-
});
|
|
620
|
-
}
|
|
621
|
-
let response;
|
|
622
|
-
try {
|
|
623
|
-
response = await requestRemoteProjectLinkJson(input.baseUrl, "/api/server/project-root", input.authToken, {
|
|
624
|
-
method: "POST",
|
|
625
|
-
headers: { "content-type": "application/json" },
|
|
626
|
-
body: JSON.stringify({ projectRoot: candidate })
|
|
627
|
-
});
|
|
628
|
-
} catch (error) {
|
|
629
|
-
return remoteProjectLinkFailure({
|
|
630
|
-
status: "error",
|
|
631
|
-
alias: input.alias,
|
|
632
|
-
baseUrl: input.baseUrl,
|
|
633
|
-
repoSlug: input.repoSlug,
|
|
634
|
-
message: `Could not validate remote project root ${candidate}: ${error instanceof Error ? error.message : String(error)}`
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
if (response.status === 401 || response.status === 403) {
|
|
638
|
-
return remoteProjectLinkFailure({
|
|
639
|
-
status: "auth_required",
|
|
640
|
-
alias: input.alias,
|
|
641
|
-
baseUrl: input.baseUrl,
|
|
642
|
-
repoSlug: input.repoSlug,
|
|
643
|
-
statusCode: response.status,
|
|
644
|
-
message: `Remote server ${input.alias} requires authentication before validating project root ${candidate}.`
|
|
645
|
-
});
|
|
646
|
-
}
|
|
647
|
-
if (!response.ok) {
|
|
648
|
-
return remoteProjectLinkFailure({
|
|
649
|
-
status: "invalid_root",
|
|
650
|
-
alias: input.alias,
|
|
651
|
-
baseUrl: input.baseUrl,
|
|
652
|
-
repoSlug: input.repoSlug,
|
|
653
|
-
statusCode: response.status,
|
|
654
|
-
message: `Remote server rejected project root ${candidate} (${response.status}): ${payloadError(response.payload, response.text || "project-root validation failed")}`
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
const record = response.payload && typeof response.payload === "object" && !Array.isArray(response.payload) ? response.payload : {};
|
|
658
|
-
if (record.ok !== true) {
|
|
659
|
-
return remoteProjectLinkFailure({
|
|
660
|
-
status: "invalid_root",
|
|
661
|
-
alias: input.alias,
|
|
662
|
-
baseUrl: input.baseUrl,
|
|
663
|
-
repoSlug: input.repoSlug,
|
|
664
|
-
message: `Remote server did not accept project root ${candidate}: ${payloadError(response.payload, "project-root validation failed")}`
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
const accepted = typeof record.projectRoot === "string" && record.projectRoot.trim() ? record.projectRoot.trim() : typeof record.requestedProjectRoot === "string" && record.requestedProjectRoot.trim() ? record.requestedProjectRoot.trim() : candidate;
|
|
668
|
-
writeRepoServerProjectRoot(input.projectRoot, accepted, { alias: input.alias, baseUrl: input.baseUrl, project: input.repoSlug });
|
|
669
|
-
writeProjectLinkConnection(input.projectRoot, input.repoSlug, input.alias);
|
|
670
|
-
const status = input.status ?? (input.prepared ? "prepared" : "backfilled");
|
|
671
|
-
return remoteProjectLinkSuccess({
|
|
672
|
-
status,
|
|
673
|
-
alias: input.alias,
|
|
674
|
-
baseUrl: input.baseUrl,
|
|
675
|
-
repoSlug: input.repoSlug,
|
|
676
|
-
serverProjectRoot: accepted,
|
|
677
|
-
source: input.source,
|
|
678
|
-
prepared: input.prepared,
|
|
679
|
-
validated: true,
|
|
680
|
-
message: status === "ready" ? `Remote project link already points to ${accepted} and was validated on ${input.alias}.` : input.prepared ? `Prepared and linked remote checkout ${accepted} for ${input.repoSlug}.` : `Backfilled remote checkout ${accepted} for ${input.repoSlug}.`
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
async function ensureRemoteProjectRootLink(projectRoot, options = {}) {
|
|
684
|
-
let selected;
|
|
685
|
-
try {
|
|
686
|
-
selected = resolveSelectedConnection(projectRoot);
|
|
687
|
-
} catch (error) {
|
|
688
|
-
return remoteProjectLinkFailure({ status: "error", message: error instanceof Error ? error.message : String(error) });
|
|
689
|
-
}
|
|
690
|
-
if (!selected || selected.connection.kind !== "remote") {
|
|
691
|
-
return remoteProjectLinkFailure({ status: "not_remote", message: "No remote Rig server is selected for this repo." });
|
|
692
|
-
}
|
|
693
|
-
const repo = readRepoConnection(projectRoot);
|
|
694
|
-
const explicitRepoRequested = options.repoSlug !== undefined;
|
|
695
|
-
const explicitRepoSlug = explicitRepoRequested ? normalizeRepoSlug(options.repoSlug) : null;
|
|
696
|
-
const repoProjectSlug = normalizeRepoSlug(repo?.project);
|
|
697
|
-
const repoSlug = explicitRepoSlug ?? repoProjectSlug ?? readProjectLinkSlug(projectRoot);
|
|
698
|
-
const alias = selected.alias;
|
|
699
|
-
const baseUrl = selected.connection.baseUrl;
|
|
700
|
-
const authToken = options.authToken === undefined ? readGitHubBearerTokenForRemote(projectRoot) : options.authToken;
|
|
701
|
-
const mode = options.mode ?? "backfill-only";
|
|
702
|
-
if (explicitRepoRequested && !explicitRepoSlug) {
|
|
703
|
-
return remoteProjectLinkFailure({
|
|
704
|
-
status: "missing_project",
|
|
705
|
-
alias,
|
|
706
|
-
baseUrl,
|
|
707
|
-
message: `Invalid --repo value ${JSON.stringify(options.repoSlug)}. Expected owner/repo.`
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
if (!repoSlug) {
|
|
711
|
-
return remoteProjectLinkFailure({
|
|
712
|
-
status: "missing_project",
|
|
713
|
-
alias,
|
|
714
|
-
baseUrl,
|
|
715
|
-
message: `Remote server ${alias} is selected, but this checkout has no GitHub repo slug recorded.`
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
const skippedCandidates = [];
|
|
719
|
-
const storedRoot = selected.serverProjectRoot?.trim() || null;
|
|
720
|
-
const storedRootMatchesResolvedRepo = repoProjectSlug === repoSlug;
|
|
721
|
-
if (storedRoot && storedRootMatchesResolvedRepo) {
|
|
722
|
-
if (localCheckoutPathCandidate(projectRoot, storedRoot)) {
|
|
723
|
-
clearRepoServerProjectRoot(projectRoot);
|
|
724
|
-
skippedCandidates.push(storedRoot);
|
|
725
|
-
} else {
|
|
726
|
-
const storedResult = await validateAndPersistRemoteRoot({
|
|
727
|
-
projectRoot,
|
|
728
|
-
alias,
|
|
729
|
-
baseUrl,
|
|
730
|
-
authToken,
|
|
731
|
-
repoSlug,
|
|
732
|
-
candidate: storedRoot,
|
|
733
|
-
source: "stored",
|
|
734
|
-
status: "ready"
|
|
735
|
-
});
|
|
736
|
-
if (storedResult.ok || storedResult.status === "auth_required" || storedResult.status === "error")
|
|
737
|
-
return storedResult;
|
|
738
|
-
clearRepoServerProjectRoot(projectRoot);
|
|
739
|
-
skippedCandidates.push(storedRoot);
|
|
740
|
-
}
|
|
741
|
-
} else if (storedRoot) {
|
|
742
|
-
skippedCandidates.push(storedRoot);
|
|
743
|
-
}
|
|
744
|
-
const authCandidate = inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug);
|
|
745
|
-
if (authCandidate) {
|
|
746
|
-
const authResult = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: authCandidate, source: "auth-state" });
|
|
747
|
-
if (authResult.ok || authResult.status === "auth_required")
|
|
748
|
-
return authResult;
|
|
749
|
-
}
|
|
750
|
-
let registryResponse;
|
|
751
|
-
try {
|
|
752
|
-
registryResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}`, authToken);
|
|
753
|
-
} catch (error) {
|
|
754
|
-
return remoteProjectLinkFailure({
|
|
755
|
-
status: "error",
|
|
756
|
-
alias,
|
|
757
|
-
baseUrl,
|
|
758
|
-
repoSlug,
|
|
759
|
-
message: `Could not read remote project registry for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
|
|
760
|
-
});
|
|
761
|
-
}
|
|
762
|
-
if (registryResponse.status === 401 || registryResponse.status === 403) {
|
|
763
|
-
return remoteProjectLinkFailure({
|
|
764
|
-
status: "auth_required",
|
|
765
|
-
alias,
|
|
766
|
-
baseUrl,
|
|
767
|
-
repoSlug,
|
|
768
|
-
statusCode: registryResponse.status,
|
|
769
|
-
message: `Remote server ${alias} requires authentication before reading the ${repoSlug} project registry.`
|
|
770
|
-
});
|
|
771
|
-
}
|
|
772
|
-
if (registryResponse.ok) {
|
|
773
|
-
const candidates = checkoutPathsFromProjectPayload(registryResponse.payload);
|
|
774
|
-
for (const candidate of candidates) {
|
|
775
|
-
const result = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate, source: "registry" });
|
|
776
|
-
if (result.ok || result.status === "auth_required")
|
|
777
|
-
return result;
|
|
778
|
-
skippedCandidates.push(candidate);
|
|
779
|
-
}
|
|
780
|
-
if (mode === "backfill-only") {
|
|
781
|
-
return remoteProjectLinkFailure({
|
|
782
|
-
status: candidates.length > 0 ? "invalid_root" : "no_server_checkout",
|
|
783
|
-
alias,
|
|
784
|
-
baseUrl,
|
|
785
|
-
repoSlug,
|
|
786
|
-
message: candidates.length > 0 ? `Remote registry has checkout candidates for ${repoSlug}, but none validated for ${alias}.` : `Remote registry has ${repoSlug}, but no server checkout path is linked yet.`,
|
|
787
|
-
skippedCandidates
|
|
788
|
-
});
|
|
789
|
-
}
|
|
790
|
-
} else if (registryResponse.status === 404) {
|
|
791
|
-
if (mode === "backfill-only") {
|
|
792
|
-
return remoteProjectLinkFailure({
|
|
793
|
-
status: "project_not_registered",
|
|
794
|
-
alias,
|
|
795
|
-
baseUrl,
|
|
796
|
-
repoSlug,
|
|
797
|
-
statusCode: registryResponse.status,
|
|
798
|
-
message: `Remote server ${alias} has no registered project record for ${repoSlug}.`
|
|
799
|
-
});
|
|
800
|
-
}
|
|
801
|
-
} else {
|
|
802
|
-
return remoteProjectLinkFailure({
|
|
803
|
-
status: "error",
|
|
804
|
-
alias,
|
|
805
|
-
baseUrl,
|
|
806
|
-
repoSlug,
|
|
807
|
-
statusCode: registryResponse.status,
|
|
808
|
-
message: `Could not backfill ${repoSlug} from remote registry (${registryResponse.status}): ${payloadError(registryResponse.payload, registryResponse.text || "registry lookup failed")}`,
|
|
809
|
-
skippedCandidates
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
|
-
let prepareResponse;
|
|
813
|
-
try {
|
|
814
|
-
prepareResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}/prepare-checkout`, authToken, {
|
|
815
|
-
method: "POST",
|
|
816
|
-
headers: { "content-type": "application/json" },
|
|
817
|
-
body: JSON.stringify({ checkout: { kind: "managed-clone" }, repoUrl: `https://github.com/${repoSlug}.git` })
|
|
818
|
-
});
|
|
819
|
-
} catch (error) {
|
|
820
|
-
return remoteProjectLinkFailure({
|
|
821
|
-
status: "error",
|
|
822
|
-
alias,
|
|
823
|
-
baseUrl,
|
|
824
|
-
repoSlug,
|
|
825
|
-
message: `Could not prepare remote checkout for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
|
|
826
|
-
});
|
|
827
|
-
}
|
|
828
|
-
if (prepareResponse.status === 401 || prepareResponse.status === 403) {
|
|
829
|
-
return remoteProjectLinkFailure({
|
|
830
|
-
status: "auth_required",
|
|
831
|
-
alias,
|
|
832
|
-
baseUrl,
|
|
833
|
-
repoSlug,
|
|
834
|
-
statusCode: prepareResponse.status,
|
|
835
|
-
message: `Remote server ${alias} requires authentication before preparing ${repoSlug}.`
|
|
836
|
-
});
|
|
837
|
-
}
|
|
838
|
-
if (!prepareResponse.ok) {
|
|
839
|
-
return remoteProjectLinkFailure({
|
|
840
|
-
status: "error",
|
|
841
|
-
alias,
|
|
842
|
-
baseUrl,
|
|
843
|
-
repoSlug,
|
|
844
|
-
statusCode: prepareResponse.status,
|
|
845
|
-
message: `Remote checkout prepare failed for ${repoSlug} (${prepareResponse.status}): ${payloadError(prepareResponse.payload, prepareResponse.text || "prepare-checkout failed")}`,
|
|
846
|
-
skippedCandidates
|
|
847
|
-
});
|
|
848
|
-
}
|
|
849
|
-
const preparedPath = checkoutPathFromPreparePayload(prepareResponse.payload);
|
|
850
|
-
if (!preparedPath) {
|
|
851
|
-
return remoteProjectLinkFailure({
|
|
852
|
-
status: "invalid_root",
|
|
853
|
-
alias,
|
|
854
|
-
baseUrl,
|
|
855
|
-
repoSlug,
|
|
856
|
-
message: `Remote checkout prepare for ${repoSlug} did not return a checkout.path.`,
|
|
857
|
-
skippedCandidates
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
return validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: preparedPath, source: "prepare", prepared: true });
|
|
861
|
-
}
|
|
862
|
-
async function repairRemoteProjectRootLink(context, options = {}) {
|
|
863
|
-
const resolution = await ensureRemoteProjectRootLink(context.projectRoot, { mode: options.mode ?? "prepare-if-missing", repoSlug: options.repoSlug });
|
|
864
|
-
if (!resolution.ok)
|
|
865
|
-
throw new CliError(resolution.message, 1, { hint: resolution.hint });
|
|
866
|
-
return resolution;
|
|
529
|
+
function readLocalConnectionFallbackToken(projectRoot) {
|
|
530
|
+
return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
|
|
867
531
|
}
|
|
868
532
|
async function ensureServerForCli(projectRoot) {
|
|
869
533
|
try {
|
|
@@ -871,12 +535,12 @@ async function ensureServerForCli(projectRoot) {
|
|
|
871
535
|
if (selected?.connection.kind === "remote") {
|
|
872
536
|
reportServerPhase(`Connecting to ${selected.alias}\u2026`);
|
|
873
537
|
const authToken = readGitHubBearerTokenForRemote(projectRoot);
|
|
874
|
-
const
|
|
538
|
+
const serverProjectRoot = selected.serverProjectRoot ?? await backfillRemoteServerProjectRoot(projectRoot, selected.connection.baseUrl, authToken);
|
|
875
539
|
return {
|
|
876
540
|
baseUrl: selected.connection.baseUrl,
|
|
877
541
|
authToken,
|
|
878
542
|
connectionKind: "remote",
|
|
879
|
-
serverProjectRoot
|
|
543
|
+
serverProjectRoot
|
|
880
544
|
};
|
|
881
545
|
}
|
|
882
546
|
reportServerPhase("Starting local Rig server\u2026");
|
|
@@ -894,23 +558,33 @@ async function ensureServerForCli(projectRoot) {
|
|
|
894
558
|
throw error;
|
|
895
559
|
}
|
|
896
560
|
}
|
|
897
|
-
function
|
|
898
|
-
const
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
|
|
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
|
+
}
|
|
906
583
|
}
|
|
907
584
|
function mergeHeaders(headers, authToken) {
|
|
908
585
|
const merged = new Headers(headers);
|
|
909
586
|
if (authToken) {
|
|
910
|
-
|
|
911
|
-
merged.set("authorization", bearer);
|
|
912
|
-
merged.set("x-auth", bearer);
|
|
913
|
-
merged.set("cookie", mergeCookie(merged.get("cookie"), "rig_auth", authToken));
|
|
587
|
+
merged.set("authorization", `Bearer ${authToken}`);
|
|
914
588
|
}
|
|
915
589
|
return merged;
|
|
916
590
|
}
|
|
@@ -971,41 +645,15 @@ async function buildServerFailureContext(projectRoot, server) {
|
|
|
971
645
|
hint: "Check the selected server with `rig server status`, or switch with `rig server use <alias|local>`."
|
|
972
646
|
};
|
|
973
647
|
}
|
|
974
|
-
function isLoopbackRemoteBaseUrl(baseUrl) {
|
|
975
|
-
try {
|
|
976
|
-
const host = new URL(baseUrl).hostname.toLowerCase();
|
|
977
|
-
return host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]";
|
|
978
|
-
} catch {
|
|
979
|
-
return false;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
function canUseRemoteWithoutProjectRoot(pathname) {
|
|
983
|
-
return pathname === "/health" || pathname === "/api/health" || pathname === "/api/server/status" || pathname === "/api/server/project-root" || pathname.startsWith("/api/github/auth/") || pathname === "/api/projects" || pathname.startsWith("/api/projects/");
|
|
984
|
-
}
|
|
985
648
|
async function requestServerJson(context, pathname, init = {}) {
|
|
986
649
|
const server = await ensureServerForCli(context.projectRoot);
|
|
987
|
-
const requestUrl = new URL(`${server.baseUrl}${pathname}`);
|
|
988
|
-
let scopedServerProjectRoot = server.serverProjectRoot;
|
|
989
|
-
if (server.connectionKind === "remote" && !scopedServerProjectRoot && !canUseRemoteWithoutProjectRoot(requestUrl.pathname) && (server.authToken || !isLoopbackRemoteBaseUrl(server.baseUrl))) {
|
|
990
|
-
const link = await ensureRemoteProjectRootLink(context.projectRoot, { mode: "backfill-only", authToken: server.authToken });
|
|
991
|
-
if (link.ok && link.serverProjectRoot) {
|
|
992
|
-
scopedServerProjectRoot = link.serverProjectRoot;
|
|
993
|
-
} else {
|
|
994
|
-
const repo = readRepoConnection(context.projectRoot);
|
|
995
|
-
const target = link.alias && link.baseUrl ? `${link.alias} (${link.baseUrl})` : server.baseUrl;
|
|
996
|
-
throw new CliError(`Remote server ${target} is selected for ${link.repoSlug ?? repo?.project ?? "this repo"}, but this checkout has no server-host project root link. ${link.message}`, 1, { hint: link.hint });
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
650
|
const headers = mergeHeaders(init.headers, server.authToken);
|
|
1000
|
-
if (
|
|
1001
|
-
headers.set("x-rig-project-root",
|
|
1002
|
-
if (server.connectionKind === "remote" && server.authToken && queryAuthFallbackEnabled()) {
|
|
1003
|
-
requestUrl.searchParams.set("rt", server.authToken);
|
|
1004
|
-
}
|
|
651
|
+
if (server.serverProjectRoot)
|
|
652
|
+
headers.set("x-rig-project-root", server.serverProjectRoot);
|
|
1005
653
|
reportServerPhase(`${(init.method ?? "GET").toUpperCase()} ${pathname.split("?")[0]}\u2026`);
|
|
1006
654
|
let response;
|
|
1007
655
|
try {
|
|
1008
|
-
response = await fetch(
|
|
656
|
+
response = await fetch(`${server.baseUrl}${pathname}`, {
|
|
1009
657
|
...init,
|
|
1010
658
|
headers
|
|
1011
659
|
});
|
|
@@ -1076,187 +724,10 @@ async function submitTaskRunViaServer(context, input) {
|
|
|
1076
724
|
return { runId };
|
|
1077
725
|
}
|
|
1078
726
|
|
|
1079
|
-
// packages/cli/src/commands/connect.ts
|
|
1080
|
-
function usageName(options) {
|
|
1081
|
-
return `rig ${options.group}`;
|
|
1082
|
-
}
|
|
1083
|
-
function parseConnection(alias, value, options) {
|
|
1084
|
-
if (alias === "local" && !value)
|
|
1085
|
-
return { kind: "local", mode: "auto" };
|
|
1086
|
-
if (!value)
|
|
1087
|
-
throw new CliError(`Missing remote server URL. Usage: ${usageName(options)} add <alias> <url>`, 1);
|
|
1088
|
-
let parsed;
|
|
1089
|
-
try {
|
|
1090
|
-
parsed = new URL(value);
|
|
1091
|
-
} catch {
|
|
1092
|
-
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`." });
|
|
1093
|
-
}
|
|
1094
|
-
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
|
|
1095
|
-
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`." });
|
|
1096
|
-
}
|
|
1097
|
-
return { kind: "remote", baseUrl: parsed.toString().replace(/\/+$/, "") };
|
|
1098
|
-
}
|
|
1099
|
-
function printJsonOrText(context, _payload, text) {
|
|
1100
|
-
if (context.outputMode !== "json") {
|
|
1101
|
-
console.log(text);
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
function formatRemoteProjectLinkText(result) {
|
|
1105
|
-
return formatSuccessCard(result.ok ? "Remote project link ready" : "Remote project link needs repair", [
|
|
1106
|
-
["selected", result.alias ?? "remote"],
|
|
1107
|
-
["target", result.baseUrl ?? "unknown"],
|
|
1108
|
-
["repo", result.repoSlug ?? "owner/repo"],
|
|
1109
|
-
["status", result.status],
|
|
1110
|
-
...result.serverProjectRoot ? [["server root", result.serverProjectRoot]] : [],
|
|
1111
|
-
["next", result.ok ? result.next ?? "rig task list" : result.hint]
|
|
1112
|
-
]);
|
|
1113
|
-
}
|
|
1114
|
-
function parseRepairLinkArgs(rest, usage) {
|
|
1115
|
-
let repoSlug;
|
|
1116
|
-
let mode = "prepare-if-missing";
|
|
1117
|
-
const pending = [...rest];
|
|
1118
|
-
while (pending.length > 0) {
|
|
1119
|
-
const token = pending.shift();
|
|
1120
|
-
if (token === "--repo") {
|
|
1121
|
-
const value = pending.shift()?.trim();
|
|
1122
|
-
if (!value)
|
|
1123
|
-
throw new CliError(`Missing --repo value. Usage: ${usage}`, 1);
|
|
1124
|
-
const normalized = normalizeRepoSlug(value);
|
|
1125
|
-
if (!normalized)
|
|
1126
|
-
throw new CliError(`Invalid --repo value: ${value}`, 1, { hint: "Use the canonical owner/repo slug, e.g. `--repo humanity-org/humanwork`." });
|
|
1127
|
-
repoSlug = normalized;
|
|
1128
|
-
} else if (token === "--backfill-only") {
|
|
1129
|
-
mode = "backfill-only";
|
|
1130
|
-
} else if (token === "--prepare") {
|
|
1131
|
-
mode = "prepare-if-missing";
|
|
1132
|
-
} else {
|
|
1133
|
-
throw new CliError(`Unexpected argument: ${String(token)}
|
|
1134
|
-
Usage: ${usage}`, 1);
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
return { repoSlug, mode };
|
|
1138
|
-
}
|
|
1139
|
-
async function promptForConnectionAlias(context) {
|
|
1140
|
-
const state = readGlobalConnections();
|
|
1141
|
-
const repo = readRepoConnection(context.projectRoot);
|
|
1142
|
-
const options = [
|
|
1143
|
-
{ value: "local", label: "local", hint: "Use/start a local Rig server" },
|
|
1144
|
-
...Object.entries(state.connections).map(([alias, connection]) => ({
|
|
1145
|
-
value: alias,
|
|
1146
|
-
label: alias,
|
|
1147
|
-
hint: connection.kind === "remote" ? connection.baseUrl : "local"
|
|
1148
|
-
}))
|
|
1149
|
-
].filter((option, index, all) => all.findIndex((candidate) => candidate.value === option.value) === index);
|
|
1150
|
-
const answer = await droneSelect({
|
|
1151
|
-
message: "Select Rig server for this repo",
|
|
1152
|
-
initialValue: repo?.selected ?? "local",
|
|
1153
|
-
options
|
|
1154
|
-
});
|
|
1155
|
-
if (answer === null) {
|
|
1156
|
-
droneCancel("No server selected.");
|
|
1157
|
-
throw new CliError("No server selected.", 3);
|
|
1158
|
-
}
|
|
1159
|
-
return String(answer);
|
|
1160
|
-
}
|
|
1161
|
-
async function executeConnectionCommand(context, args, options) {
|
|
1162
|
-
const [command, ...rest] = args;
|
|
1163
|
-
switch (command ?? "status") {
|
|
1164
|
-
case "list": {
|
|
1165
|
-
requireNoExtraArgs(rest, `${usageName(options)} list`);
|
|
1166
|
-
const state = readGlobalConnections();
|
|
1167
|
-
printJsonOrText(context, state, formatConnectionList(state.connections));
|
|
1168
|
-
return { ok: true, group: options.group, command: "list", details: state };
|
|
1169
|
-
}
|
|
1170
|
-
case "add": {
|
|
1171
|
-
const [alias, url, ...extra] = rest;
|
|
1172
|
-
if (!alias)
|
|
1173
|
-
throw new CliError(`Missing alias. Usage: ${usageName(options)} add <alias> <url>`, 1);
|
|
1174
|
-
requireNoExtraArgs(extra, `${usageName(options)} add <alias> <url>`);
|
|
1175
|
-
const connection = parseConnection(alias, url, options);
|
|
1176
|
-
const state = upsertGlobalConnection(alias, connection);
|
|
1177
|
-
printJsonOrText(context, { alias, connection }, formatSuccessCard("Rig server saved", [
|
|
1178
|
-
["alias", alias],
|
|
1179
|
-
["target", connection.kind === "remote" ? connection.baseUrl : "local"],
|
|
1180
|
-
["next", `${usageName(options)} use ${alias}`]
|
|
1181
|
-
]));
|
|
1182
|
-
return { ok: true, group: options.group, command: "add", details: { alias, connection, count: Object.keys(state.connections).length } };
|
|
1183
|
-
}
|
|
1184
|
-
case "use": {
|
|
1185
|
-
let [alias, ...extra] = rest;
|
|
1186
|
-
requireNoExtraArgs(extra, `${usageName(options)} use <alias|local>`);
|
|
1187
|
-
if (!alias && options.interactiveUse && context.outputMode === "text" && process.stdin.isTTY) {
|
|
1188
|
-
alias = await promptForConnectionAlias(context);
|
|
1189
|
-
}
|
|
1190
|
-
if (!alias)
|
|
1191
|
-
throw new CliError(`Missing alias. Usage: ${usageName(options)} use <alias|local>`, 1);
|
|
1192
|
-
let selectedConnection = { kind: "local", mode: "auto" };
|
|
1193
|
-
if (alias !== "local") {
|
|
1194
|
-
const state = readGlobalConnections();
|
|
1195
|
-
const connection = state.connections[alias];
|
|
1196
|
-
if (!connection)
|
|
1197
|
-
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>`." });
|
|
1198
|
-
selectedConnection = connection;
|
|
1199
|
-
}
|
|
1200
|
-
const previousRepo = readRepoConnection(context.projectRoot);
|
|
1201
|
-
const preserveRemoteRoot = Boolean(previousRepo?.serverProjectRoot && previousRepo.selected === alias && selectedConnection.kind === "remote" && previousRepo.serverProjectRootAlias === alias && previousRepo.serverProjectRootBaseUrl === selectedConnection.baseUrl);
|
|
1202
|
-
const repoState = {
|
|
1203
|
-
selected: alias,
|
|
1204
|
-
...previousRepo?.project ? { project: previousRepo.project } : {},
|
|
1205
|
-
linkedAt: new Date().toISOString(),
|
|
1206
|
-
...preserveRemoteRoot ? {
|
|
1207
|
-
serverProjectRoot: previousRepo.serverProjectRoot,
|
|
1208
|
-
serverProjectRootAlias: previousRepo.serverProjectRootAlias,
|
|
1209
|
-
serverProjectRootBaseUrl: previousRepo.serverProjectRootBaseUrl
|
|
1210
|
-
} : {}
|
|
1211
|
-
};
|
|
1212
|
-
writeRepoConnection(context.projectRoot, repoState);
|
|
1213
|
-
const remoteProjectLink = alias !== "local" ? await ensureRemoteProjectRootLink(context.projectRoot, { mode: "backfill-only" }).catch((error) => ({
|
|
1214
|
-
ok: false,
|
|
1215
|
-
status: "error",
|
|
1216
|
-
message: error instanceof Error ? error.message : String(error),
|
|
1217
|
-
hint: "Run `rig server repair-link` after authenticating the selected remote."
|
|
1218
|
-
})) : null;
|
|
1219
|
-
const latestRepo = readRepoConnection(context.projectRoot);
|
|
1220
|
-
const details = { selected: latestRepo?.selected ?? alias, repo: latestRepo, remoteProjectLink };
|
|
1221
|
-
printJsonOrText(context, details, formatSuccessCard("Rig server selected", [
|
|
1222
|
-
["selected", alias],
|
|
1223
|
-
["scope", "this repo"],
|
|
1224
|
-
...remoteProjectLink ? [["remote link", remoteProjectLink.ok ? `ready (${remoteProjectLink.serverProjectRoot ?? "linked"})` : `${remoteProjectLink.status}: ${remoteProjectLink.hint}`]] : [],
|
|
1225
|
-
["next", remoteProjectLink && !remoteProjectLink.ok ? "rig server repair-link" : "rig task list"]
|
|
1226
|
-
]));
|
|
1227
|
-
return { ok: true, group: options.group, command: "use", details };
|
|
1228
|
-
}
|
|
1229
|
-
case "repair-link": {
|
|
1230
|
-
const parsed = parseRepairLinkArgs(rest, `${usageName(options)} repair-link [--prepare|--backfill-only] [--repo owner/repo]`);
|
|
1231
|
-
const result = await repairRemoteProjectRootLink(context, parsed);
|
|
1232
|
-
printJsonOrText(context, result, formatRemoteProjectLinkText(result));
|
|
1233
|
-
return { ok: true, group: options.group, command: "repair-link", details: result };
|
|
1234
|
-
}
|
|
1235
|
-
case "status": {
|
|
1236
|
-
requireNoExtraArgs(rest, `${usageName(options)} status`);
|
|
1237
|
-
const repo = readRepoConnection(context.projectRoot);
|
|
1238
|
-
const global = readGlobalConnections();
|
|
1239
|
-
const remoteProjectLink = repo?.selected && repo.selected !== "local" ? await ensureRemoteProjectRootLink(context.projectRoot, { mode: "backfill-only" }).catch((error) => ({
|
|
1240
|
-
ok: false,
|
|
1241
|
-
status: "error",
|
|
1242
|
-
message: error instanceof Error ? error.message : String(error),
|
|
1243
|
-
hint: "Run `rig server repair-link` after authenticating the selected remote."
|
|
1244
|
-
})) : null;
|
|
1245
|
-
const latestRepo = readRepoConnection(context.projectRoot) ?? repo;
|
|
1246
|
-
const details = { selected: latestRepo?.selected ?? "local", repo: latestRepo, connections: global.connections, remoteProjectLink };
|
|
1247
|
-
printJsonOrText(context, details, formatConnectionStatus(details.selected, global.connections, latestRepo ?? null, remoteProjectLink));
|
|
1248
|
-
return { ok: true, group: options.group, command: "status", details };
|
|
1249
|
-
}
|
|
1250
|
-
default:
|
|
1251
|
-
throw new CliError(`Unknown ${options.group} command: ${String(command)}
|
|
1252
|
-
Usage: ${usageName(options)} <list|add|use|status|repair-link>`, 1);
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
727
|
// packages/cli/src/commands/server.ts
|
|
1257
728
|
async function executeServer(context, args, options) {
|
|
1258
729
|
const [command = "status", ...rest] = args;
|
|
1259
|
-
if (["status", "list", "add", "use"
|
|
730
|
+
if (["status", "list", "add", "use"].includes(command)) {
|
|
1260
731
|
return executeConnectionCommand(context, [command, ...rest], { group: "server", interactiveUse: true });
|
|
1261
732
|
}
|
|
1262
733
|
switch (command) {
|