@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
|
@@ -232,75 +232,12 @@ function readRepoConnection(projectRoot) {
|
|
|
232
232
|
selected,
|
|
233
233
|
project: typeof record.project === "string" ? record.project : undefined,
|
|
234
234
|
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
|
|
235
|
-
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
236
|
-
serverProjectRootAlias: typeof record.serverProjectRootAlias === "string" && record.serverProjectRootAlias.trim() ? record.serverProjectRootAlias.trim() : undefined,
|
|
237
|
-
serverProjectRootBaseUrl: typeof record.serverProjectRootBaseUrl === "string" && record.serverProjectRootBaseUrl.trim() ? record.serverProjectRootBaseUrl.trim().replace(/\/+$/, "") : undefined
|
|
235
|
+
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
238
236
|
};
|
|
239
237
|
}
|
|
240
238
|
function writeRepoConnection(projectRoot, state) {
|
|
241
239
|
writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
|
|
242
240
|
}
|
|
243
|
-
function rootAllowedForSelection(repo, connection) {
|
|
244
|
-
const root = repo.serverProjectRoot?.trim();
|
|
245
|
-
if (!root)
|
|
246
|
-
return;
|
|
247
|
-
if (connection.kind === "remote") {
|
|
248
|
-
if (repo.serverProjectRootAlias !== repo.selected)
|
|
249
|
-
return;
|
|
250
|
-
if (repo.serverProjectRootBaseUrl !== connection.baseUrl)
|
|
251
|
-
return;
|
|
252
|
-
} else if (repo.serverProjectRootAlias && repo.serverProjectRootAlias !== repo.selected) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
return root;
|
|
256
|
-
}
|
|
257
|
-
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
258
|
-
const repo = readRepoConnection(projectRoot);
|
|
259
|
-
if (!repo)
|
|
260
|
-
return null;
|
|
261
|
-
if (repo.selected === "local")
|
|
262
|
-
return { alias: "local", connection: { kind: "local", mode: "auto" }, serverProjectRoot: repo.serverProjectRoot };
|
|
263
|
-
const global = readGlobalConnections(options);
|
|
264
|
-
const connection = global.connections[repo.selected];
|
|
265
|
-
if (!connection) {
|
|
266
|
-
throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
267
|
-
}
|
|
268
|
-
return { alias: repo.selected, connection, serverProjectRoot: rootAllowedForSelection(repo, connection) };
|
|
269
|
-
}
|
|
270
|
-
function writeRepoServerProjectRoot(projectRoot, serverProjectRoot, metadata = {}) {
|
|
271
|
-
const repo = readRepoConnection(projectRoot);
|
|
272
|
-
if (!repo)
|
|
273
|
-
return;
|
|
274
|
-
let inferred = metadata;
|
|
275
|
-
if (!inferred.alias || !inferred.baseUrl) {
|
|
276
|
-
try {
|
|
277
|
-
const selected = resolveSelectedConnection(projectRoot);
|
|
278
|
-
if (selected?.connection.kind === "remote") {
|
|
279
|
-
inferred = {
|
|
280
|
-
alias: inferred.alias ?? selected.alias,
|
|
281
|
-
baseUrl: inferred.baseUrl ?? selected.connection.baseUrl
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
} catch {}
|
|
285
|
-
}
|
|
286
|
-
writeRepoConnection(projectRoot, {
|
|
287
|
-
...repo,
|
|
288
|
-
...metadata.project ? { project: metadata.project } : {},
|
|
289
|
-
serverProjectRoot,
|
|
290
|
-
...inferred.alias ? { serverProjectRootAlias: inferred.alias } : {},
|
|
291
|
-
...inferred.baseUrl ? { serverProjectRootBaseUrl: inferred.baseUrl.replace(/\/+$/, "") } : {}
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
function clearRepoServerProjectRoot(projectRoot) {
|
|
295
|
-
const repo = readRepoConnection(projectRoot);
|
|
296
|
-
if (!repo)
|
|
297
|
-
return;
|
|
298
|
-
writeRepoConnection(projectRoot, {
|
|
299
|
-
selected: repo.selected,
|
|
300
|
-
...repo.project ? { project: repo.project } : {},
|
|
301
|
-
...repo.linkedAt ? { linkedAt: repo.linkedAt } : {}
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
241
|
|
|
305
242
|
// packages/cli/src/commands/_cli-format.ts
|
|
306
243
|
import pc from "picocolors";
|
|
@@ -356,499 +293,20 @@ function formatConnectionList(connections) {
|
|
|
356
293
|
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(`
|
|
357
294
|
`);
|
|
358
295
|
}
|
|
359
|
-
function formatConnectionStatus(selected, connections
|
|
296
|
+
function formatConnectionStatus(selected, connections) {
|
|
360
297
|
const connection = selected === "local" ? { kind: "local", mode: "auto" } : connections[selected];
|
|
361
298
|
const target = !connection ? "not configured" : connection.kind === "remote" ? connection.baseUrl : "local";
|
|
362
|
-
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";
|
|
363
299
|
return [
|
|
364
300
|
formatSection("Rig server", "selected for this repo"),
|
|
365
301
|
`${themeFaint("\u2502")} ${themeDim("selected ")} ${pc.bold(selected)}`,
|
|
366
302
|
`${themeFaint("\u2502")} ${themeDim("kind ")} ${formatStatusPill(connection?.kind ?? "unknown")}`,
|
|
367
303
|
`${themeFaint("\u2502")} ${themeDim("target ")} ${target ?? "not configured"}`,
|
|
368
|
-
...repo?.project ? [`${themeFaint("\u2502")} ${themeDim("project ")} ${repo.project}`] : [],
|
|
369
|
-
...connection?.kind === "remote" ? [`${themeFaint("\u2502")} ${themeDim("root ")} ${rootLabel}`] : [],
|
|
370
304
|
"",
|
|
371
|
-
...formatNextSteps(
|
|
305
|
+
...formatNextSteps(["Change: `rig server use <alias|local>`", "List saved servers: `rig server list`"])
|
|
372
306
|
].join(`
|
|
373
307
|
`);
|
|
374
308
|
}
|
|
375
309
|
|
|
376
|
-
// packages/cli/src/commands/_server-client.ts
|
|
377
|
-
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
378
|
-
import { dirname as dirname2, isAbsolute, resolve as resolve2 } from "path";
|
|
379
|
-
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
380
|
-
var scopedGitHubBearerTokens = new Map;
|
|
381
|
-
function cleanToken(value) {
|
|
382
|
-
const trimmed = value?.trim();
|
|
383
|
-
return trimmed ? trimmed : null;
|
|
384
|
-
}
|
|
385
|
-
function readRemoteAuthState(projectRoot) {
|
|
386
|
-
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
387
|
-
if (!existsSync2(path))
|
|
388
|
-
return null;
|
|
389
|
-
try {
|
|
390
|
-
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
391
|
-
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
392
|
-
} catch {
|
|
393
|
-
return null;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
function readPrivateRemoteSessionToken(projectRoot) {
|
|
397
|
-
const parsed = readRemoteAuthState(projectRoot);
|
|
398
|
-
return parsed ? cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined) : null;
|
|
399
|
-
}
|
|
400
|
-
function readGitHubBearerTokenForRemote(projectRoot) {
|
|
401
|
-
const scopedKey = resolve2(projectRoot);
|
|
402
|
-
if (scopedGitHubBearerTokens.has(scopedKey))
|
|
403
|
-
return scopedGitHubBearerTokens.get(scopedKey) ?? null;
|
|
404
|
-
const privateSession = readPrivateRemoteSessionToken(projectRoot);
|
|
405
|
-
if (privateSession)
|
|
406
|
-
return privateSession;
|
|
407
|
-
return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
408
|
-
}
|
|
409
|
-
function inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug) {
|
|
410
|
-
if (!/^[^/]+\/[^/]+$/.test(repoSlug))
|
|
411
|
-
return null;
|
|
412
|
-
const repo = readRepoConnection(projectRoot);
|
|
413
|
-
const auth = readRemoteAuthState(projectRoot);
|
|
414
|
-
const authUpdatedAt = typeof auth?.updatedAt === "string" ? Date.parse(auth.updatedAt) : Number.NaN;
|
|
415
|
-
const repoLinkedAt = typeof repo?.linkedAt === "string" ? Date.parse(repo.linkedAt) : Number.NaN;
|
|
416
|
-
if (Number.isFinite(authUpdatedAt) && Number.isFinite(repoLinkedAt) && authUpdatedAt + 1000 < repoLinkedAt)
|
|
417
|
-
return null;
|
|
418
|
-
const checkoutBaseDir = typeof auth?.checkoutBaseDir === "string" && auth.checkoutBaseDir.trim() ? auth.checkoutBaseDir.trim() : null;
|
|
419
|
-
if (!checkoutBaseDir)
|
|
420
|
-
return null;
|
|
421
|
-
return `${checkoutBaseDir.replace(/\/+$/, "")}/${repoSlug}`;
|
|
422
|
-
}
|
|
423
|
-
function normalizeRepoSlug(value) {
|
|
424
|
-
const slug = value?.trim();
|
|
425
|
-
return slug && /^[^/\s]+\/[^/\s]+$/.test(slug) ? slug : null;
|
|
426
|
-
}
|
|
427
|
-
function readProjectLinkSlug(projectRoot) {
|
|
428
|
-
const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
|
|
429
|
-
if (!existsSync2(path))
|
|
430
|
-
return null;
|
|
431
|
-
try {
|
|
432
|
-
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
433
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
434
|
-
return null;
|
|
435
|
-
return normalizeRepoSlug(typeof parsed.repoSlug === "string" ? String(parsed.repoSlug) : null);
|
|
436
|
-
} catch {
|
|
437
|
-
return null;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
function writeProjectLinkConnection(projectRoot, repoSlug, alias) {
|
|
441
|
-
const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
|
|
442
|
-
mkdirSync2(dirname2(path), { recursive: true });
|
|
443
|
-
writeFileSync2(path, `${JSON.stringify({ repoSlug, connection: alias, linkedAt: new Date().toISOString() }, null, 2)}
|
|
444
|
-
`, "utf8");
|
|
445
|
-
}
|
|
446
|
-
function remoteLinkRepairCommand(repoSlug) {
|
|
447
|
-
return repoSlug ? `rig server repair-link --repo ${repoSlug}` : "rig server repair-link --repo owner/repo";
|
|
448
|
-
}
|
|
449
|
-
function formatRemoteProjectLinkHint(resolution) {
|
|
450
|
-
const repair = remoteLinkRepairCommand(resolution.repoSlug);
|
|
451
|
-
if (resolution.status === "auth_required") {
|
|
452
|
-
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}` : ""}\`.`;
|
|
453
|
-
}
|
|
454
|
-
if (resolution.status === "missing_project") {
|
|
455
|
-
return `Record the repo slug, then run \`${repair}\` (or \`rig init --repo owner/repo --server remote --github-auth device\`).`;
|
|
456
|
-
}
|
|
457
|
-
if (resolution.status === "not_remote")
|
|
458
|
-
return "Select a remote server with `rig server use <alias>` before repairing a remote project link.";
|
|
459
|
-
return `Run \`${repair}\` to backfill or prepare a server-host checkout for the selected remote${resolution.alias ? ` (${resolution.alias})` : ""}.`;
|
|
460
|
-
}
|
|
461
|
-
function remoteProjectLinkFailure(input) {
|
|
462
|
-
const partial = {
|
|
463
|
-
status: input.status,
|
|
464
|
-
alias: input.alias,
|
|
465
|
-
baseUrl: input.baseUrl,
|
|
466
|
-
repoSlug: input.repoSlug
|
|
467
|
-
};
|
|
468
|
-
return {
|
|
469
|
-
ok: false,
|
|
470
|
-
...input,
|
|
471
|
-
hint: formatRemoteProjectLinkHint(partial),
|
|
472
|
-
next: remoteLinkRepairCommand(input.repoSlug)
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
function remoteProjectLinkSuccess(input) {
|
|
476
|
-
return {
|
|
477
|
-
ok: true,
|
|
478
|
-
status: input.status,
|
|
479
|
-
alias: input.alias,
|
|
480
|
-
baseUrl: input.baseUrl,
|
|
481
|
-
repoSlug: input.repoSlug,
|
|
482
|
-
serverProjectRoot: input.serverProjectRoot,
|
|
483
|
-
source: input.source,
|
|
484
|
-
prepared: input.prepared ?? input.status === "prepared",
|
|
485
|
-
validated: input.validated ?? false,
|
|
486
|
-
message: input.message ?? `Remote project link ready for ${input.repoSlug}.`,
|
|
487
|
-
hint: "Remote-scoped task/run/status requests will send x-rig-project-root for this server-host checkout.",
|
|
488
|
-
next: "rig task list"
|
|
489
|
-
};
|
|
490
|
-
}
|
|
491
|
-
function localCheckoutPathCandidate(projectRoot, candidate) {
|
|
492
|
-
try {
|
|
493
|
-
const local = resolve2(projectRoot);
|
|
494
|
-
const resolved = resolve2(candidate);
|
|
495
|
-
return resolved === local || resolved.startsWith(`${local}/`);
|
|
496
|
-
} catch {
|
|
497
|
-
return false;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
async function requestRemoteProjectLinkJson(baseUrl, pathname, authToken, init = {}) {
|
|
501
|
-
const requestUrl = new URL(`${baseUrl}${pathname}`);
|
|
502
|
-
if (authToken && queryAuthFallbackEnabled())
|
|
503
|
-
requestUrl.searchParams.set("rt", authToken);
|
|
504
|
-
const response = await fetch(requestUrl, {
|
|
505
|
-
...init,
|
|
506
|
-
headers: mergeHeaders(init.headers, authToken)
|
|
507
|
-
});
|
|
508
|
-
const text = await response.text();
|
|
509
|
-
const payload = text.trim().length > 0 ? (() => {
|
|
510
|
-
try {
|
|
511
|
-
return JSON.parse(text);
|
|
512
|
-
} catch {
|
|
513
|
-
return null;
|
|
514
|
-
}
|
|
515
|
-
})() : null;
|
|
516
|
-
return { ok: response.ok, status: response.status, payload, text };
|
|
517
|
-
}
|
|
518
|
-
function payloadError(payload, fallback) {
|
|
519
|
-
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
520
|
-
const record = payload;
|
|
521
|
-
const value = record.error ?? record.message ?? record.reason;
|
|
522
|
-
if (typeof value === "string" && value.trim())
|
|
523
|
-
return value.trim();
|
|
524
|
-
}
|
|
525
|
-
return fallback;
|
|
526
|
-
}
|
|
527
|
-
function checkoutPathsFromProjectPayload(payload) {
|
|
528
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
529
|
-
return [];
|
|
530
|
-
const project = payload.project;
|
|
531
|
-
if (!project || typeof project !== "object" || Array.isArray(project))
|
|
532
|
-
return [];
|
|
533
|
-
const checkouts = project.checkouts;
|
|
534
|
-
if (!Array.isArray(checkouts))
|
|
535
|
-
return [];
|
|
536
|
-
return [...checkouts].reverse().flatMap((entry) => {
|
|
537
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
538
|
-
return [];
|
|
539
|
-
const path = entry.path;
|
|
540
|
-
return typeof path === "string" && path.trim() ? [path.trim()] : [];
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
function checkoutPathFromPreparePayload(payload) {
|
|
544
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
545
|
-
return null;
|
|
546
|
-
const checkout = payload.checkout;
|
|
547
|
-
if (!checkout || typeof checkout !== "object" || Array.isArray(checkout))
|
|
548
|
-
return null;
|
|
549
|
-
const path = checkout.path;
|
|
550
|
-
return typeof path === "string" && path.trim() ? path.trim() : null;
|
|
551
|
-
}
|
|
552
|
-
async function validateAndPersistRemoteRoot(input) {
|
|
553
|
-
const candidate = input.candidate.trim();
|
|
554
|
-
if (!candidate || !isAbsolute(candidate)) {
|
|
555
|
-
return remoteProjectLinkFailure({
|
|
556
|
-
status: "invalid_root",
|
|
557
|
-
alias: input.alias,
|
|
558
|
-
baseUrl: input.baseUrl,
|
|
559
|
-
repoSlug: input.repoSlug,
|
|
560
|
-
message: `Remote project root candidate is not an absolute server-host path: ${candidate || "(empty)"}.`
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
if (localCheckoutPathCandidate(input.projectRoot, candidate)) {
|
|
564
|
-
return remoteProjectLinkFailure({
|
|
565
|
-
status: "invalid_root",
|
|
566
|
-
alias: input.alias,
|
|
567
|
-
baseUrl: input.baseUrl,
|
|
568
|
-
repoSlug: input.repoSlug,
|
|
569
|
-
message: `Refusing to use local checkout path ${candidate} as a remote server project root.`
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
let response;
|
|
573
|
-
try {
|
|
574
|
-
response = await requestRemoteProjectLinkJson(input.baseUrl, "/api/server/project-root", input.authToken, {
|
|
575
|
-
method: "POST",
|
|
576
|
-
headers: { "content-type": "application/json" },
|
|
577
|
-
body: JSON.stringify({ projectRoot: candidate })
|
|
578
|
-
});
|
|
579
|
-
} catch (error) {
|
|
580
|
-
return remoteProjectLinkFailure({
|
|
581
|
-
status: "error",
|
|
582
|
-
alias: input.alias,
|
|
583
|
-
baseUrl: input.baseUrl,
|
|
584
|
-
repoSlug: input.repoSlug,
|
|
585
|
-
message: `Could not validate remote project root ${candidate}: ${error instanceof Error ? error.message : String(error)}`
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
if (response.status === 401 || response.status === 403) {
|
|
589
|
-
return remoteProjectLinkFailure({
|
|
590
|
-
status: "auth_required",
|
|
591
|
-
alias: input.alias,
|
|
592
|
-
baseUrl: input.baseUrl,
|
|
593
|
-
repoSlug: input.repoSlug,
|
|
594
|
-
statusCode: response.status,
|
|
595
|
-
message: `Remote server ${input.alias} requires authentication before validating project root ${candidate}.`
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
if (!response.ok) {
|
|
599
|
-
return remoteProjectLinkFailure({
|
|
600
|
-
status: "invalid_root",
|
|
601
|
-
alias: input.alias,
|
|
602
|
-
baseUrl: input.baseUrl,
|
|
603
|
-
repoSlug: input.repoSlug,
|
|
604
|
-
statusCode: response.status,
|
|
605
|
-
message: `Remote server rejected project root ${candidate} (${response.status}): ${payloadError(response.payload, response.text || "project-root validation failed")}`
|
|
606
|
-
});
|
|
607
|
-
}
|
|
608
|
-
const record = response.payload && typeof response.payload === "object" && !Array.isArray(response.payload) ? response.payload : {};
|
|
609
|
-
if (record.ok !== true) {
|
|
610
|
-
return remoteProjectLinkFailure({
|
|
611
|
-
status: "invalid_root",
|
|
612
|
-
alias: input.alias,
|
|
613
|
-
baseUrl: input.baseUrl,
|
|
614
|
-
repoSlug: input.repoSlug,
|
|
615
|
-
message: `Remote server did not accept project root ${candidate}: ${payloadError(response.payload, "project-root validation failed")}`
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
const accepted = typeof record.projectRoot === "string" && record.projectRoot.trim() ? record.projectRoot.trim() : typeof record.requestedProjectRoot === "string" && record.requestedProjectRoot.trim() ? record.requestedProjectRoot.trim() : candidate;
|
|
619
|
-
writeRepoServerProjectRoot(input.projectRoot, accepted, { alias: input.alias, baseUrl: input.baseUrl, project: input.repoSlug });
|
|
620
|
-
writeProjectLinkConnection(input.projectRoot, input.repoSlug, input.alias);
|
|
621
|
-
const status = input.status ?? (input.prepared ? "prepared" : "backfilled");
|
|
622
|
-
return remoteProjectLinkSuccess({
|
|
623
|
-
status,
|
|
624
|
-
alias: input.alias,
|
|
625
|
-
baseUrl: input.baseUrl,
|
|
626
|
-
repoSlug: input.repoSlug,
|
|
627
|
-
serverProjectRoot: accepted,
|
|
628
|
-
source: input.source,
|
|
629
|
-
prepared: input.prepared,
|
|
630
|
-
validated: true,
|
|
631
|
-
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}.`
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
async function ensureRemoteProjectRootLink(projectRoot, options = {}) {
|
|
635
|
-
let selected;
|
|
636
|
-
try {
|
|
637
|
-
selected = resolveSelectedConnection(projectRoot);
|
|
638
|
-
} catch (error) {
|
|
639
|
-
return remoteProjectLinkFailure({ status: "error", message: error instanceof Error ? error.message : String(error) });
|
|
640
|
-
}
|
|
641
|
-
if (!selected || selected.connection.kind !== "remote") {
|
|
642
|
-
return remoteProjectLinkFailure({ status: "not_remote", message: "No remote Rig server is selected for this repo." });
|
|
643
|
-
}
|
|
644
|
-
const repo = readRepoConnection(projectRoot);
|
|
645
|
-
const explicitRepoRequested = options.repoSlug !== undefined;
|
|
646
|
-
const explicitRepoSlug = explicitRepoRequested ? normalizeRepoSlug(options.repoSlug) : null;
|
|
647
|
-
const repoProjectSlug = normalizeRepoSlug(repo?.project);
|
|
648
|
-
const repoSlug = explicitRepoSlug ?? repoProjectSlug ?? readProjectLinkSlug(projectRoot);
|
|
649
|
-
const alias = selected.alias;
|
|
650
|
-
const baseUrl = selected.connection.baseUrl;
|
|
651
|
-
const authToken = options.authToken === undefined ? readGitHubBearerTokenForRemote(projectRoot) : options.authToken;
|
|
652
|
-
const mode = options.mode ?? "backfill-only";
|
|
653
|
-
if (explicitRepoRequested && !explicitRepoSlug) {
|
|
654
|
-
return remoteProjectLinkFailure({
|
|
655
|
-
status: "missing_project",
|
|
656
|
-
alias,
|
|
657
|
-
baseUrl,
|
|
658
|
-
message: `Invalid --repo value ${JSON.stringify(options.repoSlug)}. Expected owner/repo.`
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
|
-
if (!repoSlug) {
|
|
662
|
-
return remoteProjectLinkFailure({
|
|
663
|
-
status: "missing_project",
|
|
664
|
-
alias,
|
|
665
|
-
baseUrl,
|
|
666
|
-
message: `Remote server ${alias} is selected, but this checkout has no GitHub repo slug recorded.`
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
const skippedCandidates = [];
|
|
670
|
-
const storedRoot = selected.serverProjectRoot?.trim() || null;
|
|
671
|
-
const storedRootMatchesResolvedRepo = repoProjectSlug === repoSlug;
|
|
672
|
-
if (storedRoot && storedRootMatchesResolvedRepo) {
|
|
673
|
-
if (localCheckoutPathCandidate(projectRoot, storedRoot)) {
|
|
674
|
-
clearRepoServerProjectRoot(projectRoot);
|
|
675
|
-
skippedCandidates.push(storedRoot);
|
|
676
|
-
} else {
|
|
677
|
-
const storedResult = await validateAndPersistRemoteRoot({
|
|
678
|
-
projectRoot,
|
|
679
|
-
alias,
|
|
680
|
-
baseUrl,
|
|
681
|
-
authToken,
|
|
682
|
-
repoSlug,
|
|
683
|
-
candidate: storedRoot,
|
|
684
|
-
source: "stored",
|
|
685
|
-
status: "ready"
|
|
686
|
-
});
|
|
687
|
-
if (storedResult.ok || storedResult.status === "auth_required" || storedResult.status === "error")
|
|
688
|
-
return storedResult;
|
|
689
|
-
clearRepoServerProjectRoot(projectRoot);
|
|
690
|
-
skippedCandidates.push(storedRoot);
|
|
691
|
-
}
|
|
692
|
-
} else if (storedRoot) {
|
|
693
|
-
skippedCandidates.push(storedRoot);
|
|
694
|
-
}
|
|
695
|
-
const authCandidate = inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug);
|
|
696
|
-
if (authCandidate) {
|
|
697
|
-
const authResult = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: authCandidate, source: "auth-state" });
|
|
698
|
-
if (authResult.ok || authResult.status === "auth_required")
|
|
699
|
-
return authResult;
|
|
700
|
-
}
|
|
701
|
-
let registryResponse;
|
|
702
|
-
try {
|
|
703
|
-
registryResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}`, authToken);
|
|
704
|
-
} catch (error) {
|
|
705
|
-
return remoteProjectLinkFailure({
|
|
706
|
-
status: "error",
|
|
707
|
-
alias,
|
|
708
|
-
baseUrl,
|
|
709
|
-
repoSlug,
|
|
710
|
-
message: `Could not read remote project registry for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
if (registryResponse.status === 401 || registryResponse.status === 403) {
|
|
714
|
-
return remoteProjectLinkFailure({
|
|
715
|
-
status: "auth_required",
|
|
716
|
-
alias,
|
|
717
|
-
baseUrl,
|
|
718
|
-
repoSlug,
|
|
719
|
-
statusCode: registryResponse.status,
|
|
720
|
-
message: `Remote server ${alias} requires authentication before reading the ${repoSlug} project registry.`
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
if (registryResponse.ok) {
|
|
724
|
-
const candidates = checkoutPathsFromProjectPayload(registryResponse.payload);
|
|
725
|
-
for (const candidate of candidates) {
|
|
726
|
-
const result = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate, source: "registry" });
|
|
727
|
-
if (result.ok || result.status === "auth_required")
|
|
728
|
-
return result;
|
|
729
|
-
skippedCandidates.push(candidate);
|
|
730
|
-
}
|
|
731
|
-
if (mode === "backfill-only") {
|
|
732
|
-
return remoteProjectLinkFailure({
|
|
733
|
-
status: candidates.length > 0 ? "invalid_root" : "no_server_checkout",
|
|
734
|
-
alias,
|
|
735
|
-
baseUrl,
|
|
736
|
-
repoSlug,
|
|
737
|
-
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.`,
|
|
738
|
-
skippedCandidates
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
} else if (registryResponse.status === 404) {
|
|
742
|
-
if (mode === "backfill-only") {
|
|
743
|
-
return remoteProjectLinkFailure({
|
|
744
|
-
status: "project_not_registered",
|
|
745
|
-
alias,
|
|
746
|
-
baseUrl,
|
|
747
|
-
repoSlug,
|
|
748
|
-
statusCode: registryResponse.status,
|
|
749
|
-
message: `Remote server ${alias} has no registered project record for ${repoSlug}.`
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
} else {
|
|
753
|
-
return remoteProjectLinkFailure({
|
|
754
|
-
status: "error",
|
|
755
|
-
alias,
|
|
756
|
-
baseUrl,
|
|
757
|
-
repoSlug,
|
|
758
|
-
statusCode: registryResponse.status,
|
|
759
|
-
message: `Could not backfill ${repoSlug} from remote registry (${registryResponse.status}): ${payloadError(registryResponse.payload, registryResponse.text || "registry lookup failed")}`,
|
|
760
|
-
skippedCandidates
|
|
761
|
-
});
|
|
762
|
-
}
|
|
763
|
-
let prepareResponse;
|
|
764
|
-
try {
|
|
765
|
-
prepareResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}/prepare-checkout`, authToken, {
|
|
766
|
-
method: "POST",
|
|
767
|
-
headers: { "content-type": "application/json" },
|
|
768
|
-
body: JSON.stringify({ checkout: { kind: "managed-clone" }, repoUrl: `https://github.com/${repoSlug}.git` })
|
|
769
|
-
});
|
|
770
|
-
} catch (error) {
|
|
771
|
-
return remoteProjectLinkFailure({
|
|
772
|
-
status: "error",
|
|
773
|
-
alias,
|
|
774
|
-
baseUrl,
|
|
775
|
-
repoSlug,
|
|
776
|
-
message: `Could not prepare remote checkout for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
|
|
777
|
-
});
|
|
778
|
-
}
|
|
779
|
-
if (prepareResponse.status === 401 || prepareResponse.status === 403) {
|
|
780
|
-
return remoteProjectLinkFailure({
|
|
781
|
-
status: "auth_required",
|
|
782
|
-
alias,
|
|
783
|
-
baseUrl,
|
|
784
|
-
repoSlug,
|
|
785
|
-
statusCode: prepareResponse.status,
|
|
786
|
-
message: `Remote server ${alias} requires authentication before preparing ${repoSlug}.`
|
|
787
|
-
});
|
|
788
|
-
}
|
|
789
|
-
if (!prepareResponse.ok) {
|
|
790
|
-
return remoteProjectLinkFailure({
|
|
791
|
-
status: "error",
|
|
792
|
-
alias,
|
|
793
|
-
baseUrl,
|
|
794
|
-
repoSlug,
|
|
795
|
-
statusCode: prepareResponse.status,
|
|
796
|
-
message: `Remote checkout prepare failed for ${repoSlug} (${prepareResponse.status}): ${payloadError(prepareResponse.payload, prepareResponse.text || "prepare-checkout failed")}`,
|
|
797
|
-
skippedCandidates
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
const preparedPath = checkoutPathFromPreparePayload(prepareResponse.payload);
|
|
801
|
-
if (!preparedPath) {
|
|
802
|
-
return remoteProjectLinkFailure({
|
|
803
|
-
status: "invalid_root",
|
|
804
|
-
alias,
|
|
805
|
-
baseUrl,
|
|
806
|
-
repoSlug,
|
|
807
|
-
message: `Remote checkout prepare for ${repoSlug} did not return a checkout.path.`,
|
|
808
|
-
skippedCandidates
|
|
809
|
-
});
|
|
810
|
-
}
|
|
811
|
-
return validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: preparedPath, source: "prepare", prepared: true });
|
|
812
|
-
}
|
|
813
|
-
async function repairRemoteProjectRootLink(context, options = {}) {
|
|
814
|
-
const resolution = await ensureRemoteProjectRootLink(context.projectRoot, { mode: options.mode ?? "prepare-if-missing", repoSlug: options.repoSlug });
|
|
815
|
-
if (!resolution.ok)
|
|
816
|
-
throw new CliError(resolution.message, 1, { hint: resolution.hint });
|
|
817
|
-
return resolution;
|
|
818
|
-
}
|
|
819
|
-
function mergeCookie(existing, name, value) {
|
|
820
|
-
const encoded = `${name}=${encodeURIComponent(value)}`;
|
|
821
|
-
if (!existing?.trim())
|
|
822
|
-
return encoded;
|
|
823
|
-
const parts = existing.split(";").map((part) => part.trim()).filter((part) => part && !part.startsWith(`${name}=`));
|
|
824
|
-
return [...parts, encoded].join("; ");
|
|
825
|
-
}
|
|
826
|
-
function queryAuthFallbackEnabled(env = process.env) {
|
|
827
|
-
return env.RIG_ENABLE_QUERY_AUTH_FALLBACK === "1" || env.RIG_QUERY_AUTH_FALLBACK === "1";
|
|
828
|
-
}
|
|
829
|
-
function mergeHeaders(headers, authToken) {
|
|
830
|
-
const merged = new Headers(headers);
|
|
831
|
-
if (authToken) {
|
|
832
|
-
const bearer = `Bearer ${authToken}`;
|
|
833
|
-
merged.set("authorization", bearer);
|
|
834
|
-
merged.set("x-auth", bearer);
|
|
835
|
-
merged.set("cookie", mergeCookie(merged.get("cookie"), "rig_auth", authToken));
|
|
836
|
-
}
|
|
837
|
-
return merged;
|
|
838
|
-
}
|
|
839
|
-
var serverReachabilityCache = new Map;
|
|
840
|
-
var RESUMABLE_RUN_STATUSES = new Set([
|
|
841
|
-
"created",
|
|
842
|
-
"preparing",
|
|
843
|
-
"running",
|
|
844
|
-
"validating",
|
|
845
|
-
"reviewing",
|
|
846
|
-
"stopped",
|
|
847
|
-
"failed",
|
|
848
|
-
"needs-attention",
|
|
849
|
-
"needs_attention"
|
|
850
|
-
]);
|
|
851
|
-
|
|
852
310
|
// packages/cli/src/commands/connect.ts
|
|
853
311
|
function usageName(options) {
|
|
854
312
|
return `rig ${options.group}`;
|
|
@@ -869,46 +327,13 @@ function parseConnection(alias, value, options) {
|
|
|
869
327
|
}
|
|
870
328
|
return { kind: "remote", baseUrl: parsed.toString().replace(/\/+$/, "") };
|
|
871
329
|
}
|
|
872
|
-
function printJsonOrText(context,
|
|
873
|
-
if (context.outputMode
|
|
330
|
+
function printJsonOrText(context, payload, text) {
|
|
331
|
+
if (context.outputMode === "json") {
|
|
332
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
333
|
+
} else {
|
|
874
334
|
console.log(text);
|
|
875
335
|
}
|
|
876
336
|
}
|
|
877
|
-
function formatRemoteProjectLinkText(result) {
|
|
878
|
-
return formatSuccessCard(result.ok ? "Remote project link ready" : "Remote project link needs repair", [
|
|
879
|
-
["selected", result.alias ?? "remote"],
|
|
880
|
-
["target", result.baseUrl ?? "unknown"],
|
|
881
|
-
["repo", result.repoSlug ?? "owner/repo"],
|
|
882
|
-
["status", result.status],
|
|
883
|
-
...result.serverProjectRoot ? [["server root", result.serverProjectRoot]] : [],
|
|
884
|
-
["next", result.ok ? result.next ?? "rig task list" : result.hint]
|
|
885
|
-
]);
|
|
886
|
-
}
|
|
887
|
-
function parseRepairLinkArgs(rest, usage) {
|
|
888
|
-
let repoSlug;
|
|
889
|
-
let mode = "prepare-if-missing";
|
|
890
|
-
const pending = [...rest];
|
|
891
|
-
while (pending.length > 0) {
|
|
892
|
-
const token = pending.shift();
|
|
893
|
-
if (token === "--repo") {
|
|
894
|
-
const value = pending.shift()?.trim();
|
|
895
|
-
if (!value)
|
|
896
|
-
throw new CliError(`Missing --repo value. Usage: ${usage}`, 1);
|
|
897
|
-
const normalized = normalizeRepoSlug(value);
|
|
898
|
-
if (!normalized)
|
|
899
|
-
throw new CliError(`Invalid --repo value: ${value}`, 1, { hint: "Use the canonical owner/repo slug, e.g. `--repo humanity-org/humanwork`." });
|
|
900
|
-
repoSlug = normalized;
|
|
901
|
-
} else if (token === "--backfill-only") {
|
|
902
|
-
mode = "backfill-only";
|
|
903
|
-
} else if (token === "--prepare") {
|
|
904
|
-
mode = "prepare-if-missing";
|
|
905
|
-
} else {
|
|
906
|
-
throw new CliError(`Unexpected argument: ${String(token)}
|
|
907
|
-
Usage: ${usage}`, 1);
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
return { repoSlug, mode };
|
|
911
|
-
}
|
|
912
337
|
async function promptForConnectionAlias(context) {
|
|
913
338
|
const state = readGlobalConnections();
|
|
914
339
|
const repo = readRepoConnection(context.projectRoot);
|
|
@@ -962,67 +387,31 @@ async function executeConnectionCommand(context, args, options) {
|
|
|
962
387
|
}
|
|
963
388
|
if (!alias)
|
|
964
389
|
throw new CliError(`Missing alias. Usage: ${usageName(options)} use <alias|local>`, 1);
|
|
965
|
-
let selectedConnection = { kind: "local", mode: "auto" };
|
|
966
390
|
if (alias !== "local") {
|
|
967
391
|
const state = readGlobalConnections();
|
|
968
|
-
|
|
969
|
-
if (!connection)
|
|
392
|
+
if (!state.connections[alias])
|
|
970
393
|
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>`." });
|
|
971
|
-
selectedConnection = connection;
|
|
972
394
|
}
|
|
973
|
-
const
|
|
974
|
-
const preserveRemoteRoot = Boolean(previousRepo?.serverProjectRoot && previousRepo.selected === alias && selectedConnection.kind === "remote" && previousRepo.serverProjectRootAlias === alias && previousRepo.serverProjectRootBaseUrl === selectedConnection.baseUrl);
|
|
975
|
-
const repoState = {
|
|
976
|
-
selected: alias,
|
|
977
|
-
...previousRepo?.project ? { project: previousRepo.project } : {},
|
|
978
|
-
linkedAt: new Date().toISOString(),
|
|
979
|
-
...preserveRemoteRoot ? {
|
|
980
|
-
serverProjectRoot: previousRepo.serverProjectRoot,
|
|
981
|
-
serverProjectRootAlias: previousRepo.serverProjectRootAlias,
|
|
982
|
-
serverProjectRootBaseUrl: previousRepo.serverProjectRootBaseUrl
|
|
983
|
-
} : {}
|
|
984
|
-
};
|
|
395
|
+
const repoState = { selected: alias, linkedAt: new Date().toISOString() };
|
|
985
396
|
writeRepoConnection(context.projectRoot, repoState);
|
|
986
|
-
|
|
987
|
-
ok: false,
|
|
988
|
-
status: "error",
|
|
989
|
-
message: error instanceof Error ? error.message : String(error),
|
|
990
|
-
hint: "Run `rig server repair-link` after authenticating the selected remote."
|
|
991
|
-
})) : null;
|
|
992
|
-
const latestRepo = readRepoConnection(context.projectRoot);
|
|
993
|
-
const details = { selected: latestRepo?.selected ?? alias, repo: latestRepo, remoteProjectLink };
|
|
994
|
-
printJsonOrText(context, details, formatSuccessCard("Rig server selected", [
|
|
397
|
+
printJsonOrText(context, repoState, formatSuccessCard("Rig server selected", [
|
|
995
398
|
["selected", alias],
|
|
996
399
|
["scope", "this repo"],
|
|
997
|
-
|
|
998
|
-
["next", remoteProjectLink && !remoteProjectLink.ok ? "rig server repair-link" : "rig task list"]
|
|
400
|
+
["next", "rig task list"]
|
|
999
401
|
]));
|
|
1000
|
-
return { ok: true, group: options.group, command: "use", details };
|
|
1001
|
-
}
|
|
1002
|
-
case "repair-link": {
|
|
1003
|
-
const parsed = parseRepairLinkArgs(rest, `${usageName(options)} repair-link [--prepare|--backfill-only] [--repo owner/repo]`);
|
|
1004
|
-
const result = await repairRemoteProjectRootLink(context, parsed);
|
|
1005
|
-
printJsonOrText(context, result, formatRemoteProjectLinkText(result));
|
|
1006
|
-
return { ok: true, group: options.group, command: "repair-link", details: result };
|
|
402
|
+
return { ok: true, group: options.group, command: "use", details: repoState };
|
|
1007
403
|
}
|
|
1008
404
|
case "status": {
|
|
1009
405
|
requireNoExtraArgs(rest, `${usageName(options)} status`);
|
|
1010
406
|
const repo = readRepoConnection(context.projectRoot);
|
|
1011
407
|
const global = readGlobalConnections();
|
|
1012
|
-
const
|
|
1013
|
-
|
|
1014
|
-
status: "error",
|
|
1015
|
-
message: error instanceof Error ? error.message : String(error),
|
|
1016
|
-
hint: "Run `rig server repair-link` after authenticating the selected remote."
|
|
1017
|
-
})) : null;
|
|
1018
|
-
const latestRepo = readRepoConnection(context.projectRoot) ?? repo;
|
|
1019
|
-
const details = { selected: latestRepo?.selected ?? "local", repo: latestRepo, connections: global.connections, remoteProjectLink };
|
|
1020
|
-
printJsonOrText(context, details, formatConnectionStatus(details.selected, global.connections, latestRepo ?? null, remoteProjectLink));
|
|
408
|
+
const details = { selected: repo?.selected ?? "local", repo, connections: global.connections };
|
|
409
|
+
printJsonOrText(context, details, formatConnectionStatus(details.selected, global.connections));
|
|
1021
410
|
return { ok: true, group: options.group, command: "status", details };
|
|
1022
411
|
}
|
|
1023
412
|
default:
|
|
1024
413
|
throw new CliError(`Unknown ${options.group} command: ${String(command)}
|
|
1025
|
-
Usage: ${usageName(options)} <list|add|use|status
|
|
414
|
+
Usage: ${usageName(options)} <list|add|use|status>`, 1);
|
|
1026
415
|
}
|
|
1027
416
|
}
|
|
1028
417
|
export {
|