codebase-snapshot 0.22.1 → 0.22.2
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 +13 -0
- package/README.md +3 -3
- package/dist/bin.js +1200 -861
- package/dist/{chunk-7AAXOTKS.js → chunk-OVH6B3GV.js} +299 -35
- package/dist/cli.cjs +1330 -998
- package/dist/cli.js +231 -163
- package/dist/index.cjs +303 -34
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +303 -34
- package/dist/mcp.js +1 -1
- package/docs/agent.md +3 -0
- package/docs/answer.md +40 -11
- package/docs/cli.md +5 -5
- package/docs/deploy.md +2 -2
- package/docs/guard.md +14 -10
- package/docs/mcp.md +5 -5
- package/docs/security-review.md +5 -0
- package/docs/tools.md +18 -3
- package/package.json +1 -1
package/dist/mcp.cjs
CHANGED
|
@@ -3098,6 +3098,11 @@ function readConfinedText(baseDir, relativePath, maxBytes) {
|
|
|
3098
3098
|
|
|
3099
3099
|
// src/signing.ts
|
|
3100
3100
|
var SIGNATURE_FILE = "signature.json";
|
|
3101
|
+
function loadSigningKey(environment = process.env) {
|
|
3102
|
+
const pem = environment.SNAPSHOT_SIGNING_KEY;
|
|
3103
|
+
if (pem === void 0 || pem.trim() === "") return null;
|
|
3104
|
+
return crypto__namespace.createPrivateKey({ key: pem, format: "pem" });
|
|
3105
|
+
}
|
|
3101
3106
|
var MAX_SIGNATURE_BYTES = 64 * 1024;
|
|
3102
3107
|
function verifySnapshotSignature(snapshotDir) {
|
|
3103
3108
|
const signatureRead = readConfinedBytes(snapshotDir, SIGNATURE_FILE);
|
|
@@ -3152,7 +3157,7 @@ function verifySnapshotSignature(snapshotDir) {
|
|
|
3152
3157
|
|
|
3153
3158
|
// src/version.ts
|
|
3154
3159
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
3155
|
-
var GENERATOR_VERSION = "0.22.
|
|
3160
|
+
var GENERATOR_VERSION = "0.22.2";
|
|
3156
3161
|
var SCHEMA_VERSION = "3.0.0";
|
|
3157
3162
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
3158
3163
|
function isOurGeneratorName(name) {
|
|
@@ -10298,6 +10303,54 @@ var requireFromHere = module$1.createRequire((typeof document === 'undefined' ?
|
|
|
10298
10303
|
path7__namespace.dirname(requireFromHere.resolve("typescript"));
|
|
10299
10304
|
var DEFAULT_MAX_PROGRAM_FILES = 2500;
|
|
10300
10305
|
process.platform === "win32" || process.platform === "darwin";
|
|
10306
|
+
var ZERO_WIDTH = /[\u200B-\u200F\u2060-\u2064\uFEFF]/g;
|
|
10307
|
+
var BIDI_CONTROL = /[\u202A-\u202E\u2066-\u2069]/g;
|
|
10308
|
+
var HTML_COMMENT = /<!--([\s\S]*?)-->/g;
|
|
10309
|
+
function looksLikeInstruction(body) {
|
|
10310
|
+
const text = body.replace(/\s+/g, " ").trim();
|
|
10311
|
+
if (text.length === 0) return false;
|
|
10312
|
+
return /\b(ignore|disregard|forget)\b[^.]{0,100}\b(previous|prior|above|earlier)\b/i.test(text) || /\b(system|developer|assistant)\s*:/i.test(text) || /\b(print|reveal|show|dump|exfiltrate|send|curl|fetch|read)\b[^.]{0,100}\b(env|secret|token|key|password|credential|\.env)/i.test(text) || /\bAI (agent|assistant|model)\b/i.test(text) || /\bdo not (tell|mention|reveal|disclose)\b/i.test(text) || /\b(you must|you should now|new instructions?)\b/i.test(text);
|
|
10313
|
+
}
|
|
10314
|
+
function lineAt(text, index) {
|
|
10315
|
+
let line = 1;
|
|
10316
|
+
for (let i = 0; i < index; i += 1) if (text.charCodeAt(i) === 10) line += 1;
|
|
10317
|
+
return line;
|
|
10318
|
+
}
|
|
10319
|
+
function maskPreservingLines(match, marker) {
|
|
10320
|
+
const newlines = match.match(/\n/g)?.length ?? 0;
|
|
10321
|
+
return marker + "\n".repeat(newlines);
|
|
10322
|
+
}
|
|
10323
|
+
function hashSpans(spans) {
|
|
10324
|
+
if (spans.length === 0) return null;
|
|
10325
|
+
return crypto.createHash("sha256").update(spans.join("\0")).digest("hex");
|
|
10326
|
+
}
|
|
10327
|
+
function scanHiddenText(text) {
|
|
10328
|
+
const findings = [];
|
|
10329
|
+
const removedSpans = [];
|
|
10330
|
+
let output = text;
|
|
10331
|
+
output = output.replace(HTML_COMMENT, (match, body, offset) => {
|
|
10332
|
+
if (!looksLikeInstruction(body)) return match;
|
|
10333
|
+
findings.push({ kind: "html-comment", line: lineAt(text, offset), detail: "hidden instruction comment removed" });
|
|
10334
|
+
removedSpans.push(match);
|
|
10335
|
+
return maskPreservingLines(match, "[REMOVED: hidden instruction comment]");
|
|
10336
|
+
});
|
|
10337
|
+
output = output.replace(ZERO_WIDTH, (match, offset) => {
|
|
10338
|
+
findings.push({ kind: "zero-width", line: lineAt(output, offset), detail: "zero-width character removed" });
|
|
10339
|
+
removedSpans.push(match);
|
|
10340
|
+
return "";
|
|
10341
|
+
});
|
|
10342
|
+
output = output.replace(BIDI_CONTROL, (match, offset) => {
|
|
10343
|
+
findings.push({ kind: "bidi-control", line: lineAt(output, offset), detail: "bidi control removed" });
|
|
10344
|
+
removedSpans.push(match);
|
|
10345
|
+
return "";
|
|
10346
|
+
});
|
|
10347
|
+
return {
|
|
10348
|
+
text: output,
|
|
10349
|
+
findings,
|
|
10350
|
+
removed: findings.length,
|
|
10351
|
+
removedDigest: hashSpans(removedSpans)
|
|
10352
|
+
};
|
|
10353
|
+
}
|
|
10301
10354
|
|
|
10302
10355
|
// src/partitioner/part-format.ts
|
|
10303
10356
|
var FILE_HEADING = "### FILE: ";
|
|
@@ -11521,6 +11574,56 @@ function symbolsOf(entry) {
|
|
|
11521
11574
|
}
|
|
11522
11575
|
return [...new Set(names)].sort((left, right) => left.localeCompare(right));
|
|
11523
11576
|
}
|
|
11577
|
+
function declarationSpansOf(entry) {
|
|
11578
|
+
const summary = entry.summary;
|
|
11579
|
+
if (!summary || typeof summary !== "object") return [];
|
|
11580
|
+
const spans = summary.declarationSpans;
|
|
11581
|
+
if (!Array.isArray(spans)) return [];
|
|
11582
|
+
return spans.filter((span) => {
|
|
11583
|
+
if (span === null || typeof span !== "object") return false;
|
|
11584
|
+
const candidate = span;
|
|
11585
|
+
return typeof candidate.name === "string" && typeof candidate.startLine === "number" && Number.isInteger(candidate.startLine) && typeof candidate.endLine === "number" && Number.isInteger(candidate.endLine) && candidate.startLine >= 1 && candidate.endLine >= candidate.startLine;
|
|
11586
|
+
});
|
|
11587
|
+
}
|
|
11588
|
+
function symbolSpanOf(entry, symbol) {
|
|
11589
|
+
const wanted = symbol.toLowerCase();
|
|
11590
|
+
const matches = declarationSpansOf(entry).filter((span) => span.name.toLowerCase() === wanted);
|
|
11591
|
+
return matches[0] ?? null;
|
|
11592
|
+
}
|
|
11593
|
+
function identifierTokens(value) {
|
|
11594
|
+
return value.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase().split(/[^a-z0-9]+/).filter((token) => token.length > 2);
|
|
11595
|
+
}
|
|
11596
|
+
function questionSpanOf(entry, question) {
|
|
11597
|
+
const asked = question.toLowerCase();
|
|
11598
|
+
const tokens = new Set(identifierTokens(question));
|
|
11599
|
+
let best = null;
|
|
11600
|
+
let bestScore = 0;
|
|
11601
|
+
for (const span of declarationSpansOf(entry)) {
|
|
11602
|
+
if (span.name.length < 3) continue;
|
|
11603
|
+
const nameTokens = identifierTokens(span.name);
|
|
11604
|
+
if (nameTokens.length < 2) continue;
|
|
11605
|
+
let score = asked.includes(span.name.toLowerCase()) ? 8 : 0;
|
|
11606
|
+
for (const token of nameTokens) if (tokens.has(token)) score += 2;
|
|
11607
|
+
if (score > bestScore) {
|
|
11608
|
+
best = span;
|
|
11609
|
+
bestScore = score;
|
|
11610
|
+
}
|
|
11611
|
+
}
|
|
11612
|
+
return bestScore >= 4 ? best : null;
|
|
11613
|
+
}
|
|
11614
|
+
function clampRange(range, totalLines) {
|
|
11615
|
+
const start = Math.max(1, Math.min(range.startLine, Math.max(1, totalLines)));
|
|
11616
|
+
const end = Math.max(start, Math.min(range.endLine, Math.max(1, totalLines)));
|
|
11617
|
+
if (totalLines > 0 && range.startLine > totalLines) return null;
|
|
11618
|
+
return { startLine: start, endLine: end };
|
|
11619
|
+
}
|
|
11620
|
+
function stableJson(value) {
|
|
11621
|
+
if (value === void 0) return "null";
|
|
11622
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
11623
|
+
if (Array.isArray(value)) return "[" + value.map(stableJson).join(",") + "]";
|
|
11624
|
+
const record = value;
|
|
11625
|
+
return "{" + Object.keys(record).sort().map((key) => JSON.stringify(key) + ":" + stableJson(record[key])).join(",") + "}";
|
|
11626
|
+
}
|
|
11524
11627
|
async function prepare(args, context, overrides = {}) {
|
|
11525
11628
|
const rootOutcome = resolveRoot(args.root, context);
|
|
11526
11629
|
if (!rootOutcome.ok) return { ok: false, outcome: failure(rootOutcome.message) };
|
|
@@ -11634,9 +11737,9 @@ function bodyFor(workspace, index, entry, cache) {
|
|
|
11634
11737
|
}
|
|
11635
11738
|
return section.body;
|
|
11636
11739
|
}
|
|
11637
|
-
function numberWindow(text) {
|
|
11740
|
+
function numberWindow(text, startLine = 1) {
|
|
11638
11741
|
if (text.length === 0) return text;
|
|
11639
|
-
return text.split("\n").map((line, index) =>
|
|
11742
|
+
return text.split("\n").map((line, index) => startLine + index + ": " + line).join("\n");
|
|
11640
11743
|
}
|
|
11641
11744
|
var impactTool = {
|
|
11642
11745
|
name: "snapshot_impact",
|
|
@@ -11828,10 +11931,28 @@ var contextTool = {
|
|
|
11828
11931
|
question: { type: "string", description: "Natural-language question or task." },
|
|
11829
11932
|
files: { type: "array", items: { type: "string" }, description: "Explicit repository-relative paths." },
|
|
11830
11933
|
symbols: { type: "array", items: { type: "string" }, description: "Exported or defined symbol names." },
|
|
11934
|
+
ranges: {
|
|
11935
|
+
type: "array",
|
|
11936
|
+
description: "Explicit 1-based line ranges. Each range is honored before the file head or a symbol span.",
|
|
11937
|
+
items: {
|
|
11938
|
+
type: "object",
|
|
11939
|
+
properties: {
|
|
11940
|
+
path: { type: "string", description: "Repository-relative path." },
|
|
11941
|
+
startLine: { type: "integer", minimum: 1 },
|
|
11942
|
+
endLine: { type: "integer", minimum: 1 }
|
|
11943
|
+
},
|
|
11944
|
+
required: ["path", "startLine", "endLine"],
|
|
11945
|
+
additionalProperties: false
|
|
11946
|
+
}
|
|
11947
|
+
},
|
|
11831
11948
|
maxTokens: { type: "integer", minimum: 500, maximum: 2e5, default: 2e4 },
|
|
11832
11949
|
linesPerFile: { type: "integer", minimum: 10, maximum: 2e3, default: 80 },
|
|
11833
11950
|
includeTests: { type: "boolean", description: "Include test files (default false)." },
|
|
11834
11951
|
planOnly: { type: "boolean", description: "Return the reading plan without file bodies." },
|
|
11952
|
+
signReceipt: {
|
|
11953
|
+
type: "boolean",
|
|
11954
|
+
description: "Sign the context receipt with SNAPSHOT_SIGNING_KEY. Requires a configured key."
|
|
11955
|
+
},
|
|
11835
11956
|
live: LIVE_PROPERTY,
|
|
11836
11957
|
root: ROOT_PROPERTY,
|
|
11837
11958
|
outDir: OUT_DIR_PROPERTY
|
|
@@ -11847,6 +11968,8 @@ var contextTool = {
|
|
|
11847
11968
|
omitted: { type: "array", items: { type: "object" } },
|
|
11848
11969
|
skipped: { type: "array", items: { type: "object" } },
|
|
11849
11970
|
notes: { type: "array", items: { type: "string" } },
|
|
11971
|
+
security: { type: "array", items: { type: "object" } },
|
|
11972
|
+
receipt: { type: "object" },
|
|
11850
11973
|
trust: { type: "object" }
|
|
11851
11974
|
}
|
|
11852
11975
|
},
|
|
@@ -11864,8 +11987,8 @@ var contextTool = {
|
|
|
11864
11987
|
const question = typeof args.question === "string" ? args.question.trim() : "";
|
|
11865
11988
|
const wantedFiles = Array.isArray(args.files) ? args.files.filter((item) => typeof item === "string") : [];
|
|
11866
11989
|
const wantedSymbols = Array.isArray(args.symbols) ? args.symbols.filter((item) => typeof item === "string") : [];
|
|
11867
|
-
if (question.length === 0 && wantedFiles.length === 0 && wantedSymbols.length === 0) {
|
|
11868
|
-
return failure("Provide at least one of question, files or
|
|
11990
|
+
if (question.length === 0 && wantedFiles.length === 0 && wantedSymbols.length === 0 && !(Array.isArray(args.ranges) && args.ranges.length > 0)) {
|
|
11991
|
+
return failure("Provide at least one of question, files, symbols or ranges.");
|
|
11869
11992
|
}
|
|
11870
11993
|
const budget = Math.min(2e5, Math.max(500, typeof args.maxTokens === "number" ? args.maxTokens : 2e4));
|
|
11871
11994
|
const linesPerFile = Math.min(2e3, Math.max(10, typeof args.linesPerFile === "number" ? args.linesPerFile : 80));
|
|
@@ -11874,10 +11997,45 @@ var contextTool = {
|
|
|
11874
11997
|
includeTests: args.includeTests === true,
|
|
11875
11998
|
cwd: workspace.root
|
|
11876
11999
|
}) : null;
|
|
12000
|
+
const wantedRanges = [];
|
|
12001
|
+
if (args.ranges !== void 0) {
|
|
12002
|
+
if (!Array.isArray(args.ranges)) return failure('"ranges" must be an array.');
|
|
12003
|
+
for (const raw of args.ranges) {
|
|
12004
|
+
if (raw === null || typeof raw !== "object") return failure('"ranges" entries must be objects.');
|
|
12005
|
+
const candidate = raw;
|
|
12006
|
+
if (typeof candidate.path !== "string" || candidate.path.trim().length === 0) {
|
|
12007
|
+
return failure('"ranges[].path" must be a non-empty string.');
|
|
12008
|
+
}
|
|
12009
|
+
if (typeof candidate.startLine !== "number" || !Number.isInteger(candidate.startLine) || candidate.startLine < 1) {
|
|
12010
|
+
return failure('"ranges[].startLine" must be a positive integer.');
|
|
12011
|
+
}
|
|
12012
|
+
if (typeof candidate.endLine !== "number" || !Number.isInteger(candidate.endLine) || candidate.endLine < 1) {
|
|
12013
|
+
return failure('"ranges[].endLine" must be a positive integer.');
|
|
12014
|
+
}
|
|
12015
|
+
if (candidate.endLine < candidate.startLine) {
|
|
12016
|
+
return failure('"ranges[].endLine" must be greater than or equal to startLine.');
|
|
12017
|
+
}
|
|
12018
|
+
wantedRanges.push({ path: candidate.path.trim(), startLine: candidate.startLine, endLine: candidate.endLine });
|
|
12019
|
+
}
|
|
12020
|
+
}
|
|
12021
|
+
if (question.length === 0 && wantedFiles.length === 0 && wantedSymbols.length === 0 && wantedRanges.length === 0) {
|
|
12022
|
+
return failure("Provide at least one of question, files, symbols or ranges.");
|
|
12023
|
+
}
|
|
12024
|
+
const receiptKey = args.signReceipt === true ? loadSigningKey() : null;
|
|
12025
|
+
if (args.signReceipt === true && receiptKey === null) {
|
|
12026
|
+
return failure("signReceipt requires SNAPSHOT_SIGNING_KEY to contain an Ed25519 private key.");
|
|
12027
|
+
}
|
|
11877
12028
|
const targets = /* @__PURE__ */ new Map();
|
|
11878
12029
|
const preOmitted = [];
|
|
11879
12030
|
if (plan !== null) {
|
|
11880
|
-
for (const file of plan.files)
|
|
12031
|
+
for (const file of plan.files) {
|
|
12032
|
+
const entry = entryFor(index.manifest, file.path);
|
|
12033
|
+
const span = entry === null ? null : questionSpanOf(entry, question);
|
|
12034
|
+
targets.set(file.path, {
|
|
12035
|
+
why: file.why,
|
|
12036
|
+
...span === null ? {} : { range: { startLine: span.startLine, endLine: span.endLine }, symbol: span.name }
|
|
12037
|
+
});
|
|
12038
|
+
}
|
|
11881
12039
|
for (const file of plan.skipped) {
|
|
11882
12040
|
preOmitted.push({ path: file.path, reason: file.reason });
|
|
11883
12041
|
}
|
|
@@ -11892,20 +12050,38 @@ var contextTool = {
|
|
|
11892
12050
|
preOmitted.push({ path: relative14, reason: "sensitive-file" });
|
|
11893
12051
|
continue;
|
|
11894
12052
|
}
|
|
11895
|
-
targets.set(relative14, "requested file");
|
|
12053
|
+
targets.set(relative14, { why: "requested file" });
|
|
11896
12054
|
}
|
|
11897
12055
|
for (const symbol of wantedSymbols) {
|
|
11898
12056
|
const needle = symbol.toLowerCase();
|
|
11899
12057
|
for (const file of index.manifest.files) {
|
|
11900
12058
|
if (symbolsOf(file).some((name) => name.toLowerCase() === needle)) {
|
|
11901
|
-
|
|
11902
|
-
|
|
11903
|
-
|
|
12059
|
+
const span = symbolSpanOf(file, symbol);
|
|
12060
|
+
targets.set(file.relativePath, {
|
|
12061
|
+
why: "defines " + symbol,
|
|
12062
|
+
...span === null ? {} : { range: { startLine: span.startLine, endLine: span.endLine }, symbol: span.name }
|
|
12063
|
+
});
|
|
11904
12064
|
}
|
|
11905
12065
|
}
|
|
11906
12066
|
}
|
|
12067
|
+
for (const wanted of wantedRanges) {
|
|
12068
|
+
const relative14 = toRelativePath(workspace.root, wanted.path);
|
|
12069
|
+
if (relative14 === null) {
|
|
12070
|
+
preOmitted.push({ path: wanted.path, reason: "outside the served repository" });
|
|
12071
|
+
continue;
|
|
12072
|
+
}
|
|
12073
|
+
if (isSensitivePath(relative14)) {
|
|
12074
|
+
preOmitted.push({ path: relative14, reason: "sensitive-file" });
|
|
12075
|
+
continue;
|
|
12076
|
+
}
|
|
12077
|
+
targets.set(relative14, {
|
|
12078
|
+
why: "requested range",
|
|
12079
|
+
range: { startLine: wanted.startLine, endLine: wanted.endLine },
|
|
12080
|
+
explicitRange: true
|
|
12081
|
+
});
|
|
12082
|
+
}
|
|
11907
12083
|
if (args.planOnly === true) {
|
|
11908
|
-
if (plan !== null && wantedFiles.length === 0 && wantedSymbols.length === 0) {
|
|
12084
|
+
if (plan !== null && wantedFiles.length === 0 && wantedSymbols.length === 0 && wantedRanges.length === 0) {
|
|
11909
12085
|
return {
|
|
11910
12086
|
text: [
|
|
11911
12087
|
"Plan for: " + question,
|
|
@@ -11919,13 +12095,19 @@ var contextTool = {
|
|
|
11919
12095
|
const plannedFiles = [];
|
|
11920
12096
|
const planSkipped = [...preOmitted];
|
|
11921
12097
|
let planUsed = 0;
|
|
11922
|
-
for (const [relativePath,
|
|
12098
|
+
for (const [relativePath, target] of targets.entries()) {
|
|
11923
12099
|
const entry = entryFor(index.manifest, relativePath);
|
|
11924
12100
|
if (entry === null) {
|
|
11925
12101
|
planSkipped.push({ path: relativePath, reason: "not in the index" });
|
|
11926
12102
|
continue;
|
|
11927
12103
|
}
|
|
11928
|
-
const
|
|
12104
|
+
const range = target.range === void 0 ? null : clampRange(target.range, entry.lines);
|
|
12105
|
+
if (target.range !== void 0 && range === null) {
|
|
12106
|
+
planSkipped.push({ path: target.symbol === void 0 ? relativePath : relativePath + " (" + target.symbol + ")", reason: "range is past the end of the file" });
|
|
12107
|
+
continue;
|
|
12108
|
+
}
|
|
12109
|
+
const lineCount = range === null ? null : range.endLine - range.startLine + 1;
|
|
12110
|
+
const estimated = range === null ? Math.max(1, Math.ceil(entry.includedBytes / 4)) : Math.max(1, Math.ceil(entry.includedBytes * lineCount / Math.max(1, entry.includedLines) / 4));
|
|
11929
12111
|
if (planUsed + estimated > budget) {
|
|
11930
12112
|
planSkipped.push({ path: relativePath, reason: "does not fit the remaining budget" });
|
|
11931
12113
|
continue;
|
|
@@ -11937,8 +12119,11 @@ var contextTool = {
|
|
|
11937
12119
|
layer: entry.layer,
|
|
11938
12120
|
kind: entry.kind,
|
|
11939
12121
|
tokens: estimated,
|
|
11940
|
-
mode: "full",
|
|
11941
|
-
|
|
12122
|
+
mode: range === null ? "full" : "range",
|
|
12123
|
+
fromLine: range === null ? 1 : range.startLine,
|
|
12124
|
+
toLine: range === null ? entry.lines : range.endLine,
|
|
12125
|
+
...target.symbol === void 0 ? {} : { symbol: target.symbol },
|
|
12126
|
+
why: target.why
|
|
11942
12127
|
});
|
|
11943
12128
|
}
|
|
11944
12129
|
const planNotes = plan === null ? [] : [...plan.notes];
|
|
@@ -11946,7 +12131,7 @@ var contextTool = {
|
|
|
11946
12131
|
text: [
|
|
11947
12132
|
"Plan" + (question.length > 0 ? " for: " + question : ""),
|
|
11948
12133
|
"Budget: " + planUsed + " of " + budget + " tokens; " + plannedFiles.length + " file(s).",
|
|
11949
|
-
...plannedFiles.map((file, position) => position + 1 + ". " + file.path + " (" + file.tokens + " tokens) - " + file.why),
|
|
12134
|
+
...plannedFiles.map((file, position) => position + 1 + ". " + file.path + " (" + file.tokens + " tokens, lines " + file.fromLine + "\u2013" + file.toLine + ") - " + file.why),
|
|
11950
12135
|
...planNotes.map((note) => "- " + note)
|
|
11951
12136
|
].join("\n"),
|
|
11952
12137
|
structured: {
|
|
@@ -11961,10 +12146,11 @@ var contextTool = {
|
|
|
11961
12146
|
};
|
|
11962
12147
|
}
|
|
11963
12148
|
const omitted = [...preOmitted];
|
|
12149
|
+
const security = [];
|
|
11964
12150
|
const blocks = [];
|
|
11965
12151
|
const sections = [];
|
|
11966
12152
|
let used = 0;
|
|
11967
|
-
for (const [relativePath,
|
|
12153
|
+
for (const [relativePath, target] of targets.entries()) {
|
|
11968
12154
|
if (used >= budget) {
|
|
11969
12155
|
omitted.push({ path: relativePath, reason: "budget" });
|
|
11970
12156
|
continue;
|
|
@@ -11974,7 +12160,7 @@ var contextTool = {
|
|
|
11974
12160
|
omitted.push({ path: relativePath, reason: "not in the index" });
|
|
11975
12161
|
continue;
|
|
11976
12162
|
}
|
|
11977
|
-
|
|
12163
|
+
let body = bodyFor(workspace, index, entry);
|
|
11978
12164
|
if (body === null) {
|
|
11979
12165
|
omitted.push({
|
|
11980
12166
|
path: relativePath,
|
|
@@ -11982,18 +12168,36 @@ var contextTool = {
|
|
|
11982
12168
|
});
|
|
11983
12169
|
continue;
|
|
11984
12170
|
}
|
|
11985
|
-
|
|
11986
|
-
|
|
12171
|
+
const hidden = scanHiddenText(body);
|
|
12172
|
+
if (hidden.findings.length > 0) {
|
|
12173
|
+
body = hidden.text;
|
|
12174
|
+
for (const finding of hidden.findings) security.push({ path: relativePath, ...finding });
|
|
12175
|
+
}
|
|
12176
|
+
const totalLines = body.length === 0 ? 0 : body.split("\n").length;
|
|
12177
|
+
const range = target.range === void 0 ? null : clampRange(target.range, totalLines);
|
|
12178
|
+
if (target.range !== void 0 && range === null) {
|
|
12179
|
+
omitted.push({ path: relativePath, reason: "range is past the end of the file" });
|
|
12180
|
+
continue;
|
|
12181
|
+
}
|
|
12182
|
+
const startLine = range === null ? 1 : range.startLine;
|
|
12183
|
+
const requestedLines = range === null ? linesPerFile : range.endLine - range.startLine + 1;
|
|
12184
|
+
const lineLimit = target.explicitRange === true ? Math.min(2e3, requestedLines) : Math.min(linesPerFile, requestedLines);
|
|
12185
|
+
let window = windowText(body, startLine, lineLimit);
|
|
12186
|
+
if (window.pastEnd || window.returnedLines === 0) {
|
|
12187
|
+
omitted.push({ path: relativePath, reason: "range is past the end of the file" });
|
|
12188
|
+
continue;
|
|
12189
|
+
}
|
|
12190
|
+
let capped2 = capResultText(numberWindow(window.text, startLine));
|
|
11987
12191
|
let text = capped2.text;
|
|
11988
12192
|
let tokens = Math.max(1, estimateTokens(text));
|
|
11989
12193
|
if (used + tokens > budget) {
|
|
11990
|
-
const keep = Math.max(4, Math.floor((budget - used) / tokens *
|
|
12194
|
+
const keep = Math.max(4, Math.floor((budget - used) / tokens * window.returnedLines));
|
|
11991
12195
|
if (keep < 4) {
|
|
11992
12196
|
omitted.push({ path: relativePath, reason: "budget" });
|
|
11993
12197
|
continue;
|
|
11994
12198
|
}
|
|
11995
|
-
window = windowText(body,
|
|
11996
|
-
capped2 = capResultText(numberWindow(window.text));
|
|
12199
|
+
window = windowText(body, startLine, keep);
|
|
12200
|
+
capped2 = capResultText(numberWindow(window.text, startLine));
|
|
11997
12201
|
text = capped2.text;
|
|
11998
12202
|
tokens = Math.max(1, estimateTokens(text));
|
|
11999
12203
|
if (used + tokens > budget || text.length === 0) {
|
|
@@ -12003,22 +12207,60 @@ var contextTool = {
|
|
|
12003
12207
|
}
|
|
12004
12208
|
const returnedLines = text.length === 0 ? 0 : text.split("\n").length;
|
|
12005
12209
|
const truncated = window.truncated || capped2.clipped;
|
|
12210
|
+
const toLine = startLine + returnedLines - 1;
|
|
12006
12211
|
sections.push(
|
|
12007
|
-
"### " + relativePath + " (" + entry.part + ", lines
|
|
12212
|
+
"### " + relativePath + (target.symbol === void 0 ? "" : " \u2014 " + target.symbol) + " (" + entry.part + ", lines " + startLine + "\u2013" + toLine + " of " + window.totalLines + (truncated ? "; more remains" : "") + ")"
|
|
12008
12213
|
);
|
|
12009
12214
|
sections.push(text);
|
|
12010
12215
|
blocks.push({
|
|
12011
12216
|
path: relativePath,
|
|
12012
12217
|
tokens,
|
|
12013
|
-
why,
|
|
12014
|
-
fromLine:
|
|
12218
|
+
why: target.why,
|
|
12219
|
+
fromLine: startLine,
|
|
12220
|
+
toLine,
|
|
12015
12221
|
returnedLines,
|
|
12016
12222
|
totalLines: window.totalLines,
|
|
12017
|
-
truncated
|
|
12223
|
+
truncated,
|
|
12224
|
+
...target.symbol === void 0 ? {} : { symbol: target.symbol },
|
|
12225
|
+
chunkHash: sha256Of(Buffer.from(text, "utf8"))
|
|
12018
12226
|
});
|
|
12019
12227
|
used += tokens;
|
|
12020
12228
|
}
|
|
12021
|
-
|
|
12229
|
+
if (security.length > 0) {
|
|
12230
|
+
index.trust.reasons = [.../* @__PURE__ */ new Set([...index.trust.reasons, security.length + " hidden instruction or invisible character(s) removed"])];
|
|
12231
|
+
}
|
|
12232
|
+
const notes = [];
|
|
12233
|
+
if (omitted.length > 0) notes.push("Not returned: " + omitted.map((entry) => entry.path + " (" + entry.reason + ")").join(", ") + ".");
|
|
12234
|
+
if (security.length > 0) notes.push("Security: " + security.length + " hidden item(s) removed.");
|
|
12235
|
+
const receiptChunks = blocks.map((block) => ({
|
|
12236
|
+
path: block.path,
|
|
12237
|
+
fromLine: block.fromLine,
|
|
12238
|
+
toLine: block.toLine,
|
|
12239
|
+
tokens: block.tokens,
|
|
12240
|
+
why: block.why,
|
|
12241
|
+
...block.symbol === void 0 ? {} : { symbol: block.symbol },
|
|
12242
|
+
sha256: block.chunkHash
|
|
12243
|
+
}));
|
|
12244
|
+
const receiptPayload = {
|
|
12245
|
+
schemaVersion: 1,
|
|
12246
|
+
algorithm: "sha256",
|
|
12247
|
+
chunks: receiptChunks,
|
|
12248
|
+
omitted,
|
|
12249
|
+
security,
|
|
12250
|
+
trust: index.trust
|
|
12251
|
+
};
|
|
12252
|
+
const receiptDigest = sha256Of(Buffer.from(stableJson(receiptPayload), "utf8"));
|
|
12253
|
+
const receipt = { ...receiptPayload, digest: receiptDigest };
|
|
12254
|
+
if (receiptKey !== null) {
|
|
12255
|
+
const payloadBytes = Buffer.from(stableJson(receiptPayload), "utf8");
|
|
12256
|
+
const publicKey = crypto.createPublicKey(receiptKey).export({ type: "spki", format: "der" }).toString("base64");
|
|
12257
|
+
receipt.signature = {
|
|
12258
|
+
algorithm: "ed25519",
|
|
12259
|
+
publicKey,
|
|
12260
|
+
value: crypto.sign(null, payloadBytes, receiptKey).toString("base64")
|
|
12261
|
+
};
|
|
12262
|
+
}
|
|
12263
|
+
if (receiptChunks.length > 0) notes.push("Receipt: sha256 " + receiptDigest.slice(0, 16) + "\u2026");
|
|
12022
12264
|
const response = capResponseText([sections.join("\n\n"), ...notes].filter((part) => part.length > 0).join("\n\n"));
|
|
12023
12265
|
return {
|
|
12024
12266
|
text: response.text,
|
|
@@ -12027,6 +12269,8 @@ var contextTool = {
|
|
|
12027
12269
|
usedTokens: used,
|
|
12028
12270
|
files: blocks,
|
|
12029
12271
|
omitted,
|
|
12272
|
+
security,
|
|
12273
|
+
receipt,
|
|
12030
12274
|
...response.clipped ? { clippedAtBytes: MAX_RESULT_BYTES } : {},
|
|
12031
12275
|
trust: index.trust
|
|
12032
12276
|
}
|
|
@@ -12060,7 +12304,11 @@ var locateTool = {
|
|
|
12060
12304
|
},
|
|
12061
12305
|
outputSchema: {
|
|
12062
12306
|
type: "object",
|
|
12063
|
-
properties: {
|
|
12307
|
+
properties: {
|
|
12308
|
+
total: { type: "integer" },
|
|
12309
|
+
matches: { type: "array", items: { type: "object" } },
|
|
12310
|
+
security: { type: "array", items: { type: "object" } }
|
|
12311
|
+
}
|
|
12064
12312
|
},
|
|
12065
12313
|
annotations: READ_ONLY,
|
|
12066
12314
|
async handler(args, context) {
|
|
@@ -12167,6 +12415,7 @@ var locateTool = {
|
|
|
12167
12415
|
}
|
|
12168
12416
|
const shouldText = by === "text" || by === "auto" && matches.length === 0 && rawQuery.length >= 3;
|
|
12169
12417
|
let textCapReason = null;
|
|
12418
|
+
const security = [];
|
|
12170
12419
|
if (shouldText) {
|
|
12171
12420
|
let scanned = 0;
|
|
12172
12421
|
for (const entry of index.manifest.files) {
|
|
@@ -12187,6 +12436,13 @@ var locateTool = {
|
|
|
12187
12436
|
if (!(pattern === null ? line.toLowerCase().includes(needle) : pattern.test(line))) continue;
|
|
12188
12437
|
const from = Math.max(0, lineIndex - contextLines);
|
|
12189
12438
|
const to = Math.min(lines2.length, lineIndex + contextLines + 1);
|
|
12439
|
+
const excerpt = scanHiddenText(lines2.slice(from, to).join("\n").trim());
|
|
12440
|
+
if (excerpt.findings.length > 0) {
|
|
12441
|
+
for (const finding of excerpt.findings) {
|
|
12442
|
+
security.push({ path: entry.relativePath, ...finding, line: lineIndex + 1 });
|
|
12443
|
+
}
|
|
12444
|
+
}
|
|
12445
|
+
if (excerpt.text.trim().length === 0) continue;
|
|
12190
12446
|
textMatches.push({
|
|
12191
12447
|
path: entry.relativePath,
|
|
12192
12448
|
layer: entry.layer,
|
|
@@ -12194,7 +12450,7 @@ var locateTool = {
|
|
|
12194
12450
|
part: entry.part,
|
|
12195
12451
|
matchedBy: "text",
|
|
12196
12452
|
line: lineIndex + 1,
|
|
12197
|
-
text:
|
|
12453
|
+
text: excerpt.text.slice(0, 500)
|
|
12198
12454
|
});
|
|
12199
12455
|
if (textMatches.length >= limit) break;
|
|
12200
12456
|
}
|
|
@@ -12266,6 +12522,7 @@ var locateTool = {
|
|
|
12266
12522
|
structured: {
|
|
12267
12523
|
total: matches.length + textMatches.length,
|
|
12268
12524
|
matches: combined,
|
|
12525
|
+
...security.length === 0 ? {} : { security },
|
|
12269
12526
|
...references.length === 0 ? {} : { references },
|
|
12270
12527
|
trust: index.trust
|
|
12271
12528
|
}
|
|
@@ -12275,7 +12532,7 @@ var locateTool = {
|
|
|
12275
12532
|
var readTool = {
|
|
12276
12533
|
name: "snapshot_read",
|
|
12277
12534
|
title: "Read a redacted line window",
|
|
12278
|
-
description: "Return lines from one redacted file, served by the live index when available. Sensitive paths are never readable, and one response is capped at 64 KiB. Read-only.",
|
|
12535
|
+
description: "Return lines from one redacted file, served by the live index when available. Sensitive paths are never readable, hidden instructions are removed, and one response is capped at 64 KiB. Read-only.",
|
|
12279
12536
|
inputSchema: {
|
|
12280
12537
|
type: "object",
|
|
12281
12538
|
properties: {
|
|
@@ -12298,6 +12555,7 @@ var readTool = {
|
|
|
12298
12555
|
returnedLines: { type: "integer" },
|
|
12299
12556
|
totalLines: { type: "integer" },
|
|
12300
12557
|
pageable: { type: "boolean" },
|
|
12558
|
+
security: { type: "array", items: { type: "object" } },
|
|
12301
12559
|
trust: { type: "object" }
|
|
12302
12560
|
}
|
|
12303
12561
|
},
|
|
@@ -12337,10 +12595,17 @@ var readTool = {
|
|
|
12337
12595
|
if (partTooLargeFor(workspace, entry)) {
|
|
12338
12596
|
return failure(entry.part + " is larger than the " + MAX_PART_READ_BYTES + "-byte read cap; narrow the snapshot or use snapshot_locate.");
|
|
12339
12597
|
}
|
|
12340
|
-
|
|
12598
|
+
let body = bodyFor(workspace, index, entry);
|
|
12341
12599
|
if (body === null) {
|
|
12342
12600
|
return failure(relativePath + " is recorded in " + entry.part + " but its body could not be read. Run snapshot_generate.");
|
|
12343
12601
|
}
|
|
12602
|
+
const security = [];
|
|
12603
|
+
const hidden = scanHiddenText(body);
|
|
12604
|
+
if (hidden.findings.length > 0) {
|
|
12605
|
+
body = hidden.text;
|
|
12606
|
+
for (const finding of hidden.findings) security.push({ path: entry.relativePath, ...finding });
|
|
12607
|
+
index.trust.reasons = [.../* @__PURE__ */ new Set([...index.trust.reasons, security.length + " hidden instruction or invisible character(s) removed"])];
|
|
12608
|
+
}
|
|
12344
12609
|
const window = windowText(body, fromLine, lineCount);
|
|
12345
12610
|
const cappedText = capResultText(window.text, MAX_RESULT_BYTES - 1024);
|
|
12346
12611
|
const bodyLines = cappedText.text.length === 0 ? 0 : cappedText.text.split("\n").length;
|
|
@@ -12370,6 +12635,7 @@ var readTool = {
|
|
|
12370
12635
|
...!clipped && window.truncated ? { nextFromLine: window.fromLine + returnedLines } : {},
|
|
12371
12636
|
truncated: window.truncated || clipped,
|
|
12372
12637
|
pageable: !clipped,
|
|
12638
|
+
security,
|
|
12373
12639
|
trust: index.trust
|
|
12374
12640
|
}
|
|
12375
12641
|
};
|
|
@@ -16566,8 +16832,11 @@ diff, and the commit, are then yours.
|
|
|
16566
16832
|
If the agent runs inside an MCP client, \`npx ${PACKAGE_NAME2}@latest mcp\` serves this repository
|
|
16567
16833
|
as 7 tools over stdio instead of shelling out. Reads are live by default, so uncommitted edits and
|
|
16568
16834
|
new files are overlaid in memory; the snapshot is not required. Excluded files and redacted values
|
|
16569
|
-
never reach the context.
|
|
16570
|
-
|
|
16835
|
+
never reach the context. \`snapshot_context\` starts an explicit symbol at its declaration span
|
|
16836
|
+
(or a requested range), removes hidden instructions, and returns a receipt that hashes exactly
|
|
16837
|
+
what it returned; pass \`signReceipt: true\` with \`SNAPSHOT_SIGNING_KEY\` set to sign it. Use
|
|
16838
|
+
\`snapshot_impact\` before editing, \`snapshot_locate\` before \`snapshot_read\`, and
|
|
16839
|
+
\`snapshot_validate\` before trusting context from an earlier session.
|
|
16571
16840
|
`;
|
|
16572
16841
|
}
|
|
16573
16842
|
|
package/dist/mcp.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import './chunk-WMEZFLUT.js';
|
|
2
|
-
export { ERROR_CODES, LEGACY_PROTOCOL_VERSIONS, MAX_LINE_BYTES, METHOD, MODERN_PROTOCOL_VERSIONS, REPORT_RESOURCE_URIS, RESOURCE_TEMPLATE_URIS, SERVER_INSTRUCTIONS, STATIC_RESOURCE_URIS, SUPPORTED_PROTOCOL_VERSIONS, buildPrompts, buildResourceProvider, buildTools, classifyRequest, coerceNumericStrings, createLineReader, createMcpServer, createServer, createSession, createWriter, findSection, generateInWorker, generateToken, inspectModernMeta, isCommentStrippable, negotiateLegacyVersion, parsePartSections, runStdioServer, startHttpTransport, stripComments, validateArguments, windowText } from './chunk-
|
|
2
|
+
export { ERROR_CODES, LEGACY_PROTOCOL_VERSIONS, MAX_LINE_BYTES, METHOD, MODERN_PROTOCOL_VERSIONS, REPORT_RESOURCE_URIS, RESOURCE_TEMPLATE_URIS, SERVER_INSTRUCTIONS, STATIC_RESOURCE_URIS, SUPPORTED_PROTOCOL_VERSIONS, buildPrompts, buildResourceProvider, buildTools, classifyRequest, coerceNumericStrings, createLineReader, createMcpServer, createServer, createSession, createWriter, findSection, generateInWorker, generateToken, inspectModernMeta, isCommentStrippable, negotiateLegacyVersion, parsePartSections, runStdioServer, startHttpTransport, stripComments, validateArguments, windowText } from './chunk-OVH6B3GV.js';
|
package/docs/agent.md
CHANGED
|
@@ -147,6 +147,9 @@ has an MCP connection, for two reasons that are properties of the design rather
|
|
|
147
147
|
instead.
|
|
148
148
|
- **Staleness is a first-class question.** `snapshot_validate` answers "has the code moved since
|
|
149
149
|
this was built", which an agent with only a filesystem tool has no way to ask.
|
|
150
|
+
- **Context is line-targeted.** `snapshot_context` uses an explicit symbol's declaration span or a
|
|
151
|
+
requested line range, not the file head. It removes hidden instructions and returns a receipt
|
|
152
|
+
that hashes exactly what was shown, so a reviewer can audit the context later.
|
|
150
153
|
|
|
151
154
|
The tools are listed in [the MCP guide](mcp.md) and in the `mcp` block of
|
|
152
155
|
`describe --format json`. A `root` argument may name a sub-directory of the directory the server was
|