@archme/cli 0.21.0 → 0.23.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
@@ -18756,12 +18756,12 @@ function defaultReadFile(path7) {
18756
18756
  return readFileSync4(path7, "utf8");
18757
18757
  }
18758
18758
  function findPackageRoot2(startDir, opts = {}) {
18759
- const readFile25 = opts.readFile ?? defaultReadFile;
18759
+ const readFile26 = opts.readFile ?? defaultReadFile;
18760
18760
  const stopAt = parse(startDir).root;
18761
18761
  let dir = startDir;
18762
18762
  for (; ; ) {
18763
18763
  try {
18764
- const parsed = JSON.parse(readFile25(join14(dir, "package.json")));
18764
+ const parsed = JSON.parse(readFile26(join14(dir, "package.json")));
18765
18765
  if (parsed.name === PACKAGE_NAME) return dir;
18766
18766
  } catch {
18767
18767
  }
@@ -18895,15 +18895,15 @@ async function materializeDiff(dir, patch, rangeLabel) {
18895
18895
  const files = splitPatchByFile(patch);
18896
18896
  await mkdir8(dir);
18897
18897
  await mkdir8(join16(dir, "by-file"));
18898
- const write = (path7, text) => writeFile7(join16(dir, path7), text.endsWith("\n") ? text : `${text}
18898
+ const write2 = (path7, text) => writeFile7(join16(dir, path7), text.endsWith("\n") ? text : `${text}
18899
18899
  `, { encoding: "utf8", flag: "wx" });
18900
- await write("FULL.diff", patch);
18900
+ await write2("FULL.diff", patch);
18901
18901
  for (const f of files) {
18902
18902
  const rel = `by-file/${hashPath(f.path)}.diff`;
18903
18903
  f.diffPath = rel;
18904
- await write(rel, f.diff);
18904
+ await write2(rel, f.diff);
18905
18905
  }
18906
- await write("MANIFEST.md", buildManifest(files, rangeLabel));
18906
+ await write2("MANIFEST.md", buildManifest(files, rangeLabel));
18907
18907
  return { dir, fileCount: files.length };
18908
18908
  }
18909
18909
  var STATUS_LABEL;
@@ -21437,7 +21437,7 @@ function filterHeaders(headers, drop) {
21437
21437
  }
21438
21438
  return out;
21439
21439
  }
21440
- function forward(req, res, target, headers, onResponse) {
21440
+ function forward(req, res, target, headers, onResponse, body) {
21441
21441
  return new Promise((resolve9) => {
21442
21442
  let settled = false;
21443
21443
  const settle = (r) => {
@@ -21486,7 +21486,8 @@ function forward(req, res, target, headers, onResponse) {
21486
21486
  settle({ status: "aborted" });
21487
21487
  }
21488
21488
  });
21489
- req.pipe(up);
21489
+ if (body) up.end(body);
21490
+ else req.pipe(up);
21490
21491
  });
21491
21492
  }
21492
21493
  var HOP_BY_HOP;
@@ -21509,6 +21510,49 @@ var init_gateServer = __esm({
21509
21510
  });
21510
21511
 
21511
21512
  // src/daemon/sandbox/credentialGate.ts
21513
+ function refusedCapability(body, betaHeader) {
21514
+ const betas = [betaHeader ?? []].flat().join(",").toLowerCase();
21515
+ if (betas.includes("mcp-client") || betas.includes("web-fetch")) return "beta";
21516
+ if (typeof body !== "object" || body === null || Array.isArray(body)) return "body";
21517
+ const b = body;
21518
+ if (b.mcp_servers !== void 0) return "mcp_servers";
21519
+ const tools = Array.isArray(b.tools) ? b.tools : [];
21520
+ for (const t of tools) {
21521
+ const type = t?.type;
21522
+ if (typeof type !== "string") continue;
21523
+ if (type.startsWith("web_fetch")) return "web_fetch";
21524
+ if (type.startsWith("code_execution")) return "code_execution";
21525
+ }
21526
+ const stack = [b.system, b.messages];
21527
+ while (stack.length) {
21528
+ const v = stack.pop();
21529
+ if (typeof v !== "object" || v === null) continue;
21530
+ const src = v.source;
21531
+ if (typeof src === "object" && src !== null && src.type === "url") return "url_source";
21532
+ stack.push(...Object.values(v));
21533
+ }
21534
+ return null;
21535
+ }
21536
+ function readBody(req, max, charge) {
21537
+ return new Promise((resolve9, reject) => {
21538
+ const chunks = [];
21539
+ let size = 0;
21540
+ const onData = (c3) => {
21541
+ size += c3.length;
21542
+ if (size > max || !charge(c3.length)) {
21543
+ req.off("data", onData);
21544
+ req.pause();
21545
+ resolve9(null);
21546
+ return;
21547
+ }
21548
+ chunks.push(c3);
21549
+ };
21550
+ req.on("data", onData);
21551
+ req.once("end", () => resolve9(Buffer.concat(chunks)));
21552
+ req.once("error", reject);
21553
+ req.once("close", () => reject(new Error("aborted")));
21554
+ });
21555
+ }
21512
21556
  function searchOf(url) {
21513
21557
  try {
21514
21558
  return new URL(url ?? "/", "http://gate").search;
@@ -21516,7 +21560,7 @@ function searchOf(url) {
21516
21560
  return "";
21517
21561
  }
21518
21562
  }
21519
- var ANTHROPIC_UPSTREAM, ALLOWED_PATHS, CredentialGate;
21563
+ var ANTHROPIC_UPSTREAM, ALLOWED_PATHS, MAX_BODY_BYTES, MAX_SLOT_BUFFERED_BYTES, CredentialGate;
21520
21564
  var init_credentialGate = __esm({
21521
21565
  "src/daemon/sandbox/credentialGate.ts"() {
21522
21566
  "use strict";
@@ -21524,6 +21568,8 @@ var init_credentialGate = __esm({
21524
21568
  init_types2();
21525
21569
  ANTHROPIC_UPSTREAM = "https://api.anthropic.com";
21526
21570
  ALLOWED_PATHS = /* @__PURE__ */ new Set(["/v1/messages", "/v1/messages/count_tokens"]);
21571
+ MAX_BODY_BYTES = 32 * 1024 * 1024;
21572
+ MAX_SLOT_BUFFERED_BYTES = 2 * MAX_BODY_BYTES;
21527
21573
  CredentialGate = class {
21528
21574
  constructor(opts) {
21529
21575
  this.opts = opts;
@@ -21539,13 +21585,15 @@ var init_credentialGate = __esm({
21539
21585
  }
21540
21586
  gate;
21541
21587
  upstream;
21588
+ /** Request-body bytes each slot holds right now, until its forward settles. */
21589
+ buffered = /* @__PURE__ */ new Map();
21542
21590
  listen() {
21543
21591
  return this.gate.listen();
21544
21592
  }
21545
21593
  close() {
21546
21594
  return this.gate.close();
21547
21595
  }
21548
- handle(req, res, ctx) {
21596
+ async handle(req, res, ctx) {
21549
21597
  if (req.method !== "POST" || !ALLOWED_PATHS.has(ctx.path)) {
21550
21598
  ctx.done(404);
21551
21599
  res.writeHead(404).end();
@@ -21556,6 +21604,56 @@ var init_credentialGate = __esm({
21556
21604
  res.writeHead(403).end();
21557
21605
  return;
21558
21606
  }
21607
+ const slot = ctx.slot.index;
21608
+ const cap = this.opts.maxSlotBufferedBytes ?? MAX_SLOT_BUFFERED_BYTES;
21609
+ let held = 0;
21610
+ const charge = (n2) => {
21611
+ const used = (this.buffered.get(slot) ?? 0) + n2;
21612
+ if (used > cap) return false;
21613
+ this.buffered.set(slot, used);
21614
+ held += n2;
21615
+ return true;
21616
+ };
21617
+ try {
21618
+ await this.handleBody(req, res, ctx, charge);
21619
+ } finally {
21620
+ const left = (this.buffered.get(slot) ?? 0) - held;
21621
+ if (left > 0) this.buffered.set(slot, left);
21622
+ else this.buffered.delete(slot);
21623
+ }
21624
+ }
21625
+ async handleBody(req, res, ctx, charge) {
21626
+ let body;
21627
+ try {
21628
+ body = await readBody(req, MAX_BODY_BYTES, charge);
21629
+ } catch {
21630
+ ctx.done("aborted");
21631
+ res.destroy();
21632
+ return;
21633
+ }
21634
+ if (!body) {
21635
+ ctx.done(413, "body");
21636
+ res.writeHead(413, { connection: "close" }).end();
21637
+ return;
21638
+ }
21639
+ const encoding = req.headers["content-encoding"];
21640
+ if (encoding && encoding !== "identity") {
21641
+ ctx.done(415, "content-encoding");
21642
+ res.writeHead(415).end();
21643
+ return;
21644
+ }
21645
+ let parsed;
21646
+ try {
21647
+ parsed = JSON.parse(body.toString("utf8"));
21648
+ } catch {
21649
+ parsed = void 0;
21650
+ }
21651
+ const refused = refusedCapability(parsed, req.headers["anthropic-beta"]);
21652
+ if (refused) {
21653
+ ctx.done(403, `tool ${refused}`);
21654
+ res.writeHead(403).end();
21655
+ return;
21656
+ }
21559
21657
  const { counters, maxModelRequests } = ctx.binding;
21560
21658
  if (counters.model_requests >= maxModelRequests) {
21561
21659
  counters.cap_hits++;
@@ -21566,13 +21664,15 @@ var init_credentialGate = __esm({
21566
21664
  counters.model_requests++;
21567
21665
  const headers = filterHeaders(req.headers, (k) => k === "authorization" || k === "x-api-key");
21568
21666
  headers.authorization = `Bearer ${this.opts.getToken()}`;
21667
+ headers["content-length"] = String(body.length);
21569
21668
  const target = new URL(this.upstream.origin);
21570
21669
  target.pathname = ctx.path;
21571
21670
  target.search = searchOf(req.url);
21572
- void forward(req, res, target, headers, (status) => {
21671
+ const r = await forward(req, res, target, headers, (status) => {
21573
21672
  if (status === 429) counters.upstream_429++;
21574
21673
  counters.last_upstream_status = status;
21575
- }).then((r) => ctx.done(r.status));
21674
+ }, body);
21675
+ ctx.done(r.status);
21576
21676
  }
21577
21677
  };
21578
21678
  }
@@ -22418,6 +22518,24 @@ var init_claimDefaultProject = __esm({
22418
22518
  }
22419
22519
  });
22420
22520
 
22521
+ // ../shared/branchResolution.ts
22522
+ function resolveArchitectureBranchName(branches) {
22523
+ if (branches.length === 0) return null;
22524
+ const defaultBranch = branches.find((b) => b.isDefault);
22525
+ if (defaultBranch) {
22526
+ const scanName = `${defaultBranch.name}${SCAN_BRANCH_SUFFIX}`;
22527
+ const scan = branches.find((b) => b.name === scanName);
22528
+ return (scan ?? defaultBranch).name;
22529
+ }
22530
+ return branches[0].name;
22531
+ }
22532
+ var SCAN_BRANCH_SUFFIX;
22533
+ var init_branchResolution = __esm({
22534
+ "../shared/branchResolution.ts"() {
22535
+ SCAN_BRANCH_SUFFIX = "-scan";
22536
+ }
22537
+ });
22538
+
22421
22539
  // src/scan/run-scan.ts
22422
22540
  import { randomUUID as randomUUID2 } from "node:crypto";
22423
22541
  import { createWriteStream as createWriteStream2 } from "node:fs";
@@ -22712,12 +22830,15 @@ async function fetchExistingProject(supabase, org, projectSlug) {
22712
22830
  supabase.from("branches").select("name, is_default").eq("project_id", projectId),
22713
22831
  `branches lookup failed for project \`${org.slug}/${projectSlug}\``
22714
22832
  );
22715
- const defaultBranch = (branches ?? []).find((b) => b.is_default)?.name ?? "main";
22833
+ const rows = branches ?? [];
22834
+ const defaultBranch = rows.find((b) => b.is_default)?.name ?? "main";
22835
+ const architectureBranch = resolveArchitectureBranchName(rows.map((b) => ({ name: b.name, isDefault: b.is_default }))) ?? defaultBranch;
22716
22836
  return {
22717
22837
  orgSlug: org.slug,
22718
22838
  projectSlug,
22719
22839
  projectId,
22720
22840
  defaultBranch,
22841
+ architectureBranch,
22721
22842
  created: false
22722
22843
  };
22723
22844
  }
@@ -23032,6 +23153,7 @@ var init_run_scan = __esm({
23032
23153
  init_github_remote();
23033
23154
  init_architectureCounts2();
23034
23155
  init_claimDefaultProject();
23156
+ init_branchResolution();
23035
23157
  init_architectureCounts2();
23036
23158
  BOOTSTRAP_HEADLESS = `Run the \`scan\` MCP prompt now and follow it to completion. This is a non-interactive automated run \u2014 skip any steps that pause for user confirmation (e.g. "does this hierarchy look right?"). Proceed with your best-judgement decisions rather than waiting for human input.`;
23037
23159
  BOOTSTRAP_INTERACTIVE = `Run the \`scan\` MCP prompt now and follow it to completion. The user is at an interactive terminal \u2014 ask them when the prompt says to, and wait for their answer.
@@ -26481,8 +26603,8 @@ async function defaultLoadSupabaseState(_deviceId) {
26481
26603
  async function defaultLoadUptime(pid) {
26482
26604
  if (process.platform === "linux") {
26483
26605
  try {
26484
- const { readFile: readFile25 } = await import("node:fs/promises");
26485
- const stat15 = await readFile25(`/proc/${pid}/stat`, "utf8");
26606
+ const { readFile: readFile26 } = await import("node:fs/promises");
26607
+ const stat15 = await readFile26(`/proc/${pid}/stat`, "utf8");
26486
26608
  const parts = stat15.split(") ").pop()?.split(" ") ?? [];
26487
26609
  const ticks = Number(parts[19]);
26488
26610
  if (!Number.isFinite(ticks)) return null;
@@ -28180,12 +28302,6 @@ var init_saveArchitecture = __esm({
28180
28302
  }
28181
28303
  });
28182
28304
 
28183
- // ../shared/branchResolution.ts
28184
- var init_branchResolution = __esm({
28185
- "../shared/branchResolution.ts"() {
28186
- }
28187
- });
28188
-
28189
28305
  // ../shared/visibilityFlags.ts
28190
28306
  function flagsFor(row) {
28191
28307
  return {
@@ -29140,65 +29256,264 @@ function buildProjectMcpUrl(mcpBaseUrl, project, branch) {
29140
29256
  url.searchParams.set("branch", branch);
29141
29257
  return url.toString();
29142
29258
  }
29143
- function resolveAppOrigin(mcpBaseUrl, override) {
29144
- if (override) return override.replace(/\/$/, "");
29145
- return deriveWebOrigin(mcpBaseUrl, "fallback");
29146
- }
29147
- function buildInstallAgentUrl(appOrigin, mcpUrl) {
29148
- const url = new URL("/api/install-agent", appOrigin);
29149
- url.searchParams.set("mcp_url", mcpUrl);
29150
- return url.toString();
29151
- }
29152
29259
  var init_plan = __esm({
29153
29260
  "src/init/plan.ts"() {
29154
29261
  "use strict";
29155
- init_web_url();
29156
29262
  }
29157
29263
  });
29158
29264
 
29159
- // src/init/agentConfig.ts
29160
- import { mkdtemp as mkdtemp5, rm as rm9, writeFile as writeFile17 } from "node:fs/promises";
29161
- import { tmpdir as tmpdir5 } from "node:os";
29162
- import { join as join29 } from "node:path";
29163
- async function defaultFetchInstallScript(url) {
29164
- const resp = await fetch(url);
29165
- if (!resp.ok) {
29166
- throw new Error(`could not fetch agent installer (${resp.status} ${resp.statusText}) from ${url}`);
29265
+ // src/uninstall/edits.ts
29266
+ function stripArchmeClaudeBlock(content) {
29267
+ const start = content.indexOf(START_MARKER);
29268
+ if (start === -1) return UNCHANGED;
29269
+ const end = content.indexOf(END_MARKER, start);
29270
+ if (end === -1) return UNCHANGED;
29271
+ const before = content.slice(0, start).replace(/\n+$/, "");
29272
+ const after = content.slice(end + END_MARKER.length).replace(/^\n+/, "");
29273
+ if (!before.trim() && !after.trim()) return { kind: "delete" };
29274
+ if (!before.trim()) return { kind: "rewrite", content: `${after.replace(/\n*$/, "")}
29275
+ ` };
29276
+ if (!after.trim()) return { kind: "rewrite", content: `${before}
29277
+ ` };
29278
+ return { kind: "rewrite", content: `${before}
29279
+
29280
+ ${after.replace(/\n*$/, "")}
29281
+ ` };
29282
+ }
29283
+ function parseObject(raw) {
29284
+ try {
29285
+ const parsed = JSON.parse(raw);
29286
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
29287
+ return parsed;
29288
+ } catch {
29289
+ return null;
29167
29290
  }
29168
- return await resp.text();
29169
29291
  }
29170
- async function defaultRunInstallScript(script, cwd) {
29171
- const dir = await mkdtemp5(join29(tmpdir5(), "archme-init-"));
29172
- const scriptPath = join29(dir, "install-agent.sh");
29292
+ function render(value) {
29293
+ return `${JSON.stringify(value, null, 2)}
29294
+ `;
29295
+ }
29296
+ function stripArchmeMcpServer(content) {
29297
+ const root = parseObject(content);
29298
+ if (!root) return UNCHANGED;
29299
+ const servers = root.mcpServers;
29300
+ if (!servers || typeof servers !== "object" || Array.isArray(servers)) return UNCHANGED;
29301
+ const entries = servers;
29302
+ if (!(MCP_SERVER_NAME2 in entries)) return UNCHANGED;
29303
+ delete entries[MCP_SERVER_NAME2];
29304
+ const onlyKey = Object.keys(root).length === 1 && "mcpServers" in root;
29305
+ if (onlyKey && Object.keys(entries).length === 0) return { kind: "delete" };
29306
+ return { kind: "rewrite", content: render(root) };
29307
+ }
29308
+ function isArchmeHook(hook) {
29309
+ const command = hook?.command;
29310
+ return typeof command === "string" && command.includes(NUDGE_HOOK_FILE);
29311
+ }
29312
+ function stripArchmeHooks(content) {
29313
+ const root = parseObject(content);
29314
+ if (!root) return UNCHANGED;
29315
+ const hooks = root.hooks;
29316
+ if (!hooks || typeof hooks !== "object" || Array.isArray(hooks)) return UNCHANGED;
29317
+ const byEvent = hooks;
29318
+ const pre = byEvent.PreToolUse;
29319
+ if (!Array.isArray(pre)) return UNCHANGED;
29320
+ let changed = false;
29321
+ const kept = [];
29322
+ for (const entry of pre) {
29323
+ const inner = entry?.hooks;
29324
+ if (!Array.isArray(inner) || !inner.some(isArchmeHook)) {
29325
+ kept.push(entry);
29326
+ continue;
29327
+ }
29328
+ changed = true;
29329
+ const survivors = inner.filter((h2) => !isArchmeHook(h2));
29330
+ if (survivors.length > 0) kept.push({ ...entry, hooks: survivors });
29331
+ }
29332
+ if (!changed) return UNCHANGED;
29333
+ if (kept.length > 0) byEvent.PreToolUse = kept;
29334
+ else delete byEvent.PreToolUse;
29335
+ if (Object.keys(byEvent).length === 0) delete root.hooks;
29336
+ if (Object.keys(root).length === 0) return { kind: "delete" };
29337
+ return { kind: "rewrite", content: render(root) };
29338
+ }
29339
+ var UNCHANGED, START_MARKER, END_MARKER, NUDGE_HOOK_FILE, MCP_SERVER_NAME2;
29340
+ var init_edits = __esm({
29341
+ "src/uninstall/edits.ts"() {
29342
+ "use strict";
29343
+ UNCHANGED = { kind: "unchanged" };
29344
+ START_MARKER = "<!-- ARCHME-START -->";
29345
+ END_MARKER = "<!-- ARCHME-END -->";
29346
+ NUDGE_HOOK_FILE = "archme-search-nudge.mjs";
29347
+ MCP_SERVER_NAME2 = "archme";
29348
+ }
29349
+ });
29350
+
29351
+ // src/init/agentConfigEdits.ts
29352
+ function isLocalUrl(url) {
29173
29353
  try {
29174
- await writeFile17(scriptPath, script, { mode: 448 });
29175
- await execa("sh", [scriptPath], { cwd, stdio: "inherit" });
29176
- } finally {
29177
- await rm9(dir, { recursive: true, force: true });
29354
+ const host = new URL(url).hostname;
29355
+ return host === "localhost" || host === "127.0.0.1" || host === "0.0.0.0";
29356
+ } catch {
29357
+ return false;
29358
+ }
29359
+ }
29360
+ function isObject2(v) {
29361
+ return !!v && typeof v === "object" && !Array.isArray(v);
29362
+ }
29363
+ function render2(value) {
29364
+ return `${JSON.stringify(value, null, 2)}
29365
+ `;
29366
+ }
29367
+ function buildArchmeMcpServer(url) {
29368
+ return isLocalUrl(url) ? { type: "http", url, headers: { Authorization: LOCAL_DEV_AUTH } } : { type: "http", url };
29369
+ }
29370
+ function mergeArchmeMcpJson(existing, url) {
29371
+ if (existing === null) return { kind: "created", content: render2({ mcpServers: { [MCP_SERVER_NAME2]: buildArchmeMcpServer(url) } }) };
29372
+ const unparseable = { kind: "unparseable", snippet: render2({ mcpServers: { [MCP_SERVER_NAME2]: buildArchmeMcpServer(url) } }) };
29373
+ let root;
29374
+ try {
29375
+ root = JSON.parse(existing);
29376
+ } catch {
29377
+ return unparseable;
29378
+ }
29379
+ if (!isObject2(root)) return unparseable;
29380
+ const servers = root.mcpServers ?? {};
29381
+ if (!isObject2(servers)) return unparseable;
29382
+ root.mcpServers = servers;
29383
+ const current = servers[MCP_SERVER_NAME2];
29384
+ if (current === void 0) {
29385
+ servers[MCP_SERVER_NAME2] = buildArchmeMcpServer(url);
29386
+ return { kind: "added", content: render2(root) };
29387
+ }
29388
+ if (!isObject2(current)) return unparseable;
29389
+ const headersChanged = reconcileLocalDevAuth(current, url);
29390
+ if (current.url === url && !headersChanged) return { kind: "already-pinned" };
29391
+ const from = typeof current.url === "string" ? current.url : "(no url)";
29392
+ current.url = url;
29393
+ return { kind: "repinned", from, to: url, content: render2(root) };
29394
+ }
29395
+ function reconcileLocalDevAuth(server, url) {
29396
+ const headers = isObject2(server.headers) ? server.headers : {};
29397
+ const authKey = Object.keys(headers).find((k) => k.toLowerCase() === "authorization");
29398
+ if (isLocalUrl(url)) {
29399
+ if (authKey !== void 0) return false;
29400
+ server.headers = { ...headers, Authorization: LOCAL_DEV_AUTH };
29401
+ return true;
29402
+ }
29403
+ if (authKey === void 0 || headers[authKey] !== LOCAL_DEV_AUTH) return false;
29404
+ delete headers[authKey];
29405
+ if (Object.keys(headers).length === 0) delete server.headers;
29406
+ return true;
29407
+ }
29408
+ function upsertArchmeClaudeBlock(existing, block) {
29409
+ if (existing === null) return { kind: "created", content: `${block}
29410
+ ` };
29411
+ const start = existing.indexOf(START_MARKER);
29412
+ if (start === -1) {
29413
+ const prose = existing.replace(/\s+$/, "");
29414
+ return { kind: "appended", content: prose ? `${prose}
29415
+
29416
+ ${block}
29417
+ ` : `${block}
29418
+ ` };
29419
+ }
29420
+ const end = existing.indexOf(END_MARKER, start);
29421
+ if (end === -1) return { kind: "half-marked" };
29422
+ return {
29423
+ kind: "replaced",
29424
+ content: existing.slice(0, start) + block + existing.slice(end + END_MARKER.length)
29425
+ };
29426
+ }
29427
+ var LOCAL_DEV_AUTH;
29428
+ var init_agentConfigEdits = __esm({
29429
+ "src/init/agentConfigEdits.ts"() {
29430
+ "use strict";
29431
+ init_edits();
29432
+ LOCAL_DEV_AUTH = "Bearer am_local_dev";
29433
+ }
29434
+ });
29435
+
29436
+ // src/init/agentInstructions.ts
29437
+ var ARCHME_CLAUDE_BLOCK, ARCHME_SKILL;
29438
+ var init_agentInstructions = __esm({
29439
+ "src/init/agentInstructions.ts"() {
29440
+ "use strict";
29441
+ ARCHME_CLAUDE_BLOCK = (true ? "<!-- ARCHME-START -->\n## Architecture Awareness\n\nThis repository has a live ArchitectMe architecture connected through the `archme` MCP server.\n\nBefore broad code exploration, structural changes, new services, API/data-flow changes, or refactors:\n\n1. Use `read_architecture` or `find_components` to identify the relevant subsystem.\n2. Use `get_component` for the likely component before editing.\n3. Use `read_stories` and `check_impact` when behavior crosses component boundaries or when removing/renaming anything.\n4. Fall back to normal repo inspection if the architecture is missing, stale, or too vague.\n\nWhen working with a user on new features or large architecture changes, author a proposal (`create_proposal`) on its forked branch and let realization close it when the code lands \u2014 direct writes to the base branch are the daemon's incremental lane. See the `architecture` skill for the full flow.\n<!-- ARCHME-END -->" : fromSource("CLAUDE_BLOCK.md")).trimEnd();
29442
+ ARCHME_SKILL = true ? "---\nname: architecture\ndescription: Query ArchitectMe before broad code exploration, structural changes, refactors, API/data-flow work, or architecture updates. Author net-new/large design changes as proposals.\n---\n\n# Architecture Reference (ArchitectMe)\n\nThis repository's system design is managed in ArchitectMe. Use the `archme` MCP\nserver to read the live architecture while coding, and to author design changes as\nreviewable proposals. Reads and writes are scoped to the project + branch in `.mcp.json`.\n\n## Reading the architecture\n\nOrient in the map before broad repo exploration or structural edits:\n\n1. `query(\"<keyword>\")` \u2014 the one-call orientation verb. Keyword-matches components and\n returns, per match: kind/tech, a one-line description, **code anchors** (where it\n lives), direct connections, and the stories that touch it. A locator, not an\n answerer \u2014 open the anchored files yourself with Read.\n2. `read_architecture({ path: \"root\" })` \u2014 components + connections + structure at a\n scope (dot-paths: `root`, `root.api`, `root.api.db`).\n3. `get_component({ path })` \u2014 architecture + stories + context for one component.\n4. `read_stories({ path })` \u2014 user-flow stories with their Mermaid sequences.\n5. `check_impact` before removing, renaming, or moving a component boundary.\n\n**Anchors** bind a component to real code \u2014 `{ kind: \"file\" | \"directory\" | \"glob\" |\n\"symbol\", ... }`. They're how you jump from a component to its implementation: read the\nanchors, then `Read` those paths. Conceptual/external components (vendors, actors) carry\n`unanchored: true` instead. Every read surfaces a component's anchors.\n\nFor small local fixes in an already-known file, proceed normally. If ArchMe is stale,\nmissing, or too vague, fall back to regular repo inspection and mention the gap.\n\n## Proposing architecture changes (the default for net-new / large work)\n\nWhen you're about to build a net-new subsystem or make a large/structural design change,\nauthor it as a PROPOSAL \u2014 a reviewable spec against the source-of-truth branch \u2014 rather\nthan writing directly:\n\n1. `create_proposal({ title, description?, body? })` \u2014 forks a `proposal-<id>` working\n branch off the base and freezes a baseline. Returns the branch to author on, an\n `ArchMe-Proposal: <id>` trailer token, and a shareable link. **Surface the link to\n the user.** Filing a RUN of items (bugs from a triage, follow-ups from a design\n conversation)? Pass `proposals: [{ title, ... }, ...]` instead of `title` and create\n them in one call \u2014 the top-level `kind`, `parent_id`, `stage` and `base_branch` are\n defaults every item inherits and may override. Items are created in order and a\n failure part-way doesn't undo the ones before it, so retry only what the response\n reports as failed.\n Say what each one is **about** \u2014 `about: { component: 'root.\u2026' }` for the component a\n bug lives in, else `{ story: '<id>' }` for the flow, else `{ repo: 'owner/name' }`\n (null for nothing; `update_proposal` changes it later). The repo picker narrows the\n Issues and Proposals lists by it.\n2. **Author the delta on the graph \u2014 that delta IS the proposal.** On the returned\n branch, call `update_architecture` / `move_architecture` with\n `branch: \"proposal-<id>\"`: add or change the components and connections the design\n implies, and the user stories (each leaf carrying a Mermaid `sequence`) for the flows\n it introduces or changes. **Strongly prefer showing the change as a delta** \u2014 that's\n what reviewers actually read, so a representable design change described only in prose\n is close to invisible to them. Prose the graph and stories can't express \u2014 rationale,\n phased rollout, non-goals, a bug report, an ops/process change \u2014 goes in `body`. A\n prose-only proposal (populated `body`, empty delta) is valid when there's nothing\n representable to model; don't fabricate deltas to fill one out, and don't reach for\n prose to avoid modelling a change the graph could show.\n3. **Give a large proposal a walkthrough** \u2014 `set_walkthrough({ proposal: \"<id>\", steps: [...] })`.\n Each step names the stories, chapters, components and/or connections it covers,\n and the review surface filters the sequence diagram and the component graph down to\n just those, so a forty-element delta is read one bite-sized chunk at a time. Every\n step MUST reference at least one element: a step with only prose is rejected, because\n there is nothing to filter by and an explanation a reader can't check against the\n change is what this view exists to avoid. Steps go in **reading order, not build\n order** \u2014 this is not your sequencing plan restated. Titles are terse handles.\n **Every step gets a `description`**: two or three plain sentences on what this part of\n the change is and why it exists, at a high level \u2014 the narration a reviewer reads in\n guided mode while the diagrams move beside it. Not prescriptive, not a dense list of\n identifiers, and it never restates the elements the step already references.\n **Cover every change**: every story and component the delta touches must be named by\n a step, or `set_walkthrough` rejects the walkthrough and lists what is missing.\n Connections need no step of their own: they show up through the stories that draw\n them. A step that does name a connection inside a component writes it as\n `<component path>::<id>` (`daemon::session_auth->key_account`).\n Write it after the delta is in place, and skip it entirely for a small change \u2014 unless\n one already exists: when `update_architecture` warns that your writes left it out of\n date, rewrite it, or clear it with `set_walkthrough({ ..., steps: [] })`.\n4. Request review \u2014 run an automated lens yourself with `start_review` \u2192\n `submit_review` (self-contained, no user id needed), and/or `request_review` to ask a\n human teammate (needs their org-member user id).\n5. Implement in code with `ArchMe-Proposal: <id>` in the PR body. The daemon's\n realization auto-closes the proposal on merge. **Never merge the proposal branch into\n the base branch yourself.**\n\nUse `add_proposal_comment` to discuss a proposal **or a pull request** \u2014 free-form,\noptionally anchored to a component/story/connection (`anchor_kind` + `anchor_id`) or left\nas an entity-level thread, and `in_reply_to` to thread replies. Pass `proposal_id` OR\n`pr`, never both; a `pr` also takes `repo` (`\"owner/name\"`) when two watched repos in the\nproject share its number \u2014 the error names them. Distinct from `submit_review` (a typed lens verdict): use comments for\nconversation and questions on the delta.\n\nRead a PR back with `get_pr` \u2014 GitHub's own facts about it, ArchMe's description, its\nwalkthrough, and the whole comment thread. That is how you see a REPLY to a comment you\nleft, so check it before assuming a question went unanswered.\n\nA comment on a PR (or on a proposal some PR's `ArchMe-Proposal:` trailer names) is\nmirrored to that pull request on GitHub, so reviewers who live there see it. Write for\nthat audience: the first sentence is what they read.\n\n## Updating the architecture (update_architecture)\n\n`update_architecture` is additive \u2014 it merges components, connections, stories, and\nrequirements by id. Use it to author a proposal's spec on the fork; direct writes to the\nbase branch are reserved for the daemon's small incremental diffs.\n\nKeep the graph honest:\n\n- **Every component is anchored** to the code that implements it (`anchors`), or\n explicitly `unanchored: true` if it's conceptual/external. An unanchored internal\n component is drift.\n- **Connections reflect real data flow** \u2014 every call/dependency between components is a\n connection (`from`, `to`, `method`). Name the endpoints with `root.` paths; ArchMe\n stores each connection where its endpoints meet and the result says where (scope + id).\n- Add children with a separate entry using `at` (don't nest a `components` array).\n- Stories capture user flows; each leaf story carries a Mermaid `sequence` whose\n participants are `root.`-prefixed dot-paths.\n\nUse `move_architecture` to relocate components/stories (it rewrites sequences +\nconnections) and `update_node_context` for design decisions, references, and notes.\n\n## Scan\n\nUse the `/scan` MCP prompt to bootstrap or refresh the architecture from the local repo.\nFollow its setup, branch, and restart instructions.\n\n## Common Mistakes\n\n- Do not grep/read broadly first when a `query` or architecture lookup can narrow it.\n- Do not push net-new or large changes directly to the base branch \u2014 open a proposal.\n- Do not settle for a prose-only proposal when it adds or changes components,\n connections, or user flows \u2014 model those on the fork branch; `body` is for what the\n graph can't show.\n- Do not leave internal components unanchored or real connections missing.\n- Do not assume the architecture is complete; verify against code (via anchors) before\n risky edits.\n- Do not remove or rename architectural boundaries without `check_impact`.\n- Do not merge a proposal branch into the base \u2014 realization closes it when code lands.\n" : fromSource("architecture-skill.md");
29178
29443
  }
29444
+ });
29445
+
29446
+ // src/init/agentConfig.ts
29447
+ import { mkdir as mkdir18, readFile as readFile19, writeFile as writeFile17 } from "node:fs/promises";
29448
+ import { dirname as dirname20, join as join29 } from "node:path";
29449
+ async function readOrNull(path7) {
29450
+ try {
29451
+ return await readFile19(path7, "utf8");
29452
+ } catch (e) {
29453
+ if (e.code === "ENOENT") return null;
29454
+ throw e;
29455
+ }
29456
+ }
29457
+ async function write(path7, content) {
29458
+ await mkdir18(dirname20(path7), { recursive: true });
29459
+ await writeFile17(path7, content);
29179
29460
  }
29180
- async function installAgentConfig(opts, deps = {}) {
29461
+ async function installAgentConfig(opts) {
29462
+ const log = opts.log ?? ((m) => console.log(m));
29463
+ const files = [];
29464
+ const warnings = [];
29465
+ const at = (rel) => join29(opts.repoRoot, rel);
29181
29466
  const mcpUrl = buildProjectMcpUrl(opts.mcpBaseUrl, opts.project, opts.branch);
29182
- const appOrigin = resolveAppOrigin(opts.mcpBaseUrl, opts.appOrigin);
29183
- const script = await (deps.fetchInstallScript ?? defaultFetchInstallScript)(buildInstallAgentUrl(appOrigin, mcpUrl));
29184
- await (deps.runInstallScript ?? defaultRunInstallScript)(script, opts.repoRoot);
29467
+ const mcp = mergeArchmeMcpJson(await readOrNull(at(".mcp.json")), mcpUrl);
29468
+ if (mcp.kind === "unparseable") {
29469
+ files.push({ path: ".mcp.json", outcome: "left alone: could not parse it" });
29470
+ warnings.push(`.mcp.json could not be parsed, so it was left untouched. Add the archme server yourself:
29471
+ ${mcp.snippet}`);
29472
+ } else if (mcp.kind === "already-pinned") {
29473
+ files.push({ path: ".mcp.json", outcome: `already pinned to ${opts.project} (${opts.branch})` });
29474
+ } else {
29475
+ await write(at(".mcp.json"), mcp.content);
29476
+ files.push({
29477
+ path: ".mcp.json",
29478
+ outcome: mcp.kind === "repinned" ? `repinned archme: ${mcp.from} \u2192 ${mcp.to}` : mcp.kind === "added" ? "added the archme server" : "created"
29479
+ });
29480
+ }
29481
+ const block = upsertArchmeClaudeBlock(await readOrNull(at("CLAUDE.md")), ARCHME_CLAUDE_BLOCK);
29482
+ if (block.kind === "half-marked") {
29483
+ files.push({ path: "CLAUDE.md", outcome: "left alone: <!-- ARCHME-START --> with no <!-- ARCHME-END -->" });
29484
+ warnings.push(
29485
+ "CLAUDE.md has an ArchMe start marker but no end marker, so it was left untouched. Fix or remove the markers and re-run `archme init --agent-only`."
29486
+ );
29487
+ } else {
29488
+ await write(at("CLAUDE.md"), block.content);
29489
+ files.push({ path: "CLAUDE.md", outcome: block.kind === "created" ? "created" : block.kind === "replaced" ? "updated the ArchMe block" : "added the ArchMe block" });
29490
+ }
29491
+ await write(at(SKILL_PATH), ARCHME_SKILL);
29492
+ files.push({ path: SKILL_PATH, outcome: "installed" });
29493
+ for (const f of files) log(` ${f.outcome.startsWith("left alone") ? "\u26A0" : "\u2713"} ${f.path}: ${f.outcome}`);
29494
+ for (const w of warnings) log(`\u26A0 ${w}`);
29495
+ log("Next: open or restart Claude Code in this repo, and authenticate the MCP connection if prompted.");
29185
29496
  await ignoreArchmeFiles(opts.repoRoot);
29497
+ return { files, warnings };
29186
29498
  }
29499
+ var SKILL_PATH;
29187
29500
  var init_agentConfig = __esm({
29188
29501
  "src/init/agentConfig.ts"() {
29189
29502
  "use strict";
29190
- init_execa();
29191
29503
  init_repoIgnore();
29192
29504
  init_plan();
29505
+ init_agentConfigEdits();
29506
+ init_agentInstructions();
29507
+ SKILL_PATH = ".claude/skills/architecture/SKILL.md";
29193
29508
  }
29194
29509
  });
29195
29510
 
29196
29511
  // src/init/workspace.ts
29197
- import { dirname as dirname20, resolve as resolve4, sep as sep2 } from "node:path";
29512
+ import { dirname as dirname21, resolve as resolve4, sep as sep2 } from "node:path";
29198
29513
  function initWorkspace(input) {
29199
29514
  const tooBroad = (dir) => resolve4(dir) === resolve4(input.home) || resolve4(dir) === sep2;
29200
29515
  if (input.startRepoRoot) {
29201
- const parent = dirname20(input.startRepoRoot);
29516
+ const parent = dirname21(input.startRepoRoot);
29202
29517
  return tooBroad(parent) ? { ok: true, workspace: input.startRepoRoot, cloneDir: parent, searchDepth: 1 } : { ok: true, workspace: parent, cloneDir: parent, searchDepth: 3 };
29203
29518
  }
29204
29519
  if (tooBroad(input.startDir)) {
@@ -29233,7 +29548,7 @@ __export(run_exports3, {
29233
29548
  watchedElsewhere: () => watchedElsewhere
29234
29549
  });
29235
29550
  import { readdir as readdir3, stat as stat11 } from "node:fs/promises";
29236
- import { dirname as dirname21, join as join30, resolve as resolve5, sep as sep3 } from "node:path";
29551
+ import { dirname as dirname22, join as join30, resolve as resolve5, sep as sep3 } from "node:path";
29237
29552
  async function readLocalWatchedRepos(supabase, projectId) {
29238
29553
  const { data, error } = await supabase.from("watched_repos").select("repo_owner, repo_name").eq("project_id", projectId).eq("source_kind", "local").is("deleted_at", null);
29239
29554
  if (error) throw new Error(`could not read the project's locally polled repos: ${error.message}`);
@@ -29273,7 +29588,7 @@ async function listClones(dir) {
29273
29588
  return out.sort();
29274
29589
  }
29275
29590
  function commonDir(paths) {
29276
- const split = paths.map((p) => dirname21(p).split(sep3));
29591
+ const split = paths.map((p) => dirname22(p).split(sep3));
29277
29592
  const common2 = [];
29278
29593
  for (let i2 = 0; split.every((s) => s[i2] !== void 0 && s[i2] === split[0][i2]); i2++) common2.push(split[0][i2]);
29279
29594
  return common2.join(sep3) || sep3;
@@ -29484,7 +29799,7 @@ async function prepareAddRepos(opts, deps = {}) {
29484
29799
  mcpBaseUrl: cfg.archmeMcpBaseUrl,
29485
29800
  project: opts.project,
29486
29801
  branch: scanBranch,
29487
- appOrigin: opts.agentConfig.appOrigin
29802
+ log
29488
29803
  });
29489
29804
  } catch (e) {
29490
29805
  log(` ! could not install agent config in ${c3.root}: ${e instanceof Error ? e.message : String(e)}`);
@@ -29840,8 +30155,8 @@ var init_nearbyClones = __esm({
29840
30155
  });
29841
30156
 
29842
30157
  // src/init/handoff.ts
29843
- import { mkdir as mkdir18, readFile as readFile19, rename as rename4, stat as stat13, writeFile as writeFile18 } from "node:fs/promises";
29844
- import { basename as basename3, dirname as dirname22, join as join32, resolve as resolve6 } from "node:path";
30158
+ import { mkdir as mkdir19, readFile as readFile20, rename as rename4, stat as stat13, writeFile as writeFile18 } from "node:fs/promises";
30159
+ import { basename as basename3, dirname as dirname23, join as join32, resolve as resolve6 } from "node:path";
29845
30160
  function parseHandoffArgs(argv) {
29846
30161
  const errors = [];
29847
30162
  let to;
@@ -29870,7 +30185,7 @@ function parseHandoffArgs(argv) {
29870
30185
  else repos.push(arg);
29871
30186
  }
29872
30187
  if (!to) errors.push("--to <path> is required: the handoff file archme init named in your instructions");
29873
- else if (basename3(to) !== "handoff.json" || basename3(dirname22(to)) !== "init" || basename3(dirname22(dirname22(to))) !== ".archme") {
30188
+ else if (basename3(to) !== "handoff.json" || basename3(dirname23(to)) !== "init" || basename3(dirname23(dirname23(to))) !== ".archme") {
29874
30189
  errors.push(`--to must be archme init's handoff file (\u2026/${HANDOFF_FILE}), got \`${to}\``);
29875
30190
  }
29876
30191
  if (!project) errors.push("--project <org/slug> is required");
@@ -29935,7 +30250,7 @@ function isHandoff(v) {
29935
30250
  async function readHandoff(file) {
29936
30251
  let raw;
29937
30252
  try {
29938
- raw = await readFile19(file, "utf8");
30253
+ raw = await readFile20(file, "utf8");
29939
30254
  } catch (e) {
29940
30255
  if (e.code === "ENOENT") return null;
29941
30256
  throw e;
@@ -29950,7 +30265,7 @@ async function readHandoff(file) {
29950
30265
  return parsed;
29951
30266
  }
29952
30267
  async function writeHandoff(file, handoff) {
29953
- await mkdir18(dirname22(file), { recursive: true });
30268
+ await mkdir19(dirname23(file), { recursive: true });
29954
30269
  const tmp = `${file}.${process.pid}.tmp`;
29955
30270
  await writeFile18(tmp, JSON.stringify(handoff, null, 2) + "\n");
29956
30271
  await rename4(tmp, file);
@@ -29987,11 +30302,11 @@ var init_handoff = __esm({
29987
30302
  });
29988
30303
 
29989
30304
  // src/init/conversation.ts
29990
- import { mkdir as mkdir19, readFile as readFile20, rename as rename5, rm as rm10, writeFile as writeFile19 } from "node:fs/promises";
29991
- import { dirname as dirname23, join as join33 } from "node:path";
30305
+ import { mkdir as mkdir20, readFile as readFile21, rename as rename5, rm as rm9, writeFile as writeFile19 } from "node:fs/promises";
30306
+ import { dirname as dirname24, join as join33 } from "node:path";
29992
30307
  async function readInitSession(workspace) {
29993
30308
  try {
29994
- const parsed = JSON.parse(await readFile20(join33(workspace, INIT_SESSION_FILE), "utf8"));
30309
+ const parsed = JSON.parse(await readFile21(join33(workspace, INIT_SESSION_FILE), "utf8"));
29995
30310
  if (parsed.version !== 1 || typeof parsed.sessionId !== "string" || !SESSION_ID_RE2.test(parsed.sessionId)) return null;
29996
30311
  if (parsed.phase !== "discovery" && parsed.phase !== "build" && parsed.phase !== "done") return null;
29997
30312
  return { version: 1, sessionId: parsed.sessionId, phase: parsed.phase, updatedAt: String(parsed.updatedAt ?? "") };
@@ -30001,7 +30316,7 @@ async function readInitSession(workspace) {
30001
30316
  }
30002
30317
  async function writeInitSession(workspace, state) {
30003
30318
  const file = join33(workspace, INIT_SESSION_FILE);
30004
- await mkdir19(dirname23(file), { recursive: true });
30319
+ await mkdir20(dirname24(file), { recursive: true });
30005
30320
  const tmp = `${file}.${process.pid}.tmp`;
30006
30321
  await writeFile19(tmp, JSON.stringify(state, null, 2) + "\n");
30007
30322
  await rename5(tmp, file);
@@ -30011,7 +30326,7 @@ async function readFresh(file) {
30011
30326
  }
30012
30327
  async function runDiscoveryTurn(opts, deps = {}) {
30013
30328
  const spawn2 = deps.spawn ?? spawnClaude;
30014
- await rm10(opts.handoffFile, { force: true });
30329
+ await rm9(opts.handoffFile, { force: true });
30015
30330
  const base = {
30016
30331
  mcpConfigPath: opts.mcpConfigPath,
30017
30332
  cwd: opts.workspace,
@@ -30254,7 +30569,7 @@ var init_facts = __esm({
30254
30569
  });
30255
30570
 
30256
30571
  // src/doctor/collect.ts
30257
- import { readFile as readFile21 } from "node:fs/promises";
30572
+ import { readFile as readFile22 } from "node:fs/promises";
30258
30573
  import { join as join34 } from "node:path";
30259
30574
  function binaryPresent(name) {
30260
30575
  try {
@@ -30271,7 +30586,7 @@ async function git3(cwd, args) {
30271
30586
  async function readMcpPin(repoRoot) {
30272
30587
  const empty = { installed: false, pin: { project: null, branch: null } };
30273
30588
  try {
30274
- const raw = await readFile21(join34(repoRoot, ".mcp.json"), "utf8");
30589
+ const raw = await readFile22(join34(repoRoot, ".mcp.json"), "utf8");
30275
30590
  const parsed = JSON.parse(raw);
30276
30591
  const servers = parsed.mcpServers ?? {};
30277
30592
  const entry = Object.entries(servers).find(([name]) => /archme/i.test(name));
@@ -30550,7 +30865,7 @@ async function runGuidedInit(opts, deps = {}) {
30550
30865
  mcpBaseUrl: opts.mcpBaseUrl,
30551
30866
  project: onBoard.project,
30552
30867
  branch: onBoard.branch,
30553
- ...opts.appOrigin ? { appOrigin: opts.appOrigin } : {}
30868
+ log
30554
30869
  });
30555
30870
  log(`
30556
30871
  Your board: ${onBoard.webUrl}`);
@@ -30736,7 +31051,7 @@ async function runSetup(opts, deps, { workspace, cloneDir }, handoff) {
30736
31051
  project: handoff.project,
30737
31052
  local: handoff.access === "local",
30738
31053
  yes: !!opts.scriptedReplies,
30739
- agentConfig: { ...opts.appOrigin ? { appOrigin: opts.appOrigin } : {} }
31054
+ agentConfig: true
30740
31055
  },
30741
31056
  {
30742
31057
  cwd: cloneDir,
@@ -30805,7 +31120,7 @@ async function runSetup(opts, deps, { workspace, cloneDir }, handoff) {
30805
31120
  mcpBaseUrl: opts.mcpBaseUrl,
30806
31121
  project: handoff.project,
30807
31122
  branch: scanBranch,
30808
- ...opts.appOrigin ? { appOrigin: opts.appOrigin } : {}
31123
+ log
30809
31124
  });
30810
31125
  let watched = false;
30811
31126
  if (handoff.access === "github-app") {
@@ -31026,6 +31341,50 @@ var init_guided = __esm({
31026
31341
  }
31027
31342
  });
31028
31343
 
31344
+ // src/init/agentOnly.ts
31345
+ async function runAgentOnly(opts, deps = {}) {
31346
+ const { log } = opts;
31347
+ const slug = opts.project ?? (await (deps.readPin ?? readMcpPin)(opts.repoRoot)).pin.project;
31348
+ if (!slug) {
31349
+ log("archme init --agent-only: this clone's .mcp.json pins no project \u2014 pass --project <org/slug>");
31350
+ return { exitCode: EX_USAGE2, project: "", branch: "" };
31351
+ }
31352
+ const notVisible = () => {
31353
+ log(`archme init --agent-only: project ${slug} does not exist or is not visible to ${opts.authed.identity}.`);
31354
+ log(" Check the slug, or run `archme login` to sign in as someone who can see it.");
31355
+ return { exitCode: EX_USAGE2, project: slug, branch: "" };
31356
+ };
31357
+ let project;
31358
+ try {
31359
+ project = await (deps.findProject ?? findProject)(opts.authed.supabase, slug);
31360
+ } catch (e) {
31361
+ if (e instanceof Error && /^org `.*` not found$/.test(e.message)) return notVisible();
31362
+ throw e;
31363
+ }
31364
+ if (!project) return notVisible();
31365
+ log(`\u2713 using existing project ${slug}`);
31366
+ const branch = project.architectureBranch ?? project.defaultBranch;
31367
+ log("\u2192 installing agent config (.mcp.json, CLAUDE.md, architecture skill)\u2026");
31368
+ await (deps.installAgentConfig ?? installAgentConfig)({
31369
+ repoRoot: opts.repoRoot,
31370
+ mcpBaseUrl: opts.mcpBaseUrl,
31371
+ project: slug,
31372
+ branch,
31373
+ log
31374
+ });
31375
+ return { exitCode: 0, project: slug, branch };
31376
+ }
31377
+ var EX_USAGE2;
31378
+ var init_agentOnly = __esm({
31379
+ "src/init/agentOnly.ts"() {
31380
+ "use strict";
31381
+ init_run_scan();
31382
+ init_collect();
31383
+ init_agentConfig();
31384
+ EX_USAGE2 = 78;
31385
+ }
31386
+ });
31387
+
31029
31388
  // src/init/run-init.ts
31030
31389
  async function defaultStartDaemon2() {
31031
31390
  const { runStartFlow: runStartFlow2 } = await Promise.resolve().then(() => (init_install(), install_exports));
@@ -31074,8 +31433,6 @@ async function readBoardRepos2(supabase, projectId, branch) {
31074
31433
  async function runInit(opts, deps = {}) {
31075
31434
  const log = opts.log ?? ((msg) => console.log(msg));
31076
31435
  const login = deps.login ?? runLogin;
31077
- const fetchInstallScript = deps.fetchInstallScript ?? defaultFetchInstallScript;
31078
- const runInstallScript = deps.runInstallScript ?? defaultRunInstallScript;
31079
31436
  const scan = deps.scan ?? runScan;
31080
31437
  const authenticate = deps.authenticate ?? createAuthedClient;
31081
31438
  const resolveProject = deps.resolveProject ?? resolveOrCreateProject;
@@ -31088,7 +31445,7 @@ async function runInit(opts, deps = {}) {
31088
31445
  const interactive = !opts.yes && (deps.interactive ?? stdinIsInteractive());
31089
31446
  const openBoard = deps.openBoard ?? defaultOpenBoard2;
31090
31447
  const cfg = resolveConfig();
31091
- const guided = !!opts.scriptedReplies || interactive && !opts.skipScan;
31448
+ const guided = !opts.agentOnly && (!!opts.scriptedReplies || interactive && !opts.skipScan);
31092
31449
  const git4 = guided ? null : await gitContext(opts.repoPath);
31093
31450
  const { credentials } = await loadCreds(cfg.supabaseUrl);
31094
31451
  const signedIn = credentials.length > 0;
@@ -31107,6 +31464,15 @@ async function runInit(opts, deps = {}) {
31107
31464
  });
31108
31465
  log(` signed in as ${authed2.identity} \u2014 not you? \`archme login\``);
31109
31466
  const keyed = authed2.accountKind === "key";
31467
+ if (opts.agentOnly && git4) {
31468
+ const out = await runAgentOnly(
31469
+ { authed: authed2, repoRoot: git4.root, ...opts.project ? { project: opts.project } : {}, mcpBaseUrl: cfg.archmeMcpBaseUrl, log },
31470
+ { findProject: deps.findProject, readPin: deps.readPin, installAgentConfig: deps.installAgentConfig }
31471
+ );
31472
+ const ran2 = signedIn ? [] : ["login"];
31473
+ if (out.exitCode === 0) ran2.push("agent-config");
31474
+ return { exitCode: out.exitCode, project: out.project, branch: out.branch, webUrl: "", ran: ran2 };
31475
+ }
31110
31476
  if (guided || !git4) {
31111
31477
  const orgId = authed2.orgId;
31112
31478
  if (!orgId) throw new Error("could not resolve your organization \u2014 run `archme login` again");
@@ -31120,7 +31486,6 @@ async function runInit(opts, deps = {}) {
31120
31486
  mcpBaseUrl: cfg.archmeMcpBaseUrl,
31121
31487
  supabaseUrl: cfg.supabaseUrl,
31122
31488
  ...opts.project ? { project: opts.project } : {},
31123
- ...opts.appOrigin ? { appOrigin: opts.appOrigin } : {},
31124
31489
  ...opts.force ? { force: true } : {},
31125
31490
  ...opts.scriptedReplies ? { scriptedReplies: opts.scriptedReplies } : {},
31126
31491
  log
@@ -31164,9 +31529,8 @@ async function runInit(opts, deps = {}) {
31164
31529
  const ran = signedIn ? [] : ["login"];
31165
31530
  ran.push("project");
31166
31531
  log("\u2192 installing agent config (.mcp.json, CLAUDE.md, architecture skill)\u2026");
31167
- await installAgentConfig(
31168
- { repoRoot: repoPath, mcpBaseUrl: cfg.archmeMcpBaseUrl, project: fullSlug, branch: scanBranch, appOrigin: opts.appOrigin },
31169
- { fetchInstallScript, runInstallScript }
31532
+ await (deps.installAgentConfig ?? installAgentConfig)(
31533
+ { repoRoot: repoPath, mcpBaseUrl: cfg.archmeMcpBaseUrl, project: fullSlug, branch: scanBranch, log }
31170
31534
  );
31171
31535
  ran.push("agent-config");
31172
31536
  const onBoard = await (deps.boardRepos ?? readBoardRepos2)(authed2.supabase, project.projectId, scanBranch);
@@ -31400,6 +31764,7 @@ var init_run_init = __esm({
31400
31764
  init_run2();
31401
31765
  init_watchRepo();
31402
31766
  init_agentConfig();
31767
+ init_agentOnly();
31403
31768
  init_scanBranch();
31404
31769
  init_scanBranch();
31405
31770
  DAEMON_QUESTION2 = "Keep the board updating in the background?";
@@ -31440,6 +31805,7 @@ function parseInitArgs(argv) {
31440
31805
  const args = {
31441
31806
  force: false,
31442
31807
  skipScan: false,
31808
+ agentOnly: false,
31443
31809
  yes: false,
31444
31810
  noInteractive: false,
31445
31811
  help: false
@@ -31474,6 +31840,7 @@ function parseInitArgs(argv) {
31474
31840
  if (arg === "--force") args.force = true;
31475
31841
  else if (arg === "--yes") args.yes = true;
31476
31842
  else if (arg === "--no-interactive") args.noInteractive = true;
31843
+ else if (arg === "--agent-only") args.agentOnly = true;
31477
31844
  else args.skipScan = true;
31478
31845
  continue;
31479
31846
  }
@@ -31497,8 +31864,6 @@ function parseInitArgs(argv) {
31497
31864
  };
31498
31865
  }
31499
31866
  args.project = value;
31500
- } else {
31501
- args.appOrigin = value;
31502
31867
  }
31503
31868
  continue;
31504
31869
  }
@@ -31514,6 +31879,11 @@ function parseInitArgs(argv) {
31514
31879
  };
31515
31880
  }
31516
31881
  args.repoPath = positionals[0];
31882
+ if (args.agentOnly) {
31883
+ for (const [flag, set] of [["--force", args.force], ["--skip-scan", args.skipScan]]) {
31884
+ if (set) return { ok: false, error: `--agent-only cannot be combined with ${flag}: it never scans` };
31885
+ }
31886
+ }
31517
31887
  return { ok: true, args };
31518
31888
  }
31519
31889
  var BOOLEAN_FLAGS, VALUE_FLAGS, HELP_FLAGS, LOGIN_FLAGS, PROJECT_SLUG_RE2;
@@ -31523,10 +31893,11 @@ var init_args = __esm({
31523
31893
  BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
31524
31894
  "--force",
31525
31895
  "--skip-scan",
31896
+ "--agent-only",
31526
31897
  "--yes",
31527
31898
  "--no-interactive"
31528
31899
  ]);
31529
- VALUE_FLAGS = /* @__PURE__ */ new Set(["--project", "--app-origin"]);
31900
+ VALUE_FLAGS = /* @__PURE__ */ new Set(["--project"]);
31530
31901
  HELP_FLAGS = /* @__PURE__ */ new Set(["--help", "-h", "help"]);
31531
31902
  LOGIN_FLAGS = {
31532
31903
  "--no-account": "no-account",
@@ -31542,12 +31913,12 @@ var dispatch_exports4 = {};
31542
31913
  __export(dispatch_exports4, {
31543
31914
  EX_INFRA: () => EX_INFRA2,
31544
31915
  EX_OK: () => EX_OK2,
31545
- EX_USAGE: () => EX_USAGE2,
31916
+ EX_USAGE: () => EX_USAGE3,
31546
31917
  dispatchInit: () => dispatchInit,
31547
31918
  printInitHelp: () => printInitHelp,
31548
31919
  readScriptedReplies: () => readScriptedReplies
31549
31920
  });
31550
- import { readFile as readFile22 } from "node:fs/promises";
31921
+ import { readFile as readFile23 } from "node:fs/promises";
31551
31922
  import { resolve as resolve7 } from "node:path";
31552
31923
  function printInitHelp() {
31553
31924
  console.log(`archme init \u2014 set up ArchMe for your product, one repo or several
@@ -31569,10 +31940,13 @@ Usage:
31569
31940
  Options:
31570
31941
  --project <org/slug> Use this project instead of agreeing one in the conversation
31571
31942
  --skip-scan Set up agent config for this repo but do not scan
31943
+ --agent-only Join a project that already exists: write this clone's
31944
+ agent config (.mcp.json, CLAUDE.md block, architecture
31945
+ skill) and nothing else \u2014 no project, watching or scan.
31946
+ Uses --project, else the project .mcp.json pins
31572
31947
  --force Re-scan a repo whose board already has an architecture
31573
31948
  --yes Run unattended: this repo only, headless scan, no questions
31574
31949
  --no-interactive Same as --yes; for automation
31575
- --app-origin <url> Origin serving /api/install-agent (local development)
31576
31950
  --no-account If not signed in: continue without an account (a key
31577
31951
  saved on this machine signs you in; archme key show
31578
31952
  prints it)
@@ -31592,7 +31966,7 @@ into your repos except .mcp.json is git-ignored.`);
31592
31966
  async function readScriptedReplies(env) {
31593
31967
  const path7 = env.ARCHME_E2E_INIT_REPLIES;
31594
31968
  if (!path7) return void 0;
31595
- const parsed = JSON.parse(await readFile22(path7, "utf8"));
31969
+ const parsed = JSON.parse(await readFile23(path7, "utf8"));
31596
31970
  if (!Array.isArray(parsed) || !parsed.every((r) => typeof r === "string")) {
31597
31971
  throw new Error(`ARCHME_E2E_INIT_REPLIES (${path7}) must hold a JSON array of strings`);
31598
31972
  }
@@ -31611,7 +31985,7 @@ async function dispatchInit(argv) {
31611
31985
  if (!parsed.ok) {
31612
31986
  console.error(`archme init: ${parsed.error}`);
31613
31987
  printInitHelp();
31614
- return EX_USAGE2;
31988
+ return EX_USAGE3;
31615
31989
  }
31616
31990
  if (parsed.args.help) {
31617
31991
  printInitHelp();
@@ -31622,9 +31996,9 @@ async function dispatchInit(argv) {
31622
31996
  const result = await runInit({
31623
31997
  repoPath: resolve7(parsed.args.repoPath ?? process.cwd()),
31624
31998
  project: parsed.args.project,
31625
- appOrigin: parsed.args.appOrigin,
31626
31999
  force: parsed.args.force,
31627
32000
  skipScan: parsed.args.skipScan,
32001
+ agentOnly: parsed.args.agentOnly,
31628
32002
  yes: parsed.args.yes || parsed.args.noInteractive,
31629
32003
  login: parsed.args.login,
31630
32004
  ...scriptedReplies ? { scriptedReplies } : {}
@@ -31637,7 +32011,7 @@ async function dispatchInit(argv) {
31637
32011
  return EX_INFRA2;
31638
32012
  }
31639
32013
  }
31640
- var EX_OK2, EX_INFRA2, EX_USAGE2;
32014
+ var EX_OK2, EX_INFRA2, EX_USAGE3;
31641
32015
  var init_dispatch4 = __esm({
31642
32016
  "src/init/dispatch.ts"() {
31643
32017
  "use strict";
@@ -31647,93 +32021,7 @@ var init_dispatch4 = __esm({
31647
32021
  init_args();
31648
32022
  EX_OK2 = 0;
31649
32023
  EX_INFRA2 = 3;
31650
- EX_USAGE2 = 78;
31651
- }
31652
- });
31653
-
31654
- // src/uninstall/edits.ts
31655
- function stripArchmeClaudeBlock(content) {
31656
- const start = content.indexOf(START_MARKER);
31657
- if (start === -1) return UNCHANGED;
31658
- const end = content.indexOf(END_MARKER, start);
31659
- if (end === -1) return UNCHANGED;
31660
- const before = content.slice(0, start).replace(/\n+$/, "");
31661
- const after = content.slice(end + END_MARKER.length).replace(/^\n+/, "");
31662
- if (!before.trim() && !after.trim()) return { kind: "delete" };
31663
- if (!before.trim()) return { kind: "rewrite", content: `${after.replace(/\n*$/, "")}
31664
- ` };
31665
- if (!after.trim()) return { kind: "rewrite", content: `${before}
31666
- ` };
31667
- return { kind: "rewrite", content: `${before}
31668
-
31669
- ${after.replace(/\n*$/, "")}
31670
- ` };
31671
- }
31672
- function parseObject(raw) {
31673
- try {
31674
- const parsed = JSON.parse(raw);
31675
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
31676
- return parsed;
31677
- } catch {
31678
- return null;
31679
- }
31680
- }
31681
- function render(value) {
31682
- return `${JSON.stringify(value, null, 2)}
31683
- `;
31684
- }
31685
- function stripArchmeMcpServer(content) {
31686
- const root = parseObject(content);
31687
- if (!root) return UNCHANGED;
31688
- const servers = root.mcpServers;
31689
- if (!servers || typeof servers !== "object" || Array.isArray(servers)) return UNCHANGED;
31690
- const entries = servers;
31691
- if (!(MCP_SERVER_NAME2 in entries)) return UNCHANGED;
31692
- delete entries[MCP_SERVER_NAME2];
31693
- const onlyKey = Object.keys(root).length === 1 && "mcpServers" in root;
31694
- if (onlyKey && Object.keys(entries).length === 0) return { kind: "delete" };
31695
- return { kind: "rewrite", content: render(root) };
31696
- }
31697
- function isArchmeHook(hook) {
31698
- const command = hook?.command;
31699
- return typeof command === "string" && command.includes(NUDGE_HOOK_FILE);
31700
- }
31701
- function stripArchmeHooks(content) {
31702
- const root = parseObject(content);
31703
- if (!root) return UNCHANGED;
31704
- const hooks = root.hooks;
31705
- if (!hooks || typeof hooks !== "object" || Array.isArray(hooks)) return UNCHANGED;
31706
- const byEvent = hooks;
31707
- const pre = byEvent.PreToolUse;
31708
- if (!Array.isArray(pre)) return UNCHANGED;
31709
- let changed = false;
31710
- const kept = [];
31711
- for (const entry of pre) {
31712
- const inner = entry?.hooks;
31713
- if (!Array.isArray(inner) || !inner.some(isArchmeHook)) {
31714
- kept.push(entry);
31715
- continue;
31716
- }
31717
- changed = true;
31718
- const survivors = inner.filter((h2) => !isArchmeHook(h2));
31719
- if (survivors.length > 0) kept.push({ ...entry, hooks: survivors });
31720
- }
31721
- if (!changed) return UNCHANGED;
31722
- if (kept.length > 0) byEvent.PreToolUse = kept;
31723
- else delete byEvent.PreToolUse;
31724
- if (Object.keys(byEvent).length === 0) delete root.hooks;
31725
- if (Object.keys(root).length === 0) return { kind: "delete" };
31726
- return { kind: "rewrite", content: render(root) };
31727
- }
31728
- var UNCHANGED, START_MARKER, END_MARKER, NUDGE_HOOK_FILE, MCP_SERVER_NAME2;
31729
- var init_edits = __esm({
31730
- "src/uninstall/edits.ts"() {
31731
- "use strict";
31732
- UNCHANGED = { kind: "unchanged" };
31733
- START_MARKER = "<!-- ARCHME-START -->";
31734
- END_MARKER = "<!-- ARCHME-END -->";
31735
- NUDGE_HOOK_FILE = "archme-search-nudge.mjs";
31736
- MCP_SERVER_NAME2 = "archme";
32024
+ EX_USAGE3 = 78;
31737
32025
  }
31738
32026
  });
31739
32027
 
@@ -31863,7 +32151,7 @@ var init_backend = __esm({
31863
32151
  var run_uninstall_exports = {};
31864
32152
  __export(run_uninstall_exports, {
31865
32153
  EX_OK: () => EX_OK3,
31866
- EX_USAGE: () => EX_USAGE3,
32154
+ EX_USAGE: () => EX_USAGE4,
31867
32155
  runUninstall: () => runUninstall
31868
32156
  });
31869
32157
  import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync6, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
@@ -31995,7 +32283,7 @@ async function runUninstall(opts) {
31995
32283
  error(
31996
32284
  "archme uninstall: refusing to edit files without confirmation.\nThere is nobody to ask (stdin is not a terminal). Re-run with --yes."
31997
32285
  );
31998
- return { exitCode: EX_USAGE3, removed: [], unwatched: [] };
32286
+ return { exitCode: EX_USAGE4, removed: [], unwatched: [] };
31999
32287
  }
32000
32288
  const confirm = opts.confirm ?? (async (lines) => {
32001
32289
  log(`This will change, in ${repoPath} and on your ArchMe account:
@@ -32104,7 +32392,7 @@ async function defaultBackend() {
32104
32392
  const { createDefaultBackend: createDefaultBackend2 } = await Promise.resolve().then(() => (init_backend(), backend_exports));
32105
32393
  return createDefaultBackend2();
32106
32394
  }
32107
- var EX_OK3, EX_USAGE3, PRUNABLE_DIRS;
32395
+ var EX_OK3, EX_USAGE4, PRUNABLE_DIRS;
32108
32396
  var init_run_uninstall = __esm({
32109
32397
  "src/uninstall/run-uninstall.ts"() {
32110
32398
  "use strict";
@@ -32112,7 +32400,7 @@ var init_run_uninstall = __esm({
32112
32400
  init_edits();
32113
32401
  init_watching();
32114
32402
  EX_OK3 = 0;
32115
- EX_USAGE3 = 78;
32403
+ EX_USAGE4 = 78;
32116
32404
  PRUNABLE_DIRS = [
32117
32405
  ".claude/skills/architecture",
32118
32406
  ".claude/skills",
@@ -32127,7 +32415,7 @@ var dispatch_exports5 = {};
32127
32415
  __export(dispatch_exports5, {
32128
32416
  EX_INFRA: () => EX_INFRA3,
32129
32417
  EX_OK: () => EX_OK4,
32130
- EX_USAGE: () => EX_USAGE4,
32418
+ EX_USAGE: () => EX_USAGE5,
32131
32419
  dispatchUninstall: () => dispatchUninstall,
32132
32420
  parseUninstallArgs: () => parseUninstallArgs,
32133
32421
  printUninstallHelp: () => printUninstallHelp
@@ -32189,7 +32477,7 @@ async function dispatchUninstall(argv) {
32189
32477
  if (parsed.kind === "error") {
32190
32478
  console.error(`archme uninstall: ${parsed.message}`);
32191
32479
  printUninstallHelp();
32192
- return EX_USAGE4;
32480
+ return EX_USAGE5;
32193
32481
  }
32194
32482
  try {
32195
32483
  const { runUninstall: runUninstall2 } = await Promise.resolve().then(() => (init_run_uninstall(), run_uninstall_exports));
@@ -32204,13 +32492,13 @@ async function dispatchUninstall(argv) {
32204
32492
  return EX_INFRA3;
32205
32493
  }
32206
32494
  }
32207
- var EX_OK4, EX_INFRA3, EX_USAGE4;
32495
+ var EX_OK4, EX_INFRA3, EX_USAGE5;
32208
32496
  var init_dispatch5 = __esm({
32209
32497
  "src/uninstall/dispatch.ts"() {
32210
32498
  "use strict";
32211
32499
  EX_OK4 = 0;
32212
32500
  EX_INFRA3 = 3;
32213
- EX_USAGE4 = 78;
32501
+ EX_USAGE5 = 78;
32214
32502
  }
32215
32503
  });
32216
32504
 
@@ -32219,7 +32507,7 @@ var localWatchDispatch_exports = {};
32219
32507
  __export(localWatchDispatch_exports, {
32220
32508
  EX_INFRA: () => EX_INFRA4,
32221
32509
  EX_OK: () => EX_OK5,
32222
- EX_USAGE: () => EX_USAGE5,
32510
+ EX_USAGE: () => EX_USAGE6,
32223
32511
  dispatchLocalWatch: () => dispatchLocalWatch,
32224
32512
  parseLocalWatchArgs: () => parseLocalWatchArgs,
32225
32513
  printLocalWatchHelp: () => printLocalWatchHelp
@@ -32321,7 +32609,7 @@ async function dispatchLocalWatch(argv) {
32321
32609
  if (parsed.kind === "error") {
32322
32610
  console.error(parsed.message);
32323
32611
  printLocalWatchHelp();
32324
- return EX_USAGE5;
32612
+ return EX_USAGE6;
32325
32613
  }
32326
32614
  const mod = await Promise.resolve().then(() => (init_localWatch(), localWatch_exports));
32327
32615
  switch (parsed.kind) {
@@ -32335,13 +32623,13 @@ async function dispatchLocalWatch(argv) {
32335
32623
  return await mod.runLocalWatch(parsed);
32336
32624
  }
32337
32625
  }
32338
- var EX_OK5, EX_INFRA4, EX_USAGE5, PROJECT_SLUG_RE3, REPO_SLUG_RE2;
32626
+ var EX_OK5, EX_INFRA4, EX_USAGE6, PROJECT_SLUG_RE3, REPO_SLUG_RE2;
32339
32627
  var init_localWatchDispatch = __esm({
32340
32628
  "src/daemon/localWatchDispatch.ts"() {
32341
32629
  "use strict";
32342
32630
  EX_OK5 = 0;
32343
32631
  EX_INFRA4 = 3;
32344
- EX_USAGE5 = 78;
32632
+ EX_USAGE6 = 78;
32345
32633
  PROJECT_SLUG_RE3 = /^[^/\s]+\/[^/\s]+$/;
32346
32634
  REPO_SLUG_RE2 = /^[^/\s]+\/[^/\s]+$/;
32347
32635
  }
@@ -32479,7 +32767,6 @@ function parseAddReposArgs(argv) {
32479
32767
  let project;
32480
32768
  let local = false;
32481
32769
  let yes = false;
32482
- let appOrigin;
32483
32770
  for (let i2 = 0; i2 < argv.length; i2++) {
32484
32771
  const arg = argv[i2];
32485
32772
  const next = argv[i2 + 1];
@@ -32487,10 +32774,6 @@ function parseAddReposArgs(argv) {
32487
32774
  if (!next || !PROJECT_SLUG_RE5.test(next)) return err3("--project needs `org/slug`");
32488
32775
  project = next;
32489
32776
  i2++;
32490
- } else if (arg === "--app-origin") {
32491
- if (!next || next.startsWith("-")) return err3("--app-origin needs a URL");
32492
- appOrigin = next;
32493
- i2++;
32494
32777
  } else if (arg === "--local") {
32495
32778
  local = true;
32496
32779
  } else if (arg === "--yes" || arg === "--no-interactive") {
@@ -32502,7 +32785,7 @@ function parseAddReposArgs(argv) {
32502
32785
  }
32503
32786
  }
32504
32787
  if (!project) return err3("--project <org/slug> is required \u2014 the multi-repo project to add the repos to");
32505
- return { kind: "run", opts: { targets, project, local, yes, agentConfig: appOrigin ? { appOrigin } : {} } };
32788
+ return { kind: "run", opts: { targets, project, local, yes, agentConfig: true } };
32506
32789
  }
32507
32790
  function printAddReposHelp() {
32508
32791
  console.log(`archme add-repos \u2014 add several repos to a multi-repo project in one run
@@ -32537,7 +32820,6 @@ Options:
32537
32820
  --local Local watch: this machine checks for new commits, instead
32538
32821
  of GitHub watch (the ArchMe GitHub App)
32539
32822
  --yes Everything headless, no questions; the plan is approved
32540
- --app-origin <url> Origin serving /api/install-agent (local development)
32541
32823
 
32542
32824
  Every clone gets agent config (.mcp.json pinned to the project, a CLAUDE.md
32543
32825
  block, the architecture skill); everything but .mcp.json is git-ignored.`);
@@ -32648,13 +32930,13 @@ var dispatch_exports8 = {};
32648
32930
  __export(dispatch_exports8, {
32649
32931
  EX_INFRA: () => EX_INFRA5,
32650
32932
  EX_OK: () => EX_OK6,
32651
- EX_USAGE: () => EX_USAGE6,
32933
+ EX_USAGE: () => EX_USAGE7,
32652
32934
  dispatchDoctor: () => dispatchDoctor,
32653
32935
  parseDoctorArgs: () => parseDoctorArgs,
32654
32936
  printDoctorHelp: () => printDoctorHelp
32655
32937
  });
32656
- import { mkdtemp as mkdtemp6, rm as rm11, writeFile as writeFile20 } from "node:fs/promises";
32657
- import { tmpdir as tmpdir6 } from "node:os";
32938
+ import { mkdtemp as mkdtemp5, rm as rm10, writeFile as writeFile20 } from "node:fs/promises";
32939
+ import { tmpdir as tmpdir5 } from "node:os";
32658
32940
  import { join as join37 } from "node:path";
32659
32941
  function parseDoctorArgs(argv) {
32660
32942
  const args = { plain: false, help: false };
@@ -32687,7 +32969,7 @@ async function dispatchDoctor(argv) {
32687
32969
  if (!parsed.ok) {
32688
32970
  console.error(parsed.message);
32689
32971
  printDoctorHelp();
32690
- return EX_USAGE6;
32972
+ return EX_USAGE7;
32691
32973
  }
32692
32974
  if (parsed.args.help) {
32693
32975
  printDoctorHelp();
@@ -32716,7 +32998,7 @@ async function dispatchDoctor(argv) {
32716
32998
  );
32717
32999
  return EX_OK6;
32718
33000
  }
32719
- const dir = await mkdtemp6(join37(tmpdir6(), "archme-doctor-"));
33001
+ const dir = await mkdtemp5(join37(tmpdir5(), "archme-doctor-"));
32720
33002
  const mcpConfigPath = join37(dir, "mcp.json");
32721
33003
  await writeFile20(mcpConfigPath, JSON.stringify({ mcpServers: {} }), { mode: 384 });
32722
33004
  try {
@@ -32732,10 +33014,10 @@ async function dispatchDoctor(argv) {
32732
33014
  });
32733
33015
  return result.exitCode === 0 ? EX_OK6 : EX_INFRA5;
32734
33016
  } finally {
32735
- await rm11(dir, { recursive: true, force: true });
33017
+ await rm10(dir, { recursive: true, force: true });
32736
33018
  }
32737
33019
  }
32738
- var EX_OK6, EX_INFRA5, EX_USAGE6;
33020
+ var EX_OK6, EX_INFRA5, EX_USAGE7;
32739
33021
  var init_dispatch8 = __esm({
32740
33022
  "src/doctor/dispatch.ts"() {
32741
33023
  "use strict";
@@ -32746,7 +33028,7 @@ var init_dispatch8 = __esm({
32746
33028
  init_preflight();
32747
33029
  EX_OK6 = 0;
32748
33030
  EX_INFRA5 = 3;
32749
- EX_USAGE6 = 78;
33031
+ EX_USAGE7 = 78;
32750
33032
  }
32751
33033
  });
32752
33034
 
@@ -32885,7 +33167,7 @@ var init_conciergeToken = __esm({
32885
33167
  });
32886
33168
 
32887
33169
  // src/daemon/sandboxJob/input.ts
32888
- import { readFile as readFile23 } from "node:fs/promises";
33170
+ import { readFile as readFile24 } from "node:fs/promises";
32889
33171
  function isObj2(v) {
32890
33172
  return typeof v === "object" && v !== null && !Array.isArray(v);
32891
33173
  }
@@ -33138,7 +33420,7 @@ function parseInput(raw) {
33138
33420
  if (data.kind === "triage") return parseTriage(data, job);
33139
33421
  fail("kind must be clone, agent, digest, probe or triage");
33140
33422
  }
33141
- async function readInput(path7 = INPUT_PATH, read = (p) => readFile23(p, "utf8")) {
33423
+ async function readInput(path7 = INPUT_PATH, read = (p) => readFile24(p, "utf8")) {
33142
33424
  let raw;
33143
33425
  try {
33144
33426
  raw = await read(path7);
@@ -33163,7 +33445,7 @@ var init_input = __esm({
33163
33445
  REPO_PART_RE = /^[A-Za-z0-9_.-]+$/;
33164
33446
  IPV4_RE2 = /^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)$/;
33165
33447
  SOURCE_MODES = /* @__PURE__ */ new Set(["diff", "reconcile", "pr_update"]);
33166
- PROBE_KINDS = /* @__PURE__ */ new Set(["tcp", "udp_dns", "http", "connect", "ipv6_socket"]);
33448
+ PROBE_KINDS = /* @__PURE__ */ new Set(["tcp", "udp_dns", "http", "connect", "ipv6_socket", "web_fetch"]);
33167
33449
  PROBE_ID_RE = /^[a-z0-9_]{1,64}$/;
33168
33450
  }
33169
33451
  });
@@ -33220,7 +33502,8 @@ function httpStatus(t, timeoutMs, method) {
33220
33502
  method,
33221
33503
  agent: false,
33222
33504
  timeout: timeoutMs,
33223
- path: method === "CONNECT" ? t.authority ?? "github.com:443" : "/"
33505
+ path: method === "CONNECT" ? t.authority ?? "github.com:443" : method === "POST" ? "/v1/messages" : "/",
33506
+ headers: method === "POST" ? { authorization: `Bearer ${PLACEHOLDER_CLAUDE_TOKEN}`, "content-type": "application/json" } : void 0
33224
33507
  });
33225
33508
  req.on("response", (res) => {
33226
33509
  res.resume();
@@ -33232,7 +33515,7 @@ function httpStatus(t, timeoutMs, method) {
33232
33515
  });
33233
33516
  req.on("timeout", () => finish("none"));
33234
33517
  req.on("error", () => finish("none"));
33235
- req.end();
33518
+ req.end(method === "POST" ? WEB_FETCH_BODY : void 0);
33236
33519
  });
33237
33520
  }
33238
33521
  function ipv6Socket() {
@@ -33261,14 +33544,17 @@ async function runProbe(input) {
33261
33544
  return [t.id, await httpStatus(t, input.timeoutMs, "CONNECT")];
33262
33545
  case "ipv6_socket":
33263
33546
  return [t.id, await ipv6Socket()];
33547
+ case "web_fetch":
33548
+ return [t.id, await httpStatus(t, input.timeoutMs, "POST")];
33264
33549
  }
33265
33550
  }));
33266
33551
  return Object.fromEntries(results);
33267
33552
  }
33268
- var DNS_QUERY;
33553
+ var DNS_QUERY, WEB_FETCH_BODY;
33269
33554
  var init_probe = __esm({
33270
33555
  "src/daemon/sandboxJob/probe.ts"() {
33271
33556
  "use strict";
33557
+ init_types2();
33272
33558
  DNS_QUERY = Buffer.from([
33273
33559
  18,
33274
33560
  52,
@@ -33292,11 +33578,17 @@ var init_probe = __esm({
33292
33578
  0,
33293
33579
  1
33294
33580
  ]);
33581
+ WEB_FETCH_BODY = JSON.stringify({
33582
+ model: "claude-haiku-4-5",
33583
+ max_tokens: 16,
33584
+ messages: [{ role: "user", content: "fetch https://example.com/" }],
33585
+ tools: [{ type: "web_fetch_20250910", name: "web_fetch", max_uses: 1 }]
33586
+ });
33295
33587
  }
33296
33588
  });
33297
33589
 
33298
33590
  // src/daemon/sandboxJob/digest.ts
33299
- import { mkdir as mkdir20, writeFile as writeFile21 } from "node:fs/promises";
33591
+ import { mkdir as mkdir21, writeFile as writeFile21 } from "node:fs/promises";
33300
33592
  import { join as join38 } from "node:path";
33301
33593
  async function runDigestStep(input, deps = {}) {
33302
33594
  const log = deps.log ?? (() => {
@@ -33308,7 +33600,7 @@ async function runDigestStep(input, deps = {}) {
33308
33600
  const mcpDir = deps.mcpDir ?? BOX_MCP_DIR;
33309
33601
  const workDir = deps.workDir ?? "/tmp/digest";
33310
33602
  for (const d of [mcpDir, workDir, ...deps.homeDirs ?? [BOX_HOME, BOX_CLAUDE_CONFIG_DIR]]) {
33311
- await mkdir20(d, { recursive: true, mode: 448 });
33603
+ await mkdir21(d, { recursive: true, mode: 448 });
33312
33604
  }
33313
33605
  const mcpConfigPath = join38(mcpDir, "mcp.json");
33314
33606
  await writeFile21(mcpConfigPath, JSON.stringify(input.tools ? boxMcpConfig(input.gateway) : { mcpServers: {} }), { mode: 384 });
@@ -33354,7 +33646,7 @@ var init_digest2 = __esm({
33354
33646
  });
33355
33647
 
33356
33648
  // src/daemon/sandboxJob/triage.ts
33357
- import { mkdir as mkdir21, readFile as readFile24 } from "node:fs/promises";
33649
+ import { mkdir as mkdir22, readFile as readFile25 } from "node:fs/promises";
33358
33650
  async function runTriageStep(input, deps = {}) {
33359
33651
  const repoDir = deps.repoDir ?? REPO_DIR;
33360
33652
  const log = deps.log ?? (() => {
@@ -33365,7 +33657,7 @@ async function runTriageStep(input, deps = {}) {
33365
33657
  const writeStderr = deps.writeStderr ?? ((c3) => {
33366
33658
  process.stderr.write(c3);
33367
33659
  });
33368
- const diff = parsePersistedDiff(await readFile24(deps.diffPath ?? DIFF_PATH, "utf8"));
33660
+ const diff = parsePersistedDiff(await readFile25(deps.diffPath ?? DIFF_PATH, "utf8"));
33369
33661
  mark("read_diff");
33370
33662
  const { job } = input;
33371
33663
  const prompt = buildTriagePrompt({
@@ -33384,7 +33676,7 @@ async function runTriageStep(input, deps = {}) {
33384
33676
  });
33385
33677
  const promptBytes = Buffer.byteLength(prompt, "utf8");
33386
33678
  const mcpConfigPath = await writeBoxMcpConfig(input.gateway, deps.mcpDir);
33387
- for (const d of deps.homeDirs ?? [BOX_HOME, BOX_CLAUDE_CONFIG_DIR]) await mkdir21(d, { recursive: true, mode: 448 });
33679
+ for (const d of deps.homeDirs ?? [BOX_HOME, BOX_CLAUDE_CONFIG_DIR]) await mkdir22(d, { recursive: true, mode: 448 });
33388
33680
  log(`spawning triage claude (model ${input.model}, ${input.candidates.length} candidate(s), prompt ${promptBytes} bytes)`);
33389
33681
  const proc = spawn2({
33390
33682
  prompt,
@@ -33429,7 +33721,7 @@ __export(main_exports, {
33429
33721
  readNonceLine: () => readNonceLine,
33430
33722
  runSandboxJob: () => runSandboxJob
33431
33723
  });
33432
- import { mkdir as mkdir22 } from "node:fs/promises";
33724
+ import { mkdir as mkdir23 } from "node:fs/promises";
33433
33725
  function readNonceLine(stream = process.stdin) {
33434
33726
  return new Promise((resolve9) => {
33435
33727
  let buf = "";
@@ -33547,7 +33839,7 @@ async function runSandboxJob(argv, deps = {}) {
33547
33839
  if (input.kind === "digest") {
33548
33840
  log(`digest job=${input.jobId}`);
33549
33841
  try {
33550
- await mkdir22(deps.homeDir ?? process.env.HOME ?? BOX_HOME, { recursive: true, mode: 448 });
33842
+ await mkdir23(deps.homeDir ?? process.env.HOME ?? BOX_HOME, { recursive: true, mode: 448 });
33551
33843
  const { result, exitCode } = await runDigestStep(input, { log, mark, ...deps.digest });
33552
33844
  return emit2({ ...result, memoryPeakBytes: null, durations_ms: {} }, exitCode);
33553
33845
  } catch (err4) {
@@ -33558,7 +33850,7 @@ async function runSandboxJob(argv, deps = {}) {
33558
33850
  }
33559
33851
  log(`${stepName} job=${input.job.id} repo=${input.job.repo_owner}/${input.job.repo_name} ${input.job.after_sha ? `after=${input.job.after_sha.slice(0, 8)}` : `scan=${(input.job.scan_ref ?? "").slice(0, 8)}`}`);
33560
33852
  try {
33561
- await mkdir22(deps.homeDir ?? process.env.HOME ?? BOX_HOME, { recursive: true, mode: 448 });
33853
+ await mkdir23(deps.homeDir ?? process.env.HOME ?? BOX_HOME, { recursive: true, mode: 448 });
33562
33854
  if (input.kind === "clone") {
33563
33855
  const { result: result2, exitCode: exitCode2 } = await runCloneStep(input, { log, mark, ...deps.clone });
33564
33856
  return emit2({ ...result2, memoryPeakBytes: null, durations_ms: {} }, exitCode2);