@h-rig/cli 0.0.6-alpha.88 → 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 +1159 -292
- package/dist/src/app/board.js +462 -48
- package/dist/src/app-opentui/adapters/doctor.js +458 -46
- package/dist/src/app-opentui/adapters/family.js +670 -147
- 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.js +484 -53
- 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 +539 -81
- package/dist/src/app-opentui/autocomplete.js +4 -2
- package/dist/src/app-opentui/bootstrap.js +1155 -288
- package/dist/src/app-opentui/command-palette.js +37 -10
- package/dist/src/app-opentui/index.js +566 -89
- package/dist/src/app-opentui/intent.js +33 -8
- package/dist/src/app-opentui/keymap.js +43 -29
- package/dist/src/app-opentui/pi-host-child.js +465 -53
- package/dist/src/app-opentui/react/App.js +104 -44
- package/dist/src/app-opentui/react/ChromeHost.js +16 -4
- package/dist/src/app-opentui/react/launch.js +555 -88
- package/dist/src/app-opentui/react/nav.js +1 -1
- package/dist/src/app-opentui/registry.js +1062 -237
- 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/runtime.js +566 -89
- 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 +465 -53
- package/dist/src/commands/_pi-frontend.js +465 -53
- 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 +465 -53
- 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 +520 -81
- package/dist/src/commands.js +670 -147
- package/dist/src/index.js +674 -147
- package/dist/src/launcher.js +4 -0
- package/package.json +8 -8
|
@@ -384,12 +384,28 @@ function readRepoConnection(projectRoot) {
|
|
|
384
384
|
selected,
|
|
385
385
|
project: typeof record.project === "string" ? record.project : undefined,
|
|
386
386
|
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
|
|
387
|
-
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
387
|
+
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined,
|
|
388
|
+
serverProjectRootAlias: typeof record.serverProjectRootAlias === "string" && record.serverProjectRootAlias.trim() ? record.serverProjectRootAlias.trim() : undefined,
|
|
389
|
+
serverProjectRootBaseUrl: typeof record.serverProjectRootBaseUrl === "string" && record.serverProjectRootBaseUrl.trim() ? record.serverProjectRootBaseUrl.trim().replace(/\/+$/, "") : undefined
|
|
388
390
|
};
|
|
389
391
|
}
|
|
390
392
|
function writeRepoConnection(projectRoot, state) {
|
|
391
393
|
writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
|
|
392
394
|
}
|
|
395
|
+
function rootAllowedForSelection(repo, connection) {
|
|
396
|
+
const root = repo.serverProjectRoot?.trim();
|
|
397
|
+
if (!root)
|
|
398
|
+
return;
|
|
399
|
+
if (connection.kind === "remote") {
|
|
400
|
+
if (repo.serverProjectRootAlias !== repo.selected)
|
|
401
|
+
return;
|
|
402
|
+
if (repo.serverProjectRootBaseUrl !== connection.baseUrl)
|
|
403
|
+
return;
|
|
404
|
+
} else if (repo.serverProjectRootAlias && repo.serverProjectRootAlias !== repo.selected) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
return root;
|
|
408
|
+
}
|
|
393
409
|
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
394
410
|
const repo = readRepoConnection(projectRoot);
|
|
395
411
|
if (!repo)
|
|
@@ -401,18 +417,46 @@ function resolveSelectedConnection(projectRoot, options = {}) {
|
|
|
401
417
|
if (!connection) {
|
|
402
418
|
throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
403
419
|
}
|
|
404
|
-
return { alias: repo.selected, connection, serverProjectRoot: repo
|
|
420
|
+
return { alias: repo.selected, connection, serverProjectRoot: rootAllowedForSelection(repo, connection) };
|
|
421
|
+
}
|
|
422
|
+
function writeRepoServerProjectRoot(projectRoot, serverProjectRoot, metadata = {}) {
|
|
423
|
+
const repo = readRepoConnection(projectRoot);
|
|
424
|
+
if (!repo)
|
|
425
|
+
return;
|
|
426
|
+
let inferred = metadata;
|
|
427
|
+
if (!inferred.alias || !inferred.baseUrl) {
|
|
428
|
+
try {
|
|
429
|
+
const selected = resolveSelectedConnection(projectRoot);
|
|
430
|
+
if (selected?.connection.kind === "remote") {
|
|
431
|
+
inferred = {
|
|
432
|
+
alias: inferred.alias ?? selected.alias,
|
|
433
|
+
baseUrl: inferred.baseUrl ?? selected.connection.baseUrl
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
} catch {}
|
|
437
|
+
}
|
|
438
|
+
writeRepoConnection(projectRoot, {
|
|
439
|
+
...repo,
|
|
440
|
+
...metadata.project ? { project: metadata.project } : {},
|
|
441
|
+
serverProjectRoot,
|
|
442
|
+
...inferred.alias ? { serverProjectRootAlias: inferred.alias } : {},
|
|
443
|
+
...inferred.baseUrl ? { serverProjectRootBaseUrl: inferred.baseUrl.replace(/\/+$/, "") } : {}
|
|
444
|
+
});
|
|
405
445
|
}
|
|
406
|
-
function
|
|
446
|
+
function clearRepoServerProjectRoot(projectRoot) {
|
|
407
447
|
const repo = readRepoConnection(projectRoot);
|
|
408
448
|
if (!repo)
|
|
409
449
|
return;
|
|
410
|
-
writeRepoConnection(projectRoot, {
|
|
450
|
+
writeRepoConnection(projectRoot, {
|
|
451
|
+
selected: repo.selected,
|
|
452
|
+
...repo.project ? { project: repo.project } : {},
|
|
453
|
+
...repo.linkedAt ? { linkedAt: repo.linkedAt } : {}
|
|
454
|
+
});
|
|
411
455
|
}
|
|
412
456
|
|
|
413
457
|
// packages/cli/src/commands/_server-client.ts
|
|
414
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
415
|
-
import { resolve as resolve2 } from "path";
|
|
458
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
459
|
+
import { dirname as dirname2, isAbsolute, resolve as resolve2 } from "path";
|
|
416
460
|
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
417
461
|
var scopedGitHubBearerTokens = new Map;
|
|
418
462
|
var serverPhaseListener = null;
|
|
@@ -456,11 +500,10 @@ function readStoredGitHubAuthToken(projectRoot) {
|
|
|
456
500
|
const parsed = readRemoteAuthState(projectRoot);
|
|
457
501
|
return parsed ? cleanToken(typeof parsed.token === "string" ? parsed.token : undefined) : null;
|
|
458
502
|
}
|
|
459
|
-
function
|
|
460
|
-
|
|
461
|
-
const slug = repo?.project?.trim();
|
|
462
|
-
if (!slug || !/^[^/]+\/[^/]+$/.test(slug))
|
|
503
|
+
function inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug) {
|
|
504
|
+
if (!/^[^/]+\/[^/]+$/.test(repoSlug))
|
|
463
505
|
return null;
|
|
506
|
+
const repo = readRepoConnection(projectRoot);
|
|
464
507
|
const auth = readRemoteAuthState(projectRoot);
|
|
465
508
|
const authUpdatedAt = typeof auth?.updatedAt === "string" ? Date.parse(auth.updatedAt) : Number.NaN;
|
|
466
509
|
const repoLinkedAt = typeof repo?.linkedAt === "string" ? Date.parse(repo.linkedAt) : Number.NaN;
|
|
@@ -469,25 +512,413 @@ function inferRemoteServerProjectRootFromAuthState(projectRoot) {
|
|
|
469
512
|
const checkoutBaseDir = typeof auth?.checkoutBaseDir === "string" && auth.checkoutBaseDir.trim() ? auth.checkoutBaseDir.trim() : null;
|
|
470
513
|
if (!checkoutBaseDir)
|
|
471
514
|
return null;
|
|
472
|
-
|
|
473
|
-
writeRepoServerProjectRoot(projectRoot, inferred);
|
|
474
|
-
return inferred;
|
|
515
|
+
return `${checkoutBaseDir.replace(/\/+$/, "")}/${repoSlug}`;
|
|
475
516
|
}
|
|
476
517
|
function readLocalConnectionFallbackToken(projectRoot) {
|
|
477
518
|
return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
|
|
478
519
|
}
|
|
520
|
+
function normalizeRepoSlug(value) {
|
|
521
|
+
const slug = value?.trim();
|
|
522
|
+
return slug && /^[^/\s]+\/[^/\s]+$/.test(slug) ? slug : null;
|
|
523
|
+
}
|
|
524
|
+
function readProjectLinkSlug(projectRoot) {
|
|
525
|
+
const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
|
|
526
|
+
if (!existsSync2(path))
|
|
527
|
+
return null;
|
|
528
|
+
try {
|
|
529
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
530
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
531
|
+
return null;
|
|
532
|
+
return normalizeRepoSlug(typeof parsed.repoSlug === "string" ? String(parsed.repoSlug) : null);
|
|
533
|
+
} catch {
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
function writeProjectLinkConnection(projectRoot, repoSlug, alias) {
|
|
538
|
+
const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
|
|
539
|
+
mkdirSync2(dirname2(path), { recursive: true });
|
|
540
|
+
writeFileSync2(path, `${JSON.stringify({ repoSlug, connection: alias, linkedAt: new Date().toISOString() }, null, 2)}
|
|
541
|
+
`, "utf8");
|
|
542
|
+
}
|
|
543
|
+
function remoteLinkRepairCommand(repoSlug) {
|
|
544
|
+
return repoSlug ? `rig server repair-link --repo ${repoSlug}` : "rig server repair-link --repo owner/repo";
|
|
545
|
+
}
|
|
546
|
+
function formatRemoteProjectLinkHint(resolution) {
|
|
547
|
+
const repair = remoteLinkRepairCommand(resolution.repoSlug);
|
|
548
|
+
if (resolution.status === "auth_required") {
|
|
549
|
+
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}` : ""}\`.`;
|
|
550
|
+
}
|
|
551
|
+
if (resolution.status === "missing_project") {
|
|
552
|
+
return `Record the repo slug, then run \`${repair}\` (or \`rig init --repo owner/repo --server remote --github-auth device\`).`;
|
|
553
|
+
}
|
|
554
|
+
if (resolution.status === "not_remote")
|
|
555
|
+
return "Select a remote server with `rig server use <alias>` before repairing a remote project link.";
|
|
556
|
+
return `Run \`${repair}\` to backfill or prepare a server-host checkout for the selected remote${resolution.alias ? ` (${resolution.alias})` : ""}.`;
|
|
557
|
+
}
|
|
558
|
+
function remoteProjectLinkFailure(input) {
|
|
559
|
+
const partial = {
|
|
560
|
+
status: input.status,
|
|
561
|
+
alias: input.alias,
|
|
562
|
+
baseUrl: input.baseUrl,
|
|
563
|
+
repoSlug: input.repoSlug
|
|
564
|
+
};
|
|
565
|
+
return {
|
|
566
|
+
ok: false,
|
|
567
|
+
...input,
|
|
568
|
+
hint: formatRemoteProjectLinkHint(partial),
|
|
569
|
+
next: remoteLinkRepairCommand(input.repoSlug)
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
function remoteProjectLinkSuccess(input) {
|
|
573
|
+
return {
|
|
574
|
+
ok: true,
|
|
575
|
+
status: input.status,
|
|
576
|
+
alias: input.alias,
|
|
577
|
+
baseUrl: input.baseUrl,
|
|
578
|
+
repoSlug: input.repoSlug,
|
|
579
|
+
serverProjectRoot: input.serverProjectRoot,
|
|
580
|
+
source: input.source,
|
|
581
|
+
prepared: input.prepared ?? input.status === "prepared",
|
|
582
|
+
validated: input.validated ?? false,
|
|
583
|
+
message: input.message ?? `Remote project link ready for ${input.repoSlug}.`,
|
|
584
|
+
hint: "Remote-scoped task/run/status requests will send x-rig-project-root for this server-host checkout.",
|
|
585
|
+
next: "rig task list"
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
function localCheckoutPathCandidate(projectRoot, candidate) {
|
|
589
|
+
try {
|
|
590
|
+
const local = resolve2(projectRoot);
|
|
591
|
+
const resolved = resolve2(candidate);
|
|
592
|
+
return resolved === local || resolved.startsWith(`${local}/`);
|
|
593
|
+
} catch {
|
|
594
|
+
return false;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
async function requestRemoteProjectLinkJson(baseUrl, pathname, authToken, init = {}) {
|
|
598
|
+
const requestUrl = new URL(`${baseUrl}${pathname}`);
|
|
599
|
+
if (authToken && queryAuthFallbackEnabled())
|
|
600
|
+
requestUrl.searchParams.set("rt", authToken);
|
|
601
|
+
const response = await fetch(requestUrl, {
|
|
602
|
+
...init,
|
|
603
|
+
headers: mergeHeaders(init.headers, authToken)
|
|
604
|
+
});
|
|
605
|
+
const text = await response.text();
|
|
606
|
+
const payload = text.trim().length > 0 ? (() => {
|
|
607
|
+
try {
|
|
608
|
+
return JSON.parse(text);
|
|
609
|
+
} catch {
|
|
610
|
+
return null;
|
|
611
|
+
}
|
|
612
|
+
})() : null;
|
|
613
|
+
return { ok: response.ok, status: response.status, payload, text };
|
|
614
|
+
}
|
|
615
|
+
function payloadError(payload, fallback) {
|
|
616
|
+
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
617
|
+
const record = payload;
|
|
618
|
+
const value = record.error ?? record.message ?? record.reason;
|
|
619
|
+
if (typeof value === "string" && value.trim())
|
|
620
|
+
return value.trim();
|
|
621
|
+
}
|
|
622
|
+
return fallback;
|
|
623
|
+
}
|
|
624
|
+
function checkoutPathsFromProjectPayload(payload) {
|
|
625
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
626
|
+
return [];
|
|
627
|
+
const project = payload.project;
|
|
628
|
+
if (!project || typeof project !== "object" || Array.isArray(project))
|
|
629
|
+
return [];
|
|
630
|
+
const checkouts = project.checkouts;
|
|
631
|
+
if (!Array.isArray(checkouts))
|
|
632
|
+
return [];
|
|
633
|
+
return [...checkouts].reverse().flatMap((entry) => {
|
|
634
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
635
|
+
return [];
|
|
636
|
+
const path = entry.path;
|
|
637
|
+
return typeof path === "string" && path.trim() ? [path.trim()] : [];
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
function checkoutPathFromPreparePayload(payload) {
|
|
641
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
642
|
+
return null;
|
|
643
|
+
const checkout = payload.checkout;
|
|
644
|
+
if (!checkout || typeof checkout !== "object" || Array.isArray(checkout))
|
|
645
|
+
return null;
|
|
646
|
+
const path = checkout.path;
|
|
647
|
+
return typeof path === "string" && path.trim() ? path.trim() : null;
|
|
648
|
+
}
|
|
649
|
+
async function validateAndPersistRemoteRoot(input) {
|
|
650
|
+
const candidate = input.candidate.trim();
|
|
651
|
+
if (!candidate || !isAbsolute(candidate)) {
|
|
652
|
+
return remoteProjectLinkFailure({
|
|
653
|
+
status: "invalid_root",
|
|
654
|
+
alias: input.alias,
|
|
655
|
+
baseUrl: input.baseUrl,
|
|
656
|
+
repoSlug: input.repoSlug,
|
|
657
|
+
message: `Remote project root candidate is not an absolute server-host path: ${candidate || "(empty)"}.`
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
if (localCheckoutPathCandidate(input.projectRoot, candidate)) {
|
|
661
|
+
return remoteProjectLinkFailure({
|
|
662
|
+
status: "invalid_root",
|
|
663
|
+
alias: input.alias,
|
|
664
|
+
baseUrl: input.baseUrl,
|
|
665
|
+
repoSlug: input.repoSlug,
|
|
666
|
+
message: `Refusing to use local checkout path ${candidate} as a remote server project root.`
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
let response;
|
|
670
|
+
try {
|
|
671
|
+
response = await requestRemoteProjectLinkJson(input.baseUrl, "/api/server/project-root", input.authToken, {
|
|
672
|
+
method: "POST",
|
|
673
|
+
headers: { "content-type": "application/json" },
|
|
674
|
+
body: JSON.stringify({ projectRoot: candidate })
|
|
675
|
+
});
|
|
676
|
+
} catch (error) {
|
|
677
|
+
return remoteProjectLinkFailure({
|
|
678
|
+
status: "error",
|
|
679
|
+
alias: input.alias,
|
|
680
|
+
baseUrl: input.baseUrl,
|
|
681
|
+
repoSlug: input.repoSlug,
|
|
682
|
+
message: `Could not validate remote project root ${candidate}: ${error instanceof Error ? error.message : String(error)}`
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
if (response.status === 401 || response.status === 403) {
|
|
686
|
+
return remoteProjectLinkFailure({
|
|
687
|
+
status: "auth_required",
|
|
688
|
+
alias: input.alias,
|
|
689
|
+
baseUrl: input.baseUrl,
|
|
690
|
+
repoSlug: input.repoSlug,
|
|
691
|
+
statusCode: response.status,
|
|
692
|
+
message: `Remote server ${input.alias} requires authentication before validating project root ${candidate}.`
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
if (!response.ok) {
|
|
696
|
+
return remoteProjectLinkFailure({
|
|
697
|
+
status: "invalid_root",
|
|
698
|
+
alias: input.alias,
|
|
699
|
+
baseUrl: input.baseUrl,
|
|
700
|
+
repoSlug: input.repoSlug,
|
|
701
|
+
statusCode: response.status,
|
|
702
|
+
message: `Remote server rejected project root ${candidate} (${response.status}): ${payloadError(response.payload, response.text || "project-root validation failed")}`
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
const record = response.payload && typeof response.payload === "object" && !Array.isArray(response.payload) ? response.payload : {};
|
|
706
|
+
if (record.ok !== true) {
|
|
707
|
+
return remoteProjectLinkFailure({
|
|
708
|
+
status: "invalid_root",
|
|
709
|
+
alias: input.alias,
|
|
710
|
+
baseUrl: input.baseUrl,
|
|
711
|
+
repoSlug: input.repoSlug,
|
|
712
|
+
message: `Remote server did not accept project root ${candidate}: ${payloadError(response.payload, "project-root validation failed")}`
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
const accepted = typeof record.projectRoot === "string" && record.projectRoot.trim() ? record.projectRoot.trim() : typeof record.requestedProjectRoot === "string" && record.requestedProjectRoot.trim() ? record.requestedProjectRoot.trim() : candidate;
|
|
716
|
+
writeRepoServerProjectRoot(input.projectRoot, accepted, { alias: input.alias, baseUrl: input.baseUrl, project: input.repoSlug });
|
|
717
|
+
writeProjectLinkConnection(input.projectRoot, input.repoSlug, input.alias);
|
|
718
|
+
const status = input.status ?? (input.prepared ? "prepared" : "backfilled");
|
|
719
|
+
return remoteProjectLinkSuccess({
|
|
720
|
+
status,
|
|
721
|
+
alias: input.alias,
|
|
722
|
+
baseUrl: input.baseUrl,
|
|
723
|
+
repoSlug: input.repoSlug,
|
|
724
|
+
serverProjectRoot: accepted,
|
|
725
|
+
source: input.source,
|
|
726
|
+
prepared: input.prepared,
|
|
727
|
+
validated: true,
|
|
728
|
+
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}.`
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
async function ensureRemoteProjectRootLink(projectRoot, options = {}) {
|
|
732
|
+
let selected;
|
|
733
|
+
try {
|
|
734
|
+
selected = resolveSelectedConnection(projectRoot);
|
|
735
|
+
} catch (error) {
|
|
736
|
+
return remoteProjectLinkFailure({ status: "error", message: error instanceof Error ? error.message : String(error) });
|
|
737
|
+
}
|
|
738
|
+
if (!selected || selected.connection.kind !== "remote") {
|
|
739
|
+
return remoteProjectLinkFailure({ status: "not_remote", message: "No remote Rig server is selected for this repo." });
|
|
740
|
+
}
|
|
741
|
+
const repo = readRepoConnection(projectRoot);
|
|
742
|
+
const explicitRepoRequested = options.repoSlug !== undefined;
|
|
743
|
+
const explicitRepoSlug = explicitRepoRequested ? normalizeRepoSlug(options.repoSlug) : null;
|
|
744
|
+
const repoProjectSlug = normalizeRepoSlug(repo?.project);
|
|
745
|
+
const repoSlug = explicitRepoSlug ?? repoProjectSlug ?? readProjectLinkSlug(projectRoot);
|
|
746
|
+
const alias = selected.alias;
|
|
747
|
+
const baseUrl = selected.connection.baseUrl;
|
|
748
|
+
const authToken = options.authToken === undefined ? readGitHubBearerTokenForRemote(projectRoot) : options.authToken;
|
|
749
|
+
const mode = options.mode ?? "backfill-only";
|
|
750
|
+
if (explicitRepoRequested && !explicitRepoSlug) {
|
|
751
|
+
return remoteProjectLinkFailure({
|
|
752
|
+
status: "missing_project",
|
|
753
|
+
alias,
|
|
754
|
+
baseUrl,
|
|
755
|
+
message: `Invalid --repo value ${JSON.stringify(options.repoSlug)}. Expected owner/repo.`
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
if (!repoSlug) {
|
|
759
|
+
return remoteProjectLinkFailure({
|
|
760
|
+
status: "missing_project",
|
|
761
|
+
alias,
|
|
762
|
+
baseUrl,
|
|
763
|
+
message: `Remote server ${alias} is selected, but this checkout has no GitHub repo slug recorded.`
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
const skippedCandidates = [];
|
|
767
|
+
const storedRoot = selected.serverProjectRoot?.trim() || null;
|
|
768
|
+
const storedRootMatchesResolvedRepo = repoProjectSlug === repoSlug;
|
|
769
|
+
if (storedRoot && storedRootMatchesResolvedRepo) {
|
|
770
|
+
if (localCheckoutPathCandidate(projectRoot, storedRoot)) {
|
|
771
|
+
clearRepoServerProjectRoot(projectRoot);
|
|
772
|
+
skippedCandidates.push(storedRoot);
|
|
773
|
+
} else {
|
|
774
|
+
const storedResult = await validateAndPersistRemoteRoot({
|
|
775
|
+
projectRoot,
|
|
776
|
+
alias,
|
|
777
|
+
baseUrl,
|
|
778
|
+
authToken,
|
|
779
|
+
repoSlug,
|
|
780
|
+
candidate: storedRoot,
|
|
781
|
+
source: "stored",
|
|
782
|
+
status: "ready"
|
|
783
|
+
});
|
|
784
|
+
if (storedResult.ok || storedResult.status === "auth_required" || storedResult.status === "error")
|
|
785
|
+
return storedResult;
|
|
786
|
+
clearRepoServerProjectRoot(projectRoot);
|
|
787
|
+
skippedCandidates.push(storedRoot);
|
|
788
|
+
}
|
|
789
|
+
} else if (storedRoot) {
|
|
790
|
+
skippedCandidates.push(storedRoot);
|
|
791
|
+
}
|
|
792
|
+
const authCandidate = inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug);
|
|
793
|
+
if (authCandidate) {
|
|
794
|
+
const authResult = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: authCandidate, source: "auth-state" });
|
|
795
|
+
if (authResult.ok || authResult.status === "auth_required")
|
|
796
|
+
return authResult;
|
|
797
|
+
}
|
|
798
|
+
let registryResponse;
|
|
799
|
+
try {
|
|
800
|
+
registryResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}`, authToken);
|
|
801
|
+
} catch (error) {
|
|
802
|
+
return remoteProjectLinkFailure({
|
|
803
|
+
status: "error",
|
|
804
|
+
alias,
|
|
805
|
+
baseUrl,
|
|
806
|
+
repoSlug,
|
|
807
|
+
message: `Could not read remote project registry for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
if (registryResponse.status === 401 || registryResponse.status === 403) {
|
|
811
|
+
return remoteProjectLinkFailure({
|
|
812
|
+
status: "auth_required",
|
|
813
|
+
alias,
|
|
814
|
+
baseUrl,
|
|
815
|
+
repoSlug,
|
|
816
|
+
statusCode: registryResponse.status,
|
|
817
|
+
message: `Remote server ${alias} requires authentication before reading the ${repoSlug} project registry.`
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
if (registryResponse.ok) {
|
|
821
|
+
const candidates = checkoutPathsFromProjectPayload(registryResponse.payload);
|
|
822
|
+
for (const candidate of candidates) {
|
|
823
|
+
const result = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate, source: "registry" });
|
|
824
|
+
if (result.ok || result.status === "auth_required")
|
|
825
|
+
return result;
|
|
826
|
+
skippedCandidates.push(candidate);
|
|
827
|
+
}
|
|
828
|
+
if (mode === "backfill-only") {
|
|
829
|
+
return remoteProjectLinkFailure({
|
|
830
|
+
status: candidates.length > 0 ? "invalid_root" : "no_server_checkout",
|
|
831
|
+
alias,
|
|
832
|
+
baseUrl,
|
|
833
|
+
repoSlug,
|
|
834
|
+
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.`,
|
|
835
|
+
skippedCandidates
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
} else if (registryResponse.status === 404) {
|
|
839
|
+
if (mode === "backfill-only") {
|
|
840
|
+
return remoteProjectLinkFailure({
|
|
841
|
+
status: "project_not_registered",
|
|
842
|
+
alias,
|
|
843
|
+
baseUrl,
|
|
844
|
+
repoSlug,
|
|
845
|
+
statusCode: registryResponse.status,
|
|
846
|
+
message: `Remote server ${alias} has no registered project record for ${repoSlug}.`
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
} else {
|
|
850
|
+
return remoteProjectLinkFailure({
|
|
851
|
+
status: "error",
|
|
852
|
+
alias,
|
|
853
|
+
baseUrl,
|
|
854
|
+
repoSlug,
|
|
855
|
+
statusCode: registryResponse.status,
|
|
856
|
+
message: `Could not backfill ${repoSlug} from remote registry (${registryResponse.status}): ${payloadError(registryResponse.payload, registryResponse.text || "registry lookup failed")}`,
|
|
857
|
+
skippedCandidates
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
let prepareResponse;
|
|
861
|
+
try {
|
|
862
|
+
prepareResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}/prepare-checkout`, authToken, {
|
|
863
|
+
method: "POST",
|
|
864
|
+
headers: { "content-type": "application/json" },
|
|
865
|
+
body: JSON.stringify({ checkout: { kind: "managed-clone" }, repoUrl: `https://github.com/${repoSlug}.git` })
|
|
866
|
+
});
|
|
867
|
+
} catch (error) {
|
|
868
|
+
return remoteProjectLinkFailure({
|
|
869
|
+
status: "error",
|
|
870
|
+
alias,
|
|
871
|
+
baseUrl,
|
|
872
|
+
repoSlug,
|
|
873
|
+
message: `Could not prepare remote checkout for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
if (prepareResponse.status === 401 || prepareResponse.status === 403) {
|
|
877
|
+
return remoteProjectLinkFailure({
|
|
878
|
+
status: "auth_required",
|
|
879
|
+
alias,
|
|
880
|
+
baseUrl,
|
|
881
|
+
repoSlug,
|
|
882
|
+
statusCode: prepareResponse.status,
|
|
883
|
+
message: `Remote server ${alias} requires authentication before preparing ${repoSlug}.`
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
if (!prepareResponse.ok) {
|
|
887
|
+
return remoteProjectLinkFailure({
|
|
888
|
+
status: "error",
|
|
889
|
+
alias,
|
|
890
|
+
baseUrl,
|
|
891
|
+
repoSlug,
|
|
892
|
+
statusCode: prepareResponse.status,
|
|
893
|
+
message: `Remote checkout prepare failed for ${repoSlug} (${prepareResponse.status}): ${payloadError(prepareResponse.payload, prepareResponse.text || "prepare-checkout failed")}`,
|
|
894
|
+
skippedCandidates
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
const preparedPath = checkoutPathFromPreparePayload(prepareResponse.payload);
|
|
898
|
+
if (!preparedPath) {
|
|
899
|
+
return remoteProjectLinkFailure({
|
|
900
|
+
status: "invalid_root",
|
|
901
|
+
alias,
|
|
902
|
+
baseUrl,
|
|
903
|
+
repoSlug,
|
|
904
|
+
message: `Remote checkout prepare for ${repoSlug} did not return a checkout.path.`,
|
|
905
|
+
skippedCandidates
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
return validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: preparedPath, source: "prepare", prepared: true });
|
|
909
|
+
}
|
|
479
910
|
async function ensureServerForCli(projectRoot) {
|
|
480
911
|
try {
|
|
481
912
|
const selected = resolveSelectedConnection(projectRoot);
|
|
482
913
|
if (selected?.connection.kind === "remote") {
|
|
483
914
|
reportServerPhase(`Connecting to ${selected.alias}\u2026`);
|
|
484
915
|
const authToken = readGitHubBearerTokenForRemote(projectRoot);
|
|
485
|
-
const
|
|
916
|
+
const link = await ensureRemoteProjectRootLink(projectRoot, { mode: "backfill-only", authToken });
|
|
486
917
|
return {
|
|
487
918
|
baseUrl: selected.connection.baseUrl,
|
|
488
919
|
authToken,
|
|
489
920
|
connectionKind: "remote",
|
|
490
|
-
serverProjectRoot
|
|
921
|
+
serverProjectRoot: link.ok ? link.serverProjectRoot ?? null : null
|
|
491
922
|
};
|
|
492
923
|
}
|
|
493
924
|
reportServerPhase("Starting local Rig server\u2026");
|
|
@@ -505,32 +936,6 @@ async function ensureServerForCli(projectRoot) {
|
|
|
505
936
|
throw error;
|
|
506
937
|
}
|
|
507
938
|
}
|
|
508
|
-
async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
|
|
509
|
-
const repo = readRepoConnection(projectRoot);
|
|
510
|
-
const slug = repo?.project?.trim();
|
|
511
|
-
if (!slug)
|
|
512
|
-
return null;
|
|
513
|
-
try {
|
|
514
|
-
const url = new URL(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`);
|
|
515
|
-
if (authToken && queryAuthFallbackEnabled())
|
|
516
|
-
url.searchParams.set("rt", authToken);
|
|
517
|
-
const response = await fetch(url, {
|
|
518
|
-
headers: mergeHeaders(undefined, authToken)
|
|
519
|
-
});
|
|
520
|
-
if (!response.ok)
|
|
521
|
-
return null;
|
|
522
|
-
const payload = await response.json();
|
|
523
|
-
const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
|
|
524
|
-
const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
|
|
525
|
-
const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
|
|
526
|
-
const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
|
|
527
|
-
if (path)
|
|
528
|
-
writeRepoServerProjectRoot(projectRoot, path);
|
|
529
|
-
return path;
|
|
530
|
-
} catch {
|
|
531
|
-
return null;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
939
|
function appendTaskFilterParams(url, filters) {
|
|
535
940
|
if (filters.assignee)
|
|
536
941
|
url.searchParams.set("assignee", filters.assignee);
|
|
@@ -632,13 +1037,20 @@ function canUseRemoteWithoutProjectRoot(pathname) {
|
|
|
632
1037
|
async function requestServerJson(context, pathname, init = {}) {
|
|
633
1038
|
const server = await ensureServerForCli(context.projectRoot);
|
|
634
1039
|
const requestUrl = new URL(`${server.baseUrl}${pathname}`);
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
1040
|
+
let scopedServerProjectRoot = server.serverProjectRoot;
|
|
1041
|
+
if (server.connectionKind === "remote" && !scopedServerProjectRoot && !canUseRemoteWithoutProjectRoot(requestUrl.pathname) && (server.authToken || !isLoopbackRemoteBaseUrl(server.baseUrl))) {
|
|
1042
|
+
const link = await ensureRemoteProjectRootLink(context.projectRoot, { mode: "backfill-only", authToken: server.authToken });
|
|
1043
|
+
if (link.ok && link.serverProjectRoot) {
|
|
1044
|
+
scopedServerProjectRoot = link.serverProjectRoot;
|
|
1045
|
+
} else {
|
|
1046
|
+
const repo = readRepoConnection(context.projectRoot);
|
|
1047
|
+
const target = link.alias && link.baseUrl ? `${link.alias} (${link.baseUrl})` : server.baseUrl;
|
|
1048
|
+
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 });
|
|
1049
|
+
}
|
|
638
1050
|
}
|
|
639
1051
|
const headers = mergeHeaders(init.headers, server.authToken);
|
|
640
|
-
if (
|
|
641
|
-
headers.set("x-rig-project-root",
|
|
1052
|
+
if (scopedServerProjectRoot)
|
|
1053
|
+
headers.set("x-rig-project-root", scopedServerProjectRoot);
|
|
642
1054
|
if (server.connectionKind === "remote" && server.authToken && queryAuthFallbackEnabled()) {
|
|
643
1055
|
requestUrl.searchParams.set("rt", server.authToken);
|
|
644
1056
|
}
|
|
@@ -849,6 +1261,14 @@ function permissionAllowsPr(payload) {
|
|
|
849
1261
|
function isNotFoundError(error) {
|
|
850
1262
|
return /\b(404|not found)\b/i.test(message(error));
|
|
851
1263
|
}
|
|
1264
|
+
function isLoopbackBaseUrl(baseUrl) {
|
|
1265
|
+
try {
|
|
1266
|
+
const host = new URL(baseUrl).hostname.toLowerCase();
|
|
1267
|
+
return host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]";
|
|
1268
|
+
} catch {
|
|
1269
|
+
return false;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
852
1272
|
function projectCheckoutReady(payload) {
|
|
853
1273
|
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
854
1274
|
return null;
|
|
@@ -903,25 +1323,37 @@ async function runFastTaskRunPreflight(context, options = {}) {
|
|
|
903
1323
|
}
|
|
904
1324
|
const repo = readRepoConnection(context.projectRoot);
|
|
905
1325
|
const remoteWithoutProjectLink = selectedServer?.connectionKind === "remote" && !repo?.project;
|
|
906
|
-
|
|
1326
|
+
let remoteRootBlocked = false;
|
|
1327
|
+
checks.push(repo ? preflightCheck("project-link", "project linked to selected server", repo.project ? "pass" : remoteWithoutProjectLink ? "fail" : "warn", `${repo.selected}${repo.project ? ` -> ${repo.project}` : " (missing project link)"}`, remoteWithoutProjectLink ? "Run `rig server repair-link --repo owner/repo` or `rig init --repo owner/repo --server remote` to restore the remote project link." : "Run `rig init --yes --repo owner/repo` to record the GitHub repo slug.") : preflightCheck("project-link", "project linked to selected server", legacyServerCompatibility ? "warn" : "fail", "missing .rig/state/connection.json", "Run `rig init` or `rig server use <alias|local>`."));
|
|
1328
|
+
if (selectedServer?.connectionKind === "remote" && repo?.project && !selectedServer.serverProjectRoot) {
|
|
1329
|
+
const link = await ensureRemoteProjectRootLink(context.projectRoot, { mode: "backfill-only", authToken: selectedServer.authToken });
|
|
1330
|
+
const loopbackDevRemote = !selectedServer.authToken && isLoopbackBaseUrl(selectedServer.baseUrl);
|
|
1331
|
+
checks.push(preflightCheck("remote-project-root-link", "remote server checkout/root linked", link.ok ? "pass" : loopbackDevRemote ? "warn" : "fail", link.ok ? `${link.repoSlug} -> ${link.serverProjectRoot}` : link.message, link.ok ? undefined : loopbackDevRemote ? "Loopback development remotes may continue without x-rig-project-root; production remotes must run `rig server repair-link`." : link.hint));
|
|
1332
|
+
remoteRootBlocked = !link.ok && !loopbackDevRemote;
|
|
1333
|
+
}
|
|
907
1334
|
try {
|
|
908
1335
|
const auth = await request("/api/github/auth/status");
|
|
909
1336
|
checks.push(isAuthenticated(auth) ? preflightCheck("github-auth", "GitHub auth valid", "pass") : preflightCheck("github-auth", "GitHub auth valid", legacyServerCompatibility ? "warn" : "fail", "not authenticated", "Run `rig github auth import-gh` or `rig github auth token --token <token>`."));
|
|
910
1337
|
} catch (error) {
|
|
911
1338
|
checks.push(preflightCheck("github-auth", "GitHub auth valid", legacyServerCompatibility ? "warn" : "fail", message(error), "Fix GitHub auth on the selected Rig server."));
|
|
912
1339
|
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
1340
|
+
if (!remoteRootBlocked) {
|
|
1341
|
+
try {
|
|
1342
|
+
const projection = await request("/api/workspace/task-projection");
|
|
1343
|
+
checks.push(preflightCheck("task-projection", "task projection ready", "pass", JSON.stringify(projection).slice(0, 120)));
|
|
1344
|
+
} catch (error) {
|
|
1345
|
+
checks.push(preflightCheck("task-projection", "task projection ready", "warn", message(error), "Refresh task projection with `rig task list` before launching."));
|
|
1346
|
+
}
|
|
1347
|
+
try {
|
|
1348
|
+
const permissions = await request("/api/github/repo/permissions");
|
|
1349
|
+
const allowed = permissionAllowsPr(permissions);
|
|
1350
|
+
checks.push(allowed === false ? preflightCheck("github-repo-permissions", "GitHub PR permissions", "fail", JSON.stringify(permissions).slice(0, 120), "Grant the selected GitHub token permission to push branches and open PRs.") : preflightCheck("github-repo-permissions", "GitHub PR permissions", allowed === true ? "pass" : "warn", JSON.stringify(permissions).slice(0, 120), "Confirm the selected token can push branches and open PRs."));
|
|
1351
|
+
} catch (error) {
|
|
1352
|
+
checks.push(preflightCheck("github-repo-permissions", "GitHub PR permissions", "warn", message(error), "Ensure the selected token can push branches and open PRs."));
|
|
1353
|
+
}
|
|
1354
|
+
} else {
|
|
1355
|
+
checks.push(preflightCheck("task-projection", "task projection ready", "warn", "skipped until remote project-root link is repaired", "Run `rig server repair-link`, then retry."));
|
|
1356
|
+
checks.push(preflightCheck("github-repo-permissions", "GitHub PR permissions", "warn", "skipped until remote project-root link is repaired", "Run `rig server repair-link`, then retry."));
|
|
925
1357
|
}
|
|
926
1358
|
if (repo?.project) {
|
|
927
1359
|
try {
|
|
@@ -933,19 +1365,24 @@ async function runFastTaskRunPreflight(context, options = {}) {
|
|
|
933
1365
|
}
|
|
934
1366
|
}
|
|
935
1367
|
if (taskId) {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1368
|
+
if (!remoteRootBlocked) {
|
|
1369
|
+
try {
|
|
1370
|
+
const tasks = await request(`/api/workspace/tasks?limit=200&refresh=1`);
|
|
1371
|
+
const found = Array.isArray(tasks) && tasks.some((task) => taskMatchesId(task, taskId));
|
|
1372
|
+
checks.push(found ? preflightCheck("issue", "task/issue accessible", "pass", taskId) : preflightCheck("issue", "task/issue accessible", legacyServerCompatibility ? "warn" : "fail", taskId, "Confirm the issue exists and matches the configured task filters."));
|
|
1373
|
+
} catch (error) {
|
|
1374
|
+
checks.push(preflightCheck("issue", "task/issue accessible", legacyServerCompatibility ? "warn" : "fail", message(error), "Fix the task source before launching a run."));
|
|
1375
|
+
}
|
|
1376
|
+
try {
|
|
1377
|
+
const runs = await request("/api/runs?limit=200");
|
|
1378
|
+
const duplicate = activeDuplicateRun(runs, taskId);
|
|
1379
|
+
checks.push(duplicate ? preflightCheck("duplicate-active-run", "one active run per task", "fail", String(duplicate.runId ?? taskId), "Attach to or stop the existing run before starting another one for this task.") : preflightCheck("duplicate-active-run", "one active run per task", "pass", taskId));
|
|
1380
|
+
} catch (error) {
|
|
1381
|
+
checks.push(preflightCheck("duplicate-active-run", "one active run per task", "warn", message(error), "Could not list active runs; the server will still reject conflicting runs if configured."));
|
|
1382
|
+
}
|
|
1383
|
+
} else {
|
|
1384
|
+
checks.push(preflightCheck("issue", "task/issue accessible", "fail", "skipped until remote project-root link is repaired", "Run `rig server repair-link`, then retry."));
|
|
1385
|
+
checks.push(preflightCheck("duplicate-active-run", "one active run per task", "warn", "skipped until remote project-root link is repaired", "Run `rig server repair-link`, then retry."));
|
|
949
1386
|
}
|
|
950
1387
|
}
|
|
951
1388
|
if ((options.runtimeAdapter ?? "pi") === "pi") {
|
|
@@ -1357,7 +1794,7 @@ async function withSpinner(label, work, options = {}) {
|
|
|
1357
1794
|
}
|
|
1358
1795
|
|
|
1359
1796
|
// packages/cli/src/commands/_pi-frontend.ts
|
|
1360
|
-
import { existsSync as existsSync3, mkdirSync as
|
|
1797
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync3, mkdtempSync, readFileSync as readFileSync3, rmSync, writeFileSync as writeFileSync3 } from "fs";
|
|
1361
1798
|
import { homedir as homedir2, tmpdir } from "os";
|
|
1362
1799
|
import { join } from "path";
|
|
1363
1800
|
import { main as runPiMain } from "@earendil-works/pi-coding-agent";
|
|
@@ -1417,7 +1854,7 @@ function statusFromRunDetails(run) {
|
|
|
1417
1854
|
async function prepareOperatorConsole(context, runId, tempSessionDir) {
|
|
1418
1855
|
const server = await ensureServerForCli(context.projectRoot);
|
|
1419
1856
|
const localCwd = join(homedir2(), ".rig", "drones", runId.slice(0, 8));
|
|
1420
|
-
|
|
1857
|
+
mkdirSync3(localCwd, { recursive: true });
|
|
1421
1858
|
trustDroneCwd(localCwd);
|
|
1422
1859
|
installRigPiTheme();
|
|
1423
1860
|
let sessionFileArg = [];
|
|
@@ -1439,7 +1876,7 @@ async function prepareOperatorConsole(context, runId, tempSessionDir) {
|
|
|
1439
1876
|
return line;
|
|
1440
1877
|
}).join(`
|
|
1441
1878
|
`);
|
|
1442
|
-
|
|
1879
|
+
writeFileSync3(localSessionPath, content);
|
|
1443
1880
|
sessionFileArg = ["--session", localSessionPath];
|
|
1444
1881
|
}
|
|
1445
1882
|
} catch {}
|
|
@@ -1529,12 +1966,12 @@ var RIG_PI_THEME = {
|
|
|
1529
1966
|
function trustDroneCwd(localCwd) {
|
|
1530
1967
|
try {
|
|
1531
1968
|
const agentDir = join(homedir2(), ".pi", "agent");
|
|
1532
|
-
|
|
1969
|
+
mkdirSync3(agentDir, { recursive: true });
|
|
1533
1970
|
const trustPath = join(agentDir, "trust.json");
|
|
1534
1971
|
const store = existsSync3(trustPath) ? JSON.parse(readFileSync3(trustPath, "utf8")) : {};
|
|
1535
1972
|
if (store[localCwd] !== true) {
|
|
1536
1973
|
store[localCwd] = true;
|
|
1537
|
-
|
|
1974
|
+
writeFileSync3(trustPath, `${JSON.stringify(store, null, "\t")}
|
|
1538
1975
|
`);
|
|
1539
1976
|
}
|
|
1540
1977
|
} catch {}
|
|
@@ -1542,12 +1979,12 @@ function trustDroneCwd(localCwd) {
|
|
|
1542
1979
|
function installRigPiTheme() {
|
|
1543
1980
|
try {
|
|
1544
1981
|
const themesDir = join(homedir2(), ".pi", "agent", "themes");
|
|
1545
|
-
|
|
1982
|
+
mkdirSync3(themesDir, { recursive: true });
|
|
1546
1983
|
const themePath = join(themesDir, "rig.json");
|
|
1547
1984
|
const next = `${JSON.stringify(RIG_PI_THEME, null, "\t")}
|
|
1548
1985
|
`;
|
|
1549
1986
|
if (!existsSync3(themePath) || readFileSync3(themePath, "utf8") !== next) {
|
|
1550
|
-
|
|
1987
|
+
writeFileSync3(themePath, next);
|
|
1551
1988
|
}
|
|
1552
1989
|
} catch {}
|
|
1553
1990
|
}
|
|
@@ -1985,12 +2422,13 @@ var PRIMARY_GROUPS = [
|
|
|
1985
2422
|
{
|
|
1986
2423
|
name: "server",
|
|
1987
2424
|
summary: "Choose, inspect, and start the Rig server that owns tasks and runs.",
|
|
1988
|
-
usage: ["rig server <status|list|add|use|start> [options]"],
|
|
2425
|
+
usage: ["rig server <status|list|add|use|repair-link|start> [options]"],
|
|
1989
2426
|
commands: [
|
|
1990
|
-
{ command: "status", description: "Show the selected server for this repo.", primary: true },
|
|
2427
|
+
{ command: "status", description: "Show the selected server and remote project-root link for this repo.", primary: true },
|
|
1991
2428
|
{ command: "use local", description: "Switch this repo to the local Rig server.", primary: true },
|
|
1992
2429
|
{ command: "add <alias> <url>", description: "Save a remote Rig server URL.", primary: true },
|
|
1993
2430
|
{ command: "use <alias>", description: "Select a saved remote server alias.", primary: true },
|
|
2431
|
+
{ command: "repair-link [--prepare|--backfill-only] [--repo owner/repo]", description: "Backfill or prepare the selected remote's server-host checkout link.", primary: true },
|
|
1994
2432
|
{ command: "list", description: "List saved local/remote server aliases.", primary: true },
|
|
1995
2433
|
{ command: "start [--host <host>] [--port <n>]", description: "Start a local rig-server process." }
|
|
1996
2434
|
],
|
|
@@ -1998,6 +2436,7 @@ var PRIMARY_GROUPS = [
|
|
|
1998
2436
|
"rig server status",
|
|
1999
2437
|
"rig server add prod https://where.rig-does.work",
|
|
2000
2438
|
"rig server use prod",
|
|
2439
|
+
"rig server repair-link --repo owner/repo",
|
|
2001
2440
|
"rig server use local",
|
|
2002
2441
|
"rig server start --port 3773"
|
|
2003
2442
|
],
|