@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
package/dist/src/commands/run.js
CHANGED
|
@@ -86,8 +86,8 @@ function parsePositiveInt(value, option, fallback) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
// packages/cli/src/commands/_server-client.ts
|
|
89
|
-
import { existsSync as existsSync2,
|
|
90
|
-
import {
|
|
89
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
90
|
+
import { resolve as resolve2 } from "path";
|
|
91
91
|
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
92
92
|
|
|
93
93
|
// packages/cli/src/commands/_connection-state.ts
|
|
@@ -161,28 +161,12 @@ function readRepoConnection(projectRoot) {
|
|
|
161
161
|
selected,
|
|
162
162
|
project: typeof record.project === "string" ? record.project : undefined,
|
|
163
163
|
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
|
|
164
|
-
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
165
|
-
serverProjectRootAlias: typeof record.serverProjectRootAlias === "string" && record.serverProjectRootAlias.trim() ? record.serverProjectRootAlias.trim() : undefined,
|
|
166
|
-
serverProjectRootBaseUrl: typeof record.serverProjectRootBaseUrl === "string" && record.serverProjectRootBaseUrl.trim() ? record.serverProjectRootBaseUrl.trim().replace(/\/+$/, "") : undefined
|
|
164
|
+
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
167
165
|
};
|
|
168
166
|
}
|
|
169
167
|
function writeRepoConnection(projectRoot, state) {
|
|
170
168
|
writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
|
|
171
169
|
}
|
|
172
|
-
function rootAllowedForSelection(repo, connection) {
|
|
173
|
-
const root = repo.serverProjectRoot?.trim();
|
|
174
|
-
if (!root)
|
|
175
|
-
return;
|
|
176
|
-
if (connection.kind === "remote") {
|
|
177
|
-
if (repo.serverProjectRootAlias !== repo.selected)
|
|
178
|
-
return;
|
|
179
|
-
if (repo.serverProjectRootBaseUrl !== connection.baseUrl)
|
|
180
|
-
return;
|
|
181
|
-
} else if (repo.serverProjectRootAlias && repo.serverProjectRootAlias !== repo.selected) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
return root;
|
|
185
|
-
}
|
|
186
170
|
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
187
171
|
const repo = readRepoConnection(projectRoot);
|
|
188
172
|
if (!repo)
|
|
@@ -194,41 +178,13 @@ function resolveSelectedConnection(projectRoot, options = {}) {
|
|
|
194
178
|
if (!connection) {
|
|
195
179
|
throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
196
180
|
}
|
|
197
|
-
return { alias: repo.selected, connection, serverProjectRoot:
|
|
198
|
-
}
|
|
199
|
-
function writeRepoServerProjectRoot(projectRoot, serverProjectRoot, metadata = {}) {
|
|
200
|
-
const repo = readRepoConnection(projectRoot);
|
|
201
|
-
if (!repo)
|
|
202
|
-
return;
|
|
203
|
-
let inferred = metadata;
|
|
204
|
-
if (!inferred.alias || !inferred.baseUrl) {
|
|
205
|
-
try {
|
|
206
|
-
const selected = resolveSelectedConnection(projectRoot);
|
|
207
|
-
if (selected?.connection.kind === "remote") {
|
|
208
|
-
inferred = {
|
|
209
|
-
alias: inferred.alias ?? selected.alias,
|
|
210
|
-
baseUrl: inferred.baseUrl ?? selected.connection.baseUrl
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
} catch {}
|
|
214
|
-
}
|
|
215
|
-
writeRepoConnection(projectRoot, {
|
|
216
|
-
...repo,
|
|
217
|
-
...metadata.project ? { project: metadata.project } : {},
|
|
218
|
-
serverProjectRoot,
|
|
219
|
-
...inferred.alias ? { serverProjectRootAlias: inferred.alias } : {},
|
|
220
|
-
...inferred.baseUrl ? { serverProjectRootBaseUrl: inferred.baseUrl.replace(/\/+$/, "") } : {}
|
|
221
|
-
});
|
|
181
|
+
return { alias: repo.selected, connection, serverProjectRoot: repo.serverProjectRoot };
|
|
222
182
|
}
|
|
223
|
-
function
|
|
183
|
+
function writeRepoServerProjectRoot(projectRoot, serverProjectRoot) {
|
|
224
184
|
const repo = readRepoConnection(projectRoot);
|
|
225
185
|
if (!repo)
|
|
226
186
|
return;
|
|
227
|
-
writeRepoConnection(projectRoot, {
|
|
228
|
-
selected: repo.selected,
|
|
229
|
-
...repo.project ? { project: repo.project } : {},
|
|
230
|
-
...repo.linkedAt ? { linkedAt: repo.linkedAt } : {}
|
|
231
|
-
});
|
|
187
|
+
writeRepoConnection(projectRoot, { ...repo, serverProjectRoot });
|
|
232
188
|
}
|
|
233
189
|
function isRemoteConnectionSelected(projectRoot) {
|
|
234
190
|
return resolveSelectedConnection(projectRoot)?.connection.kind === "remote";
|
|
@@ -249,21 +205,17 @@ function cleanToken(value) {
|
|
|
249
205
|
const trimmed = value?.trim();
|
|
250
206
|
return trimmed ? trimmed : null;
|
|
251
207
|
}
|
|
252
|
-
function
|
|
208
|
+
function readPrivateRemoteSessionToken(projectRoot) {
|
|
253
209
|
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
254
210
|
if (!existsSync2(path))
|
|
255
211
|
return null;
|
|
256
212
|
try {
|
|
257
213
|
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
258
|
-
return
|
|
214
|
+
return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
|
|
259
215
|
} catch {
|
|
260
216
|
return null;
|
|
261
217
|
}
|
|
262
218
|
}
|
|
263
|
-
function readPrivateRemoteSessionToken(projectRoot) {
|
|
264
|
-
const parsed = readRemoteAuthState(projectRoot);
|
|
265
|
-
return parsed ? cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined) : null;
|
|
266
|
-
}
|
|
267
219
|
function readGitHubBearerTokenForRemote(projectRoot) {
|
|
268
220
|
const scopedKey = resolve2(projectRoot);
|
|
269
221
|
if (scopedGitHubBearerTokens.has(scopedKey))
|
|
@@ -274,415 +226,18 @@ function readGitHubBearerTokenForRemote(projectRoot) {
|
|
|
274
226
|
return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
275
227
|
}
|
|
276
228
|
function readStoredGitHubAuthToken(projectRoot) {
|
|
277
|
-
const
|
|
278
|
-
return parsed ? cleanToken(typeof parsed.token === "string" ? parsed.token : undefined) : null;
|
|
279
|
-
}
|
|
280
|
-
function inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug) {
|
|
281
|
-
if (!/^[^/]+\/[^/]+$/.test(repoSlug))
|
|
282
|
-
return null;
|
|
283
|
-
const repo = readRepoConnection(projectRoot);
|
|
284
|
-
const auth = readRemoteAuthState(projectRoot);
|
|
285
|
-
const authUpdatedAt = typeof auth?.updatedAt === "string" ? Date.parse(auth.updatedAt) : Number.NaN;
|
|
286
|
-
const repoLinkedAt = typeof repo?.linkedAt === "string" ? Date.parse(repo.linkedAt) : Number.NaN;
|
|
287
|
-
if (Number.isFinite(authUpdatedAt) && Number.isFinite(repoLinkedAt) && authUpdatedAt + 1000 < repoLinkedAt)
|
|
288
|
-
return null;
|
|
289
|
-
const checkoutBaseDir = typeof auth?.checkoutBaseDir === "string" && auth.checkoutBaseDir.trim() ? auth.checkoutBaseDir.trim() : null;
|
|
290
|
-
if (!checkoutBaseDir)
|
|
291
|
-
return null;
|
|
292
|
-
return `${checkoutBaseDir.replace(/\/+$/, "")}/${repoSlug}`;
|
|
293
|
-
}
|
|
294
|
-
function readLocalConnectionFallbackToken(projectRoot) {
|
|
295
|
-
return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
|
|
296
|
-
}
|
|
297
|
-
function normalizeRepoSlug(value) {
|
|
298
|
-
const slug = value?.trim();
|
|
299
|
-
return slug && /^[^/\s]+\/[^/\s]+$/.test(slug) ? slug : null;
|
|
300
|
-
}
|
|
301
|
-
function readProjectLinkSlug(projectRoot) {
|
|
302
|
-
const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
|
|
229
|
+
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
303
230
|
if (!existsSync2(path))
|
|
304
231
|
return null;
|
|
305
232
|
try {
|
|
306
233
|
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
307
|
-
|
|
308
|
-
return null;
|
|
309
|
-
return normalizeRepoSlug(typeof parsed.repoSlug === "string" ? String(parsed.repoSlug) : null);
|
|
234
|
+
return cleanToken(typeof parsed.token === "string" ? parsed.token : undefined);
|
|
310
235
|
} catch {
|
|
311
236
|
return null;
|
|
312
237
|
}
|
|
313
238
|
}
|
|
314
|
-
function
|
|
315
|
-
|
|
316
|
-
mkdirSync2(dirname2(path), { recursive: true });
|
|
317
|
-
writeFileSync2(path, `${JSON.stringify({ repoSlug, connection: alias, linkedAt: new Date().toISOString() }, null, 2)}
|
|
318
|
-
`, "utf8");
|
|
319
|
-
}
|
|
320
|
-
function remoteLinkRepairCommand(repoSlug) {
|
|
321
|
-
return repoSlug ? `rig server repair-link --repo ${repoSlug}` : "rig server repair-link --repo owner/repo";
|
|
322
|
-
}
|
|
323
|
-
function formatRemoteProjectLinkHint(resolution) {
|
|
324
|
-
const repair = remoteLinkRepairCommand(resolution.repoSlug);
|
|
325
|
-
if (resolution.status === "auth_required") {
|
|
326
|
-
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}` : ""}\`.`;
|
|
327
|
-
}
|
|
328
|
-
if (resolution.status === "missing_project") {
|
|
329
|
-
return `Record the repo slug, then run \`${repair}\` (or \`rig init --repo owner/repo --server remote --github-auth device\`).`;
|
|
330
|
-
}
|
|
331
|
-
if (resolution.status === "not_remote")
|
|
332
|
-
return "Select a remote server with `rig server use <alias>` before repairing a remote project link.";
|
|
333
|
-
return `Run \`${repair}\` to backfill or prepare a server-host checkout for the selected remote${resolution.alias ? ` (${resolution.alias})` : ""}.`;
|
|
334
|
-
}
|
|
335
|
-
function remoteProjectLinkFailure(input) {
|
|
336
|
-
const partial = {
|
|
337
|
-
status: input.status,
|
|
338
|
-
alias: input.alias,
|
|
339
|
-
baseUrl: input.baseUrl,
|
|
340
|
-
repoSlug: input.repoSlug
|
|
341
|
-
};
|
|
342
|
-
return {
|
|
343
|
-
ok: false,
|
|
344
|
-
...input,
|
|
345
|
-
hint: formatRemoteProjectLinkHint(partial),
|
|
346
|
-
next: remoteLinkRepairCommand(input.repoSlug)
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
function remoteProjectLinkSuccess(input) {
|
|
350
|
-
return {
|
|
351
|
-
ok: true,
|
|
352
|
-
status: input.status,
|
|
353
|
-
alias: input.alias,
|
|
354
|
-
baseUrl: input.baseUrl,
|
|
355
|
-
repoSlug: input.repoSlug,
|
|
356
|
-
serverProjectRoot: input.serverProjectRoot,
|
|
357
|
-
source: input.source,
|
|
358
|
-
prepared: input.prepared ?? input.status === "prepared",
|
|
359
|
-
validated: input.validated ?? false,
|
|
360
|
-
message: input.message ?? `Remote project link ready for ${input.repoSlug}.`,
|
|
361
|
-
hint: "Remote-scoped task/run/status requests will send x-rig-project-root for this server-host checkout.",
|
|
362
|
-
next: "rig task list"
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
function localCheckoutPathCandidate(projectRoot, candidate) {
|
|
366
|
-
try {
|
|
367
|
-
const local = resolve2(projectRoot);
|
|
368
|
-
const resolved = resolve2(candidate);
|
|
369
|
-
return resolved === local || resolved.startsWith(`${local}/`);
|
|
370
|
-
} catch {
|
|
371
|
-
return false;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
async function requestRemoteProjectLinkJson(baseUrl, pathname, authToken, init = {}) {
|
|
375
|
-
const requestUrl = new URL(`${baseUrl}${pathname}`);
|
|
376
|
-
if (authToken && queryAuthFallbackEnabled())
|
|
377
|
-
requestUrl.searchParams.set("rt", authToken);
|
|
378
|
-
const response = await fetch(requestUrl, {
|
|
379
|
-
...init,
|
|
380
|
-
headers: mergeHeaders(init.headers, authToken)
|
|
381
|
-
});
|
|
382
|
-
const text = await response.text();
|
|
383
|
-
const payload = text.trim().length > 0 ? (() => {
|
|
384
|
-
try {
|
|
385
|
-
return JSON.parse(text);
|
|
386
|
-
} catch {
|
|
387
|
-
return null;
|
|
388
|
-
}
|
|
389
|
-
})() : null;
|
|
390
|
-
return { ok: response.ok, status: response.status, payload, text };
|
|
391
|
-
}
|
|
392
|
-
function payloadError(payload, fallback) {
|
|
393
|
-
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
394
|
-
const record = payload;
|
|
395
|
-
const value = record.error ?? record.message ?? record.reason;
|
|
396
|
-
if (typeof value === "string" && value.trim())
|
|
397
|
-
return value.trim();
|
|
398
|
-
}
|
|
399
|
-
return fallback;
|
|
400
|
-
}
|
|
401
|
-
function checkoutPathsFromProjectPayload(payload) {
|
|
402
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
403
|
-
return [];
|
|
404
|
-
const project = payload.project;
|
|
405
|
-
if (!project || typeof project !== "object" || Array.isArray(project))
|
|
406
|
-
return [];
|
|
407
|
-
const checkouts = project.checkouts;
|
|
408
|
-
if (!Array.isArray(checkouts))
|
|
409
|
-
return [];
|
|
410
|
-
return [...checkouts].reverse().flatMap((entry) => {
|
|
411
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
412
|
-
return [];
|
|
413
|
-
const path = entry.path;
|
|
414
|
-
return typeof path === "string" && path.trim() ? [path.trim()] : [];
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
function checkoutPathFromPreparePayload(payload) {
|
|
418
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
419
|
-
return null;
|
|
420
|
-
const checkout = payload.checkout;
|
|
421
|
-
if (!checkout || typeof checkout !== "object" || Array.isArray(checkout))
|
|
422
|
-
return null;
|
|
423
|
-
const path = checkout.path;
|
|
424
|
-
return typeof path === "string" && path.trim() ? path.trim() : null;
|
|
425
|
-
}
|
|
426
|
-
async function validateAndPersistRemoteRoot(input) {
|
|
427
|
-
const candidate = input.candidate.trim();
|
|
428
|
-
if (!candidate || !isAbsolute(candidate)) {
|
|
429
|
-
return remoteProjectLinkFailure({
|
|
430
|
-
status: "invalid_root",
|
|
431
|
-
alias: input.alias,
|
|
432
|
-
baseUrl: input.baseUrl,
|
|
433
|
-
repoSlug: input.repoSlug,
|
|
434
|
-
message: `Remote project root candidate is not an absolute server-host path: ${candidate || "(empty)"}.`
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
if (localCheckoutPathCandidate(input.projectRoot, candidate)) {
|
|
438
|
-
return remoteProjectLinkFailure({
|
|
439
|
-
status: "invalid_root",
|
|
440
|
-
alias: input.alias,
|
|
441
|
-
baseUrl: input.baseUrl,
|
|
442
|
-
repoSlug: input.repoSlug,
|
|
443
|
-
message: `Refusing to use local checkout path ${candidate} as a remote server project root.`
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
let response;
|
|
447
|
-
try {
|
|
448
|
-
response = await requestRemoteProjectLinkJson(input.baseUrl, "/api/server/project-root", input.authToken, {
|
|
449
|
-
method: "POST",
|
|
450
|
-
headers: { "content-type": "application/json" },
|
|
451
|
-
body: JSON.stringify({ projectRoot: candidate })
|
|
452
|
-
});
|
|
453
|
-
} catch (error) {
|
|
454
|
-
return remoteProjectLinkFailure({
|
|
455
|
-
status: "error",
|
|
456
|
-
alias: input.alias,
|
|
457
|
-
baseUrl: input.baseUrl,
|
|
458
|
-
repoSlug: input.repoSlug,
|
|
459
|
-
message: `Could not validate remote project root ${candidate}: ${error instanceof Error ? error.message : String(error)}`
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
if (response.status === 401 || response.status === 403) {
|
|
463
|
-
return remoteProjectLinkFailure({
|
|
464
|
-
status: "auth_required",
|
|
465
|
-
alias: input.alias,
|
|
466
|
-
baseUrl: input.baseUrl,
|
|
467
|
-
repoSlug: input.repoSlug,
|
|
468
|
-
statusCode: response.status,
|
|
469
|
-
message: `Remote server ${input.alias} requires authentication before validating project root ${candidate}.`
|
|
470
|
-
});
|
|
471
|
-
}
|
|
472
|
-
if (!response.ok) {
|
|
473
|
-
return remoteProjectLinkFailure({
|
|
474
|
-
status: "invalid_root",
|
|
475
|
-
alias: input.alias,
|
|
476
|
-
baseUrl: input.baseUrl,
|
|
477
|
-
repoSlug: input.repoSlug,
|
|
478
|
-
statusCode: response.status,
|
|
479
|
-
message: `Remote server rejected project root ${candidate} (${response.status}): ${payloadError(response.payload, response.text || "project-root validation failed")}`
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
const record = response.payload && typeof response.payload === "object" && !Array.isArray(response.payload) ? response.payload : {};
|
|
483
|
-
if (record.ok !== true) {
|
|
484
|
-
return remoteProjectLinkFailure({
|
|
485
|
-
status: "invalid_root",
|
|
486
|
-
alias: input.alias,
|
|
487
|
-
baseUrl: input.baseUrl,
|
|
488
|
-
repoSlug: input.repoSlug,
|
|
489
|
-
message: `Remote server did not accept project root ${candidate}: ${payloadError(response.payload, "project-root validation failed")}`
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
const accepted = typeof record.projectRoot === "string" && record.projectRoot.trim() ? record.projectRoot.trim() : typeof record.requestedProjectRoot === "string" && record.requestedProjectRoot.trim() ? record.requestedProjectRoot.trim() : candidate;
|
|
493
|
-
writeRepoServerProjectRoot(input.projectRoot, accepted, { alias: input.alias, baseUrl: input.baseUrl, project: input.repoSlug });
|
|
494
|
-
writeProjectLinkConnection(input.projectRoot, input.repoSlug, input.alias);
|
|
495
|
-
const status = input.status ?? (input.prepared ? "prepared" : "backfilled");
|
|
496
|
-
return remoteProjectLinkSuccess({
|
|
497
|
-
status,
|
|
498
|
-
alias: input.alias,
|
|
499
|
-
baseUrl: input.baseUrl,
|
|
500
|
-
repoSlug: input.repoSlug,
|
|
501
|
-
serverProjectRoot: accepted,
|
|
502
|
-
source: input.source,
|
|
503
|
-
prepared: input.prepared,
|
|
504
|
-
validated: true,
|
|
505
|
-
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}.`
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
async function ensureRemoteProjectRootLink(projectRoot, options = {}) {
|
|
509
|
-
let selected;
|
|
510
|
-
try {
|
|
511
|
-
selected = resolveSelectedConnection(projectRoot);
|
|
512
|
-
} catch (error) {
|
|
513
|
-
return remoteProjectLinkFailure({ status: "error", message: error instanceof Error ? error.message : String(error) });
|
|
514
|
-
}
|
|
515
|
-
if (!selected || selected.connection.kind !== "remote") {
|
|
516
|
-
return remoteProjectLinkFailure({ status: "not_remote", message: "No remote Rig server is selected for this repo." });
|
|
517
|
-
}
|
|
518
|
-
const repo = readRepoConnection(projectRoot);
|
|
519
|
-
const explicitRepoRequested = options.repoSlug !== undefined;
|
|
520
|
-
const explicitRepoSlug = explicitRepoRequested ? normalizeRepoSlug(options.repoSlug) : null;
|
|
521
|
-
const repoProjectSlug = normalizeRepoSlug(repo?.project);
|
|
522
|
-
const repoSlug = explicitRepoSlug ?? repoProjectSlug ?? readProjectLinkSlug(projectRoot);
|
|
523
|
-
const alias = selected.alias;
|
|
524
|
-
const baseUrl = selected.connection.baseUrl;
|
|
525
|
-
const authToken = options.authToken === undefined ? readGitHubBearerTokenForRemote(projectRoot) : options.authToken;
|
|
526
|
-
const mode = options.mode ?? "backfill-only";
|
|
527
|
-
if (explicitRepoRequested && !explicitRepoSlug) {
|
|
528
|
-
return remoteProjectLinkFailure({
|
|
529
|
-
status: "missing_project",
|
|
530
|
-
alias,
|
|
531
|
-
baseUrl,
|
|
532
|
-
message: `Invalid --repo value ${JSON.stringify(options.repoSlug)}. Expected owner/repo.`
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
if (!repoSlug) {
|
|
536
|
-
return remoteProjectLinkFailure({
|
|
537
|
-
status: "missing_project",
|
|
538
|
-
alias,
|
|
539
|
-
baseUrl,
|
|
540
|
-
message: `Remote server ${alias} is selected, but this checkout has no GitHub repo slug recorded.`
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
const skippedCandidates = [];
|
|
544
|
-
const storedRoot = selected.serverProjectRoot?.trim() || null;
|
|
545
|
-
const storedRootMatchesResolvedRepo = repoProjectSlug === repoSlug;
|
|
546
|
-
if (storedRoot && storedRootMatchesResolvedRepo) {
|
|
547
|
-
if (localCheckoutPathCandidate(projectRoot, storedRoot)) {
|
|
548
|
-
clearRepoServerProjectRoot(projectRoot);
|
|
549
|
-
skippedCandidates.push(storedRoot);
|
|
550
|
-
} else {
|
|
551
|
-
const storedResult = await validateAndPersistRemoteRoot({
|
|
552
|
-
projectRoot,
|
|
553
|
-
alias,
|
|
554
|
-
baseUrl,
|
|
555
|
-
authToken,
|
|
556
|
-
repoSlug,
|
|
557
|
-
candidate: storedRoot,
|
|
558
|
-
source: "stored",
|
|
559
|
-
status: "ready"
|
|
560
|
-
});
|
|
561
|
-
if (storedResult.ok || storedResult.status === "auth_required" || storedResult.status === "error")
|
|
562
|
-
return storedResult;
|
|
563
|
-
clearRepoServerProjectRoot(projectRoot);
|
|
564
|
-
skippedCandidates.push(storedRoot);
|
|
565
|
-
}
|
|
566
|
-
} else if (storedRoot) {
|
|
567
|
-
skippedCandidates.push(storedRoot);
|
|
568
|
-
}
|
|
569
|
-
const authCandidate = inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug);
|
|
570
|
-
if (authCandidate) {
|
|
571
|
-
const authResult = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: authCandidate, source: "auth-state" });
|
|
572
|
-
if (authResult.ok || authResult.status === "auth_required")
|
|
573
|
-
return authResult;
|
|
574
|
-
}
|
|
575
|
-
let registryResponse;
|
|
576
|
-
try {
|
|
577
|
-
registryResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}`, authToken);
|
|
578
|
-
} catch (error) {
|
|
579
|
-
return remoteProjectLinkFailure({
|
|
580
|
-
status: "error",
|
|
581
|
-
alias,
|
|
582
|
-
baseUrl,
|
|
583
|
-
repoSlug,
|
|
584
|
-
message: `Could not read remote project registry for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
if (registryResponse.status === 401 || registryResponse.status === 403) {
|
|
588
|
-
return remoteProjectLinkFailure({
|
|
589
|
-
status: "auth_required",
|
|
590
|
-
alias,
|
|
591
|
-
baseUrl,
|
|
592
|
-
repoSlug,
|
|
593
|
-
statusCode: registryResponse.status,
|
|
594
|
-
message: `Remote server ${alias} requires authentication before reading the ${repoSlug} project registry.`
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
if (registryResponse.ok) {
|
|
598
|
-
const candidates = checkoutPathsFromProjectPayload(registryResponse.payload);
|
|
599
|
-
for (const candidate of candidates) {
|
|
600
|
-
const result = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate, source: "registry" });
|
|
601
|
-
if (result.ok || result.status === "auth_required")
|
|
602
|
-
return result;
|
|
603
|
-
skippedCandidates.push(candidate);
|
|
604
|
-
}
|
|
605
|
-
if (mode === "backfill-only") {
|
|
606
|
-
return remoteProjectLinkFailure({
|
|
607
|
-
status: candidates.length > 0 ? "invalid_root" : "no_server_checkout",
|
|
608
|
-
alias,
|
|
609
|
-
baseUrl,
|
|
610
|
-
repoSlug,
|
|
611
|
-
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.`,
|
|
612
|
-
skippedCandidates
|
|
613
|
-
});
|
|
614
|
-
}
|
|
615
|
-
} else if (registryResponse.status === 404) {
|
|
616
|
-
if (mode === "backfill-only") {
|
|
617
|
-
return remoteProjectLinkFailure({
|
|
618
|
-
status: "project_not_registered",
|
|
619
|
-
alias,
|
|
620
|
-
baseUrl,
|
|
621
|
-
repoSlug,
|
|
622
|
-
statusCode: registryResponse.status,
|
|
623
|
-
message: `Remote server ${alias} has no registered project record for ${repoSlug}.`
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
} else {
|
|
627
|
-
return remoteProjectLinkFailure({
|
|
628
|
-
status: "error",
|
|
629
|
-
alias,
|
|
630
|
-
baseUrl,
|
|
631
|
-
repoSlug,
|
|
632
|
-
statusCode: registryResponse.status,
|
|
633
|
-
message: `Could not backfill ${repoSlug} from remote registry (${registryResponse.status}): ${payloadError(registryResponse.payload, registryResponse.text || "registry lookup failed")}`,
|
|
634
|
-
skippedCandidates
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
let prepareResponse;
|
|
638
|
-
try {
|
|
639
|
-
prepareResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}/prepare-checkout`, authToken, {
|
|
640
|
-
method: "POST",
|
|
641
|
-
headers: { "content-type": "application/json" },
|
|
642
|
-
body: JSON.stringify({ checkout: { kind: "managed-clone" }, repoUrl: `https://github.com/${repoSlug}.git` })
|
|
643
|
-
});
|
|
644
|
-
} catch (error) {
|
|
645
|
-
return remoteProjectLinkFailure({
|
|
646
|
-
status: "error",
|
|
647
|
-
alias,
|
|
648
|
-
baseUrl,
|
|
649
|
-
repoSlug,
|
|
650
|
-
message: `Could not prepare remote checkout for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
if (prepareResponse.status === 401 || prepareResponse.status === 403) {
|
|
654
|
-
return remoteProjectLinkFailure({
|
|
655
|
-
status: "auth_required",
|
|
656
|
-
alias,
|
|
657
|
-
baseUrl,
|
|
658
|
-
repoSlug,
|
|
659
|
-
statusCode: prepareResponse.status,
|
|
660
|
-
message: `Remote server ${alias} requires authentication before preparing ${repoSlug}.`
|
|
661
|
-
});
|
|
662
|
-
}
|
|
663
|
-
if (!prepareResponse.ok) {
|
|
664
|
-
return remoteProjectLinkFailure({
|
|
665
|
-
status: "error",
|
|
666
|
-
alias,
|
|
667
|
-
baseUrl,
|
|
668
|
-
repoSlug,
|
|
669
|
-
statusCode: prepareResponse.status,
|
|
670
|
-
message: `Remote checkout prepare failed for ${repoSlug} (${prepareResponse.status}): ${payloadError(prepareResponse.payload, prepareResponse.text || "prepare-checkout failed")}`,
|
|
671
|
-
skippedCandidates
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
const preparedPath = checkoutPathFromPreparePayload(prepareResponse.payload);
|
|
675
|
-
if (!preparedPath) {
|
|
676
|
-
return remoteProjectLinkFailure({
|
|
677
|
-
status: "invalid_root",
|
|
678
|
-
alias,
|
|
679
|
-
baseUrl,
|
|
680
|
-
repoSlug,
|
|
681
|
-
message: `Remote checkout prepare for ${repoSlug} did not return a checkout.path.`,
|
|
682
|
-
skippedCandidates
|
|
683
|
-
});
|
|
684
|
-
}
|
|
685
|
-
return validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: preparedPath, source: "prepare", prepared: true });
|
|
239
|
+
function readLocalConnectionFallbackToken(projectRoot) {
|
|
240
|
+
return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
|
|
686
241
|
}
|
|
687
242
|
async function ensureServerForCli(projectRoot) {
|
|
688
243
|
try {
|
|
@@ -690,12 +245,12 @@ async function ensureServerForCli(projectRoot) {
|
|
|
690
245
|
if (selected?.connection.kind === "remote") {
|
|
691
246
|
reportServerPhase(`Connecting to ${selected.alias}\u2026`);
|
|
692
247
|
const authToken = readGitHubBearerTokenForRemote(projectRoot);
|
|
693
|
-
const
|
|
248
|
+
const serverProjectRoot = selected.serverProjectRoot ?? await backfillRemoteServerProjectRoot(projectRoot, selected.connection.baseUrl, authToken);
|
|
694
249
|
return {
|
|
695
250
|
baseUrl: selected.connection.baseUrl,
|
|
696
251
|
authToken,
|
|
697
252
|
connectionKind: "remote",
|
|
698
|
-
serverProjectRoot
|
|
253
|
+
serverProjectRoot
|
|
699
254
|
};
|
|
700
255
|
}
|
|
701
256
|
reportServerPhase("Starting local Rig server\u2026");
|
|
@@ -713,23 +268,33 @@ async function ensureServerForCli(projectRoot) {
|
|
|
713
268
|
throw error;
|
|
714
269
|
}
|
|
715
270
|
}
|
|
716
|
-
function
|
|
717
|
-
const
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
|
|
271
|
+
async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
|
|
272
|
+
const repo = readRepoConnection(projectRoot);
|
|
273
|
+
const slug = repo?.project?.trim();
|
|
274
|
+
if (!slug)
|
|
275
|
+
return null;
|
|
276
|
+
try {
|
|
277
|
+
const response = await fetch(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`, {
|
|
278
|
+
headers: mergeHeaders(undefined, authToken)
|
|
279
|
+
});
|
|
280
|
+
if (!response.ok)
|
|
281
|
+
return null;
|
|
282
|
+
const payload = await response.json();
|
|
283
|
+
const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
|
|
284
|
+
const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
|
|
285
|
+
const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
|
|
286
|
+
const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
|
|
287
|
+
if (path)
|
|
288
|
+
writeRepoServerProjectRoot(projectRoot, path);
|
|
289
|
+
return path;
|
|
290
|
+
} catch {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
725
293
|
}
|
|
726
294
|
function mergeHeaders(headers, authToken) {
|
|
727
295
|
const merged = new Headers(headers);
|
|
728
296
|
if (authToken) {
|
|
729
|
-
|
|
730
|
-
merged.set("authorization", bearer);
|
|
731
|
-
merged.set("x-auth", bearer);
|
|
732
|
-
merged.set("cookie", mergeCookie(merged.get("cookie"), "rig_auth", authToken));
|
|
297
|
+
merged.set("authorization", `Bearer ${authToken}`);
|
|
733
298
|
}
|
|
734
299
|
return merged;
|
|
735
300
|
}
|
|
@@ -790,41 +355,15 @@ async function buildServerFailureContext(projectRoot, server) {
|
|
|
790
355
|
hint: "Check the selected server with `rig server status`, or switch with `rig server use <alias|local>`."
|
|
791
356
|
};
|
|
792
357
|
}
|
|
793
|
-
function isLoopbackRemoteBaseUrl(baseUrl) {
|
|
794
|
-
try {
|
|
795
|
-
const host = new URL(baseUrl).hostname.toLowerCase();
|
|
796
|
-
return host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]";
|
|
797
|
-
} catch {
|
|
798
|
-
return false;
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
function canUseRemoteWithoutProjectRoot(pathname) {
|
|
802
|
-
return pathname === "/health" || pathname === "/api/health" || pathname === "/api/server/status" || pathname === "/api/server/project-root" || pathname.startsWith("/api/github/auth/") || pathname === "/api/projects" || pathname.startsWith("/api/projects/");
|
|
803
|
-
}
|
|
804
358
|
async function requestServerJson(context, pathname, init = {}) {
|
|
805
359
|
const server = await ensureServerForCli(context.projectRoot);
|
|
806
|
-
const requestUrl = new URL(`${server.baseUrl}${pathname}`);
|
|
807
|
-
let scopedServerProjectRoot = server.serverProjectRoot;
|
|
808
|
-
if (server.connectionKind === "remote" && !scopedServerProjectRoot && !canUseRemoteWithoutProjectRoot(requestUrl.pathname) && (server.authToken || !isLoopbackRemoteBaseUrl(server.baseUrl))) {
|
|
809
|
-
const link = await ensureRemoteProjectRootLink(context.projectRoot, { mode: "backfill-only", authToken: server.authToken });
|
|
810
|
-
if (link.ok && link.serverProjectRoot) {
|
|
811
|
-
scopedServerProjectRoot = link.serverProjectRoot;
|
|
812
|
-
} else {
|
|
813
|
-
const repo = readRepoConnection(context.projectRoot);
|
|
814
|
-
const target = link.alias && link.baseUrl ? `${link.alias} (${link.baseUrl})` : server.baseUrl;
|
|
815
|
-
throw new CliError(`Remote server ${target} is selected for ${link.repoSlug ?? repo?.project ?? "this repo"}, but this checkout has no server-host project root link. ${link.message}`, 1, { hint: link.hint });
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
360
|
const headers = mergeHeaders(init.headers, server.authToken);
|
|
819
|
-
if (
|
|
820
|
-
headers.set("x-rig-project-root",
|
|
821
|
-
if (server.connectionKind === "remote" && server.authToken && queryAuthFallbackEnabled()) {
|
|
822
|
-
requestUrl.searchParams.set("rt", server.authToken);
|
|
823
|
-
}
|
|
361
|
+
if (server.serverProjectRoot)
|
|
362
|
+
headers.set("x-rig-project-root", server.serverProjectRoot);
|
|
824
363
|
reportServerPhase(`${(init.method ?? "GET").toUpperCase()} ${pathname.split("?")[0]}\u2026`);
|
|
825
364
|
let response;
|
|
826
365
|
try {
|
|
827
|
-
response = await fetch(
|
|
366
|
+
response = await fetch(`${server.baseUrl}${pathname}`, {
|
|
828
367
|
...init,
|
|
829
368
|
headers
|
|
830
369
|
});
|
|
@@ -1270,7 +809,7 @@ function createOperatorSurface(options = {}) {
|
|
|
1270
809
|
}
|
|
1271
810
|
|
|
1272
811
|
// packages/cli/src/commands/_pi-frontend.ts
|
|
1273
|
-
import { existsSync as existsSync4, mkdirSync as
|
|
812
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync2, mkdtempSync, readFileSync as readFileSync3, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
1274
813
|
import { homedir as homedir2, tmpdir } from "os";
|
|
1275
814
|
import { join as join2 } from "path";
|
|
1276
815
|
import { main as runPiMain } from "@earendil-works/pi-coding-agent";
|
|
@@ -1310,7 +849,7 @@ function createTtySpinner(input) {
|
|
|
1310
849
|
output.write("\r\x1B[2K");
|
|
1311
850
|
};
|
|
1312
851
|
render();
|
|
1313
|
-
const timer = isTty ? setInterval(render, input.intervalMs ??
|
|
852
|
+
const timer = isTty ? setInterval(render, input.intervalMs ?? 120) : null;
|
|
1314
853
|
return {
|
|
1315
854
|
setLabel(next) {
|
|
1316
855
|
label = next;
|
|
@@ -1469,14 +1008,6 @@ async function withSpinner(label, work, options = {}) {
|
|
|
1469
1008
|
}
|
|
1470
1009
|
|
|
1471
1010
|
// packages/cli/src/commands/_pi-frontend.ts
|
|
1472
|
-
var TERMINAL_RUN_STATUSES = new Set(["completed", "failed", "stopped", "cancelled", "canceled", "closed", "merged", "needs_attention", "needs-attention"]);
|
|
1473
|
-
|
|
1474
|
-
class OperatorTranscriptUnavailableError extends Error {
|
|
1475
|
-
constructor(message) {
|
|
1476
|
-
super(message);
|
|
1477
|
-
this.name = "OperatorTranscriptUnavailableError";
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
1011
|
function setTemporaryEnv(updates) {
|
|
1481
1012
|
const previous = new Map;
|
|
1482
1013
|
for (const [key, value] of Object.entries(updates)) {
|
|
@@ -1504,27 +1035,10 @@ function buildOperatorPiEnv(input) {
|
|
|
1504
1035
|
...input.serverProjectRoot ? { RIG_PROJECT_ROOT: input.serverProjectRoot } : {}
|
|
1505
1036
|
};
|
|
1506
1037
|
}
|
|
1507
|
-
function shouldRequireOperatorTranscript(status) {
|
|
1508
|
-
return typeof status === "string" && TERMINAL_RUN_STATUSES.has(status.trim().toLowerCase());
|
|
1509
|
-
}
|
|
1510
|
-
function missingOperatorTranscriptMessage(runId, status) {
|
|
1511
|
-
const shortRun = runId.trim().slice(0, 8) || "unknown";
|
|
1512
|
-
const statusText = typeof status === "string" && status.trim() ? status.trim() : "terminal";
|
|
1513
|
-
return `Run ${shortRun} is ${statusText}, but no worker Pi session transcript is recorded for this run. It likely failed before Pi started or predates full-session capture. Use \`rig run show ${runId}\` and \`rig run logs ${runId}\` for the lifecycle details.`;
|
|
1514
|
-
}
|
|
1515
|
-
function statusFromRunDetails(run) {
|
|
1516
|
-
if (!run || typeof run !== "object" || Array.isArray(run))
|
|
1517
|
-
return;
|
|
1518
|
-
const record = run;
|
|
1519
|
-
if (typeof record.status === "string")
|
|
1520
|
-
return record.status;
|
|
1521
|
-
const nested = record.run;
|
|
1522
|
-
return nested && typeof nested === "object" && !Array.isArray(nested) ? nested.status : undefined;
|
|
1523
|
-
}
|
|
1524
1038
|
async function prepareOperatorConsole(context, runId, tempSessionDir) {
|
|
1525
1039
|
const server = await ensureServerForCli(context.projectRoot);
|
|
1526
1040
|
const localCwd = join2(homedir2(), ".rig", "drones", runId.slice(0, 8));
|
|
1527
|
-
|
|
1041
|
+
mkdirSync2(localCwd, { recursive: true });
|
|
1528
1042
|
trustDroneCwd(localCwd);
|
|
1529
1043
|
installRigPiTheme();
|
|
1530
1044
|
let sessionFileArg = [];
|
|
@@ -1546,17 +1060,10 @@ async function prepareOperatorConsole(context, runId, tempSessionDir) {
|
|
|
1546
1060
|
return line;
|
|
1547
1061
|
}).join(`
|
|
1548
1062
|
`);
|
|
1549
|
-
|
|
1063
|
+
writeFileSync2(localSessionPath, content);
|
|
1550
1064
|
sessionFileArg = ["--session", localSessionPath];
|
|
1551
1065
|
}
|
|
1552
1066
|
} catch {}
|
|
1553
|
-
if (sessionFileArg.length === 0) {
|
|
1554
|
-
const run = await getRunDetailsViaServer(context, runId).catch(() => null);
|
|
1555
|
-
const status = statusFromRunDetails(run);
|
|
1556
|
-
if (shouldRequireOperatorTranscript(status)) {
|
|
1557
|
-
throw new OperatorTranscriptUnavailableError(missingOperatorTranscriptMessage(runId, status));
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
1067
|
return { server, sessionFileArg };
|
|
1561
1068
|
}
|
|
1562
1069
|
var RIG_PI_THEME = {
|
|
@@ -1636,12 +1143,12 @@ var RIG_PI_THEME = {
|
|
|
1636
1143
|
function trustDroneCwd(localCwd) {
|
|
1637
1144
|
try {
|
|
1638
1145
|
const agentDir = join2(homedir2(), ".pi", "agent");
|
|
1639
|
-
|
|
1146
|
+
mkdirSync2(agentDir, { recursive: true });
|
|
1640
1147
|
const trustPath = join2(agentDir, "trust.json");
|
|
1641
1148
|
const store = existsSync4(trustPath) ? JSON.parse(readFileSync3(trustPath, "utf8")) : {};
|
|
1642
1149
|
if (store[localCwd] !== true) {
|
|
1643
1150
|
store[localCwd] = true;
|
|
1644
|
-
|
|
1151
|
+
writeFileSync2(trustPath, `${JSON.stringify(store, null, "\t")}
|
|
1645
1152
|
`);
|
|
1646
1153
|
}
|
|
1647
1154
|
} catch {}
|
|
@@ -1649,38 +1156,15 @@ function trustDroneCwd(localCwd) {
|
|
|
1649
1156
|
function installRigPiTheme() {
|
|
1650
1157
|
try {
|
|
1651
1158
|
const themesDir = join2(homedir2(), ".pi", "agent", "themes");
|
|
1652
|
-
|
|
1159
|
+
mkdirSync2(themesDir, { recursive: true });
|
|
1653
1160
|
const themePath = join2(themesDir, "rig.json");
|
|
1654
1161
|
const next = `${JSON.stringify(RIG_PI_THEME, null, "\t")}
|
|
1655
1162
|
`;
|
|
1656
1163
|
if (!existsSync4(themePath) || readFileSync3(themePath, "utf8") !== next) {
|
|
1657
|
-
|
|
1164
|
+
writeFileSync2(themePath, next);
|
|
1658
1165
|
}
|
|
1659
1166
|
} catch {}
|
|
1660
1167
|
}
|
|
1661
|
-
async function runWithProcessExitGuard(body) {
|
|
1662
|
-
const realExit = process.exit;
|
|
1663
|
-
let exitCode = 0;
|
|
1664
|
-
let signalQuit = () => {};
|
|
1665
|
-
const quit = new Promise((resolve4) => {
|
|
1666
|
-
signalQuit = resolve4;
|
|
1667
|
-
});
|
|
1668
|
-
const guardedExit = (code) => {
|
|
1669
|
-
exitCode = typeof code === "number" ? code : 0;
|
|
1670
|
-
signalQuit();
|
|
1671
|
-
return;
|
|
1672
|
-
};
|
|
1673
|
-
process.exit = guardedExit;
|
|
1674
|
-
try {
|
|
1675
|
-
await Promise.race([Promise.resolve().then(body), quit]);
|
|
1676
|
-
} finally {
|
|
1677
|
-
process.exit = realExit;
|
|
1678
|
-
}
|
|
1679
|
-
return exitCode;
|
|
1680
|
-
}
|
|
1681
|
-
function runPiMainReturningOnQuit(args, options) {
|
|
1682
|
-
return runWithProcessExitGuard(() => runPiMain(args, options));
|
|
1683
|
-
}
|
|
1684
1168
|
async function attachRunBundledPiFrontend(context, input) {
|
|
1685
1169
|
const tempSessionDir = mkdtempSync(join2(tmpdir(), "rig-pi-frontend-sessions-"));
|
|
1686
1170
|
const { server, sessionFileArg } = await withSpinner(`Opening Pi console for run ${input.runId}\u2026`, () => prepareOperatorConsole(context, input.runId, tempSessionDir), { outputMode: context.outputMode });
|
|
@@ -1696,20 +1180,15 @@ async function attachRunBundledPiFrontend(context, input) {
|
|
|
1696
1180
|
};
|
|
1697
1181
|
let detached = false;
|
|
1698
1182
|
try {
|
|
1699
|
-
|
|
1700
|
-
"--offline",
|
|
1183
|
+
await runPiMain([
|
|
1701
1184
|
"--no-extensions",
|
|
1702
1185
|
"--no-skills",
|
|
1703
1186
|
"--no-prompt-templates",
|
|
1704
1187
|
"--no-context-files",
|
|
1705
1188
|
...sessionFileArg
|
|
1706
|
-
]
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
await runPiMainReturningOnQuit(piArgs, piOptions);
|
|
1710
|
-
} else {
|
|
1711
|
-
await runPiMain(piArgs, piOptions);
|
|
1712
|
-
}
|
|
1189
|
+
], {
|
|
1190
|
+
extensionFactories: [piRigExtensionFactory]
|
|
1191
|
+
});
|
|
1713
1192
|
detached = true;
|
|
1714
1193
|
} finally {
|
|
1715
1194
|
restoreEnv();
|
|
@@ -1731,7 +1210,7 @@ async function attachRunBundledPiFrontend(context, input) {
|
|
|
1731
1210
|
}
|
|
1732
1211
|
|
|
1733
1212
|
// packages/cli/src/commands/_operator-view.ts
|
|
1734
|
-
var
|
|
1213
|
+
var TERMINAL_RUN_STATUSES = new Set(["completed", "failed", "stopped", "cancelled", "canceled", "closed", "merged", "needs_attention", "needs-attention"]);
|
|
1735
1214
|
function runStatusFromPayload(payload) {
|
|
1736
1215
|
const run = payload.run && typeof payload.run === "object" && !Array.isArray(payload.run) ? payload.run : payload;
|
|
1737
1216
|
return String(run.status ?? "unknown").toLowerCase();
|
|
@@ -1809,7 +1288,7 @@ async function attachRunOperatorView(context, input) {
|
|
|
1809
1288
|
}
|
|
1810
1289
|
const pollMs = Math.max(250, Math.trunc(input.pollMs ?? 2000));
|
|
1811
1290
|
let timelineCursor = snapshot.timelineCursor;
|
|
1812
|
-
while (!detached && !
|
|
1291
|
+
while (!detached && !TERMINAL_RUN_STATUSES.has(runStatusFromPayload(snapshot.run))) {
|
|
1813
1292
|
await Bun.sleep(pollMs);
|
|
1814
1293
|
snapshot = await readOperatorSnapshot(context, input.runId, { timelineCursor });
|
|
1815
1294
|
timelineCursor = snapshot.timelineCursor;
|
|
@@ -2512,9 +1991,6 @@ async function executeRun(context, args) {
|
|
|
2512
1991
|
console.log(`Stop requested: ${runId}`);
|
|
2513
1992
|
return { ok: true, group: "run", command, details: stopped };
|
|
2514
1993
|
}
|
|
2515
|
-
if (isRemoteConnectionSelected(context.projectRoot)) {
|
|
2516
|
-
throw new CliError("Remote run stop requires an explicit run id.", 2, { hint: "Run `rig run list`, then `rig run stop <run-id>`." });
|
|
2517
|
-
}
|
|
2518
1994
|
const result = await runStop(context.projectRoot);
|
|
2519
1995
|
if (result.remaining.length > 0) {
|
|
2520
1996
|
throw new CliError(`Failed to stop run(s): ${result.remaining.join(", ")}`, 1, { hint: "Check `rig run status`, then retry `rig run stop <run-id>` for the remaining runs." });
|