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/index.cjs
CHANGED
|
@@ -4012,7 +4012,7 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
4012
4012
|
|
|
4013
4013
|
// src/version.ts
|
|
4014
4014
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
4015
|
-
var GENERATOR_VERSION = "0.
|
|
4015
|
+
var GENERATOR_VERSION = "0.16.0";
|
|
4016
4016
|
var SCHEMA_VERSION = "3.0.0";
|
|
4017
4017
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
4018
4018
|
function isOurGeneratorName(name) {
|
|
@@ -5884,7 +5884,12 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
5884
5884
|
logCount: resolveLogCount(
|
|
5885
5885
|
cliOptions?.logCount ?? cliOptions?.includeLogs ?? userConfig?.logCount
|
|
5886
5886
|
),
|
|
5887
|
-
|
|
5887
|
+
// `--only` replaces the allow-list for this run; `--ignore` adds to the deny-list. The two
|
|
5888
|
+
// directions are different on purpose: a narrower allow-list is a statement about the whole
|
|
5889
|
+
// run, while "also ignore this" is naturally cumulative with what the config already excludes.
|
|
5890
|
+
include: resolveInclude(
|
|
5891
|
+
cliOptions?.only ?? userConfig?.include
|
|
5892
|
+
),
|
|
5888
5893
|
preset: preset.presetName,
|
|
5889
5894
|
presetExclude,
|
|
5890
5895
|
artifacts,
|
|
@@ -5895,9 +5900,12 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
5895
5900
|
kinds,
|
|
5896
5901
|
// `exclude` is the flag spelling of the same setting; writing it in a config used to
|
|
5897
5902
|
// be ignored without a word.
|
|
5898
|
-
excludePatterns:
|
|
5899
|
-
|
|
5900
|
-
|
|
5903
|
+
excludePatterns: [
|
|
5904
|
+
...resolveExcludePatterns(
|
|
5905
|
+
userConfig?.excludePatterns ?? userConfig?.exclude
|
|
5906
|
+
),
|
|
5907
|
+
...resolveExcludePatterns(cliOptions?.ignore)
|
|
5908
|
+
],
|
|
5901
5909
|
secretRules,
|
|
5902
5910
|
// Extra property rather than a `ResolvedSnapshotConfig` field: the resolved
|
|
5903
5911
|
// shape is owned elsewhere, and every scan reads it through the registry in
|
|
@@ -6962,6 +6970,51 @@ function generateNavigation(manifest) {
|
|
|
6962
6970
|
return lines.join("\n");
|
|
6963
6971
|
}
|
|
6964
6972
|
|
|
6973
|
+
// src/generator/selection.ts
|
|
6974
|
+
function generateSelectionReport(manifest, selection) {
|
|
6975
|
+
const lines = [];
|
|
6976
|
+
lines.push("# Selection");
|
|
6977
|
+
lines.push("");
|
|
6978
|
+
lines.push("**Kind:** `" + selection.kind + "` ");
|
|
6979
|
+
for (const detailLine of selection.detail.split("\n")) {
|
|
6980
|
+
lines.push("**" + detailLine.slice(0, detailLine.indexOf(":")) + ":**" + detailLine.slice(detailLine.indexOf(":") + 1) + " ");
|
|
6981
|
+
}
|
|
6982
|
+
lines.push("**Selected files:** " + selection.files.length + " ");
|
|
6983
|
+
const spent = manifest.budget?.usedTokens ?? manifest.slice?.usedTokens ?? 0;
|
|
6984
|
+
lines.push("**Tokens spent:** " + spent.toLocaleString("en-US"));
|
|
6985
|
+
lines.push("");
|
|
6986
|
+
lines.push("## Why each file is here");
|
|
6987
|
+
lines.push("");
|
|
6988
|
+
lines.push("| File | Tokens | Reason |");
|
|
6989
|
+
lines.push("| :-- | --: | :-- |");
|
|
6990
|
+
for (const file of selection.files) {
|
|
6991
|
+
lines.push("| `" + file.path + "` | " + file.tokens.toLocaleString("en-US") + " | " + file.why + " |");
|
|
6992
|
+
}
|
|
6993
|
+
lines.push("");
|
|
6994
|
+
const dropped = selection.kind === "slice" ? manifest.slice?.dropped : manifest.budget?.dropped;
|
|
6995
|
+
if (typeof dropped === "number") {
|
|
6996
|
+
lines.push("## What was left out");
|
|
6997
|
+
lines.push("");
|
|
6998
|
+
lines.push(dropped + " file(s) were not selected. They are recorded in `manifest.json` as `skipped`");
|
|
6999
|
+
lines.push("with the reason `not-selected`, so nothing left the snapshot without a reason.");
|
|
7000
|
+
lines.push("");
|
|
7001
|
+
}
|
|
7002
|
+
const next = manifest.budget?.nextInLine ?? [];
|
|
7003
|
+
if (next.length > 0) {
|
|
7004
|
+
lines.push("## What a larger budget would buy");
|
|
7005
|
+
lines.push("");
|
|
7006
|
+
lines.push("Headroom: " + (manifest.budget?.headroomTokens ?? 0).toLocaleString("en-US") + " tokens.");
|
|
7007
|
+
lines.push("");
|
|
7008
|
+
lines.push("| File | Tokens |");
|
|
7009
|
+
lines.push("| :-- | --: |");
|
|
7010
|
+
for (const item of next) {
|
|
7011
|
+
lines.push("| `" + item.path + "` | " + item.tokens.toLocaleString("en-US") + " |");
|
|
7012
|
+
}
|
|
7013
|
+
lines.push("");
|
|
7014
|
+
}
|
|
7015
|
+
return lines.join("\n");
|
|
7016
|
+
}
|
|
7017
|
+
|
|
6965
7018
|
// src/mcp/retrieval.ts
|
|
6966
7019
|
var STOPWORDS = /* @__PURE__ */ new Set([
|
|
6967
7020
|
"the",
|
|
@@ -9481,6 +9534,7 @@ function validateSnapshot(configInput) {
|
|
|
9481
9534
|
["reports/diff.md", manifest.artifacts?.diff],
|
|
9482
9535
|
["reports/log.md", manifest.artifacts?.log],
|
|
9483
9536
|
["reports/tokens.md", manifest.artifacts?.tokenTree],
|
|
9537
|
+
["reports/selection.md", manifest.artifacts?.selection],
|
|
9484
9538
|
["full-codebase.json", manifest.artifacts?.fullJson],
|
|
9485
9539
|
["full-codebase.md", manifest.artifacts?.fullMarkdown],
|
|
9486
9540
|
["full-codebase.xml", manifest.artifacts?.fullXml]
|
|
@@ -10091,6 +10145,7 @@ var ARTIFACT_FILES = {
|
|
|
10091
10145
|
diff: "reports/diff.md",
|
|
10092
10146
|
log: "reports/log.md",
|
|
10093
10147
|
tokenTree: "reports/tokens.md",
|
|
10148
|
+
selection: "reports/selection.md",
|
|
10094
10149
|
fullJson: "full-codebase.json",
|
|
10095
10150
|
fullMarkdown: "full-codebase.md",
|
|
10096
10151
|
fullXml: "full-codebase.xml",
|
|
@@ -11532,6 +11587,65 @@ var historyTool = {
|
|
|
11532
11587
|
};
|
|
11533
11588
|
}
|
|
11534
11589
|
};
|
|
11590
|
+
var budgetTool = {
|
|
11591
|
+
name: "snapshot_budget",
|
|
11592
|
+
title: "What a larger budget would buy",
|
|
11593
|
+
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.',
|
|
11594
|
+
inputSchema: {
|
|
11595
|
+
type: "object",
|
|
11596
|
+
properties: {
|
|
11597
|
+
budgets: {
|
|
11598
|
+
type: "array",
|
|
11599
|
+
items: { type: "integer", minimum: 500 },
|
|
11600
|
+
description: "Token budgets to compare, ascending (default 10000, 30000, 60000)."
|
|
11601
|
+
},
|
|
11602
|
+
question: { type: "string", description: "Optional question to plan for; absent plans for the repository as a whole." },
|
|
11603
|
+
includeTests: { type: "boolean", description: "Include test files (default false)." },
|
|
11604
|
+
root: ROOT_PROPERTY,
|
|
11605
|
+
outDir: OUT_DIR_PROPERTY
|
|
11606
|
+
},
|
|
11607
|
+
additionalProperties: false
|
|
11608
|
+
},
|
|
11609
|
+
outputSchema: {
|
|
11610
|
+
type: "object",
|
|
11611
|
+
properties: { budgets: { type: "array", items: { type: "object" } } }
|
|
11612
|
+
},
|
|
11613
|
+
annotations: READ_ONLY,
|
|
11614
|
+
async handler(args, context) {
|
|
11615
|
+
const prepared = await prepare(args, context, outDirOverride(args));
|
|
11616
|
+
if (!prepared.ok) return prepared.outcome;
|
|
11617
|
+
const read = readManifest3(prepared.workspace);
|
|
11618
|
+
if (!read.ok) return { text: read.message + " Call snapshot_generate first.", isError: true };
|
|
11619
|
+
const requested = Array.isArray(args.budgets) ? args.budgets.filter((value) => typeof value === "number").map((value) => Math.max(500, value)) : [1e4, 3e4, 6e4];
|
|
11620
|
+
const budgets = [...new Set(requested)].sort((left, right) => left - right);
|
|
11621
|
+
if (budgets.length === 0) return { text: "budgets must hold at least one number", isError: true };
|
|
11622
|
+
const question = typeof args.question === "string" ? args.question : "";
|
|
11623
|
+
const rows = [];
|
|
11624
|
+
let previous = /* @__PURE__ */ new Set();
|
|
11625
|
+
for (const budget of budgets) {
|
|
11626
|
+
const plan = planForQuestion(read.manifest, question, {
|
|
11627
|
+
maxTokens: budget,
|
|
11628
|
+
...args.includeTests === true ? { includeTests: true } : {}
|
|
11629
|
+
});
|
|
11630
|
+
const paths = new Set(plan.files.map((file) => file.path));
|
|
11631
|
+
const gained = [...paths].filter((path26) => !previous.has(path26)).sort();
|
|
11632
|
+
previous = paths;
|
|
11633
|
+
rows.push({
|
|
11634
|
+
budget,
|
|
11635
|
+
files: plan.files.length,
|
|
11636
|
+
usedTokens: plan.usedTokens,
|
|
11637
|
+
gained
|
|
11638
|
+
});
|
|
11639
|
+
}
|
|
11640
|
+
const lines = [question === "" ? "No question: planning for the repository as a whole." : "Question: " + question];
|
|
11641
|
+
for (const row of rows) {
|
|
11642
|
+
lines.push(
|
|
11643
|
+
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" : "") + ")")
|
|
11644
|
+
);
|
|
11645
|
+
}
|
|
11646
|
+
return { text: lines.join("\n"), structured: { budgets: rows } };
|
|
11647
|
+
}
|
|
11648
|
+
};
|
|
11535
11649
|
var testsTool = {
|
|
11536
11650
|
name: "snapshot_tests",
|
|
11537
11651
|
title: "Tests that cover a file, and files a test covers",
|
|
@@ -12218,6 +12332,11 @@ var symbolTool = {
|
|
|
12218
12332
|
name: { type: "string", description: "Symbol name, case-insensitive." },
|
|
12219
12333
|
lines: { type: "integer", description: "Window size around the definition (default 40).", minimum: 5 },
|
|
12220
12334
|
maxFiles: { type: "integer", description: "Cap on files searched (default 5).", minimum: 1 },
|
|
12335
|
+
references: {
|
|
12336
|
+
type: "boolean",
|
|
12337
|
+
description: "Also report call sites: other files whose body mentions the name (default true)."
|
|
12338
|
+
},
|
|
12339
|
+
maxReferences: { type: "integer", description: "Cap on reported call sites (default 20).", minimum: 1 },
|
|
12221
12340
|
root: ROOT_PROPERTY,
|
|
12222
12341
|
outDir: OUT_DIR_PROPERTY
|
|
12223
12342
|
},
|
|
@@ -12228,7 +12347,8 @@ var symbolTool = {
|
|
|
12228
12347
|
type: "object",
|
|
12229
12348
|
properties: {
|
|
12230
12349
|
found: { type: "integer" },
|
|
12231
|
-
matches: { type: "array", items: { type: "object" } }
|
|
12350
|
+
matches: { type: "array", items: { type: "object" } },
|
|
12351
|
+
references: { type: "array", items: { type: "object" } }
|
|
12232
12352
|
}
|
|
12233
12353
|
},
|
|
12234
12354
|
annotations: READ_ONLY,
|
|
@@ -12281,8 +12401,44 @@ var symbolTool = {
|
|
|
12281
12401
|
structured: { found: 0, matches: [] }
|
|
12282
12402
|
};
|
|
12283
12403
|
}
|
|
12284
|
-
const
|
|
12285
|
-
|
|
12404
|
+
const callSites = [];
|
|
12405
|
+
if (args.references !== false) {
|
|
12406
|
+
const limit = Math.max(1, typeof args.maxReferences === "number" ? args.maxReferences : 20);
|
|
12407
|
+
const definitionKeys = new Set(matches.map((match) => match.path + ":" + match.line));
|
|
12408
|
+
const word = new RegExp("\\b" + name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "\\b");
|
|
12409
|
+
const parts = /* @__PURE__ */ new Map();
|
|
12410
|
+
let scanned = 0;
|
|
12411
|
+
for (const file of read.manifest.files) {
|
|
12412
|
+
if (callSites.length >= limit) break;
|
|
12413
|
+
const partPath = partPathFor(workspace, file.part);
|
|
12414
|
+
if (partPath === null) continue;
|
|
12415
|
+
let partText = parts.get(partPath);
|
|
12416
|
+
if (partText === void 0) {
|
|
12417
|
+
try {
|
|
12418
|
+
partText = fs24__namespace.readFileSync(partPath, "utf8");
|
|
12419
|
+
} catch {
|
|
12420
|
+
continue;
|
|
12421
|
+
}
|
|
12422
|
+
parts.set(partPath, partText);
|
|
12423
|
+
}
|
|
12424
|
+
if (scanned > MAX_SEARCH_BYTES) break;
|
|
12425
|
+
scanned += Buffer.byteLength(partText, "utf8");
|
|
12426
|
+
const section = findSection(parsePartSections(partText), file.relativePath);
|
|
12427
|
+
if (section === null) continue;
|
|
12428
|
+
const bodyLines = section.body.split("\n");
|
|
12429
|
+
for (let index = 0; index < bodyLines.length && callSites.length < limit; index += 1) {
|
|
12430
|
+
if (!word.test(bodyLines[index])) continue;
|
|
12431
|
+
callSites.push({
|
|
12432
|
+
path: file.relativePath,
|
|
12433
|
+
line: index + 1,
|
|
12434
|
+
text: bodyLines[index].trim().slice(0, 200),
|
|
12435
|
+
definition: definitionKeys.has(file.relativePath + ":" + (index + 1))
|
|
12436
|
+
});
|
|
12437
|
+
}
|
|
12438
|
+
}
|
|
12439
|
+
}
|
|
12440
|
+
const text2 = 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")));
|
|
12441
|
+
return { text: text2, structured: { found: matches.length, matches, references: callSites } };
|
|
12286
12442
|
}
|
|
12287
12443
|
};
|
|
12288
12444
|
var contextTool = {
|
|
@@ -12516,6 +12672,110 @@ var planForTool = {
|
|
|
12516
12672
|
return { text: lines.join("\n"), structured: plan };
|
|
12517
12673
|
}
|
|
12518
12674
|
};
|
|
12675
|
+
var answerTool = {
|
|
12676
|
+
name: "snapshot_answer",
|
|
12677
|
+
title: "Question in, budgeted context out",
|
|
12678
|
+
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.",
|
|
12679
|
+
inputSchema: {
|
|
12680
|
+
type: "object",
|
|
12681
|
+
properties: {
|
|
12682
|
+
question: { type: "string", description: "What you need to answer." },
|
|
12683
|
+
maxTokens: { type: "integer", description: "Budget for the whole block (default 20000).", minimum: 500 },
|
|
12684
|
+
linesPerFile: { type: "integer", description: "Head lines per file (default 60).", minimum: 10 },
|
|
12685
|
+
includeTests: { type: "boolean", description: "Include test files (default false)." },
|
|
12686
|
+
root: ROOT_PROPERTY,
|
|
12687
|
+
outDir: OUT_DIR_PROPERTY
|
|
12688
|
+
},
|
|
12689
|
+
required: ["question"],
|
|
12690
|
+
additionalProperties: false
|
|
12691
|
+
},
|
|
12692
|
+
outputSchema: {
|
|
12693
|
+
type: "object",
|
|
12694
|
+
properties: {
|
|
12695
|
+
question: { type: "string" },
|
|
12696
|
+
budgetTokens: { type: "integer" },
|
|
12697
|
+
usedTokens: { type: "integer" },
|
|
12698
|
+
files: { type: "array", items: { type: "object" } },
|
|
12699
|
+
omitted: { type: "array", items: { type: "object" } }
|
|
12700
|
+
}
|
|
12701
|
+
},
|
|
12702
|
+
annotations: READ_ONLY,
|
|
12703
|
+
async handler(args, context) {
|
|
12704
|
+
const question = typeof args.question === "string" ? args.question.trim() : "";
|
|
12705
|
+
if (question.length === 0) return { text: "question must be a non-empty string", isError: true };
|
|
12706
|
+
const prepared = await prepare(args, context, outDirOverride(args));
|
|
12707
|
+
if (!prepared.ok) return prepared.outcome;
|
|
12708
|
+
const read = readManifest3(prepared.workspace);
|
|
12709
|
+
if (!read.ok) return { text: read.message + " Call snapshot_generate first.", isError: true };
|
|
12710
|
+
const maxTokens = Math.max(500, typeof args.maxTokens === "number" ? args.maxTokens : 2e4);
|
|
12711
|
+
const linesPerFile = Math.max(10, typeof args.linesPerFile === "number" ? args.linesPerFile : 60);
|
|
12712
|
+
const plan = planForQuestion(read.manifest, question, {
|
|
12713
|
+
maxTokens,
|
|
12714
|
+
...args.includeTests === true ? { includeTests: true } : {}
|
|
12715
|
+
});
|
|
12716
|
+
const blocks = [];
|
|
12717
|
+
const omitted = [];
|
|
12718
|
+
let used = 0;
|
|
12719
|
+
const parts = /* @__PURE__ */ new Map();
|
|
12720
|
+
for (const planned of plan.files) {
|
|
12721
|
+
if (used >= maxTokens) {
|
|
12722
|
+
omitted.push({ path: planned.path, reason: "the budget was spent on earlier files" });
|
|
12723
|
+
continue;
|
|
12724
|
+
}
|
|
12725
|
+
const partPath = partPathFor(prepared.workspace, planned.part);
|
|
12726
|
+
if (partPath === null) {
|
|
12727
|
+
omitted.push({ path: planned.path, reason: "its part is not in the snapshot" });
|
|
12728
|
+
continue;
|
|
12729
|
+
}
|
|
12730
|
+
let partText = parts.get(partPath);
|
|
12731
|
+
if (partText === void 0) {
|
|
12732
|
+
try {
|
|
12733
|
+
partText = fs24__namespace.readFileSync(partPath, "utf8");
|
|
12734
|
+
} catch {
|
|
12735
|
+
omitted.push({ path: planned.path, reason: "its part could not be read" });
|
|
12736
|
+
continue;
|
|
12737
|
+
}
|
|
12738
|
+
parts.set(partPath, partText);
|
|
12739
|
+
}
|
|
12740
|
+
const section = findSection(parsePartSections(partText), planned.path);
|
|
12741
|
+
if (section === null) {
|
|
12742
|
+
omitted.push({ path: planned.path, reason: "no section in its part" });
|
|
12743
|
+
continue;
|
|
12744
|
+
}
|
|
12745
|
+
const window = windowText(section.body, 1, linesPerFile);
|
|
12746
|
+
const text2 = window.text;
|
|
12747
|
+
const tokens = estimateTokens(text2);
|
|
12748
|
+
if (used + tokens > maxTokens && blocks.length > 0) {
|
|
12749
|
+
omitted.push({ path: planned.path, reason: "did not fit the remaining budget" });
|
|
12750
|
+
continue;
|
|
12751
|
+
}
|
|
12752
|
+
const numbered = text2.split("\n").map((line, index) => String(index + 1).padStart(5, " ") + " " + line).join("\n");
|
|
12753
|
+
blocks.push({ path: planned.path, why: planned.why, tokens, text: numbered, truncated: window.truncated, totalLines: window.totalLines });
|
|
12754
|
+
used += tokens;
|
|
12755
|
+
}
|
|
12756
|
+
const lines = [
|
|
12757
|
+
"# Answer context: " + question,
|
|
12758
|
+
"Budget: " + used + " of " + maxTokens + " tokens; " + blocks.length + " file(s)."
|
|
12759
|
+
];
|
|
12760
|
+
for (const block of blocks) {
|
|
12761
|
+
lines.push("");
|
|
12762
|
+
lines.push("## " + block.path + " (" + block.tokens + " tokens, " + (block.truncated ? "first lines of " + block.totalLines : "whole file") + ")");
|
|
12763
|
+
lines.push("Why: " + block.why);
|
|
12764
|
+
lines.push("```");
|
|
12765
|
+
lines.push(block.text);
|
|
12766
|
+
lines.push("```");
|
|
12767
|
+
}
|
|
12768
|
+
if (omitted.length > 0) {
|
|
12769
|
+
lines.push("");
|
|
12770
|
+
lines.push("Not included:");
|
|
12771
|
+
for (const entry of omitted) lines.push("- " + entry.path + " - " + entry.reason);
|
|
12772
|
+
}
|
|
12773
|
+
return {
|
|
12774
|
+
text: lines.join("\n"),
|
|
12775
|
+
structured: { question, budgetTokens: maxTokens, usedTokens: used, files: blocks, omitted }
|
|
12776
|
+
};
|
|
12777
|
+
}
|
|
12778
|
+
};
|
|
12519
12779
|
var healthTool = {
|
|
12520
12780
|
name: "snapshot_health",
|
|
12521
12781
|
title: "Snapshot health audit",
|
|
@@ -13366,6 +13626,7 @@ var explainTool = {
|
|
|
13366
13626
|
var TOOL_COSTS = {
|
|
13367
13627
|
snapshot_status: "cheap",
|
|
13368
13628
|
snapshot_health: "expensive",
|
|
13629
|
+
snapshot_budget: "medium",
|
|
13369
13630
|
snapshot_history: "cheap",
|
|
13370
13631
|
snapshot_tests: "cheap",
|
|
13371
13632
|
snapshot_workspace: "cheap",
|
|
@@ -13381,6 +13642,7 @@ var TOOL_COSTS = {
|
|
|
13381
13642
|
snapshot_context: "medium",
|
|
13382
13643
|
snapshot_query: "cheap",
|
|
13383
13644
|
snapshot_plan_for: "cheap",
|
|
13645
|
+
snapshot_answer: "medium",
|
|
13384
13646
|
snapshot_plan: "expensive",
|
|
13385
13647
|
snapshot_generate: "expensive",
|
|
13386
13648
|
snapshot_validate: "medium",
|
|
@@ -13393,6 +13655,7 @@ function buildTools() {
|
|
|
13393
13655
|
return [
|
|
13394
13656
|
statusTool,
|
|
13395
13657
|
healthTool,
|
|
13658
|
+
budgetTool,
|
|
13396
13659
|
historyTool,
|
|
13397
13660
|
testsTool,
|
|
13398
13661
|
workspaceTool,
|
|
@@ -13408,6 +13671,7 @@ function buildTools() {
|
|
|
13408
13671
|
contextTool,
|
|
13409
13672
|
queryTool,
|
|
13410
13673
|
planForTool,
|
|
13674
|
+
answerTool,
|
|
13411
13675
|
planTool,
|
|
13412
13676
|
generateTool,
|
|
13413
13677
|
validateTool,
|
|
@@ -13586,6 +13850,8 @@ var VALIDATE_OPTIONS = [
|
|
|
13586
13850
|
"sarif",
|
|
13587
13851
|
"strip-comments",
|
|
13588
13852
|
"remove-empty-lines",
|
|
13853
|
+
"only",
|
|
13854
|
+
"ignore",
|
|
13589
13855
|
"pack",
|
|
13590
13856
|
// The opt-in reports change the artifact selection the manifest records, so validate must accept
|
|
13591
13857
|
// them to compare like with like: without the flags it reports the selection as drift.
|
|
@@ -13621,6 +13887,8 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
13621
13887
|
generate: [
|
|
13622
13888
|
"strip-comments",
|
|
13623
13889
|
"remove-empty-lines",
|
|
13890
|
+
"only",
|
|
13891
|
+
"ignore",
|
|
13624
13892
|
"workspace",
|
|
13625
13893
|
"budget-tokens",
|
|
13626
13894
|
"sign",
|
|
@@ -13701,6 +13969,10 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
13701
13969
|
// Removed rather than implemented, because a flag that parses and does nothing is the defect
|
|
13702
13970
|
// this table exists to prevent.
|
|
13703
13971
|
"large-file-bytes",
|
|
13972
|
+
// `--only` and `--ignore` change which files are scanned, so they change what `explain` can say
|
|
13973
|
+
// about a path; without them the answer for an ignored file is "included: true".
|
|
13974
|
+
"only",
|
|
13975
|
+
"ignore",
|
|
13704
13976
|
"include-sensitive-files",
|
|
13705
13977
|
"no-config",
|
|
13706
13978
|
"discovery",
|
|
@@ -14173,6 +14445,18 @@ function buildAgentContract() {
|
|
|
14173
14445
|
appliesTo: optionAppliesTo("allow-origin"),
|
|
14174
14446
|
summary: "mcp --http: comma-separated extra CORS origins. Loopback origins are always allowed."
|
|
14175
14447
|
},
|
|
14448
|
+
{
|
|
14449
|
+
flag: "--only",
|
|
14450
|
+
type: "string",
|
|
14451
|
+
summary: "Comma-separated globs to include: overrides the config include list for this run.",
|
|
14452
|
+
appliesTo: optionAppliesTo("only")
|
|
14453
|
+
},
|
|
14454
|
+
{
|
|
14455
|
+
flag: "--ignore",
|
|
14456
|
+
type: "string",
|
|
14457
|
+
summary: "Comma-separated globs to exclude, added to the config exclude list for this run.",
|
|
14458
|
+
appliesTo: optionAppliesTo("ignore")
|
|
14459
|
+
},
|
|
14176
14460
|
{
|
|
14177
14461
|
flag: "--remove-empty-lines",
|
|
14178
14462
|
type: "boolean",
|
|
@@ -14711,7 +14995,7 @@ diff, and the commit, are then yours.
|
|
|
14711
14995
|
## When the client speaks MCP
|
|
14712
14996
|
|
|
14713
14997
|
If the agent runs inside an MCP client, \`npx ${PACKAGE_NAME2}@latest mcp\` serves this repository
|
|
14714
|
-
as
|
|
14998
|
+
as 26 tools over stdio instead of shelling out. Its reads come from the snapshot rather than
|
|
14715
14999
|
the working tree, so excluded files and redacted values never reach the context. Use
|
|
14716
15000
|
\`snapshot_locate\` before \`snapshot_read\`, and \`snapshot_validate\` before trusting a snapshot
|
|
14717
15001
|
from an earlier session.
|
|
@@ -19427,6 +19711,7 @@ function generateSnapshot(configInput, options) {
|
|
|
19427
19711
|
}
|
|
19428
19712
|
}
|
|
19429
19713
|
let sliceBlock;
|
|
19714
|
+
let selectionReport = null;
|
|
19430
19715
|
if (options?.slice !== void 0) {
|
|
19431
19716
|
const byFile = files.filter((file) => isSourceSummary(file.summary)).map((file) => ({
|
|
19432
19717
|
path: file.relativePath,
|
|
@@ -19450,6 +19735,11 @@ function generateSnapshot(configInput, options) {
|
|
|
19450
19735
|
files: plan.files.map((file) => file.path),
|
|
19451
19736
|
dropped: scanned - plan.files.length
|
|
19452
19737
|
};
|
|
19738
|
+
selectionReport = {
|
|
19739
|
+
kind: "slice",
|
|
19740
|
+
detail: "Question: " + options.slice.question + "\nBudget: " + plan.budgetTokens.toLocaleString("en-US") + " tokens",
|
|
19741
|
+
files: plan.files.map((file) => ({ path: file.path, tokens: file.tokens, why: file.why }))
|
|
19742
|
+
};
|
|
19453
19743
|
}
|
|
19454
19744
|
let budgetBlock;
|
|
19455
19745
|
if (options?.budgetTokens !== void 0) {
|
|
@@ -19475,12 +19765,26 @@ function generateSnapshot(configInput, options) {
|
|
|
19475
19765
|
const keep = /* @__PURE__ */ new Set();
|
|
19476
19766
|
let used = 0;
|
|
19477
19767
|
const selected = [];
|
|
19768
|
+
const chosen = [];
|
|
19478
19769
|
for (const item of ranked) {
|
|
19479
19770
|
if (used + item.tokens > budget) continue;
|
|
19480
19771
|
keep.add(item.file.relativePath);
|
|
19481
19772
|
selected.push(item.file.relativePath);
|
|
19773
|
+
chosen.push({
|
|
19774
|
+
path: item.file.relativePath,
|
|
19775
|
+
tokens: item.tokens,
|
|
19776
|
+
why: (entry(item.file.relativePath) ? "entry point" : "not an entry point") + "; " + (importers.get(item.file.relativePath) ?? 0) + " importer(s); layer " + item.file.layer
|
|
19777
|
+
});
|
|
19482
19778
|
used += item.tokens;
|
|
19483
19779
|
}
|
|
19780
|
+
const nextInLine = [];
|
|
19781
|
+
let headroom = budget - used;
|
|
19782
|
+
for (const item of ranked) {
|
|
19783
|
+
if (keep.has(item.file.relativePath)) continue;
|
|
19784
|
+
if (nextInLine.length >= 10) break;
|
|
19785
|
+
nextInLine.push({ path: item.file.relativePath, tokens: item.tokens });
|
|
19786
|
+
headroom = Math.max(headroom, item.tokens);
|
|
19787
|
+
}
|
|
19484
19788
|
const scanned = files.length;
|
|
19485
19789
|
const byLayer = {};
|
|
19486
19790
|
let entryKept = 0;
|
|
@@ -19509,7 +19813,14 @@ function generateSnapshot(configInput, options) {
|
|
|
19509
19813
|
usedTokens: used,
|
|
19510
19814
|
files: selected,
|
|
19511
19815
|
dropped: scanned - selected.length,
|
|
19512
|
-
coverage: { byLayer, entryPoints: { kept: entryKept, total: entryTotal }, symbols: { kept: symbolsKept, total: symbolsTotal } }
|
|
19816
|
+
coverage: { byLayer, entryPoints: { kept: entryKept, total: entryTotal }, symbols: { kept: symbolsKept, total: symbolsTotal } },
|
|
19817
|
+
headroomTokens: Math.max(0, budget - used),
|
|
19818
|
+
nextInLine
|
|
19819
|
+
};
|
|
19820
|
+
selectionReport = {
|
|
19821
|
+
kind: "budget",
|
|
19822
|
+
detail: "Budget: " + budget.toLocaleString("en-US") + " tokens",
|
|
19823
|
+
files: chosen
|
|
19513
19824
|
};
|
|
19514
19825
|
if (entryTotal > 0 && entryKept < entryTotal) {
|
|
19515
19826
|
warnings.push(
|
|
@@ -19818,6 +20129,8 @@ function generateSnapshot(configInput, options) {
|
|
|
19818
20129
|
}) : null;
|
|
19819
20130
|
if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
|
|
19820
20131
|
if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
|
|
20132
|
+
const selectionText = selectionReport === null ? null : generateSelectionReport(manifest, selectionReport);
|
|
20133
|
+
if (selectionText !== null) manifest.artifacts.selection = artifactRecord(selectionText);
|
|
19821
20134
|
let monolithJson = null;
|
|
19822
20135
|
let monolithMarkdown = null;
|
|
19823
20136
|
let monolithXml = null;
|
|
@@ -19974,6 +20287,9 @@ function generateSnapshot(configInput, options) {
|
|
|
19974
20287
|
if (tokenTree !== null) {
|
|
19975
20288
|
writeArtifact(reportsDir, "tokens.md", tokenTree.text);
|
|
19976
20289
|
}
|
|
20290
|
+
if (selectionText !== null) {
|
|
20291
|
+
writeArtifact(reportsDir, "selection.md", selectionText);
|
|
20292
|
+
}
|
|
19977
20293
|
if (sarifText !== null) {
|
|
19978
20294
|
writeArtifact(reportsDir, "audit.sarif", sarifText);
|
|
19979
20295
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as SecretRule, D as DiscoveryMode, a as SkipRecord, J as JsonSummary, M as MarkdownSummary, b as SourceSummary, K as KindRule, L as LayerRule, R as ResolvedSnapshotConfig, c as SnapshotConfig, B as ByteSize, C as CliOptions, d as PartMetadata, F as FileEntry, T as TextEncoding, e as SecretFinding, V as ValidationResult, f as Manifest, A as ArtifactSelection } from './types-
|
|
2
|
-
export { g as BudgetConfig, H as HooksConfig, I as InclusionMode, h as IncompleteFile, i as ManifestArtifact, j as ManifestConfigSnapshot, k as ManifestIndexes, l as ManifestTotals, m as Mode, O as OutputFormat, n as OwnerBrief, o as PartFileEntry, P as PromptTask, p as ResolvedArtifacts, q as ResolvedBudgets, r as SecretRuleInput, s as SkipReason, t as SummaryQuality, u as TruncationReason, v as ValidationDrift } from './types-
|
|
1
|
+
import { S as SecretRule, D as DiscoveryMode, a as SkipRecord, J as JsonSummary, M as MarkdownSummary, b as SourceSummary, K as KindRule, L as LayerRule, R as ResolvedSnapshotConfig, c as SnapshotConfig, B as ByteSize, C as CliOptions, d as PartMetadata, F as FileEntry, T as TextEncoding, e as SecretFinding, V as ValidationResult, f as Manifest, A as ArtifactSelection } from './types-Cr5H2Y3t.cjs';
|
|
2
|
+
export { g as BudgetConfig, H as HooksConfig, I as InclusionMode, h as IncompleteFile, i as ManifestArtifact, j as ManifestConfigSnapshot, k as ManifestIndexes, l as ManifestTotals, m as Mode, O as OutputFormat, n as OwnerBrief, o as PartFileEntry, P as PromptTask, p as ResolvedArtifacts, q as ResolvedBudgets, r as SecretRuleInput, s as SkipReason, t as SummaryQuality, u as TruncationReason, v as ValidationDrift } from './types-Cr5H2Y3t.cjs';
|
|
3
3
|
export { w as workerEntry } from './generate-worker-B79yGkQO.cjs';
|
|
4
4
|
|
|
5
5
|
interface GitInfo {
|
|
@@ -548,7 +548,7 @@ declare function validateSnapshot(configInput: ResolvedSnapshotConfig | Snapshot
|
|
|
548
548
|
* `package.json` carries the same version; `npm run verify` compares the two.
|
|
549
549
|
*/
|
|
550
550
|
declare const GENERATOR_NAME = "codebase-snapshot";
|
|
551
|
-
declare const GENERATOR_VERSION = "0.
|
|
551
|
+
declare const GENERATOR_VERSION = "0.16.0";
|
|
552
552
|
/**
|
|
553
553
|
* The manifest and ownership-marker schema this build writes and understands.
|
|
554
554
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as SecretRule, D as DiscoveryMode, a as SkipRecord, J as JsonSummary, M as MarkdownSummary, b as SourceSummary, K as KindRule, L as LayerRule, R as ResolvedSnapshotConfig, c as SnapshotConfig, B as ByteSize, C as CliOptions, d as PartMetadata, F as FileEntry, T as TextEncoding, e as SecretFinding, V as ValidationResult, f as Manifest, A as ArtifactSelection } from './types-
|
|
2
|
-
export { g as BudgetConfig, H as HooksConfig, I as InclusionMode, h as IncompleteFile, i as ManifestArtifact, j as ManifestConfigSnapshot, k as ManifestIndexes, l as ManifestTotals, m as Mode, O as OutputFormat, n as OwnerBrief, o as PartFileEntry, P as PromptTask, p as ResolvedArtifacts, q as ResolvedBudgets, r as SecretRuleInput, s as SkipReason, t as SummaryQuality, u as TruncationReason, v as ValidationDrift } from './types-
|
|
1
|
+
import { S as SecretRule, D as DiscoveryMode, a as SkipRecord, J as JsonSummary, M as MarkdownSummary, b as SourceSummary, K as KindRule, L as LayerRule, R as ResolvedSnapshotConfig, c as SnapshotConfig, B as ByteSize, C as CliOptions, d as PartMetadata, F as FileEntry, T as TextEncoding, e as SecretFinding, V as ValidationResult, f as Manifest, A as ArtifactSelection } from './types-Cr5H2Y3t.js';
|
|
2
|
+
export { g as BudgetConfig, H as HooksConfig, I as InclusionMode, h as IncompleteFile, i as ManifestArtifact, j as ManifestConfigSnapshot, k as ManifestIndexes, l as ManifestTotals, m as Mode, O as OutputFormat, n as OwnerBrief, o as PartFileEntry, P as PromptTask, p as ResolvedArtifacts, q as ResolvedBudgets, r as SecretRuleInput, s as SkipReason, t as SummaryQuality, u as TruncationReason, v as ValidationDrift } from './types-Cr5H2Y3t.js';
|
|
3
3
|
export { w as workerEntry } from './generate-worker-B79yGkQO.js';
|
|
4
4
|
|
|
5
5
|
interface GitInfo {
|
|
@@ -548,7 +548,7 @@ declare function validateSnapshot(configInput: ResolvedSnapshotConfig | Snapshot
|
|
|
548
548
|
* `package.json` carries the same version; `npm run verify` compares the two.
|
|
549
549
|
*/
|
|
550
550
|
declare const GENERATOR_NAME = "codebase-snapshot";
|
|
551
|
-
declare const GENERATOR_VERSION = "0.
|
|
551
|
+
declare const GENERATOR_VERSION = "0.16.0";
|
|
552
552
|
/**
|
|
553
553
|
* The manifest and ownership-marker schema this build writes and understands.
|
|
554
554
|
*
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ARTIFACT_NAMES, CHECK_INTERVAL_MS, CONFIG_KEYS, DEFAULT_ANSWERS, DEFAULT_SECRET_PATTERNS, FAILURE_INTERVAL_MS, GENERATOR_NAME, GENERATOR_VERSION, HOOK_MARKER, LANGUAGE_PROFILES, MIN_MAX_PART_BYTES, MIN_MAX_PART_TOKENS, PACKAGE_LATEST_URL, PRESETS, PromptBack, PromptCancelled, REQUEST_TIMEOUT_MS, SCHEMA_VERSION, UP_TO_DATE_INTERVAL_MS, anchorForPath, appendGitignoreEntries, assertPublicHost, assertReplaceable, assertUsableConfigInput, buildImportResolver, bytesForTokens, cacheDirectory, cacheFilePath, checkForUpdate, classifyKind, classifyLayer, cloneRepository, collectFiles, compareManifests, configDigest, countInvalidUtf8Bytes, countLines, crc32, decodeText, defineConfig, detectLanguage, detectPreset, displayPath, displayWidth, enforceBudget, estimateTokens, explainPath, fenceForContent, fenceForText, fetchLatestVersion, findSecretInPath, firstRunMessage, formatTokens, formatUpdateNotice, generateProjectTree, generateSarifReport, generateSnapshot, generateSnapshotAsync, getGitInfo, getPreset, gitignorePath, globToRegExp, hasPriorSnapshot, importsChangedFile, importsOfFile, importsOfText, installKind, installPreCommitHook, isBinaryBuffer, isBinaryExtension, isBinaryFile, isEffectivelyEmpty, isInteractive, isNewer, isPrivateHost, isResolvedConfig, isSensitivePath, isSkeletonizable, isTsxFileName, listPresetNames, loadConfigFile, loadConfigFileDetailed, loadManifest, lockPathFor, makeCloneDirectory, markResolvedConfig, matchRule, matchesExclude, normalizeResolvedConfig, parseByteSize, parseRemoteSource, partitionFiles, planFirstRun, profileForPath, renderConfig, renderDiffText, renderExplainText, renumberParts, resolveChangedScope, resolveConfig, resolveSafeOutputDirs, resolveSpecifier, runInit, scanAndRedactSecrets, shouldCheck, skeletonizeTypeScript, startWebServer, stripJsonComments, summarizeJson, summarizeMarkdown, summarizeTypeScriptSource, summarizeWithProfile, supportsTypeScriptImports, treeTruncationWarnings, truncatePreview, truncateToBytes, tsconfigPathsFor, updateCommand, validateSnapshot, walkFiles, workerEntry, wrapLines, writeZip } from './chunk-
|
|
1
|
+
export { ARTIFACT_NAMES, CHECK_INTERVAL_MS, CONFIG_KEYS, DEFAULT_ANSWERS, DEFAULT_SECRET_PATTERNS, FAILURE_INTERVAL_MS, GENERATOR_NAME, GENERATOR_VERSION, HOOK_MARKER, LANGUAGE_PROFILES, MIN_MAX_PART_BYTES, MIN_MAX_PART_TOKENS, PACKAGE_LATEST_URL, PRESETS, PromptBack, PromptCancelled, REQUEST_TIMEOUT_MS, SCHEMA_VERSION, UP_TO_DATE_INTERVAL_MS, anchorForPath, appendGitignoreEntries, assertPublicHost, assertReplaceable, assertUsableConfigInput, buildImportResolver, bytesForTokens, cacheDirectory, cacheFilePath, checkForUpdate, classifyKind, classifyLayer, cloneRepository, collectFiles, compareManifests, configDigest, countInvalidUtf8Bytes, countLines, crc32, decodeText, defineConfig, detectLanguage, detectPreset, displayPath, displayWidth, enforceBudget, estimateTokens, explainPath, fenceForContent, fenceForText, fetchLatestVersion, findSecretInPath, firstRunMessage, formatTokens, formatUpdateNotice, generateProjectTree, generateSarifReport, generateSnapshot, generateSnapshotAsync, getGitInfo, getPreset, gitignorePath, globToRegExp, hasPriorSnapshot, importsChangedFile, importsOfFile, importsOfText, installKind, installPreCommitHook, isBinaryBuffer, isBinaryExtension, isBinaryFile, isEffectivelyEmpty, isInteractive, isNewer, isPrivateHost, isResolvedConfig, isSensitivePath, isSkeletonizable, isTsxFileName, listPresetNames, loadConfigFile, loadConfigFileDetailed, loadManifest, lockPathFor, makeCloneDirectory, markResolvedConfig, matchRule, matchesExclude, normalizeResolvedConfig, parseByteSize, parseRemoteSource, partitionFiles, planFirstRun, profileForPath, renderConfig, renderDiffText, renderExplainText, renumberParts, resolveChangedScope, resolveConfig, resolveSafeOutputDirs, resolveSpecifier, runInit, scanAndRedactSecrets, shouldCheck, skeletonizeTypeScript, startWebServer, stripJsonComments, summarizeJson, summarizeMarkdown, summarizeTypeScriptSource, summarizeWithProfile, supportsTypeScriptImports, treeTruncationWarnings, truncatePreview, truncateToBytes, tsconfigPathsFor, updateCommand, validateSnapshot, walkFiles, workerEntry, wrapLines, writeZip } from './chunk-AEGJYOCF.js';
|