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/bin.js
CHANGED
|
@@ -2191,7 +2191,7 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
2191
2191
|
|
|
2192
2192
|
// src/version.ts
|
|
2193
2193
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
2194
|
-
var GENERATOR_VERSION = "0.
|
|
2194
|
+
var GENERATOR_VERSION = "0.16.0";
|
|
2195
2195
|
var SCHEMA_VERSION = "3.0.0";
|
|
2196
2196
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2197
2197
|
function isOurGeneratorName(name) {
|
|
@@ -4352,7 +4352,12 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
4352
4352
|
logCount: resolveLogCount(
|
|
4353
4353
|
cliOptions?.logCount ?? cliOptions?.includeLogs ?? userConfig?.logCount
|
|
4354
4354
|
),
|
|
4355
|
-
|
|
4355
|
+
// `--only` replaces the allow-list for this run; `--ignore` adds to the deny-list. The two
|
|
4356
|
+
// directions are different on purpose: a narrower allow-list is a statement about the whole
|
|
4357
|
+
// run, while "also ignore this" is naturally cumulative with what the config already excludes.
|
|
4358
|
+
include: resolveInclude(
|
|
4359
|
+
cliOptions?.only ?? userConfig?.include
|
|
4360
|
+
),
|
|
4356
4361
|
preset: preset.presetName,
|
|
4357
4362
|
presetExclude,
|
|
4358
4363
|
artifacts,
|
|
@@ -4363,9 +4368,12 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
4363
4368
|
kinds,
|
|
4364
4369
|
// `exclude` is the flag spelling of the same setting; writing it in a config used to
|
|
4365
4370
|
// be ignored without a word.
|
|
4366
|
-
excludePatterns:
|
|
4367
|
-
|
|
4368
|
-
|
|
4371
|
+
excludePatterns: [
|
|
4372
|
+
...resolveExcludePatterns(
|
|
4373
|
+
userConfig?.excludePatterns ?? userConfig?.exclude
|
|
4374
|
+
),
|
|
4375
|
+
...resolveExcludePatterns(cliOptions?.ignore)
|
|
4376
|
+
],
|
|
4369
4377
|
secretRules,
|
|
4370
4378
|
// Extra property rather than a `ResolvedSnapshotConfig` field: the resolved
|
|
4371
4379
|
// shape is owned elsewhere, and every scan reads it through the registry in
|
|
@@ -7137,6 +7145,7 @@ function validateSnapshot(configInput) {
|
|
|
7137
7145
|
["reports/diff.md", manifest.artifacts?.diff],
|
|
7138
7146
|
["reports/log.md", manifest.artifacts?.log],
|
|
7139
7147
|
["reports/tokens.md", manifest.artifacts?.tokenTree],
|
|
7148
|
+
["reports/selection.md", manifest.artifacts?.selection],
|
|
7140
7149
|
["full-codebase.json", manifest.artifacts?.fullJson],
|
|
7141
7150
|
["full-codebase.md", manifest.artifacts?.fullMarkdown],
|
|
7142
7151
|
["full-codebase.xml", manifest.artifacts?.fullXml]
|
|
@@ -10195,6 +10204,51 @@ function generateNavigation(manifest) {
|
|
|
10195
10204
|
return lines.join("\n");
|
|
10196
10205
|
}
|
|
10197
10206
|
|
|
10207
|
+
// src/generator/selection.ts
|
|
10208
|
+
function generateSelectionReport(manifest, selection) {
|
|
10209
|
+
const lines = [];
|
|
10210
|
+
lines.push("# Selection");
|
|
10211
|
+
lines.push("");
|
|
10212
|
+
lines.push("**Kind:** `" + selection.kind + "` ");
|
|
10213
|
+
for (const detailLine of selection.detail.split("\n")) {
|
|
10214
|
+
lines.push("**" + detailLine.slice(0, detailLine.indexOf(":")) + ":**" + detailLine.slice(detailLine.indexOf(":") + 1) + " ");
|
|
10215
|
+
}
|
|
10216
|
+
lines.push("**Selected files:** " + selection.files.length + " ");
|
|
10217
|
+
const spent = manifest.budget?.usedTokens ?? manifest.slice?.usedTokens ?? 0;
|
|
10218
|
+
lines.push("**Tokens spent:** " + spent.toLocaleString("en-US"));
|
|
10219
|
+
lines.push("");
|
|
10220
|
+
lines.push("## Why each file is here");
|
|
10221
|
+
lines.push("");
|
|
10222
|
+
lines.push("| File | Tokens | Reason |");
|
|
10223
|
+
lines.push("| :-- | --: | :-- |");
|
|
10224
|
+
for (const file of selection.files) {
|
|
10225
|
+
lines.push("| `" + file.path + "` | " + file.tokens.toLocaleString("en-US") + " | " + file.why + " |");
|
|
10226
|
+
}
|
|
10227
|
+
lines.push("");
|
|
10228
|
+
const dropped = selection.kind === "slice" ? manifest.slice?.dropped : manifest.budget?.dropped;
|
|
10229
|
+
if (typeof dropped === "number") {
|
|
10230
|
+
lines.push("## What was left out");
|
|
10231
|
+
lines.push("");
|
|
10232
|
+
lines.push(dropped + " file(s) were not selected. They are recorded in `manifest.json` as `skipped`");
|
|
10233
|
+
lines.push("with the reason `not-selected`, so nothing left the snapshot without a reason.");
|
|
10234
|
+
lines.push("");
|
|
10235
|
+
}
|
|
10236
|
+
const next = manifest.budget?.nextInLine ?? [];
|
|
10237
|
+
if (next.length > 0) {
|
|
10238
|
+
lines.push("## What a larger budget would buy");
|
|
10239
|
+
lines.push("");
|
|
10240
|
+
lines.push("Headroom: " + (manifest.budget?.headroomTokens ?? 0).toLocaleString("en-US") + " tokens.");
|
|
10241
|
+
lines.push("");
|
|
10242
|
+
lines.push("| File | Tokens |");
|
|
10243
|
+
lines.push("| :-- | --: |");
|
|
10244
|
+
for (const item of next) {
|
|
10245
|
+
lines.push("| `" + item.path + "` | " + item.tokens.toLocaleString("en-US") + " |");
|
|
10246
|
+
}
|
|
10247
|
+
lines.push("");
|
|
10248
|
+
}
|
|
10249
|
+
return lines.join("\n");
|
|
10250
|
+
}
|
|
10251
|
+
|
|
10198
10252
|
// src/mcp/retrieval.ts
|
|
10199
10253
|
var STOPWORDS = /* @__PURE__ */ new Set([
|
|
10200
10254
|
"the",
|
|
@@ -11974,6 +12028,7 @@ var ARTIFACT_FILES = {
|
|
|
11974
12028
|
diff: "reports/diff.md",
|
|
11975
12029
|
log: "reports/log.md",
|
|
11976
12030
|
tokenTree: "reports/tokens.md",
|
|
12031
|
+
selection: "reports/selection.md",
|
|
11977
12032
|
fullJson: "full-codebase.json",
|
|
11978
12033
|
fullMarkdown: "full-codebase.md",
|
|
11979
12034
|
fullXml: "full-codebase.xml",
|
|
@@ -13186,6 +13241,65 @@ var historyTool = {
|
|
|
13186
13241
|
};
|
|
13187
13242
|
}
|
|
13188
13243
|
};
|
|
13244
|
+
var budgetTool = {
|
|
13245
|
+
name: "snapshot_budget",
|
|
13246
|
+
title: "What a larger budget would buy",
|
|
13247
|
+
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.',
|
|
13248
|
+
inputSchema: {
|
|
13249
|
+
type: "object",
|
|
13250
|
+
properties: {
|
|
13251
|
+
budgets: {
|
|
13252
|
+
type: "array",
|
|
13253
|
+
items: { type: "integer", minimum: 500 },
|
|
13254
|
+
description: "Token budgets to compare, ascending (default 10000, 30000, 60000)."
|
|
13255
|
+
},
|
|
13256
|
+
question: { type: "string", description: "Optional question to plan for; absent plans for the repository as a whole." },
|
|
13257
|
+
includeTests: { type: "boolean", description: "Include test files (default false)." },
|
|
13258
|
+
root: ROOT_PROPERTY,
|
|
13259
|
+
outDir: OUT_DIR_PROPERTY
|
|
13260
|
+
},
|
|
13261
|
+
additionalProperties: false
|
|
13262
|
+
},
|
|
13263
|
+
outputSchema: {
|
|
13264
|
+
type: "object",
|
|
13265
|
+
properties: { budgets: { type: "array", items: { type: "object" } } }
|
|
13266
|
+
},
|
|
13267
|
+
annotations: READ_ONLY,
|
|
13268
|
+
async handler(args, context) {
|
|
13269
|
+
const prepared = await prepare(args, context, outDirOverride(args));
|
|
13270
|
+
if (!prepared.ok) return prepared.outcome;
|
|
13271
|
+
const read = readManifest3(prepared.workspace);
|
|
13272
|
+
if (!read.ok) return { text: read.message + " Call snapshot_generate first.", isError: true };
|
|
13273
|
+
const requested = Array.isArray(args.budgets) ? args.budgets.filter((value) => typeof value === "number").map((value) => Math.max(500, value)) : [1e4, 3e4, 6e4];
|
|
13274
|
+
const budgets = [...new Set(requested)].sort((left, right) => left - right);
|
|
13275
|
+
if (budgets.length === 0) return { text: "budgets must hold at least one number", isError: true };
|
|
13276
|
+
const question = typeof args.question === "string" ? args.question : "";
|
|
13277
|
+
const rows = [];
|
|
13278
|
+
let previous = /* @__PURE__ */ new Set();
|
|
13279
|
+
for (const budget of budgets) {
|
|
13280
|
+
const plan = planForQuestion(read.manifest, question, {
|
|
13281
|
+
maxTokens: budget,
|
|
13282
|
+
...args.includeTests === true ? { includeTests: true } : {}
|
|
13283
|
+
});
|
|
13284
|
+
const paths = new Set(plan.files.map((file) => file.path));
|
|
13285
|
+
const gained = [...paths].filter((path28) => !previous.has(path28)).sort();
|
|
13286
|
+
previous = paths;
|
|
13287
|
+
rows.push({
|
|
13288
|
+
budget,
|
|
13289
|
+
files: plan.files.length,
|
|
13290
|
+
usedTokens: plan.usedTokens,
|
|
13291
|
+
gained
|
|
13292
|
+
});
|
|
13293
|
+
}
|
|
13294
|
+
const lines = [question === "" ? "No question: planning for the repository as a whole." : "Question: " + question];
|
|
13295
|
+
for (const row of rows) {
|
|
13296
|
+
lines.push(
|
|
13297
|
+
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" : "") + ")")
|
|
13298
|
+
);
|
|
13299
|
+
}
|
|
13300
|
+
return { text: lines.join("\n"), structured: { budgets: rows } };
|
|
13301
|
+
}
|
|
13302
|
+
};
|
|
13189
13303
|
var testsTool = {
|
|
13190
13304
|
name: "snapshot_tests",
|
|
13191
13305
|
title: "Tests that cover a file, and files a test covers",
|
|
@@ -13872,6 +13986,11 @@ var symbolTool = {
|
|
|
13872
13986
|
name: { type: "string", description: "Symbol name, case-insensitive." },
|
|
13873
13987
|
lines: { type: "integer", description: "Window size around the definition (default 40).", minimum: 5 },
|
|
13874
13988
|
maxFiles: { type: "integer", description: "Cap on files searched (default 5).", minimum: 1 },
|
|
13989
|
+
references: {
|
|
13990
|
+
type: "boolean",
|
|
13991
|
+
description: "Also report call sites: other files whose body mentions the name (default true)."
|
|
13992
|
+
},
|
|
13993
|
+
maxReferences: { type: "integer", description: "Cap on reported call sites (default 20).", minimum: 1 },
|
|
13875
13994
|
root: ROOT_PROPERTY,
|
|
13876
13995
|
outDir: OUT_DIR_PROPERTY
|
|
13877
13996
|
},
|
|
@@ -13882,7 +14001,8 @@ var symbolTool = {
|
|
|
13882
14001
|
type: "object",
|
|
13883
14002
|
properties: {
|
|
13884
14003
|
found: { type: "integer" },
|
|
13885
|
-
matches: { type: "array", items: { type: "object" } }
|
|
14004
|
+
matches: { type: "array", items: { type: "object" } },
|
|
14005
|
+
references: { type: "array", items: { type: "object" } }
|
|
13886
14006
|
}
|
|
13887
14007
|
},
|
|
13888
14008
|
annotations: READ_ONLY,
|
|
@@ -13935,8 +14055,44 @@ var symbolTool = {
|
|
|
13935
14055
|
structured: { found: 0, matches: [] }
|
|
13936
14056
|
};
|
|
13937
14057
|
}
|
|
13938
|
-
const
|
|
13939
|
-
|
|
14058
|
+
const callSites = [];
|
|
14059
|
+
if (args.references !== false) {
|
|
14060
|
+
const limit = Math.max(1, typeof args.maxReferences === "number" ? args.maxReferences : 20);
|
|
14061
|
+
const definitionKeys = new Set(matches.map((match) => match.path + ":" + match.line));
|
|
14062
|
+
const word = new RegExp("\\b" + name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "\\b");
|
|
14063
|
+
const parts = /* @__PURE__ */ new Map();
|
|
14064
|
+
let scanned = 0;
|
|
14065
|
+
for (const file of read.manifest.files) {
|
|
14066
|
+
if (callSites.length >= limit) break;
|
|
14067
|
+
const partPath = partPathFor(workspace, file.part);
|
|
14068
|
+
if (partPath === null) continue;
|
|
14069
|
+
let partText = parts.get(partPath);
|
|
14070
|
+
if (partText === void 0) {
|
|
14071
|
+
try {
|
|
14072
|
+
partText = fs18.readFileSync(partPath, "utf8");
|
|
14073
|
+
} catch {
|
|
14074
|
+
continue;
|
|
14075
|
+
}
|
|
14076
|
+
parts.set(partPath, partText);
|
|
14077
|
+
}
|
|
14078
|
+
if (scanned > MAX_SEARCH_BYTES) break;
|
|
14079
|
+
scanned += Buffer.byteLength(partText, "utf8");
|
|
14080
|
+
const section = findSection(parsePartSections(partText), file.relativePath);
|
|
14081
|
+
if (section === null) continue;
|
|
14082
|
+
const bodyLines = section.body.split("\n");
|
|
14083
|
+
for (let index = 0; index < bodyLines.length && callSites.length < limit; index += 1) {
|
|
14084
|
+
if (!word.test(bodyLines[index])) continue;
|
|
14085
|
+
callSites.push({
|
|
14086
|
+
path: file.relativePath,
|
|
14087
|
+
line: index + 1,
|
|
14088
|
+
text: bodyLines[index].trim().slice(0, 200),
|
|
14089
|
+
definition: definitionKeys.has(file.relativePath + ":" + (index + 1))
|
|
14090
|
+
});
|
|
14091
|
+
}
|
|
14092
|
+
}
|
|
14093
|
+
}
|
|
14094
|
+
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")));
|
|
14095
|
+
return { text: text2, structured: { found: matches.length, matches, references: callSites } };
|
|
13940
14096
|
}
|
|
13941
14097
|
};
|
|
13942
14098
|
var contextTool = {
|
|
@@ -14170,6 +14326,110 @@ var planForTool = {
|
|
|
14170
14326
|
return { text: lines.join("\n"), structured: plan };
|
|
14171
14327
|
}
|
|
14172
14328
|
};
|
|
14329
|
+
var answerTool = {
|
|
14330
|
+
name: "snapshot_answer",
|
|
14331
|
+
title: "Question in, budgeted context out",
|
|
14332
|
+
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.",
|
|
14333
|
+
inputSchema: {
|
|
14334
|
+
type: "object",
|
|
14335
|
+
properties: {
|
|
14336
|
+
question: { type: "string", description: "What you need to answer." },
|
|
14337
|
+
maxTokens: { type: "integer", description: "Budget for the whole block (default 20000).", minimum: 500 },
|
|
14338
|
+
linesPerFile: { type: "integer", description: "Head lines per file (default 60).", minimum: 10 },
|
|
14339
|
+
includeTests: { type: "boolean", description: "Include test files (default false)." },
|
|
14340
|
+
root: ROOT_PROPERTY,
|
|
14341
|
+
outDir: OUT_DIR_PROPERTY
|
|
14342
|
+
},
|
|
14343
|
+
required: ["question"],
|
|
14344
|
+
additionalProperties: false
|
|
14345
|
+
},
|
|
14346
|
+
outputSchema: {
|
|
14347
|
+
type: "object",
|
|
14348
|
+
properties: {
|
|
14349
|
+
question: { type: "string" },
|
|
14350
|
+
budgetTokens: { type: "integer" },
|
|
14351
|
+
usedTokens: { type: "integer" },
|
|
14352
|
+
files: { type: "array", items: { type: "object" } },
|
|
14353
|
+
omitted: { type: "array", items: { type: "object" } }
|
|
14354
|
+
}
|
|
14355
|
+
},
|
|
14356
|
+
annotations: READ_ONLY,
|
|
14357
|
+
async handler(args, context) {
|
|
14358
|
+
const question = typeof args.question === "string" ? args.question.trim() : "";
|
|
14359
|
+
if (question.length === 0) return { text: "question must be a non-empty string", isError: true };
|
|
14360
|
+
const prepared = await prepare(args, context, outDirOverride(args));
|
|
14361
|
+
if (!prepared.ok) return prepared.outcome;
|
|
14362
|
+
const read = readManifest3(prepared.workspace);
|
|
14363
|
+
if (!read.ok) return { text: read.message + " Call snapshot_generate first.", isError: true };
|
|
14364
|
+
const maxTokens = Math.max(500, typeof args.maxTokens === "number" ? args.maxTokens : 2e4);
|
|
14365
|
+
const linesPerFile = Math.max(10, typeof args.linesPerFile === "number" ? args.linesPerFile : 60);
|
|
14366
|
+
const plan = planForQuestion(read.manifest, question, {
|
|
14367
|
+
maxTokens,
|
|
14368
|
+
...args.includeTests === true ? { includeTests: true } : {}
|
|
14369
|
+
});
|
|
14370
|
+
const blocks = [];
|
|
14371
|
+
const omitted = [];
|
|
14372
|
+
let used = 0;
|
|
14373
|
+
const parts = /* @__PURE__ */ new Map();
|
|
14374
|
+
for (const planned of plan.files) {
|
|
14375
|
+
if (used >= maxTokens) {
|
|
14376
|
+
omitted.push({ path: planned.path, reason: "the budget was spent on earlier files" });
|
|
14377
|
+
continue;
|
|
14378
|
+
}
|
|
14379
|
+
const partPath = partPathFor(prepared.workspace, planned.part);
|
|
14380
|
+
if (partPath === null) {
|
|
14381
|
+
omitted.push({ path: planned.path, reason: "its part is not in the snapshot" });
|
|
14382
|
+
continue;
|
|
14383
|
+
}
|
|
14384
|
+
let partText = parts.get(partPath);
|
|
14385
|
+
if (partText === void 0) {
|
|
14386
|
+
try {
|
|
14387
|
+
partText = fs18.readFileSync(partPath, "utf8");
|
|
14388
|
+
} catch {
|
|
14389
|
+
omitted.push({ path: planned.path, reason: "its part could not be read" });
|
|
14390
|
+
continue;
|
|
14391
|
+
}
|
|
14392
|
+
parts.set(partPath, partText);
|
|
14393
|
+
}
|
|
14394
|
+
const section = findSection(parsePartSections(partText), planned.path);
|
|
14395
|
+
if (section === null) {
|
|
14396
|
+
omitted.push({ path: planned.path, reason: "no section in its part" });
|
|
14397
|
+
continue;
|
|
14398
|
+
}
|
|
14399
|
+
const window = windowText(section.body, 1, linesPerFile);
|
|
14400
|
+
const text2 = window.text;
|
|
14401
|
+
const tokens = estimateTokens(text2);
|
|
14402
|
+
if (used + tokens > maxTokens && blocks.length > 0) {
|
|
14403
|
+
omitted.push({ path: planned.path, reason: "did not fit the remaining budget" });
|
|
14404
|
+
continue;
|
|
14405
|
+
}
|
|
14406
|
+
const numbered = text2.split("\n").map((line, index) => String(index + 1).padStart(5, " ") + " " + line).join("\n");
|
|
14407
|
+
blocks.push({ path: planned.path, why: planned.why, tokens, text: numbered, truncated: window.truncated, totalLines: window.totalLines });
|
|
14408
|
+
used += tokens;
|
|
14409
|
+
}
|
|
14410
|
+
const lines = [
|
|
14411
|
+
"# Answer context: " + question,
|
|
14412
|
+
"Budget: " + used + " of " + maxTokens + " tokens; " + blocks.length + " file(s)."
|
|
14413
|
+
];
|
|
14414
|
+
for (const block of blocks) {
|
|
14415
|
+
lines.push("");
|
|
14416
|
+
lines.push("## " + block.path + " (" + block.tokens + " tokens, " + (block.truncated ? "first lines of " + block.totalLines : "whole file") + ")");
|
|
14417
|
+
lines.push("Why: " + block.why);
|
|
14418
|
+
lines.push("```");
|
|
14419
|
+
lines.push(block.text);
|
|
14420
|
+
lines.push("```");
|
|
14421
|
+
}
|
|
14422
|
+
if (omitted.length > 0) {
|
|
14423
|
+
lines.push("");
|
|
14424
|
+
lines.push("Not included:");
|
|
14425
|
+
for (const entry of omitted) lines.push("- " + entry.path + " - " + entry.reason);
|
|
14426
|
+
}
|
|
14427
|
+
return {
|
|
14428
|
+
text: lines.join("\n"),
|
|
14429
|
+
structured: { question, budgetTokens: maxTokens, usedTokens: used, files: blocks, omitted }
|
|
14430
|
+
};
|
|
14431
|
+
}
|
|
14432
|
+
};
|
|
14173
14433
|
var healthTool = {
|
|
14174
14434
|
name: "snapshot_health",
|
|
14175
14435
|
title: "Snapshot health audit",
|
|
@@ -15020,6 +15280,7 @@ var explainTool = {
|
|
|
15020
15280
|
var TOOL_COSTS = {
|
|
15021
15281
|
snapshot_status: "cheap",
|
|
15022
15282
|
snapshot_health: "expensive",
|
|
15283
|
+
snapshot_budget: "medium",
|
|
15023
15284
|
snapshot_history: "cheap",
|
|
15024
15285
|
snapshot_tests: "cheap",
|
|
15025
15286
|
snapshot_workspace: "cheap",
|
|
@@ -15035,6 +15296,7 @@ var TOOL_COSTS = {
|
|
|
15035
15296
|
snapshot_context: "medium",
|
|
15036
15297
|
snapshot_query: "cheap",
|
|
15037
15298
|
snapshot_plan_for: "cheap",
|
|
15299
|
+
snapshot_answer: "medium",
|
|
15038
15300
|
snapshot_plan: "expensive",
|
|
15039
15301
|
snapshot_generate: "expensive",
|
|
15040
15302
|
snapshot_validate: "medium",
|
|
@@ -15047,6 +15309,7 @@ function buildTools() {
|
|
|
15047
15309
|
return [
|
|
15048
15310
|
statusTool,
|
|
15049
15311
|
healthTool,
|
|
15312
|
+
budgetTool,
|
|
15050
15313
|
historyTool,
|
|
15051
15314
|
testsTool,
|
|
15052
15315
|
workspaceTool,
|
|
@@ -15062,6 +15325,7 @@ function buildTools() {
|
|
|
15062
15325
|
contextTool,
|
|
15063
15326
|
queryTool,
|
|
15064
15327
|
planForTool,
|
|
15328
|
+
answerTool,
|
|
15065
15329
|
planTool,
|
|
15066
15330
|
generateTool,
|
|
15067
15331
|
validateTool,
|
|
@@ -15240,6 +15504,8 @@ var VALIDATE_OPTIONS = [
|
|
|
15240
15504
|
"sarif",
|
|
15241
15505
|
"strip-comments",
|
|
15242
15506
|
"remove-empty-lines",
|
|
15507
|
+
"only",
|
|
15508
|
+
"ignore",
|
|
15243
15509
|
"pack",
|
|
15244
15510
|
// The opt-in reports change the artifact selection the manifest records, so validate must accept
|
|
15245
15511
|
// them to compare like with like: without the flags it reports the selection as drift.
|
|
@@ -15275,6 +15541,8 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
15275
15541
|
generate: [
|
|
15276
15542
|
"strip-comments",
|
|
15277
15543
|
"remove-empty-lines",
|
|
15544
|
+
"only",
|
|
15545
|
+
"ignore",
|
|
15278
15546
|
"workspace",
|
|
15279
15547
|
"budget-tokens",
|
|
15280
15548
|
"sign",
|
|
@@ -15355,6 +15623,10 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
15355
15623
|
// Removed rather than implemented, because a flag that parses and does nothing is the defect
|
|
15356
15624
|
// this table exists to prevent.
|
|
15357
15625
|
"large-file-bytes",
|
|
15626
|
+
// `--only` and `--ignore` change which files are scanned, so they change what `explain` can say
|
|
15627
|
+
// about a path; without them the answer for an ignored file is "included: true".
|
|
15628
|
+
"only",
|
|
15629
|
+
"ignore",
|
|
15358
15630
|
"include-sensitive-files",
|
|
15359
15631
|
"no-config",
|
|
15360
15632
|
"discovery",
|
|
@@ -15896,6 +16168,18 @@ function buildAgentContract() {
|
|
|
15896
16168
|
appliesTo: optionAppliesTo("allow-origin"),
|
|
15897
16169
|
summary: "mcp --http: comma-separated extra CORS origins. Loopback origins are always allowed."
|
|
15898
16170
|
},
|
|
16171
|
+
{
|
|
16172
|
+
flag: "--only",
|
|
16173
|
+
type: "string",
|
|
16174
|
+
summary: "Comma-separated globs to include: overrides the config include list for this run.",
|
|
16175
|
+
appliesTo: optionAppliesTo("only")
|
|
16176
|
+
},
|
|
16177
|
+
{
|
|
16178
|
+
flag: "--ignore",
|
|
16179
|
+
type: "string",
|
|
16180
|
+
summary: "Comma-separated globs to exclude, added to the config exclude list for this run.",
|
|
16181
|
+
appliesTo: optionAppliesTo("ignore")
|
|
16182
|
+
},
|
|
15899
16183
|
{
|
|
15900
16184
|
flag: "--remove-empty-lines",
|
|
15901
16185
|
type: "boolean",
|
|
@@ -16434,7 +16718,7 @@ diff, and the commit, are then yours.
|
|
|
16434
16718
|
## When the client speaks MCP
|
|
16435
16719
|
|
|
16436
16720
|
If the agent runs inside an MCP client, \`npx ${PACKAGE_NAME2}@latest mcp\` serves this repository
|
|
16437
|
-
as
|
|
16721
|
+
as 26 tools over stdio instead of shelling out. Its reads come from the snapshot rather than
|
|
16438
16722
|
the working tree, so excluded files and redacted values never reach the context. Use
|
|
16439
16723
|
\`snapshot_locate\` before \`snapshot_read\`, and \`snapshot_validate\` before trusting a snapshot
|
|
16440
16724
|
from an earlier session.
|
|
@@ -19806,6 +20090,7 @@ function generateSnapshot(configInput, options) {
|
|
|
19806
20090
|
}
|
|
19807
20091
|
}
|
|
19808
20092
|
let sliceBlock;
|
|
20093
|
+
let selectionReport = null;
|
|
19809
20094
|
if (options?.slice !== void 0) {
|
|
19810
20095
|
const byFile = files.filter((file) => isSourceSummary(file.summary)).map((file) => ({
|
|
19811
20096
|
path: file.relativePath,
|
|
@@ -19829,6 +20114,11 @@ function generateSnapshot(configInput, options) {
|
|
|
19829
20114
|
files: plan.files.map((file) => file.path),
|
|
19830
20115
|
dropped: scanned - plan.files.length
|
|
19831
20116
|
};
|
|
20117
|
+
selectionReport = {
|
|
20118
|
+
kind: "slice",
|
|
20119
|
+
detail: "Question: " + options.slice.question + "\nBudget: " + plan.budgetTokens.toLocaleString("en-US") + " tokens",
|
|
20120
|
+
files: plan.files.map((file) => ({ path: file.path, tokens: file.tokens, why: file.why }))
|
|
20121
|
+
};
|
|
19832
20122
|
}
|
|
19833
20123
|
let budgetBlock;
|
|
19834
20124
|
if (options?.budgetTokens !== void 0) {
|
|
@@ -19854,12 +20144,26 @@ function generateSnapshot(configInput, options) {
|
|
|
19854
20144
|
const keep = /* @__PURE__ */ new Set();
|
|
19855
20145
|
let used = 0;
|
|
19856
20146
|
const selected = [];
|
|
20147
|
+
const chosen = [];
|
|
19857
20148
|
for (const item of ranked) {
|
|
19858
20149
|
if (used + item.tokens > budget) continue;
|
|
19859
20150
|
keep.add(item.file.relativePath);
|
|
19860
20151
|
selected.push(item.file.relativePath);
|
|
20152
|
+
chosen.push({
|
|
20153
|
+
path: item.file.relativePath,
|
|
20154
|
+
tokens: item.tokens,
|
|
20155
|
+
why: (entry(item.file.relativePath) ? "entry point" : "not an entry point") + "; " + (importers.get(item.file.relativePath) ?? 0) + " importer(s); layer " + item.file.layer
|
|
20156
|
+
});
|
|
19861
20157
|
used += item.tokens;
|
|
19862
20158
|
}
|
|
20159
|
+
const nextInLine = [];
|
|
20160
|
+
let headroom = budget - used;
|
|
20161
|
+
for (const item of ranked) {
|
|
20162
|
+
if (keep.has(item.file.relativePath)) continue;
|
|
20163
|
+
if (nextInLine.length >= 10) break;
|
|
20164
|
+
nextInLine.push({ path: item.file.relativePath, tokens: item.tokens });
|
|
20165
|
+
headroom = Math.max(headroom, item.tokens);
|
|
20166
|
+
}
|
|
19863
20167
|
const scanned = files.length;
|
|
19864
20168
|
const byLayer = {};
|
|
19865
20169
|
let entryKept = 0;
|
|
@@ -19888,7 +20192,14 @@ function generateSnapshot(configInput, options) {
|
|
|
19888
20192
|
usedTokens: used,
|
|
19889
20193
|
files: selected,
|
|
19890
20194
|
dropped: scanned - selected.length,
|
|
19891
|
-
coverage: { byLayer, entryPoints: { kept: entryKept, total: entryTotal }, symbols: { kept: symbolsKept, total: symbolsTotal } }
|
|
20195
|
+
coverage: { byLayer, entryPoints: { kept: entryKept, total: entryTotal }, symbols: { kept: symbolsKept, total: symbolsTotal } },
|
|
20196
|
+
headroomTokens: Math.max(0, budget - used),
|
|
20197
|
+
nextInLine
|
|
20198
|
+
};
|
|
20199
|
+
selectionReport = {
|
|
20200
|
+
kind: "budget",
|
|
20201
|
+
detail: "Budget: " + budget.toLocaleString("en-US") + " tokens",
|
|
20202
|
+
files: chosen
|
|
19892
20203
|
};
|
|
19893
20204
|
if (entryTotal > 0 && entryKept < entryTotal) {
|
|
19894
20205
|
warnings.push(
|
|
@@ -20197,6 +20508,8 @@ function generateSnapshot(configInput, options) {
|
|
|
20197
20508
|
}) : null;
|
|
20198
20509
|
if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
|
|
20199
20510
|
if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
|
|
20511
|
+
const selectionText = selectionReport === null ? null : generateSelectionReport(manifest, selectionReport);
|
|
20512
|
+
if (selectionText !== null) manifest.artifacts.selection = artifactRecord(selectionText);
|
|
20200
20513
|
let monolithJson = null;
|
|
20201
20514
|
let monolithMarkdown = null;
|
|
20202
20515
|
let monolithXml = null;
|
|
@@ -20353,6 +20666,9 @@ function generateSnapshot(configInput, options) {
|
|
|
20353
20666
|
if (tokenTree !== null) {
|
|
20354
20667
|
writeArtifact(reportsDir, "tokens.md", tokenTree.text);
|
|
20355
20668
|
}
|
|
20669
|
+
if (selectionText !== null) {
|
|
20670
|
+
writeArtifact(reportsDir, "selection.md", selectionText);
|
|
20671
|
+
}
|
|
20356
20672
|
if (sarifText !== null) {
|
|
20357
20673
|
writeArtifact(reportsDir, "audit.sarif", sarifText);
|
|
20358
20674
|
}
|
|
@@ -20930,6 +21246,8 @@ var CLI_OPTIONS = {
|
|
|
20930
21246
|
workspace: { type: "string" },
|
|
20931
21247
|
"strip-comments": { type: "boolean" },
|
|
20932
21248
|
"remove-empty-lines": { type: "boolean" },
|
|
21249
|
+
only: { type: "string" },
|
|
21250
|
+
ignore: { type: "string" },
|
|
20933
21251
|
"all-members": { type: "boolean" },
|
|
20934
21252
|
help: { type: "boolean", short: "h" },
|
|
20935
21253
|
version: { type: "boolean", short: "v" }
|
|
@@ -21378,6 +21696,8 @@ function parseCliArgs(argv) {
|
|
|
21378
21696
|
workspace: values.workspace === void 0 ? void 0 : String(values.workspace),
|
|
21379
21697
|
stripComments: values["strip-comments"] === true ? true : void 0,
|
|
21380
21698
|
removeEmptyLines: values["remove-empty-lines"] === true ? true : void 0,
|
|
21699
|
+
only: values.only === void 0 ? void 0 : String(values.only).split(",").map((item) => item.trim()).filter(Boolean),
|
|
21700
|
+
ignore: values.ignore === void 0 ? void 0 : String(values.ignore).split(",").map((item) => item.trim()).filter(Boolean),
|
|
21381
21701
|
allMembers: values["all-members"] === true ? true : void 0,
|
|
21382
21702
|
budgetTokens: values["budget-tokens"] === void 0 ? void 0 : parsePositiveInteger(values["budget-tokens"], "budget-tokens", 500),
|
|
21383
21703
|
delta: values.delta === void 0 ? void 0 : String(values.delta),
|
|
@@ -22079,6 +22399,8 @@ ${USAGE}
|
|
|
22079
22399
|
...invocation.tokenTree === true ? { tokenTree: true } : {},
|
|
22080
22400
|
...invocation.stripComments === true ? { stripComments: true } : {},
|
|
22081
22401
|
...invocation.removeEmptyLines === true ? { removeEmptyLines: true } : {},
|
|
22402
|
+
...invocation.only === void 0 ? {} : { only: invocation.only },
|
|
22403
|
+
...invocation.ignore === void 0 ? {} : { ignore: invocation.ignore },
|
|
22082
22404
|
...invocation.pack === void 0 ? {} : { pack: invocation.pack },
|
|
22083
22405
|
brief: invocation.brief,
|
|
22084
22406
|
promptTask: invocation.promptTask,
|
|
@@ -22215,6 +22537,15 @@ ${USAGE}
|
|
|
22215
22537
|
info(` - Entry points: ${coverage.entryPoints.kept} of ${coverage.entryPoints.total}`);
|
|
22216
22538
|
info(` - Symbols: ${coverage.symbols.kept} of ${coverage.symbols.total}`);
|
|
22217
22539
|
}
|
|
22540
|
+
if (manifest.budget.headroomTokens !== void 0) {
|
|
22541
|
+
info(` - Headroom: ${formatNumber(manifest.budget.headroomTokens)} tokens`);
|
|
22542
|
+
}
|
|
22543
|
+
if (manifest.budget.nextInLine !== void 0 && manifest.budget.nextInLine.length > 0) {
|
|
22544
|
+
const next = manifest.budget.nextInLine.slice(0, 5);
|
|
22545
|
+
info(
|
|
22546
|
+
" - Next in line: " + next.map((item) => item.path + " (" + formatNumber(item.tokens) + ")").join(", ") + (manifest.budget.nextInLine.length > next.length ? ", \u2026" : "")
|
|
22547
|
+
);
|
|
22548
|
+
}
|
|
22218
22549
|
}
|
|
22219
22550
|
if (manifest.delta !== void 0) {
|
|
22220
22551
|
const delta = manifest.delta;
|