codebase-snapshot 0.14.0 → 0.16.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 +184 -0
- package/README.md +3 -3
- package/SECURITY.md +2 -2
- package/dist/bin.js +341 -10
- package/dist/{chunk-2YNQ42B3.js → chunk-AEGJYOCF.js} +326 -10
- package/dist/{chunk-7WSZUMT6.js → chunk-ZDTAWUD4.js} +1 -1
- package/dist/cli.cjs +341 -10
- package/dist/cli.d.cts +11 -1
- package/dist/cli.d.ts +11 -1
- package/dist/cli.js +18 -3
- package/dist/index.cjs +326 -10
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +248 -9
- package/dist/mcp.d.cts +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +2 -2
- package/dist/{types-CbD8yQRZ.d.cts → types-Cr5H2Y3t.d.cts} +13 -0
- package/dist/{types-CbD8yQRZ.d.ts → types-Cr5H2Y3t.d.ts} +13 -0
- package/docs/benchmarks.md +54 -9
- package/docs/cli.md +7 -5
- package/docs/deploy.md +2 -2
- package/docs/mcp.md +7 -5
- package/docs/slice.md +8 -0
- package/docs/tools.md +16 -2
- package/docs/vs-repomix.md +1 -1
- package/package.json +1 -1
package/dist/mcp.cjs
CHANGED
|
@@ -2548,7 +2548,7 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
2548
2548
|
|
|
2549
2549
|
// src/version.ts
|
|
2550
2550
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
2551
|
-
var GENERATOR_VERSION = "0.
|
|
2551
|
+
var GENERATOR_VERSION = "0.16.0";
|
|
2552
2552
|
var SCHEMA_VERSION = "3.0.0";
|
|
2553
2553
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2554
2554
|
function isOurGeneratorName(name) {
|
|
@@ -4372,7 +4372,12 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
4372
4372
|
logCount: resolveLogCount(
|
|
4373
4373
|
cliOptions?.logCount ?? cliOptions?.includeLogs ?? userConfig?.logCount
|
|
4374
4374
|
),
|
|
4375
|
-
|
|
4375
|
+
// `--only` replaces the allow-list for this run; `--ignore` adds to the deny-list. The two
|
|
4376
|
+
// directions are different on purpose: a narrower allow-list is a statement about the whole
|
|
4377
|
+
// run, while "also ignore this" is naturally cumulative with what the config already excludes.
|
|
4378
|
+
include: resolveInclude(
|
|
4379
|
+
cliOptions?.only ?? userConfig?.include
|
|
4380
|
+
),
|
|
4376
4381
|
preset: preset.presetName,
|
|
4377
4382
|
presetExclude,
|
|
4378
4383
|
artifacts,
|
|
@@ -4383,9 +4388,12 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
4383
4388
|
kinds,
|
|
4384
4389
|
// `exclude` is the flag spelling of the same setting; writing it in a config used to
|
|
4385
4390
|
// be ignored without a word.
|
|
4386
|
-
excludePatterns:
|
|
4387
|
-
|
|
4388
|
-
|
|
4391
|
+
excludePatterns: [
|
|
4392
|
+
...resolveExcludePatterns(
|
|
4393
|
+
userConfig?.excludePatterns ?? userConfig?.exclude
|
|
4394
|
+
),
|
|
4395
|
+
...resolveExcludePatterns(cliOptions?.ignore)
|
|
4396
|
+
],
|
|
4389
4397
|
secretRules,
|
|
4390
4398
|
// Extra property rather than a `ResolvedSnapshotConfig` field: the resolved
|
|
4391
4399
|
// shape is owned elsewhere, and every scan reads it through the registry in
|
|
@@ -7617,6 +7625,7 @@ function validateSnapshot(configInput) {
|
|
|
7617
7625
|
["reports/diff.md", manifest.artifacts?.diff],
|
|
7618
7626
|
["reports/log.md", manifest.artifacts?.log],
|
|
7619
7627
|
["reports/tokens.md", manifest.artifacts?.tokenTree],
|
|
7628
|
+
["reports/selection.md", manifest.artifacts?.selection],
|
|
7620
7629
|
["full-codebase.json", manifest.artifacts?.fullJson],
|
|
7621
7630
|
["full-codebase.md", manifest.artifacts?.fullMarkdown],
|
|
7622
7631
|
["full-codebase.xml", manifest.artifacts?.fullXml]
|
|
@@ -8125,6 +8134,7 @@ var ARTIFACT_FILES = {
|
|
|
8125
8134
|
diff: "reports/diff.md",
|
|
8126
8135
|
log: "reports/log.md",
|
|
8127
8136
|
tokenTree: "reports/tokens.md",
|
|
8137
|
+
selection: "reports/selection.md",
|
|
8128
8138
|
fullJson: "full-codebase.json",
|
|
8129
8139
|
fullMarkdown: "full-codebase.md",
|
|
8130
8140
|
fullXml: "full-codebase.xml",
|
|
@@ -9566,6 +9576,65 @@ var historyTool = {
|
|
|
9566
9576
|
};
|
|
9567
9577
|
}
|
|
9568
9578
|
};
|
|
9579
|
+
var budgetTool = {
|
|
9580
|
+
name: "snapshot_budget",
|
|
9581
|
+
title: "What a larger budget would buy",
|
|
9582
|
+
description: 'Run the planner at several token budgets and report what each one adds: files, tokens used, entry points kept and the files gained over the previous budget. Answers "should I raise the budget, and what would I get?" without writing a snapshot. Read-only.',
|
|
9583
|
+
inputSchema: {
|
|
9584
|
+
type: "object",
|
|
9585
|
+
properties: {
|
|
9586
|
+
budgets: {
|
|
9587
|
+
type: "array",
|
|
9588
|
+
items: { type: "integer", minimum: 500 },
|
|
9589
|
+
description: "Token budgets to compare, ascending (default 10000, 30000, 60000)."
|
|
9590
|
+
},
|
|
9591
|
+
question: { type: "string", description: "Optional question to plan for; absent plans for the repository as a whole." },
|
|
9592
|
+
includeTests: { type: "boolean", description: "Include test files (default false)." },
|
|
9593
|
+
root: ROOT_PROPERTY,
|
|
9594
|
+
outDir: OUT_DIR_PROPERTY
|
|
9595
|
+
},
|
|
9596
|
+
additionalProperties: false
|
|
9597
|
+
},
|
|
9598
|
+
outputSchema: {
|
|
9599
|
+
type: "object",
|
|
9600
|
+
properties: { budgets: { type: "array", items: { type: "object" } } }
|
|
9601
|
+
},
|
|
9602
|
+
annotations: READ_ONLY,
|
|
9603
|
+
async handler(args, context) {
|
|
9604
|
+
const prepared = await prepare(args, context, outDirOverride(args));
|
|
9605
|
+
if (!prepared.ok) return prepared.outcome;
|
|
9606
|
+
const read = readManifest3(prepared.workspace);
|
|
9607
|
+
if (!read.ok) return { text: read.message + " Call snapshot_generate first.", isError: true };
|
|
9608
|
+
const requested = Array.isArray(args.budgets) ? args.budgets.filter((value) => typeof value === "number").map((value) => Math.max(500, value)) : [1e4, 3e4, 6e4];
|
|
9609
|
+
const budgets = [...new Set(requested)].sort((left, right) => left - right);
|
|
9610
|
+
if (budgets.length === 0) return { text: "budgets must hold at least one number", isError: true };
|
|
9611
|
+
const question = typeof args.question === "string" ? args.question : "";
|
|
9612
|
+
const rows = [];
|
|
9613
|
+
let previous = /* @__PURE__ */ new Set();
|
|
9614
|
+
for (const budget of budgets) {
|
|
9615
|
+
const plan = planForQuestion(read.manifest, question, {
|
|
9616
|
+
maxTokens: budget,
|
|
9617
|
+
...args.includeTests === true ? { includeTests: true } : {}
|
|
9618
|
+
});
|
|
9619
|
+
const paths = new Set(plan.files.map((file) => file.path));
|
|
9620
|
+
const gained = [...paths].filter((path16) => !previous.has(path16)).sort();
|
|
9621
|
+
previous = paths;
|
|
9622
|
+
rows.push({
|
|
9623
|
+
budget,
|
|
9624
|
+
files: plan.files.length,
|
|
9625
|
+
usedTokens: plan.usedTokens,
|
|
9626
|
+
gained
|
|
9627
|
+
});
|
|
9628
|
+
}
|
|
9629
|
+
const lines = [question === "" ? "No question: planning for the repository as a whole." : "Question: " + question];
|
|
9630
|
+
for (const row of rows) {
|
|
9631
|
+
lines.push(
|
|
9632
|
+
row.budget.toLocaleString("en-US") + " tokens: " + row.files + " file(s), " + row.usedTokens.toLocaleString("en-US") + " used" + (row.gained.length === 0 ? "" : ", " + row.gained.length + " gained (" + row.gained.slice(0, 4).join(", ") + (row.gained.length > 4 ? ", \u2026" : "") + ")")
|
|
9633
|
+
);
|
|
9634
|
+
}
|
|
9635
|
+
return { text: lines.join("\n"), structured: { budgets: rows } };
|
|
9636
|
+
}
|
|
9637
|
+
};
|
|
9569
9638
|
var testsTool = {
|
|
9570
9639
|
name: "snapshot_tests",
|
|
9571
9640
|
title: "Tests that cover a file, and files a test covers",
|
|
@@ -10252,6 +10321,11 @@ var symbolTool = {
|
|
|
10252
10321
|
name: { type: "string", description: "Symbol name, case-insensitive." },
|
|
10253
10322
|
lines: { type: "integer", description: "Window size around the definition (default 40).", minimum: 5 },
|
|
10254
10323
|
maxFiles: { type: "integer", description: "Cap on files searched (default 5).", minimum: 1 },
|
|
10324
|
+
references: {
|
|
10325
|
+
type: "boolean",
|
|
10326
|
+
description: "Also report call sites: other files whose body mentions the name (default true)."
|
|
10327
|
+
},
|
|
10328
|
+
maxReferences: { type: "integer", description: "Cap on reported call sites (default 20).", minimum: 1 },
|
|
10255
10329
|
root: ROOT_PROPERTY,
|
|
10256
10330
|
outDir: OUT_DIR_PROPERTY
|
|
10257
10331
|
},
|
|
@@ -10262,7 +10336,8 @@ var symbolTool = {
|
|
|
10262
10336
|
type: "object",
|
|
10263
10337
|
properties: {
|
|
10264
10338
|
found: { type: "integer" },
|
|
10265
|
-
matches: { type: "array", items: { type: "object" } }
|
|
10339
|
+
matches: { type: "array", items: { type: "object" } },
|
|
10340
|
+
references: { type: "array", items: { type: "object" } }
|
|
10266
10341
|
}
|
|
10267
10342
|
},
|
|
10268
10343
|
annotations: READ_ONLY,
|
|
@@ -10315,8 +10390,44 @@ var symbolTool = {
|
|
|
10315
10390
|
structured: { found: 0, matches: [] }
|
|
10316
10391
|
};
|
|
10317
10392
|
}
|
|
10318
|
-
const
|
|
10319
|
-
|
|
10393
|
+
const callSites = [];
|
|
10394
|
+
if (args.references !== false) {
|
|
10395
|
+
const limit = Math.max(1, typeof args.maxReferences === "number" ? args.maxReferences : 20);
|
|
10396
|
+
const definitionKeys = new Set(matches.map((match) => match.path + ":" + match.line));
|
|
10397
|
+
const word = new RegExp("\\b" + name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "\\b");
|
|
10398
|
+
const parts = /* @__PURE__ */ new Map();
|
|
10399
|
+
let scanned = 0;
|
|
10400
|
+
for (const file of read.manifest.files) {
|
|
10401
|
+
if (callSites.length >= limit) break;
|
|
10402
|
+
const partPath = partPathFor(workspace, file.part);
|
|
10403
|
+
if (partPath === null) continue;
|
|
10404
|
+
let partText = parts.get(partPath);
|
|
10405
|
+
if (partText === void 0) {
|
|
10406
|
+
try {
|
|
10407
|
+
partText = fs2__namespace.readFileSync(partPath, "utf8");
|
|
10408
|
+
} catch {
|
|
10409
|
+
continue;
|
|
10410
|
+
}
|
|
10411
|
+
parts.set(partPath, partText);
|
|
10412
|
+
}
|
|
10413
|
+
if (scanned > MAX_SEARCH_BYTES) break;
|
|
10414
|
+
scanned += Buffer.byteLength(partText, "utf8");
|
|
10415
|
+
const section = findSection(parsePartSections(partText), file.relativePath);
|
|
10416
|
+
if (section === null) continue;
|
|
10417
|
+
const bodyLines = section.body.split("\n");
|
|
10418
|
+
for (let index = 0; index < bodyLines.length && callSites.length < limit; index += 1) {
|
|
10419
|
+
if (!word.test(bodyLines[index])) continue;
|
|
10420
|
+
callSites.push({
|
|
10421
|
+
path: file.relativePath,
|
|
10422
|
+
line: index + 1,
|
|
10423
|
+
text: bodyLines[index].trim().slice(0, 200),
|
|
10424
|
+
definition: definitionKeys.has(file.relativePath + ":" + (index + 1))
|
|
10425
|
+
});
|
|
10426
|
+
}
|
|
10427
|
+
}
|
|
10428
|
+
}
|
|
10429
|
+
const text = matches.map((match) => "### " + match.path + " (" + match.part + ", line " + match.line + ")\n" + match.text).join("\n\n") + (args.references === false ? "" : "\n\n" + (callSites.length === 0 ? "No call site was found in the snapshot." : "Call sites (" + callSites.length + "):\n" + callSites.map((site) => " " + site.path + ":" + site.line + " " + site.text).join("\n")));
|
|
10430
|
+
return { text, structured: { found: matches.length, matches, references: callSites } };
|
|
10320
10431
|
}
|
|
10321
10432
|
};
|
|
10322
10433
|
var contextTool = {
|
|
@@ -10550,6 +10661,110 @@ var planForTool = {
|
|
|
10550
10661
|
return { text: lines.join("\n"), structured: plan };
|
|
10551
10662
|
}
|
|
10552
10663
|
};
|
|
10664
|
+
var answerTool = {
|
|
10665
|
+
name: "snapshot_answer",
|
|
10666
|
+
title: "Question in, budgeted context out",
|
|
10667
|
+
description: "The one-call version of plan-then-read: plan a question, then return each chosen file as a head window with line numbers within the token budget. Every included file says why it is there; every planned file that did not fit says so. Read-only.",
|
|
10668
|
+
inputSchema: {
|
|
10669
|
+
type: "object",
|
|
10670
|
+
properties: {
|
|
10671
|
+
question: { type: "string", description: "What you need to answer." },
|
|
10672
|
+
maxTokens: { type: "integer", description: "Budget for the whole block (default 20000).", minimum: 500 },
|
|
10673
|
+
linesPerFile: { type: "integer", description: "Head lines per file (default 60).", minimum: 10 },
|
|
10674
|
+
includeTests: { type: "boolean", description: "Include test files (default false)." },
|
|
10675
|
+
root: ROOT_PROPERTY,
|
|
10676
|
+
outDir: OUT_DIR_PROPERTY
|
|
10677
|
+
},
|
|
10678
|
+
required: ["question"],
|
|
10679
|
+
additionalProperties: false
|
|
10680
|
+
},
|
|
10681
|
+
outputSchema: {
|
|
10682
|
+
type: "object",
|
|
10683
|
+
properties: {
|
|
10684
|
+
question: { type: "string" },
|
|
10685
|
+
budgetTokens: { type: "integer" },
|
|
10686
|
+
usedTokens: { type: "integer" },
|
|
10687
|
+
files: { type: "array", items: { type: "object" } },
|
|
10688
|
+
omitted: { type: "array", items: { type: "object" } }
|
|
10689
|
+
}
|
|
10690
|
+
},
|
|
10691
|
+
annotations: READ_ONLY,
|
|
10692
|
+
async handler(args, context) {
|
|
10693
|
+
const question = typeof args.question === "string" ? args.question.trim() : "";
|
|
10694
|
+
if (question.length === 0) return { text: "question must be a non-empty string", isError: true };
|
|
10695
|
+
const prepared = await prepare(args, context, outDirOverride(args));
|
|
10696
|
+
if (!prepared.ok) return prepared.outcome;
|
|
10697
|
+
const read = readManifest3(prepared.workspace);
|
|
10698
|
+
if (!read.ok) return { text: read.message + " Call snapshot_generate first.", isError: true };
|
|
10699
|
+
const maxTokens = Math.max(500, typeof args.maxTokens === "number" ? args.maxTokens : 2e4);
|
|
10700
|
+
const linesPerFile = Math.max(10, typeof args.linesPerFile === "number" ? args.linesPerFile : 60);
|
|
10701
|
+
const plan = planForQuestion(read.manifest, question, {
|
|
10702
|
+
maxTokens,
|
|
10703
|
+
...args.includeTests === true ? { includeTests: true } : {}
|
|
10704
|
+
});
|
|
10705
|
+
const blocks = [];
|
|
10706
|
+
const omitted = [];
|
|
10707
|
+
let used = 0;
|
|
10708
|
+
const parts = /* @__PURE__ */ new Map();
|
|
10709
|
+
for (const planned of plan.files) {
|
|
10710
|
+
if (used >= maxTokens) {
|
|
10711
|
+
omitted.push({ path: planned.path, reason: "the budget was spent on earlier files" });
|
|
10712
|
+
continue;
|
|
10713
|
+
}
|
|
10714
|
+
const partPath = partPathFor(prepared.workspace, planned.part);
|
|
10715
|
+
if (partPath === null) {
|
|
10716
|
+
omitted.push({ path: planned.path, reason: "its part is not in the snapshot" });
|
|
10717
|
+
continue;
|
|
10718
|
+
}
|
|
10719
|
+
let partText = parts.get(partPath);
|
|
10720
|
+
if (partText === void 0) {
|
|
10721
|
+
try {
|
|
10722
|
+
partText = fs2__namespace.readFileSync(partPath, "utf8");
|
|
10723
|
+
} catch {
|
|
10724
|
+
omitted.push({ path: planned.path, reason: "its part could not be read" });
|
|
10725
|
+
continue;
|
|
10726
|
+
}
|
|
10727
|
+
parts.set(partPath, partText);
|
|
10728
|
+
}
|
|
10729
|
+
const section = findSection(parsePartSections(partText), planned.path);
|
|
10730
|
+
if (section === null) {
|
|
10731
|
+
omitted.push({ path: planned.path, reason: "no section in its part" });
|
|
10732
|
+
continue;
|
|
10733
|
+
}
|
|
10734
|
+
const window = windowText(section.body, 1, linesPerFile);
|
|
10735
|
+
const text = window.text;
|
|
10736
|
+
const tokens = estimateTokens(text);
|
|
10737
|
+
if (used + tokens > maxTokens && blocks.length > 0) {
|
|
10738
|
+
omitted.push({ path: planned.path, reason: "did not fit the remaining budget" });
|
|
10739
|
+
continue;
|
|
10740
|
+
}
|
|
10741
|
+
const numbered = text.split("\n").map((line, index) => String(index + 1).padStart(5, " ") + " " + line).join("\n");
|
|
10742
|
+
blocks.push({ path: planned.path, why: planned.why, tokens, text: numbered, truncated: window.truncated, totalLines: window.totalLines });
|
|
10743
|
+
used += tokens;
|
|
10744
|
+
}
|
|
10745
|
+
const lines = [
|
|
10746
|
+
"# Answer context: " + question,
|
|
10747
|
+
"Budget: " + used + " of " + maxTokens + " tokens; " + blocks.length + " file(s)."
|
|
10748
|
+
];
|
|
10749
|
+
for (const block of blocks) {
|
|
10750
|
+
lines.push("");
|
|
10751
|
+
lines.push("## " + block.path + " (" + block.tokens + " tokens, " + (block.truncated ? "first lines of " + block.totalLines : "whole file") + ")");
|
|
10752
|
+
lines.push("Why: " + block.why);
|
|
10753
|
+
lines.push("```");
|
|
10754
|
+
lines.push(block.text);
|
|
10755
|
+
lines.push("```");
|
|
10756
|
+
}
|
|
10757
|
+
if (omitted.length > 0) {
|
|
10758
|
+
lines.push("");
|
|
10759
|
+
lines.push("Not included:");
|
|
10760
|
+
for (const entry of omitted) lines.push("- " + entry.path + " - " + entry.reason);
|
|
10761
|
+
}
|
|
10762
|
+
return {
|
|
10763
|
+
text: lines.join("\n"),
|
|
10764
|
+
structured: { question, budgetTokens: maxTokens, usedTokens: used, files: blocks, omitted }
|
|
10765
|
+
};
|
|
10766
|
+
}
|
|
10767
|
+
};
|
|
10553
10768
|
var healthTool = {
|
|
10554
10769
|
name: "snapshot_health",
|
|
10555
10770
|
title: "Snapshot health audit",
|
|
@@ -11400,6 +11615,7 @@ var explainTool = {
|
|
|
11400
11615
|
var TOOL_COSTS = {
|
|
11401
11616
|
snapshot_status: "cheap",
|
|
11402
11617
|
snapshot_health: "expensive",
|
|
11618
|
+
snapshot_budget: "medium",
|
|
11403
11619
|
snapshot_history: "cheap",
|
|
11404
11620
|
snapshot_tests: "cheap",
|
|
11405
11621
|
snapshot_workspace: "cheap",
|
|
@@ -11415,6 +11631,7 @@ var TOOL_COSTS = {
|
|
|
11415
11631
|
snapshot_context: "medium",
|
|
11416
11632
|
snapshot_query: "cheap",
|
|
11417
11633
|
snapshot_plan_for: "cheap",
|
|
11634
|
+
snapshot_answer: "medium",
|
|
11418
11635
|
snapshot_plan: "expensive",
|
|
11419
11636
|
snapshot_generate: "expensive",
|
|
11420
11637
|
snapshot_validate: "medium",
|
|
@@ -11427,6 +11644,7 @@ function buildTools() {
|
|
|
11427
11644
|
return [
|
|
11428
11645
|
statusTool,
|
|
11429
11646
|
healthTool,
|
|
11647
|
+
budgetTool,
|
|
11430
11648
|
historyTool,
|
|
11431
11649
|
testsTool,
|
|
11432
11650
|
workspaceTool,
|
|
@@ -11442,6 +11660,7 @@ function buildTools() {
|
|
|
11442
11660
|
contextTool,
|
|
11443
11661
|
queryTool,
|
|
11444
11662
|
planForTool,
|
|
11663
|
+
answerTool,
|
|
11445
11664
|
planTool,
|
|
11446
11665
|
generateTool,
|
|
11447
11666
|
validateTool,
|
|
@@ -11589,6 +11808,8 @@ var VALIDATE_OPTIONS = [
|
|
|
11589
11808
|
"sarif",
|
|
11590
11809
|
"strip-comments",
|
|
11591
11810
|
"remove-empty-lines",
|
|
11811
|
+
"only",
|
|
11812
|
+
"ignore",
|
|
11592
11813
|
"pack",
|
|
11593
11814
|
// The opt-in reports change the artifact selection the manifest records, so validate must accept
|
|
11594
11815
|
// them to compare like with like: without the flags it reports the selection as drift.
|
|
@@ -11624,6 +11845,8 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
11624
11845
|
generate: [
|
|
11625
11846
|
"strip-comments",
|
|
11626
11847
|
"remove-empty-lines",
|
|
11848
|
+
"only",
|
|
11849
|
+
"ignore",
|
|
11627
11850
|
"workspace",
|
|
11628
11851
|
"budget-tokens",
|
|
11629
11852
|
"sign",
|
|
@@ -11704,6 +11927,10 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
11704
11927
|
// Removed rather than implemented, because a flag that parses and does nothing is the defect
|
|
11705
11928
|
// this table exists to prevent.
|
|
11706
11929
|
"large-file-bytes",
|
|
11930
|
+
// `--only` and `--ignore` change which files are scanned, so they change what `explain` can say
|
|
11931
|
+
// about a path; without them the answer for an ignored file is "included: true".
|
|
11932
|
+
"only",
|
|
11933
|
+
"ignore",
|
|
11707
11934
|
"include-sensitive-files",
|
|
11708
11935
|
"no-config",
|
|
11709
11936
|
"discovery",
|
|
@@ -12176,6 +12403,18 @@ function buildAgentContract() {
|
|
|
12176
12403
|
appliesTo: optionAppliesTo("allow-origin"),
|
|
12177
12404
|
summary: "mcp --http: comma-separated extra CORS origins. Loopback origins are always allowed."
|
|
12178
12405
|
},
|
|
12406
|
+
{
|
|
12407
|
+
flag: "--only",
|
|
12408
|
+
type: "string",
|
|
12409
|
+
summary: "Comma-separated globs to include: overrides the config include list for this run.",
|
|
12410
|
+
appliesTo: optionAppliesTo("only")
|
|
12411
|
+
},
|
|
12412
|
+
{
|
|
12413
|
+
flag: "--ignore",
|
|
12414
|
+
type: "string",
|
|
12415
|
+
summary: "Comma-separated globs to exclude, added to the config exclude list for this run.",
|
|
12416
|
+
appliesTo: optionAppliesTo("ignore")
|
|
12417
|
+
},
|
|
12179
12418
|
{
|
|
12180
12419
|
flag: "--remove-empty-lines",
|
|
12181
12420
|
type: "boolean",
|
|
@@ -12714,7 +12953,7 @@ diff, and the commit, are then yours.
|
|
|
12714
12953
|
## When the client speaks MCP
|
|
12715
12954
|
|
|
12716
12955
|
If the agent runs inside an MCP client, \`npx ${PACKAGE_NAME2}@latest mcp\` serves this repository
|
|
12717
|
-
as
|
|
12956
|
+
as 26 tools over stdio instead of shelling out. Its reads come from the snapshot rather than
|
|
12718
12957
|
the working tree, so excluded files and redacted values never reach the context. Use
|
|
12719
12958
|
\`snapshot_locate\` before \`snapshot_read\`, and \`snapshot_validate\` before trusting a snapshot
|
|
12720
12959
|
from an earlier session.
|
package/dist/mcp.d.cts
CHANGED
|
@@ -166,7 +166,7 @@ interface ToolContext {
|
|
|
166
166
|
* Client-facing hints.
|
|
167
167
|
*
|
|
168
168
|
* `readOnlyHint` is the one that changes behaviour rather than appearance: clients use it to
|
|
169
|
-
* auto-approve a call. Seven of the
|
|
169
|
+
* auto-approve a call. Seven of the 26 tools never touch the filesystem, so they are marked
|
|
170
170
|
* read-only and only `snapshot_generate` prompts.
|
|
171
171
|
*/
|
|
172
172
|
interface ToolAnnotations {
|
package/dist/mcp.d.ts
CHANGED
|
@@ -166,7 +166,7 @@ interface ToolContext {
|
|
|
166
166
|
* Client-facing hints.
|
|
167
167
|
*
|
|
168
168
|
* `readOnlyHint` is the one that changes behaviour rather than appearance: clients use it to
|
|
169
|
-
* auto-approve a call. Seven of the
|
|
169
|
+
* auto-approve a call. Seven of the 26 tools never touch the filesystem, so they are marked
|
|
170
170
|
* read-only and only `snapshot_generate` prompts.
|
|
171
171
|
*/
|
|
172
172
|
interface ToolAnnotations {
|
package/dist/mcp.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { generateToken, startHttpTransport } from './chunk-
|
|
2
|
-
export { ERROR_CODES, LEGACY_PROTOCOL_VERSIONS, MAX_LINE_BYTES, METHOD, MODERN_PROTOCOL_VERSIONS, SERVER_INSTRUCTIONS, SUPPORTED_PROTOCOL_VERSIONS, buildPrompts, buildResourceProvider, buildTools, classifyRequest, coerceNumericStrings, createLineReader, createMcpServer, createServer, createSession, createWriter, findSection, generateInWorker, inspectModernMeta, isCommentStrippable, negotiateLegacyVersion, parsePartSections, runStdioServer, stripComments, validateArguments, windowText } from './chunk-
|
|
1
|
+
export { generateToken, startHttpTransport } from './chunk-ZDTAWUD4.js';
|
|
2
|
+
export { ERROR_CODES, LEGACY_PROTOCOL_VERSIONS, MAX_LINE_BYTES, METHOD, MODERN_PROTOCOL_VERSIONS, SERVER_INSTRUCTIONS, SUPPORTED_PROTOCOL_VERSIONS, buildPrompts, buildResourceProvider, buildTools, classifyRequest, coerceNumericStrings, createLineReader, createMcpServer, createServer, createSession, createWriter, findSection, generateInWorker, inspectModernMeta, isCommentStrippable, negotiateLegacyVersion, parsePartSections, runStdioServer, stripComments, validateArguments, windowText } from './chunk-AEGJYOCF.js';
|
|
@@ -522,6 +522,8 @@ interface Manifest {
|
|
|
522
522
|
prompt?: ManifestArtifact;
|
|
523
523
|
navigation?: ManifestArtifact;
|
|
524
524
|
projectTree?: ManifestArtifact;
|
|
525
|
+
/** Why a slice or budget snapshot holds what it holds (written only when narrowed). */
|
|
526
|
+
selection?: ManifestArtifact;
|
|
525
527
|
audit?: ManifestArtifact;
|
|
526
528
|
/** `reports/diff.md`, when `diff` was requested and the repository had changes. */
|
|
527
529
|
diff?: ManifestArtifact;
|
|
@@ -578,6 +580,13 @@ interface Manifest {
|
|
|
578
580
|
total: number;
|
|
579
581
|
};
|
|
580
582
|
};
|
|
583
|
+
/** Tokens left unspent in the budget. */
|
|
584
|
+
headroomTokens?: number;
|
|
585
|
+
/** The next files a larger budget would take, in the order it would take them. */
|
|
586
|
+
nextInLine?: Array<{
|
|
587
|
+
path: string;
|
|
588
|
+
tokens: number;
|
|
589
|
+
}>;
|
|
581
590
|
/** Paths chosen, in the order they were selected. */
|
|
582
591
|
files: string[];
|
|
583
592
|
/** Scanned paths that did not fit. */
|
|
@@ -923,6 +932,10 @@ interface CliOptions {
|
|
|
923
932
|
stripComments?: boolean;
|
|
924
933
|
/** `--remove-empty-lines`: drop blank lines from emitted bodies. */
|
|
925
934
|
removeEmptyLines?: boolean;
|
|
935
|
+
/** `--only <globs>`: override the config include allow-list for this run. */
|
|
936
|
+
only?: string[];
|
|
937
|
+
/** `--ignore <globs>`: add to the config exclude list for this run. */
|
|
938
|
+
ignore?: string[];
|
|
926
939
|
maxPartBytes?: number;
|
|
927
940
|
maxPartTokens?: ByteSize | null;
|
|
928
941
|
largeFileBytes?: number;
|
|
@@ -522,6 +522,8 @@ interface Manifest {
|
|
|
522
522
|
prompt?: ManifestArtifact;
|
|
523
523
|
navigation?: ManifestArtifact;
|
|
524
524
|
projectTree?: ManifestArtifact;
|
|
525
|
+
/** Why a slice or budget snapshot holds what it holds (written only when narrowed). */
|
|
526
|
+
selection?: ManifestArtifact;
|
|
525
527
|
audit?: ManifestArtifact;
|
|
526
528
|
/** `reports/diff.md`, when `diff` was requested and the repository had changes. */
|
|
527
529
|
diff?: ManifestArtifact;
|
|
@@ -578,6 +580,13 @@ interface Manifest {
|
|
|
578
580
|
total: number;
|
|
579
581
|
};
|
|
580
582
|
};
|
|
583
|
+
/** Tokens left unspent in the budget. */
|
|
584
|
+
headroomTokens?: number;
|
|
585
|
+
/** The next files a larger budget would take, in the order it would take them. */
|
|
586
|
+
nextInLine?: Array<{
|
|
587
|
+
path: string;
|
|
588
|
+
tokens: number;
|
|
589
|
+
}>;
|
|
581
590
|
/** Paths chosen, in the order they were selected. */
|
|
582
591
|
files: string[];
|
|
583
592
|
/** Scanned paths that did not fit. */
|
|
@@ -923,6 +932,10 @@ interface CliOptions {
|
|
|
923
932
|
stripComments?: boolean;
|
|
924
933
|
/** `--remove-empty-lines`: drop blank lines from emitted bodies. */
|
|
925
934
|
removeEmptyLines?: boolean;
|
|
935
|
+
/** `--only <globs>`: override the config include allow-list for this run. */
|
|
936
|
+
only?: string[];
|
|
937
|
+
/** `--ignore <globs>`: add to the config exclude list for this run. */
|
|
938
|
+
ignore?: string[];
|
|
926
939
|
maxPartBytes?: number;
|
|
927
940
|
maxPartTokens?: ByteSize | null;
|
|
928
941
|
largeFileBytes?: number;
|
package/docs/benchmarks.md
CHANGED
|
@@ -37,6 +37,47 @@ tokens in full.
|
|
|
37
37
|
4. **Generation is not the bottleneck.** All three modes take about the same time; the saving is in
|
|
38
38
|
what gets written, not in what gets read.
|
|
39
39
|
|
|
40
|
+
## Ten public repositories
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
node scripts/benchmark-suite.mjs # the ten default repositories
|
|
44
|
+
node scripts/benchmark-suite.mjs --json # the same run, as data
|
|
45
|
+
node scripts/benchmark-suite.mjs <url> ... # your own list
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Each repository is cloned shallow into a scratch directory, packed by all three tools, and the
|
|
49
|
+
clone is deleted. A repository that cannot be cloned is reported as skipped with the reason, never
|
|
50
|
+
dropped from the table. Measured at 0.14.5, repomix 1.19.0, gitingest from PyPI:
|
|
51
|
+
|
|
52
|
+
| Repository | Ours files | Ours tokens | repomix tokens | repomix / ours | gitingest bytes |
|
|
53
|
+
| :-- | --: | --: | --: | --: | --: |
|
|
54
|
+
| jonschlinkert/is-odd | 11 | 5,450 | 4,291 | 0.79 | 29,392 |
|
|
55
|
+
| chalk/chalk | 32 | 77,684 | 79,006 | 1.02 | 238,864 |
|
|
56
|
+
| tj/co | 19 | 12,996 | 9,189 | 0.71 | 74,613 |
|
|
57
|
+
| isaacs/minimatch | 85 | 319,879 | 64,846,987 | 202.7 | 1,800,672 |
|
|
58
|
+
| moment/luxon | 151 | 303,032 | 250,093 | 0.83 | 806,740 |
|
|
59
|
+
| psf/requests | 117 | 382,695 | 687,333 | 1.80 | 524,712 |
|
|
60
|
+
| pallets/click | 177 | 470,265 | 335,153 | 0.71 | 1,413,342 |
|
|
61
|
+
| expressjs/express | 215 | 261,829 | 198,639 | 0.76 | 792,177 |
|
|
62
|
+
| colinhacks/zod | 686 | 1,762,835 | 1,748,187 | 0.99 | 4,468,877 |
|
|
63
|
+
| anuraghazra/github-readme-stats | 131 | 205,009 | 169,079 | 0.82 | 553,367 |
|
|
64
|
+
|
|
65
|
+
Read it carefully:
|
|
66
|
+
|
|
67
|
+
- **The ratio is not a contest.** Our estimate is one token per four bytes of emitted body; repomix
|
|
68
|
+
uses a tokenizer. Across nine repositories the two land within about plus or minus 30%, which is
|
|
69
|
+
what two reasonable estimates of the same text do.
|
|
70
|
+
- **minimatch is the exception, and it is a policy difference, not an estimate.** That repository
|
|
71
|
+
carries five benchmark fixtures of 20 to 25 MB of JSON. repomix emits them (64.8M tokens); our
|
|
72
|
+
large-file rule emits a bounded preview and records the omission, so the pack stays 319,879 tokens.
|
|
73
|
+
A pack that will not fit in a context window has not helped the reader, however complete it is.
|
|
74
|
+
- **gitingest publishes no token count**, so its column is the size of its one-document digest.
|
|
75
|
+
- **File counts agree within one or two** everywhere except minimatch, where our preview keeps the
|
|
76
|
+
files and repomix keeps their bytes.
|
|
77
|
+
|
|
78
|
+
The point of ten repositories is not a leaderboard; it is that the shape holds outside the
|
|
79
|
+
repository the tool was written in.
|
|
80
|
+
|
|
40
81
|
## Honest limits
|
|
41
82
|
|
|
42
83
|
- Self-benchmark. This repository is TypeScript with a clean import graph; a vendored monorepo with
|
|
@@ -52,15 +93,17 @@ tokens in full.
|
|
|
52
93
|
node scripts/compare.mjs --repomix # add --json for machine-readable output
|
|
53
94
|
```
|
|
54
95
|
|
|
55
|
-
repomix is fetched through `npx` at run time
|
|
56
|
-
this repository at 0.
|
|
96
|
+
repomix is fetched through `npx` at run time and gitingest through `python -m gitingest`;
|
|
97
|
+
neither is a dependency of this package. Measured on this repository at 0.14.2, repomix 1.19.0,
|
|
98
|
+
gitingest from PyPI, same machine:
|
|
57
99
|
|
|
58
100
|
| Tool / mode | Files | Content bytes | Tokens | vs full | Time |
|
|
59
101
|
| :-- | --: | --: | --: | --: | --: |
|
|
60
|
-
| codebase-snapshot (full) |
|
|
61
|
-
| codebase-snapshot (slice) | 4 | 239,
|
|
62
|
-
| codebase-snapshot (budget 30,000) |
|
|
63
|
-
| repomix 1.19.0 |
|
|
102
|
+
| codebase-snapshot (full) | 336 | 3,301,883 | 1,060,727 | 100% | 2.22 s |
|
|
103
|
+
| codebase-snapshot (slice) | 4 | 239,837 | 66,903 | 6.3% | 2.14 s |
|
|
104
|
+
| codebase-snapshot (budget 30,000) | 22 | 119,915 | 36,107 | 3.4% | 2.09 s |
|
|
105
|
+
| repomix 1.19.0 | 335 | 3,519,653 | 888,168 | 83.7% | n/a |
|
|
106
|
+
| gitingest | ? | 3,123,817 | n/a | n/a | n/a |
|
|
64
107
|
|
|
65
108
|
Read that honestly:
|
|
66
109
|
|
|
@@ -72,9 +115,11 @@ Read that honestly:
|
|
|
72
115
|
which includes its own wrappers), and the file sets differ slightly: 330 against 329.
|
|
73
116
|
- **The modes are what the other tool does not have.** repomix packs the repository; a slice and a
|
|
74
117
|
budget are the same snapshot narrowed after scanning, at 6.5% and 3.5% of the tokens.
|
|
75
|
-
- **gitingest is
|
|
76
|
-
|
|
118
|
+
- **gitingest's digest is smaller in bytes** (3.12 MB against our 3.30 MB of file content), and it
|
|
119
|
+
publishes no token count at all; the harness reports its digest size and says so. Its output is
|
|
120
|
+
one flat document with a tree and a separator per file, which is why a byte comparison is the
|
|
121
|
+
only honest one.
|
|
77
122
|
|
|
78
123
|
The same caveats apply to any comparison: different ignore rules, different wrappers, different
|
|
79
124
|
tokenizers. What is comparable is the shape — full packs are too large for a context window, and a
|
|
80
|
-
selection is one to two orders of magnitude smaller.
|
|
125
|
+
selection is one to two orders of magnitude smaller.
|
package/docs/cli.md
CHANGED
|
@@ -97,7 +97,7 @@ Exit `0` when the snapshot passes its own integrity check, `1` when it does not.
|
|
|
97
97
|
|
|
98
98
|
```
|
|
99
99
|
📸 Generating snapshot for: /path/to/repo
|
|
100
|
-
Branch: main | Part budget: 300 KB | Generator: 0.
|
|
100
|
+
Branch: main | Part budget: 300 KB | Generator: 0.16.0 (project dependency ^0.16.0)
|
|
101
101
|
|
|
102
102
|
✅ Snapshot generated in 0.14s:
|
|
103
103
|
- Tracked files: 121 included of 128 paths found — 7 skipped (default-ignore 5, binary 1, sensitive-file 1); every one is listed in snapshot/reports/audit.md
|
|
@@ -218,7 +218,7 @@ The whole first run in one command, with defaults and no prompts. This is the sa
|
|
|
218
218
|
🚀 Setup for: /path/to/repo
|
|
219
219
|
✅ Created snapshot.config.ts (preset: nextjs)
|
|
220
220
|
Added npm scripts: snapshot, snapshot:validate
|
|
221
|
-
Added devDependency: codebase-snapshot ^0.
|
|
221
|
+
Added devDependency: codebase-snapshot ^0.16.0
|
|
222
222
|
Added to .gitignore: /snapshot/, /snapshot.tmp/
|
|
223
223
|
⏳ Installing dependencies…
|
|
224
224
|
✅ Installed dependencies (npm install, 2.1s)
|
|
@@ -270,7 +270,7 @@ It also has three side effects on files you own, and it says so when it does the
|
|
|
270
270
|
```
|
|
271
271
|
✅ Created snapshot.config.ts (preset: node-lib)
|
|
272
272
|
Added npm scripts: snapshot, snapshot:validate
|
|
273
|
-
Added devDependency: codebase-snapshot ^0.
|
|
273
|
+
Added devDependency: codebase-snapshot ^0.16.0
|
|
274
274
|
Added to .gitignore: /snapshot/, /snapshot.tmp/
|
|
275
275
|
```
|
|
276
276
|
|
|
@@ -450,7 +450,7 @@ codebase-snapshot mcp # serve the current directory over stdio
|
|
|
450
450
|
codebase-snapshot mcp --cwd <path> # serve another repository
|
|
451
451
|
```
|
|
452
452
|
|
|
453
|
-
Serves the repository to a Model Context Protocol client over stdio:
|
|
453
|
+
Serves the repository to a Model Context Protocol client over stdio: 26 tools, `snapshot://`
|
|
454
454
|
resources and two prompts. Stdout carries JSON-RPC messages and nothing else; every note goes to
|
|
455
455
|
stderr. It speaks both protocol eras — the legacy `initialize` handshake and the stateless
|
|
456
456
|
`2026-07-28` revision — and answers whichever the client starts with.
|
|
@@ -494,6 +494,8 @@ for the two install flags, and the init-and-setup flags list both commands.
|
|
|
494
494
|
| `--prompt-task <task>` | string | `audit` | generate, validate | `audit`, `review` or `explain` — which job the brief is written for. Changes the opening section, not the standard. |
|
|
495
495
|
| `--budget-tokens <n>` | count | unset | generate | Fit the snapshot into n tokens by selecting whole files (entry points, then the most-imported). Records a `budget` block; the rest are `not-selected`. See [budget](budget.md). |
|
|
496
496
|
| `--sign` | flag | off | generate | Sign `manifest.json` with Ed25519 and write `signature.json`. Key from `SNAPSHOT_SIGNING_KEY`, else generated (trust on first use). See [signing](signing.md). |
|
|
497
|
+
| `--only <globs>` | list | unset | generate, validate, explain | Comma-separated globs to include: **replaces** the config `include` list for this run. |
|
|
498
|
+
| `--ignore <globs>` | list | unset | generate, validate, explain | Comma-separated globs to exclude: **adds to** the config exclude list for this run. Both are part of the config digest, so `validate` needs the same flags. |
|
|
497
499
|
| `--remove-empty-lines` | flag | off | generate, validate | Drop blank and whitespace-only lines from emitted bodies. Line numbers no longer match the source; every affected file records `emptyLinesRemoved: true` and the brief says so. |
|
|
498
500
|
| `--strip-comments` | flag | off | generate, validate | Remove comment text from JavaScript/TypeScript bodies. Newlines are kept, so line numbers do not move; files record `inclusionMode: "comments-stripped"`. |
|
|
499
501
|
| `--workspace <a,b>` | list | unset | generate | One snapshot per member under `<outDir>/<name>`, plus `WORKSPACE.json`. Exits 1 if any member failed. See [workspaces](workspace.md). |
|
|
@@ -671,4 +673,4 @@ npx codebase-snapshot generate --watch
|
|
|
671
673
|
|
|
672
674
|
# Give an agent everything it needs
|
|
673
675
|
npx codebase-snapshot skill --install
|
|
674
|
-
```
|
|
676
|
+
```
|
package/docs/deploy.md
CHANGED
|
@@ -61,8 +61,8 @@ After=network.target
|
|
|
61
61
|
Type=oneshot
|
|
62
62
|
User=deploy
|
|
63
63
|
WorkingDirectory=/srv/app
|
|
64
|
-
ExecStart=/usr/bin/npx -y codebase-snapshot@0.
|
|
65
|
-
ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.
|
|
64
|
+
ExecStart=/usr/bin/npx -y codebase-snapshot@0.16.0 generate --cwd /srv/app
|
|
65
|
+
ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.16.0 validate --cwd /srv/app
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
```ini
|