@archme/cli 0.25.2 → 0.25.3

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/cli.js CHANGED
@@ -22776,6 +22776,7 @@ async function resolveOrCreateProject(supabase, userId, fullSlug) {
22776
22776
  );
22777
22777
  }
22778
22778
  return {
22779
+ orgId: org.id,
22779
22780
  orgSlug: org.slug,
22780
22781
  projectSlug,
22781
22782
  projectId,
@@ -22810,6 +22811,7 @@ async function claimSignupDefaultProject(supabase, org, projectSlug) {
22810
22811
  const { error: renameErr } = await supabase.from("projects").update({ name: projectSlug, slug: projectSlug }).eq("id", row.id);
22811
22812
  if (renameErr) return null;
22812
22813
  return {
22814
+ orgId: org.id,
22813
22815
  orgSlug: org.slug,
22814
22816
  projectSlug,
22815
22817
  projectId: row.id,
@@ -22830,6 +22832,16 @@ async function findProject(supabase, fullSlug) {
22830
22832
  if (!org) throw new Error(`org \`${orgSlug}\` not found`);
22831
22833
  return fetchExistingProject(supabase, org, projectSlug);
22832
22834
  }
22835
+ async function findOrgId(supabase, fullSlug) {
22836
+ const orgSlug = fullSlug.split("/")[0];
22837
+ if (!orgSlug) throw new Error(`invalid project slug \`${fullSlug}\` \u2014 expected \`org/project\``);
22838
+ const org = await mustQuery(
22839
+ supabase.from("organizations").select("id").eq("slug", orgSlug).maybeSingle(),
22840
+ "org lookup failed"
22841
+ );
22842
+ if (!org) throw new Error(`org \`${orgSlug}\` not found`);
22843
+ return org.id;
22844
+ }
22833
22845
  async function fetchExistingProject(supabase, org, projectSlug) {
22834
22846
  const project = await mustQuery(
22835
22847
  supabase.from("projects").select("id, slug").eq("org_id", org.id).eq("slug", projectSlug).is("deleted_at", null).maybeSingle(),
@@ -22845,6 +22857,7 @@ async function fetchExistingProject(supabase, org, projectSlug) {
22845
22857
  const defaultBranch = rows.find((b) => b.is_default)?.name ?? DEFAULT_BRANCH_NAME;
22846
22858
  const architectureBranch = resolveArchitectureBranchName(rows.map((b) => ({ name: b.name, isDefault: b.is_default }))) ?? defaultBranch;
22847
22859
  return {
22860
+ orgId: org.id,
22848
22861
  orgSlug: org.slug,
22849
22862
  projectSlug,
22850
22863
  projectId,
@@ -27033,6 +27046,24 @@ var init_githubInstallations = __esm({
27033
27046
  }
27034
27047
  });
27035
27048
 
27049
+ // src/auth/machineOrgs.ts
27050
+ async function readMachineOrgIds() {
27051
+ try {
27052
+ const { credentials } = await loadAllCredentials(resolveConfig().supabaseUrl);
27053
+ const orgs = credentials.flatMap((c3) => c3.bindings?.length ? c3.bindings.map((b) => b.org_id) : [c3.org_id]);
27054
+ return orgs.length ? new Set(orgs) : null;
27055
+ } catch {
27056
+ return null;
27057
+ }
27058
+ }
27059
+ var init_machineOrgs = __esm({
27060
+ "src/auth/machineOrgs.ts"() {
27061
+ "use strict";
27062
+ init_defaults();
27063
+ init_credentials();
27064
+ }
27065
+ });
27066
+
27036
27067
  // src/init/watchRepo.ts
27037
27068
  async function findInstallation(supabase, orgId, owner) {
27038
27069
  const { data: installs, error: installErr } = await supabase.from("org_github_installations").select("installation_id").eq("org_id", orgId);
@@ -27102,12 +27133,18 @@ async function watchRepoForProject(input) {
27102
27133
  reason: `the repo is linked but commit-driven updates could not be switched on (${enableErr.message}). Pushes will not reach your daemon until they are.`
27103
27134
  };
27104
27135
  }
27136
+ if ((await readMachineOrgIds())?.has(orgId) === false) {
27137
+ input.log?.(
27138
+ " ! This machine isn't paired with the board's org, so its daemon won't run these updates.\n Run `archme login` and tick that org, or have a teammate's daemon or ArchMe's managed daemon run them."
27139
+ );
27140
+ }
27105
27141
  return { watched: true };
27106
27142
  }
27107
27143
  var init_watchRepo = __esm({
27108
27144
  "src/init/watchRepo.ts"() {
27109
27145
  "use strict";
27110
27146
  init_githubInstallations();
27147
+ init_machineOrgs();
27111
27148
  }
27112
27149
  });
27113
27150
 
@@ -27419,7 +27456,7 @@ async function runLocalWatch(opts) {
27419
27456
  log(` project: ${project.orgSlug}/${project.projectSlug}${project.created ? " (created)" : ""}`);
27420
27457
  const registered = await registerLocalWatch({
27421
27458
  supabase,
27422
- orgId,
27459
+ orgId: project.orgId,
27423
27460
  projectId: project.projectId,
27424
27461
  repoPath,
27425
27462
  originUrl,
@@ -27452,6 +27489,12 @@ async function runLocalWatch(opts) {
27452
27489
  return 0;
27453
27490
  }
27454
27491
  async function watchLocalRepoRow(args) {
27492
+ if ((await readMachineOrgIds())?.has(args.orgId) === false) {
27493
+ return {
27494
+ ok: false,
27495
+ reason: "this machine isn't paired with the board's org, so its daemon could never run this repo's updates. Run `archme login`, tick that org, and try again."
27496
+ };
27497
+ }
27455
27498
  const { data, error } = await args.supabase.rpc("watch_local_repo", {
27456
27499
  p_org_id: args.orgId,
27457
27500
  p_project_id: args.projectId,
@@ -27631,6 +27674,7 @@ var init_localWatch = __esm({
27631
27674
  init_localGit();
27632
27675
  init_localRepos();
27633
27676
  init_branchMarker();
27677
+ init_machineOrgs();
27634
27678
  init_localWatchList();
27635
27679
  init_localWatchResolve();
27636
27680
  init_prompt();
@@ -28657,7 +28701,7 @@ async function runAddRepo(opts, deps = {}) {
28657
28701
  const project = await (deps.resolveProject ?? resolveOrCreateProject)(authed2.supabase, authed2.userId, opts.project);
28658
28702
  const scanBranch = initScanBranch(project.defaultBranch);
28659
28703
  const added = await addRepoToBoard(
28660
- { authed: authed2, orgId: authed2.orgId, projectId: project.projectId, project: opts.project, scanBranch },
28704
+ { authed: authed2, orgId: project.orgId, projectId: project.projectId, project: opts.project, scanBranch },
28661
28705
  {
28662
28706
  root: inspected.root,
28663
28707
  originUrl: inspected.originUrl,
@@ -29770,10 +29814,11 @@ async function prepareAddRepos(opts, deps = {}) {
29770
29814
  if (unscannable.length) return fail2(78, `${unscannable.join("\n ")}
29771
29815
  Nothing was changed.`);
29772
29816
  const watching = [...todo, ...toWatch];
29817
+ const orgId = existing?.orgId ?? await (deps.findOrgId ?? findOrgId)(supabase, opts.project);
29773
29818
  const elsewhere = [];
29774
29819
  for (const c3 of watching) {
29775
29820
  const holder = await (deps.watchedElsewhere ?? watchedElsewhere)(supabase, {
29776
- orgId: authed2.orgId,
29821
+ orgId,
29777
29822
  projectId: existing?.projectId ?? null,
29778
29823
  target: c3.target
29779
29824
  });
@@ -29786,7 +29831,7 @@ async function prepareAddRepos(opts, deps = {}) {
29786
29831
  if (!opts.local) {
29787
29832
  const missing = [];
29788
29833
  for (const c3 of watching) {
29789
- const found = await (deps.findInstallation ?? findInstallation)(supabase, authed2.orgId, c3.target.repoOwner);
29834
+ const found = await (deps.findInstallation ?? findInstallation)(supabase, orgId, c3.target.repoOwner);
29790
29835
  if (!found.ok) missing.push(`${c3.target.repo}: ${found.reason}`);
29791
29836
  }
29792
29837
  if (missing.length) {
@@ -29795,7 +29840,7 @@ async function prepareAddRepos(opts, deps = {}) {
29795
29840
  }
29796
29841
  }
29797
29842
  const project = existing ?? await (deps.resolveProject ?? resolveOrCreateProject)(supabase, authed2.userId, opts.project);
29798
- const board = { authed: authed2, orgId: authed2.orgId, projectId: project.projectId, project: opts.project, scanBranch };
29843
+ const board = { authed: authed2, orgId: project.orgId, projectId: project.projectId, project: opts.project, scanBranch };
29799
29844
  if (roster.fold) {
29800
29845
  const failed = await foldForRepos({ supabase, projectId: project.projectId, scanBranch }, roster.fold, "multi-repo add-repos", {
29801
29846
  foldBoard: deps.foldBoard,
@@ -29842,7 +29887,7 @@ async function prepareAddRepos(opts, deps = {}) {
29842
29887
  for (const clone of toPoll) {
29843
29888
  const out = await (deps.registerLocalWatch ?? register)({
29844
29889
  supabase,
29845
- orgId: authed2.orgId,
29890
+ orgId: project.orgId,
29846
29891
  projectId: project.projectId,
29847
29892
  repoPath: clone.root,
29848
29893
  originUrl: clone.originUrl,
@@ -30992,8 +31037,7 @@ async function alreadyOnBoard(opts, deps, root, repo) {
30992
31037
  return null;
30993
31038
  }
30994
31039
  }
30995
- async function ensureAppInstalled(opts, deps, owners2) {
30996
- const orgId = opts.authed.orgId;
31040
+ async function ensureAppInstalled(opts, deps, orgId, owners2) {
30997
31041
  const missing = async () => {
30998
31042
  const out = [];
30999
31043
  for (const owner of owners2) {
@@ -31029,7 +31073,6 @@ async function ensureAppInstalled(opts, deps, owners2) {
31029
31073
  async function runSetup(opts, deps, { workspace, cloneDir }, handoff) {
31030
31074
  const { authed: authed2, log } = opts;
31031
31075
  const supabase = authed2.supabase;
31032
- const orgId = authed2.orgId;
31033
31076
  if (opts.keyed && handoff.access === "github-app") {
31034
31077
  return { ok: false, reason: "this login has no account, so GitHub watch is not available (the GitHub App links to an account); use local watch (--local-watch)" };
31035
31078
  }
@@ -31053,7 +31096,8 @@ async function runSetup(opts, deps, { workspace, cloneDir }, handoff) {
31053
31096
  }
31054
31097
  if (handoff.access === "github-app") {
31055
31098
  const owners2 = [...new Set(handoff.repos.map((r) => r.repo.split("/")[0]))];
31056
- const notInstalled = await ensureAppInstalled(opts, deps, owners2);
31099
+ const orgId = existing?.orgId ?? await (deps.findOrgId ?? findOrgId)(supabase, handoff.project);
31100
+ const notInstalled = await ensureAppInstalled(opts, deps, orgId, owners2);
31057
31101
  if (notInstalled) return { ok: false, reason: notInstalled };
31058
31102
  }
31059
31103
  if (shape === "multi") {
@@ -31139,7 +31183,7 @@ async function runSetup(opts, deps, { workspace, cloneDir }, handoff) {
31139
31183
  if (handoff.access === "github-app") {
31140
31184
  const w = await (deps.watchRepo ?? watchRepoForProject)({
31141
31185
  supabase,
31142
- orgId,
31186
+ orgId: project.orgId,
31143
31187
  projectId: project.projectId,
31144
31188
  repoSlug: target.target.repo,
31145
31189
  branch: target.target.repoBranch,
@@ -31236,7 +31280,7 @@ The scan did not finish (exit ${exitCode}). Run \`archme init\` here again to co
31236
31280
  if (target.ok) {
31237
31281
  const res = await (deps.registerLocalWatch ?? registerLocalWatch)({
31238
31282
  supabase: authed2.supabase,
31239
- orgId: authed2.orgId,
31283
+ orgId: project.orgId,
31240
31284
  projectId: project.projectId,
31241
31285
  repoPath: repo.root,
31242
31286
  originUrl: repo.originUrl,
@@ -31557,10 +31601,10 @@ ${fullSlug} already holds other repos, so ${git4.repoSlug} needs its own contain
31557
31601
  const target = resolveInitTarget({ originUrl: git4.originUrl, detectedDefaultBranch: git4.branch, archmeBranchOverride: scanBranch });
31558
31602
  if (!target.ok) throw new Error(target.error);
31559
31603
  const owner = git4.repoSlug.split("/")[0];
31560
- const app = !keyed && authed2.orgId ? (await (deps.findInstallation ?? findInstallation)(authed2.supabase, authed2.orgId, owner)).ok : false;
31604
+ const app = !keyed && project.orgId ? (await (deps.findInstallation ?? findInstallation)(authed2.supabase, project.orgId, owner)).ok : false;
31561
31605
  log(`\u2192 ${fullSlug} already holds other repos: adding ${git4.repoSlug} in its own container (${app ? "GitHub watch" : "local watch"})`);
31562
31606
  const added = await (deps.addRepoToBoard ?? addRepoToBoard)(
31563
- { authed: authed2, orgId: authed2.orgId, projectId: project.projectId, project: fullSlug, scanBranch },
31607
+ { authed: authed2, orgId: project.orgId, projectId: project.projectId, project: fullSlug, scanBranch },
31564
31608
  { root: repoPath, originUrl: git4.originUrl, target: target.target, local: !app, interactive },
31565
31609
  { log }
31566
31610
  );
@@ -31583,7 +31627,7 @@ ${fullSlug} already holds other repos, so ${git4.repoSlug} needs its own contain
31583
31627
  }
31584
31628
  const watched = await watchRepo({
31585
31629
  supabase: authed2.supabase,
31586
- orgId: authed2.orgId,
31630
+ orgId: project.orgId,
31587
31631
  projectId: project.projectId,
31588
31632
  repoSlug: git4.repoSlug,
31589
31633
  branch: git4.branch,
@@ -31652,10 +31696,10 @@ Your board: ${webUrl}`);
31652
31696
  startGitHubAppInstall: () => (deps.buildInstallUrl ?? buildInstallUrl)({
31653
31697
  supabaseUrl: cfg.supabaseUrl,
31654
31698
  accessToken: getCurrentAccessToken() ?? "",
31655
- orgId: authed2.orgId
31699
+ orgId: project.orgId
31656
31700
  }),
31657
31701
  waitForInstallation: () => (deps.waitForInstallation ?? waitForInstallation)({
31658
- hasInstallation: () => (deps.orgHasInstallation ?? orgHasInstallation)(authed2.supabase, authed2.orgId),
31702
+ hasInstallation: () => (deps.orgHasInstallation ?? orgHasInstallation)(authed2.supabase, project.orgId),
31659
31703
  sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
31660
31704
  now: () => Date.now(),
31661
31705
  log
@@ -31663,7 +31707,7 @@ Your board: ${webUrl}`);
31663
31707
  watchRepo: async () => {
31664
31708
  const w = await watchRepo({
31665
31709
  supabase: authed2.supabase,
31666
- orgId: authed2.orgId,
31710
+ orgId: project.orgId,
31667
31711
  projectId: project.projectId,
31668
31712
  repoSlug: git4.repoSlug,
31669
31713
  branch: git4.branch,
@@ -31686,7 +31730,7 @@ Your board: ${webUrl}`);
31686
31730
  if (!target.ok) return { ok: false, reason: target.error };
31687
31731
  const res = await (deps.registerLocalWatch ?? registerLocalWatch)({
31688
31732
  supabase: authed2.supabase,
31689
- orgId: authed2.orgId,
31733
+ orgId: project.orgId,
31690
31734
  projectId: project.projectId,
31691
31735
  repoPath: git4.root,
31692
31736
  originUrl: git4.originUrl,
@@ -31704,7 +31748,7 @@ Your board: ${webUrl}`);
31704
31748
  if (outcome.localWatchRegistered && registered.watchedRepoId && deps.offerPrReviews) {
31705
31749
  await deps.offerPrReviews({
31706
31750
  supabase: authed2.supabase,
31707
- orgId: authed2.orgId,
31751
+ orgId: project.orgId,
31708
31752
  projectId: project.projectId,
31709
31753
  watchedRepoId: registered.watchedRepoId,
31710
31754
  repoSlug: git4.repoSlug,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archme/cli",
3
- "version": "0.25.2",
3
+ "version": "0.25.3",
4
4
  "description": "Map your codebase into a living architecture diagram: run `archme init` in a repo to scan it, `archme daemon start` to keep it current on every commit.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "image": "ghcr.io/architectme/archme-job",
3
- "digest": "sha256:8c54e1436285bb4f661a4088911b80c9050289333ebab063c207292f3c6b5fbc"
3
+ "digest": "sha256:46805fb6e8c6d858d5139da90026a47041ddb492304e4b316b9ef3097d4fdc2f"
4
4
  }