@archme/cli 0.25.2 → 0.26.0

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
@@ -18982,14 +18982,15 @@ function observeGithubPull(p) {
18982
18982
  // Before the merge it is GitHub's throwaway test merge.
18983
18983
  mergeCommitSha: p.merged_at ? p.merge_commit_sha ?? null : null,
18984
18984
  headRepo: p.head.repo?.full_name ?? null,
18985
- baseRepo: p.base.repo?.full_name ?? null
18985
+ baseRepo: p.base.repo?.full_name ?? null,
18986
+ draft: p.draft === true
18986
18987
  };
18987
18988
  }
18988
18989
  function metaKey(o2) {
18989
18990
  return createHash3("sha256").update(JSON.stringify([o2.title, o2.body])).digest("hex").slice(0, 16);
18990
18991
  }
18991
18992
  function record(o2, prev, action) {
18992
- const r = { head: o2.headSha, state: o2.state, meta: metaKey(o2), html: true };
18993
+ const r = { head: o2.headSha, state: o2.state, meta: metaKey(o2), html: true, draft: o2.draft };
18993
18994
  const seq = action === "synchronize" ? (prev?.seq ?? 0) + 1 : prev?.seq;
18994
18995
  if (seq !== void 0) r.seq = seq;
18995
18996
  return r;
@@ -19001,9 +19002,12 @@ function decideAction(prev, o2) {
19001
19002
  if (wasOpen && !isOpen) return "closed";
19002
19003
  if (!wasOpen && isOpen) return "reopened";
19003
19004
  if (isOpen && prev.head !== o2.headSha) return "synchronize";
19005
+ if (isOpen && prev.draft !== void 0 && prev.draft !== o2.draft) {
19006
+ return o2.draft ? "converted_to_draft" : "ready_for_review";
19007
+ }
19004
19008
  if (!isOpen && prev.state !== o2.state) return "edited";
19005
19009
  if (prev.meta !== void 0 && prev.meta !== metaKey(o2)) return "edited";
19006
- if (isOpen && !prev.html) return "edited";
19010
+ if (isOpen && (!prev.html || prev.draft === void 0)) return "edited";
19007
19011
  return null;
19008
19012
  }
19009
19013
  function toItem(o2, action, sent) {
@@ -19023,6 +19027,7 @@ function toItem(o2, action, sent) {
19023
19027
  body_html: o2.bodyHtml,
19024
19028
  head_repo: o2.headRepo,
19025
19029
  ...o2.baseRepo ? { base_repo: o2.baseRepo } : {},
19030
+ draft: o2.draft,
19026
19031
  ...action === "synchronize" && sent.seq !== void 0 ? { seq: sent.seq } : {}
19027
19032
  };
19028
19033
  }
@@ -19072,6 +19077,7 @@ function parsePrPollState(raw) {
19072
19077
  if (typeof r.meta === "string") entry.meta = r.meta;
19073
19078
  if (Number.isInteger(r.seq) && r.seq > 0) entry.seq = r.seq;
19074
19079
  if (r.html === true) entry.html = true;
19080
+ if (typeof r.draft === "boolean") entry.draft = r.draft;
19075
19081
  prs[k] = entry;
19076
19082
  }
19077
19083
  }
@@ -19791,6 +19797,10 @@ async function pollPrsOnce(entry, deps) {
19791
19797
  deps.log(
19792
19798
  fork ? ` ${repo}: PR #${item.number} ${item.action} \u2192 held: it comes from a fork, and a locally watched repo does not review fork pull requests (there is no way to approve one without the GitHub App).` : ` ${repo}: PR #${item.number} ${item.action} \u2192 held: the server did not approve it for review (its head repo could not be confirmed as this repo, e.g. GitHub did not report it).`
19793
19799
  );
19800
+ } else if (kind === "draft_held") {
19801
+ deps.log(
19802
+ ` ${repo}: PR #${item.number} ${item.action} \u2192 draft: not reviewed until it is marked ready for review, or Scan is pressed in ArchMe.`
19803
+ );
19794
19804
  } else if (kind !== void 0) {
19795
19805
  deps.log(` ${repo}: PR #${item.number} ${item.action} \u2192 ${kind}`);
19796
19806
  }
