@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
|
@@ -1,715 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/cli/src/commands/_server-events.ts
|
|
3
|
-
import { WsTransport } from "@rig/client";
|
|
4
|
-
import { RIG_WS_CHANNELS } from "@rig/contracts";
|
|
5
|
-
|
|
6
|
-
// packages/cli/src/commands/_server-client.ts
|
|
7
|
-
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
8
|
-
import { dirname as dirname2, isAbsolute, resolve as resolve2 } from "path";
|
|
9
|
-
|
|
10
|
-
// packages/cli/src/runner.ts
|
|
11
|
-
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
12
|
-
import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
|
|
13
|
-
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
14
|
-
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
15
|
-
|
|
16
|
-
class CliError extends RuntimeCliError {
|
|
17
|
-
hint;
|
|
18
|
-
constructor(message, exitCode = 1, options = {}) {
|
|
19
|
-
super(message, exitCode);
|
|
20
|
-
if (options.hint?.trim()) {
|
|
21
|
-
this.hint = options.hint.trim();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// packages/cli/src/commands/_server-client.ts
|
|
27
|
-
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
28
|
-
|
|
29
|
-
// packages/cli/src/commands/_connection-state.ts
|
|
30
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
31
|
-
import { homedir } from "os";
|
|
32
|
-
import { dirname, resolve } from "path";
|
|
33
|
-
function resolveGlobalConnectionsPath(env = process.env) {
|
|
34
|
-
const explicit = env.RIG_CONNECTIONS_FILE?.trim();
|
|
35
|
-
if (explicit)
|
|
36
|
-
return resolve(explicit);
|
|
37
|
-
const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
|
|
38
|
-
if (stateDir)
|
|
39
|
-
return resolve(stateDir, "connections.json");
|
|
40
|
-
return resolve(homedir(), ".rig", "connections.json");
|
|
41
|
-
}
|
|
42
|
-
function resolveRepoConnectionPath(projectRoot) {
|
|
43
|
-
return resolve(projectRoot, ".rig", "state", "connection.json");
|
|
44
|
-
}
|
|
45
|
-
function readJsonFile(path) {
|
|
46
|
-
if (!existsSync(path))
|
|
47
|
-
return null;
|
|
48
|
-
try {
|
|
49
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
50
|
-
} catch (error) {
|
|
51
|
-
throw new CliError(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1, { hint: "Fix or delete that file, then re-select a server with `rig server use <alias|local>`." });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function writeJsonFile(path, value) {
|
|
55
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
56
|
-
writeFileSync(path, `${JSON.stringify(value, null, 2)}
|
|
57
|
-
`, "utf8");
|
|
58
|
-
}
|
|
59
|
-
function normalizeConnection(value) {
|
|
60
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
61
|
-
return null;
|
|
62
|
-
const record = value;
|
|
63
|
-
if (record.kind === "local")
|
|
64
|
-
return { kind: "local", mode: "auto" };
|
|
65
|
-
if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
|
|
66
|
-
const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
|
|
67
|
-
return { kind: "remote", baseUrl };
|
|
68
|
-
}
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
function readGlobalConnections(options = {}) {
|
|
72
|
-
const path = resolveGlobalConnectionsPath(options.env ?? process.env);
|
|
73
|
-
const payload = readJsonFile(path);
|
|
74
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
75
|
-
return { connections: {} };
|
|
76
|
-
}
|
|
77
|
-
const rawConnections = payload.connections;
|
|
78
|
-
const connections = {};
|
|
79
|
-
if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
|
|
80
|
-
for (const [alias, raw] of Object.entries(rawConnections)) {
|
|
81
|
-
const connection = normalizeConnection(raw);
|
|
82
|
-
if (connection)
|
|
83
|
-
connections[alias] = connection;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return { connections };
|
|
87
|
-
}
|
|
88
|
-
function readRepoConnection(projectRoot) {
|
|
89
|
-
const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
|
|
90
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
91
|
-
return null;
|
|
92
|
-
const record = payload;
|
|
93
|
-
const selected = typeof record.selected === "string" ? record.selected.trim() : "";
|
|
94
|
-
if (!selected)
|
|
95
|
-
return null;
|
|
96
|
-
return {
|
|
97
|
-
selected,
|
|
98
|
-
project: typeof record.project === "string" ? record.project : undefined,
|
|
99
|
-
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
|
|
100
|
-
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined,
|
|
101
|
-
serverProjectRootAlias: typeof record.serverProjectRootAlias === "string" && record.serverProjectRootAlias.trim() ? record.serverProjectRootAlias.trim() : undefined,
|
|
102
|
-
serverProjectRootBaseUrl: typeof record.serverProjectRootBaseUrl === "string" && record.serverProjectRootBaseUrl.trim() ? record.serverProjectRootBaseUrl.trim().replace(/\/+$/, "") : undefined
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
function writeRepoConnection(projectRoot, state) {
|
|
106
|
-
writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
|
|
107
|
-
}
|
|
108
|
-
function rootAllowedForSelection(repo, connection) {
|
|
109
|
-
const root = repo.serverProjectRoot?.trim();
|
|
110
|
-
if (!root)
|
|
111
|
-
return;
|
|
112
|
-
if (connection.kind === "remote") {
|
|
113
|
-
if (repo.serverProjectRootAlias !== repo.selected)
|
|
114
|
-
return;
|
|
115
|
-
if (repo.serverProjectRootBaseUrl !== connection.baseUrl)
|
|
116
|
-
return;
|
|
117
|
-
} else if (repo.serverProjectRootAlias && repo.serverProjectRootAlias !== repo.selected) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
return root;
|
|
121
|
-
}
|
|
122
|
-
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
123
|
-
const repo = readRepoConnection(projectRoot);
|
|
124
|
-
if (!repo)
|
|
125
|
-
return null;
|
|
126
|
-
if (repo.selected === "local")
|
|
127
|
-
return { alias: "local", connection: { kind: "local", mode: "auto" }, serverProjectRoot: repo.serverProjectRoot };
|
|
128
|
-
const global = readGlobalConnections(options);
|
|
129
|
-
const connection = global.connections[repo.selected];
|
|
130
|
-
if (!connection) {
|
|
131
|
-
throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
132
|
-
}
|
|
133
|
-
return { alias: repo.selected, connection, serverProjectRoot: rootAllowedForSelection(repo, connection) };
|
|
134
|
-
}
|
|
135
|
-
function writeRepoServerProjectRoot(projectRoot, serverProjectRoot, metadata = {}) {
|
|
136
|
-
const repo = readRepoConnection(projectRoot);
|
|
137
|
-
if (!repo)
|
|
138
|
-
return;
|
|
139
|
-
let inferred = metadata;
|
|
140
|
-
if (!inferred.alias || !inferred.baseUrl) {
|
|
141
|
-
try {
|
|
142
|
-
const selected = resolveSelectedConnection(projectRoot);
|
|
143
|
-
if (selected?.connection.kind === "remote") {
|
|
144
|
-
inferred = {
|
|
145
|
-
alias: inferred.alias ?? selected.alias,
|
|
146
|
-
baseUrl: inferred.baseUrl ?? selected.connection.baseUrl
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
} catch {}
|
|
150
|
-
}
|
|
151
|
-
writeRepoConnection(projectRoot, {
|
|
152
|
-
...repo,
|
|
153
|
-
...metadata.project ? { project: metadata.project } : {},
|
|
154
|
-
serverProjectRoot,
|
|
155
|
-
...inferred.alias ? { serverProjectRootAlias: inferred.alias } : {},
|
|
156
|
-
...inferred.baseUrl ? { serverProjectRootBaseUrl: inferred.baseUrl.replace(/\/+$/, "") } : {}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
function clearRepoServerProjectRoot(projectRoot) {
|
|
160
|
-
const repo = readRepoConnection(projectRoot);
|
|
161
|
-
if (!repo)
|
|
162
|
-
return;
|
|
163
|
-
writeRepoConnection(projectRoot, {
|
|
164
|
-
selected: repo.selected,
|
|
165
|
-
...repo.project ? { project: repo.project } : {},
|
|
166
|
-
...repo.linkedAt ? { linkedAt: repo.linkedAt } : {}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// packages/cli/src/commands/_server-client.ts
|
|
171
|
-
var scopedGitHubBearerTokens = new Map;
|
|
172
|
-
var serverPhaseListener = null;
|
|
173
|
-
function reportServerPhase(label) {
|
|
174
|
-
serverPhaseListener?.(label);
|
|
175
|
-
}
|
|
176
|
-
function cleanToken(value) {
|
|
177
|
-
const trimmed = value?.trim();
|
|
178
|
-
return trimmed ? trimmed : null;
|
|
179
|
-
}
|
|
180
|
-
function readRemoteAuthState(projectRoot) {
|
|
181
|
-
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
182
|
-
if (!existsSync2(path))
|
|
183
|
-
return null;
|
|
184
|
-
try {
|
|
185
|
-
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
186
|
-
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
187
|
-
} catch {
|
|
188
|
-
return null;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
function readPrivateRemoteSessionToken(projectRoot) {
|
|
192
|
-
const parsed = readRemoteAuthState(projectRoot);
|
|
193
|
-
return parsed ? cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined) : null;
|
|
194
|
-
}
|
|
195
|
-
function readGitHubBearerTokenForRemote(projectRoot) {
|
|
196
|
-
const scopedKey = resolve2(projectRoot);
|
|
197
|
-
if (scopedGitHubBearerTokens.has(scopedKey))
|
|
198
|
-
return scopedGitHubBearerTokens.get(scopedKey) ?? null;
|
|
199
|
-
const privateSession = readPrivateRemoteSessionToken(projectRoot);
|
|
200
|
-
if (privateSession)
|
|
201
|
-
return privateSession;
|
|
202
|
-
return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
203
|
-
}
|
|
204
|
-
function readStoredGitHubAuthToken(projectRoot) {
|
|
205
|
-
const parsed = readRemoteAuthState(projectRoot);
|
|
206
|
-
return parsed ? cleanToken(typeof parsed.token === "string" ? parsed.token : undefined) : null;
|
|
207
|
-
}
|
|
208
|
-
function inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug) {
|
|
209
|
-
if (!/^[^/]+\/[^/]+$/.test(repoSlug))
|
|
210
|
-
return null;
|
|
211
|
-
const repo = readRepoConnection(projectRoot);
|
|
212
|
-
const auth = readRemoteAuthState(projectRoot);
|
|
213
|
-
const authUpdatedAt = typeof auth?.updatedAt === "string" ? Date.parse(auth.updatedAt) : Number.NaN;
|
|
214
|
-
const repoLinkedAt = typeof repo?.linkedAt === "string" ? Date.parse(repo.linkedAt) : Number.NaN;
|
|
215
|
-
if (Number.isFinite(authUpdatedAt) && Number.isFinite(repoLinkedAt) && authUpdatedAt + 1000 < repoLinkedAt)
|
|
216
|
-
return null;
|
|
217
|
-
const checkoutBaseDir = typeof auth?.checkoutBaseDir === "string" && auth.checkoutBaseDir.trim() ? auth.checkoutBaseDir.trim() : null;
|
|
218
|
-
if (!checkoutBaseDir)
|
|
219
|
-
return null;
|
|
220
|
-
return `${checkoutBaseDir.replace(/\/+$/, "")}/${repoSlug}`;
|
|
221
|
-
}
|
|
222
|
-
function readLocalConnectionFallbackToken(projectRoot) {
|
|
223
|
-
return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
|
|
224
|
-
}
|
|
225
|
-
function normalizeRepoSlug(value) {
|
|
226
|
-
const slug = value?.trim();
|
|
227
|
-
return slug && /^[^/\s]+\/[^/\s]+$/.test(slug) ? slug : null;
|
|
228
|
-
}
|
|
229
|
-
function readProjectLinkSlug(projectRoot) {
|
|
230
|
-
const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
|
|
231
|
-
if (!existsSync2(path))
|
|
232
|
-
return null;
|
|
233
|
-
try {
|
|
234
|
-
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
235
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
236
|
-
return null;
|
|
237
|
-
return normalizeRepoSlug(typeof parsed.repoSlug === "string" ? String(parsed.repoSlug) : null);
|
|
238
|
-
} catch {
|
|
239
|
-
return null;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
function writeProjectLinkConnection(projectRoot, repoSlug, alias) {
|
|
243
|
-
const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
|
|
244
|
-
mkdirSync2(dirname2(path), { recursive: true });
|
|
245
|
-
writeFileSync2(path, `${JSON.stringify({ repoSlug, connection: alias, linkedAt: new Date().toISOString() }, null, 2)}
|
|
246
|
-
`, "utf8");
|
|
247
|
-
}
|
|
248
|
-
function remoteLinkRepairCommand(repoSlug) {
|
|
249
|
-
return repoSlug ? `rig server repair-link --repo ${repoSlug}` : "rig server repair-link --repo owner/repo";
|
|
250
|
-
}
|
|
251
|
-
function formatRemoteProjectLinkHint(resolution) {
|
|
252
|
-
const repair = remoteLinkRepairCommand(resolution.repoSlug);
|
|
253
|
-
if (resolution.status === "auth_required") {
|
|
254
|
-
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}` : ""}\`.`;
|
|
255
|
-
}
|
|
256
|
-
if (resolution.status === "missing_project") {
|
|
257
|
-
return `Record the repo slug, then run \`${repair}\` (or \`rig init --repo owner/repo --server remote --github-auth device\`).`;
|
|
258
|
-
}
|
|
259
|
-
if (resolution.status === "not_remote")
|
|
260
|
-
return "Select a remote server with `rig server use <alias>` before repairing a remote project link.";
|
|
261
|
-
return `Run \`${repair}\` to backfill or prepare a server-host checkout for the selected remote${resolution.alias ? ` (${resolution.alias})` : ""}.`;
|
|
262
|
-
}
|
|
263
|
-
function remoteProjectLinkFailure(input) {
|
|
264
|
-
const partial = {
|
|
265
|
-
status: input.status,
|
|
266
|
-
alias: input.alias,
|
|
267
|
-
baseUrl: input.baseUrl,
|
|
268
|
-
repoSlug: input.repoSlug
|
|
269
|
-
};
|
|
270
|
-
return {
|
|
271
|
-
ok: false,
|
|
272
|
-
...input,
|
|
273
|
-
hint: formatRemoteProjectLinkHint(partial),
|
|
274
|
-
next: remoteLinkRepairCommand(input.repoSlug)
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
function remoteProjectLinkSuccess(input) {
|
|
278
|
-
return {
|
|
279
|
-
ok: true,
|
|
280
|
-
status: input.status,
|
|
281
|
-
alias: input.alias,
|
|
282
|
-
baseUrl: input.baseUrl,
|
|
283
|
-
repoSlug: input.repoSlug,
|
|
284
|
-
serverProjectRoot: input.serverProjectRoot,
|
|
285
|
-
source: input.source,
|
|
286
|
-
prepared: input.prepared ?? input.status === "prepared",
|
|
287
|
-
validated: input.validated ?? false,
|
|
288
|
-
message: input.message ?? `Remote project link ready for ${input.repoSlug}.`,
|
|
289
|
-
hint: "Remote-scoped task/run/status requests will send x-rig-project-root for this server-host checkout.",
|
|
290
|
-
next: "rig task list"
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
function localCheckoutPathCandidate(projectRoot, candidate) {
|
|
294
|
-
try {
|
|
295
|
-
const local = resolve2(projectRoot);
|
|
296
|
-
const resolved = resolve2(candidate);
|
|
297
|
-
return resolved === local || resolved.startsWith(`${local}/`);
|
|
298
|
-
} catch {
|
|
299
|
-
return false;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
async function requestRemoteProjectLinkJson(baseUrl, pathname, authToken, init = {}) {
|
|
303
|
-
const requestUrl = new URL(`${baseUrl}${pathname}`);
|
|
304
|
-
if (authToken && queryAuthFallbackEnabled())
|
|
305
|
-
requestUrl.searchParams.set("rt", authToken);
|
|
306
|
-
const response = await fetch(requestUrl, {
|
|
307
|
-
...init,
|
|
308
|
-
headers: mergeHeaders(init.headers, authToken)
|
|
309
|
-
});
|
|
310
|
-
const text = await response.text();
|
|
311
|
-
const payload = text.trim().length > 0 ? (() => {
|
|
312
|
-
try {
|
|
313
|
-
return JSON.parse(text);
|
|
314
|
-
} catch {
|
|
315
|
-
return null;
|
|
316
|
-
}
|
|
317
|
-
})() : null;
|
|
318
|
-
return { ok: response.ok, status: response.status, payload, text };
|
|
319
|
-
}
|
|
320
|
-
function payloadError(payload, fallback) {
|
|
321
|
-
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
322
|
-
const record = payload;
|
|
323
|
-
const value = record.error ?? record.message ?? record.reason;
|
|
324
|
-
if (typeof value === "string" && value.trim())
|
|
325
|
-
return value.trim();
|
|
326
|
-
}
|
|
327
|
-
return fallback;
|
|
328
|
-
}
|
|
329
|
-
function checkoutPathsFromProjectPayload(payload) {
|
|
330
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
331
|
-
return [];
|
|
332
|
-
const project = payload.project;
|
|
333
|
-
if (!project || typeof project !== "object" || Array.isArray(project))
|
|
334
|
-
return [];
|
|
335
|
-
const checkouts = project.checkouts;
|
|
336
|
-
if (!Array.isArray(checkouts))
|
|
337
|
-
return [];
|
|
338
|
-
return [...checkouts].reverse().flatMap((entry) => {
|
|
339
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
340
|
-
return [];
|
|
341
|
-
const path = entry.path;
|
|
342
|
-
return typeof path === "string" && path.trim() ? [path.trim()] : [];
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
function checkoutPathFromPreparePayload(payload) {
|
|
346
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
347
|
-
return null;
|
|
348
|
-
const checkout = payload.checkout;
|
|
349
|
-
if (!checkout || typeof checkout !== "object" || Array.isArray(checkout))
|
|
350
|
-
return null;
|
|
351
|
-
const path = checkout.path;
|
|
352
|
-
return typeof path === "string" && path.trim() ? path.trim() : null;
|
|
353
|
-
}
|
|
354
|
-
async function validateAndPersistRemoteRoot(input) {
|
|
355
|
-
const candidate = input.candidate.trim();
|
|
356
|
-
if (!candidate || !isAbsolute(candidate)) {
|
|
357
|
-
return remoteProjectLinkFailure({
|
|
358
|
-
status: "invalid_root",
|
|
359
|
-
alias: input.alias,
|
|
360
|
-
baseUrl: input.baseUrl,
|
|
361
|
-
repoSlug: input.repoSlug,
|
|
362
|
-
message: `Remote project root candidate is not an absolute server-host path: ${candidate || "(empty)"}.`
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
if (localCheckoutPathCandidate(input.projectRoot, candidate)) {
|
|
366
|
-
return remoteProjectLinkFailure({
|
|
367
|
-
status: "invalid_root",
|
|
368
|
-
alias: input.alias,
|
|
369
|
-
baseUrl: input.baseUrl,
|
|
370
|
-
repoSlug: input.repoSlug,
|
|
371
|
-
message: `Refusing to use local checkout path ${candidate} as a remote server project root.`
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
let response;
|
|
375
|
-
try {
|
|
376
|
-
response = await requestRemoteProjectLinkJson(input.baseUrl, "/api/server/project-root", input.authToken, {
|
|
377
|
-
method: "POST",
|
|
378
|
-
headers: { "content-type": "application/json" },
|
|
379
|
-
body: JSON.stringify({ projectRoot: candidate })
|
|
380
|
-
});
|
|
381
|
-
} catch (error) {
|
|
382
|
-
return remoteProjectLinkFailure({
|
|
383
|
-
status: "error",
|
|
384
|
-
alias: input.alias,
|
|
385
|
-
baseUrl: input.baseUrl,
|
|
386
|
-
repoSlug: input.repoSlug,
|
|
387
|
-
message: `Could not validate remote project root ${candidate}: ${error instanceof Error ? error.message : String(error)}`
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
if (response.status === 401 || response.status === 403) {
|
|
391
|
-
return remoteProjectLinkFailure({
|
|
392
|
-
status: "auth_required",
|
|
393
|
-
alias: input.alias,
|
|
394
|
-
baseUrl: input.baseUrl,
|
|
395
|
-
repoSlug: input.repoSlug,
|
|
396
|
-
statusCode: response.status,
|
|
397
|
-
message: `Remote server ${input.alias} requires authentication before validating project root ${candidate}.`
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
if (!response.ok) {
|
|
401
|
-
return remoteProjectLinkFailure({
|
|
402
|
-
status: "invalid_root",
|
|
403
|
-
alias: input.alias,
|
|
404
|
-
baseUrl: input.baseUrl,
|
|
405
|
-
repoSlug: input.repoSlug,
|
|
406
|
-
statusCode: response.status,
|
|
407
|
-
message: `Remote server rejected project root ${candidate} (${response.status}): ${payloadError(response.payload, response.text || "project-root validation failed")}`
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
const record = response.payload && typeof response.payload === "object" && !Array.isArray(response.payload) ? response.payload : {};
|
|
411
|
-
if (record.ok !== true) {
|
|
412
|
-
return remoteProjectLinkFailure({
|
|
413
|
-
status: "invalid_root",
|
|
414
|
-
alias: input.alias,
|
|
415
|
-
baseUrl: input.baseUrl,
|
|
416
|
-
repoSlug: input.repoSlug,
|
|
417
|
-
message: `Remote server did not accept project root ${candidate}: ${payloadError(response.payload, "project-root validation failed")}`
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
const accepted = typeof record.projectRoot === "string" && record.projectRoot.trim() ? record.projectRoot.trim() : typeof record.requestedProjectRoot === "string" && record.requestedProjectRoot.trim() ? record.requestedProjectRoot.trim() : candidate;
|
|
421
|
-
writeRepoServerProjectRoot(input.projectRoot, accepted, { alias: input.alias, baseUrl: input.baseUrl, project: input.repoSlug });
|
|
422
|
-
writeProjectLinkConnection(input.projectRoot, input.repoSlug, input.alias);
|
|
423
|
-
const status = input.status ?? (input.prepared ? "prepared" : "backfilled");
|
|
424
|
-
return remoteProjectLinkSuccess({
|
|
425
|
-
status,
|
|
426
|
-
alias: input.alias,
|
|
427
|
-
baseUrl: input.baseUrl,
|
|
428
|
-
repoSlug: input.repoSlug,
|
|
429
|
-
serverProjectRoot: accepted,
|
|
430
|
-
source: input.source,
|
|
431
|
-
prepared: input.prepared,
|
|
432
|
-
validated: true,
|
|
433
|
-
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}.`
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
async function ensureRemoteProjectRootLink(projectRoot, options = {}) {
|
|
437
|
-
let selected;
|
|
438
|
-
try {
|
|
439
|
-
selected = resolveSelectedConnection(projectRoot);
|
|
440
|
-
} catch (error) {
|
|
441
|
-
return remoteProjectLinkFailure({ status: "error", message: error instanceof Error ? error.message : String(error) });
|
|
442
|
-
}
|
|
443
|
-
if (!selected || selected.connection.kind !== "remote") {
|
|
444
|
-
return remoteProjectLinkFailure({ status: "not_remote", message: "No remote Rig server is selected for this repo." });
|
|
445
|
-
}
|
|
446
|
-
const repo = readRepoConnection(projectRoot);
|
|
447
|
-
const explicitRepoRequested = options.repoSlug !== undefined;
|
|
448
|
-
const explicitRepoSlug = explicitRepoRequested ? normalizeRepoSlug(options.repoSlug) : null;
|
|
449
|
-
const repoProjectSlug = normalizeRepoSlug(repo?.project);
|
|
450
|
-
const repoSlug = explicitRepoSlug ?? repoProjectSlug ?? readProjectLinkSlug(projectRoot);
|
|
451
|
-
const alias = selected.alias;
|
|
452
|
-
const baseUrl = selected.connection.baseUrl;
|
|
453
|
-
const authToken = options.authToken === undefined ? readGitHubBearerTokenForRemote(projectRoot) : options.authToken;
|
|
454
|
-
const mode = options.mode ?? "backfill-only";
|
|
455
|
-
if (explicitRepoRequested && !explicitRepoSlug) {
|
|
456
|
-
return remoteProjectLinkFailure({
|
|
457
|
-
status: "missing_project",
|
|
458
|
-
alias,
|
|
459
|
-
baseUrl,
|
|
460
|
-
message: `Invalid --repo value ${JSON.stringify(options.repoSlug)}. Expected owner/repo.`
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
if (!repoSlug) {
|
|
464
|
-
return remoteProjectLinkFailure({
|
|
465
|
-
status: "missing_project",
|
|
466
|
-
alias,
|
|
467
|
-
baseUrl,
|
|
468
|
-
message: `Remote server ${alias} is selected, but this checkout has no GitHub repo slug recorded.`
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
const skippedCandidates = [];
|
|
472
|
-
const storedRoot = selected.serverProjectRoot?.trim() || null;
|
|
473
|
-
const storedRootMatchesResolvedRepo = repoProjectSlug === repoSlug;
|
|
474
|
-
if (storedRoot && storedRootMatchesResolvedRepo) {
|
|
475
|
-
if (localCheckoutPathCandidate(projectRoot, storedRoot)) {
|
|
476
|
-
clearRepoServerProjectRoot(projectRoot);
|
|
477
|
-
skippedCandidates.push(storedRoot);
|
|
478
|
-
} else {
|
|
479
|
-
const storedResult = await validateAndPersistRemoteRoot({
|
|
480
|
-
projectRoot,
|
|
481
|
-
alias,
|
|
482
|
-
baseUrl,
|
|
483
|
-
authToken,
|
|
484
|
-
repoSlug,
|
|
485
|
-
candidate: storedRoot,
|
|
486
|
-
source: "stored",
|
|
487
|
-
status: "ready"
|
|
488
|
-
});
|
|
489
|
-
if (storedResult.ok || storedResult.status === "auth_required" || storedResult.status === "error")
|
|
490
|
-
return storedResult;
|
|
491
|
-
clearRepoServerProjectRoot(projectRoot);
|
|
492
|
-
skippedCandidates.push(storedRoot);
|
|
493
|
-
}
|
|
494
|
-
} else if (storedRoot) {
|
|
495
|
-
skippedCandidates.push(storedRoot);
|
|
496
|
-
}
|
|
497
|
-
const authCandidate = inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug);
|
|
498
|
-
if (authCandidate) {
|
|
499
|
-
const authResult = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: authCandidate, source: "auth-state" });
|
|
500
|
-
if (authResult.ok || authResult.status === "auth_required")
|
|
501
|
-
return authResult;
|
|
502
|
-
}
|
|
503
|
-
let registryResponse;
|
|
504
|
-
try {
|
|
505
|
-
registryResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}`, authToken);
|
|
506
|
-
} catch (error) {
|
|
507
|
-
return remoteProjectLinkFailure({
|
|
508
|
-
status: "error",
|
|
509
|
-
alias,
|
|
510
|
-
baseUrl,
|
|
511
|
-
repoSlug,
|
|
512
|
-
message: `Could not read remote project registry for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
if (registryResponse.status === 401 || registryResponse.status === 403) {
|
|
516
|
-
return remoteProjectLinkFailure({
|
|
517
|
-
status: "auth_required",
|
|
518
|
-
alias,
|
|
519
|
-
baseUrl,
|
|
520
|
-
repoSlug,
|
|
521
|
-
statusCode: registryResponse.status,
|
|
522
|
-
message: `Remote server ${alias} requires authentication before reading the ${repoSlug} project registry.`
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
if (registryResponse.ok) {
|
|
526
|
-
const candidates = checkoutPathsFromProjectPayload(registryResponse.payload);
|
|
527
|
-
for (const candidate of candidates) {
|
|
528
|
-
const result = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate, source: "registry" });
|
|
529
|
-
if (result.ok || result.status === "auth_required")
|
|
530
|
-
return result;
|
|
531
|
-
skippedCandidates.push(candidate);
|
|
532
|
-
}
|
|
533
|
-
if (mode === "backfill-only") {
|
|
534
|
-
return remoteProjectLinkFailure({
|
|
535
|
-
status: candidates.length > 0 ? "invalid_root" : "no_server_checkout",
|
|
536
|
-
alias,
|
|
537
|
-
baseUrl,
|
|
538
|
-
repoSlug,
|
|
539
|
-
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.`,
|
|
540
|
-
skippedCandidates
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
} else if (registryResponse.status === 404) {
|
|
544
|
-
if (mode === "backfill-only") {
|
|
545
|
-
return remoteProjectLinkFailure({
|
|
546
|
-
status: "project_not_registered",
|
|
547
|
-
alias,
|
|
548
|
-
baseUrl,
|
|
549
|
-
repoSlug,
|
|
550
|
-
statusCode: registryResponse.status,
|
|
551
|
-
message: `Remote server ${alias} has no registered project record for ${repoSlug}.`
|
|
552
|
-
});
|
|
553
|
-
}
|
|
554
|
-
} else {
|
|
555
|
-
return remoteProjectLinkFailure({
|
|
556
|
-
status: "error",
|
|
557
|
-
alias,
|
|
558
|
-
baseUrl,
|
|
559
|
-
repoSlug,
|
|
560
|
-
statusCode: registryResponse.status,
|
|
561
|
-
message: `Could not backfill ${repoSlug} from remote registry (${registryResponse.status}): ${payloadError(registryResponse.payload, registryResponse.text || "registry lookup failed")}`,
|
|
562
|
-
skippedCandidates
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
let prepareResponse;
|
|
566
|
-
try {
|
|
567
|
-
prepareResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}/prepare-checkout`, authToken, {
|
|
568
|
-
method: "POST",
|
|
569
|
-
headers: { "content-type": "application/json" },
|
|
570
|
-
body: JSON.stringify({ checkout: { kind: "managed-clone" }, repoUrl: `https://github.com/${repoSlug}.git` })
|
|
571
|
-
});
|
|
572
|
-
} catch (error) {
|
|
573
|
-
return remoteProjectLinkFailure({
|
|
574
|
-
status: "error",
|
|
575
|
-
alias,
|
|
576
|
-
baseUrl,
|
|
577
|
-
repoSlug,
|
|
578
|
-
message: `Could not prepare remote checkout for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
if (prepareResponse.status === 401 || prepareResponse.status === 403) {
|
|
582
|
-
return remoteProjectLinkFailure({
|
|
583
|
-
status: "auth_required",
|
|
584
|
-
alias,
|
|
585
|
-
baseUrl,
|
|
586
|
-
repoSlug,
|
|
587
|
-
statusCode: prepareResponse.status,
|
|
588
|
-
message: `Remote server ${alias} requires authentication before preparing ${repoSlug}.`
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
if (!prepareResponse.ok) {
|
|
592
|
-
return remoteProjectLinkFailure({
|
|
593
|
-
status: "error",
|
|
594
|
-
alias,
|
|
595
|
-
baseUrl,
|
|
596
|
-
repoSlug,
|
|
597
|
-
statusCode: prepareResponse.status,
|
|
598
|
-
message: `Remote checkout prepare failed for ${repoSlug} (${prepareResponse.status}): ${payloadError(prepareResponse.payload, prepareResponse.text || "prepare-checkout failed")}`,
|
|
599
|
-
skippedCandidates
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
const preparedPath = checkoutPathFromPreparePayload(prepareResponse.payload);
|
|
603
|
-
if (!preparedPath) {
|
|
604
|
-
return remoteProjectLinkFailure({
|
|
605
|
-
status: "invalid_root",
|
|
606
|
-
alias,
|
|
607
|
-
baseUrl,
|
|
608
|
-
repoSlug,
|
|
609
|
-
message: `Remote checkout prepare for ${repoSlug} did not return a checkout.path.`,
|
|
610
|
-
skippedCandidates
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
return validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: preparedPath, source: "prepare", prepared: true });
|
|
614
|
-
}
|
|
615
|
-
async function ensureServerForCli(projectRoot) {
|
|
616
|
-
try {
|
|
617
|
-
const selected = resolveSelectedConnection(projectRoot);
|
|
618
|
-
if (selected?.connection.kind === "remote") {
|
|
619
|
-
reportServerPhase(`Connecting to ${selected.alias}\u2026`);
|
|
620
|
-
const authToken = readGitHubBearerTokenForRemote(projectRoot);
|
|
621
|
-
const link = await ensureRemoteProjectRootLink(projectRoot, { mode: "backfill-only", authToken });
|
|
622
|
-
return {
|
|
623
|
-
baseUrl: selected.connection.baseUrl,
|
|
624
|
-
authToken,
|
|
625
|
-
connectionKind: "remote",
|
|
626
|
-
serverProjectRoot: link.ok ? link.serverProjectRoot ?? null : null
|
|
627
|
-
};
|
|
628
|
-
}
|
|
629
|
-
reportServerPhase("Starting local Rig server\u2026");
|
|
630
|
-
const connection = await ensureLocalRigServerConnection(projectRoot);
|
|
631
|
-
return {
|
|
632
|
-
baseUrl: connection.baseUrl,
|
|
633
|
-
authToken: connection.authToken ?? readLocalConnectionFallbackToken(projectRoot),
|
|
634
|
-
connectionKind: "local",
|
|
635
|
-
serverProjectRoot: resolve2(projectRoot)
|
|
636
|
-
};
|
|
637
|
-
} catch (error) {
|
|
638
|
-
if (error instanceof Error) {
|
|
639
|
-
throw new CliError(error.message, 1);
|
|
640
|
-
}
|
|
641
|
-
throw error;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
function mergeCookie(existing, name, value) {
|
|
645
|
-
const encoded = `${name}=${encodeURIComponent(value)}`;
|
|
646
|
-
if (!existing?.trim())
|
|
647
|
-
return encoded;
|
|
648
|
-
const parts = existing.split(";").map((part) => part.trim()).filter((part) => part && !part.startsWith(`${name}=`));
|
|
649
|
-
return [...parts, encoded].join("; ");
|
|
650
|
-
}
|
|
651
|
-
function queryAuthFallbackEnabled(env = process.env) {
|
|
652
|
-
return env.RIG_ENABLE_QUERY_AUTH_FALLBACK === "1" || env.RIG_QUERY_AUTH_FALLBACK === "1";
|
|
653
|
-
}
|
|
654
|
-
function mergeHeaders(headers, authToken) {
|
|
655
|
-
const merged = new Headers(headers);
|
|
656
|
-
if (authToken) {
|
|
657
|
-
const bearer = `Bearer ${authToken}`;
|
|
658
|
-
merged.set("authorization", bearer);
|
|
659
|
-
merged.set("x-auth", bearer);
|
|
660
|
-
merged.set("cookie", mergeCookie(merged.get("cookie"), "rig_auth", authToken));
|
|
661
|
-
}
|
|
662
|
-
return merged;
|
|
663
|
-
}
|
|
664
|
-
var serverReachabilityCache = new Map;
|
|
665
|
-
var RESUMABLE_RUN_STATUSES = new Set([
|
|
666
|
-
"created",
|
|
667
|
-
"preparing",
|
|
668
|
-
"running",
|
|
669
|
-
"validating",
|
|
670
|
-
"reviewing",
|
|
671
|
-
"stopped",
|
|
672
|
-
"failed",
|
|
673
|
-
"needs-attention",
|
|
674
|
-
"needs_attention"
|
|
675
|
-
]);
|
|
676
|
-
|
|
677
|
-
// packages/cli/src/commands/_server-events.ts
|
|
678
|
-
function buildRigWebSocketUrl(baseUrl, authToken) {
|
|
679
|
-
const url = new URL(baseUrl);
|
|
680
|
-
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
681
|
-
if (authToken)
|
|
682
|
-
url.searchParams.set("token", authToken);
|
|
683
|
-
return url.toString();
|
|
684
|
-
}
|
|
685
|
-
async function connectRigServerEvents(projectRoot, handlers) {
|
|
686
|
-
const { baseUrl, authToken } = await ensureServerForCli(projectRoot);
|
|
687
|
-
const transport = new WsTransport(buildRigWebSocketUrl(baseUrl, authToken));
|
|
688
|
-
const unsubscribers = [];
|
|
689
|
-
if (handlers.onSnapshotInvalidated)
|
|
690
|
-
unsubscribers.push(transport.subscribe(RIG_WS_CHANNELS.snapshotInvalidated, handlers.onSnapshotInvalidated));
|
|
691
|
-
if (handlers.onRunLogAppended)
|
|
692
|
-
unsubscribers.push(transport.subscribe(RIG_WS_CHANNELS.runLogAppended, handlers.onRunLogAppended));
|
|
693
|
-
if (handlers.onEngineEvent)
|
|
694
|
-
unsubscribers.push(transport.subscribe(RIG_WS_CHANNELS.event, handlers.onEngineEvent));
|
|
695
|
-
let status = "connecting";
|
|
696
|
-
unsubscribers.push(transport.subscribeState((state) => {
|
|
697
|
-
status = state.status;
|
|
698
|
-
handlers.onStatus?.(state.status);
|
|
699
|
-
}));
|
|
700
|
-
return {
|
|
701
|
-
connected: () => status === "connected",
|
|
702
|
-
close: () => {
|
|
703
|
-
for (const unsubscribe of unsubscribers) {
|
|
704
|
-
try {
|
|
705
|
-
unsubscribe();
|
|
706
|
-
} catch {}
|
|
707
|
-
}
|
|
708
|
-
transport.dispose();
|
|
709
|
-
}
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
export {
|
|
713
|
-
connectRigServerEvents,
|
|
714
|
-
buildRigWebSocketUrl
|
|
715
|
-
};
|