codebase-snapshot 0.13.0 → 0.14.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/CHANGELOG.md +130 -0
- package/README.md +1 -1
- package/SECURITY.md +2 -2
- package/dist/bin.js +329 -85
- package/dist/{chunk-BOJYZQFB.js → chunk-2YNQ42B3.js} +287 -85
- package/dist/{chunk-NESEHOPU.js → chunk-7WSZUMT6.js} +41 -1
- package/dist/cli.cjs +327 -85
- package/dist/cli.js +3 -3
- package/dist/index.cjs +287 -85
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +327 -85
- package/dist/mcp.d.cts +6 -15
- package/dist/mcp.d.ts +6 -15
- package/dist/mcp.js +2 -2
- package/docs/cli.md +3 -3
- package/docs/deploy.md +2 -2
- package/docs/health.md +31 -0
- package/docs/mcp.md +9 -5
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -2221,7 +2221,7 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
2221
2221
|
|
|
2222
2222
|
// src/version.ts
|
|
2223
2223
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
2224
|
-
var GENERATOR_VERSION = "0.
|
|
2224
|
+
var GENERATOR_VERSION = "0.14.0";
|
|
2225
2225
|
var SCHEMA_VERSION = "3.0.0";
|
|
2226
2226
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2227
2227
|
function isOurGeneratorName(name) {
|
|
@@ -11777,6 +11777,92 @@ function verifySnapshotSignature(snapshotDir) {
|
|
|
11777
11777
|
return verified ? { ok: true, record } : { ok: false, reason: "the signature does not match the manifest" };
|
|
11778
11778
|
}
|
|
11779
11779
|
|
|
11780
|
+
// src/partitioner/part-format.ts
|
|
11781
|
+
var FILE_HEADING = "### FILE: ";
|
|
11782
|
+
var CONTENT_MARKERS = /* @__PURE__ */ new Set(["#### Content", "#### Bounded Preview"]);
|
|
11783
|
+
var ANCHOR_LINE = /^<a id="([^"]+)"><\/a>$/;
|
|
11784
|
+
var META_PREFIX = "- Meta: ";
|
|
11785
|
+
var LEGACY_INCLUSION_PREFIX = "- Inclusion: ";
|
|
11786
|
+
var LEGACY_INCLUDED_LINES_PREFIX = "- Included Lines: ";
|
|
11787
|
+
var INCLUSION_MODES = /* @__PURE__ */ new Set(["full", "preview", "signatures"]);
|
|
11788
|
+
var COMPACT_COUNTS = /^(\d+)\s+lines?(?:\s+of\s+\d+\s+lines?)?/;
|
|
11789
|
+
function readIncludedLines(fields) {
|
|
11790
|
+
const last = fields[fields.length - 1];
|
|
11791
|
+
if (last === void 0) return null;
|
|
11792
|
+
const counts = COMPACT_COUNTS.exec(last.trim());
|
|
11793
|
+
return counts === null ? null : Number(counts[1]);
|
|
11794
|
+
}
|
|
11795
|
+
function parsePartSections(partText) {
|
|
11796
|
+
const lines = partText.split("\n");
|
|
11797
|
+
const sections = [];
|
|
11798
|
+
let index = 0;
|
|
11799
|
+
while (index < lines.length) {
|
|
11800
|
+
if (!lines[index].startsWith(FILE_HEADING)) {
|
|
11801
|
+
index += 1;
|
|
11802
|
+
continue;
|
|
11803
|
+
}
|
|
11804
|
+
const heading = lines[index].slice(FILE_HEADING.length);
|
|
11805
|
+
const anchorMatch = index > 0 ? ANCHOR_LINE.exec(lines[index - 1]) : null;
|
|
11806
|
+
let cursor = index + 1;
|
|
11807
|
+
let inclusion = null;
|
|
11808
|
+
let includedLines = null;
|
|
11809
|
+
while (cursor < lines.length && !CONTENT_MARKERS.has(lines[cursor])) {
|
|
11810
|
+
const line = lines[cursor];
|
|
11811
|
+
if (line.startsWith(FILE_HEADING)) break;
|
|
11812
|
+
if (line.startsWith(META_PREFIX)) {
|
|
11813
|
+
const fields = line.slice(META_PREFIX.length).split("|");
|
|
11814
|
+
for (const field of fields) {
|
|
11815
|
+
const value = field.trim();
|
|
11816
|
+
if (INCLUSION_MODES.has(value)) inclusion = value;
|
|
11817
|
+
}
|
|
11818
|
+
includedLines = readIncludedLines(fields);
|
|
11819
|
+
} else if (line.startsWith(LEGACY_INCLUSION_PREFIX)) {
|
|
11820
|
+
inclusion = line.slice(LEGACY_INCLUSION_PREFIX.length).trim();
|
|
11821
|
+
} else if (line.startsWith(LEGACY_INCLUDED_LINES_PREFIX)) {
|
|
11822
|
+
const value = Number(line.slice(LEGACY_INCLUDED_LINES_PREFIX.length).trim());
|
|
11823
|
+
includedLines = Number.isFinite(value) ? value : null;
|
|
11824
|
+
}
|
|
11825
|
+
cursor += 1;
|
|
11826
|
+
}
|
|
11827
|
+
if (cursor >= lines.length || !CONTENT_MARKERS.has(lines[cursor])) {
|
|
11828
|
+
index = cursor + 1;
|
|
11829
|
+
continue;
|
|
11830
|
+
}
|
|
11831
|
+
let fenceLine = cursor + 1;
|
|
11832
|
+
while (fenceLine < lines.length && lines[fenceLine].trim().length === 0) fenceLine += 1;
|
|
11833
|
+
const fenceMatch = /^(`{4,})/.exec(lines[fenceLine] ?? "");
|
|
11834
|
+
if (!fenceMatch) {
|
|
11835
|
+
index = cursor + 1;
|
|
11836
|
+
continue;
|
|
11837
|
+
}
|
|
11838
|
+
const fence = fenceMatch[1];
|
|
11839
|
+
const body = [];
|
|
11840
|
+
let bodyLine = fenceLine + 1;
|
|
11841
|
+
while (bodyLine < lines.length && lines[bodyLine] !== fence) {
|
|
11842
|
+
body.push(lines[bodyLine]);
|
|
11843
|
+
bodyLine += 1;
|
|
11844
|
+
}
|
|
11845
|
+
sections.push({ path: heading, anchor: anchorMatch?.[1] ?? null, body: body.join("\n"), inclusion, includedLines });
|
|
11846
|
+
index = bodyLine + 1;
|
|
11847
|
+
}
|
|
11848
|
+
return sections;
|
|
11849
|
+
}
|
|
11850
|
+
function findSection(sections, relativePath) {
|
|
11851
|
+
const anchor = anchorForPath(relativePath);
|
|
11852
|
+
const byAnchor = sections.find((section) => section.anchor === anchor);
|
|
11853
|
+
if (byAnchor) return byAnchor;
|
|
11854
|
+
const rendered = displayPath(relativePath);
|
|
11855
|
+
const samePath = (section) => section.path === relativePath || section.path === rendered;
|
|
11856
|
+
const exact = sections.find(samePath);
|
|
11857
|
+
if (exact) return exact;
|
|
11858
|
+
const foldedPath = rendered.toLowerCase();
|
|
11859
|
+
const folded = sections.filter((section) => {
|
|
11860
|
+
const path28 = section.path.toLowerCase();
|
|
11861
|
+
return path28 === relativePath.toLowerCase() || path28 === foldedPath;
|
|
11862
|
+
});
|
|
11863
|
+
return folded.length === 1 ? folded[0] : null;
|
|
11864
|
+
}
|
|
11865
|
+
|
|
11780
11866
|
// src/auditor/health.ts
|
|
11781
11867
|
var ARTIFACT_FILES = {
|
|
11782
11868
|
readme: "README.md",
|
|
@@ -12086,6 +12172,206 @@ function auditSnapshot(options) {
|
|
|
12086
12172
|
)
|
|
12087
12173
|
);
|
|
12088
12174
|
}
|
|
12175
|
+
const bookkeeping = [];
|
|
12176
|
+
const expect = (name, recorded2, computed) => {
|
|
12177
|
+
if (recorded2 !== computed) bookkeeping.push(name + ": manifest says " + recorded2 + ", the data has " + computed);
|
|
12178
|
+
};
|
|
12179
|
+
expect("counts.totalFiles", manifest.counts.totalFiles, manifest.files.length);
|
|
12180
|
+
expect("counts.partsCount", manifest.counts.partsCount, manifest.parts.length);
|
|
12181
|
+
expect("counts.skippedCount", manifest.counts.skippedCount, manifest.skipped.length);
|
|
12182
|
+
if (typeof manifest.totals.includedFiles === "number") {
|
|
12183
|
+
expect("totals.includedFiles", manifest.totals.includedFiles, manifest.files.length);
|
|
12184
|
+
}
|
|
12185
|
+
const contentBytes = manifest.files.reduce((sum, file) => sum + file.includedBytes, 0);
|
|
12186
|
+
expect("totals.totalContentBytes", manifest.totals.totalContentBytes, contentBytes);
|
|
12187
|
+
const layerCounts = /* @__PURE__ */ new Map();
|
|
12188
|
+
for (const file of manifest.files) layerCounts.set(file.layer, (layerCounts.get(file.layer) ?? 0) + 1);
|
|
12189
|
+
for (const [layer2, count] of layerCounts) {
|
|
12190
|
+
expect("layers." + layer2, manifest.layers[layer2] ?? -1, count);
|
|
12191
|
+
}
|
|
12192
|
+
for (const layer2 of Object.keys(manifest.layers)) {
|
|
12193
|
+
if (!layerCounts.has(layer2)) expect("layers." + layer2, manifest.layers[layer2], 0);
|
|
12194
|
+
}
|
|
12195
|
+
checks.push(
|
|
12196
|
+
bookkeeping.length === 0 ? check(
|
|
12197
|
+
"bookkeeping",
|
|
12198
|
+
"The counts equal the data they summarise",
|
|
12199
|
+
"critical",
|
|
12200
|
+
"pass",
|
|
12201
|
+
"Files, parts, skips, content bytes and layer counts all agree."
|
|
12202
|
+
) : check(
|
|
12203
|
+
"bookkeeping",
|
|
12204
|
+
"The counts equal the data they summarise",
|
|
12205
|
+
"critical",
|
|
12206
|
+
"fail",
|
|
12207
|
+
bookkeeping.length + " mismatch(es): " + sample(bookkeeping)
|
|
12208
|
+
)
|
|
12209
|
+
);
|
|
12210
|
+
const packReaders = [
|
|
12211
|
+
{
|
|
12212
|
+
key: "fullJson",
|
|
12213
|
+
file: "full-codebase.json",
|
|
12214
|
+
label: "JSON",
|
|
12215
|
+
paths: (text2) => {
|
|
12216
|
+
try {
|
|
12217
|
+
const parsed = JSON.parse(text2);
|
|
12218
|
+
if (!Array.isArray(parsed?.files)) return null;
|
|
12219
|
+
return new Set(parsed.files.map((entry) => String(entry?.relativePath)));
|
|
12220
|
+
} catch {
|
|
12221
|
+
return null;
|
|
12222
|
+
}
|
|
12223
|
+
}
|
|
12224
|
+
},
|
|
12225
|
+
{
|
|
12226
|
+
key: "fullXml",
|
|
12227
|
+
file: "full-codebase.xml",
|
|
12228
|
+
label: "XML",
|
|
12229
|
+
paths: (text2) => {
|
|
12230
|
+
const found = [...text2.matchAll(/<file path="([^"]+)"/g)].map((match) => match[1]);
|
|
12231
|
+
if (found.length === 0) return null;
|
|
12232
|
+
return new Set(found.map((value) => value.replace(/"/g, '"').replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&")));
|
|
12233
|
+
}
|
|
12234
|
+
},
|
|
12235
|
+
{
|
|
12236
|
+
key: "fullMarkdown",
|
|
12237
|
+
file: "full-codebase.md",
|
|
12238
|
+
label: "markdown",
|
|
12239
|
+
paths: (text2) => {
|
|
12240
|
+
const found = [...text2.matchAll(/^## File: (.+)$/gm)].map((match) => match[1].trim());
|
|
12241
|
+
if (found.length === 0) return null;
|
|
12242
|
+
return new Set(found);
|
|
12243
|
+
}
|
|
12244
|
+
}
|
|
12245
|
+
];
|
|
12246
|
+
for (const reader of packReaders) {
|
|
12247
|
+
if (manifest.artifacts?.[reader.key] == null) continue;
|
|
12248
|
+
const packText = readText2(path27__namespace.join(snapshotDir, reader.file));
|
|
12249
|
+
const problems = [];
|
|
12250
|
+
if (packText === null) {
|
|
12251
|
+
problems.push(reader.file + " is recorded but unreadable");
|
|
12252
|
+
} else {
|
|
12253
|
+
const packed = reader.paths(packText);
|
|
12254
|
+
if (packed === null) {
|
|
12255
|
+
problems.push(reader.file + " could not be parsed for its file list");
|
|
12256
|
+
} else {
|
|
12257
|
+
const known2 = new Set(manifest.files.map((file) => file.relativePath));
|
|
12258
|
+
for (const file of manifest.files) {
|
|
12259
|
+
if (!packed.has(file.relativePath)) problems.push(file.relativePath + " is in the manifest but not the pack");
|
|
12260
|
+
}
|
|
12261
|
+
for (const path28 of packed) {
|
|
12262
|
+
if (!known2.has(path28)) problems.push(path28 + " is in the pack but not the manifest");
|
|
12263
|
+
}
|
|
12264
|
+
}
|
|
12265
|
+
}
|
|
12266
|
+
const title = "The " + reader.label + " pack holds every file the manifest lists";
|
|
12267
|
+
checks.push(
|
|
12268
|
+
problems.length === 0 ? check(
|
|
12269
|
+
"pipeline.monolith",
|
|
12270
|
+
title,
|
|
12271
|
+
"critical",
|
|
12272
|
+
"pass",
|
|
12273
|
+
manifest.files.length + " file(s) present in " + reader.file + ", and nothing extra."
|
|
12274
|
+
) : check(
|
|
12275
|
+
"pipeline.monolith",
|
|
12276
|
+
title,
|
|
12277
|
+
"critical",
|
|
12278
|
+
"fail",
|
|
12279
|
+
problems.length + " problem(s): " + sample(problems)
|
|
12280
|
+
)
|
|
12281
|
+
);
|
|
12282
|
+
}
|
|
12283
|
+
const bodyProblems = [];
|
|
12284
|
+
let bodiesChecked = 0;
|
|
12285
|
+
for (const part of manifest.parts) {
|
|
12286
|
+
const partText = readText2(path27__namespace.join(snapshotDir, "parts", part.filename));
|
|
12287
|
+
if (partText === null) continue;
|
|
12288
|
+
const sections = parsePartSections(partText);
|
|
12289
|
+
for (const file of manifest.files) {
|
|
12290
|
+
if (file.part !== part.filename) continue;
|
|
12291
|
+
const section = findSection(sections, file.relativePath);
|
|
12292
|
+
if (section === null) {
|
|
12293
|
+
bodyProblems.push(file.relativePath + " has no section in " + part.filename);
|
|
12294
|
+
continue;
|
|
12295
|
+
}
|
|
12296
|
+
bodiesChecked += 1;
|
|
12297
|
+
const bytes = Buffer.byteLength(section.body, "utf8");
|
|
12298
|
+
const bodyLines = section.body === "" ? 0 : section.body.split("\n").length - (section.body.endsWith("\n") ? 1 : 0);
|
|
12299
|
+
if (bytes !== file.includedBytes) {
|
|
12300
|
+
bodyProblems.push(file.relativePath + ": manifest says " + file.includedBytes + " B, part holds " + bytes + " B");
|
|
12301
|
+
} else if (bodyLines !== file.includedLines) {
|
|
12302
|
+
bodyProblems.push(file.relativePath + ": manifest says " + file.includedLines + " line(s), part holds " + bodyLines);
|
|
12303
|
+
}
|
|
12304
|
+
}
|
|
12305
|
+
}
|
|
12306
|
+
checks.push(
|
|
12307
|
+
bodyProblems.length === 0 ? check(
|
|
12308
|
+
"pipeline.bodies",
|
|
12309
|
+
"Every file body matches the manifest accounting",
|
|
12310
|
+
"critical",
|
|
12311
|
+
"pass",
|
|
12312
|
+
bodiesChecked + " file body/bodies match their recorded bytes and lines."
|
|
12313
|
+
) : check(
|
|
12314
|
+
"pipeline.bodies",
|
|
12315
|
+
"Every file body matches the manifest accounting",
|
|
12316
|
+
"critical",
|
|
12317
|
+
"fail",
|
|
12318
|
+
bodyProblems.length + " file(s) disagree: " + sample(bodyProblems)
|
|
12319
|
+
)
|
|
12320
|
+
);
|
|
12321
|
+
const indexParent = path27__namespace.dirname(snapshotDir);
|
|
12322
|
+
const indexPath = path27__namespace.join(indexParent, "WORKSPACE.json");
|
|
12323
|
+
if (fs24__namespace.existsSync(indexPath)) {
|
|
12324
|
+
const indexText = readText2(indexPath);
|
|
12325
|
+
let members = [];
|
|
12326
|
+
let problem2 = null;
|
|
12327
|
+
try {
|
|
12328
|
+
const parsed = JSON.parse(indexText ?? "null");
|
|
12329
|
+
if (!Array.isArray(parsed?.members)) problem2 = "its members field is not an array";
|
|
12330
|
+
else members = parsed.members;
|
|
12331
|
+
} catch (error) {
|
|
12332
|
+
problem2 = error.message;
|
|
12333
|
+
}
|
|
12334
|
+
const memberName = path27__namespace.basename(snapshotDir);
|
|
12335
|
+
const member = members.find((entry) => entry.name === memberName);
|
|
12336
|
+
if (problem2 !== null) {
|
|
12337
|
+
checks.push(check(
|
|
12338
|
+
"workspace.index",
|
|
12339
|
+
"The workspace index agrees with this member",
|
|
12340
|
+
"warning",
|
|
12341
|
+
"warn",
|
|
12342
|
+
"WORKSPACE.json could not be read: " + problem2
|
|
12343
|
+
));
|
|
12344
|
+
} else if (member === void 0) {
|
|
12345
|
+
checks.push(check(
|
|
12346
|
+
"workspace.index",
|
|
12347
|
+
"The workspace index agrees with this member",
|
|
12348
|
+
"warning",
|
|
12349
|
+
"skip",
|
|
12350
|
+
"WORKSPACE.json lists no member named " + memberName + "."
|
|
12351
|
+
));
|
|
12352
|
+
} else {
|
|
12353
|
+
const disagreements = [];
|
|
12354
|
+
if (member.fingerprint !== manifest.fingerprint) disagreements.push("fingerprint");
|
|
12355
|
+
if (typeof member.files === "number" && member.files !== manifest.counts.totalFiles) {
|
|
12356
|
+
disagreements.push("file count");
|
|
12357
|
+
}
|
|
12358
|
+
checks.push(
|
|
12359
|
+
disagreements.length === 0 ? check(
|
|
12360
|
+
"workspace.index",
|
|
12361
|
+
"The workspace index agrees with this member",
|
|
12362
|
+
"warning",
|
|
12363
|
+
"pass",
|
|
12364
|
+
"Member " + memberName + " matches the index fingerprint and file count."
|
|
12365
|
+
) : check(
|
|
12366
|
+
"workspace.index",
|
|
12367
|
+
"The workspace index agrees with this member",
|
|
12368
|
+
"warning",
|
|
12369
|
+
"warn",
|
|
12370
|
+
"The index disagrees with this member on: " + disagreements.join(", ") + ". Regenerate the workspace."
|
|
12371
|
+
)
|
|
12372
|
+
);
|
|
12373
|
+
}
|
|
12374
|
+
}
|
|
12089
12375
|
const rules = [...compileSecretRules(DEFAULT_SECRET_PATTERNS), ...options.secretRules ?? []];
|
|
12090
12376
|
const scanBudget = options.maxScanBytes ?? 32 * 1024 * 1024;
|
|
12091
12377
|
const leakHits = [];
|
|
@@ -12359,90 +12645,6 @@ function generateInWorker(cwd, cliOptions, options = {}) {
|
|
|
12359
12645
|
}
|
|
12360
12646
|
|
|
12361
12647
|
// src/mcp/part.ts
|
|
12362
|
-
var FILE_HEADING = "### FILE: ";
|
|
12363
|
-
var CONTENT_MARKERS = /* @__PURE__ */ new Set(["#### Content", "#### Bounded Preview"]);
|
|
12364
|
-
var ANCHOR_LINE = /^<a id="([^"]+)"><\/a>$/;
|
|
12365
|
-
var META_PREFIX = "- Meta: ";
|
|
12366
|
-
var LEGACY_INCLUSION_PREFIX = "- Inclusion: ";
|
|
12367
|
-
var LEGACY_INCLUDED_LINES_PREFIX = "- Included Lines: ";
|
|
12368
|
-
var INCLUSION_MODES = /* @__PURE__ */ new Set(["full", "preview", "signatures"]);
|
|
12369
|
-
var COMPACT_COUNTS = /^(\d+)\s+lines?(?:\s+of\s+\d+\s+lines?)?/;
|
|
12370
|
-
function readIncludedLines(fields) {
|
|
12371
|
-
const last = fields[fields.length - 1];
|
|
12372
|
-
if (last === void 0) return null;
|
|
12373
|
-
const counts = COMPACT_COUNTS.exec(last.trim());
|
|
12374
|
-
return counts === null ? null : Number(counts[1]);
|
|
12375
|
-
}
|
|
12376
|
-
function parsePartSections(partText) {
|
|
12377
|
-
const lines = partText.split("\n");
|
|
12378
|
-
const sections = [];
|
|
12379
|
-
let index = 0;
|
|
12380
|
-
while (index < lines.length) {
|
|
12381
|
-
if (!lines[index].startsWith(FILE_HEADING)) {
|
|
12382
|
-
index += 1;
|
|
12383
|
-
continue;
|
|
12384
|
-
}
|
|
12385
|
-
const heading = lines[index].slice(FILE_HEADING.length);
|
|
12386
|
-
const anchorMatch = index > 0 ? ANCHOR_LINE.exec(lines[index - 1]) : null;
|
|
12387
|
-
let cursor = index + 1;
|
|
12388
|
-
let inclusion = null;
|
|
12389
|
-
let includedLines = null;
|
|
12390
|
-
while (cursor < lines.length && !CONTENT_MARKERS.has(lines[cursor])) {
|
|
12391
|
-
const line = lines[cursor];
|
|
12392
|
-
if (line.startsWith(FILE_HEADING)) break;
|
|
12393
|
-
if (line.startsWith(META_PREFIX)) {
|
|
12394
|
-
const fields = line.slice(META_PREFIX.length).split("|");
|
|
12395
|
-
for (const field of fields) {
|
|
12396
|
-
const value = field.trim();
|
|
12397
|
-
if (INCLUSION_MODES.has(value)) inclusion = value;
|
|
12398
|
-
}
|
|
12399
|
-
includedLines = readIncludedLines(fields);
|
|
12400
|
-
} else if (line.startsWith(LEGACY_INCLUSION_PREFIX)) {
|
|
12401
|
-
inclusion = line.slice(LEGACY_INCLUSION_PREFIX.length).trim();
|
|
12402
|
-
} else if (line.startsWith(LEGACY_INCLUDED_LINES_PREFIX)) {
|
|
12403
|
-
const value = Number(line.slice(LEGACY_INCLUDED_LINES_PREFIX.length).trim());
|
|
12404
|
-
includedLines = Number.isFinite(value) ? value : null;
|
|
12405
|
-
}
|
|
12406
|
-
cursor += 1;
|
|
12407
|
-
}
|
|
12408
|
-
if (cursor >= lines.length || !CONTENT_MARKERS.has(lines[cursor])) {
|
|
12409
|
-
index = cursor + 1;
|
|
12410
|
-
continue;
|
|
12411
|
-
}
|
|
12412
|
-
let fenceLine = cursor + 1;
|
|
12413
|
-
while (fenceLine < lines.length && lines[fenceLine].trim().length === 0) fenceLine += 1;
|
|
12414
|
-
const fenceMatch = /^(`{4,})/.exec(lines[fenceLine] ?? "");
|
|
12415
|
-
if (!fenceMatch) {
|
|
12416
|
-
index = cursor + 1;
|
|
12417
|
-
continue;
|
|
12418
|
-
}
|
|
12419
|
-
const fence = fenceMatch[1];
|
|
12420
|
-
const body = [];
|
|
12421
|
-
let bodyLine = fenceLine + 1;
|
|
12422
|
-
while (bodyLine < lines.length && lines[bodyLine] !== fence) {
|
|
12423
|
-
body.push(lines[bodyLine]);
|
|
12424
|
-
bodyLine += 1;
|
|
12425
|
-
}
|
|
12426
|
-
sections.push({ path: heading, anchor: anchorMatch?.[1] ?? null, body: body.join("\n"), inclusion, includedLines });
|
|
12427
|
-
index = bodyLine + 1;
|
|
12428
|
-
}
|
|
12429
|
-
return sections;
|
|
12430
|
-
}
|
|
12431
|
-
function findSection(sections, relativePath) {
|
|
12432
|
-
const anchor = anchorForPath(relativePath);
|
|
12433
|
-
const byAnchor = sections.find((section) => section.anchor === anchor);
|
|
12434
|
-
if (byAnchor) return byAnchor;
|
|
12435
|
-
const rendered = displayPath(relativePath);
|
|
12436
|
-
const samePath = (section) => section.path === relativePath || section.path === rendered;
|
|
12437
|
-
const exact = sections.find(samePath);
|
|
12438
|
-
if (exact) return exact;
|
|
12439
|
-
const foldedPath = rendered.toLowerCase();
|
|
12440
|
-
const folded = sections.filter((section) => {
|
|
12441
|
-
const path28 = section.path.toLowerCase();
|
|
12442
|
-
return path28 === relativePath.toLowerCase() || path28 === foldedPath;
|
|
12443
|
-
});
|
|
12444
|
-
return folded.length === 1 ? folded[0] : null;
|
|
12445
|
-
}
|
|
12446
12648
|
function windowText(body, fromLine, lineCount) {
|
|
12447
12649
|
const lines = body.split("\n");
|
|
12448
12650
|
const total = body.length === 0 ? 0 : lines.length;
|
|
@@ -20243,12 +20445,23 @@ async function startHttpTransport(options) {
|
|
|
20243
20445
|
return fromQuery !== null && timingSafeEqual3(fromQuery, token);
|
|
20244
20446
|
};
|
|
20245
20447
|
const sessions = /* @__PURE__ */ new Map();
|
|
20448
|
+
const metrics = {
|
|
20449
|
+
requests: 0,
|
|
20450
|
+
byMethod: /* @__PURE__ */ new Map(),
|
|
20451
|
+
refused: 0,
|
|
20452
|
+
rateLimited: 0};
|
|
20453
|
+
const noteRequest = (request) => {
|
|
20454
|
+
metrics.requests += 1;
|
|
20455
|
+
const method = request.method ?? "UNKNOWN";
|
|
20456
|
+
metrics.byMethod.set(method, (metrics.byMethod.get(method) ?? 0) + 1);
|
|
20457
|
+
};
|
|
20246
20458
|
const allowedOrigin = (origin) => {
|
|
20247
20459
|
if (origin === void 0) return null;
|
|
20248
20460
|
if (isLoopbackOrigin(origin)) return origin;
|
|
20249
20461
|
return extraOrigins.includes(origin) ? origin : null;
|
|
20250
20462
|
};
|
|
20251
20463
|
const httpServer = http__namespace.createServer((request, response) => {
|
|
20464
|
+
noteRequest(request);
|
|
20252
20465
|
const send = (status, body, extra = {}) => {
|
|
20253
20466
|
const text2 = typeof body === "string" ? body : JSON.stringify(body);
|
|
20254
20467
|
response.writeHead(status, {
|
|
@@ -20262,6 +20475,7 @@ async function startHttpTransport(options) {
|
|
|
20262
20475
|
const origin = typeof request.headers.origin === "string" ? request.headers.origin : void 0;
|
|
20263
20476
|
const allowed = allowedOrigin(origin);
|
|
20264
20477
|
if (origin !== void 0 && allowed === null) {
|
|
20478
|
+
metrics.refused += 1;
|
|
20265
20479
|
send(403, { error: "origin not allowed" });
|
|
20266
20480
|
return;
|
|
20267
20481
|
}
|
|
@@ -20291,6 +20505,33 @@ async function startHttpTransport(options) {
|
|
|
20291
20505
|
);
|
|
20292
20506
|
return;
|
|
20293
20507
|
}
|
|
20508
|
+
if (request.method === "GET" && request.url === "/metrics") {
|
|
20509
|
+
const lines = [
|
|
20510
|
+
"# HELP snapshot_uptime_seconds Seconds since the process started.",
|
|
20511
|
+
"# TYPE snapshot_uptime_seconds gauge",
|
|
20512
|
+
"snapshot_uptime_seconds " + Math.round(process.uptime()),
|
|
20513
|
+
"# HELP snapshot_requests_total HTTP requests received.",
|
|
20514
|
+
"# TYPE snapshot_requests_total counter",
|
|
20515
|
+
"snapshot_requests_total " + metrics.requests,
|
|
20516
|
+
"# HELP snapshot_requests_refused_total Requests refused before dispatch.",
|
|
20517
|
+
"# TYPE snapshot_requests_refused_total counter",
|
|
20518
|
+
"snapshot_requests_refused_total " + metrics.refused,
|
|
20519
|
+
"# HELP snapshot_requests_rate_limited_total Requests rejected by the rate limit.",
|
|
20520
|
+
"# TYPE snapshot_requests_rate_limited_total counter",
|
|
20521
|
+
"snapshot_requests_rate_limited_total " + metrics.rateLimited,
|
|
20522
|
+
"# HELP snapshot_tools Number of tools this server serves.",
|
|
20523
|
+
"# TYPE snapshot_tools gauge",
|
|
20524
|
+
"snapshot_tools " + toolCount
|
|
20525
|
+
];
|
|
20526
|
+
for (const [method, count] of metrics.byMethod) {
|
|
20527
|
+
lines.push('snapshot_requests_by_method_total{method="' + method + '"} ' + count);
|
|
20528
|
+
}
|
|
20529
|
+
send(200, lines.join("\n") + "\n", {
|
|
20530
|
+
...cors,
|
|
20531
|
+
"content-type": "text/plain; version=0.0.4; charset=utf-8"
|
|
20532
|
+
});
|
|
20533
|
+
return;
|
|
20534
|
+
}
|
|
20294
20535
|
const url = new URL(request.url ?? "/", "http://localhost");
|
|
20295
20536
|
if (request.method === "GET" && url.pathname === "/sse") {
|
|
20296
20537
|
if (!tokenAccepted(request, url)) {
|
|
@@ -20382,6 +20623,7 @@ async function startHttpTransport(options) {
|
|
|
20382
20623
|
const window = sessions.get(remote);
|
|
20383
20624
|
if (window === void 0 || window.resetAt <= now) sessions.set(remote, { count: 1, resetAt: now + RATE_WINDOW_MS });
|
|
20384
20625
|
else if (window.count >= RATE_LIMIT) {
|
|
20626
|
+
metrics.rateLimited += 1;
|
|
20385
20627
|
send(429, { error: "too many requests" }, { ...cors, "retry-after": "10" });
|
|
20386
20628
|
return;
|
|
20387
20629
|
} else window.count += 1;
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { startHttpTransport } from './chunk-
|
|
2
|
-
import { shouldCheck, checkForUpdate, GENERATOR_VERSION, cacheFilePath, formatUpdateNotice, installKind, buildAgentContract, startWebServer, runStdioServer, parseRemoteSource, assertPublicHost, cloneRepository, makeCloneDirectory, loadConfigFileDetailed, resolveConfig, validateSnapshot, auditSnapshot, describeManifestShapeProblem, explainPath, compareManifests, loadManifest, renderDiffText, generateSnapshot, signManifest, loadSigningKey, writeSignature, formatNumber, isDiscoveryMode, ARTIFACT_NAMES, COMMAND_OPTION_SCOPE, commandsForOption, getPreset, unknownPresetMessage, GENERATOR_NAME, runInit, installPreCommitHook, PromptCancelled, SKILL_NAME, renderSkill, findConfigFile, planFirstRun, isEffectivelyEmpty, isInteractive, defaultIO, hasPriorSnapshot, DEFAULT_ANSWERS, firstRunMessage, stripJsonComments, parseByteSize, gitignorePath, appendGitignoreEntries, escapeControls, runWithStdoutCapture, MIN_MAX_PART_TOKENS, MIN_MAX_PART_BYTES, renderContractText, renderExplainText } from './chunk-
|
|
3
|
-
export { buildAgentContract } from './chunk-
|
|
1
|
+
import { startHttpTransport } from './chunk-7WSZUMT6.js';
|
|
2
|
+
import { shouldCheck, checkForUpdate, GENERATOR_VERSION, cacheFilePath, formatUpdateNotice, installKind, buildAgentContract, startWebServer, runStdioServer, parseRemoteSource, assertPublicHost, cloneRepository, makeCloneDirectory, loadConfigFileDetailed, resolveConfig, validateSnapshot, auditSnapshot, describeManifestShapeProblem, explainPath, compareManifests, loadManifest, renderDiffText, generateSnapshot, signManifest, loadSigningKey, writeSignature, formatNumber, isDiscoveryMode, ARTIFACT_NAMES, COMMAND_OPTION_SCOPE, commandsForOption, getPreset, unknownPresetMessage, GENERATOR_NAME, runInit, installPreCommitHook, PromptCancelled, SKILL_NAME, renderSkill, findConfigFile, planFirstRun, isEffectivelyEmpty, isInteractive, defaultIO, hasPriorSnapshot, DEFAULT_ANSWERS, firstRunMessage, stripJsonComments, parseByteSize, gitignorePath, appendGitignoreEntries, escapeControls, runWithStdoutCapture, MIN_MAX_PART_TOKENS, MIN_MAX_PART_BYTES, renderContractText, renderExplainText } from './chunk-2YNQ42B3.js';
|
|
3
|
+
export { buildAgentContract } from './chunk-2YNQ42B3.js';
|
|
4
4
|
import { spawnSync } from 'child_process';
|
|
5
5
|
import * as fs2 from 'fs';
|
|
6
6
|
import * as path2 from 'path';
|