@archme/cli 0.22.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
@@ -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
  }
@@ -33345,7 +33445,7 @@ var init_input = __esm({
33345
33445
  REPO_PART_RE = /^[A-Za-z0-9_.-]+$/;
33346
33446
  IPV4_RE2 = /^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)$/;
33347
33447
  SOURCE_MODES = /* @__PURE__ */ new Set(["diff", "reconcile", "pr_update"]);
33348
- 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"]);
33349
33449
  PROBE_ID_RE = /^[a-z0-9_]{1,64}$/;
33350
33450
  }
33351
33451
  });
@@ -33402,7 +33502,8 @@ function httpStatus(t, timeoutMs, method) {
33402
33502
  method,
33403
33503
  agent: false,
33404
33504
  timeout: timeoutMs,
33405
- 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
33406
33507
  });
33407
33508
  req.on("response", (res) => {
33408
33509
  res.resume();
@@ -33414,7 +33515,7 @@ function httpStatus(t, timeoutMs, method) {
33414
33515
  });
33415
33516
  req.on("timeout", () => finish("none"));
33416
33517
  req.on("error", () => finish("none"));
33417
- req.end();
33518
+ req.end(method === "POST" ? WEB_FETCH_BODY : void 0);
33418
33519
  });
33419
33520
  }
33420
33521
  function ipv6Socket() {
@@ -33443,14 +33544,17 @@ async function runProbe(input) {
33443
33544
  return [t.id, await httpStatus(t, input.timeoutMs, "CONNECT")];
33444
33545
  case "ipv6_socket":
33445
33546
  return [t.id, await ipv6Socket()];
33547
+ case "web_fetch":
33548
+ return [t.id, await httpStatus(t, input.timeoutMs, "POST")];
33446
33549
  }
33447
33550
  }));
33448
33551
  return Object.fromEntries(results);
33449
33552
  }
33450
- var DNS_QUERY;
33553
+ var DNS_QUERY, WEB_FETCH_BODY;
33451
33554
  var init_probe = __esm({
33452
33555
  "src/daemon/sandboxJob/probe.ts"() {
33453
33556
  "use strict";
33557
+ init_types2();
33454
33558
  DNS_QUERY = Buffer.from([
33455
33559
  18,
33456
33560
  52,
@@ -33474,6 +33578,12 @@ var init_probe = __esm({
33474
33578
  0,
33475
33579
  1
33476
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
+ });
33477
33587
  }
33478
33588
  });
33479
33589
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archme/cli",
3
- "version": "0.22.0",
3
+ "version": "0.23.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:3044db3a6c5fa7403a3092c3d5bde77410d1c84602c49e22112e78d39b2e0d78"
3
+ "digest": "sha256:3c2485d70aaa785c55a1fc9afaa29ffd0fa5284fb85847a0e9510072435bea9f"
4
4
  }