create-egregore 0.20.3 → 0.20.4
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/assets/egregore-launcher.js +2 -2
- package/bin/cli.js +11 -66
- package/lib/api.js +6 -2
- package/lib/auth.js +1 -1
- package/lib/install-access.js +87 -0
- package/lib/setup.js +81 -7
- package/lib/token-install.js +65 -0
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// egregore-launcher-version: 0.20.
|
|
2
|
+
// egregore-launcher-version: 0.20.4
|
|
3
3
|
//
|
|
4
4
|
// egregore — launch and browse Egregore instances from your terminal.
|
|
5
5
|
// Installed by create-egregore. Reads ~/.egregore/instances.json.
|
|
@@ -33,7 +33,7 @@ const crypto = require("node:crypto");
|
|
|
33
33
|
const { spawnSync, spawn } = require("node:child_process");
|
|
34
34
|
const readline = require("node:readline");
|
|
35
35
|
|
|
36
|
-
const VERSION = "0.20.
|
|
36
|
+
const VERSION = "0.20.4";
|
|
37
37
|
const REGISTRY = path.join(os.homedir(), ".egregore", "instances.json");
|
|
38
38
|
const DEFAULT_FILE = path.join(os.homedir(), ".egregore", "default");
|
|
39
39
|
const UPDATE_CACHE_FILE = path.join(os.homedir(), ".egregore", "update-check.json");
|
package/bin/cli.js
CHANGED
|
@@ -543,75 +543,20 @@ async function main() {
|
|
|
543
543
|
}
|
|
544
544
|
|
|
545
545
|
async function tokenFlow(api, token, ctx) {
|
|
546
|
-
const
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
ui.error(err.message);
|
|
554
|
-
ui.info("");
|
|
555
|
-
ui.info("The token may have expired or already been used.");
|
|
556
|
-
ui.info("Visit egregore.xyz to get a new one, or run without --token:");
|
|
557
|
-
ui.info(" npx -y create-egregore@latest");
|
|
558
|
-
process.exit(1);
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
// Joiner tokens don't include a github_token — try gh CLI first. If gh is
|
|
562
|
-
// installed but logged out, run gh auth login instead of device flow.
|
|
563
|
-
if (!data.github_token || data.needs_cli_auth) {
|
|
564
|
-
const ghAuth = tryGhAuthOrLogin(ui, data.needs_cli_auth ? { mode: "join" } : {});
|
|
565
|
-
if (ghAuth) {
|
|
566
|
-
ui.success(`Using your ${ui.bold("gh")} CLI auth${ghAuth.user ? ` (${ghAuth.user})` : ""}`);
|
|
567
|
-
data.github_token = ghAuth.token;
|
|
568
|
-
} else if (ghCliExists()) {
|
|
569
|
-
ui.error("GitHub CLI auth did not complete.");
|
|
570
|
-
ui.info(`Run ${ui.bold("gh auth login")} and then re-run this command.`);
|
|
571
|
-
process.exit(1);
|
|
572
|
-
} else {
|
|
546
|
+
const { installFromToken } = require("../lib/token-install");
|
|
547
|
+
await installFromToken(api, token, ctx, {
|
|
548
|
+
ui, install, request: ghApi,
|
|
549
|
+
authenticate: async (forceLogin) => {
|
|
550
|
+
const auth = tryGhAuthOrLogin(ui, { mode: "join", requireRepoScope: true, forceLogin });
|
|
551
|
+
if (auth) return auth;
|
|
552
|
+
if (ghCliExists()) return null;
|
|
573
553
|
if (!canUseInteractiveBrowserFlow()) {
|
|
574
554
|
explainNoGhHeadless(ui);
|
|
575
|
-
|
|
555
|
+
return null;
|
|
576
556
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
ui.success("Authenticated with GitHub");
|
|
581
|
-
} catch (err) {
|
|
582
|
-
ui.error(`GitHub auth failed: ${err.message}`);
|
|
583
|
-
process.exit(1);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
// Token-mode setups already have their repo list baked in server-side. If
|
|
589
|
-
// the user's current working repo happens to match a managed-repo name, skip
|
|
590
|
-
// the clone/pull/configure step for it so we don't clobber uncommitted work.
|
|
591
|
-
const skipRepos = new Set();
|
|
592
|
-
if (ctx.prefilledRepo && Array.isArray(data.repos)) {
|
|
593
|
-
for (const r of data.repos) {
|
|
594
|
-
const n = typeof r === "string" ? r : r && r.name;
|
|
595
|
-
if (n && n === ctx.prefilledRepo.name) skipRepos.add(n);
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
try {
|
|
599
|
-
await install(data, ui, ctx.targetDir, {
|
|
600
|
-
skipRepos,
|
|
601
|
-
noAutolaunch: ctx.noAutolaunch,
|
|
602
|
-
noScreens: ctx.noScreens,
|
|
603
|
-
flowVariant: ctx.flowVariant,
|
|
604
|
-
runtime: ctx.runtime,
|
|
605
|
-
});
|
|
606
|
-
if (ctx.prefilledRepo && skipRepos.size === 0) {
|
|
607
|
-
console.log("");
|
|
608
|
-
ui.info(`Tip: add your current repo to managed_repos with:`);
|
|
609
|
-
ui.info(` /add ${ctx.prefilledRepo.toplevel || `../${ctx.prefilledRepo.localName}`}`);
|
|
610
|
-
}
|
|
611
|
-
} catch (err) {
|
|
612
|
-
ui.error(`Install failed: ${err.message}`);
|
|
613
|
-
process.exit(1);
|
|
614
|
-
}
|
|
557
|
+
return { token: await deviceFlow(ui, { mode: "join", scope: "repo" }) };
|
|
558
|
+
},
|
|
559
|
+
});
|
|
615
560
|
}
|
|
616
561
|
|
|
617
562
|
async function interactiveFlow(api, ctx) {
|
package/lib/api.js
CHANGED
|
@@ -63,8 +63,12 @@ class EgregoreAPI {
|
|
|
63
63
|
this.base = (baseUrl || DEFAULT_API).replace(/\/$/, "");
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
async claimToken(token) {
|
|
67
|
-
|
|
66
|
+
async claimToken(token, githubToken) {
|
|
67
|
+
// Old APIs reject POST without consuming a one-time setup token. Never
|
|
68
|
+
// silently downgrade an authenticated retry to the legacy GET protocol.
|
|
69
|
+
return request(githubToken ? "POST" : "GET", `${this.base}/api/org/claim/${token}`, {
|
|
70
|
+
headers: githubToken ? { Authorization: `Bearer ${githubToken}` } : {},
|
|
71
|
+
});
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
async getOrgs(githubToken) {
|
package/lib/auth.js
CHANGED
|
@@ -212,7 +212,7 @@ function runGhAuthLogin(ui, opts = {}) {
|
|
|
212
212
|
|
|
213
213
|
function tryGhAuthOrLogin(ui, opts = {}) {
|
|
214
214
|
const existing = tryGhAuth();
|
|
215
|
-
if (existing) return existing;
|
|
215
|
+
if (existing && !opts.forceLogin && !(opts.requireRepoScope && existing.hasRepoScope === false)) return existing;
|
|
216
216
|
if (!ghCliExists()) return null;
|
|
217
217
|
return runGhAuthLogin(ui, opts);
|
|
218
218
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** Repository access for a connected install. Never accept unrelated invitations. */
|
|
2
|
+
class RepositoryAccessError extends Error {
|
|
3
|
+
constructor(message, canReauthenticate = false) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "RepositoryAccessError";
|
|
6
|
+
this.canReauthenticate = canReauthenticate;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function repositoryFromUrl(value) {
|
|
11
|
+
const url = new URL(value);
|
|
12
|
+
const name = url.pathname.replace(/^\//, "").replace(/\.git$/, "");
|
|
13
|
+
if (url.protocol !== "https:" || url.hostname !== "github.com" || url.username || url.password ||
|
|
14
|
+
url.search || url.hash || !/^[\w.-]+\/[\w.-]+$/.test(name)) {
|
|
15
|
+
throw new Error("Setup contains an invalid GitHub repository URL.");
|
|
16
|
+
}
|
|
17
|
+
return name;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function requiredRepositories(data) {
|
|
21
|
+
const names = [repositoryFromUrl(data.fork_url), repositoryFromUrl(data.memory_url)];
|
|
22
|
+
for (const entry of data.repos || []) {
|
|
23
|
+
const name = typeof entry === "string" ? entry : entry?.name;
|
|
24
|
+
if (!/^[\w.-]+$/.test(name || "") || name === "." || name === "..") {
|
|
25
|
+
throw new Error("Setup contains an invalid managed repository name.");
|
|
26
|
+
}
|
|
27
|
+
names.push(repositoryFromUrl(`https://github.com/${data.github_org}/${name}`));
|
|
28
|
+
}
|
|
29
|
+
return [...new Map(names.map(name => [name.toLowerCase(), name])).values()];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function matchesIdentity(data, user) {
|
|
33
|
+
// IDs survive account renames. Older payloads can only be checked by login.
|
|
34
|
+
if (data.github_id != null) return String(data.github_id) === String(user?.id);
|
|
35
|
+
return !!data.github_username && data.github_username.toLowerCase() === user?.login?.toLowerCase();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function ensureRepositoryAccess(data, ui, { request, sleep = ms => new Promise(r => setTimeout(r, ms)) }) {
|
|
39
|
+
const token = data.github_token;
|
|
40
|
+
if (!token) throw new RepositoryAccessError("GitHub authentication is required for this installation.", true);
|
|
41
|
+
const who = await request("GET", "/user", token);
|
|
42
|
+
if (who.status !== 200) throw new RepositoryAccessError(`GitHub identity check failed (HTTP ${who.status}).`, who.status === 401 || who.status === 403);
|
|
43
|
+
if (!matchesIdentity(data, who.data)) throw new RepositoryAccessError("Your active GitHub account does not match the account that accepted this invitation. Sign in to that account and retry.");
|
|
44
|
+
|
|
45
|
+
const required = requiredRepositories(data);
|
|
46
|
+
async function missingRepos() {
|
|
47
|
+
const missing = [];
|
|
48
|
+
for (const name of required) {
|
|
49
|
+
const result = await request("GET", `/repos/${name}`, token);
|
|
50
|
+
if (result.status === 200 && result.data?.permissions?.pull !== false) continue;
|
|
51
|
+
if (![401, 403, 404, 200].includes(result.status)) {
|
|
52
|
+
throw new RepositoryAccessError(`GitHub access check for ${name} failed (HTTP ${result.status}). Retry the same install command.`);
|
|
53
|
+
}
|
|
54
|
+
missing.push(name);
|
|
55
|
+
}
|
|
56
|
+
return missing;
|
|
57
|
+
}
|
|
58
|
+
let missing = await missingRepos();
|
|
59
|
+
if (!missing.length) return required;
|
|
60
|
+
const wanted = new Set(missing.map(name => name.toLowerCase()));
|
|
61
|
+
// Collect before accepting: removing invitations while paginating would skip entries.
|
|
62
|
+
const invitations = [];
|
|
63
|
+
for (let page = 1; ; page++) {
|
|
64
|
+
const result = await request("GET", `/user/repository_invitations?per_page=100&page=${page}`, token);
|
|
65
|
+
if (result.status !== 200 || !Array.isArray(result.data)) {
|
|
66
|
+
throw new RepositoryAccessError(`Could not list GitHub repository invitations (HTTP ${result.status}); access is missing for ${missing.join(", ")}.`, [401, 403].includes(result.status));
|
|
67
|
+
}
|
|
68
|
+
invitations.push(...result.data.filter(inv => wanted.has(inv.repository?.full_name?.toLowerCase())));
|
|
69
|
+
if (result.data.length < 100) break;
|
|
70
|
+
if (page === 100) throw new RepositoryAccessError("GitHub returned too many invitation pages. Retry after reviewing pending invitations.");
|
|
71
|
+
}
|
|
72
|
+
let acceptanceError;
|
|
73
|
+
for (const inv of invitations) {
|
|
74
|
+
const result = await request("PATCH", `/user/repository_invitations/${inv.id}`, token);
|
|
75
|
+
if (result.status >= 200 && result.status < 300) ui.success(`Accepted invite to ${inv.repository.full_name}`);
|
|
76
|
+
else acceptanceError = new RepositoryAccessError(`Could not accept the GitHub invitation for ${inv.repository.full_name} (HTTP ${result.status}).`, [401, 403].includes(result.status));
|
|
77
|
+
}
|
|
78
|
+
// A concurrent acceptance can reject our PATCH yet leave effective access ready.
|
|
79
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
80
|
+
missing = await missingRepos();
|
|
81
|
+
if (!missing.length) return required;
|
|
82
|
+
if (attempt < 2) await sleep(250 * (attempt + 1));
|
|
83
|
+
}
|
|
84
|
+
throw acceptanceError || new RepositoryAccessError(`GitHub access is still missing for ${missing.join(", ")}. Confirm this account has been invited to these repositories, then retry the same install command.`, true);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = { RepositoryAccessError, requiredRepositories, matchesIdentity, ensureRepositoryAccess };
|
package/lib/setup.js
CHANGED
|
@@ -29,6 +29,7 @@ const {
|
|
|
29
29
|
const { commandExists } = require("./path-lookup");
|
|
30
30
|
|
|
31
31
|
const https = require("node:https");
|
|
32
|
+
const { RepositoryAccessError, ensureRepositoryAccess } = require("./install-access");
|
|
32
33
|
|
|
33
34
|
function run(cmd, opts = {}) {
|
|
34
35
|
return execSync(cmd, { stdio: "pipe", encoding: "utf-8", timeout: 60000, ...opts }).trim();
|
|
@@ -52,6 +53,7 @@ function ghApi(method, apiPath, token, body) {
|
|
|
52
53
|
path: apiPath,
|
|
53
54
|
method,
|
|
54
55
|
headers,
|
|
56
|
+
timeout: 15000,
|
|
55
57
|
},
|
|
56
58
|
(res) => {
|
|
57
59
|
let buf = "";
|
|
@@ -66,6 +68,7 @@ function ghApi(method, apiPath, token, body) {
|
|
|
66
68
|
}
|
|
67
69
|
);
|
|
68
70
|
req.on("error", reject);
|
|
71
|
+
req.on("timeout", () => req.destroy(new Error("GitHub request timed out. Retry the same install command.")));
|
|
69
72
|
if (payload) req.write(payload);
|
|
70
73
|
req.end();
|
|
71
74
|
});
|
|
@@ -416,9 +419,15 @@ async function install(data, ui, targetDir, opts = {}) {
|
|
|
416
419
|
// steps are skipped. Falls through to the normal flow if anything is off.
|
|
417
420
|
const alreadyInstalled = isFullySetUp(egregoreDir, memoryDir, fork_url, memory_url);
|
|
418
421
|
|
|
419
|
-
//
|
|
420
|
-
|
|
421
|
-
|
|
422
|
+
// Verify before credential writes or cloning. The same verified credential
|
|
423
|
+
// handles Git operations, so an unrelated SSH account cannot take over.
|
|
424
|
+
if (opts.verifyAccess) {
|
|
425
|
+
const required = await ensureRepositoryAccess(data, ui, { request: ghApi });
|
|
426
|
+
for (const name of required) verifyGitAccess(`https://github.com/${name}.git`, github_token);
|
|
427
|
+
} else {
|
|
428
|
+
if (github_token) configureGitCredentials(github_token);
|
|
429
|
+
await acceptPendingInvitations(github_token, github_org, ui);
|
|
430
|
+
}
|
|
422
431
|
|
|
423
432
|
if (alreadyInstalled) {
|
|
424
433
|
ui.success(`Already installed at ${ui.bold(egregoreDir)} — refreshing setup`);
|
|
@@ -426,7 +435,9 @@ async function install(data, ui, targetDir, opts = {}) {
|
|
|
426
435
|
} else {
|
|
427
436
|
// 1. Clone fork (SSH first, HTTPS fallback — no token embedding)
|
|
428
437
|
ui.step(1, totalSteps, "Cloning egregore...");
|
|
429
|
-
if (
|
|
438
|
+
if (opts.verifyAccess) {
|
|
439
|
+
syncAuthenticatedRepository(fork_url, egregoreDir, github_token);
|
|
440
|
+
} else if (fs.existsSync(egregoreDir)) {
|
|
430
441
|
ui.warn("egregore/ already exists — pulling latest");
|
|
431
442
|
run("git pull", { cwd: egregoreDir });
|
|
432
443
|
} else {
|
|
@@ -449,7 +460,9 @@ async function install(data, ui, targetDir, opts = {}) {
|
|
|
449
460
|
|
|
450
461
|
// 2. Clone memory
|
|
451
462
|
ui.step(2, totalSteps, "Cloning shared memory...");
|
|
452
|
-
if (
|
|
463
|
+
if (opts.verifyAccess) {
|
|
464
|
+
syncAuthenticatedRepository(memory_url, memoryDir, github_token);
|
|
465
|
+
} else if (fs.existsSync(memoryDir)) {
|
|
453
466
|
ui.warn(`${memoryDirName}/ already exists — pulling latest`);
|
|
454
467
|
run("git pull", { cwd: memoryDir });
|
|
455
468
|
} else {
|
|
@@ -576,7 +589,9 @@ async function install(data, ui, targetDir, opts = {}) {
|
|
|
576
589
|
continue;
|
|
577
590
|
}
|
|
578
591
|
try {
|
|
579
|
-
if (
|
|
592
|
+
if (opts.verifyAccess) {
|
|
593
|
+
syncAuthenticatedRepository(`https://github.com/${github_org}/${repoName}.git`, repoDir, github_token);
|
|
594
|
+
} else if (fs.existsSync(repoDir)) {
|
|
580
595
|
ui.warn(`${repoName}/ already exists — pulling latest`);
|
|
581
596
|
run("git pull", { cwd: repoDir });
|
|
582
597
|
} else {
|
|
@@ -588,7 +603,8 @@ async function install(data, ui, targetDir, opts = {}) {
|
|
|
588
603
|
try { run("git config credential.helper store", { cwd: repoDir }); } catch {}
|
|
589
604
|
clonedRepos.push(repoName);
|
|
590
605
|
ui.success(`Cloned ${repoName}`);
|
|
591
|
-
} catch {
|
|
606
|
+
} catch (err) {
|
|
607
|
+
if (opts.verifyAccess) throw err;
|
|
592
608
|
failedRepos.push(repoName);
|
|
593
609
|
ui.warn(`Could not clone ${repoName} — you may not have access yet. Ask the org admin to grant access.`);
|
|
594
610
|
}
|
|
@@ -823,6 +839,61 @@ function gitCloneEnv(base = process.env) {
|
|
|
823
839
|
};
|
|
824
840
|
}
|
|
825
841
|
|
|
842
|
+
function authenticatedGitEnv(token, base = process.env) {
|
|
843
|
+
if (!token || /[\r\n]/.test(token)) throw new Error("A valid GitHub credential is required.");
|
|
844
|
+
const env = gitCloneEnv(base);
|
|
845
|
+
const count = Number(env.GIT_CONFIG_COUNT || 0);
|
|
846
|
+
if (!Number.isSafeInteger(count) || count < 0) throw new Error("Invalid Git configuration environment.");
|
|
847
|
+
const settings = [
|
|
848
|
+
["credential.helper", ""],
|
|
849
|
+
["http.https://github.com/.extraheader", ""],
|
|
850
|
+
["http.https://github.com/.extraheader", `Authorization: Basic ${Buffer.from("x-access-token:" + token).toString("base64")}`],
|
|
851
|
+
];
|
|
852
|
+
settings.forEach(([key, value], index) => {
|
|
853
|
+
env[`GIT_CONFIG_KEY_${count + index}`] = key;
|
|
854
|
+
env[`GIT_CONFIG_VALUE_${count + index}`] = value;
|
|
855
|
+
});
|
|
856
|
+
env.GIT_CONFIG_COUNT = String(count + settings.length);
|
|
857
|
+
return env;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
function authenticatedGit(args, token, cwd) {
|
|
861
|
+
try {
|
|
862
|
+
return execFileSync("git", args, {
|
|
863
|
+
cwd, env: authenticatedGitEnv(token), timeout: 60000,
|
|
864
|
+
stdio: "pipe", encoding: "utf-8",
|
|
865
|
+
}).trim();
|
|
866
|
+
} catch (err) {
|
|
867
|
+
const detail = redactToken(err.stderr || err.message, token)
|
|
868
|
+
.split(Buffer.from("x-access-token:" + token).toString("base64")).join("***");
|
|
869
|
+
throw new Error(`Git ${args[0]} failed: ${detail.trim()}`);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
function verifyGitAccess(url, token) {
|
|
874
|
+
try {
|
|
875
|
+
authenticatedGit(["ls-remote", url], token);
|
|
876
|
+
} catch (err) {
|
|
877
|
+
throw new RepositoryAccessError(
|
|
878
|
+
`Cannot read ${url} with the verified GitHub account. ${err.message}`,
|
|
879
|
+
/authentication|could not read Username|not found|403|access denied/i.test(err.message),
|
|
880
|
+
);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
function syncAuthenticatedRepository(url, dir, token) {
|
|
885
|
+
if (fs.existsSync(dir)) {
|
|
886
|
+
const origin = authenticatedGit(["remote", "get-url", "origin"], token, dir);
|
|
887
|
+
if (normalizeGitUrl(origin) !== normalizeGitUrl(url)) {
|
|
888
|
+
throw new Error(`Refusing to update ${dir}: its Git origin differs from this setup.`);
|
|
889
|
+
}
|
|
890
|
+
// A retry reuses completed clones. Do not merge a remote default branch
|
|
891
|
+
// into a user's working branch or disturb changes made after the failure.
|
|
892
|
+
} else {
|
|
893
|
+
authenticatedGit(["clone", url, dir], token);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
826
897
|
/**
|
|
827
898
|
* Clone a repo, trying SSH first then HTTPS (no token embedded).
|
|
828
899
|
* The repo:invite-scoped OAuth token can't clone — we rely on the
|
|
@@ -1544,6 +1615,9 @@ module.exports = {
|
|
|
1544
1615
|
redactToken,
|
|
1545
1616
|
configureGitCredentials,
|
|
1546
1617
|
gitCloneEnv,
|
|
1618
|
+
authenticatedGitEnv,
|
|
1619
|
+
verifyGitAccess,
|
|
1620
|
+
syncAuthenticatedRepository,
|
|
1547
1621
|
assistantInstallCommand,
|
|
1548
1622
|
initMemoryDirs,
|
|
1549
1623
|
ensureDevelop,
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Authenticate before redeeming, and keep retries on the original connected setup. */
|
|
2
|
+
const { RepositoryAccessError, matchesIdentity } = require("./install-access");
|
|
3
|
+
|
|
4
|
+
async function installFromToken(api, token, ctx, deps) {
|
|
5
|
+
const { ui, authenticate, request, install } = deps;
|
|
6
|
+
let auth = await authenticate(false);
|
|
7
|
+
if (!auth?.token) throw new Error("GitHub sign-in did not complete. Retry this install command to continue joining the same Egregore.");
|
|
8
|
+
let who = await request("GET", "/user", auth.token);
|
|
9
|
+
if ([401, 403].includes(who.status)) {
|
|
10
|
+
ui.info("Your GitHub session needs authentication. Signing in again before opening this setup.");
|
|
11
|
+
auth = await authenticate(true);
|
|
12
|
+
if (!auth?.token) throw new Error("GitHub sign-in did not complete. Retry this install command.");
|
|
13
|
+
who = await request("GET", "/user", auth.token);
|
|
14
|
+
}
|
|
15
|
+
if (who.status !== 200 || !who.data?.id) throw new Error(`GitHub identity check failed (HTTP ${who.status}). Retry after signing in.`);
|
|
16
|
+
const spinner = ui.spinner("Verifying setup...");
|
|
17
|
+
let data;
|
|
18
|
+
try {
|
|
19
|
+
data = await api.claimToken(token, auth.token);
|
|
20
|
+
spinner.stop(`Setting up ${ui.bold(data.org_name)}`);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
spinner.fail("Could not open this setup");
|
|
23
|
+
if (/Method Not Allowed|HTTP 405/i.test(err.message)) {
|
|
24
|
+
throw new Error("The setup service needs the authenticated retry update before this installer can continue. The setup token has not been consumed.");
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`${err.message}. Retry with the GitHub account that accepted the invitation. If the setup has expired, reopen the invitation page to continue joining the same Egregore.`);
|
|
27
|
+
}
|
|
28
|
+
if (!matchesIdentity(data, who.data)) throw new Error("This setup belongs to a different GitHub account. Sign in to the account that accepted the invitation and retry.");
|
|
29
|
+
|
|
30
|
+
const skipRepos = new Set();
|
|
31
|
+
if (ctx.prefilledRepo && Array.isArray(data.repos)) {
|
|
32
|
+
for (const repo of data.repos) {
|
|
33
|
+
const name = typeof repo === "string" ? repo : repo?.name;
|
|
34
|
+
if (name === ctx.prefilledRepo.name) skipRepos.add(name);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const options = {
|
|
38
|
+
skipRepos,
|
|
39
|
+
noAutolaunch: ctx.noAutolaunch,
|
|
40
|
+
noScreens: ctx.noScreens,
|
|
41
|
+
flowVariant: ctx.flowVariant,
|
|
42
|
+
runtime: ctx.runtime,
|
|
43
|
+
verifyAccess: true,
|
|
44
|
+
};
|
|
45
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
46
|
+
try {
|
|
47
|
+
await install({ ...data, github_token: auth.token }, ui, ctx.targetDir, options);
|
|
48
|
+
return;
|
|
49
|
+
} catch (err) {
|
|
50
|
+
if (attempt === 0 && err instanceof RepositoryAccessError && err.canReauthenticate) {
|
|
51
|
+
ui.warn(err.message);
|
|
52
|
+
ui.info("Signing in again with permission to accept invitations and read the required repositories.");
|
|
53
|
+
const next = await authenticate(true);
|
|
54
|
+
if (next?.token) {
|
|
55
|
+
auth = next;
|
|
56
|
+
// install() verifies identity again before invitations or any writes.
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`${err.message}\nRetry the same install command to continue this setup before its token expires.`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = { installFromToken };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-egregore",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.4",
|
|
4
4
|
"description": "Set up Egregore for your team in one command \u2014 installs the egregore launcher and your choice of Claude Code, Codex, or Pi.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"build:runtime": "node ../../bin/capability-distribution.mjs generate-skill-view --root ../.. && node scripts/build-runtime-bundle.mjs && node scripts/build-pi-runtime-bundle.mjs && node scripts/build-prime-runtime-bundle.mjs && node ../../api/scripts/build-connect-runtime-pack.mjs",
|
|
14
14
|
"build:pi-runtime": "node scripts/build-pi-runtime-bundle.mjs",
|
|
15
15
|
"build:prime-runtime": "node scripts/build-prime-runtime-bundle.mjs",
|
|
16
|
-
"test": "node ../../bin/capability-distribution.mjs validate --root ../.. && node scripts/build-runtime-bundle.mjs --check && node scripts/build-pi-runtime-bundle.mjs --check && node scripts/build-prime-runtime-bundle.mjs --check && node ../../bin/prime-render-spec.mjs --check && node ../../bin/pi-render-spec.mjs --check && node ../../api/scripts/build-connect-runtime-pack.mjs --check && node --test test/capability-distribution.test.js test/connect-runtime.test.js test/context.test.js test/path-lookup.test.js test/nixos-portability.test.js test/parse-join-target.test.js test/skip-repos.test.js test/install-origin-guard.test.js test/onboarding-shortcircuit.test.js test/welcome-screen.test.js test/runtime-selection.test.js test/command-generation.test.js test/auth-gh.test.js test/gauntlet-fixes.test.js test/codex-runtime.test.js test/pi-runtime.test.js test/prime-runtime.test.js test/prime-branch-policy.test.js test/prime-bridge-skill.test.js test/prime-session-smoke.test.js test/pi-product-workflows.test.js test/installer-runtime-source.test.js test/scroll-repro.test.js test/launcher-refocus-redraw.test.js test/multiselect-remote-search.test.js test/back-navigation.test.js test/manifest-form.test.js test/launcher-delete.test.js test/launcher-connect.test.js test/installer-connect-choice.test.js test/launcher-connected-status.test.js test/launcher-permissions.test.js test/launcher-update.test.js test/connected-config.test.js test/workflow-settings.test.js",
|
|
16
|
+
"test": "node ../../bin/capability-distribution.mjs validate --root ../.. && node scripts/build-runtime-bundle.mjs --check && node scripts/build-pi-runtime-bundle.mjs --check && node scripts/build-prime-runtime-bundle.mjs --check && node ../../bin/prime-render-spec.mjs --check && node ../../bin/pi-render-spec.mjs --check && node ../../api/scripts/build-connect-runtime-pack.mjs --check && node --test test/invite-install.test.js test/capability-distribution.test.js test/connect-runtime.test.js test/context.test.js test/path-lookup.test.js test/nixos-portability.test.js test/parse-join-target.test.js test/skip-repos.test.js test/install-origin-guard.test.js test/onboarding-shortcircuit.test.js test/welcome-screen.test.js test/runtime-selection.test.js test/command-generation.test.js test/auth-gh.test.js test/gauntlet-fixes.test.js test/codex-runtime.test.js test/pi-runtime.test.js test/prime-runtime.test.js test/prime-branch-policy.test.js test/prime-bridge-skill.test.js test/prime-session-smoke.test.js test/pi-product-workflows.test.js test/installer-runtime-source.test.js test/scroll-repro.test.js test/launcher-refocus-redraw.test.js test/multiselect-remote-search.test.js test/back-navigation.test.js test/manifest-form.test.js test/launcher-delete.test.js test/launcher-connect.test.js test/installer-connect-choice.test.js test/launcher-connected-status.test.js test/launcher-permissions.test.js test/launcher-update.test.js test/connected-config.test.js test/workflow-settings.test.js",
|
|
17
17
|
"test:e2e": "node --test test/e2e-local.test.js",
|
|
18
18
|
"test:all": "node scripts/build-runtime-bundle.mjs --check && node scripts/build-pi-runtime-bundle.mjs --check && node --test test/"
|
|
19
19
|
},
|