codebase-snapshot 0.15.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 +89 -0
- package/README.md +3 -3
- package/SECURITY.md +2 -2
- package/dist/bin.js +258 -3
- package/dist/{chunk-KHHUC6UT.js → chunk-AEGJYOCF.js} +249 -3
- package/dist/{chunk-4OHQULCV.js → chunk-ZDTAWUD4.js} +1 -1
- package/dist/cli.cjs +258 -3
- package/dist/cli.d.cts +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +12 -3
- package/dist/index.cjs +249 -3
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +171 -2
- package/dist/mcp.d.cts +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +2 -2
- package/dist/{types-5G2Q6tWP.d.cts → types-Cr5H2Y3t.d.cts} +9 -0
- package/dist/{types-5G2Q6tWP.d.ts → types-Cr5H2Y3t.d.ts} +9 -0
- package/docs/cli.md +4 -4
- package/docs/deploy.md +2 -2
- package/docs/mcp.md +7 -5
- package/docs/slice.md +8 -0
- package/docs/tools.md +13 -1
- 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) {
|
|
@@ -6970,6 +6970,51 @@ function generateNavigation(manifest) {
|
|
|
6970
6970
|
return lines.join("\n");
|
|
6971
6971
|
}
|
|
6972
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
|
+
|
|
6973
7018
|
// src/mcp/retrieval.ts
|
|
6974
7019
|
var STOPWORDS = /* @__PURE__ */ new Set([
|
|
6975
7020
|
"the",
|
|
@@ -9489,6 +9534,7 @@ function validateSnapshot(configInput) {
|
|
|
9489
9534
|
["reports/diff.md", manifest.artifacts?.diff],
|
|
9490
9535
|
["reports/log.md", manifest.artifacts?.log],
|
|
9491
9536
|
["reports/tokens.md", manifest.artifacts?.tokenTree],
|
|
9537
|
+
["reports/selection.md", manifest.artifacts?.selection],
|
|
9492
9538
|
["full-codebase.json", manifest.artifacts?.fullJson],
|
|
9493
9539
|
["full-codebase.md", manifest.artifacts?.fullMarkdown],
|
|
9494
9540
|
["full-codebase.xml", manifest.artifacts?.fullXml]
|
|
@@ -10099,6 +10145,7 @@ var ARTIFACT_FILES = {
|
|
|
10099
10145
|
diff: "reports/diff.md",
|
|
10100
10146
|
log: "reports/log.md",
|
|
10101
10147
|
tokenTree: "reports/tokens.md",
|
|
10148
|
+
selection: "reports/selection.md",
|
|
10102
10149
|
fullJson: "full-codebase.json",
|
|
10103
10150
|
fullMarkdown: "full-codebase.md",
|
|
10104
10151
|
fullXml: "full-codebase.xml",
|
|
@@ -11540,6 +11587,65 @@ var historyTool = {
|
|
|
11540
11587
|
};
|
|
11541
11588
|
}
|
|
11542
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
|
+
};
|
|
11543
11649
|
var testsTool = {
|
|
11544
11650
|
name: "snapshot_tests",
|
|
11545
11651
|
title: "Tests that cover a file, and files a test covers",
|
|
@@ -12566,6 +12672,110 @@ var planForTool = {
|
|
|
12566
12672
|
return { text: lines.join("\n"), structured: plan };
|
|
12567
12673
|
}
|
|
12568
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
|
+
};
|
|
12569
12779
|
var healthTool = {
|
|
12570
12780
|
name: "snapshot_health",
|
|
12571
12781
|
title: "Snapshot health audit",
|
|
@@ -13416,6 +13626,7 @@ var explainTool = {
|
|
|
13416
13626
|
var TOOL_COSTS = {
|
|
13417
13627
|
snapshot_status: "cheap",
|
|
13418
13628
|
snapshot_health: "expensive",
|
|
13629
|
+
snapshot_budget: "medium",
|
|
13419
13630
|
snapshot_history: "cheap",
|
|
13420
13631
|
snapshot_tests: "cheap",
|
|
13421
13632
|
snapshot_workspace: "cheap",
|
|
@@ -13431,6 +13642,7 @@ var TOOL_COSTS = {
|
|
|
13431
13642
|
snapshot_context: "medium",
|
|
13432
13643
|
snapshot_query: "cheap",
|
|
13433
13644
|
snapshot_plan_for: "cheap",
|
|
13645
|
+
snapshot_answer: "medium",
|
|
13434
13646
|
snapshot_plan: "expensive",
|
|
13435
13647
|
snapshot_generate: "expensive",
|
|
13436
13648
|
snapshot_validate: "medium",
|
|
@@ -13443,6 +13655,7 @@ function buildTools() {
|
|
|
13443
13655
|
return [
|
|
13444
13656
|
statusTool,
|
|
13445
13657
|
healthTool,
|
|
13658
|
+
budgetTool,
|
|
13446
13659
|
historyTool,
|
|
13447
13660
|
testsTool,
|
|
13448
13661
|
workspaceTool,
|
|
@@ -13458,6 +13671,7 @@ function buildTools() {
|
|
|
13458
13671
|
contextTool,
|
|
13459
13672
|
queryTool,
|
|
13460
13673
|
planForTool,
|
|
13674
|
+
answerTool,
|
|
13461
13675
|
planTool,
|
|
13462
13676
|
generateTool,
|
|
13463
13677
|
validateTool,
|
|
@@ -14781,7 +14995,7 @@ diff, and the commit, are then yours.
|
|
|
14781
14995
|
## When the client speaks MCP
|
|
14782
14996
|
|
|
14783
14997
|
If the agent runs inside an MCP client, \`npx ${PACKAGE_NAME2}@latest mcp\` serves this repository
|
|
14784
|
-
as
|
|
14998
|
+
as 26 tools over stdio instead of shelling out. Its reads come from the snapshot rather than
|
|
14785
14999
|
the working tree, so excluded files and redacted values never reach the context. Use
|
|
14786
15000
|
\`snapshot_locate\` before \`snapshot_read\`, and \`snapshot_validate\` before trusting a snapshot
|
|
14787
15001
|
from an earlier session.
|
|
@@ -19497,6 +19711,7 @@ function generateSnapshot(configInput, options) {
|
|
|
19497
19711
|
}
|
|
19498
19712
|
}
|
|
19499
19713
|
let sliceBlock;
|
|
19714
|
+
let selectionReport = null;
|
|
19500
19715
|
if (options?.slice !== void 0) {
|
|
19501
19716
|
const byFile = files.filter((file) => isSourceSummary(file.summary)).map((file) => ({
|
|
19502
19717
|
path: file.relativePath,
|
|
@@ -19520,6 +19735,11 @@ function generateSnapshot(configInput, options) {
|
|
|
19520
19735
|
files: plan.files.map((file) => file.path),
|
|
19521
19736
|
dropped: scanned - plan.files.length
|
|
19522
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
|
+
};
|
|
19523
19743
|
}
|
|
19524
19744
|
let budgetBlock;
|
|
19525
19745
|
if (options?.budgetTokens !== void 0) {
|
|
@@ -19545,12 +19765,26 @@ function generateSnapshot(configInput, options) {
|
|
|
19545
19765
|
const keep = /* @__PURE__ */ new Set();
|
|
19546
19766
|
let used = 0;
|
|
19547
19767
|
const selected = [];
|
|
19768
|
+
const chosen = [];
|
|
19548
19769
|
for (const item of ranked) {
|
|
19549
19770
|
if (used + item.tokens > budget) continue;
|
|
19550
19771
|
keep.add(item.file.relativePath);
|
|
19551
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
|
+
});
|
|
19552
19778
|
used += item.tokens;
|
|
19553
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
|
+
}
|
|
19554
19788
|
const scanned = files.length;
|
|
19555
19789
|
const byLayer = {};
|
|
19556
19790
|
let entryKept = 0;
|
|
@@ -19579,7 +19813,14 @@ function generateSnapshot(configInput, options) {
|
|
|
19579
19813
|
usedTokens: used,
|
|
19580
19814
|
files: selected,
|
|
19581
19815
|
dropped: scanned - selected.length,
|
|
19582
|
-
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
|
|
19583
19824
|
};
|
|
19584
19825
|
if (entryTotal > 0 && entryKept < entryTotal) {
|
|
19585
19826
|
warnings.push(
|
|
@@ -19888,6 +20129,8 @@ function generateSnapshot(configInput, options) {
|
|
|
19888
20129
|
}) : null;
|
|
19889
20130
|
if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
|
|
19890
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);
|
|
19891
20134
|
let monolithJson = null;
|
|
19892
20135
|
let monolithMarkdown = null;
|
|
19893
20136
|
let monolithXml = null;
|
|
@@ -20044,6 +20287,9 @@ function generateSnapshot(configInput, options) {
|
|
|
20044
20287
|
if (tokenTree !== null) {
|
|
20045
20288
|
writeArtifact(reportsDir, "tokens.md", tokenTree.text);
|
|
20046
20289
|
}
|
|
20290
|
+
if (selectionText !== null) {
|
|
20291
|
+
writeArtifact(reportsDir, "selection.md", selectionText);
|
|
20292
|
+
}
|
|
20047
20293
|
if (sarifText !== null) {
|
|
20048
20294
|
writeArtifact(reportsDir, "audit.sarif", sarifText);
|
|
20049
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';
|
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) {
|
|
@@ -7625,6 +7625,7 @@ function validateSnapshot(configInput) {
|
|
|
7625
7625
|
["reports/diff.md", manifest.artifacts?.diff],
|
|
7626
7626
|
["reports/log.md", manifest.artifacts?.log],
|
|
7627
7627
|
["reports/tokens.md", manifest.artifacts?.tokenTree],
|
|
7628
|
+
["reports/selection.md", manifest.artifacts?.selection],
|
|
7628
7629
|
["full-codebase.json", manifest.artifacts?.fullJson],
|
|
7629
7630
|
["full-codebase.md", manifest.artifacts?.fullMarkdown],
|
|
7630
7631
|
["full-codebase.xml", manifest.artifacts?.fullXml]
|
|
@@ -8133,6 +8134,7 @@ var ARTIFACT_FILES = {
|
|
|
8133
8134
|
diff: "reports/diff.md",
|
|
8134
8135
|
log: "reports/log.md",
|
|
8135
8136
|
tokenTree: "reports/tokens.md",
|
|
8137
|
+
selection: "reports/selection.md",
|
|
8136
8138
|
fullJson: "full-codebase.json",
|
|
8137
8139
|
fullMarkdown: "full-codebase.md",
|
|
8138
8140
|
fullXml: "full-codebase.xml",
|
|
@@ -9574,6 +9576,65 @@ var historyTool = {
|
|
|
9574
9576
|
};
|
|
9575
9577
|
}
|
|
9576
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
|
+
};
|
|
9577
9638
|
var testsTool = {
|
|
9578
9639
|
name: "snapshot_tests",
|
|
9579
9640
|
title: "Tests that cover a file, and files a test covers",
|
|
@@ -10600,6 +10661,110 @@ var planForTool = {
|
|
|
10600
10661
|
return { text: lines.join("\n"), structured: plan };
|
|
10601
10662
|
}
|
|
10602
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
|
+
};
|
|
10603
10768
|
var healthTool = {
|
|
10604
10769
|
name: "snapshot_health",
|
|
10605
10770
|
title: "Snapshot health audit",
|
|
@@ -11450,6 +11615,7 @@ var explainTool = {
|
|
|
11450
11615
|
var TOOL_COSTS = {
|
|
11451
11616
|
snapshot_status: "cheap",
|
|
11452
11617
|
snapshot_health: "expensive",
|
|
11618
|
+
snapshot_budget: "medium",
|
|
11453
11619
|
snapshot_history: "cheap",
|
|
11454
11620
|
snapshot_tests: "cheap",
|
|
11455
11621
|
snapshot_workspace: "cheap",
|
|
@@ -11465,6 +11631,7 @@ var TOOL_COSTS = {
|
|
|
11465
11631
|
snapshot_context: "medium",
|
|
11466
11632
|
snapshot_query: "cheap",
|
|
11467
11633
|
snapshot_plan_for: "cheap",
|
|
11634
|
+
snapshot_answer: "medium",
|
|
11468
11635
|
snapshot_plan: "expensive",
|
|
11469
11636
|
snapshot_generate: "expensive",
|
|
11470
11637
|
snapshot_validate: "medium",
|
|
@@ -11477,6 +11644,7 @@ function buildTools() {
|
|
|
11477
11644
|
return [
|
|
11478
11645
|
statusTool,
|
|
11479
11646
|
healthTool,
|
|
11647
|
+
budgetTool,
|
|
11480
11648
|
historyTool,
|
|
11481
11649
|
testsTool,
|
|
11482
11650
|
workspaceTool,
|
|
@@ -11492,6 +11660,7 @@ function buildTools() {
|
|
|
11492
11660
|
contextTool,
|
|
11493
11661
|
queryTool,
|
|
11494
11662
|
planForTool,
|
|
11663
|
+
answerTool,
|
|
11495
11664
|
planTool,
|
|
11496
11665
|
generateTool,
|
|
11497
11666
|
validateTool,
|
|
@@ -12784,7 +12953,7 @@ diff, and the commit, are then yours.
|
|
|
12784
12953
|
## When the client speaks MCP
|
|
12785
12954
|
|
|
12786
12955
|
If the agent runs inside an MCP client, \`npx ${PACKAGE_NAME2}@latest mcp\` serves this repository
|
|
12787
|
-
as
|
|
12956
|
+
as 26 tools over stdio instead of shelling out. Its reads come from the snapshot rather than
|
|
12788
12957
|
the working tree, so excluded files and redacted values never reach the context. Use
|
|
12789
12958
|
\`snapshot_locate\` before \`snapshot_read\`, and \`snapshot_validate\` before trusting a snapshot
|
|
12790
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 {
|