@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
|
@@ -320,7 +320,7 @@ var init_drone_ui = __esm(() => {
|
|
|
320
320
|
});
|
|
321
321
|
|
|
322
322
|
// packages/cli/src/commands/init.ts
|
|
323
|
-
import { appendFileSync, existsSync as existsSync5, mkdirSync as
|
|
323
|
+
import { appendFileSync, existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
324
324
|
import { spawnSync } from "child_process";
|
|
325
325
|
import { basename, resolve as resolve6 } from "path";
|
|
326
326
|
|
|
@@ -459,12 +459,28 @@ function readRepoConnection(projectRoot) {
|
|
|
459
459
|
selected,
|
|
460
460
|
project: typeof record.project === "string" ? record.project : undefined,
|
|
461
461
|
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
|
|
462
|
-
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
462
|
+
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined,
|
|
463
|
+
serverProjectRootAlias: typeof record.serverProjectRootAlias === "string" && record.serverProjectRootAlias.trim() ? record.serverProjectRootAlias.trim() : undefined,
|
|
464
|
+
serverProjectRootBaseUrl: typeof record.serverProjectRootBaseUrl === "string" && record.serverProjectRootBaseUrl.trim() ? record.serverProjectRootBaseUrl.trim().replace(/\/+$/, "") : undefined
|
|
463
465
|
};
|
|
464
466
|
}
|
|
465
467
|
function writeRepoConnection(projectRoot, state) {
|
|
466
468
|
writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
|
|
467
469
|
}
|
|
470
|
+
function rootAllowedForSelection(repo, connection) {
|
|
471
|
+
const root = repo.serverProjectRoot?.trim();
|
|
472
|
+
if (!root)
|
|
473
|
+
return;
|
|
474
|
+
if (connection.kind === "remote") {
|
|
475
|
+
if (repo.serverProjectRootAlias !== repo.selected)
|
|
476
|
+
return;
|
|
477
|
+
if (repo.serverProjectRootBaseUrl !== connection.baseUrl)
|
|
478
|
+
return;
|
|
479
|
+
} else if (repo.serverProjectRootAlias && repo.serverProjectRootAlias !== repo.selected) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
return root;
|
|
483
|
+
}
|
|
468
484
|
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
469
485
|
const repo = readRepoConnection(projectRoot);
|
|
470
486
|
if (!repo)
|
|
@@ -476,18 +492,46 @@ function resolveSelectedConnection(projectRoot, options = {}) {
|
|
|
476
492
|
if (!connection) {
|
|
477
493
|
throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
478
494
|
}
|
|
479
|
-
return { alias: repo.selected, connection, serverProjectRoot: repo
|
|
495
|
+
return { alias: repo.selected, connection, serverProjectRoot: rootAllowedForSelection(repo, connection) };
|
|
496
|
+
}
|
|
497
|
+
function writeRepoServerProjectRoot(projectRoot, serverProjectRoot, metadata = {}) {
|
|
498
|
+
const repo = readRepoConnection(projectRoot);
|
|
499
|
+
if (!repo)
|
|
500
|
+
return;
|
|
501
|
+
let inferred = metadata;
|
|
502
|
+
if (!inferred.alias || !inferred.baseUrl) {
|
|
503
|
+
try {
|
|
504
|
+
const selected = resolveSelectedConnection(projectRoot);
|
|
505
|
+
if (selected?.connection.kind === "remote") {
|
|
506
|
+
inferred = {
|
|
507
|
+
alias: inferred.alias ?? selected.alias,
|
|
508
|
+
baseUrl: inferred.baseUrl ?? selected.connection.baseUrl
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
} catch {}
|
|
512
|
+
}
|
|
513
|
+
writeRepoConnection(projectRoot, {
|
|
514
|
+
...repo,
|
|
515
|
+
...metadata.project ? { project: metadata.project } : {},
|
|
516
|
+
serverProjectRoot,
|
|
517
|
+
...inferred.alias ? { serverProjectRootAlias: inferred.alias } : {},
|
|
518
|
+
...inferred.baseUrl ? { serverProjectRootBaseUrl: inferred.baseUrl.replace(/\/+$/, "") } : {}
|
|
519
|
+
});
|
|
480
520
|
}
|
|
481
|
-
function
|
|
521
|
+
function clearRepoServerProjectRoot(projectRoot) {
|
|
482
522
|
const repo = readRepoConnection(projectRoot);
|
|
483
523
|
if (!repo)
|
|
484
524
|
return;
|
|
485
|
-
writeRepoConnection(projectRoot, {
|
|
525
|
+
writeRepoConnection(projectRoot, {
|
|
526
|
+
selected: repo.selected,
|
|
527
|
+
...repo.project ? { project: repo.project } : {},
|
|
528
|
+
...repo.linkedAt ? { linkedAt: repo.linkedAt } : {}
|
|
529
|
+
});
|
|
486
530
|
}
|
|
487
531
|
|
|
488
532
|
// packages/cli/src/commands/_server-client.ts
|
|
489
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
490
|
-
import { resolve as resolve2 } from "path";
|
|
533
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
534
|
+
import { dirname as dirname2, isAbsolute, resolve as resolve2 } from "path";
|
|
491
535
|
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
492
536
|
var scopedGitHubBearerTokens = new Map;
|
|
493
537
|
var serverPhaseListener = null;
|
|
@@ -530,11 +574,10 @@ function readStoredGitHubAuthToken(projectRoot) {
|
|
|
530
574
|
const parsed = readRemoteAuthState(projectRoot);
|
|
531
575
|
return parsed ? cleanToken(typeof parsed.token === "string" ? parsed.token : undefined) : null;
|
|
532
576
|
}
|
|
533
|
-
function
|
|
534
|
-
|
|
535
|
-
const slug = repo?.project?.trim();
|
|
536
|
-
if (!slug || !/^[^/]+\/[^/]+$/.test(slug))
|
|
577
|
+
function inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug) {
|
|
578
|
+
if (!/^[^/]+\/[^/]+$/.test(repoSlug))
|
|
537
579
|
return null;
|
|
580
|
+
const repo = readRepoConnection(projectRoot);
|
|
538
581
|
const auth = readRemoteAuthState(projectRoot);
|
|
539
582
|
const authUpdatedAt = typeof auth?.updatedAt === "string" ? Date.parse(auth.updatedAt) : Number.NaN;
|
|
540
583
|
const repoLinkedAt = typeof repo?.linkedAt === "string" ? Date.parse(repo.linkedAt) : Number.NaN;
|
|
@@ -543,25 +586,413 @@ function inferRemoteServerProjectRootFromAuthState(projectRoot) {
|
|
|
543
586
|
const checkoutBaseDir = typeof auth?.checkoutBaseDir === "string" && auth.checkoutBaseDir.trim() ? auth.checkoutBaseDir.trim() : null;
|
|
544
587
|
if (!checkoutBaseDir)
|
|
545
588
|
return null;
|
|
546
|
-
|
|
547
|
-
writeRepoServerProjectRoot(projectRoot, inferred);
|
|
548
|
-
return inferred;
|
|
589
|
+
return `${checkoutBaseDir.replace(/\/+$/, "")}/${repoSlug}`;
|
|
549
590
|
}
|
|
550
591
|
function readLocalConnectionFallbackToken(projectRoot) {
|
|
551
592
|
return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
|
|
552
593
|
}
|
|
594
|
+
function normalizeRepoSlug(value) {
|
|
595
|
+
const slug = value?.trim();
|
|
596
|
+
return slug && /^[^/\s]+\/[^/\s]+$/.test(slug) ? slug : null;
|
|
597
|
+
}
|
|
598
|
+
function readProjectLinkSlug(projectRoot) {
|
|
599
|
+
const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
|
|
600
|
+
if (!existsSync2(path))
|
|
601
|
+
return null;
|
|
602
|
+
try {
|
|
603
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
604
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
605
|
+
return null;
|
|
606
|
+
return normalizeRepoSlug(typeof parsed.repoSlug === "string" ? String(parsed.repoSlug) : null);
|
|
607
|
+
} catch {
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
function writeProjectLinkConnection(projectRoot, repoSlug, alias) {
|
|
612
|
+
const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
|
|
613
|
+
mkdirSync2(dirname2(path), { recursive: true });
|
|
614
|
+
writeFileSync2(path, `${JSON.stringify({ repoSlug, connection: alias, linkedAt: new Date().toISOString() }, null, 2)}
|
|
615
|
+
`, "utf8");
|
|
616
|
+
}
|
|
617
|
+
function remoteLinkRepairCommand(repoSlug) {
|
|
618
|
+
return repoSlug ? `rig server repair-link --repo ${repoSlug}` : "rig server repair-link --repo owner/repo";
|
|
619
|
+
}
|
|
620
|
+
function formatRemoteProjectLinkHint(resolution) {
|
|
621
|
+
const repair = remoteLinkRepairCommand(resolution.repoSlug);
|
|
622
|
+
if (resolution.status === "auth_required") {
|
|
623
|
+
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}` : ""}\`.`;
|
|
624
|
+
}
|
|
625
|
+
if (resolution.status === "missing_project") {
|
|
626
|
+
return `Record the repo slug, then run \`${repair}\` (or \`rig init --repo owner/repo --server remote --github-auth device\`).`;
|
|
627
|
+
}
|
|
628
|
+
if (resolution.status === "not_remote")
|
|
629
|
+
return "Select a remote server with `rig server use <alias>` before repairing a remote project link.";
|
|
630
|
+
return `Run \`${repair}\` to backfill or prepare a server-host checkout for the selected remote${resolution.alias ? ` (${resolution.alias})` : ""}.`;
|
|
631
|
+
}
|
|
632
|
+
function remoteProjectLinkFailure(input) {
|
|
633
|
+
const partial = {
|
|
634
|
+
status: input.status,
|
|
635
|
+
alias: input.alias,
|
|
636
|
+
baseUrl: input.baseUrl,
|
|
637
|
+
repoSlug: input.repoSlug
|
|
638
|
+
};
|
|
639
|
+
return {
|
|
640
|
+
ok: false,
|
|
641
|
+
...input,
|
|
642
|
+
hint: formatRemoteProjectLinkHint(partial),
|
|
643
|
+
next: remoteLinkRepairCommand(input.repoSlug)
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
function remoteProjectLinkSuccess(input) {
|
|
647
|
+
return {
|
|
648
|
+
ok: true,
|
|
649
|
+
status: input.status,
|
|
650
|
+
alias: input.alias,
|
|
651
|
+
baseUrl: input.baseUrl,
|
|
652
|
+
repoSlug: input.repoSlug,
|
|
653
|
+
serverProjectRoot: input.serverProjectRoot,
|
|
654
|
+
source: input.source,
|
|
655
|
+
prepared: input.prepared ?? input.status === "prepared",
|
|
656
|
+
validated: input.validated ?? false,
|
|
657
|
+
message: input.message ?? `Remote project link ready for ${input.repoSlug}.`,
|
|
658
|
+
hint: "Remote-scoped task/run/status requests will send x-rig-project-root for this server-host checkout.",
|
|
659
|
+
next: "rig task list"
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
function localCheckoutPathCandidate(projectRoot, candidate) {
|
|
663
|
+
try {
|
|
664
|
+
const local = resolve2(projectRoot);
|
|
665
|
+
const resolved = resolve2(candidate);
|
|
666
|
+
return resolved === local || resolved.startsWith(`${local}/`);
|
|
667
|
+
} catch {
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
async function requestRemoteProjectLinkJson(baseUrl, pathname, authToken, init = {}) {
|
|
672
|
+
const requestUrl = new URL(`${baseUrl}${pathname}`);
|
|
673
|
+
if (authToken && queryAuthFallbackEnabled())
|
|
674
|
+
requestUrl.searchParams.set("rt", authToken);
|
|
675
|
+
const response = await fetch(requestUrl, {
|
|
676
|
+
...init,
|
|
677
|
+
headers: mergeHeaders(init.headers, authToken)
|
|
678
|
+
});
|
|
679
|
+
const text = await response.text();
|
|
680
|
+
const payload = text.trim().length > 0 ? (() => {
|
|
681
|
+
try {
|
|
682
|
+
return JSON.parse(text);
|
|
683
|
+
} catch {
|
|
684
|
+
return null;
|
|
685
|
+
}
|
|
686
|
+
})() : null;
|
|
687
|
+
return { ok: response.ok, status: response.status, payload, text };
|
|
688
|
+
}
|
|
689
|
+
function payloadError(payload, fallback) {
|
|
690
|
+
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
691
|
+
const record = payload;
|
|
692
|
+
const value = record.error ?? record.message ?? record.reason;
|
|
693
|
+
if (typeof value === "string" && value.trim())
|
|
694
|
+
return value.trim();
|
|
695
|
+
}
|
|
696
|
+
return fallback;
|
|
697
|
+
}
|
|
698
|
+
function checkoutPathsFromProjectPayload(payload) {
|
|
699
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
700
|
+
return [];
|
|
701
|
+
const project = payload.project;
|
|
702
|
+
if (!project || typeof project !== "object" || Array.isArray(project))
|
|
703
|
+
return [];
|
|
704
|
+
const checkouts = project.checkouts;
|
|
705
|
+
if (!Array.isArray(checkouts))
|
|
706
|
+
return [];
|
|
707
|
+
return [...checkouts].reverse().flatMap((entry) => {
|
|
708
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
709
|
+
return [];
|
|
710
|
+
const path = entry.path;
|
|
711
|
+
return typeof path === "string" && path.trim() ? [path.trim()] : [];
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
function checkoutPathFromPreparePayload(payload) {
|
|
715
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
716
|
+
return null;
|
|
717
|
+
const checkout = payload.checkout;
|
|
718
|
+
if (!checkout || typeof checkout !== "object" || Array.isArray(checkout))
|
|
719
|
+
return null;
|
|
720
|
+
const path = checkout.path;
|
|
721
|
+
return typeof path === "string" && path.trim() ? path.trim() : null;
|
|
722
|
+
}
|
|
723
|
+
async function validateAndPersistRemoteRoot(input) {
|
|
724
|
+
const candidate = input.candidate.trim();
|
|
725
|
+
if (!candidate || !isAbsolute(candidate)) {
|
|
726
|
+
return remoteProjectLinkFailure({
|
|
727
|
+
status: "invalid_root",
|
|
728
|
+
alias: input.alias,
|
|
729
|
+
baseUrl: input.baseUrl,
|
|
730
|
+
repoSlug: input.repoSlug,
|
|
731
|
+
message: `Remote project root candidate is not an absolute server-host path: ${candidate || "(empty)"}.`
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
if (localCheckoutPathCandidate(input.projectRoot, candidate)) {
|
|
735
|
+
return remoteProjectLinkFailure({
|
|
736
|
+
status: "invalid_root",
|
|
737
|
+
alias: input.alias,
|
|
738
|
+
baseUrl: input.baseUrl,
|
|
739
|
+
repoSlug: input.repoSlug,
|
|
740
|
+
message: `Refusing to use local checkout path ${candidate} as a remote server project root.`
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
let response;
|
|
744
|
+
try {
|
|
745
|
+
response = await requestRemoteProjectLinkJson(input.baseUrl, "/api/server/project-root", input.authToken, {
|
|
746
|
+
method: "POST",
|
|
747
|
+
headers: { "content-type": "application/json" },
|
|
748
|
+
body: JSON.stringify({ projectRoot: candidate })
|
|
749
|
+
});
|
|
750
|
+
} catch (error) {
|
|
751
|
+
return remoteProjectLinkFailure({
|
|
752
|
+
status: "error",
|
|
753
|
+
alias: input.alias,
|
|
754
|
+
baseUrl: input.baseUrl,
|
|
755
|
+
repoSlug: input.repoSlug,
|
|
756
|
+
message: `Could not validate remote project root ${candidate}: ${error instanceof Error ? error.message : String(error)}`
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
if (response.status === 401 || response.status === 403) {
|
|
760
|
+
return remoteProjectLinkFailure({
|
|
761
|
+
status: "auth_required",
|
|
762
|
+
alias: input.alias,
|
|
763
|
+
baseUrl: input.baseUrl,
|
|
764
|
+
repoSlug: input.repoSlug,
|
|
765
|
+
statusCode: response.status,
|
|
766
|
+
message: `Remote server ${input.alias} requires authentication before validating project root ${candidate}.`
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
if (!response.ok) {
|
|
770
|
+
return remoteProjectLinkFailure({
|
|
771
|
+
status: "invalid_root",
|
|
772
|
+
alias: input.alias,
|
|
773
|
+
baseUrl: input.baseUrl,
|
|
774
|
+
repoSlug: input.repoSlug,
|
|
775
|
+
statusCode: response.status,
|
|
776
|
+
message: `Remote server rejected project root ${candidate} (${response.status}): ${payloadError(response.payload, response.text || "project-root validation failed")}`
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
const record = response.payload && typeof response.payload === "object" && !Array.isArray(response.payload) ? response.payload : {};
|
|
780
|
+
if (record.ok !== true) {
|
|
781
|
+
return remoteProjectLinkFailure({
|
|
782
|
+
status: "invalid_root",
|
|
783
|
+
alias: input.alias,
|
|
784
|
+
baseUrl: input.baseUrl,
|
|
785
|
+
repoSlug: input.repoSlug,
|
|
786
|
+
message: `Remote server did not accept project root ${candidate}: ${payloadError(response.payload, "project-root validation failed")}`
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
const accepted = typeof record.projectRoot === "string" && record.projectRoot.trim() ? record.projectRoot.trim() : typeof record.requestedProjectRoot === "string" && record.requestedProjectRoot.trim() ? record.requestedProjectRoot.trim() : candidate;
|
|
790
|
+
writeRepoServerProjectRoot(input.projectRoot, accepted, { alias: input.alias, baseUrl: input.baseUrl, project: input.repoSlug });
|
|
791
|
+
writeProjectLinkConnection(input.projectRoot, input.repoSlug, input.alias);
|
|
792
|
+
const status = input.status ?? (input.prepared ? "prepared" : "backfilled");
|
|
793
|
+
return remoteProjectLinkSuccess({
|
|
794
|
+
status,
|
|
795
|
+
alias: input.alias,
|
|
796
|
+
baseUrl: input.baseUrl,
|
|
797
|
+
repoSlug: input.repoSlug,
|
|
798
|
+
serverProjectRoot: accepted,
|
|
799
|
+
source: input.source,
|
|
800
|
+
prepared: input.prepared,
|
|
801
|
+
validated: true,
|
|
802
|
+
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}.`
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
async function ensureRemoteProjectRootLink(projectRoot, options = {}) {
|
|
806
|
+
let selected;
|
|
807
|
+
try {
|
|
808
|
+
selected = resolveSelectedConnection(projectRoot);
|
|
809
|
+
} catch (error) {
|
|
810
|
+
return remoteProjectLinkFailure({ status: "error", message: error instanceof Error ? error.message : String(error) });
|
|
811
|
+
}
|
|
812
|
+
if (!selected || selected.connection.kind !== "remote") {
|
|
813
|
+
return remoteProjectLinkFailure({ status: "not_remote", message: "No remote Rig server is selected for this repo." });
|
|
814
|
+
}
|
|
815
|
+
const repo = readRepoConnection(projectRoot);
|
|
816
|
+
const explicitRepoRequested = options.repoSlug !== undefined;
|
|
817
|
+
const explicitRepoSlug = explicitRepoRequested ? normalizeRepoSlug(options.repoSlug) : null;
|
|
818
|
+
const repoProjectSlug = normalizeRepoSlug(repo?.project);
|
|
819
|
+
const repoSlug = explicitRepoSlug ?? repoProjectSlug ?? readProjectLinkSlug(projectRoot);
|
|
820
|
+
const alias = selected.alias;
|
|
821
|
+
const baseUrl = selected.connection.baseUrl;
|
|
822
|
+
const authToken = options.authToken === undefined ? readGitHubBearerTokenForRemote(projectRoot) : options.authToken;
|
|
823
|
+
const mode = options.mode ?? "backfill-only";
|
|
824
|
+
if (explicitRepoRequested && !explicitRepoSlug) {
|
|
825
|
+
return remoteProjectLinkFailure({
|
|
826
|
+
status: "missing_project",
|
|
827
|
+
alias,
|
|
828
|
+
baseUrl,
|
|
829
|
+
message: `Invalid --repo value ${JSON.stringify(options.repoSlug)}. Expected owner/repo.`
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
if (!repoSlug) {
|
|
833
|
+
return remoteProjectLinkFailure({
|
|
834
|
+
status: "missing_project",
|
|
835
|
+
alias,
|
|
836
|
+
baseUrl,
|
|
837
|
+
message: `Remote server ${alias} is selected, but this checkout has no GitHub repo slug recorded.`
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
const skippedCandidates = [];
|
|
841
|
+
const storedRoot = selected.serverProjectRoot?.trim() || null;
|
|
842
|
+
const storedRootMatchesResolvedRepo = repoProjectSlug === repoSlug;
|
|
843
|
+
if (storedRoot && storedRootMatchesResolvedRepo) {
|
|
844
|
+
if (localCheckoutPathCandidate(projectRoot, storedRoot)) {
|
|
845
|
+
clearRepoServerProjectRoot(projectRoot);
|
|
846
|
+
skippedCandidates.push(storedRoot);
|
|
847
|
+
} else {
|
|
848
|
+
const storedResult = await validateAndPersistRemoteRoot({
|
|
849
|
+
projectRoot,
|
|
850
|
+
alias,
|
|
851
|
+
baseUrl,
|
|
852
|
+
authToken,
|
|
853
|
+
repoSlug,
|
|
854
|
+
candidate: storedRoot,
|
|
855
|
+
source: "stored",
|
|
856
|
+
status: "ready"
|
|
857
|
+
});
|
|
858
|
+
if (storedResult.ok || storedResult.status === "auth_required" || storedResult.status === "error")
|
|
859
|
+
return storedResult;
|
|
860
|
+
clearRepoServerProjectRoot(projectRoot);
|
|
861
|
+
skippedCandidates.push(storedRoot);
|
|
862
|
+
}
|
|
863
|
+
} else if (storedRoot) {
|
|
864
|
+
skippedCandidates.push(storedRoot);
|
|
865
|
+
}
|
|
866
|
+
const authCandidate = inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug);
|
|
867
|
+
if (authCandidate) {
|
|
868
|
+
const authResult = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: authCandidate, source: "auth-state" });
|
|
869
|
+
if (authResult.ok || authResult.status === "auth_required")
|
|
870
|
+
return authResult;
|
|
871
|
+
}
|
|
872
|
+
let registryResponse;
|
|
873
|
+
try {
|
|
874
|
+
registryResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}`, authToken);
|
|
875
|
+
} catch (error) {
|
|
876
|
+
return remoteProjectLinkFailure({
|
|
877
|
+
status: "error",
|
|
878
|
+
alias,
|
|
879
|
+
baseUrl,
|
|
880
|
+
repoSlug,
|
|
881
|
+
message: `Could not read remote project registry for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
if (registryResponse.status === 401 || registryResponse.status === 403) {
|
|
885
|
+
return remoteProjectLinkFailure({
|
|
886
|
+
status: "auth_required",
|
|
887
|
+
alias,
|
|
888
|
+
baseUrl,
|
|
889
|
+
repoSlug,
|
|
890
|
+
statusCode: registryResponse.status,
|
|
891
|
+
message: `Remote server ${alias} requires authentication before reading the ${repoSlug} project registry.`
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
if (registryResponse.ok) {
|
|
895
|
+
const candidates = checkoutPathsFromProjectPayload(registryResponse.payload);
|
|
896
|
+
for (const candidate of candidates) {
|
|
897
|
+
const result = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate, source: "registry" });
|
|
898
|
+
if (result.ok || result.status === "auth_required")
|
|
899
|
+
return result;
|
|
900
|
+
skippedCandidates.push(candidate);
|
|
901
|
+
}
|
|
902
|
+
if (mode === "backfill-only") {
|
|
903
|
+
return remoteProjectLinkFailure({
|
|
904
|
+
status: candidates.length > 0 ? "invalid_root" : "no_server_checkout",
|
|
905
|
+
alias,
|
|
906
|
+
baseUrl,
|
|
907
|
+
repoSlug,
|
|
908
|
+
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.`,
|
|
909
|
+
skippedCandidates
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
} else if (registryResponse.status === 404) {
|
|
913
|
+
if (mode === "backfill-only") {
|
|
914
|
+
return remoteProjectLinkFailure({
|
|
915
|
+
status: "project_not_registered",
|
|
916
|
+
alias,
|
|
917
|
+
baseUrl,
|
|
918
|
+
repoSlug,
|
|
919
|
+
statusCode: registryResponse.status,
|
|
920
|
+
message: `Remote server ${alias} has no registered project record for ${repoSlug}.`
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
} else {
|
|
924
|
+
return remoteProjectLinkFailure({
|
|
925
|
+
status: "error",
|
|
926
|
+
alias,
|
|
927
|
+
baseUrl,
|
|
928
|
+
repoSlug,
|
|
929
|
+
statusCode: registryResponse.status,
|
|
930
|
+
message: `Could not backfill ${repoSlug} from remote registry (${registryResponse.status}): ${payloadError(registryResponse.payload, registryResponse.text || "registry lookup failed")}`,
|
|
931
|
+
skippedCandidates
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
let prepareResponse;
|
|
935
|
+
try {
|
|
936
|
+
prepareResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}/prepare-checkout`, authToken, {
|
|
937
|
+
method: "POST",
|
|
938
|
+
headers: { "content-type": "application/json" },
|
|
939
|
+
body: JSON.stringify({ checkout: { kind: "managed-clone" }, repoUrl: `https://github.com/${repoSlug}.git` })
|
|
940
|
+
});
|
|
941
|
+
} catch (error) {
|
|
942
|
+
return remoteProjectLinkFailure({
|
|
943
|
+
status: "error",
|
|
944
|
+
alias,
|
|
945
|
+
baseUrl,
|
|
946
|
+
repoSlug,
|
|
947
|
+
message: `Could not prepare remote checkout for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
if (prepareResponse.status === 401 || prepareResponse.status === 403) {
|
|
951
|
+
return remoteProjectLinkFailure({
|
|
952
|
+
status: "auth_required",
|
|
953
|
+
alias,
|
|
954
|
+
baseUrl,
|
|
955
|
+
repoSlug,
|
|
956
|
+
statusCode: prepareResponse.status,
|
|
957
|
+
message: `Remote server ${alias} requires authentication before preparing ${repoSlug}.`
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
if (!prepareResponse.ok) {
|
|
961
|
+
return remoteProjectLinkFailure({
|
|
962
|
+
status: "error",
|
|
963
|
+
alias,
|
|
964
|
+
baseUrl,
|
|
965
|
+
repoSlug,
|
|
966
|
+
statusCode: prepareResponse.status,
|
|
967
|
+
message: `Remote checkout prepare failed for ${repoSlug} (${prepareResponse.status}): ${payloadError(prepareResponse.payload, prepareResponse.text || "prepare-checkout failed")}`,
|
|
968
|
+
skippedCandidates
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
const preparedPath = checkoutPathFromPreparePayload(prepareResponse.payload);
|
|
972
|
+
if (!preparedPath) {
|
|
973
|
+
return remoteProjectLinkFailure({
|
|
974
|
+
status: "invalid_root",
|
|
975
|
+
alias,
|
|
976
|
+
baseUrl,
|
|
977
|
+
repoSlug,
|
|
978
|
+
message: `Remote checkout prepare for ${repoSlug} did not return a checkout.path.`,
|
|
979
|
+
skippedCandidates
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
return validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: preparedPath, source: "prepare", prepared: true });
|
|
983
|
+
}
|
|
553
984
|
async function ensureServerForCli(projectRoot) {
|
|
554
985
|
try {
|
|
555
986
|
const selected = resolveSelectedConnection(projectRoot);
|
|
556
987
|
if (selected?.connection.kind === "remote") {
|
|
557
988
|
reportServerPhase(`Connecting to ${selected.alias}\u2026`);
|
|
558
989
|
const authToken = readGitHubBearerTokenForRemote(projectRoot);
|
|
559
|
-
const
|
|
990
|
+
const link = await ensureRemoteProjectRootLink(projectRoot, { mode: "backfill-only", authToken });
|
|
560
991
|
return {
|
|
561
992
|
baseUrl: selected.connection.baseUrl,
|
|
562
993
|
authToken,
|
|
563
994
|
connectionKind: "remote",
|
|
564
|
-
serverProjectRoot
|
|
995
|
+
serverProjectRoot: link.ok ? link.serverProjectRoot ?? null : null
|
|
565
996
|
};
|
|
566
997
|
}
|
|
567
998
|
reportServerPhase("Starting local Rig server\u2026");
|
|
@@ -579,32 +1010,6 @@ async function ensureServerForCli(projectRoot) {
|
|
|
579
1010
|
throw error;
|
|
580
1011
|
}
|
|
581
1012
|
}
|
|
582
|
-
async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
|
|
583
|
-
const repo = readRepoConnection(projectRoot);
|
|
584
|
-
const slug = repo?.project?.trim();
|
|
585
|
-
if (!slug)
|
|
586
|
-
return null;
|
|
587
|
-
try {
|
|
588
|
-
const url = new URL(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`);
|
|
589
|
-
if (authToken && queryAuthFallbackEnabled())
|
|
590
|
-
url.searchParams.set("rt", authToken);
|
|
591
|
-
const response = await fetch(url, {
|
|
592
|
-
headers: mergeHeaders(undefined, authToken)
|
|
593
|
-
});
|
|
594
|
-
if (!response.ok)
|
|
595
|
-
return null;
|
|
596
|
-
const payload = await response.json();
|
|
597
|
-
const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
|
|
598
|
-
const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
|
|
599
|
-
const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
|
|
600
|
-
const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
|
|
601
|
-
if (path)
|
|
602
|
-
writeRepoServerProjectRoot(projectRoot, path);
|
|
603
|
-
return path;
|
|
604
|
-
} catch {
|
|
605
|
-
return null;
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
1013
|
function mergeCookie(existing, name, value) {
|
|
609
1014
|
const encoded = `${name}=${encodeURIComponent(value)}`;
|
|
610
1015
|
if (!existing?.trim())
|
|
@@ -696,13 +1101,20 @@ function canUseRemoteWithoutProjectRoot(pathname) {
|
|
|
696
1101
|
async function requestServerJson(context, pathname, init = {}) {
|
|
697
1102
|
const server = await ensureServerForCli(context.projectRoot);
|
|
698
1103
|
const requestUrl = new URL(`${server.baseUrl}${pathname}`);
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
1104
|
+
let scopedServerProjectRoot = server.serverProjectRoot;
|
|
1105
|
+
if (server.connectionKind === "remote" && !scopedServerProjectRoot && !canUseRemoteWithoutProjectRoot(requestUrl.pathname) && (server.authToken || !isLoopbackRemoteBaseUrl(server.baseUrl))) {
|
|
1106
|
+
const link = await ensureRemoteProjectRootLink(context.projectRoot, { mode: "backfill-only", authToken: server.authToken });
|
|
1107
|
+
if (link.ok && link.serverProjectRoot) {
|
|
1108
|
+
scopedServerProjectRoot = link.serverProjectRoot;
|
|
1109
|
+
} else {
|
|
1110
|
+
const repo = readRepoConnection(context.projectRoot);
|
|
1111
|
+
const target = link.alias && link.baseUrl ? `${link.alias} (${link.baseUrl})` : server.baseUrl;
|
|
1112
|
+
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 });
|
|
1113
|
+
}
|
|
702
1114
|
}
|
|
703
1115
|
const headers = mergeHeaders(init.headers, server.authToken);
|
|
704
|
-
if (
|
|
705
|
-
headers.set("x-rig-project-root",
|
|
1116
|
+
if (scopedServerProjectRoot)
|
|
1117
|
+
headers.set("x-rig-project-root", scopedServerProjectRoot);
|
|
706
1118
|
if (server.connectionKind === "remote" && server.authToken && queryAuthFallbackEnabled()) {
|
|
707
1119
|
requestUrl.searchParams.set("rt", server.authToken);
|
|
708
1120
|
}
|
|
@@ -1021,7 +1433,7 @@ async function buildPiSetupChecks(input = {}) {
|
|
|
1021
1433
|
|
|
1022
1434
|
// packages/cli/src/commands/_snapshot-upload.ts
|
|
1023
1435
|
import { mkdir, readdir, readFile, writeFile } from "fs/promises";
|
|
1024
|
-
import { dirname as
|
|
1436
|
+
import { dirname as dirname3, resolve as resolve4, relative, sep } from "path";
|
|
1025
1437
|
var SNAPSHOT_ARCHIVE_VERSION = 1;
|
|
1026
1438
|
var SNAPSHOT_ARCHIVE_CONTENT_TYPE = "application/vnd.rig.snapshot+json";
|
|
1027
1439
|
var DEFAULT_EXCLUDED_DIRECTORIES = new Set([
|
|
@@ -1369,14 +1781,14 @@ function parseRepoSlug(value) {
|
|
|
1369
1781
|
}
|
|
1370
1782
|
function ensureRigPrivateDirs(projectRoot) {
|
|
1371
1783
|
const rigDir = resolve6(projectRoot, ".rig");
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1784
|
+
mkdirSync3(resolve6(rigDir, "state"), { recursive: true });
|
|
1785
|
+
mkdirSync3(resolve6(rigDir, "logs"), { recursive: true });
|
|
1786
|
+
mkdirSync3(resolve6(rigDir, "runs"), { recursive: true });
|
|
1787
|
+
mkdirSync3(resolve6(rigDir, "tmp"), { recursive: true });
|
|
1788
|
+
mkdirSync3(resolve6(projectRoot, "artifacts"), { recursive: true });
|
|
1377
1789
|
const taskConfigPath = resolve6(rigDir, "task-config.json");
|
|
1378
1790
|
if (!existsSync5(taskConfigPath))
|
|
1379
|
-
|
|
1791
|
+
writeFileSync3(taskConfigPath, `{}
|
|
1380
1792
|
`, "utf-8");
|
|
1381
1793
|
}
|
|
1382
1794
|
function ensureGitignoreEntries(projectRoot) {
|
|
@@ -1404,7 +1816,7 @@ function ensureRigConfigPackageDependencies(projectRoot) {
|
|
|
1404
1816
|
...existsSync5(path) ? existing : { name: "rig-project", private: true },
|
|
1405
1817
|
devDependencies
|
|
1406
1818
|
};
|
|
1407
|
-
|
|
1819
|
+
writeFileSync3(path, `${JSON.stringify(next, null, 2)}
|
|
1408
1820
|
`, "utf8");
|
|
1409
1821
|
}
|
|
1410
1822
|
function applyGitHubProjectConfig(source, options) {
|
|
@@ -1430,9 +1842,9 @@ function checkoutForInit(projectRoot, serverKind, strategy) {
|
|
|
1430
1842
|
const selected = strategy ?? { kind: "managed-clone" };
|
|
1431
1843
|
switch (selected.kind) {
|
|
1432
1844
|
case "managed-clone":
|
|
1433
|
-
return { kind: "managed-clone"
|
|
1845
|
+
return { kind: "managed-clone" };
|
|
1434
1846
|
case "current-ref":
|
|
1435
|
-
return { kind: "current-ref",
|
|
1847
|
+
return { kind: "current-ref", ...selected.ref ? { ref: selected.ref } : {} };
|
|
1436
1848
|
case "uploaded-snapshot":
|
|
1437
1849
|
return { kind: "uploaded-snapshot", path: projectRoot, source: "local-working-tree" };
|
|
1438
1850
|
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") {
|
|
@@ -1823,7 +2235,7 @@ function runDemoInit(context, options) {
|
|
|
1823
2235
|
console.log("rig.config already exists; leaving it unchanged. Pass --repair to rewrite it for the demo.");
|
|
1824
2236
|
}
|
|
1825
2237
|
} else {
|
|
1826
|
-
|
|
2238
|
+
writeFileSync3(configTsPath, buildRigInitConfigSource({
|
|
1827
2239
|
projectName: basename(projectRoot) || "rig-demo",
|
|
1828
2240
|
taskSource: { kind: "files", path: DEMO_TASKS_RELATIVE_DIR },
|
|
1829
2241
|
useStandardPlugin: true
|
|
@@ -1832,14 +2244,14 @@ function runDemoInit(context, options) {
|
|
|
1832
2244
|
}
|
|
1833
2245
|
ensureRigConfigPackageDependencies(projectRoot);
|
|
1834
2246
|
const demoTasksDir = resolve6(projectRoot, DEMO_TASKS_RELATIVE_DIR);
|
|
1835
|
-
|
|
2247
|
+
mkdirSync3(demoTasksDir, { recursive: true });
|
|
1836
2248
|
const taskIds = [];
|
|
1837
2249
|
for (const task of DEMO_TASKS) {
|
|
1838
2250
|
const id = String(task.id);
|
|
1839
2251
|
taskIds.push(id);
|
|
1840
2252
|
const taskPath = resolve6(demoTasksDir, `${id}.json`);
|
|
1841
2253
|
if (!existsSync5(taskPath)) {
|
|
1842
|
-
|
|
2254
|
+
writeFileSync3(taskPath, `${JSON.stringify(task, null, 2)}
|
|
1843
2255
|
`, "utf-8");
|
|
1844
2256
|
}
|
|
1845
2257
|
}
|
|
@@ -1867,21 +2279,32 @@ function runDemoInit(context, options) {
|
|
|
1867
2279
|
}
|
|
1868
2280
|
async function runControlPlaneInit(context, options) {
|
|
1869
2281
|
const projectRoot = context.projectRoot;
|
|
1870
|
-
const
|
|
2282
|
+
const existingRepoConnection = readRepoConnection(projectRoot);
|
|
2283
|
+
const selectedConnection = (() => {
|
|
2284
|
+
try {
|
|
2285
|
+
return resolveSelectedConnection(projectRoot);
|
|
2286
|
+
} catch {
|
|
2287
|
+
return null;
|
|
2288
|
+
}
|
|
2289
|
+
})();
|
|
2290
|
+
const selectedRemote = selectedConnection?.connection.kind === "remote" ? { alias: selectedConnection.alias, connection: selectedConnection.connection } : null;
|
|
2291
|
+
const detectedSlug = options.repoSlug ?? existingRepoConnection?.project ?? detectOriginRepoSlug(projectRoot);
|
|
2292
|
+
const serverKind = options.server ?? (selectedRemote ? "remote" : "local");
|
|
1871
2293
|
if (!detectedSlug) {
|
|
1872
2294
|
const authMethod2 = options.githubAuthMethod ?? (options.githubToken ? "token" : "skip");
|
|
1873
|
-
if (
|
|
2295
|
+
if (serverKind === "local" && authMethod2 === "skip") {
|
|
1874
2296
|
return runLocalFilesInit(context, options);
|
|
1875
2297
|
}
|
|
1876
2298
|
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);
|
|
1877
2299
|
}
|
|
1878
2300
|
const repo = parseRepoSlug(detectedSlug);
|
|
1879
|
-
const
|
|
1880
|
-
const
|
|
2301
|
+
const connectionAlias = options.connectionAlias ?? (serverKind === "local" ? "local" : selectedRemote?.alias ?? "remote");
|
|
2302
|
+
const selectedRemoteUrl = selectedRemote && (!options.connectionAlias || options.connectionAlias === selectedRemote.alias) ? selectedRemote.connection.baseUrl : undefined;
|
|
2303
|
+
const remoteUrl = serverKind === "remote" ? (options.remoteUrl ?? selectedRemoteUrl)?.replace(/\/+$/, "") : undefined;
|
|
1881
2304
|
if (serverKind === "remote") {
|
|
1882
|
-
if (!
|
|
1883
|
-
throw new CliError("Missing --remote-url for --server remote.", 1, { hint: "Re-run as `rig init --server remote --remote-url https://your-rig-server
|
|
1884
|
-
upsertGlobalConnection(connectionAlias, { kind: "remote", baseUrl:
|
|
2305
|
+
if (!remoteUrl)
|
|
2306
|
+
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>`." });
|
|
2307
|
+
upsertGlobalConnection(connectionAlias, { kind: "remote", baseUrl: remoteUrl });
|
|
1885
2308
|
}
|
|
1886
2309
|
writeRepoConnection(projectRoot, {
|
|
1887
2310
|
selected: connectionAlias,
|
|
@@ -1904,11 +2327,11 @@ async function runControlPlaneInit(context, options) {
|
|
|
1904
2327
|
taskSource: { kind: "github-issues", owner: repo.owner, repo: repo.repo },
|
|
1905
2328
|
useStandardPlugin: true
|
|
1906
2329
|
}), options);
|
|
1907
|
-
|
|
2330
|
+
writeFileSync3(configTsPath, source, "utf-8");
|
|
1908
2331
|
}
|
|
1909
2332
|
ensureRigConfigPackageDependencies(projectRoot);
|
|
1910
2333
|
}
|
|
1911
|
-
|
|
2334
|
+
writeFileSync3(resolve6(projectRoot, ".rig", "state", "project-link.json"), `${JSON.stringify({ repoSlug: repo.slug, connection: connectionAlias, linkedAt: new Date().toISOString() }, null, 2)}
|
|
1912
2335
|
`, "utf8");
|
|
1913
2336
|
const checkout = checkoutForInit(projectRoot, serverKind, options.remoteCheckout);
|
|
1914
2337
|
let uploadedSnapshot = null;
|
|
@@ -1923,7 +2346,7 @@ async function runControlPlaneInit(context, options) {
|
|
|
1923
2346
|
let githubAuth = null;
|
|
1924
2347
|
let deviceAuth = null;
|
|
1925
2348
|
const authMethod = options.githubAuthMethod ?? (options.githubToken ? "token" : "skip");
|
|
1926
|
-
const remoteGhTokenWarning = serverKind === "remote" && authMethod === "gh" ? `This sends a GitHub token from this machine to ${
|
|
2349
|
+
const remoteGhTokenWarning = serverKind === "remote" && authMethod === "gh" ? `This sends a GitHub token from this machine to ${remoteUrl ?? "the remote Rig server"}.` : null;
|
|
1927
2350
|
if (remoteGhTokenWarning && !options.yes) {
|
|
1928
2351
|
throw new CliError(`${remoteGhTokenWarning} Re-run with --yes to confirm this explicit token transfer.`, 1);
|
|
1929
2352
|
}
|