@@ -22776,6 +22786,7 @@ async function resolveOrCreateProject(supabase, userId, fullSlug) {
22776
22786
  );
22777
22787
  }
22778
22788
  return {
22789
+ orgId: org.id,
22779
22790
  orgSlug: org.slug,
22780
22791
  projectSlug,
22781
22792
  projectId,
@@ -22810,6 +22821,7 @@ async function claimSignupDefaultProject(supabase, org, projectSlug) {
22810
22821
  const { error: renameErr } = await supabase.from("projects").update({ name: projectSlug, slug: projectSlug }).eq("id", row.id);
22811
22822
  if (renameErr) return null;
22812
22823
  return {
22824
+ orgId: org.id,
22813
22825
  orgSlug: org.slug,
22814
22826
  projectSlug,
22815
22827
  projectId: row.id,
@@ -22830,6 +22842,16 @@ async function findProject(supabase, fullSlug) {
22830
22842
  if (!org) throw new Error(`org \`${orgSlug}\` not found`);
22831
22843
  return fetchExistingProject(supabase, org, projectSlug);
22832
22844
  }
22845
+ async function findOrgId(supabase, fullSlug) {
22846
+ const orgSlug = fullSlug.split("/")[0];
22847
+ if (!orgSlug) throw new Error(`invalid project slug \`${fullSlug}\` \u2014 expected \`org/project\``);
22848
+ const org = await mustQuery(
22849
+ supabase.from("organizations").select("id").eq("slug", orgSlug).maybeSingle(),
22850
+ "org lookup failed"
22851
+ );
22852
+ if (!org) throw new Error(`org \`${orgSlug}\` not found`);
22853
+ return org.id;
22854
+ }
22833
22855
  async function fetchExistingProject(supabase, org, projectSlug) {
22834
22856
  const project = await mustQuery(
22835
22857
  supabase.from("projects").select("id, slug").eq("org_id", org.id).eq("slug", projectSlug).is("deleted_at", null).maybeSingle(),
@@ -22845,6 +22867,7 @@ async function fetchExistingProject(supabase, org, projectSlug) {
22845
22867
  const defaultBranch = rows.find((b) => b.is_default)?.name ?? DEFAULT_BRANCH_NAME;
22846
22868
  const architectureBranch = resolveArchitectureBranchName(rows.map((b) => ({ name: b.name, isDefault: b.is_default }))) ?? defaultBranch;
22847
22869
  return {
22870
+ orgId: org.id,
22848
22871
  orgSlug: org.slug,
22849
22872
  projectSlug,
22850
22873
  projectId,
@@ -27033,6 +27056,24 @@ var init_githubInstallations = __esm({
27033
27056
  }
27034
27057
  });
27035
27058
 
27059
+ // src/auth/machineOrgs.ts
27060
+ async function readMachineOrgIds() {
27061
+ try {
27062
+ const { credentials } = await loadAllCredentials(resolveConfig().supabaseUrl);
27063
+ const orgs = credentials.flatMap((c3) => c3.bindings?.length ? c3.bindings.map((b) => b.org_id) : [c3.org_id]);
27064
+ return orgs.length ? new Set(orgs) : null;
27065
+ } catch {
27066
+ return null;
27067
+ }
27068
+ }
27069
+ var init_machineOrgs = __esm({
27070
+ "src/auth/machineOrgs.ts"() {
27071
+ "use strict";
27072
+ init_defaults();
27073
+ init_credentials();
27074
+ }
27075
+ });
27076
+
27036
27077
  // src/init/watchRepo.ts
27037
27078
  async function findInstallation(supabase, orgId, owner) {
27038
27079
  const { data: installs, error: installErr } = await supabase.from("org_github_installations").select("installation_id").eq("org_id", orgId);
@@ -27102,12 +27143,18 @@ async function watchRepoForProject(input) {
27102
27143
  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
27144
  };
27104
27145
  }
27146
+ if ((await readMachineOrgIds())?.has(orgId) === false) {
27147
+ input.log?.(
27148
+ " ! 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."
27149
+ );
27150
+ }
27105
27151
  return { watched: true };
27106
27152
  }
27107
27153
  var init_watchRepo = __esm({
27108
27154
  "src/init/watchRepo.ts"() {
27109
27155
  "use strict";
27110
27156
  init_githubInstallations();
27157
+ init_machineOrgs();
27111
27158
  }
27112
27159
  });
27113
27160
 
@@ -27419,7 +27466,7 @@ async function runLocalWatch(opts) {
27419
27466
  log(` project: ${project.orgSlug}/${project.projectSlug}${project.created ? " (created)" : ""}`);
27420
27467
  const registered = await registerLocalWatch({
27421
27468
  supabase,
27422
- orgId,
27469
+ orgId: project.orgId,
27423
27470
  projectId: project.projectId,
27424
27471
  repoPath,
27425
27472
  originUrl,
@@ -27452,6 +27499,12 @@ async function runLocalWatch(opts) {
27452
27499
  return 0;
27453
27500
  }
27454
27501
  async function watchLocalRepoRow(args) {
27502
+ if ((await readMachineOrgIds())?.has(args.orgId) === false) {
27503
+ return {
27504
+ ok: false,
27505
+ 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."
27506
+ };
27507
+ }
27455
27508
  const { data, error } = await args.supabase.rpc("watch_local_repo", {
27456
27509
  p_org_id: args.orgId,
27457
27510
  p_project_id: args.projectId,
@@ -27631,6 +27684,7 @@ var init_localWatch = __esm({
27631
27684
  init_localGit();
27632
27685
  init_localRepos();
27633
27686
  init_branchMarker();
27687
+ init_machineOrgs();
27634
27688
  init_localWatchList();
27635
27689
  init_localWatchResolve();
27636
27690
  init_prompt();
@@ -28657,7 +28711,7 @@ async function runAddRepo(opts, deps = {}) {
28657
28711
  const project = await (deps.resolveProject ?? resolveOrCreateProject)(authed2.supabase, authed2.userId, opts.project);
28658
28712
  const scanBranch = initScanBranch(project.defaultBranch);
28659
28713
  const added = await addRepoToBoard(
28660
- { authed: authed2, orgId: authed2.orgId, projectId: project.projectId, project: opts.project, scanBranch },
28714
+ { authed: authed2, orgId: project.orgId, projectId: project.projectId, project: opts.project, scanBranch },
28661
28715
  {
28662
28716
  root: inspected.root,
28663
28717
  originUrl: inspected.originUrl,
@@ -29770,10 +29824,11 @@ async function prepareAddRepos(opts, deps = {}) {
29770
29824
  if (unscannable.length) return fail2(78, `${unscannable.join("\n ")}
29771
29825
  Nothing was changed.`);
29772
29826
  const watching = [...todo, ...toWatch];
29827
+ const orgId = existing?.orgId ?? await (deps.findOrgId ?? findOrgId)(supabase, opts.project);
29773
29828
  const elsewhere = [];
29774
29829
  for (const c3 of watching) {
29775
29830
  const holder = await (deps.watchedElsewhere ?? watchedElsewhere)(supabase, {
29776
- orgId: authed2.orgId,
29831
+ orgId,
29777
29832
  projectId: existing?.projectId ?? null,
29778
29833
  target: c3.target
29779
29834
  });
@@ -29786,7 +29841,7 @@ async function prepareAddRepos(opts, deps = {}) {
29786
29841
  if (!opts.local) {
29787
29842
  const missing = [];
29788
29843
  for (const c3 of watching) {
29789
- const found = await (deps.findInstallation ?? findInstallation)(supabase, authed2.orgId, c3.target.repoOwner);
29844
+ const found = await (deps.findInstallation ?? findInstallation)(supabase, orgId, c3.target.repoOwner);
29790
29845
  if (!found.ok) missing.push(`${c3.target.repo}: ${found.reason}`);
29791
29846
  }
29792
29847
  if (missing.length) {
@@ -29795,7 +29850,7 @@ async function prepareAddRepos(opts, deps = {}) {
29795
29850
  }
29796
29851
  }
29797
29852
  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 };
29853
+ const board = { authed: authed2, orgId: project.orgId, projectId: project.projectId, project: opts.project, scanBranch };
29799
29854
  if (roster.fold) {
29800
29855
  const failed = await foldForRepos({ supabase, projectId: project.projectId, scanBranch }, roster.fold, "multi-repo add-repos", {
29801
29856
  foldBoard: deps.foldBoard,
@@ -29842,7 +29897,7 @@ async function prepareAddRepos(opts, deps = {}) {
29842
29897
  for (const clone of toPoll) {
29843
29898
  const out = await (deps.registerLocalWatch ?? register)({
29844
29899
  supabase,
29845
- orgId: authed2.orgId,
29900
+ orgId: project.orgId,
29846
29901
  projectId: project.projectId,
29847
29902
  repoPath: clone.root,
29848
29903
  originUrl: clone.originUrl,
@@ -30992,8 +31047,7 @@ async function alreadyOnBoard(opts, deps, root, repo) {
30992
31047
  return null;
30993
31048
  }
30994
31049
  }
30995
- async function ensureAppInstalled(opts, deps, owners2) {
30996
- const orgId = opts.authed.orgId;
31050
+ async function ensureAppInstalled(opts, deps, orgId, owners2) {
30997
31051
  const missing = async () => {
30998
31052
  const out = [];
30999
31053
  for (const owner of owners2) {
@@ -31029,7 +31083,6 @@ async function ensureAppInstalled(opts, deps, owners2) {
31029
31083
  async function runSetup(opts, deps, { workspace, cloneDir }, handoff) {
31030
31084
  const { authed: authed2, log } = opts;
31031
31085
  const supabase = authed2.supabase;
31032
- const orgId = authed2.orgId;
31033
31086
  if (opts.keyed && handoff.access === "github-app") {
31034
31087
  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
31088
  }
@@ -31053,7 +31106,8 @@ async function runSetup(opts, deps, { workspace, cloneDir }, handoff) {
31053
31106
  }
31054
31107
  if (handoff.access === "github-app") {
31055
31108
  const owners2 = [...new Set(handoff.repos.map((r) => r.repo.split("/")[0]))];
31056
- const notInstalled = await ensureAppInstalled(opts, deps, owners2);
31109
+ const orgId = existing?.orgId ?? await (deps.findOrgId ?? findOrgId)(supabase, handoff.project);
31110
+ const notInstalled = await ensureAppInstalled(opts, deps, orgId, owners2);
31057
31111
  if (notInstalled) return { ok: false, reason: notInstalled };
31058
31112
  }
31059
31113
  if (shape === "multi") {
@@ -31139,7 +31193,7 @@ async function runSetup(opts, deps, { workspace, cloneDir }, handoff) {
31139
31193
  if (handoff.access === "github-app") {
31140
31194
  const w = await (deps.watchRepo ?? watchRepoForProject)({
31141
31195
  supabase,
31142
- orgId,
31196
+ orgId: project.orgId,
31143
31197
  projectId: project.projectId,
31144
31198
  repoSlug: target.target.repo,
31145
31199
  branch: target.target.repoBranch,
@@ -31236,7 +31290,7 @@ The scan did not finish (exit ${exitCode}). Run \`archme init\` here again to co
31236
31290
  if (target.ok) {
31237
31291
  const res = await (deps.registerLocalWatch ?? registerLocalWatch)({
31238
31292
  supabase: authed2.supabase,
31239
- orgId: authed2.orgId,
31293
+ orgId: project.orgId,
31240
31294
  projectId: project.projectId,
31241
31295
  repoPath: repo.root,
31242
31296
  originUrl: repo.originUrl,
@@ -31557,10 +31611,10 @@ ${fullSlug} already holds other repos, so ${git4.repoSlug} needs its own contain
31557
31611
  const target = resolveInitTarget({ originUrl: git4.originUrl, detectedDefaultBranch: git4.branch, archmeBranchOverride: scanBranch });
31558
31612
  if (!target.ok) throw new Error(target.error);
31559
31613
  const owner = git4.repoSlug.split("/")[0];
31560
- const app = !keyed && authed2.orgId ? (await (deps.findInstallation ?? findInstallation)(authed2.supabase, authed2.orgId, owner)).ok : false;
31614
+ const app = !keyed && project.orgId ? (await (deps.findInstallation ?? findInstallation)(authed2.supabase, project.orgId, owner)).ok : false;
31561
31615
  log(`\u2192 ${fullSlug} already holds other repos: adding ${git4.repoSlug} in its own container (${app ? "GitHub watch" : "local watch"})`);
31562
31616
  const added = await (deps.addRepoToBoard ?? addRepoToBoard)(
31563
- { authed: authed2, orgId: authed2.orgId, projectId: project.projectId, project: fullSlug, scanBranch },
31617
+ { authed: authed2, orgId: project.orgId, projectId: project.projectId, project: fullSlug, scanBranch },
31564
31618
  { root: repoPath, originUrl: git4.originUrl, target: target.target, local: !app, interactive },
31565
31619
  { log }
31566
31620
  );
@@ -31583,7 +31637,7 @@ ${fullSlug} already holds other repos, so ${git4.repoSlug} needs its own contain
31583
31637
  }
31584
31638
  const watched = await watchRepo({
31585
31639
  supabase: authed2.supabase,
31586
- orgId: authed2.orgId,
31640
+ orgId: project.orgId,
31587
31641
  projectId: project.projectId,
31588
31642
  repoSlug: git4.repoSlug,
31589
31643
  branch: git4.branch,
@@ -31652,10 +31706,10 @@ Your board: ${webUrl}`);
31652
31706
  startGitHubAppInstall: () => (deps.buildInstallUrl ?? buildInstallUrl)({
31653
31707
  supabaseUrl: cfg.supabaseUrl,
31654
31708
  accessToken: getCurrentAccessToken() ?? "",
31655
- orgId: authed2.orgId
31709
+ orgId: project.orgId
31656
31710
  }),
31657
31711
  waitForInstallation: () => (deps.waitForInstallation ?? waitForInstallation)({
31658
- hasInstallation: () => (deps.orgHasInstallation ?? orgHasInstallation)(authed2.supabase, authed2.orgId),
31712
+ hasInstallation: () => (deps.orgHasInstallation ?? orgHasInstallation)(authed2.supabase, project.orgId),
31659
31713
  sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
31660
31714
  now: () => Date.now(),
31661
31715
  log
@@ -31663,7 +31717,7 @@ Your board: ${webUrl}`);
31663
31717
  watchRepo: async () => {
31664
31718
  const w = await watchRepo({
31665
31719
  supabase: authed2.supabase,
31666
- orgId: authed2.orgId,
31720
+ orgId: project.orgId,
31667
31721
  projectId: project.projectId,
31668
31722
  repoSlug: git4.repoSlug,
31669
31723
  branch: git4.branch,
@@ -31686,7 +31740,7 @@ Your board: ${webUrl}`);
31686
31740
  if (!target.ok) return { ok: false, reason: target.error };
31687
31741
  const res = await (deps.registerLocalWatch ?? registerLocalWatch)({
31688
31742
  supabase: authed2.supabase,
31689
- orgId: authed2.orgId,
31743
+ orgId: project.orgId,
31690
31744
  projectId: project.projectId,
31691
31745
  repoPath: git4.root,
31692
31746
  originUrl: git4.originUrl,
@@ -31704,7 +31758,7 @@ Your board: ${webUrl}`);
31704
31758
  if (outcome.localWatchRegistered && registered.watchedRepoId && deps.offerPrReviews) {
31705
31759
  await deps.offerPrReviews({
31706
31760
  supabase: authed2.supabase,
31707
- orgId: authed2.orgId,
31761
+ orgId: project.orgId,
31708
31762
  projectId: project.projectId,
31709
31763
  watchedRepoId: registered.watchedRepoId,
31710
31764
  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.26.0",
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:eba064bd85a35bf697038defe2bfcadad4c508bc810ef552431344760874e061"
4
4
  }