@h-rig/cli 0.0.6-alpha.87 → 0.0.6-alpha.89
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/rig.js +1380 -865
- package/dist/src/app/board.js +462 -48
- package/dist/src/app-opentui/adapters/common.d.ts +3 -0
- package/dist/src/app-opentui/adapters/common.js +4 -0
- package/dist/src/app-opentui/adapters/doctor.js +458 -46
- package/dist/src/app-opentui/adapters/family.js +701 -151
- package/dist/src/app-opentui/adapters/fleet.js +477 -46
- package/dist/src/app-opentui/adapters/inbox.js +477 -46
- package/dist/src/app-opentui/adapters/init.js +497 -74
- package/dist/src/app-opentui/adapters/inspect.js +477 -46
- package/dist/src/app-opentui/adapters/pi-attach.d.ts +7 -0
- package/dist/src/app-opentui/adapters/pi-attach.js +1004 -519
- package/dist/src/app-opentui/adapters/run-detail.js +477 -46
- package/dist/src/app-opentui/adapters/server.d.ts +26 -0
- package/dist/src/app-opentui/adapters/server.js +676 -59
- package/dist/src/app-opentui/adapters/tasks.js +621 -549
- package/dist/src/app-opentui/autocomplete.js +4 -2
- package/dist/src/app-opentui/bootstrap.js +1376 -861
- package/dist/src/app-opentui/command-palette.js +37 -10
- package/dist/src/app-opentui/index.js +632 -528
- package/dist/src/app-opentui/intent.js +33 -8
- package/dist/src/app-opentui/keymap.js +43 -414
- package/dist/src/app-opentui/pi-host-child.js +496 -57
- package/dist/src/app-opentui/pi-pty-host.d.ts +14 -64
- package/dist/src/app-opentui/pi-pty-host.js +3 -397
- package/dist/src/app-opentui/react/App.js +144 -469
- package/dist/src/app-opentui/react/ChromeHost.js +44 -415
- package/dist/src/app-opentui/react/launch.js +659 -552
- package/dist/src/app-opentui/react/nav.js +1 -1
- package/dist/src/app-opentui/registry.js +1181 -742
- package/dist/src/app-opentui/remote-link.d.ts +10 -0
- package/dist/src/app-opentui/remote-link.js +47 -0
- package/dist/src/app-opentui/render/terminal-handoff.d.ts +16 -0
- package/dist/src/app-opentui/render/terminal-handoff.js +14 -0
- package/dist/src/app-opentui/runtime.js +632 -528
- package/dist/src/app-opentui/scenes/doctor.js +1 -1
- package/dist/src/app-opentui/scenes/error.js +50 -4
- package/dist/src/app-opentui/scenes/family.js +60 -6
- package/dist/src/app-opentui/scenes/fleet.js +65 -13
- package/dist/src/app-opentui/scenes/help.js +4 -2
- package/dist/src/app-opentui/scenes/init.js +12 -12
- package/dist/src/app-opentui/scenes/main.js +7 -7
- package/dist/src/app-opentui/scenes/server.js +83 -11
- package/dist/src/app-opentui/scenes/tasks.js +79 -16
- package/dist/src/app-opentui/state.js +25 -5
- package/dist/src/app-opentui/surface-catalog.js +4 -2
- package/dist/src/app-opentui/types.d.ts +1 -1
- package/dist/src/commands/_cli-format.d.ts +10 -1
- package/dist/src/commands/_cli-format.js +5 -2
- package/dist/src/commands/_connection-state.d.ts +11 -1
- package/dist/src/commands/_connection-state.js +50 -5
- package/dist/src/commands/_doctor-checks.js +458 -46
- package/dist/src/commands/_help-catalog.js +4 -2
- package/dist/src/commands/_json-output.js +4 -0
- package/dist/src/commands/_operator-view.js +496 -57
- package/dist/src/commands/_pi-frontend.d.ts +25 -0
- package/dist/src/commands/_pi-frontend.js +497 -57
- package/dist/src/commands/_preflight.js +509 -72
- package/dist/src/commands/_server-client.d.ts +33 -0
- package/dist/src/commands/_server-client.js +477 -46
- package/dist/src/commands/_server-events.js +446 -41
- package/dist/src/commands/_snapshot-upload.js +460 -48
- package/dist/src/commands/connect.js +620 -15
- package/dist/src/commands/doctor.js +458 -46
- package/dist/src/commands/github.js +462 -50
- package/dist/src/commands/inbox.js +458 -46
- package/dist/src/commands/init.js +497 -74
- package/dist/src/commands/inspect.js +458 -46
- package/dist/src/commands/run.js +496 -57
- package/dist/src/commands/server.js +647 -163
- package/dist/src/commands/setup.js +463 -51
- package/dist/src/commands/stats.js +462 -48
- package/dist/src/commands/task-run-driver.js +464 -52
- package/dist/src/commands/task.js +551 -85
- package/dist/src/commands.js +701 -151
- package/dist/src/index.js +705 -151
- package/dist/src/launcher.js +4 -0
- package/package.json +8 -8
|
@@ -149,12 +149,28 @@ function readRepoConnection(projectRoot) {
|
|
|
149
149
|
selected,
|
|
150
150
|
project: typeof record.project === "string" ? record.project : undefined,
|
|
151
151
|
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
|
|
152
|
-
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
152
|
+
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined,
|
|
153
|
+
serverProjectRootAlias: typeof record.serverProjectRootAlias === "string" && record.serverProjectRootAlias.trim() ? record.serverProjectRootAlias.trim() : undefined,
|
|
154
|
+
serverProjectRootBaseUrl: typeof record.serverProjectRootBaseUrl === "string" && record.serverProjectRootBaseUrl.trim() ? record.serverProjectRootBaseUrl.trim().replace(/\/+$/, "") : undefined
|
|
153
155
|
};
|
|
154
156
|
}
|
|
155
157
|
function writeRepoConnection(projectRoot, state) {
|
|
156
158
|
writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
|
|
157
159
|
}
|
|
160
|
+
function rootAllowedForSelection(repo, connection) {
|
|
161
|
+
const root = repo.serverProjectRoot?.trim();
|
|
162
|
+
if (!root)
|
|
163
|
+
return;
|
|
164
|
+
if (connection.kind === "remote") {
|
|
165
|
+
if (repo.serverProjectRootAlias !== repo.selected)
|
|
166
|
+
return;
|
|
167
|
+
if (repo.serverProjectRootBaseUrl !== connection.baseUrl)
|
|
168
|
+
return;
|
|
169
|
+
} else if (repo.serverProjectRootAlias && repo.serverProjectRootAlias !== repo.selected) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
return root;
|
|
173
|
+
}
|
|
158
174
|
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
159
175
|
const repo = readRepoConnection(projectRoot);
|
|
160
176
|
if (!repo)
|
|
@@ -166,21 +182,49 @@ function resolveSelectedConnection(projectRoot, options = {}) {
|
|
|
166
182
|
if (!connection) {
|
|
167
183
|
throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
168
184
|
}
|
|
169
|
-
return { alias: repo.selected, connection, serverProjectRoot: repo
|
|
185
|
+
return { alias: repo.selected, connection, serverProjectRoot: rootAllowedForSelection(repo, connection) };
|
|
186
|
+
}
|
|
187
|
+
function writeRepoServerProjectRoot(projectRoot, serverProjectRoot, metadata = {}) {
|
|
188
|
+
const repo = readRepoConnection(projectRoot);
|
|
189
|
+
if (!repo)
|
|
190
|
+
return;
|
|
191
|
+
let inferred = metadata;
|
|
192
|
+
if (!inferred.alias || !inferred.baseUrl) {
|
|
193
|
+
try {
|
|
194
|
+
const selected = resolveSelectedConnection(projectRoot);
|
|
195
|
+
if (selected?.connection.kind === "remote") {
|
|
196
|
+
inferred = {
|
|
197
|
+
alias: inferred.alias ?? selected.alias,
|
|
198
|
+
baseUrl: inferred.baseUrl ?? selected.connection.baseUrl
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
} catch {}
|
|
202
|
+
}
|
|
203
|
+
writeRepoConnection(projectRoot, {
|
|
204
|
+
...repo,
|
|
205
|
+
...metadata.project ? { project: metadata.project } : {},
|
|
206
|
+
serverProjectRoot,
|
|
207
|
+
...inferred.alias ? { serverProjectRootAlias: inferred.alias } : {},
|
|
208
|
+
...inferred.baseUrl ? { serverProjectRootBaseUrl: inferred.baseUrl.replace(/\/+$/, "") } : {}
|
|
209
|
+
});
|
|
170
210
|
}
|
|
171
|
-
function
|
|
211
|
+
function clearRepoServerProjectRoot(projectRoot) {
|
|
172
212
|
const repo = readRepoConnection(projectRoot);
|
|
173
213
|
if (!repo)
|
|
174
214
|
return;
|
|
175
|
-
writeRepoConnection(projectRoot, {
|
|
215
|
+
writeRepoConnection(projectRoot, {
|
|
216
|
+
selected: repo.selected,
|
|
217
|
+
...repo.project ? { project: repo.project } : {},
|
|
218
|
+
...repo.linkedAt ? { linkedAt: repo.linkedAt } : {}
|
|
219
|
+
});
|
|
176
220
|
}
|
|
177
221
|
var init__connection_state = __esm(() => {
|
|
178
222
|
init_runner();
|
|
179
223
|
});
|
|
180
224
|
|
|
181
225
|
// packages/cli/src/commands/_server-client.ts
|
|
182
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
183
|
-
import { resolve as resolve2 } from "path";
|
|
226
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
227
|
+
import { dirname as dirname2, isAbsolute, resolve as resolve2 } from "path";
|
|
184
228
|
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
185
229
|
function reportServerPhase(label) {
|
|
186
230
|
serverPhaseListener?.(label);
|
|
@@ -221,11 +265,10 @@ function readStoredGitHubAuthToken(projectRoot) {
|
|
|
221
265
|
const parsed = readRemoteAuthState(projectRoot);
|
|
222
266
|
return parsed ? cleanToken(typeof parsed.token === "string" ? parsed.token : undefined) : null;
|
|
223
267
|
}
|
|
224
|
-
function
|
|
225
|
-
|
|
226
|
-
const slug = repo?.project?.trim();
|
|
227
|
-
if (!slug || !/^[^/]+\/[^/]+$/.test(slug))
|
|
268
|
+
function inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug) {
|
|
269
|
+
if (!/^[^/]+\/[^/]+$/.test(repoSlug))
|
|
228
270
|
return null;
|
|
271
|
+
const repo = readRepoConnection(projectRoot);
|
|
229
272
|
const auth = readRemoteAuthState(projectRoot);
|
|
230
273
|
const authUpdatedAt = typeof auth?.updatedAt === "string" ? Date.parse(auth.updatedAt) : Number.NaN;
|
|
231
274
|
const repoLinkedAt = typeof repo?.linkedAt === "string" ? Date.parse(repo.linkedAt) : Number.NaN;
|
|
@@ -234,25 +277,413 @@ function inferRemoteServerProjectRootFromAuthState(projectRoot) {
|
|
|
234
277
|
const checkoutBaseDir = typeof auth?.checkoutBaseDir === "string" && auth.checkoutBaseDir.trim() ? auth.checkoutBaseDir.trim() : null;
|
|
235
278
|
if (!checkoutBaseDir)
|
|
236
279
|
return null;
|
|
237
|
-
|
|
238
|
-
writeRepoServerProjectRoot(projectRoot, inferred);
|
|
239
|
-
return inferred;
|
|
280
|
+
return `${checkoutBaseDir.replace(/\/+$/, "")}/${repoSlug}`;
|
|
240
281
|
}
|
|
241
282
|
function readLocalConnectionFallbackToken(projectRoot) {
|
|
242
283
|
return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
|
|
243
284
|
}
|
|
285
|
+
function normalizeRepoSlug(value) {
|
|
286
|
+
const slug = value?.trim();
|
|
287
|
+
return slug && /^[^/\s]+\/[^/\s]+$/.test(slug) ? slug : null;
|
|
288
|
+
}
|
|
289
|
+
function readProjectLinkSlug(projectRoot) {
|
|
290
|
+
const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
|
|
291
|
+
if (!existsSync2(path))
|
|
292
|
+
return null;
|
|
293
|
+
try {
|
|
294
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
295
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
296
|
+
return null;
|
|
297
|
+
return normalizeRepoSlug(typeof parsed.repoSlug === "string" ? String(parsed.repoSlug) : null);
|
|
298
|
+
} catch {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function writeProjectLinkConnection(projectRoot, repoSlug, alias) {
|
|
303
|
+
const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
|
|
304
|
+
mkdirSync2(dirname2(path), { recursive: true });
|
|
305
|
+
writeFileSync2(path, `${JSON.stringify({ repoSlug, connection: alias, linkedAt: new Date().toISOString() }, null, 2)}
|
|
306
|
+
`, "utf8");
|
|
307
|
+
}
|
|
308
|
+
function remoteLinkRepairCommand(repoSlug) {
|
|
309
|
+
return repoSlug ? `rig server repair-link --repo ${repoSlug}` : "rig server repair-link --repo owner/repo";
|
|
310
|
+
}
|
|
311
|
+
function formatRemoteProjectLinkHint(resolution) {
|
|
312
|
+
const repair = remoteLinkRepairCommand(resolution.repoSlug);
|
|
313
|
+
if (resolution.status === "auth_required") {
|
|
314
|
+
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}` : ""}\`.`;
|
|
315
|
+
}
|
|
316
|
+
if (resolution.status === "missing_project") {
|
|
317
|
+
return `Record the repo slug, then run \`${repair}\` (or \`rig init --repo owner/repo --server remote --github-auth device\`).`;
|
|
318
|
+
}
|
|
319
|
+
if (resolution.status === "not_remote")
|
|
320
|
+
return "Select a remote server with `rig server use <alias>` before repairing a remote project link.";
|
|
321
|
+
return `Run \`${repair}\` to backfill or prepare a server-host checkout for the selected remote${resolution.alias ? ` (${resolution.alias})` : ""}.`;
|
|
322
|
+
}
|
|
323
|
+
function remoteProjectLinkFailure(input) {
|
|
324
|
+
const partial = {
|
|
325
|
+
status: input.status,
|
|
326
|
+
alias: input.alias,
|
|
327
|
+
baseUrl: input.baseUrl,
|
|
328
|
+
repoSlug: input.repoSlug
|
|
329
|
+
};
|
|
330
|
+
return {
|
|
331
|
+
ok: false,
|
|
332
|
+
...input,
|
|
333
|
+
hint: formatRemoteProjectLinkHint(partial),
|
|
334
|
+
next: remoteLinkRepairCommand(input.repoSlug)
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function remoteProjectLinkSuccess(input) {
|
|
338
|
+
return {
|
|
339
|
+
ok: true,
|
|
340
|
+
status: input.status,
|
|
341
|
+
alias: input.alias,
|
|
342
|
+
baseUrl: input.baseUrl,
|
|
343
|
+
repoSlug: input.repoSlug,
|
|
344
|
+
serverProjectRoot: input.serverProjectRoot,
|
|
345
|
+
source: input.source,
|
|
346
|
+
prepared: input.prepared ?? input.status === "prepared",
|
|
347
|
+
validated: input.validated ?? false,
|
|
348
|
+
message: input.message ?? `Remote project link ready for ${input.repoSlug}.`,
|
|
349
|
+
hint: "Remote-scoped task/run/status requests will send x-rig-project-root for this server-host checkout.",
|
|
350
|
+
next: "rig task list"
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function localCheckoutPathCandidate(projectRoot, candidate) {
|
|
354
|
+
try {
|
|
355
|
+
const local = resolve2(projectRoot);
|
|
356
|
+
const resolved = resolve2(candidate);
|
|
357
|
+
return resolved === local || resolved.startsWith(`${local}/`);
|
|
358
|
+
} catch {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
async function requestRemoteProjectLinkJson(baseUrl, pathname, authToken, init = {}) {
|
|
363
|
+
const requestUrl = new URL(`${baseUrl}${pathname}`);
|
|
364
|
+
if (authToken && queryAuthFallbackEnabled())
|
|
365
|
+
requestUrl.searchParams.set("rt", authToken);
|
|
366
|
+
const response = await fetch(requestUrl, {
|
|
367
|
+
...init,
|
|
368
|
+
headers: mergeHeaders(init.headers, authToken)
|
|
369
|
+
});
|
|
370
|
+
const text = await response.text();
|
|
371
|
+
const payload = text.trim().length > 0 ? (() => {
|
|
372
|
+
try {
|
|
373
|
+
return JSON.parse(text);
|
|
374
|
+
} catch {
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
377
|
+
})() : null;
|
|
378
|
+
return { ok: response.ok, status: response.status, payload, text };
|
|
379
|
+
}
|
|
380
|
+
function payloadError(payload, fallback) {
|
|
381
|
+
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
382
|
+
const record = payload;
|
|
383
|
+
const value = record.error ?? record.message ?? record.reason;
|
|
384
|
+
if (typeof value === "string" && value.trim())
|
|
385
|
+
return value.trim();
|
|
386
|
+
}
|
|
387
|
+
return fallback;
|
|
388
|
+
}
|
|
389
|
+
function checkoutPathsFromProjectPayload(payload) {
|
|
390
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
391
|
+
return [];
|
|
392
|
+
const project = payload.project;
|
|
393
|
+
if (!project || typeof project !== "object" || Array.isArray(project))
|
|
394
|
+
return [];
|
|
395
|
+
const checkouts = project.checkouts;
|
|
396
|
+
if (!Array.isArray(checkouts))
|
|
397
|
+
return [];
|
|
398
|
+
return [...checkouts].reverse().flatMap((entry) => {
|
|
399
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
400
|
+
return [];
|
|
401
|
+
const path = entry.path;
|
|
402
|
+
return typeof path === "string" && path.trim() ? [path.trim()] : [];
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
function checkoutPathFromPreparePayload(payload) {
|
|
406
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
407
|
+
return null;
|
|
408
|
+
const checkout = payload.checkout;
|
|
409
|
+
if (!checkout || typeof checkout !== "object" || Array.isArray(checkout))
|
|
410
|
+
return null;
|
|
411
|
+
const path = checkout.path;
|
|
412
|
+
return typeof path === "string" && path.trim() ? path.trim() : null;
|
|
413
|
+
}
|
|
414
|
+
async function validateAndPersistRemoteRoot(input) {
|
|
415
|
+
const candidate = input.candidate.trim();
|
|
416
|
+
if (!candidate || !isAbsolute(candidate)) {
|
|
417
|
+
return remoteProjectLinkFailure({
|
|
418
|
+
status: "invalid_root",
|
|
419
|
+
alias: input.alias,
|
|
420
|
+
baseUrl: input.baseUrl,
|
|
421
|
+
repoSlug: input.repoSlug,
|
|
422
|
+
message: `Remote project root candidate is not an absolute server-host path: ${candidate || "(empty)"}.`
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
if (localCheckoutPathCandidate(input.projectRoot, candidate)) {
|
|
426
|
+
return remoteProjectLinkFailure({
|
|
427
|
+
status: "invalid_root",
|
|
428
|
+
alias: input.alias,
|
|
429
|
+
baseUrl: input.baseUrl,
|
|
430
|
+
repoSlug: input.repoSlug,
|
|
431
|
+
message: `Refusing to use local checkout path ${candidate} as a remote server project root.`
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
let response;
|
|
435
|
+
try {
|
|
436
|
+
response = await requestRemoteProjectLinkJson(input.baseUrl, "/api/server/project-root", input.authToken, {
|
|
437
|
+
method: "POST",
|
|
438
|
+
headers: { "content-type": "application/json" },
|
|
439
|
+
body: JSON.stringify({ projectRoot: candidate })
|
|
440
|
+
});
|
|
441
|
+
} catch (error) {
|
|
442
|
+
return remoteProjectLinkFailure({
|
|
443
|
+
status: "error",
|
|
444
|
+
alias: input.alias,
|
|
445
|
+
baseUrl: input.baseUrl,
|
|
446
|
+
repoSlug: input.repoSlug,
|
|
447
|
+
message: `Could not validate remote project root ${candidate}: ${error instanceof Error ? error.message : String(error)}`
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
if (response.status === 401 || response.status === 403) {
|
|
451
|
+
return remoteProjectLinkFailure({
|
|
452
|
+
status: "auth_required",
|
|
453
|
+
alias: input.alias,
|
|
454
|
+
baseUrl: input.baseUrl,
|
|
455
|
+
repoSlug: input.repoSlug,
|
|
456
|
+
statusCode: response.status,
|
|
457
|
+
message: `Remote server ${input.alias} requires authentication before validating project root ${candidate}.`
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
if (!response.ok) {
|
|
461
|
+
return remoteProjectLinkFailure({
|
|
462
|
+
status: "invalid_root",
|
|
463
|
+
alias: input.alias,
|
|
464
|
+
baseUrl: input.baseUrl,
|
|
465
|
+
repoSlug: input.repoSlug,
|
|
466
|
+
statusCode: response.status,
|
|
467
|
+
message: `Remote server rejected project root ${candidate} (${response.status}): ${payloadError(response.payload, response.text || "project-root validation failed")}`
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
const record = response.payload && typeof response.payload === "object" && !Array.isArray(response.payload) ? response.payload : {};
|
|
471
|
+
if (record.ok !== true) {
|
|
472
|
+
return remoteProjectLinkFailure({
|
|
473
|
+
status: "invalid_root",
|
|
474
|
+
alias: input.alias,
|
|
475
|
+
baseUrl: input.baseUrl,
|
|
476
|
+
repoSlug: input.repoSlug,
|
|
477
|
+
message: `Remote server did not accept project root ${candidate}: ${payloadError(response.payload, "project-root validation failed")}`
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
const accepted = typeof record.projectRoot === "string" && record.projectRoot.trim() ? record.projectRoot.trim() : typeof record.requestedProjectRoot === "string" && record.requestedProjectRoot.trim() ? record.requestedProjectRoot.trim() : candidate;
|
|
481
|
+
writeRepoServerProjectRoot(input.projectRoot, accepted, { alias: input.alias, baseUrl: input.baseUrl, project: input.repoSlug });
|
|
482
|
+
writeProjectLinkConnection(input.projectRoot, input.repoSlug, input.alias);
|
|
483
|
+
const status = input.status ?? (input.prepared ? "prepared" : "backfilled");
|
|
484
|
+
return remoteProjectLinkSuccess({
|
|
485
|
+
status,
|
|
486
|
+
alias: input.alias,
|
|
487
|
+
baseUrl: input.baseUrl,
|
|
488
|
+
repoSlug: input.repoSlug,
|
|
489
|
+
serverProjectRoot: accepted,
|
|
490
|
+
source: input.source,
|
|
491
|
+
prepared: input.prepared,
|
|
492
|
+
validated: true,
|
|
493
|
+
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}.`
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
async function ensureRemoteProjectRootLink(projectRoot, options = {}) {
|
|
497
|
+
let selected;
|
|
498
|
+
try {
|
|
499
|
+
selected = resolveSelectedConnection(projectRoot);
|
|
500
|
+
} catch (error) {
|
|
501
|
+
return remoteProjectLinkFailure({ status: "error", message: error instanceof Error ? error.message : String(error) });
|
|
502
|
+
}
|
|
503
|
+
if (!selected || selected.connection.kind !== "remote") {
|
|
504
|
+
return remoteProjectLinkFailure({ status: "not_remote", message: "No remote Rig server is selected for this repo." });
|
|
505
|
+
}
|
|
506
|
+
const repo = readRepoConnection(projectRoot);
|
|
507
|
+
const explicitRepoRequested = options.repoSlug !== undefined;
|
|
508
|
+
const explicitRepoSlug = explicitRepoRequested ? normalizeRepoSlug(options.repoSlug) : null;
|
|
509
|
+
const repoProjectSlug = normalizeRepoSlug(repo?.project);
|
|
510
|
+
const repoSlug = explicitRepoSlug ?? repoProjectSlug ?? readProjectLinkSlug(projectRoot);
|
|
511
|
+
const alias = selected.alias;
|
|
512
|
+
const baseUrl = selected.connection.baseUrl;
|
|
513
|
+
const authToken = options.authToken === undefined ? readGitHubBearerTokenForRemote(projectRoot) : options.authToken;
|
|
514
|
+
const mode = options.mode ?? "backfill-only";
|
|
515
|
+
if (explicitRepoRequested && !explicitRepoSlug) {
|
|
516
|
+
return remoteProjectLinkFailure({
|
|
517
|
+
status: "missing_project",
|
|
518
|
+
alias,
|
|
519
|
+
baseUrl,
|
|
520
|
+
message: `Invalid --repo value ${JSON.stringify(options.repoSlug)}. Expected owner/repo.`
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
if (!repoSlug) {
|
|
524
|
+
return remoteProjectLinkFailure({
|
|
525
|
+
status: "missing_project",
|
|
526
|
+
alias,
|
|
527
|
+
baseUrl,
|
|
528
|
+
message: `Remote server ${alias} is selected, but this checkout has no GitHub repo slug recorded.`
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
const skippedCandidates = [];
|
|
532
|
+
const storedRoot = selected.serverProjectRoot?.trim() || null;
|
|
533
|
+
const storedRootMatchesResolvedRepo = repoProjectSlug === repoSlug;
|
|
534
|
+
if (storedRoot && storedRootMatchesResolvedRepo) {
|
|
535
|
+
if (localCheckoutPathCandidate(projectRoot, storedRoot)) {
|
|
536
|
+
clearRepoServerProjectRoot(projectRoot);
|
|
537
|
+
skippedCandidates.push(storedRoot);
|
|
538
|
+
} else {
|
|
539
|
+
const storedResult = await validateAndPersistRemoteRoot({
|
|
540
|
+
projectRoot,
|
|
541
|
+
alias,
|
|
542
|
+
baseUrl,
|
|
543
|
+
authToken,
|
|
544
|
+
repoSlug,
|
|
545
|
+
candidate: storedRoot,
|
|
546
|
+
source: "stored",
|
|
547
|
+
status: "ready"
|
|
548
|
+
});
|
|
549
|
+
if (storedResult.ok || storedResult.status === "auth_required" || storedResult.status === "error")
|
|
550
|
+
return storedResult;
|
|
551
|
+
clearRepoServerProjectRoot(projectRoot);
|
|
552
|
+
skippedCandidates.push(storedRoot);
|
|
553
|
+
}
|
|
554
|
+
} else if (storedRoot) {
|
|
555
|
+
skippedCandidates.push(storedRoot);
|
|
556
|
+
}
|
|
557
|
+
const authCandidate = inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug);
|
|
558
|
+
if (authCandidate) {
|
|
559
|
+
const authResult = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: authCandidate, source: "auth-state" });
|
|
560
|
+
if (authResult.ok || authResult.status === "auth_required")
|
|
561
|
+
return authResult;
|
|
562
|
+
}
|
|
563
|
+
let registryResponse;
|
|
564
|
+
try {
|
|
565
|
+
registryResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}`, authToken);
|
|
566
|
+
} catch (error) {
|
|
567
|
+
return remoteProjectLinkFailure({
|
|
568
|
+
status: "error",
|
|
569
|
+
alias,
|
|
570
|
+
baseUrl,
|
|
571
|
+
repoSlug,
|
|
572
|
+
message: `Could not read remote project registry for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
if (registryResponse.status === 401 || registryResponse.status === 403) {
|
|
576
|
+
return remoteProjectLinkFailure({
|
|
577
|
+
status: "auth_required",
|
|
578
|
+
alias,
|
|
579
|
+
baseUrl,
|
|
580
|
+
repoSlug,
|
|
581
|
+
statusCode: registryResponse.status,
|
|
582
|
+
message: `Remote server ${alias} requires authentication before reading the ${repoSlug} project registry.`
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
if (registryResponse.ok) {
|
|
586
|
+
const candidates = checkoutPathsFromProjectPayload(registryResponse.payload);
|
|
587
|
+
for (const candidate of candidates) {
|
|
588
|
+
const result = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate, source: "registry" });
|
|
589
|
+
if (result.ok || result.status === "auth_required")
|
|
590
|
+
return result;
|
|
591
|
+
skippedCandidates.push(candidate);
|
|
592
|
+
}
|
|
593
|
+
if (mode === "backfill-only") {
|
|
594
|
+
return remoteProjectLinkFailure({
|
|
595
|
+
status: candidates.length > 0 ? "invalid_root" : "no_server_checkout",
|
|
596
|
+
alias,
|
|
597
|
+
baseUrl,
|
|
598
|
+
repoSlug,
|
|
599
|
+
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.`,
|
|
600
|
+
skippedCandidates
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
} else if (registryResponse.status === 404) {
|
|
604
|
+
if (mode === "backfill-only") {
|
|
605
|
+
return remoteProjectLinkFailure({
|
|
606
|
+
status: "project_not_registered",
|
|
607
|
+
alias,
|
|
608
|
+
baseUrl,
|
|
609
|
+
repoSlug,
|
|
610
|
+
statusCode: registryResponse.status,
|
|
611
|
+
message: `Remote server ${alias} has no registered project record for ${repoSlug}.`
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
} else {
|
|
615
|
+
return remoteProjectLinkFailure({
|
|
616
|
+
status: "error",
|
|
617
|
+
alias,
|
|
618
|
+
baseUrl,
|
|
619
|
+
repoSlug,
|
|
620
|
+
statusCode: registryResponse.status,
|
|
621
|
+
message: `Could not backfill ${repoSlug} from remote registry (${registryResponse.status}): ${payloadError(registryResponse.payload, registryResponse.text || "registry lookup failed")}`,
|
|
622
|
+
skippedCandidates
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
let prepareResponse;
|
|
626
|
+
try {
|
|
627
|
+
prepareResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}/prepare-checkout`, authToken, {
|
|
628
|
+
method: "POST",
|
|
629
|
+
headers: { "content-type": "application/json" },
|
|
630
|
+
body: JSON.stringify({ checkout: { kind: "managed-clone" }, repoUrl: `https://github.com/${repoSlug}.git` })
|
|
631
|
+
});
|
|
632
|
+
} catch (error) {
|
|
633
|
+
return remoteProjectLinkFailure({
|
|
634
|
+
status: "error",
|
|
635
|
+
alias,
|
|
636
|
+
baseUrl,
|
|
637
|
+
repoSlug,
|
|
638
|
+
message: `Could not prepare remote checkout for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
if (prepareResponse.status === 401 || prepareResponse.status === 403) {
|
|
642
|
+
return remoteProjectLinkFailure({
|
|
643
|
+
status: "auth_required",
|
|
644
|
+
alias,
|
|
645
|
+
baseUrl,
|
|
646
|
+
repoSlug,
|
|
647
|
+
statusCode: prepareResponse.status,
|
|
648
|
+
message: `Remote server ${alias} requires authentication before preparing ${repoSlug}.`
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
if (!prepareResponse.ok) {
|
|
652
|
+
return remoteProjectLinkFailure({
|
|
653
|
+
status: "error",
|
|
654
|
+
alias,
|
|
655
|
+
baseUrl,
|
|
656
|
+
repoSlug,
|
|
657
|
+
statusCode: prepareResponse.status,
|
|
658
|
+
message: `Remote checkout prepare failed for ${repoSlug} (${prepareResponse.status}): ${payloadError(prepareResponse.payload, prepareResponse.text || "prepare-checkout failed")}`,
|
|
659
|
+
skippedCandidates
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
const preparedPath = checkoutPathFromPreparePayload(prepareResponse.payload);
|
|
663
|
+
if (!preparedPath) {
|
|
664
|
+
return remoteProjectLinkFailure({
|
|
665
|
+
status: "invalid_root",
|
|
666
|
+
alias,
|
|
667
|
+
baseUrl,
|
|
668
|
+
repoSlug,
|
|
669
|
+
message: `Remote checkout prepare for ${repoSlug} did not return a checkout.path.`,
|
|
670
|
+
skippedCandidates
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
return validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: preparedPath, source: "prepare", prepared: true });
|
|
674
|
+
}
|
|
244
675
|
async function ensureServerForCli(projectRoot) {
|
|
245
676
|
try {
|
|
246
677
|
const selected = resolveSelectedConnection(projectRoot);
|
|
247
678
|
if (selected?.connection.kind === "remote") {
|
|
248
679
|
reportServerPhase(`Connecting to ${selected.alias}\u2026`);
|
|
249
680
|
const authToken = readGitHubBearerTokenForRemote(projectRoot);
|
|
250
|
-
const
|
|
681
|
+
const link = await ensureRemoteProjectRootLink(projectRoot, { mode: "backfill-only", authToken });
|
|
251
682
|
return {
|
|
252
683
|
baseUrl: selected.connection.baseUrl,
|
|
253
684
|
authToken,
|
|
254
685
|
connectionKind: "remote",
|
|
255
|
-
serverProjectRoot
|
|
686
|
+
serverProjectRoot: link.ok ? link.serverProjectRoot ?? null : null
|
|
256
687
|
};
|
|
257
688
|
}
|
|
258
689
|
reportServerPhase("Starting local Rig server\u2026");
|
|
@@ -270,32 +701,6 @@ async function ensureServerForCli(projectRoot) {
|
|
|
270
701
|
throw error;
|
|
271
702
|
}
|
|
272
703
|
}
|
|
273
|
-
async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
|
|
274
|
-
const repo = readRepoConnection(projectRoot);
|
|
275
|
-
const slug = repo?.project?.trim();
|
|
276
|
-
if (!slug)
|
|
277
|
-
return null;
|
|
278
|
-
try {
|
|
279
|
-
const url = new URL(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`);
|
|
280
|
-
if (authToken && queryAuthFallbackEnabled())
|
|
281
|
-
url.searchParams.set("rt", authToken);
|
|
282
|
-
const response = await fetch(url, {
|
|
283
|
-
headers: mergeHeaders(undefined, authToken)
|
|
284
|
-
});
|
|
285
|
-
if (!response.ok)
|
|
286
|
-
return null;
|
|
287
|
-
const payload = await response.json();
|
|
288
|
-
const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
|
|
289
|
-
const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
|
|
290
|
-
const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
|
|
291
|
-
const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
|
|
292
|
-
if (path)
|
|
293
|
-
writeRepoServerProjectRoot(projectRoot, path);
|
|
294
|
-
return path;
|
|
295
|
-
} catch {
|
|
296
|
-
return null;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
704
|
function mergeCookie(existing, name, value) {
|
|
300
705
|
const encoded = `${name}=${encodeURIComponent(value)}`;
|
|
301
706
|
if (!existing?.trim())
|
|
@@ -386,13 +791,20 @@ function canUseRemoteWithoutProjectRoot(pathname) {
|
|
|
386
791
|
async function requestServerJson(context, pathname, init = {}) {
|
|
387
792
|
const server = await ensureServerForCli(context.projectRoot);
|
|
388
793
|
const requestUrl = new URL(`${server.baseUrl}${pathname}`);
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
794
|
+
let scopedServerProjectRoot = server.serverProjectRoot;
|
|
795
|
+
if (server.connectionKind === "remote" && !scopedServerProjectRoot && !canUseRemoteWithoutProjectRoot(requestUrl.pathname) && (server.authToken || !isLoopbackRemoteBaseUrl(server.baseUrl))) {
|
|
796
|
+
const link = await ensureRemoteProjectRootLink(context.projectRoot, { mode: "backfill-only", authToken: server.authToken });
|
|
797
|
+
if (link.ok && link.serverProjectRoot) {
|
|
798
|
+
scopedServerProjectRoot = link.serverProjectRoot;
|
|
799
|
+
} else {
|
|
800
|
+
const repo = readRepoConnection(context.projectRoot);
|
|
801
|
+
const target = link.alias && link.baseUrl ? `${link.alias} (${link.baseUrl})` : server.baseUrl;
|
|
802
|
+
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 });
|
|
803
|
+
}
|
|
392
804
|
}
|
|
393
805
|
const headers = mergeHeaders(init.headers, server.authToken);
|
|
394
|
-
if (
|
|
395
|
-
headers.set("x-rig-project-root",
|
|
806
|
+
if (scopedServerProjectRoot)
|
|
807
|
+
headers.set("x-rig-project-root", scopedServerProjectRoot);
|
|
396
808
|
if (server.connectionKind === "remote" && server.authToken && queryAuthFallbackEnabled()) {
|
|
397
809
|
requestUrl.searchParams.set("rt", server.authToken);
|
|
398
810
|
}
|
|
@@ -717,7 +1129,7 @@ var init__pi_install = () => {};
|
|
|
717
1129
|
|
|
718
1130
|
// packages/cli/src/commands/_snapshot-upload.ts
|
|
719
1131
|
import { mkdir, readdir, readFile, writeFile } from "fs/promises";
|
|
720
|
-
import { dirname as
|
|
1132
|
+
import { dirname as dirname3, resolve as resolve4, relative, sep } from "path";
|
|
721
1133
|
function toPosixPath(path) {
|
|
722
1134
|
return path.split(sep).join("/");
|
|
723
1135
|
}
|
|
@@ -1362,7 +1774,7 @@ __export(exports_init, {
|
|
|
1362
1774
|
DEMO_TASKS_RELATIVE_DIR: () => DEMO_TASKS_RELATIVE_DIR,
|
|
1363
1775
|
DEMO_TASKS: () => DEMO_TASKS
|
|
1364
1776
|
});
|
|
1365
|
-
import { appendFileSync, existsSync as existsSync5, mkdirSync as
|
|
1777
|
+
import { appendFileSync, existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
1366
1778
|
import { spawnSync } from "child_process";
|
|
1367
1779
|
import { basename, resolve as resolve6 } from "path";
|
|
1368
1780
|
import { buildRigInitConfigSource } from "@rig/core";
|
|
@@ -1386,14 +1798,14 @@ function parseRepoSlug(value) {
|
|
|
1386
1798
|
}
|
|
1387
1799
|
function ensureRigPrivateDirs(projectRoot) {
|
|
1388
1800
|
const rigDir = resolve6(projectRoot, ".rig");
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1801
|
+
mkdirSync3(resolve6(rigDir, "state"), { recursive: true });
|
|
1802
|
+
mkdirSync3(resolve6(rigDir, "logs"), { recursive: true });
|
|
1803
|
+
mkdirSync3(resolve6(rigDir, "runs"), { recursive: true });
|
|
1804
|
+
mkdirSync3(resolve6(rigDir, "tmp"), { recursive: true });
|
|
1805
|
+
mkdirSync3(resolve6(projectRoot, "artifacts"), { recursive: true });
|
|
1394
1806
|
const taskConfigPath = resolve6(rigDir, "task-config.json");
|
|
1395
1807
|
if (!existsSync5(taskConfigPath))
|
|
1396
|
-
|
|
1808
|
+
writeFileSync3(taskConfigPath, `{}
|
|
1397
1809
|
`, "utf-8");
|
|
1398
1810
|
}
|
|
1399
1811
|
function ensureGitignoreEntries(projectRoot) {
|
|
@@ -1421,7 +1833,7 @@ function ensureRigConfigPackageDependencies(projectRoot) {
|
|
|
1421
1833
|
...existsSync5(path) ? existing : { name: "rig-project", private: true },
|
|
1422
1834
|
devDependencies
|
|
1423
1835
|
};
|
|
1424
|
-
|
|
1836
|
+
writeFileSync3(path, `${JSON.stringify(next, null, 2)}
|
|
1425
1837
|
`, "utf8");
|
|
1426
1838
|
}
|
|
1427
1839
|
function applyGitHubProjectConfig(source, options) {
|
|
@@ -1447,9 +1859,9 @@ function checkoutForInit(projectRoot, serverKind, strategy) {
|
|
|
1447
1859
|
const selected = strategy ?? { kind: "managed-clone" };
|
|
1448
1860
|
switch (selected.kind) {
|
|
1449
1861
|
case "managed-clone":
|
|
1450
|
-
return { kind: "managed-clone"
|
|
1862
|
+
return { kind: "managed-clone" };
|
|
1451
1863
|
case "current-ref":
|
|
1452
|
-
return { kind: "current-ref",
|
|
1864
|
+
return { kind: "current-ref", ...selected.ref ? { ref: selected.ref } : {} };
|
|
1453
1865
|
case "uploaded-snapshot":
|
|
1454
1866
|
return { kind: "uploaded-snapshot", path: projectRoot, source: "local-working-tree" };
|
|
1455
1867
|
case "existing-path":
|
|
@@ -1702,7 +2114,7 @@ function remoteGitHubAuthMetadata(payload) {
|
|
|
1702
2114
|
};
|
|
1703
2115
|
}
|
|
1704
2116
|
function writeRemoteGitHubAuthState(projectRoot, input) {
|
|
1705
|
-
|
|
2117
|
+
writeFileSync3(resolve6(projectRoot, ".rig", "state", "github-auth.json"), `${JSON.stringify({
|
|
1706
2118
|
authenticated: true,
|
|
1707
2119
|
source: input.source,
|
|
1708
2120
|
storedOnServer: true,
|
|
@@ -1750,7 +2162,7 @@ function runLocalFilesInit(context, options) {
|
|
|
1750
2162
|
console.log("rig.config already exists; leaving it unchanged. Pass --repair to rewrite it.");
|
|
1751
2163
|
} else {
|
|
1752
2164
|
const projectName = basename(projectRoot) || "rig-project";
|
|
1753
|
-
|
|
2165
|
+
writeFileSync3(configTsPath, buildRigInitConfigSource({
|
|
1754
2166
|
projectName,
|
|
1755
2167
|
taskSource: { kind: "files", path: "tasks" },
|
|
1756
2168
|
useStandardPlugin: true
|
|
@@ -1759,8 +2171,8 @@ function runLocalFilesInit(context, options) {
|
|
|
1759
2171
|
ensureRigConfigPackageDependencies(projectRoot);
|
|
1760
2172
|
const tasksDir = resolve6(projectRoot, "tasks");
|
|
1761
2173
|
if (!existsSync5(tasksDir)) {
|
|
1762
|
-
|
|
1763
|
-
|
|
2174
|
+
mkdirSync3(tasksDir, { recursive: true });
|
|
2175
|
+
writeFileSync3(resolve6(tasksDir, "T-1.json"), `${JSON.stringify({ id: "T-1", title: "My first Rig task", body: "Describe the change you want an agent to make." }, null, 2)}
|
|
1764
2176
|
`, "utf-8");
|
|
1765
2177
|
}
|
|
1766
2178
|
if (context.outputMode !== "json") {
|
|
@@ -1784,7 +2196,7 @@ function runDemoInit(context, options) {
|
|
|
1784
2196
|
console.log("rig.config already exists; leaving it unchanged. Pass --repair to rewrite it for the demo.");
|
|
1785
2197
|
}
|
|
1786
2198
|
} else {
|
|
1787
|
-
|
|
2199
|
+
writeFileSync3(configTsPath, buildRigInitConfigSource({
|
|
1788
2200
|
projectName: basename(projectRoot) || "rig-demo",
|
|
1789
2201
|
taskSource: { kind: "files", path: DEMO_TASKS_RELATIVE_DIR },
|
|
1790
2202
|
useStandardPlugin: true
|
|
@@ -1793,14 +2205,14 @@ function runDemoInit(context, options) {
|
|
|
1793
2205
|
}
|
|
1794
2206
|
ensureRigConfigPackageDependencies(projectRoot);
|
|
1795
2207
|
const demoTasksDir = resolve6(projectRoot, DEMO_TASKS_RELATIVE_DIR);
|
|
1796
|
-
|
|
2208
|
+
mkdirSync3(demoTasksDir, { recursive: true });
|
|
1797
2209
|
const taskIds = [];
|
|
1798
2210
|
for (const task of DEMO_TASKS) {
|
|
1799
2211
|
const id = String(task.id);
|
|
1800
2212
|
taskIds.push(id);
|
|
1801
2213
|
const taskPath = resolve6(demoTasksDir, `${id}.json`);
|
|
1802
2214
|
if (!existsSync5(taskPath)) {
|
|
1803
|
-
|
|
2215
|
+
writeFileSync3(taskPath, `${JSON.stringify(task, null, 2)}
|
|
1804
2216
|
`, "utf-8");
|
|
1805
2217
|
}
|
|
1806
2218
|
}
|
|
@@ -1828,21 +2240,32 @@ function runDemoInit(context, options) {
|
|
|
1828
2240
|
}
|
|
1829
2241
|
async function runControlPlaneInit(context, options) {
|
|
1830
2242
|
const projectRoot = context.projectRoot;
|
|
1831
|
-
const
|
|
2243
|
+
const existingRepoConnection = readRepoConnection(projectRoot);
|
|
2244
|
+
const selectedConnection = (() => {
|
|
2245
|
+
try {
|
|
2246
|
+
return resolveSelectedConnection(projectRoot);
|
|
2247
|
+
} catch {
|
|
2248
|
+
return null;
|
|
2249
|
+
}
|
|
2250
|
+
})();
|
|
2251
|
+
const selectedRemote = selectedConnection?.connection.kind === "remote" ? { alias: selectedConnection.alias, connection: selectedConnection.connection } : null;
|
|
2252
|
+
const detectedSlug = options.repoSlug ?? existingRepoConnection?.project ?? detectOriginRepoSlug(projectRoot);
|
|
2253
|
+
const serverKind = options.server ?? (selectedRemote ? "remote" : "local");
|
|
1832
2254
|
if (!detectedSlug) {
|
|
1833
2255
|
const authMethod2 = options.githubAuthMethod ?? (options.githubToken ? "token" : "skip");
|
|
1834
|
-
if (
|
|
2256
|
+
if (serverKind === "local" && authMethod2 === "skip") {
|
|
1835
2257
|
return runLocalFilesInit(context, options);
|
|
1836
2258
|
}
|
|
1837
2259
|
throw new CliError("Could not detect GitHub repo slug from origin. Pass --repo owner/repo \u2014 or run `rig init --yes --server local --github-auth skip` for a local files-source project without GitHub.", 1);
|
|
1838
2260
|
}
|
|
1839
2261
|
const repo = parseRepoSlug(detectedSlug);
|
|
1840
|
-
const
|
|
1841
|
-
const
|
|
2262
|
+
const connectionAlias = options.connectionAlias ?? (serverKind === "local" ? "local" : selectedRemote?.alias ?? "remote");
|
|
2263
|
+
const selectedRemoteUrl = selectedRemote && (!options.connectionAlias || options.connectionAlias === selectedRemote.alias) ? selectedRemote.connection.baseUrl : undefined;
|
|
2264
|
+
const remoteUrl = serverKind === "remote" ? (options.remoteUrl ?? selectedRemoteUrl)?.replace(/\/+$/, "") : undefined;
|
|
1842
2265
|
if (serverKind === "remote") {
|
|
1843
|
-
if (!
|
|
1844
|
-
throw new CliError("Missing --remote-url for --server remote.", 1, { hint: "Re-run as `rig init --server remote --remote-url https://your-rig-server
|
|
1845
|
-
upsertGlobalConnection(connectionAlias, { kind: "remote", baseUrl:
|
|
2266
|
+
if (!remoteUrl)
|
|
2267
|
+
throw new CliError("Missing --remote-url for --server remote.", 1, { hint: "Re-run as `rig init --server remote --remote-url https://your-rig-server`, or first select a saved remote with `rig server use <alias>`." });
|
|
2268
|
+
upsertGlobalConnection(connectionAlias, { kind: "remote", baseUrl: remoteUrl });
|
|
1846
2269
|
}
|
|
1847
2270
|
writeRepoConnection(projectRoot, {
|
|
1848
2271
|
selected: connectionAlias,
|
|
@@ -1865,11 +2288,11 @@ async function runControlPlaneInit(context, options) {
|
|
|
1865
2288
|
taskSource: { kind: "github-issues", owner: repo.owner, repo: repo.repo },
|
|
1866
2289
|
useStandardPlugin: true
|
|
1867
2290
|
}), options);
|
|
1868
|
-
|
|
2291
|
+
writeFileSync3(configTsPath, source, "utf-8");
|
|
1869
2292
|
}
|
|
1870
2293
|
ensureRigConfigPackageDependencies(projectRoot);
|
|
1871
2294
|
}
|
|
1872
|
-
|
|
2295
|
+
writeFileSync3(resolve6(projectRoot, ".rig", "state", "project-link.json"), `${JSON.stringify({ repoSlug: repo.slug, connection: connectionAlias, linkedAt: new Date().toISOString() }, null, 2)}
|
|
1873
2296
|
`, "utf8");
|
|
1874
2297
|
const checkout = checkoutForInit(projectRoot, serverKind, options.remoteCheckout);
|
|
1875
2298
|
let uploadedSnapshot = null;
|
|
@@ -1884,7 +2307,7 @@ async function runControlPlaneInit(context, options) {
|
|
|
1884
2307
|
let githubAuth = null;
|
|
1885
2308
|
let deviceAuth = null;
|
|
1886
2309
|
const authMethod = options.githubAuthMethod ?? (options.githubToken ? "token" : "skip");
|
|
1887
|
-
const remoteGhTokenWarning = serverKind === "remote" && authMethod === "gh" ? `This sends a GitHub token from this machine to ${
|
|
2310
|
+
const remoteGhTokenWarning = serverKind === "remote" && authMethod === "gh" ? `This sends a GitHub token from this machine to ${remoteUrl ?? "the remote Rig server"}.` : null;
|
|
1888
2311
|
if (remoteGhTokenWarning && !options.yes) {
|
|
1889
2312
|
throw new CliError(`${remoteGhTokenWarning} Re-run with --yes to confirm this explicit token transfer.`, 1);
|
|
1890
2313
|
}
|