@archme/cli 0.22.0 → 0.24.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 +142 -14
- package/package.json +1 -1
- package/sandbox-image.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -18920,7 +18920,13 @@ function pickSourceMarker(rows, legacy, repo) {
|
|
|
18920
18920
|
return legacy?.last_source_sha && !legacy.last_source_repo ? { sha: legacy.last_source_sha, repo: null } : { sha: null, repo: null };
|
|
18921
18921
|
}
|
|
18922
18922
|
const row = rows.find((r) => sameRepo(`${r.repo_owner}/${r.repo_name}`, repo));
|
|
18923
|
-
if (row)
|
|
18923
|
+
if (row) {
|
|
18924
|
+
return {
|
|
18925
|
+
sha: row.last_source_sha,
|
|
18926
|
+
repo: `${row.repo_owner}/${row.repo_name}`,
|
|
18927
|
+
...row.rolled_up_through_sha ? { rolledUpThrough: row.rolled_up_through_sha } : {}
|
|
18928
|
+
};
|
|
18929
|
+
}
|
|
18924
18930
|
if (legacy?.last_source_sha && sameRepo(legacy.last_source_repo, repo)) {
|
|
18925
18931
|
return { sha: legacy.last_source_sha, repo: legacy.last_source_repo };
|
|
18926
18932
|
}
|
|
@@ -18937,7 +18943,7 @@ async function readBranchMarker(client, projectId, archmeBranch, repo) {
|
|
|
18937
18943
|
const { data, error } = await client.from("branches").select("id, last_source_sha, last_source_repo").eq("project_id", projectId).eq("name", archmeBranch).is("deleted_at", null).maybeSingle();
|
|
18938
18944
|
if (error || !data) return NO_MARKER;
|
|
18939
18945
|
const branch = data;
|
|
18940
|
-
const markers = await client.from("branch_source_markers").select("repo_owner, repo_name, last_source_sha").eq("branch_id", branch.id);
|
|
18946
|
+
const markers = await client.from("branch_source_markers").select("repo_owner, repo_name, last_source_sha, rolled_up_through_sha").eq("branch_id", branch.id);
|
|
18941
18947
|
if (markers.error && !MISSING_RELATION.has(markers.error.code ?? "")) {
|
|
18942
18948
|
return NO_MARKER;
|
|
18943
18949
|
}
|
|
@@ -19972,7 +19978,8 @@ async function pollRepoOnce(entry, deps) {
|
|
|
19972
19978
|
}
|
|
19973
19979
|
await deps.git.fetchOrigin(entry.mirrorPath, row.repoBranch);
|
|
19974
19980
|
const jobRepo = row.repoOwner && row.repoName ? `${row.repoOwner}/${row.repoName}` : repo;
|
|
19975
|
-
const
|
|
19981
|
+
const read = await deps.readMarker(row.projectId, row.archmeBranch, jobRepo);
|
|
19982
|
+
const marker = { ...read, sha: read.rolledUpThrough ?? read.sha };
|
|
19976
19983
|
const upstreamTip = await deps.git.revParse(entry.mirrorPath, `origin/${row.repoBranch}`);
|
|
19977
19984
|
const base = {
|
|
19978
19985
|
marker,
|
|
@@ -21437,7 +21444,7 @@ function filterHeaders(headers, drop) {
|
|
|
21437
21444
|
}
|
|
21438
21445
|
return out;
|
|
21439
21446
|
}
|
|
21440
|
-
function forward(req, res, target, headers, onResponse) {
|
|
21447
|
+
function forward(req, res, target, headers, onResponse, body) {
|
|
21441
21448
|
return new Promise((resolve9) => {
|
|
21442
21449
|
let settled = false;
|
|
21443
21450
|
const settle = (r) => {
|
|
@@ -21486,7 +21493,8 @@ function forward(req, res, target, headers, onResponse) {
|
|
|
21486
21493
|
settle({ status: "aborted" });
|
|
21487
21494
|
}
|
|
21488
21495
|
});
|
|
21489
|
-
|
|
21496
|
+
if (body) up.end(body);
|
|
21497
|
+
else req.pipe(up);
|
|
21490
21498
|
});
|
|
21491
21499
|
}
|
|
21492
21500
|
var HOP_BY_HOP;
|
|
@@ -21509,6 +21517,49 @@ var init_gateServer = __esm({
|
|
|
21509
21517
|
});
|
|
21510
21518
|
|
|
21511
21519
|
// src/daemon/sandbox/credentialGate.ts
|
|
21520
|
+
function refusedCapability(body, betaHeader) {
|
|
21521
|
+
const betas = [betaHeader ?? []].flat().join(",").toLowerCase();
|
|
21522
|
+
if (betas.includes("mcp-client") || betas.includes("web-fetch")) return "beta";
|
|
21523
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) return "body";
|
|
21524
|
+
const b = body;
|
|
21525
|
+
if (b.mcp_servers !== void 0) return "mcp_servers";
|
|
21526
|
+
const tools = Array.isArray(b.tools) ? b.tools : [];
|
|
21527
|
+
for (const t of tools) {
|
|
21528
|
+
const type = t?.type;
|
|
21529
|
+
if (typeof type !== "string") continue;
|
|
21530
|
+
if (type.startsWith("web_fetch")) return "web_fetch";
|
|
21531
|
+
if (type.startsWith("code_execution")) return "code_execution";
|
|
21532
|
+
}
|
|
21533
|
+
const stack = [b.system, b.messages];
|
|
21534
|
+
while (stack.length) {
|
|
21535
|
+
const v = stack.pop();
|
|
21536
|
+
if (typeof v !== "object" || v === null) continue;
|
|
21537
|
+
const src = v.source;
|
|
21538
|
+
if (typeof src === "object" && src !== null && src.type === "url") return "url_source";
|
|
21539
|
+
stack.push(...Object.values(v));
|
|
21540
|
+
}
|
|
21541
|
+
return null;
|
|
21542
|
+
}
|
|
21543
|
+
function readBody(req, max, charge) {
|
|
21544
|
+
return new Promise((resolve9, reject) => {
|
|
21545
|
+
const chunks = [];
|
|
21546
|
+
let size = 0;
|
|
21547
|
+
const onData = (c3) => {
|
|
21548
|
+
size += c3.length;
|
|
21549
|
+
if (size > max || !charge(c3.length)) {
|
|
21550
|
+
req.off("data", onData);
|
|
21551
|
+
req.pause();
|
|
21552
|
+
resolve9(null);
|
|
21553
|
+
return;
|
|
21554
|
+
}
|
|
21555
|
+
chunks.push(c3);
|
|
21556
|
+
};
|
|
21557
|
+
req.on("data", onData);
|
|
21558
|
+
req.once("end", () => resolve9(Buffer.concat(chunks)));
|
|
21559
|
+
req.once("error", reject);
|
|
21560
|
+
req.once("close", () => reject(new Error("aborted")));
|
|
21561
|
+
});
|
|
21562
|
+
}
|
|
21512
21563
|
function searchOf(url) {
|
|
21513
21564
|
try {
|
|
21514
21565
|
return new URL(url ?? "/", "http://gate").search;
|
|
@@ -21516,7 +21567,7 @@ function searchOf(url) {
|
|
|
21516
21567
|
return "";
|
|
21517
21568
|
}
|
|
21518
21569
|
}
|
|
21519
|
-
var ANTHROPIC_UPSTREAM, ALLOWED_PATHS, CredentialGate;
|
|
21570
|
+
var ANTHROPIC_UPSTREAM, ALLOWED_PATHS, MAX_BODY_BYTES, MAX_SLOT_BUFFERED_BYTES, CredentialGate;
|
|
21520
21571
|
var init_credentialGate = __esm({
|
|
21521
21572
|
"src/daemon/sandbox/credentialGate.ts"() {
|
|
21522
21573
|
"use strict";
|
|
@@ -21524,6 +21575,8 @@ var init_credentialGate = __esm({
|
|
|
21524
21575
|
init_types2();
|
|
21525
21576
|
ANTHROPIC_UPSTREAM = "https://api.anthropic.com";
|
|
21526
21577
|
ALLOWED_PATHS = /* @__PURE__ */ new Set(["/v1/messages", "/v1/messages/count_tokens"]);
|
|
21578
|
+
MAX_BODY_BYTES = 32 * 1024 * 1024;
|
|
21579
|
+
MAX_SLOT_BUFFERED_BYTES = 2 * MAX_BODY_BYTES;
|
|
21527
21580
|
CredentialGate = class {
|
|
21528
21581
|
constructor(opts) {
|
|
21529
21582
|
this.opts = opts;
|
|
@@ -21539,13 +21592,15 @@ var init_credentialGate = __esm({
|
|
|
21539
21592
|
}
|
|
21540
21593
|
gate;
|
|
21541
21594
|
upstream;
|
|
21595
|
+
/** Request-body bytes each slot holds right now, until its forward settles. */
|
|
21596
|
+
buffered = /* @__PURE__ */ new Map();
|
|
21542
21597
|
listen() {
|
|
21543
21598
|
return this.gate.listen();
|
|
21544
21599
|
}
|
|
21545
21600
|
close() {
|
|
21546
21601
|
return this.gate.close();
|
|
21547
21602
|
}
|
|
21548
|
-
handle(req, res, ctx) {
|
|
21603
|
+
async handle(req, res, ctx) {
|
|
21549
21604
|
if (req.method !== "POST" || !ALLOWED_PATHS.has(ctx.path)) {
|
|
21550
21605
|
ctx.done(404);
|
|
21551
21606
|
res.writeHead(404).end();
|
|
@@ -21556,6 +21611,56 @@ var init_credentialGate = __esm({
|
|
|
21556
21611
|
res.writeHead(403).end();
|
|
21557
21612
|
return;
|
|
21558
21613
|
}
|
|
21614
|
+
const slot = ctx.slot.index;
|
|
21615
|
+
const cap = this.opts.maxSlotBufferedBytes ?? MAX_SLOT_BUFFERED_BYTES;
|
|
21616
|
+
let held = 0;
|
|
21617
|
+
const charge = (n2) => {
|
|
21618
|
+
const used = (this.buffered.get(slot) ?? 0) + n2;
|
|
21619
|
+
if (used > cap) return false;
|
|
21620
|
+
this.buffered.set(slot, used);
|
|
21621
|
+
held += n2;
|
|
21622
|
+
return true;
|
|
21623
|
+
};
|
|
21624
|
+
try {
|
|
21625
|
+
await this.handleBody(req, res, ctx, charge);
|
|
21626
|
+
} finally {
|
|
21627
|
+
const left = (this.buffered.get(slot) ?? 0) - held;
|
|
21628
|
+
if (left > 0) this.buffered.set(slot, left);
|
|
21629
|
+
else this.buffered.delete(slot);
|
|
21630
|
+
}
|
|
21631
|
+
}
|
|
21632
|
+
async handleBody(req, res, ctx, charge) {
|
|
21633
|
+
let body;
|
|
21634
|
+
try {
|
|
21635
|
+
body = await readBody(req, MAX_BODY_BYTES, charge);
|
|
21636
|
+
} catch {
|
|
21637
|
+
ctx.done("aborted");
|
|
21638
|
+
res.destroy();
|
|
21639
|
+
return;
|
|
21640
|
+
}
|
|
21641
|
+
if (!body) {
|
|
21642
|
+
ctx.done(413, "body");
|
|
21643
|
+
res.writeHead(413, { connection: "close" }).end();
|
|
21644
|
+
return;
|
|
21645
|
+
}
|
|
21646
|
+
const encoding = req.headers["content-encoding"];
|
|
21647
|
+
if (encoding && encoding !== "identity") {
|
|
21648
|
+
ctx.done(415, "content-encoding");
|
|
21649
|
+
res.writeHead(415).end();
|
|
21650
|
+
return;
|
|
21651
|
+
}
|
|
21652
|
+
let parsed;
|
|
21653
|
+
try {
|
|
21654
|
+
parsed = JSON.parse(body.toString("utf8"));
|
|
21655
|
+
} catch {
|
|
21656
|
+
parsed = void 0;
|
|
21657
|
+
}
|
|
21658
|
+
const refused = refusedCapability(parsed, req.headers["anthropic-beta"]);
|
|
21659
|
+
if (refused) {
|
|
21660
|
+
ctx.done(403, `tool ${refused}`);
|
|
21661
|
+
res.writeHead(403).end();
|
|
21662
|
+
return;
|
|
21663
|
+
}
|
|
21559
21664
|
const { counters, maxModelRequests } = ctx.binding;
|
|
21560
21665
|
if (counters.model_requests >= maxModelRequests) {
|
|
21561
21666
|
counters.cap_hits++;
|
|
@@ -21566,13 +21671,15 @@ var init_credentialGate = __esm({
|
|
|
21566
21671
|
counters.model_requests++;
|
|
21567
21672
|
const headers = filterHeaders(req.headers, (k) => k === "authorization" || k === "x-api-key");
|
|
21568
21673
|
headers.authorization = `Bearer ${this.opts.getToken()}`;
|
|
21674
|
+
headers["content-length"] = String(body.length);
|
|
21569
21675
|
const target = new URL(this.upstream.origin);
|
|
21570
21676
|
target.pathname = ctx.path;
|
|
21571
21677
|
target.search = searchOf(req.url);
|
|
21572
|
-
|
|
21678
|
+
const r = await forward(req, res, target, headers, (status) => {
|
|
21573
21679
|
if (status === 429) counters.upstream_429++;
|
|
21574
21680
|
counters.last_upstream_status = status;
|
|
21575
|
-
}
|
|
21681
|
+
}, body);
|
|
21682
|
+
ctx.done(r.status);
|
|
21576
21683
|
}
|
|
21577
21684
|
};
|
|
21578
21685
|
}
|
|
@@ -23854,6 +23961,12 @@ async function computeDiff(job, repoDir, marker, gitEnv) {
|
|
|
23854
23961
|
}
|
|
23855
23962
|
const { exitCode } = await execa("git", ["merge-base", "--is-ancestor", after, base], { cwd: repoDir, reject: false });
|
|
23856
23963
|
if (exitCode === 0) return "skip";
|
|
23964
|
+
const before = job.before_sha?.toLowerCase();
|
|
23965
|
+
if (!job.forced && before && before !== base.toLowerCase() && before !== marker.rolledUpThrough?.toLowerCase()) {
|
|
23966
|
+
throw new Error(
|
|
23967
|
+
`commit ${after.slice(0, 8)} does not follow ${base.slice(0, 8)}, the last commit this board reflects for ${job.repo_owner}/${job.repo_name}: a commit between them has no architecture update. Requeue it, or roll it up into the next one.`
|
|
23968
|
+
);
|
|
23969
|
+
}
|
|
23857
23970
|
const payload = await buildDiffPayload(repoDir, base, after);
|
|
23858
23971
|
if (job.forced) payload.provenance = await forcePushProvenance(repoDir, base, after);
|
|
23859
23972
|
return payload;
|
|
@@ -33168,7 +33281,12 @@ function parseCredentials(raw) {
|
|
|
33168
33281
|
}
|
|
33169
33282
|
function parseMarker(raw) {
|
|
33170
33283
|
if (!isObj2(raw)) fail("marker must be an object");
|
|
33171
|
-
|
|
33284
|
+
const rolledUpThrough = optStr(raw, "rolledUpThrough", "marker");
|
|
33285
|
+
return {
|
|
33286
|
+
sha: optStr(raw, "sha", "marker"),
|
|
33287
|
+
repo: optStr(raw, "repo", "marker"),
|
|
33288
|
+
...rolledUpThrough ? { rolledUpThrough } : {}
|
|
33289
|
+
};
|
|
33172
33290
|
}
|
|
33173
33291
|
function parseSeedArch(raw) {
|
|
33174
33292
|
if (raw === null || raw === void 0) return null;
|
|
@@ -33345,7 +33463,7 @@ var init_input = __esm({
|
|
|
33345
33463
|
REPO_PART_RE = /^[A-Za-z0-9_.-]+$/;
|
|
33346
33464
|
IPV4_RE2 = /^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)$/;
|
|
33347
33465
|
SOURCE_MODES = /* @__PURE__ */ new Set(["diff", "reconcile", "pr_update"]);
|
|
33348
|
-
PROBE_KINDS = /* @__PURE__ */ new Set(["tcp", "udp_dns", "http", "connect", "ipv6_socket"]);
|
|
33466
|
+
PROBE_KINDS = /* @__PURE__ */ new Set(["tcp", "udp_dns", "http", "connect", "ipv6_socket", "web_fetch"]);
|
|
33349
33467
|
PROBE_ID_RE = /^[a-z0-9_]{1,64}$/;
|
|
33350
33468
|
}
|
|
33351
33469
|
});
|
|
@@ -33402,7 +33520,8 @@ function httpStatus(t, timeoutMs, method) {
|
|
|
33402
33520
|
method,
|
|
33403
33521
|
agent: false,
|
|
33404
33522
|
timeout: timeoutMs,
|
|
33405
|
-
path: method === "CONNECT" ? t.authority ?? "github.com:443" : "/"
|
|
33523
|
+
path: method === "CONNECT" ? t.authority ?? "github.com:443" : method === "POST" ? "/v1/messages" : "/",
|
|
33524
|
+
headers: method === "POST" ? { authorization: `Bearer ${PLACEHOLDER_CLAUDE_TOKEN}`, "content-type": "application/json" } : void 0
|
|
33406
33525
|
});
|
|
33407
33526
|
req.on("response", (res) => {
|
|
33408
33527
|
res.resume();
|
|
@@ -33414,7 +33533,7 @@ function httpStatus(t, timeoutMs, method) {
|
|
|
33414
33533
|
});
|
|
33415
33534
|
req.on("timeout", () => finish("none"));
|
|
33416
33535
|
req.on("error", () => finish("none"));
|
|
33417
|
-
req.end();
|
|
33536
|
+
req.end(method === "POST" ? WEB_FETCH_BODY : void 0);
|
|
33418
33537
|
});
|
|
33419
33538
|
}
|
|
33420
33539
|
function ipv6Socket() {
|
|
@@ -33443,14 +33562,17 @@ async function runProbe(input) {
|
|
|
33443
33562
|
return [t.id, await httpStatus(t, input.timeoutMs, "CONNECT")];
|
|
33444
33563
|
case "ipv6_socket":
|
|
33445
33564
|
return [t.id, await ipv6Socket()];
|
|
33565
|
+
case "web_fetch":
|
|
33566
|
+
return [t.id, await httpStatus(t, input.timeoutMs, "POST")];
|
|
33446
33567
|
}
|
|
33447
33568
|
}));
|
|
33448
33569
|
return Object.fromEntries(results);
|
|
33449
33570
|
}
|
|
33450
|
-
var DNS_QUERY;
|
|
33571
|
+
var DNS_QUERY, WEB_FETCH_BODY;
|
|
33451
33572
|
var init_probe = __esm({
|
|
33452
33573
|
"src/daemon/sandboxJob/probe.ts"() {
|
|
33453
33574
|
"use strict";
|
|
33575
|
+
init_types2();
|
|
33454
33576
|
DNS_QUERY = Buffer.from([
|
|
33455
33577
|
18,
|
|
33456
33578
|
52,
|
|
@@ -33474,6 +33596,12 @@ var init_probe = __esm({
|
|
|
33474
33596
|
0,
|
|
33475
33597
|
1
|
|
33476
33598
|
]);
|
|
33599
|
+
WEB_FETCH_BODY = JSON.stringify({
|
|
33600
|
+
model: "claude-haiku-4-5",
|
|
33601
|
+
max_tokens: 16,
|
|
33602
|
+
messages: [{ role: "user", content: "fetch https://example.com/" }],
|
|
33603
|
+
tools: [{ type: "web_fetch_20250910", name: "web_fetch", max_uses: 1 }]
|
|
33604
|
+
});
|
|
33477
33605
|
}
|
|
33478
33606
|
});
|
|
33479
33607
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@archme/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.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