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
|
@@ -3994,7 +3994,7 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
3994
3994
|
|
|
3995
3995
|
// src/version.ts
|
|
3996
3996
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
3997
|
-
var GENERATOR_VERSION = "0.
|
|
3997
|
+
var GENERATOR_VERSION = "0.16.0";
|
|
3998
3998
|
var SCHEMA_VERSION = "3.0.0";
|
|
3999
3999
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
4000
4000
|
function isOurGeneratorName(name) {
|
|
@@ -5888,7 +5888,12 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
5888
5888
|
logCount: resolveLogCount(
|
|
5889
5889
|
cliOptions?.logCount ?? cliOptions?.includeLogs ?? userConfig?.logCount
|
|
5890
5890
|
),
|
|
5891
|
-
|
|
5891
|
+
// `--only` replaces the allow-list for this run; `--ignore` adds to the deny-list. The two
|
|
5892
|
+
// directions are different on purpose: a narrower allow-list is a statement about the whole
|
|
5893
|
+
// run, while "also ignore this" is naturally cumulative with what the config already excludes.
|
|
5894
|
+
include: resolveInclude(
|
|
5895
|
+
cliOptions?.only ?? userConfig?.include
|
|
5896
|
+
),
|
|
5892
5897
|
preset: preset.presetName,
|
|
5893
5898
|
presetExclude,
|
|
5894
5899
|
artifacts,
|
|
@@ -5899,9 +5904,12 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
5899
5904
|
kinds,
|
|
5900
5905
|
// `exclude` is the flag spelling of the same setting; writing it in a config used to
|
|
5901
5906
|
// be ignored without a word.
|
|
5902
|
-
excludePatterns:
|
|
5903
|
-
|
|
5904
|
-
|
|
5907
|
+
excludePatterns: [
|
|
5908
|
+
...resolveExcludePatterns(
|
|
5909
|
+
userConfig?.excludePatterns ?? userConfig?.exclude
|
|
5910
|
+
),
|
|
5911
|
+
...resolveExcludePatterns(cliOptions?.ignore)
|
|
5912
|
+
],
|
|
5905
5913
|
secretRules,
|
|
5906
5914
|
// Extra property rather than a `ResolvedSnapshotConfig` field: the resolved
|
|
5907
5915
|
// shape is owned elsewhere, and every scan reads it through the registry in
|
|
@@ -6966,6 +6974,51 @@ function generateNavigation(manifest) {
|
|
|
6966
6974
|
return lines.join("\n");
|
|
6967
6975
|
}
|
|
6968
6976
|
|
|
6977
|
+
// src/generator/selection.ts
|
|
6978
|
+
function generateSelectionReport(manifest, selection) {
|
|
6979
|
+
const lines = [];
|
|
6980
|
+
lines.push("# Selection");
|
|
6981
|
+
lines.push("");
|
|
6982
|
+
lines.push("**Kind:** `" + selection.kind + "` ");
|
|
6983
|
+
for (const detailLine of selection.detail.split("\n")) {
|
|
6984
|
+
lines.push("**" + detailLine.slice(0, detailLine.indexOf(":")) + ":**" + detailLine.slice(detailLine.indexOf(":") + 1) + " ");
|
|
6985
|
+
}
|
|
6986
|
+
lines.push("**Selected files:** " + selection.files.length + " ");
|
|
6987
|
+
const spent = manifest.budget?.usedTokens ?? manifest.slice?.usedTokens ?? 0;
|
|
6988
|
+
lines.push("**Tokens spent:** " + spent.toLocaleString("en-US"));
|
|
6989
|
+
lines.push("");
|
|
6990
|
+
lines.push("## Why each file is here");
|
|
6991
|
+
lines.push("");
|
|
6992
|
+
lines.push("| File | Tokens | Reason |");
|
|
6993
|
+
lines.push("| :-- | --: | :-- |");
|
|
6994
|
+
for (const file of selection.files) {
|
|
6995
|
+
lines.push("| `" + file.path + "` | " + file.tokens.toLocaleString("en-US") + " | " + file.why + " |");
|
|
6996
|
+
}
|
|
6997
|
+
lines.push("");
|
|
6998
|
+
const dropped = selection.kind === "slice" ? manifest.slice?.dropped : manifest.budget?.dropped;
|
|
6999
|
+
if (typeof dropped === "number") {
|
|
7000
|
+
lines.push("## What was left out");
|
|
7001
|
+
lines.push("");
|
|
7002
|
+
lines.push(dropped + " file(s) were not selected. They are recorded in `manifest.json` as `skipped`");
|
|
7003
|
+
lines.push("with the reason `not-selected`, so nothing left the snapshot without a reason.");
|
|
7004
|
+
lines.push("");
|
|
7005
|
+
}
|
|
7006
|
+
const next = manifest.budget?.nextInLine ?? [];
|
|
7007
|
+
if (next.length > 0) {
|
|
7008
|
+
lines.push("## What a larger budget would buy");
|
|
7009
|
+
lines.push("");
|
|
7010
|
+
lines.push("Headroom: " + (manifest.budget?.headroomTokens ?? 0).toLocaleString("en-US") + " tokens.");
|
|
7011
|
+
lines.push("");
|
|
7012
|
+
lines.push("| File | Tokens |");
|
|
7013
|
+
lines.push("| :-- | --: |");
|
|
7014
|
+
for (const item of next) {
|
|
7015
|
+
lines.push("| `" + item.path + "` | " + item.tokens.toLocaleString("en-US") + " |");
|
|
7016
|
+
}
|
|
7017
|
+
lines.push("");
|
|
7018
|
+
}
|
|
7019
|
+
return lines.join("\n");
|
|
7020
|
+
}
|
|
7021
|
+
|
|
6969
7022
|
// src/mcp/retrieval.ts
|
|
6970
7023
|
var STOPWORDS = /* @__PURE__ */ new Set([
|
|
6971
7024
|
"the",
|
|
@@ -9485,6 +9538,7 @@ function validateSnapshot(configInput) {
|
|
|
9485
9538
|
["reports/diff.md", manifest.artifacts?.diff],
|
|
9486
9539
|
["reports/log.md", manifest.artifacts?.log],
|
|
9487
9540
|
["reports/tokens.md", manifest.artifacts?.tokenTree],
|
|
9541
|
+
["reports/selection.md", manifest.artifacts?.selection],
|
|
9488
9542
|
["full-codebase.json", manifest.artifacts?.fullJson],
|
|
9489
9543
|
["full-codebase.md", manifest.artifacts?.fullMarkdown],
|
|
9490
9544
|
["full-codebase.xml", manifest.artifacts?.fullXml]
|
|
@@ -10135,6 +10189,7 @@ var ARTIFACT_FILES = {
|
|
|
10135
10189
|
diff: "reports/diff.md",
|
|
10136
10190
|
log: "reports/log.md",
|
|
10137
10191
|
tokenTree: "reports/tokens.md",
|
|
10192
|
+
selection: "reports/selection.md",
|
|
10138
10193
|
fullJson: "full-codebase.json",
|
|
10139
10194
|
fullMarkdown: "full-codebase.md",
|
|
10140
10195
|
fullXml: "full-codebase.xml",
|
|
@@ -11576,6 +11631,65 @@ var historyTool = {
|
|
|
11576
11631
|
};
|
|
11577
11632
|
}
|
|
11578
11633
|
};
|
|
11634
|
+
var budgetTool = {
|
|
11635
|
+
name: "snapshot_budget",
|
|
11636
|
+
title: "What a larger budget would buy",
|
|
11637
|
+
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.',
|
|
11638
|
+
inputSchema: {
|
|
11639
|
+
type: "object",
|
|
11640
|
+
properties: {
|
|
11641
|
+
budgets: {
|
|
11642
|
+
type: "array",
|
|
11643
|
+
items: { type: "integer", minimum: 500 },
|
|
11644
|
+
description: "Token budgets to compare, ascending (default 10000, 30000, 60000)."
|
|
11645
|
+
},
|
|
11646
|
+
question: { type: "string", description: "Optional question to plan for; absent plans for the repository as a whole." },
|
|
11647
|
+
includeTests: { type: "boolean", description: "Include test files (default false)." },
|
|
11648
|
+
root: ROOT_PROPERTY,
|
|
11649
|
+
outDir: OUT_DIR_PROPERTY
|
|
11650
|
+
},
|
|
11651
|
+
additionalProperties: false
|
|
11652
|
+
},
|
|
11653
|
+
outputSchema: {
|
|
11654
|
+
type: "object",
|
|
11655
|
+
properties: { budgets: { type: "array", items: { type: "object" } } }
|
|
11656
|
+
},
|
|
11657
|
+
annotations: READ_ONLY,
|
|
11658
|
+
async handler(args, context) {
|
|
11659
|
+
const prepared = await prepare(args, context, outDirOverride(args));
|
|
11660
|
+
if (!prepared.ok) return prepared.outcome;
|
|
11661
|
+
const read = readManifest3(prepared.workspace);
|
|
11662
|
+
if (!read.ok) return { text: read.message + " Call snapshot_generate first.", isError: true };
|
|
11663
|
+
const requested = Array.isArray(args.budgets) ? args.budgets.filter((value) => typeof value === "number").map((value) => Math.max(500, value)) : [1e4, 3e4, 6e4];
|
|
11664
|
+
const budgets = [...new Set(requested)].sort((left, right) => left - right);
|
|
11665
|
+
if (budgets.length === 0) return { text: "budgets must hold at least one number", isError: true };
|
|
11666
|
+
const question = typeof args.question === "string" ? args.question : "";
|
|
11667
|
+
const rows = [];
|
|
11668
|
+
let previous = /* @__PURE__ */ new Set();
|
|
11669
|
+
for (const budget of budgets) {
|
|
11670
|
+
const plan = planForQuestion(read.manifest, question, {
|
|
11671
|
+
maxTokens: budget,
|
|
11672
|
+
...args.includeTests === true ? { includeTests: true } : {}
|
|
11673
|
+
});
|
|
11674
|
+
const paths = new Set(plan.files.map((file) => file.path));
|
|
11675
|
+
const gained = [...paths].filter((path26) => !previous.has(path26)).sort();
|
|
11676
|
+
previous = paths;
|
|
11677
|
+
rows.push({
|
|
11678
|
+
budget,
|
|
11679
|
+
files: plan.files.length,
|
|
11680
|
+
usedTokens: plan.usedTokens,
|
|
11681
|
+
gained
|
|
11682
|
+
});
|
|
11683
|
+
}
|
|
11684
|
+
const lines = [question === "" ? "No question: planning for the repository as a whole." : "Question: " + question];
|
|
11685
|
+
for (const row of rows) {
|
|
11686
|
+
lines.push(
|
|
11687
|
+
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" : "") + ")")
|
|
11688
|
+
);
|
|
11689
|
+
}
|
|
11690
|
+
return { text: lines.join("\n"), structured: { budgets: rows } };
|
|
11691
|
+
}
|
|
11692
|
+
};
|
|
11579
11693
|
var testsTool = {
|
|
11580
11694
|
name: "snapshot_tests",
|
|
11581
11695
|
title: "Tests that cover a file, and files a test covers",
|
|
@@ -12262,6 +12376,11 @@ var symbolTool = {
|
|
|
12262
12376
|
name: { type: "string", description: "Symbol name, case-insensitive." },
|
|
12263
12377
|
lines: { type: "integer", description: "Window size around the definition (default 40).", minimum: 5 },
|
|
12264
12378
|
maxFiles: { type: "integer", description: "Cap on files searched (default 5).", minimum: 1 },
|
|
12379
|
+
references: {
|
|
12380
|
+
type: "boolean",
|
|
12381
|
+
description: "Also report call sites: other files whose body mentions the name (default true)."
|
|
12382
|
+
},
|
|
12383
|
+
maxReferences: { type: "integer", description: "Cap on reported call sites (default 20).", minimum: 1 },
|
|
12265
12384
|
root: ROOT_PROPERTY,
|
|
12266
12385
|
outDir: OUT_DIR_PROPERTY
|
|
12267
12386
|
},
|
|
@@ -12272,7 +12391,8 @@ var symbolTool = {
|
|
|
12272
12391
|
type: "object",
|
|
12273
12392
|
properties: {
|
|
12274
12393
|
found: { type: "integer" },
|
|
12275
|
-
matches: { type: "array", items: { type: "object" } }
|
|
12394
|
+
matches: { type: "array", items: { type: "object" } },
|
|
12395
|
+
references: { type: "array", items: { type: "object" } }
|
|
12276
12396
|
}
|
|
12277
12397
|
},
|
|
12278
12398
|
annotations: READ_ONLY,
|
|
@@ -12325,8 +12445,44 @@ var symbolTool = {
|
|
|
12325
12445
|
structured: { found: 0, matches: [] }
|
|
12326
12446
|
};
|
|
12327
12447
|
}
|
|
12328
|
-
const
|
|
12329
|
-
|
|
12448
|
+
const callSites = [];
|
|
12449
|
+
if (args.references !== false) {
|
|
12450
|
+
const limit = Math.max(1, typeof args.maxReferences === "number" ? args.maxReferences : 20);
|
|
12451
|
+
const definitionKeys = new Set(matches.map((match) => match.path + ":" + match.line));
|
|
12452
|
+
const word = new RegExp("\\b" + name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "\\b");
|
|
12453
|
+
const parts = /* @__PURE__ */ new Map();
|
|
12454
|
+
let scanned = 0;
|
|
12455
|
+
for (const file of read.manifest.files) {
|
|
12456
|
+
if (callSites.length >= limit) break;
|
|
12457
|
+
const partPath = partPathFor(workspace, file.part);
|
|
12458
|
+
if (partPath === null) continue;
|
|
12459
|
+
let partText = parts.get(partPath);
|
|
12460
|
+
if (partText === void 0) {
|
|
12461
|
+
try {
|
|
12462
|
+
partText = fs24.readFileSync(partPath, "utf8");
|
|
12463
|
+
} catch {
|
|
12464
|
+
continue;
|
|
12465
|
+
}
|
|
12466
|
+
parts.set(partPath, partText);
|
|
12467
|
+
}
|
|
12468
|
+
if (scanned > MAX_SEARCH_BYTES) break;
|
|
12469
|
+
scanned += Buffer.byteLength(partText, "utf8");
|
|
12470
|
+
const section = findSection(parsePartSections(partText), file.relativePath);
|
|
12471
|
+
if (section === null) continue;
|
|
12472
|
+
const bodyLines = section.body.split("\n");
|
|
12473
|
+
for (let index = 0; index < bodyLines.length && callSites.length < limit; index += 1) {
|
|
12474
|
+
if (!word.test(bodyLines[index])) continue;
|
|
12475
|
+
callSites.push({
|
|
12476
|
+
path: file.relativePath,
|
|
12477
|
+
line: index + 1,
|
|
12478
|
+
text: bodyLines[index].trim().slice(0, 200),
|
|
12479
|
+
definition: definitionKeys.has(file.relativePath + ":" + (index + 1))
|
|
12480
|
+
});
|
|
12481
|
+
}
|
|
12482
|
+
}
|
|
12483
|
+
}
|
|
12484
|
+
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")));
|
|
12485
|
+
return { text: text2, structured: { found: matches.length, matches, references: callSites } };
|
|
12330
12486
|
}
|
|
12331
12487
|
};
|
|
12332
12488
|
var contextTool = {
|
|
@@ -12560,6 +12716,110 @@ var planForTool = {
|
|
|
12560
12716
|
return { text: lines.join("\n"), structured: plan };
|
|
12561
12717
|
}
|
|
12562
12718
|
};
|
|
12719
|
+
var answerTool = {
|
|
12720
|
+
name: "snapshot_answer",
|
|
12721
|
+
title: "Question in, budgeted context out",
|
|
12722
|
+
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.",
|
|
12723
|
+
inputSchema: {
|
|
12724
|
+
type: "object",
|
|
12725
|
+
properties: {
|
|
12726
|
+
question: { type: "string", description: "What you need to answer." },
|
|
12727
|
+
maxTokens: { type: "integer", description: "Budget for the whole block (default 20000).", minimum: 500 },
|
|
12728
|
+
linesPerFile: { type: "integer", description: "Head lines per file (default 60).", minimum: 10 },
|
|
12729
|
+
includeTests: { type: "boolean", description: "Include test files (default false)." },
|
|
12730
|
+
root: ROOT_PROPERTY,
|
|
12731
|
+
outDir: OUT_DIR_PROPERTY
|
|
12732
|
+
},
|
|
12733
|
+
required: ["question"],
|
|
12734
|
+
additionalProperties: false
|
|
12735
|
+
},
|
|
12736
|
+
outputSchema: {
|
|
12737
|
+
type: "object",
|
|
12738
|
+
properties: {
|
|
12739
|
+
question: { type: "string" },
|
|
12740
|
+
budgetTokens: { type: "integer" },
|
|
12741
|
+
usedTokens: { type: "integer" },
|
|
12742
|
+
files: { type: "array", items: { type: "object" } },
|
|
12743
|
+
omitted: { type: "array", items: { type: "object" } }
|
|
12744
|
+
}
|
|
12745
|
+
},
|
|
12746
|
+
annotations: READ_ONLY,
|
|
12747
|
+
async handler(args, context) {
|
|
12748
|
+
const question = typeof args.question === "string" ? args.question.trim() : "";
|
|
12749
|
+
if (question.length === 0) return { text: "question must be a non-empty string", isError: true };
|
|
12750
|
+
const prepared = await prepare(args, context, outDirOverride(args));
|
|
12751
|
+
if (!prepared.ok) return prepared.outcome;
|
|
12752
|
+
const read = readManifest3(prepared.workspace);
|
|
12753
|
+
if (!read.ok) return { text: read.message + " Call snapshot_generate first.", isError: true };
|
|
12754
|
+
const maxTokens = Math.max(500, typeof args.maxTokens === "number" ? args.maxTokens : 2e4);
|
|
12755
|
+
const linesPerFile = Math.max(10, typeof args.linesPerFile === "number" ? args.linesPerFile : 60);
|
|
12756
|
+
const plan = planForQuestion(read.manifest, question, {
|
|
12757
|
+
maxTokens,
|
|
12758
|
+
...args.includeTests === true ? { includeTests: true } : {}
|
|
12759
|
+
});
|
|
12760
|
+
const blocks = [];
|
|
12761
|
+
const omitted = [];
|
|
12762
|
+
let used = 0;
|
|
12763
|
+
const parts = /* @__PURE__ */ new Map();
|
|
12764
|
+
for (const planned of plan.files) {
|
|
12765
|
+
if (used >= maxTokens) {
|
|
12766
|
+
omitted.push({ path: planned.path, reason: "the budget was spent on earlier files" });
|
|
12767
|
+
continue;
|
|
12768
|
+
}
|
|
12769
|
+
const partPath = partPathFor(prepared.workspace, planned.part);
|
|
12770
|
+
if (partPath === null) {
|
|
12771
|
+
omitted.push({ path: planned.path, reason: "its part is not in the snapshot" });
|
|
12772
|
+
continue;
|
|
12773
|
+
}
|
|
12774
|
+
let partText = parts.get(partPath);
|
|
12775
|
+
if (partText === void 0) {
|
|
12776
|
+
try {
|
|
12777
|
+
partText = fs24.readFileSync(partPath, "utf8");
|
|
12778
|
+
} catch {
|
|
12779
|
+
omitted.push({ path: planned.path, reason: "its part could not be read" });
|
|
12780
|
+
continue;
|
|
12781
|
+
}
|
|
12782
|
+
parts.set(partPath, partText);
|
|
12783
|
+
}
|
|
12784
|
+
const section = findSection(parsePartSections(partText), planned.path);
|
|
12785
|
+
if (section === null) {
|
|
12786
|
+
omitted.push({ path: planned.path, reason: "no section in its part" });
|
|
12787
|
+
continue;
|
|
12788
|
+
}
|
|
12789
|
+
const window = windowText(section.body, 1, linesPerFile);
|
|
12790
|
+
const text2 = window.text;
|
|
12791
|
+
const tokens = estimateTokens(text2);
|
|
12792
|
+
if (used + tokens > maxTokens && blocks.length > 0) {
|
|
12793
|
+
omitted.push({ path: planned.path, reason: "did not fit the remaining budget" });
|
|
12794
|
+
continue;
|
|
12795
|
+
}
|
|
12796
|
+
const numbered = text2.split("\n").map((line, index) => String(index + 1).padStart(5, " ") + " " + line).join("\n");
|
|
12797
|
+
blocks.push({ path: planned.path, why: planned.why, tokens, text: numbered, truncated: window.truncated, totalLines: window.totalLines });
|
|
12798
|
+
used += tokens;
|
|
12799
|
+
}
|
|
12800
|
+
const lines = [
|
|
12801
|
+
"# Answer context: " + question,
|
|
12802
|
+
"Budget: " + used + " of " + maxTokens + " tokens; " + blocks.length + " file(s)."
|
|
12803
|
+
];
|
|
12804
|
+
for (const block of blocks) {
|
|
12805
|
+
lines.push("");
|
|
12806
|
+
lines.push("## " + block.path + " (" + block.tokens + " tokens, " + (block.truncated ? "first lines of " + block.totalLines : "whole file") + ")");
|
|
12807
|
+
lines.push("Why: " + block.why);
|
|
12808
|
+
lines.push("```");
|
|
12809
|
+
lines.push(block.text);
|
|
12810
|
+
lines.push("```");
|
|
12811
|
+
}
|
|
12812
|
+
if (omitted.length > 0) {
|
|
12813
|
+
lines.push("");
|
|
12814
|
+
lines.push("Not included:");
|
|
12815
|
+
for (const entry of omitted) lines.push("- " + entry.path + " - " + entry.reason);
|
|
12816
|
+
}
|
|
12817
|
+
return {
|
|
12818
|
+
text: lines.join("\n"),
|
|
12819
|
+
structured: { question, budgetTokens: maxTokens, usedTokens: used, files: blocks, omitted }
|
|
12820
|
+
};
|
|
12821
|
+
}
|
|
12822
|
+
};
|
|
12563
12823
|
var healthTool = {
|
|
12564
12824
|
name: "snapshot_health",
|
|
12565
12825
|
title: "Snapshot health audit",
|
|
@@ -13410,6 +13670,7 @@ var explainTool = {
|
|
|
13410
13670
|
var TOOL_COSTS = {
|
|
13411
13671
|
snapshot_status: "cheap",
|
|
13412
13672
|
snapshot_health: "expensive",
|
|
13673
|
+
snapshot_budget: "medium",
|
|
13413
13674
|
snapshot_history: "cheap",
|
|
13414
13675
|
snapshot_tests: "cheap",
|
|
13415
13676
|
snapshot_workspace: "cheap",
|
|
@@ -13425,6 +13686,7 @@ var TOOL_COSTS = {
|
|
|
13425
13686
|
snapshot_context: "medium",
|
|
13426
13687
|
snapshot_query: "cheap",
|
|
13427
13688
|
snapshot_plan_for: "cheap",
|
|
13689
|
+
snapshot_answer: "medium",
|
|
13428
13690
|
snapshot_plan: "expensive",
|
|
13429
13691
|
snapshot_generate: "expensive",
|
|
13430
13692
|
snapshot_validate: "medium",
|
|
@@ -13437,6 +13699,7 @@ function buildTools() {
|
|
|
13437
13699
|
return [
|
|
13438
13700
|
statusTool,
|
|
13439
13701
|
healthTool,
|
|
13702
|
+
budgetTool,
|
|
13440
13703
|
historyTool,
|
|
13441
13704
|
testsTool,
|
|
13442
13705
|
workspaceTool,
|
|
@@ -13452,6 +13715,7 @@ function buildTools() {
|
|
|
13452
13715
|
contextTool,
|
|
13453
13716
|
queryTool,
|
|
13454
13717
|
planForTool,
|
|
13718
|
+
answerTool,
|
|
13455
13719
|
planTool,
|
|
13456
13720
|
generateTool,
|
|
13457
13721
|
validateTool,
|
|
@@ -13630,6 +13894,8 @@ var VALIDATE_OPTIONS = [
|
|
|
13630
13894
|
"sarif",
|
|
13631
13895
|
"strip-comments",
|
|
13632
13896
|
"remove-empty-lines",
|
|
13897
|
+
"only",
|
|
13898
|
+
"ignore",
|
|
13633
13899
|
"pack",
|
|
13634
13900
|
// The opt-in reports change the artifact selection the manifest records, so validate must accept
|
|
13635
13901
|
// them to compare like with like: without the flags it reports the selection as drift.
|
|
@@ -13665,6 +13931,8 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
13665
13931
|
generate: [
|
|
13666
13932
|
"strip-comments",
|
|
13667
13933
|
"remove-empty-lines",
|
|
13934
|
+
"only",
|
|
13935
|
+
"ignore",
|
|
13668
13936
|
"workspace",
|
|
13669
13937
|
"budget-tokens",
|
|
13670
13938
|
"sign",
|
|
@@ -13745,6 +14013,10 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
13745
14013
|
// Removed rather than implemented, because a flag that parses and does nothing is the defect
|
|
13746
14014
|
// this table exists to prevent.
|
|
13747
14015
|
"large-file-bytes",
|
|
14016
|
+
// `--only` and `--ignore` change which files are scanned, so they change what `explain` can say
|
|
14017
|
+
// about a path; without them the answer for an ignored file is "included: true".
|
|
14018
|
+
"only",
|
|
14019
|
+
"ignore",
|
|
13748
14020
|
"include-sensitive-files",
|
|
13749
14021
|
"no-config",
|
|
13750
14022
|
"discovery",
|
|
@@ -14286,6 +14558,18 @@ function buildAgentContract() {
|
|
|
14286
14558
|
appliesTo: optionAppliesTo("allow-origin"),
|
|
14287
14559
|
summary: "mcp --http: comma-separated extra CORS origins. Loopback origins are always allowed."
|
|
14288
14560
|
},
|
|
14561
|
+
{
|
|
14562
|
+
flag: "--only",
|
|
14563
|
+
type: "string",
|
|
14564
|
+
summary: "Comma-separated globs to include: overrides the config include list for this run.",
|
|
14565
|
+
appliesTo: optionAppliesTo("only")
|
|
14566
|
+
},
|
|
14567
|
+
{
|
|
14568
|
+
flag: "--ignore",
|
|
14569
|
+
type: "string",
|
|
14570
|
+
summary: "Comma-separated globs to exclude, added to the config exclude list for this run.",
|
|
14571
|
+
appliesTo: optionAppliesTo("ignore")
|
|
14572
|
+
},
|
|
14289
14573
|
{
|
|
14290
14574
|
flag: "--remove-empty-lines",
|
|
14291
14575
|
type: "boolean",
|
|
@@ -14824,7 +15108,7 @@ diff, and the commit, are then yours.
|
|
|
14824
15108
|
## When the client speaks MCP
|
|
14825
15109
|
|
|
14826
15110
|
If the agent runs inside an MCP client, \`npx ${PACKAGE_NAME2}@latest mcp\` serves this repository
|
|
14827
|
-
as
|
|
15111
|
+
as 26 tools over stdio instead of shelling out. Its reads come from the snapshot rather than
|
|
14828
15112
|
the working tree, so excluded files and redacted values never reach the context. Use
|
|
14829
15113
|
\`snapshot_locate\` before \`snapshot_read\`, and \`snapshot_validate\` before trusting a snapshot
|
|
14830
15114
|
from an earlier session.
|
|
@@ -19729,6 +20013,7 @@ function generateSnapshot(configInput, options) {
|
|
|
19729
20013
|
}
|
|
19730
20014
|
}
|
|
19731
20015
|
let sliceBlock;
|
|
20016
|
+
let selectionReport = null;
|
|
19732
20017
|
if (options?.slice !== void 0) {
|
|
19733
20018
|
const byFile = files.filter((file) => isSourceSummary(file.summary)).map((file) => ({
|
|
19734
20019
|
path: file.relativePath,
|
|
@@ -19752,6 +20037,11 @@ function generateSnapshot(configInput, options) {
|
|
|
19752
20037
|
files: plan.files.map((file) => file.path),
|
|
19753
20038
|
dropped: scanned - plan.files.length
|
|
19754
20039
|
};
|
|
20040
|
+
selectionReport = {
|
|
20041
|
+
kind: "slice",
|
|
20042
|
+
detail: "Question: " + options.slice.question + "\nBudget: " + plan.budgetTokens.toLocaleString("en-US") + " tokens",
|
|
20043
|
+
files: plan.files.map((file) => ({ path: file.path, tokens: file.tokens, why: file.why }))
|
|
20044
|
+
};
|
|
19755
20045
|
}
|
|
19756
20046
|
let budgetBlock;
|
|
19757
20047
|
if (options?.budgetTokens !== void 0) {
|
|
@@ -19777,12 +20067,26 @@ function generateSnapshot(configInput, options) {
|
|
|
19777
20067
|
const keep = /* @__PURE__ */ new Set();
|
|
19778
20068
|
let used = 0;
|
|
19779
20069
|
const selected = [];
|
|
20070
|
+
const chosen = [];
|
|
19780
20071
|
for (const item of ranked) {
|
|
19781
20072
|
if (used + item.tokens > budget) continue;
|
|
19782
20073
|
keep.add(item.file.relativePath);
|
|
19783
20074
|
selected.push(item.file.relativePath);
|
|
20075
|
+
chosen.push({
|
|
20076
|
+
path: item.file.relativePath,
|
|
20077
|
+
tokens: item.tokens,
|
|
20078
|
+
why: (entry(item.file.relativePath) ? "entry point" : "not an entry point") + "; " + (importers.get(item.file.relativePath) ?? 0) + " importer(s); layer " + item.file.layer
|
|
20079
|
+
});
|
|
19784
20080
|
used += item.tokens;
|
|
19785
20081
|
}
|
|
20082
|
+
const nextInLine = [];
|
|
20083
|
+
let headroom = budget - used;
|
|
20084
|
+
for (const item of ranked) {
|
|
20085
|
+
if (keep.has(item.file.relativePath)) continue;
|
|
20086
|
+
if (nextInLine.length >= 10) break;
|
|
20087
|
+
nextInLine.push({ path: item.file.relativePath, tokens: item.tokens });
|
|
20088
|
+
headroom = Math.max(headroom, item.tokens);
|
|
20089
|
+
}
|
|
19786
20090
|
const scanned = files.length;
|
|
19787
20091
|
const byLayer = {};
|
|
19788
20092
|
let entryKept = 0;
|
|
@@ -19811,7 +20115,14 @@ function generateSnapshot(configInput, options) {
|
|
|
19811
20115
|
usedTokens: used,
|
|
19812
20116
|
files: selected,
|
|
19813
20117
|
dropped: scanned - selected.length,
|
|
19814
|
-
coverage: { byLayer, entryPoints: { kept: entryKept, total: entryTotal }, symbols: { kept: symbolsKept, total: symbolsTotal } }
|
|
20118
|
+
coverage: { byLayer, entryPoints: { kept: entryKept, total: entryTotal }, symbols: { kept: symbolsKept, total: symbolsTotal } },
|
|
20119
|
+
headroomTokens: Math.max(0, budget - used),
|
|
20120
|
+
nextInLine
|
|
20121
|
+
};
|
|
20122
|
+
selectionReport = {
|
|
20123
|
+
kind: "budget",
|
|
20124
|
+
detail: "Budget: " + budget.toLocaleString("en-US") + " tokens",
|
|
20125
|
+
files: chosen
|
|
19815
20126
|
};
|
|
19816
20127
|
if (entryTotal > 0 && entryKept < entryTotal) {
|
|
19817
20128
|
warnings.push(
|
|
@@ -20120,6 +20431,8 @@ function generateSnapshot(configInput, options) {
|
|
|
20120
20431
|
}) : null;
|
|
20121
20432
|
if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
|
|
20122
20433
|
if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
|
|
20434
|
+
const selectionText = selectionReport === null ? null : generateSelectionReport(manifest, selectionReport);
|
|
20435
|
+
if (selectionText !== null) manifest.artifacts.selection = artifactRecord(selectionText);
|
|
20123
20436
|
let monolithJson = null;
|
|
20124
20437
|
let monolithMarkdown = null;
|
|
20125
20438
|
let monolithXml = null;
|
|
@@ -20276,6 +20589,9 @@ function generateSnapshot(configInput, options) {
|
|
|
20276
20589
|
if (tokenTree !== null) {
|
|
20277
20590
|
writeArtifact(reportsDir, "tokens.md", tokenTree.text);
|
|
20278
20591
|
}
|
|
20592
|
+
if (selectionText !== null) {
|
|
20593
|
+
writeArtifact(reportsDir, "selection.md", selectionText);
|
|
20594
|
+
}
|
|
20279
20595
|
if (sarifText !== null) {
|
|
20280
20596
|
writeArtifact(reportsDir, "audit.sarif", sarifText);
|
|
20281
20597
|
}
|