@archme/cli 0.28.0 → 0.29.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 +118 -4
- package/package.json +1 -1
- package/sandbox-image.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -27155,7 +27155,11 @@ var init_scanBranch = __esm({
|
|
|
27155
27155
|
// ../shared/githubInstallations.ts
|
|
27156
27156
|
function installationForOwner(installs, owner) {
|
|
27157
27157
|
const key = owner.toLowerCase();
|
|
27158
|
-
|
|
27158
|
+
let newest = null;
|
|
27159
|
+
for (const i2 of installs) {
|
|
27160
|
+
if (i2.account_login.toLowerCase() === key && (!newest || i2.installation_id > newest.installation_id)) newest = i2;
|
|
27161
|
+
}
|
|
27162
|
+
return newest;
|
|
27159
27163
|
}
|
|
27160
27164
|
var init_githubInstallations = __esm({
|
|
27161
27165
|
"../shared/githubInstallations.ts"() {
|
|
@@ -29436,6 +29440,71 @@ var init_plan = __esm({
|
|
|
29436
29440
|
}
|
|
29437
29441
|
});
|
|
29438
29442
|
|
|
29443
|
+
// src/init/selfScanGate.ts
|
|
29444
|
+
function decideSelfScan(state) {
|
|
29445
|
+
return state === "requested" || state === "queued" || state === "scanning" ? "takeover" : "carry-on";
|
|
29446
|
+
}
|
|
29447
|
+
function takeoverLine(repo) {
|
|
29448
|
+
return `You'd asked ArchMe to scan ${repo}; you're scanning it yourself now, so that request is closed.`;
|
|
29449
|
+
}
|
|
29450
|
+
async function selfScanPreflight(deps, ctx) {
|
|
29451
|
+
return postTakeover(deps, ctx, (await checkSelfScan(deps, ctx)).takeover);
|
|
29452
|
+
}
|
|
29453
|
+
async function checkSelfScan(deps, ctx) {
|
|
29454
|
+
if (ctx.keyed || !ctx.orgId || !ctx.repoSlug) return { takeover: false };
|
|
29455
|
+
try {
|
|
29456
|
+
return { takeover: decideSelfScan((await deps.fetchState(ctx.orgId, ctx.repoSlug)).state) === "takeover" };
|
|
29457
|
+
} catch (err4) {
|
|
29458
|
+
deps.log(` ! couldn't check whether ArchMe was asked to scan ${ctx.repoSlug} (${err4 instanceof Error ? err4.message : String(err4)}) \u2014 going ahead`);
|
|
29459
|
+
return { takeover: false };
|
|
29460
|
+
}
|
|
29461
|
+
}
|
|
29462
|
+
async function postTakeover(deps, ctx, takeover) {
|
|
29463
|
+
if (!takeover || !ctx.orgId || !ctx.repoSlug) return { go: true, tookOver: false };
|
|
29464
|
+
try {
|
|
29465
|
+
await deps.postSelfScan(ctx.orgId, ctx.repoSlug);
|
|
29466
|
+
} catch (err4) {
|
|
29467
|
+
deps.log(`
|
|
29468
|
+
archme init: couldn't close your request to ArchMe for ${ctx.repoSlug} (${err4 instanceof Error ? err4.message : String(err4)}). Nothing was scanned; try again.`);
|
|
29469
|
+
return { go: false, exitCode: 1 };
|
|
29470
|
+
}
|
|
29471
|
+
deps.log(takeoverLine(ctx.repoSlug));
|
|
29472
|
+
return { go: true, tookOver: true };
|
|
29473
|
+
}
|
|
29474
|
+
async function invoke(client, path7, body) {
|
|
29475
|
+
const { data, error } = await client.functions.invoke(path7, { body });
|
|
29476
|
+
if (error) {
|
|
29477
|
+
let detail = error.message;
|
|
29478
|
+
const ctx = error.context;
|
|
29479
|
+
if (ctx instanceof Response) {
|
|
29480
|
+
const b = await ctx.json().catch(() => null);
|
|
29481
|
+
detail = `${ctx.status} ${typeof b?.error === "string" ? b.error : typeof b?.status === "string" ? b.status : ""}`.trim();
|
|
29482
|
+
}
|
|
29483
|
+
throw new Error(detail);
|
|
29484
|
+
}
|
|
29485
|
+
return data;
|
|
29486
|
+
}
|
|
29487
|
+
function selfScanDeps(client, log) {
|
|
29488
|
+
return {
|
|
29489
|
+
fetchState: async (orgId, repo) => {
|
|
29490
|
+
const data = await invoke(client, "notifications/scan-state", { org_id: orgId, repo });
|
|
29491
|
+
if (!data || typeof data.state !== "string") throw new Error("malformed scan-state response");
|
|
29492
|
+
return data;
|
|
29493
|
+
},
|
|
29494
|
+
postSelfScan: async (orgId, repo) => {
|
|
29495
|
+
await invoke(client, "notifications/self-scan", { org_id: orgId, repo });
|
|
29496
|
+
},
|
|
29497
|
+
log
|
|
29498
|
+
};
|
|
29499
|
+
}
|
|
29500
|
+
var TAKEOVER_FAILED_NOTE;
|
|
29501
|
+
var init_selfScanGate = __esm({
|
|
29502
|
+
"src/init/selfScanGate.ts"() {
|
|
29503
|
+
"use strict";
|
|
29504
|
+
TAKEOVER_FAILED_NOTE = "Your request to ArchMe was closed when this scan started \u2014 re-run `archme init` here, or request a scan again from your board.";
|
|
29505
|
+
}
|
|
29506
|
+
});
|
|
29507
|
+
|
|
29439
29508
|
// src/uninstall/edits.ts
|
|
29440
29509
|
function stripArchmeClaudeBlock(content) {
|
|
29441
29510
|
const start = content.indexOf(START_MARKER);
|
|
@@ -31332,6 +31401,27 @@ async function runSetup(opts, deps, { workspace, cloneDir }, handoff) {
|
|
|
31332
31401
|
return { ok: false, reason: e instanceof Error ? e.message : String(e) };
|
|
31333
31402
|
}
|
|
31334
31403
|
}
|
|
31404
|
+
function guidedSelfScanDeps(opts, deps) {
|
|
31405
|
+
return deps.selfScan ?? selfScanDeps(opts.authed.supabase, opts.log);
|
|
31406
|
+
}
|
|
31407
|
+
async function guidedSelfScan(opts, deps, orgId, repos) {
|
|
31408
|
+
const ssDeps = guidedSelfScanDeps(opts, deps);
|
|
31409
|
+
const checked = [];
|
|
31410
|
+
for (const repo of repos) {
|
|
31411
|
+
const ctx = { keyed: opts.keyed, orgId, repoSlug: repo };
|
|
31412
|
+
checked.push({ ctx, takeover: (await checkSelfScan(ssDeps, ctx)).takeover });
|
|
31413
|
+
}
|
|
31414
|
+
let tookOver = false;
|
|
31415
|
+
for (const { ctx, takeover } of checked) {
|
|
31416
|
+
const posted = await postTakeover(ssDeps, ctx, takeover);
|
|
31417
|
+
if (!posted.go) {
|
|
31418
|
+
if (tookOver) opts.log(TAKEOVER_FAILED_NOTE);
|
|
31419
|
+
return posted;
|
|
31420
|
+
}
|
|
31421
|
+
tookOver ||= posted.tookOver;
|
|
31422
|
+
}
|
|
31423
|
+
return { go: true, tookOver };
|
|
31424
|
+
}
|
|
31335
31425
|
async function offerDaemon(deps, interactive, log) {
|
|
31336
31426
|
if (!interactive) return false;
|
|
31337
31427
|
if (!await (deps.confirm ?? ((q) => promptYesNo(q)))(DAEMON_QUESTION)) return false;
|
|
@@ -31366,6 +31456,8 @@ async function buildSingle(opts, deps, setup, handoff, conversation, interactive
|
|
|
31366
31456
|
if (!opts.force && (setup.scanned || setup.architectureExists && !resumedBuild)) {
|
|
31367
31457
|
log(`\u2713 ${fullSlug} already has an architecture for ${repo.repo} \u2014 not rescanned (archme init --force rescans it)`);
|
|
31368
31458
|
} else {
|
|
31459
|
+
const pre = await guidedSelfScan(opts, deps, project.orgId, [repo.repo]);
|
|
31460
|
+
if (!pre.go) return { exitCode: pre.exitCode, project: fullSlug, branch: scanBranch, webUrl };
|
|
31369
31461
|
const measurement = await (deps.measure ?? measureRepo)(repo.root);
|
|
31370
31462
|
const briefing = formatRepoBriefing(measurement, repo.root, { project: fullSlug, branch: scanBranch });
|
|
31371
31463
|
log("\u2192 back to Claude Code for the scan \u2014 it will confirm before scanning");
|
|
@@ -31383,6 +31475,7 @@ async function buildSingle(opts, deps, setup, handoff, conversation, interactive
|
|
|
31383
31475
|
if (exitCode !== 0) {
|
|
31384
31476
|
log(`
|
|
31385
31477
|
The scan did not finish (exit ${exitCode}). Run \`archme init\` here again to continue it.`);
|
|
31478
|
+
if (pre.tookOver) log(TAKEOVER_FAILED_NOTE);
|
|
31386
31479
|
return { exitCode, project: fullSlug, branch: scanBranch, webUrl };
|
|
31387
31480
|
}
|
|
31388
31481
|
log(`
|
|
@@ -31446,6 +31539,9 @@ async function buildMulti(opts, deps, setup, handoff, conversation, interactive,
|
|
|
31446
31539
|
if (setup.prepared.kind === "ready") {
|
|
31447
31540
|
const { prepared } = setup.prepared;
|
|
31448
31541
|
projectId = prepared.project.projectId;
|
|
31542
|
+
const pre = await guidedSelfScan(opts, deps, prepared.project.orgId, prepared.todo.map((c3) => c3.target.repo));
|
|
31543
|
+
if (!pre.go) return { exitCode: pre.exitCode, project: setup.project, branch: setup.scanBranch, webUrl: "" };
|
|
31544
|
+
const { tookOver } = pre;
|
|
31449
31545
|
const out = await (deps.runPreparedAddRepos ?? runPreparedAddRepos)(
|
|
31450
31546
|
prepared,
|
|
31451
31547
|
{ interactive, conversation, rerun: "archme init", daemonNote: false },
|
|
@@ -31453,6 +31549,7 @@ async function buildMulti(opts, deps, setup, handoff, conversation, interactive,
|
|
|
31453
31549
|
);
|
|
31454
31550
|
exitCode = out.exitCode;
|
|
31455
31551
|
webUrl = out.webUrl;
|
|
31552
|
+
if (exitCode !== 0 && tookOver) log(TAKEOVER_FAILED_NOTE);
|
|
31456
31553
|
reviewed = [...out.added, ...prepared.done.map((c3) => c3.target.repo)];
|
|
31457
31554
|
} else if (setup.prepared.kind === "done") {
|
|
31458
31555
|
const found = await (deps.findProject ?? findProject)(opts.authed.supabase, setup.project);
|
|
@@ -31494,6 +31591,7 @@ var init_guided = __esm({
|
|
|
31494
31591
|
init_localGit();
|
|
31495
31592
|
init_prompt();
|
|
31496
31593
|
init_run3();
|
|
31594
|
+
init_selfScanGate();
|
|
31497
31595
|
init_run2();
|
|
31498
31596
|
init_repoContainer();
|
|
31499
31597
|
init_agentConfig();
|
|
@@ -31700,14 +31798,24 @@ async function runInit(opts, deps = {}) {
|
|
|
31700
31798
|
const architectureExists = detail.components.length > 0;
|
|
31701
31799
|
const ran = signedIn ? [] : ["login"];
|
|
31702
31800
|
ran.push("project");
|
|
31801
|
+
const onBoard = await (deps.boardRepos ?? readBoardRepos2)(authed2.supabase, project.projectId, scanBranch);
|
|
31802
|
+
const joint = !!git4.repoSlug && setupShape({ repos: 1, repo: git4.repoSlug, hasContainers: onBoard.hasContainers, boardRepos: onBoard.repos }) === "multi";
|
|
31803
|
+
let tookOver = false;
|
|
31804
|
+
const jointSkip = joint && opts.skipScan;
|
|
31805
|
+
if (!opts.skipScan && (joint || shouldRunScan({ architectureExists, force: opts.force }))) {
|
|
31806
|
+
const pre = await selfScanPreflight(
|
|
31807
|
+
deps.selfScan ?? selfScanDeps(authed2.supabase, log),
|
|
31808
|
+
{ keyed, orgId: project.orgId, repoSlug: git4.repoSlug ?? null }
|
|
31809
|
+
);
|
|
31810
|
+
if (!pre.go) return { exitCode: pre.exitCode, project: fullSlug, branch: scanBranch, webUrl: "", ran };
|
|
31811
|
+
tookOver = pre.tookOver;
|
|
31812
|
+
}
|
|
31703
31813
|
log("\u2192 installing agent config (.mcp.json, CLAUDE.md, architecture skill)\u2026");
|
|
31704
31814
|
await (deps.installAgentConfig ?? installAgentConfig)(
|
|
31705
31815
|
{ repoRoot: repoPath, mcpBaseUrl: cfg.archmeMcpBaseUrl, project: fullSlug, branch: scanBranch, log }
|
|
31706
31816
|
);
|
|
31707
31817
|
ran.push("agent-config");
|
|
31708
|
-
|
|
31709
|
-
const joint = !!git4.repoSlug && setupShape({ repos: 1, repo: git4.repoSlug, hasContainers: onBoard.hasContainers, boardRepos: onBoard.repos }) === "multi";
|
|
31710
|
-
if (joint && opts.skipScan) {
|
|
31818
|
+
if (jointSkip) {
|
|
31711
31819
|
log(`
|
|
31712
31820
|
${fullSlug} already holds other repos, so ${git4.repoSlug} needs its own container and scan before it is watched.`);
|
|
31713
31821
|
log(` Run \`archme add-repo --project ${fullSlug}\` here when you want it added.`);
|
|
@@ -31726,6 +31834,7 @@ ${fullSlug} already holds other repos, so ${git4.repoSlug} needs its own contain
|
|
|
31726
31834
|
);
|
|
31727
31835
|
if (!added.ok) {
|
|
31728
31836
|
if (added.reason) log(`archme init: ${added.reason}`);
|
|
31837
|
+
if (tookOver) log(TAKEOVER_FAILED_NOTE);
|
|
31729
31838
|
return { exitCode: added.exitCode, project: fullSlug, branch: scanBranch, webUrl: "", ran };
|
|
31730
31839
|
}
|
|
31731
31840
|
ran.push("scan");
|
|
@@ -31793,6 +31902,7 @@ Your board: ${webUrl}`);
|
|
|
31793
31902
|
});
|
|
31794
31903
|
ran.push("scan");
|
|
31795
31904
|
const finalUrl = result.webUrl || webUrl;
|
|
31905
|
+
if (result.exitCode !== 0 && tookOver) log(TAKEOVER_FAILED_NOTE);
|
|
31796
31906
|
if (result.exitCode === 0) {
|
|
31797
31907
|
log(`
|
|
31798
31908
|
\u2713 Done. Your architecture: ${finalUrl}`);
|
|
@@ -31930,6 +32040,7 @@ var init_run_init = __esm({
|
|
|
31930
32040
|
init_prompt();
|
|
31931
32041
|
init_localWatch();
|
|
31932
32042
|
init_plan();
|
|
32043
|
+
init_selfScanGate();
|
|
31933
32044
|
init_guided();
|
|
31934
32045
|
init_run2();
|
|
31935
32046
|
init_watchRepo();
|
|
@@ -32101,6 +32212,9 @@ for them). Then it sets everything up \u2014 clones,
|
|
|
32101
32212
|
project, watching, agent config \u2014 and continues the same conversation to scan:
|
|
32102
32213
|
one repo the usual way, several with one planned multi-repo bootstrap.
|
|
32103
32214
|
|
|
32215
|
+
If you asked ArchMe to scan a repo, running archme init there scans it yourself instead:
|
|
32216
|
+
your request is closed and ArchMe's queued or running scan is stopped first.
|
|
32217
|
+
|
|
32104
32218
|
Usage:
|
|
32105
32219
|
archme init [path] [options]
|
|
32106
32220
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@archme/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.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",
|
package/sandbox-image.json
CHANGED