codebase-snapshot 0.16.0 → 0.18.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 +699 -0
- package/README.md +4 -3
- package/SECURITY.md +2 -2
- package/dist/bin.js +505 -269
- package/dist/{chunk-ZDTAWUD4.js → chunk-IZPCJYZU.js} +3 -3
- package/dist/{chunk-AEGJYOCF.js → chunk-VMRKUSXL.js} +354 -157
- package/dist/cli.cjs +401 -168
- package/dist/cli.d.cts +2 -2
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +42 -4
- package/dist/{generate-worker-B79yGkQO.d.cts → generate-worker-C6Z1I0XS.d.cts} +3 -0
- package/dist/{generate-worker-B79yGkQO.d.ts → generate-worker-C6Z1I0XS.d.ts} +3 -0
- package/dist/index.cjs +313 -116
- package/dist/index.d.cts +27 -9
- package/dist/index.d.ts +27 -9
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +292 -92
- package/dist/mcp.d.cts +22 -2
- package/dist/mcp.d.ts +22 -2
- package/dist/mcp.js +2 -2
- package/dist/{types-Cr5H2Y3t.d.cts → types-Drw1J0e0.d.cts} +8 -0
- package/dist/{types-Cr5H2Y3t.d.ts → types-Drw1J0e0.d.ts} +8 -0
- package/docs/agent.md +2 -2
- package/docs/answer.md +54 -0
- package/docs/benchmarks.md +4 -2
- package/docs/cli.md +39 -10
- package/docs/configuration.md +1 -1
- package/docs/deploy.md +2 -2
- package/docs/health.md +29 -18
- package/docs/mcp.md +16 -14
- package/docs/migration.md +19 -0
- package/docs/output.md +5 -3
- package/docs/security-review.md +22 -2
- package/docs/serve.md +20 -4
- package/docs/signing.md +3 -1
- package/docs/tools.md +13 -2
- package/package.json +1 -1
package/dist/mcp.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var fs2 = require('fs');
|
|
4
4
|
var path5 = require('path');
|
|
5
|
-
var
|
|
5
|
+
var crypto2 = require('crypto');
|
|
6
6
|
var module$1 = require('module');
|
|
7
7
|
var url = require('url');
|
|
8
8
|
var childProcess = require('child_process');
|
|
@@ -34,7 +34,7 @@ function _interopNamespace(e) {
|
|
|
34
34
|
|
|
35
35
|
var fs2__namespace = /*#__PURE__*/_interopNamespace(fs2);
|
|
36
36
|
var path5__namespace = /*#__PURE__*/_interopNamespace(path5);
|
|
37
|
-
var
|
|
37
|
+
var crypto2__namespace = /*#__PURE__*/_interopNamespace(crypto2);
|
|
38
38
|
var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
|
|
39
39
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
40
40
|
var http__namespace = /*#__PURE__*/_interopNamespace(http);
|
|
@@ -363,7 +363,7 @@ function parseOwnerBrief(filePath, text) {
|
|
|
363
363
|
return {
|
|
364
364
|
brief: {
|
|
365
365
|
path: filePath,
|
|
366
|
-
digest:
|
|
366
|
+
digest: crypto2.createHash("sha256").update(text, "utf8").digest("hex"),
|
|
367
367
|
...recognised["Stakes"] ? { stakes: recognised["Stakes"] } : {},
|
|
368
368
|
...recognised["The system"] ? { system: recognised["The system"] } : {},
|
|
369
369
|
...recognised["What came before"] ? { history: recognised["What came before"] } : {},
|
|
@@ -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.18.0";
|
|
2552
2552
|
var SCHEMA_VERSION = "3.0.0";
|
|
2553
2553
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2554
2554
|
function isOurGeneratorName(name) {
|
|
@@ -2599,6 +2599,7 @@ function getGitInfo(cwd, fallbackBranch = "main") {
|
|
|
2599
2599
|
let branch = fallbackBranch;
|
|
2600
2600
|
let commit = "unknown";
|
|
2601
2601
|
let isDirty = false;
|
|
2602
|
+
let branchFromGit = false;
|
|
2602
2603
|
const records = output.split("\0").flatMap((record) => record.split("\n"));
|
|
2603
2604
|
for (const record of records) {
|
|
2604
2605
|
if (record.length === 0) continue;
|
|
@@ -2614,13 +2615,14 @@ function getGitInfo(cwd, fallbackBranch = "main") {
|
|
|
2614
2615
|
const head = record.match(/^# branch\.head (.+)$/);
|
|
2615
2616
|
if (head) {
|
|
2616
2617
|
branch = head[1] === "(detached)" ? fallbackBranch : head[1];
|
|
2618
|
+
branchFromGit = head[1] !== "(detached)";
|
|
2617
2619
|
}
|
|
2618
2620
|
}
|
|
2619
|
-
return { branch, commit, isDirty };
|
|
2621
|
+
return { branch, commit, isDirty, branchFromGit };
|
|
2620
2622
|
} catch (err) {
|
|
2621
2623
|
const code = err.code;
|
|
2622
2624
|
const isDirty = code === "ENOBUFS";
|
|
2623
|
-
return { branch: fallbackBranch, commit: "unknown", isDirty };
|
|
2625
|
+
return { branch: fallbackBranch, commit: "unknown", isDirty, branchFromGit: false };
|
|
2624
2626
|
}
|
|
2625
2627
|
}
|
|
2626
2628
|
var DEFAULT_IGNORED_DIRS = [
|
|
@@ -3666,7 +3668,7 @@ function readConfigExport(exported, file) {
|
|
|
3666
3668
|
var lastModuleConfig = null;
|
|
3667
3669
|
function moduleConfigKey(fullPath) {
|
|
3668
3670
|
try {
|
|
3669
|
-
return
|
|
3671
|
+
return crypto2.createHash("sha256").update(fs2__namespace.readFileSync(fullPath)).digest("hex").slice(0, 24);
|
|
3670
3672
|
} catch {
|
|
3671
3673
|
try {
|
|
3672
3674
|
const stats = fs2__namespace.statSync(fullPath);
|
|
@@ -4514,7 +4516,7 @@ function configDigest(config) {
|
|
|
4514
4516
|
(rule) => `${rule.rule}:${rule.pattern.source}/${rule.pattern.flags}:${rule.valueGroup ?? ""}`
|
|
4515
4517
|
).sort()
|
|
4516
4518
|
};
|
|
4517
|
-
return
|
|
4519
|
+
return crypto2.createHash("sha256").update(JSON.stringify(material)).digest("hex");
|
|
4518
4520
|
}
|
|
4519
4521
|
|
|
4520
4522
|
// src/ast/profiles/shared.ts
|
|
@@ -5335,7 +5337,7 @@ function summarizeTypeScriptSource(relativePath, content) {
|
|
|
5335
5337
|
}
|
|
5336
5338
|
const callee = node.expression;
|
|
5337
5339
|
if (ts__default.default.isPropertyAccessExpression(callee) && ts__default.default.isIdentifier(callee.expression) && ROUTE_RECEIVERS.has(callee.expression.text) && ROUTE_REGISTRATION_VERBS.has(callee.name.text.toLowerCase()) && firstArgument !== void 0 && ts__default.default.isStringLiteral(firstArgument)) {
|
|
5338
|
-
summary.routeHandlers.push(callee.name.text.toUpperCase());
|
|
5340
|
+
summary.routeHandlers.push(callee.name.text.toUpperCase() + " " + firstArgument.text);
|
|
5339
5341
|
}
|
|
5340
5342
|
}
|
|
5341
5343
|
if (ts__default.default.isExportDeclaration(node)) {
|
|
@@ -6079,7 +6081,7 @@ function capValue(value, max) {
|
|
|
6079
6081
|
var displayPath = (value) => capValue(escapeControls(value), DISPLAY_PATH_MAX);
|
|
6080
6082
|
function anchorForPath(filePath) {
|
|
6081
6083
|
const slug = filePath.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
6082
|
-
const digest =
|
|
6084
|
+
const digest = crypto2__namespace.createHash("sha256").update(filePath).digest("hex").slice(0, 8);
|
|
6083
6085
|
return `${slug || "file"}-${digest}`;
|
|
6084
6086
|
}
|
|
6085
6087
|
|
|
@@ -6269,13 +6271,19 @@ function planForQuestion(manifest, question, options = {}) {
|
|
|
6269
6271
|
scored.push({ file, score, why: reasons.slice(0, 3).join(", ") || "centrality " + hub });
|
|
6270
6272
|
}
|
|
6271
6273
|
const notes = [];
|
|
6274
|
+
if (manifest.files.length === 0) {
|
|
6275
|
+
notes.push("The snapshot holds no files; there is nothing to plan. Check manifest.skipped for why paths were not emitted.");
|
|
6276
|
+
return { question, budgetTokens: budget, usedTokens: 0, files: [], skipped: [], notes };
|
|
6277
|
+
}
|
|
6272
6278
|
if (scored.length === 0) {
|
|
6273
|
-
notes.push("No file matched the question's terms; the plan falls back to the most-imported files.");
|
|
6274
6279
|
const hubs = manifest.indexes.imports.centralFiles.slice(0, 12);
|
|
6275
6280
|
for (const hub of hubs) {
|
|
6276
6281
|
const file = byPath.get(hub.path);
|
|
6277
6282
|
if (file !== void 0) scored.push({ file, score: 1, why: "hub, " + hub.importedByCount + " importers" });
|
|
6278
6283
|
}
|
|
6284
|
+
if (scored.length > 0) {
|
|
6285
|
+
notes.push("No file matched the question's terms; the plan falls back to the most-imported files.");
|
|
6286
|
+
}
|
|
6279
6287
|
}
|
|
6280
6288
|
scored.sort((left, right) => right.score - left.score || left.file.relativePath.localeCompare(right.file.relativePath));
|
|
6281
6289
|
const chosen = /* @__PURE__ */ new Map();
|
|
@@ -6339,7 +6347,14 @@ function planForQuestion(manifest, question, options = {}) {
|
|
|
6339
6347
|
}
|
|
6340
6348
|
}
|
|
6341
6349
|
}
|
|
6342
|
-
if (chosen.size === 0)
|
|
6350
|
+
if (chosen.size === 0) {
|
|
6351
|
+
if (scored.length === 0) {
|
|
6352
|
+
notes.push("No candidate file matched the question, and this snapshot has no centrality data to fall back on.");
|
|
6353
|
+
} else {
|
|
6354
|
+
const cheapest = scored.reduce((minimum, item) => Math.min(minimum, Math.ceil(item.file.includedBytes / 4)), Infinity);
|
|
6355
|
+
notes.push("Nothing fit the budget: the cheapest candidate costs about " + formatNumber(cheapest) + " tokens.");
|
|
6356
|
+
}
|
|
6357
|
+
}
|
|
6343
6358
|
notes.push(
|
|
6344
6359
|
formatNumber(chosen.size) + " file(s) chosen of " + formatNumber(manifest.files.length) + " in the snapshot; " + formatNumber(skipped.length) + " skipped for budget."
|
|
6345
6360
|
);
|
|
@@ -6519,6 +6534,48 @@ var RUBY_EXTENSIONS = /* @__PURE__ */ new Set([".rb", ".rake", ".gemspec"]);
|
|
|
6519
6534
|
var C_EXTENSIONS = /* @__PURE__ */ new Set([".c", ".h", ".cc", ".cpp", ".cxx", ".hpp", ".hxx", ".m", ".mm"]);
|
|
6520
6535
|
var PYTHON_SUFFIXES = [".py", ".pyi", "/__init__.py", "/__init__.pyi"];
|
|
6521
6536
|
var CASE_INSENSITIVE_FILESYSTEM = process.platform === "win32" || process.platform === "darwin";
|
|
6537
|
+
var TSCONFIG_CACHE = /* @__PURE__ */ new Map();
|
|
6538
|
+
function tsconfigPathsFor(cwd) {
|
|
6539
|
+
const configPath = path5__namespace.join(cwd, "tsconfig.json");
|
|
6540
|
+
let stats;
|
|
6541
|
+
try {
|
|
6542
|
+
stats = fs2__namespace.statSync(configPath);
|
|
6543
|
+
} catch (err) {
|
|
6544
|
+
if (err.code === "ENOENT") return null;
|
|
6545
|
+
return null;
|
|
6546
|
+
}
|
|
6547
|
+
const key = `${stats.mtimeMs}:${stats.size}`;
|
|
6548
|
+
const cached = TSCONFIG_CACHE.get(configPath);
|
|
6549
|
+
if (cached !== void 0 && cached.key === key) return cached.value;
|
|
6550
|
+
let value = null;
|
|
6551
|
+
try {
|
|
6552
|
+
const read = ts__default.default.readConfigFile(configPath, ts__default.default.sys.readFile);
|
|
6553
|
+
if (read.error === void 0) {
|
|
6554
|
+
const parsed = ts__default.default.parseJsonConfigFileContent(read.config, ts__default.default.sys, cwd, void 0, configPath);
|
|
6555
|
+
const options = parsed.options;
|
|
6556
|
+
const baseUrl = typeof options.baseUrl === "string" ? repositoryRelative(cwd, options.baseUrl) : null;
|
|
6557
|
+
const rules = [];
|
|
6558
|
+
if (options.paths !== void 0) {
|
|
6559
|
+
for (const [pattern, targets] of Object.entries(options.paths)) {
|
|
6560
|
+
if (!Array.isArray(targets)) continue;
|
|
6561
|
+
rules.push({
|
|
6562
|
+
pattern,
|
|
6563
|
+
targets: targets.map((target) => String(target).replace(/\\/g, "/"))
|
|
6564
|
+
});
|
|
6565
|
+
}
|
|
6566
|
+
}
|
|
6567
|
+
if (baseUrl !== null || rules.length > 0) value = { baseUrl, paths: rules };
|
|
6568
|
+
}
|
|
6569
|
+
} catch (err) {
|
|
6570
|
+
value = null;
|
|
6571
|
+
}
|
|
6572
|
+
TSCONFIG_CACHE.set(configPath, { key, value });
|
|
6573
|
+
return value;
|
|
6574
|
+
}
|
|
6575
|
+
function repositoryRelative(cwd, target) {
|
|
6576
|
+
const relative9 = path5__namespace.relative(cwd, target).replace(/\\/g, "/");
|
|
6577
|
+
return relative9.length === 0 || !relative9.startsWith("..") && !path5__namespace.isAbsolute(relative9) ? relative9 : null;
|
|
6578
|
+
}
|
|
6522
6579
|
function rememberFirst(map, key, value) {
|
|
6523
6580
|
if (!map.has(key)) map.set(key, value);
|
|
6524
6581
|
}
|
|
@@ -6710,6 +6767,41 @@ function detectLanguage(filePath) {
|
|
|
6710
6767
|
const ext = path5__namespace.posix.extname(base).toLowerCase();
|
|
6711
6768
|
return LANGUAGE_BY_EXTENSION[ext] ?? "text";
|
|
6712
6769
|
}
|
|
6770
|
+
var SIGNATURE_FILE = "signature.json";
|
|
6771
|
+
function verifySnapshotSignature(snapshotDir) {
|
|
6772
|
+
const signaturePath = path5__namespace.join(snapshotDir, SIGNATURE_FILE);
|
|
6773
|
+
const manifestPath = path5__namespace.join(snapshotDir, "manifest.json");
|
|
6774
|
+
if (!fs2__namespace.existsSync(signaturePath)) return { ok: false, reason: "no signature.json in this snapshot" };
|
|
6775
|
+
let record;
|
|
6776
|
+
try {
|
|
6777
|
+
record = JSON.parse(fs2__namespace.readFileSync(signaturePath, "utf8"));
|
|
6778
|
+
} catch (error) {
|
|
6779
|
+
return { ok: false, reason: "signature.json is not JSON: " + error.message };
|
|
6780
|
+
}
|
|
6781
|
+
if (record.algorithm !== "ed25519" || typeof record.signature !== "string" || typeof record.publicKey !== "string") {
|
|
6782
|
+
return { ok: false, reason: "signature.json is not an ed25519 record" };
|
|
6783
|
+
}
|
|
6784
|
+
let bytes;
|
|
6785
|
+
try {
|
|
6786
|
+
bytes = fs2__namespace.readFileSync(manifestPath);
|
|
6787
|
+
} catch {
|
|
6788
|
+
return { ok: false, reason: "the signed manifest is missing" };
|
|
6789
|
+
}
|
|
6790
|
+
const sha2562 = crypto2__namespace.createHash("sha256").update(bytes).digest("hex");
|
|
6791
|
+
if (sha2562 !== record.manifestSha256) {
|
|
6792
|
+
return { ok: false, reason: "manifest.json changed after it was signed" };
|
|
6793
|
+
}
|
|
6794
|
+
let verified = false;
|
|
6795
|
+
try {
|
|
6796
|
+
const key = crypto2__namespace.createPublicKey({ key: Buffer.from(record.publicKey, "base64"), format: "der", type: "spki" });
|
|
6797
|
+
verified = crypto2__namespace.verify(null, bytes, key, Buffer.from(record.signature, "base64"));
|
|
6798
|
+
} catch (error) {
|
|
6799
|
+
return { ok: false, reason: "the signature could not be checked: " + error.message };
|
|
6800
|
+
}
|
|
6801
|
+
return verified ? { ok: true, record } : { ok: false, reason: "the signature does not match the manifest" };
|
|
6802
|
+
}
|
|
6803
|
+
|
|
6804
|
+
// src/validator/validate.ts
|
|
6713
6805
|
function maskedPath(value, secretRules) {
|
|
6714
6806
|
return findSecretInPath(value, secretRules)?.masked ?? value;
|
|
6715
6807
|
}
|
|
@@ -6773,7 +6865,7 @@ function emptyDrift() {
|
|
|
6773
6865
|
};
|
|
6774
6866
|
}
|
|
6775
6867
|
function sha256Hex(buffer) {
|
|
6776
|
-
return
|
|
6868
|
+
return crypto2__namespace.createHash("sha256").update(buffer).digest("hex");
|
|
6777
6869
|
}
|
|
6778
6870
|
function wouldNowBeIncluded(cwd, relativePath) {
|
|
6779
6871
|
const absolutePath = path5__namespace.join(cwd, relativePath);
|
|
@@ -7710,6 +7802,11 @@ function validateSnapshot(configInput) {
|
|
|
7710
7802
|
`${drift.configMismatches.length} configuration mismatch(es) between the manifest and this run.`
|
|
7711
7803
|
);
|
|
7712
7804
|
}
|
|
7805
|
+
const signaturePath = path5__namespace.join(path5__namespace.dirname(manifestPath), "signature.json");
|
|
7806
|
+
if (fs2__namespace.existsSync(signaturePath)) {
|
|
7807
|
+
const outcome = verifySnapshotSignature(path5__namespace.dirname(manifestPath));
|
|
7808
|
+
if (!outcome.ok) errors.push("signature: " + outcome.reason + ".");
|
|
7809
|
+
}
|
|
7713
7810
|
if (manifest.slice !== void 0 || manifest.budget !== void 0) {
|
|
7714
7811
|
warnings.push(
|
|
7715
7812
|
"This snapshot is a selection (" + (manifest.slice !== void 0 ? "--slice" : "--budget-tokens") + "); validate checks what is present and does not re-run the planner, so a file the selection left out is not reported as missing."
|
|
@@ -8004,39 +8101,6 @@ var PROMPTS = [
|
|
|
8004
8101
|
function buildPrompts() {
|
|
8005
8102
|
return PROMPTS;
|
|
8006
8103
|
}
|
|
8007
|
-
var SIGNATURE_FILE = "signature.json";
|
|
8008
|
-
function verifySnapshotSignature(snapshotDir) {
|
|
8009
|
-
const signaturePath = path5__namespace.join(snapshotDir, SIGNATURE_FILE);
|
|
8010
|
-
const manifestPath = path5__namespace.join(snapshotDir, "manifest.json");
|
|
8011
|
-
if (!fs2__namespace.existsSync(signaturePath)) return { ok: false, reason: "no signature.json in this snapshot" };
|
|
8012
|
-
let record;
|
|
8013
|
-
try {
|
|
8014
|
-
record = JSON.parse(fs2__namespace.readFileSync(signaturePath, "utf8"));
|
|
8015
|
-
} catch (error) {
|
|
8016
|
-
return { ok: false, reason: "signature.json is not JSON: " + error.message };
|
|
8017
|
-
}
|
|
8018
|
-
if (record.algorithm !== "ed25519" || typeof record.signature !== "string" || typeof record.publicKey !== "string") {
|
|
8019
|
-
return { ok: false, reason: "signature.json is not an ed25519 record" };
|
|
8020
|
-
}
|
|
8021
|
-
let bytes;
|
|
8022
|
-
try {
|
|
8023
|
-
bytes = fs2__namespace.readFileSync(manifestPath);
|
|
8024
|
-
} catch {
|
|
8025
|
-
return { ok: false, reason: "the signed manifest is missing" };
|
|
8026
|
-
}
|
|
8027
|
-
const sha2562 = crypto3__namespace.createHash("sha256").update(bytes).digest("hex");
|
|
8028
|
-
if (sha2562 !== record.manifestSha256) {
|
|
8029
|
-
return { ok: false, reason: "manifest.json changed after it was signed" };
|
|
8030
|
-
}
|
|
8031
|
-
let verified = false;
|
|
8032
|
-
try {
|
|
8033
|
-
const key = crypto3__namespace.createPublicKey({ key: Buffer.from(record.publicKey, "base64"), format: "der", type: "spki" });
|
|
8034
|
-
verified = crypto3__namespace.verify(null, bytes, key, Buffer.from(record.signature, "base64"));
|
|
8035
|
-
} catch (error) {
|
|
8036
|
-
return { ok: false, reason: "the signature could not be checked: " + error.message };
|
|
8037
|
-
}
|
|
8038
|
-
return verified ? { ok: true, record } : { ok: false, reason: "the signature does not match the manifest" };
|
|
8039
|
-
}
|
|
8040
8104
|
|
|
8041
8105
|
// src/partitioner/part-format.ts
|
|
8042
8106
|
var FILE_HEADING = "### FILE: ";
|
|
@@ -8142,7 +8206,7 @@ var ARTIFACT_FILES = {
|
|
|
8142
8206
|
};
|
|
8143
8207
|
var TEXT_ARTIFACT = /\.(md|json|txt|sarif)$/i;
|
|
8144
8208
|
function sha256(buffer) {
|
|
8145
|
-
return
|
|
8209
|
+
return crypto2.createHash("sha256").update(buffer).digest("hex");
|
|
8146
8210
|
}
|
|
8147
8211
|
function readBytes(file) {
|
|
8148
8212
|
try {
|
|
@@ -8617,8 +8681,9 @@ function auditSnapshot(options) {
|
|
|
8617
8681
|
if (typeof member.files === "number" && member.files !== manifest.counts.totalFiles) {
|
|
8618
8682
|
disagreements.push("file count");
|
|
8619
8683
|
}
|
|
8684
|
+
const sourceGone = typeof member.path === "string" && !fs2__namespace.existsSync(member.path) ? "Member " + memberName + " source directory is gone (" + member.path + "); the snapshot still describes it. Regenerate the workspace." : null;
|
|
8620
8685
|
checks.push(
|
|
8621
|
-
disagreements.length === 0 ? check(
|
|
8686
|
+
sourceGone !== null ? check("workspace.index", "The workspace index agrees with this member", "warning", "warn", sourceGone) : disagreements.length === 0 ? check(
|
|
8622
8687
|
"workspace.index",
|
|
8623
8688
|
"The workspace index agrees with this member",
|
|
8624
8689
|
"warning",
|
|
@@ -8640,6 +8705,7 @@ function auditSnapshot(options) {
|
|
|
8640
8705
|
let scannedBytes = 0;
|
|
8641
8706
|
for (const relative9 of walk(snapshotDir)) {
|
|
8642
8707
|
if (!TEXT_ARTIFACT.test(relative9) || scannedBytes > scanBudget) continue;
|
|
8708
|
+
if (relative9 === SIGNATURE_FILE) continue;
|
|
8643
8709
|
const text = readText(path5__namespace.join(snapshotDir, relative9));
|
|
8644
8710
|
if (text === null) continue;
|
|
8645
8711
|
scannedBytes += Buffer.byteLength(text, "utf8");
|
|
@@ -8648,6 +8714,28 @@ function auditSnapshot(options) {
|
|
|
8648
8714
|
leakHits.push(relative9 + " (" + found.findings.length + " line(s))");
|
|
8649
8715
|
}
|
|
8650
8716
|
}
|
|
8717
|
+
const signatureRecordPath = path5__namespace.join(snapshotDir, SIGNATURE_FILE);
|
|
8718
|
+
if (fs2__namespace.existsSync(signatureRecordPath)) {
|
|
8719
|
+
const recordText = readText(signatureRecordPath);
|
|
8720
|
+
if (recordText !== null) {
|
|
8721
|
+
scannedBytes += Buffer.byteLength(recordText, "utf8");
|
|
8722
|
+
let scanText = recordText;
|
|
8723
|
+
try {
|
|
8724
|
+
const record = JSON.parse(recordText);
|
|
8725
|
+
const rest = { ...record };
|
|
8726
|
+
delete rest.publicKey;
|
|
8727
|
+
delete rest.signature;
|
|
8728
|
+
delete rest.manifestSha256;
|
|
8729
|
+
delete rest.fingerprint;
|
|
8730
|
+
scanText = JSON.stringify(rest, null, 2);
|
|
8731
|
+
} catch {
|
|
8732
|
+
}
|
|
8733
|
+
const found = scanAndRedactSecrets(scanText, rules, SIGNATURE_FILE);
|
|
8734
|
+
if (found.findings.length > 0) {
|
|
8735
|
+
leakHits.push(SIGNATURE_FILE + " (" + found.findings.length + " line(s))");
|
|
8736
|
+
}
|
|
8737
|
+
}
|
|
8738
|
+
}
|
|
8651
8739
|
checks.push(
|
|
8652
8740
|
leakHits.length === 0 ? check(
|
|
8653
8741
|
"secrets.artifacts",
|
|
@@ -9381,6 +9469,10 @@ var WRITES = {
|
|
|
9381
9469
|
openWorldHint: false
|
|
9382
9470
|
};
|
|
9383
9471
|
var MAX_RESULT_BYTES = 64 * 1024;
|
|
9472
|
+
function capResultText(text) {
|
|
9473
|
+
const clipped = truncateToBytes(text, MAX_RESULT_BYTES);
|
|
9474
|
+
return { text: clipped.isTruncated ? clipped.content : text, clipped: clipped.isTruncated };
|
|
9475
|
+
}
|
|
9384
9476
|
var ROOT_PROPERTY = {
|
|
9385
9477
|
type: "string",
|
|
9386
9478
|
description: "Repository root. Defaults to the directory this server was started in."
|
|
@@ -9568,6 +9660,17 @@ var historyTool = {
|
|
|
9568
9660
|
isError: true
|
|
9569
9661
|
};
|
|
9570
9662
|
}
|
|
9663
|
+
const manifestRead = readManifest3(prepared.workspace);
|
|
9664
|
+
const recordedLog = manifestRead.ok ? manifestRead.manifest.artifacts?.log : void 0;
|
|
9665
|
+
if (recordedLog !== void 0 && recordedLog !== null) {
|
|
9666
|
+
const digest = crypto2.createHash("sha256").update(text, "utf8").digest("hex");
|
|
9667
|
+
if (digest !== recordedLog.sha256) {
|
|
9668
|
+
return {
|
|
9669
|
+
text: "reports/log.md changed after the snapshot was generated (its digest no longer matches the manifest). Regenerate the snapshot rather than trusting this history.",
|
|
9670
|
+
isError: true
|
|
9671
|
+
};
|
|
9672
|
+
}
|
|
9673
|
+
}
|
|
9571
9674
|
const limit = Math.max(1, typeof args.limit === "number" ? args.limit : 20);
|
|
9572
9675
|
const commits = parseHistoryReport(text).slice(0, limit);
|
|
9573
9676
|
return {
|
|
@@ -9627,9 +9730,12 @@ var budgetTool = {
|
|
|
9627
9730
|
});
|
|
9628
9731
|
}
|
|
9629
9732
|
const lines = [question === "" ? "No question: planning for the repository as a whole." : "Question: " + question];
|
|
9733
|
+
if (read.manifest.files.length === 0) {
|
|
9734
|
+
lines.push("The snapshot holds no files, so every budget selects nothing. Check manifest.skipped for why.");
|
|
9735
|
+
}
|
|
9630
9736
|
for (const row of rows) {
|
|
9631
9737
|
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" : "") + ")")
|
|
9738
|
+
row.budget.toLocaleString("en-US") + " tokens: " + row.files + " file(s), " + row.usedTokens.toLocaleString("en-US") + " used" + (row.files === 0 && read.manifest.files.length > 0 ? " - no file fits this budget" : "") + (row.gained.length === 0 ? "" : ", " + row.gained.length + " gained (" + row.gained.slice(0, 4).join(", ") + (row.gained.length > 4 ? ", \u2026" : "") + ")")
|
|
9633
9739
|
);
|
|
9634
9740
|
}
|
|
9635
9741
|
return { text: lines.join("\n"), structured: { budgets: rows } };
|
|
@@ -9881,7 +9987,7 @@ var routesTool = {
|
|
|
9881
9987
|
routes.sort((left, right) => left.path.localeCompare(right.path) || left.route.localeCompare(right.route));
|
|
9882
9988
|
const text = routes.length === 0 ? "No route was recorded. Routes come from decorators, framework attributes and route tables." : [
|
|
9883
9989
|
routes.length + " route(s):",
|
|
9884
|
-
...routes.map((route) => route.route + " (" + route.path + ", " + route.part + ")")
|
|
9990
|
+
...routes.map((route) => route.route.trim() + " (" + route.path + ", " + route.part + ")")
|
|
9885
9991
|
].join("\n");
|
|
9886
9992
|
return { text, structured: { total: routes.length, routes } };
|
|
9887
9993
|
}
|
|
@@ -10050,8 +10156,9 @@ var searchTool = {
|
|
|
10050
10156
|
}
|
|
10051
10157
|
}
|
|
10052
10158
|
}
|
|
10159
|
+
const matchedFiles = new Set(matches.map((match) => match.path)).size;
|
|
10053
10160
|
const lines = [
|
|
10054
|
-
matches.length
|
|
10161
|
+
matches.length === 0 ? "No match in " + read.manifest.files.length + " file(s)." : matches.length + " match(es) in " + matchedFiles + " file(s) of " + read.manifest.files.length + " searched." + (truncated ? " Results are capped, so not every file was searched; narrow the query." : ""),
|
|
10055
10162
|
...skippedOversize.length > 0 ? ["Skipped " + skippedOversize.length + " oversized part(s): " + skippedOversize.slice(0, 5).join(", ")] : [],
|
|
10056
10163
|
...matches.map((match) => match.path + ":" + match.line + " (" + match.part + "): " + match.text)
|
|
10057
10164
|
];
|
|
@@ -10074,7 +10181,9 @@ var statsTool = {
|
|
|
10074
10181
|
parts: { type: "integer" },
|
|
10075
10182
|
tokens: { type: "integer" },
|
|
10076
10183
|
layers: { type: "object" },
|
|
10077
|
-
kinds: { type: "object" }
|
|
10184
|
+
kinds: { type: "object" },
|
|
10185
|
+
heaviest: { type: "array", items: { type: "object" } },
|
|
10186
|
+
partSizes: { type: "array", items: { type: "object" } }
|
|
10078
10187
|
}
|
|
10079
10188
|
},
|
|
10080
10189
|
annotations: READ_ONLY,
|
|
@@ -10085,7 +10194,11 @@ var statsTool = {
|
|
|
10085
10194
|
if (!read.ok) return { text: read.message + " Call snapshot_generate first.", isError: true };
|
|
10086
10195
|
const manifest = read.manifest;
|
|
10087
10196
|
const heaviest = [...manifest.files].sort((left, right) => right.includedBytes - left.includedBytes).slice(0, 10).map((file) => ({ path: file.relativePath, tokens: Math.ceil(file.includedBytes / 4), part: file.part }));
|
|
10088
|
-
const parts = manifest.parts.map((part) => ({
|
|
10197
|
+
const parts = manifest.parts.map((part) => ({
|
|
10198
|
+
filename: part.filename,
|
|
10199
|
+
bytes: part.byteSize,
|
|
10200
|
+
tokens: part.estimatedTokens
|
|
10201
|
+
}));
|
|
10089
10202
|
const lines = [
|
|
10090
10203
|
manifest.counts.totalFiles + " file(s) in " + manifest.counts.partsCount + " part(s), " + (manifest.totals.estimatedTokens ?? 0) + " estimated tokens.",
|
|
10091
10204
|
"Layers: " + Object.entries(manifest.layers).map(([name, count]) => name + "=" + count).join(", "),
|
|
@@ -10141,7 +10254,7 @@ var reviewTool = {
|
|
|
10141
10254
|
if (!read.ok) return { text: read.message + " Call snapshot_generate first.", isError: true };
|
|
10142
10255
|
let validation;
|
|
10143
10256
|
try {
|
|
10144
|
-
validation = validateSnapshot(workspace.
|
|
10257
|
+
validation = validateSnapshot(configAsGenerated(workspace, read.manifest));
|
|
10145
10258
|
} catch (error) {
|
|
10146
10259
|
return { text: error.message, isError: true };
|
|
10147
10260
|
}
|
|
@@ -10241,24 +10354,17 @@ var diffContextTool = {
|
|
|
10241
10354
|
const budget = Math.max(500, typeof args.maxTokens === "number" ? args.maxTokens : 15e3);
|
|
10242
10355
|
const linesPerFile = Math.max(10, typeof args.linesPerFile === "number" ? args.linesPerFile : 80);
|
|
10243
10356
|
const byPath = new Map(read.manifest.files.map((file) => [file.relativePath.toLowerCase(), file]));
|
|
10357
|
+
const resolver = buildImportResolver(read.manifest.files, {
|
|
10358
|
+
tsconfig: tsconfigPathsFor(workspace.root)
|
|
10359
|
+
});
|
|
10244
10360
|
const importers = /* @__PURE__ */ new Map();
|
|
10245
10361
|
for (const entry of read.manifest.indexes.imports.byFile) {
|
|
10246
10362
|
for (const specifier of entry.imports) {
|
|
10247
|
-
|
|
10248
|
-
|
|
10249
|
-
const
|
|
10250
|
-
for (const segment of (base + "/" + specifier).split("/")) {
|
|
10251
|
-
if (segment === "" || segment === ".") continue;
|
|
10252
|
-
if (segment === "..") parts.pop();
|
|
10253
|
-
else parts.push(segment);
|
|
10254
|
-
}
|
|
10255
|
-
const joined = parts.join("/").toLowerCase();
|
|
10256
|
-
const withoutExtension = joined.replace(/\.[cm]?[jt]sx?$/, "");
|
|
10257
|
-
const target = byPath.get(joined) ?? byPath.get(withoutExtension + ".ts") ?? byPath.get(withoutExtension + ".tsx") ?? byPath.get(withoutExtension + ".js") ?? byPath.get(withoutExtension + ".py") ?? byPath.get(withoutExtension + "/index.ts") ?? byPath.get(withoutExtension);
|
|
10258
|
-
if (target === void 0) continue;
|
|
10259
|
-
const list = importers.get(target.relativePath) ?? [];
|
|
10363
|
+
const target = resolveSpecifier(entry.path, specifier, resolver);
|
|
10364
|
+
if (target === null) continue;
|
|
10365
|
+
const list = importers.get(target) ?? [];
|
|
10260
10366
|
list.push(entry.path);
|
|
10261
|
-
importers.set(target
|
|
10367
|
+
importers.set(target, list);
|
|
10262
10368
|
}
|
|
10263
10369
|
}
|
|
10264
10370
|
const missing = [];
|
|
@@ -10293,9 +10399,12 @@ var diffContextTool = {
|
|
|
10293
10399
|
continue;
|
|
10294
10400
|
}
|
|
10295
10401
|
used += tokens;
|
|
10402
|
+
const capped2 = capResultText(window.text);
|
|
10296
10403
|
changed.push({ path: file.relativePath, part: file.part, tokens });
|
|
10297
|
-
text.push(
|
|
10298
|
-
|
|
10404
|
+
text.push(
|
|
10405
|
+
"### " + file.relativePath + " (" + file.part + (capped2.clipped ? ", first 64 KiB" : "") + ")"
|
|
10406
|
+
);
|
|
10407
|
+
text.push(capped2.text);
|
|
10299
10408
|
}
|
|
10300
10409
|
const dependents = [];
|
|
10301
10410
|
for (const entry of changed) {
|
|
@@ -10377,11 +10486,13 @@ var symbolTool = {
|
|
|
10377
10486
|
if (index === -1) continue;
|
|
10378
10487
|
const from = Math.max(0, index - 3);
|
|
10379
10488
|
const to = Math.min(lines.length, index + windowSize);
|
|
10489
|
+
const capped2 = capResultText(lines.slice(from, to).join("\n"));
|
|
10380
10490
|
matches.push({
|
|
10381
10491
|
path: file.relativePath,
|
|
10382
10492
|
part: file.part,
|
|
10383
10493
|
line: index + 1,
|
|
10384
|
-
text:
|
|
10494
|
+
text: capped2.text,
|
|
10495
|
+
...capped2.clipped ? { clippedAtBytes: MAX_RESULT_BYTES } : {}
|
|
10385
10496
|
});
|
|
10386
10497
|
}
|
|
10387
10498
|
if (matches.length === 0) {
|
|
@@ -10512,7 +10623,8 @@ var contextTool = {
|
|
|
10512
10623
|
continue;
|
|
10513
10624
|
}
|
|
10514
10625
|
const window = windowText(section.body, 1, linesPerFile);
|
|
10515
|
-
const
|
|
10626
|
+
const capped2 = capResultText(window.text);
|
|
10627
|
+
const body = capped2.text;
|
|
10516
10628
|
let tokens = Math.max(1, Math.ceil(Buffer.byteLength(body, "utf8") / 4));
|
|
10517
10629
|
if (used + tokens > budget) {
|
|
10518
10630
|
const keep = Math.max(4, Math.floor((budget - used) / tokens * linesPerFile));
|
|
@@ -10521,14 +10633,19 @@ var contextTool = {
|
|
|
10521
10633
|
missing.push(file.relativePath + " (budget)");
|
|
10522
10634
|
continue;
|
|
10523
10635
|
}
|
|
10524
|
-
const
|
|
10525
|
-
|
|
10526
|
-
text.push(
|
|
10636
|
+
const smallerCapped = capResultText(smaller.text);
|
|
10637
|
+
const partial = Math.max(1, Math.ceil(Buffer.byteLength(smallerCapped.text, "utf8") / 4));
|
|
10638
|
+
text.push(
|
|
10639
|
+
"### " + file.relativePath + " (" + file.part + ", first " + Math.max(4, keep) + " lines" + (smallerCapped.clipped ? ", first 64 KiB" : "") + ")"
|
|
10640
|
+
);
|
|
10641
|
+
text.push(smallerCapped.text);
|
|
10527
10642
|
blocks.push({ path: file.relativePath, part: file.part, lines: Math.max(4, keep), tokens: partial });
|
|
10528
10643
|
used += partial;
|
|
10529
10644
|
continue;
|
|
10530
10645
|
}
|
|
10531
|
-
text.push(
|
|
10646
|
+
text.push(
|
|
10647
|
+
"### " + file.relativePath + " (" + file.part + (capped2.clipped ? ", first 64 KiB" : "") + ")"
|
|
10648
|
+
);
|
|
10532
10649
|
text.push(body);
|
|
10533
10650
|
blocks.push({ path: file.relativePath, part: file.part, lines: window.text === "" ? 0 : window.text.split("\n").length, tokens });
|
|
10534
10651
|
used += tokens;
|
|
@@ -10702,8 +10819,17 @@ var answerTool = {
|
|
|
10702
10819
|
maxTokens,
|
|
10703
10820
|
...args.includeTests === true ? { includeTests: true } : {}
|
|
10704
10821
|
});
|
|
10822
|
+
if (read.manifest.files.length === 0) {
|
|
10823
|
+
return {
|
|
10824
|
+
text: "The snapshot holds no files, so nothing can be assembled for this question. manifest.skipped records why paths were not emitted (excluded, binary, unchanged).",
|
|
10825
|
+
structured: { question, budgetTokens: maxTokens, usedTokens: 0, files: [], omitted: [] }
|
|
10826
|
+
};
|
|
10827
|
+
}
|
|
10705
10828
|
const blocks = [];
|
|
10706
|
-
const omitted =
|
|
10829
|
+
const omitted = plan.skipped.map((entry) => ({
|
|
10830
|
+
path: entry.path,
|
|
10831
|
+
reason: entry.reason
|
|
10832
|
+
}));
|
|
10707
10833
|
let used = 0;
|
|
10708
10834
|
const parts = /* @__PURE__ */ new Map();
|
|
10709
10835
|
for (const planned of plan.files) {
|
|
@@ -10732,14 +10858,23 @@ var answerTool = {
|
|
|
10732
10858
|
continue;
|
|
10733
10859
|
}
|
|
10734
10860
|
const window = windowText(section.body, 1, linesPerFile);
|
|
10735
|
-
const
|
|
10736
|
-
const
|
|
10861
|
+
const numbered = window.text.split("\n").map((line, index) => String(index + 1).padStart(5, " ") + " " + line).join("\n");
|
|
10862
|
+
const clipped = truncateToBytes(numbered, MAX_RESULT_BYTES);
|
|
10863
|
+
const bodyText = clipped.isTruncated ? clipped.content : numbered;
|
|
10864
|
+
const tokens = estimateTokens(bodyText);
|
|
10737
10865
|
if (used + tokens > maxTokens && blocks.length > 0) {
|
|
10738
10866
|
omitted.push({ path: planned.path, reason: "did not fit the remaining budget" });
|
|
10739
10867
|
continue;
|
|
10740
10868
|
}
|
|
10741
|
-
|
|
10742
|
-
|
|
10869
|
+
blocks.push({
|
|
10870
|
+
path: planned.path,
|
|
10871
|
+
why: planned.why,
|
|
10872
|
+
tokens,
|
|
10873
|
+
text: bodyText,
|
|
10874
|
+
truncated: window.truncated || clipped.isTruncated,
|
|
10875
|
+
totalLines: window.totalLines,
|
|
10876
|
+
...clipped.isTruncated ? { clippedAtBytes: MAX_RESULT_BYTES } : {}
|
|
10877
|
+
});
|
|
10743
10878
|
used += tokens;
|
|
10744
10879
|
}
|
|
10745
10880
|
const lines = [
|
|
@@ -10748,7 +10883,9 @@ var answerTool = {
|
|
|
10748
10883
|
];
|
|
10749
10884
|
for (const block of blocks) {
|
|
10750
10885
|
lines.push("");
|
|
10751
|
-
lines.push(
|
|
10886
|
+
lines.push(
|
|
10887
|
+
"## " + block.path + " (" + block.tokens + " tokens, " + (block.clippedAtBytes !== void 0 ? "first " + Math.round(block.clippedAtBytes / 1024) + " KiB of the window" : block.truncated ? "first lines of " + block.totalLines : "whole file") + ")"
|
|
10888
|
+
);
|
|
10752
10889
|
lines.push("Why: " + block.why);
|
|
10753
10890
|
lines.push("```");
|
|
10754
10891
|
lines.push(block.text);
|
|
@@ -10759,6 +10896,11 @@ var answerTool = {
|
|
|
10759
10896
|
lines.push("Not included:");
|
|
10760
10897
|
for (const entry of omitted) lines.push("- " + entry.path + " - " + entry.reason);
|
|
10761
10898
|
}
|
|
10899
|
+
if (plan.notes.length > 0) {
|
|
10900
|
+
lines.push("");
|
|
10901
|
+
lines.push("Notes:");
|
|
10902
|
+
for (const note of plan.notes) lines.push("- " + note);
|
|
10903
|
+
}
|
|
10762
10904
|
return {
|
|
10763
10905
|
text: lines.join("\n"),
|
|
10764
10906
|
structured: { question, budgetTokens: maxTokens, usedTokens: used, files: blocks, omitted }
|
|
@@ -10873,7 +11015,7 @@ var statusTool = {
|
|
|
10873
11015
|
`Files: ${manifest.counts.totalFiles} included, ${manifest.counts.skippedCount} skipped, ${plural(manifest.counts.partsCount, "part")}`,
|
|
10874
11016
|
`Content: ${formatBytes2(manifest.counts.totalSizeBytes)} of source in ${formatBytes2(manifest.totals.totalContentBytes)} emitted`,
|
|
10875
11017
|
`Fingerprint: ${manifest.fingerprint}`,
|
|
10876
|
-
`Git: ${manifest.git.branch} @ ${manifest.git.commit}${manifest.git.isDirty ? " (dirty)" : " (clean)"}`
|
|
11018
|
+
`Git: ${manifest.git.branch}${manifest.git.branchFromGit === false ? " (fallback; no git branch)" : ""} @ ${manifest.git.commit}${manifest.git.isDirty ? " (dirty)" : " (clean)"}`
|
|
10877
11019
|
];
|
|
10878
11020
|
if (manifest.totals.warningCount > 0) lines.push(`Warnings: ${manifest.totals.warningCount}`);
|
|
10879
11021
|
if (!versionMatches) {
|
|
@@ -11024,6 +11166,16 @@ var generateTool = {
|
|
|
11024
11166
|
minimum: 500,
|
|
11025
11167
|
description: "Fit the snapshot into this token budget, highest value first."
|
|
11026
11168
|
},
|
|
11169
|
+
only: {
|
|
11170
|
+
type: "array",
|
|
11171
|
+
items: { type: "string" },
|
|
11172
|
+
description: "Globs to include: replaces the config allow-list for this run."
|
|
11173
|
+
},
|
|
11174
|
+
ignore: {
|
|
11175
|
+
type: "array",
|
|
11176
|
+
items: { type: "string" },
|
|
11177
|
+
description: "Globs to exclude, added to the config deny-list for this run."
|
|
11178
|
+
},
|
|
11027
11179
|
...SCOPE_PROPERTIES
|
|
11028
11180
|
},
|
|
11029
11181
|
additionalProperties: false
|
|
@@ -11052,7 +11204,9 @@ var generateTool = {
|
|
|
11052
11204
|
...args.tokenTree === true ? { tokenTree: true } : {},
|
|
11053
11205
|
...args.stripComments === true ? { stripComments: true } : {},
|
|
11054
11206
|
...args.removeEmptyLines === true ? { removeEmptyLines: true } : {},
|
|
11055
|
-
...typeof args.pack === "string" ? { pack: args.pack } : {}
|
|
11207
|
+
...typeof args.pack === "string" ? { pack: args.pack } : {},
|
|
11208
|
+
...Array.isArray(args.only) ? { only: args.only.filter((value) => typeof value === "string") } : {},
|
|
11209
|
+
...Array.isArray(args.ignore) ? { ignore: args.ignore.filter((value) => typeof value === "string") } : {}
|
|
11056
11210
|
};
|
|
11057
11211
|
if (typeof args.slice === "string" && typeof args.budgetTokens === "number") {
|
|
11058
11212
|
return failure("slice and budgetTokens both narrow the selection; pass one.");
|
|
@@ -11096,6 +11250,20 @@ var generateTool = {
|
|
|
11096
11250
|
};
|
|
11097
11251
|
}
|
|
11098
11252
|
};
|
|
11253
|
+
function configAsGenerated(workspace, manifest) {
|
|
11254
|
+
const recorded = manifest.config;
|
|
11255
|
+
return {
|
|
11256
|
+
...workspace.config,
|
|
11257
|
+
...recorded?.artifacts === void 0 ? {} : { artifacts: recorded.artifacts },
|
|
11258
|
+
...recorded?.stripComments === void 0 ? {} : { stripComments: recorded.stripComments },
|
|
11259
|
+
...recorded?.removeEmptyLines === void 0 ? {} : { removeEmptyLines: recorded.removeEmptyLines },
|
|
11260
|
+
...recorded?.pack === void 0 ? {} : { pack: recorded.pack },
|
|
11261
|
+
...recorded?.logCount === void 0 ? {} : { logCount: recorded.logCount },
|
|
11262
|
+
...recorded?.skeleton === void 0 ? {} : { skeleton: recorded.skeleton },
|
|
11263
|
+
...recorded?.sarif === void 0 ? {} : { sarif: recorded.sarif },
|
|
11264
|
+
...recorded?.maxParts === void 0 ? {} : { maxParts: recorded.maxParts }
|
|
11265
|
+
};
|
|
11266
|
+
}
|
|
11099
11267
|
var validateTool = {
|
|
11100
11268
|
name: "snapshot_validate",
|
|
11101
11269
|
title: "Validate the snapshot",
|
|
@@ -11117,9 +11285,11 @@ var validateTool = {
|
|
|
11117
11285
|
const prepared = await prepare(args, context, workspaceOverrides(args));
|
|
11118
11286
|
if (!prepared.ok) return prepared.outcome;
|
|
11119
11287
|
const workspace = prepared.workspace;
|
|
11288
|
+
const read = readManifest3(workspace);
|
|
11289
|
+
if (!read.ok) return failure(read.message);
|
|
11120
11290
|
let result;
|
|
11121
11291
|
try {
|
|
11122
|
-
result = validateSnapshot(workspace.
|
|
11292
|
+
result = validateSnapshot(configAsGenerated(workspace, read.manifest));
|
|
11123
11293
|
} catch (error) {
|
|
11124
11294
|
return failure(error instanceof Error ? error.message : String(error));
|
|
11125
11295
|
}
|
|
@@ -11483,6 +11653,12 @@ var readTool = {
|
|
|
11483
11653
|
`${relativePath} is recorded in ${entry.part} but its section could not be located there. Run snapshot_generate to rebuild the snapshot.`
|
|
11484
11654
|
);
|
|
11485
11655
|
}
|
|
11656
|
+
if (typeof args.fromLine === "number" && (!Number.isInteger(args.fromLine) || args.fromLine < 1)) {
|
|
11657
|
+
return failure('"fromLine" must be an integer of at least 1 (received ' + String(args.fromLine) + ").");
|
|
11658
|
+
}
|
|
11659
|
+
if (typeof args.lines === "number" && (!Number.isInteger(args.lines) || args.lines < 1)) {
|
|
11660
|
+
return failure('"lines" must be an integer of at least 1 (received ' + String(args.lines) + ").");
|
|
11661
|
+
}
|
|
11486
11662
|
const fromLine = typeof args.fromLine === "number" ? args.fromLine : 1;
|
|
11487
11663
|
const lineCount = typeof args.lines === "number" ? args.lines : 200;
|
|
11488
11664
|
const window = windowText(section.body, fromLine, lineCount);
|
|
@@ -11901,6 +12077,8 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
11901
12077
|
// — the exact "flag that parses but changes nothing" this table exists to prevent — while
|
|
11902
12078
|
// `--discovery` was already rejected. Both the parser and `describe`'s `appliesTo` read this
|
|
11903
12079
|
// list, so removing them narrows the two together.
|
|
12080
|
+
// It asks the registry, not the repository: no cwd, no out-dir, nothing a config could change.
|
|
12081
|
+
update: ["format", "help"],
|
|
11904
12082
|
report: [
|
|
11905
12083
|
"cwd",
|
|
11906
12084
|
"out-dir",
|
|
@@ -12193,6 +12371,13 @@ function buildAgentContract() {
|
|
|
12193
12371
|
positionals: [],
|
|
12194
12372
|
exits: [0]
|
|
12195
12373
|
},
|
|
12374
|
+
{
|
|
12375
|
+
name: "update",
|
|
12376
|
+
aliases: [],
|
|
12377
|
+
summary: "Ask the npm registry whether a newer release exists and print the version it compared against. Exit 0 when current, 1 when an update is available, 2 when the registry could not be reached. The passive notice is suppressed in CI and JSON output; this command always asks and bypasses the cache.",
|
|
12378
|
+
positionals: [],
|
|
12379
|
+
exits: [0, 1, 2]
|
|
12380
|
+
},
|
|
12196
12381
|
{
|
|
12197
12382
|
name: "skill",
|
|
12198
12383
|
aliases: [],
|
|
@@ -12488,14 +12673,14 @@ function buildAgentContract() {
|
|
|
12488
12673
|
type: "boolean",
|
|
12489
12674
|
default: false,
|
|
12490
12675
|
appliesTo: optionAppliesTo("include-diffs"),
|
|
12491
|
-
summary: "Also write reports/diff.md: the unstaged and staged diff, with the command that produced each, bounded to 200 KiB and truncated with a note. Absent when there is no change."
|
|
12676
|
+
summary: "Also write reports/diff.md: the unstaged and staged diff, with the command that produced each, bounded to 200 KiB and truncated with a note. Absent when there is no change; outside a git repository the run warns and writes nothing."
|
|
12492
12677
|
},
|
|
12493
12678
|
{
|
|
12494
12679
|
flag: "--include-logs",
|
|
12495
12680
|
type: "string",
|
|
12496
12681
|
default: "unset",
|
|
12497
12682
|
appliesTo: optionAppliesTo("include-logs"),
|
|
12498
|
-
summary: "Also write reports/log.md: the last n commits (1-500), one line each, newest first."
|
|
12683
|
+
summary: "Also write reports/log.md: the last n commits (1-500), one line each, newest first. Outside a git repository the run warns and writes nothing."
|
|
12499
12684
|
},
|
|
12500
12685
|
{
|
|
12501
12686
|
flag: "--token-tree",
|
|
@@ -13489,6 +13674,18 @@ function createMcpServer(options) {
|
|
|
13489
13674
|
if (!isJsonObject(rawArguments)) {
|
|
13490
13675
|
return errorResponse(id, ERROR_CODES.invalidParams, '"arguments" must be a JSON object.');
|
|
13491
13676
|
}
|
|
13677
|
+
const missing = (prompt.arguments ?? []).filter((argument) => {
|
|
13678
|
+
if (argument.required !== true) return false;
|
|
13679
|
+
const value = rawArguments[argument.name];
|
|
13680
|
+
return typeof value !== "string" || value.trim() === "";
|
|
13681
|
+
});
|
|
13682
|
+
if (missing.length > 0) {
|
|
13683
|
+
return errorResponse(
|
|
13684
|
+
id,
|
|
13685
|
+
ERROR_CODES.invalidParams,
|
|
13686
|
+
'Prompt "' + name + '" requires the ' + missing.map((argument) => '"' + argument.name + '"').join(", ") + " argument(s): " + missing.map((argument) => argument.description).join(" ")
|
|
13687
|
+
);
|
|
13688
|
+
}
|
|
13492
13689
|
const built = prompt.build(rawArguments);
|
|
13493
13690
|
const messages = built.messages.map((message) => ({
|
|
13494
13691
|
role: message.role,
|
|
@@ -13602,7 +13799,7 @@ var DEFAULT_MAX_BODY = 2 * 1024 * 1024;
|
|
|
13602
13799
|
var RATE_LIMIT = 60;
|
|
13603
13800
|
var RATE_WINDOW_MS = 1e4;
|
|
13604
13801
|
function generateToken() {
|
|
13605
|
-
return
|
|
13802
|
+
return crypto2__namespace.randomBytes(24).toString("base64url");
|
|
13606
13803
|
}
|
|
13607
13804
|
function isLoopbackOrigin(origin) {
|
|
13608
13805
|
try {
|
|
@@ -13618,7 +13815,7 @@ function timingSafeEqual2(left, right) {
|
|
|
13618
13815
|
const a = Buffer.from(left, "utf8");
|
|
13619
13816
|
const b = Buffer.from(right, "utf8");
|
|
13620
13817
|
if (a.length !== b.length) return false;
|
|
13621
|
-
return
|
|
13818
|
+
return crypto2__namespace.timingSafeEqual(a, b);
|
|
13622
13819
|
}
|
|
13623
13820
|
async function startHttpTransport(options) {
|
|
13624
13821
|
const host = options.host ?? "127.0.0.1";
|
|
@@ -13663,6 +13860,7 @@ async function startHttpTransport(options) {
|
|
|
13663
13860
|
noteRequest(request);
|
|
13664
13861
|
const send = (status, body, extra = {}) => {
|
|
13665
13862
|
const text = typeof body === "string" ? body : JSON.stringify(body);
|
|
13863
|
+
if (status >= 400 && status < 500 && status !== 429) metrics.refused += 1;
|
|
13666
13864
|
response.writeHead(status, {
|
|
13667
13865
|
"content-type": typeof body === "string" ? "text/plain; charset=utf-8" : "application/json",
|
|
13668
13866
|
"content-length": Buffer.byteLength(text, "utf8"),
|
|
@@ -13674,7 +13872,6 @@ async function startHttpTransport(options) {
|
|
|
13674
13872
|
const origin = typeof request.headers.origin === "string" ? request.headers.origin : void 0;
|
|
13675
13873
|
const allowed = allowedOrigin(origin);
|
|
13676
13874
|
if (origin !== void 0 && allowed === null) {
|
|
13677
|
-
metrics.refused += 1;
|
|
13678
13875
|
send(403, { error: "origin not allowed" });
|
|
13679
13876
|
return;
|
|
13680
13877
|
}
|
|
@@ -13712,7 +13909,7 @@ async function startHttpTransport(options) {
|
|
|
13712
13909
|
"# HELP snapshot_requests_total HTTP requests received.",
|
|
13713
13910
|
"# TYPE snapshot_requests_total counter",
|
|
13714
13911
|
"snapshot_requests_total " + metrics.requests,
|
|
13715
|
-
"# HELP snapshot_requests_refused_total Requests refused before dispatch.",
|
|
13912
|
+
"# HELP snapshot_requests_refused_total Requests refused before dispatch (4xx other than 429).",
|
|
13716
13913
|
"# TYPE snapshot_requests_refused_total counter",
|
|
13717
13914
|
"snapshot_requests_refused_total " + metrics.refused,
|
|
13718
13915
|
"# HELP snapshot_requests_rate_limited_total Requests rejected by the rate limit.",
|
|
@@ -13737,7 +13934,7 @@ async function startHttpTransport(options) {
|
|
|
13737
13934
|
send(401, { error: "unauthorized" }, { ...cors, "www-authenticate": 'Bearer realm="codebase-snapshot"' });
|
|
13738
13935
|
return;
|
|
13739
13936
|
}
|
|
13740
|
-
const id =
|
|
13937
|
+
const id = crypto2__namespace.randomBytes(12).toString("hex");
|
|
13741
13938
|
response.writeHead(200, {
|
|
13742
13939
|
...cors,
|
|
13743
13940
|
"content-type": "text/event-stream",
|
|
@@ -13903,7 +14100,10 @@ exports.LEGACY_PROTOCOL_VERSIONS = LEGACY_PROTOCOL_VERSIONS;
|
|
|
13903
14100
|
exports.MAX_LINE_BYTES = MAX_LINE_BYTES;
|
|
13904
14101
|
exports.METHOD = METHOD;
|
|
13905
14102
|
exports.MODERN_PROTOCOL_VERSIONS = MODERN_PROTOCOL_VERSIONS;
|
|
14103
|
+
exports.REPORT_RESOURCE_URIS = REPORT_RESOURCE_URIS;
|
|
14104
|
+
exports.RESOURCE_TEMPLATE_URIS = RESOURCE_TEMPLATE_URIS;
|
|
13906
14105
|
exports.SERVER_INSTRUCTIONS = SERVER_INSTRUCTIONS;
|
|
14106
|
+
exports.STATIC_RESOURCE_URIS = STATIC_RESOURCE_URIS;
|
|
13907
14107
|
exports.SUPPORTED_PROTOCOL_VERSIONS = SUPPORTED_PROTOCOL_VERSIONS;
|
|
13908
14108
|
exports.buildPrompts = buildPrompts;
|
|
13909
14109
|
exports.buildResourceProvider = buildResourceProvider;
|