codebase-snapshot 0.9.16 → 0.9.17

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.
@@ -1,4 +1,4 @@
1
- import { GENERATOR_VERSION, anchorForPath, displayPath, MIN_MAX_PART_BYTES, SCHEMA_VERSION, GENERATOR_NAME, ARTIFACT_NAMES, PRESETS, generateSnapshot, generateInWorker, validateSnapshot, buildImportResolver, resolveSpecifier, truncateToBytes, explainPath, renderExplainText, describeManifestShapeProblem, loadConfigFileDetailed, parseByteSize, resolveConfig } from './chunk-6TRFLA7N.js';
1
+ import { GENERATOR_VERSION, anchorForPath, displayPath, MIN_MAX_PART_BYTES, SCHEMA_VERSION, GENERATOR_NAME, ARTIFACT_NAMES, PRESETS, generateSnapshot, generateInWorker, validateSnapshot, buildImportResolver, resolveSpecifier, truncateToBytes, explainPath, renderExplainText, describeManifestShapeProblem, loadConfigFileDetailed, parseByteSize, resolveConfig } from './chunk-IIP43I7C.js';
2
2
  import * as fs from 'fs';
3
3
  import * as path from 'path';
4
4
 
@@ -26,6 +26,13 @@ var ERROR_CODES = {
26
26
  * invent a partial one.
27
27
  */
28
28
  resourceTooLarge: -32e3,
29
+ /**
30
+ * The server is at its concurrency limit.
31
+ *
32
+ * Implementation-defined range, like `resourceTooLarge`. A typed error rather than silent
33
+ * queueing or a dropped request: the caller can retry, and knows why.
34
+ */
35
+ overloaded: -32001,
29
36
  unsupportedProtocolVersion: -32022
30
37
  };
31
38
  var METHOD = {
@@ -323,8 +330,8 @@ function resolveRoot(requested, context) {
323
330
  message: `"${wanted}" resolves outside the directories this server may read (${shown}). The server reads the directory it was started for; restart it with --cwd <directory> to serve a different repository.`
324
331
  };
325
332
  }
326
- async function openWorkspace(root, overrides = {}, allowedRoots) {
327
- const loaded = await loadConfigFileDetailed(root);
333
+ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
334
+ const loaded = await loadConfigFileDetailed(root, options);
328
335
  if (loaded.errors.length > 0) {
329
336
  return {
330
337
  ok: false,
@@ -388,6 +395,7 @@ async function openWorkspace(root, overrides = {}, allowedRoots) {
388
395
  return { ok: false, message: error instanceof Error ? error.message : String(error) };
389
396
  }
390
397
  }
398
+ var MANIFEST_CACHE_LIMIT = 8;
391
399
  var manifestCache = /* @__PURE__ */ new Map();
392
400
  function manifestPathFor(workspace) {
393
401
  return path.resolve(workspace.root, workspace.config.outDir, "manifest.json");
@@ -400,6 +408,18 @@ function partPathFor(workspace, filename) {
400
408
  if (relative3.length === 0 || relative3.includes(path.sep) || relative3.includes("/") || relative3.includes("\\") || path.isAbsolute(relative3)) {
401
409
  return null;
402
410
  }
411
+ let stats;
412
+ try {
413
+ stats = fs.lstatSync(resolved);
414
+ } catch {
415
+ return null;
416
+ }
417
+ if (!stats.isFile()) return null;
418
+ try {
419
+ if (path.dirname(fs.realpathSync(resolved)) !== fs.realpathSync(partsDir)) return null;
420
+ } catch {
421
+ return null;
422
+ }
403
423
  return resolved;
404
424
  }
405
425
  function readManifest(workspace) {
@@ -416,7 +436,7 @@ function readManifest(workspace) {
416
436
  };
417
437
  }
418
438
  const cached = manifestCache.get(file);
419
- if (cached && cached.mtimeMs === stats.mtimeMs && cached.size === stats.size) {
439
+ if (cached && cached.mtimeMs === stats.mtimeMs && cached.ctimeMs === stats.ctimeMs && cached.size === stats.size) {
420
440
  return { ok: true, manifest: cached.manifest, file };
421
441
  }
422
442
  let raw;
@@ -440,7 +460,18 @@ function readManifest(workspace) {
440
460
  return { ok: false, missing: false, message: `${shown} is not a snapshot manifest: ${problem}` };
441
461
  }
442
462
  const manifest = parsed;
443
- manifestCache.set(file, { mtimeMs: stats.mtimeMs, size: stats.size, manifest });
463
+ manifestCache.delete(file);
464
+ manifestCache.set(file, {
465
+ mtimeMs: stats.mtimeMs,
466
+ ctimeMs: stats.ctimeMs,
467
+ size: stats.size,
468
+ manifest
469
+ });
470
+ while (manifestCache.size > MANIFEST_CACHE_LIMIT) {
471
+ const oldest = manifestCache.keys().next().value;
472
+ if (oldest === void 0) break;
473
+ manifestCache.delete(oldest);
474
+ }
444
475
  return { ok: true, manifest, file };
445
476
  }
446
477
  function forgetManifest(file) {
@@ -588,7 +619,9 @@ function symbolsOf(entry) {
588
619
  async function prepare(args, context, overrides = {}) {
589
620
  const rootOutcome = resolveRoot(args.root, context);
590
621
  if (!rootOutcome.ok) return { ok: false, outcome: failure(rootOutcome.message) };
591
- const opened = await openWorkspace(rootOutcome.root, overrides, context.roots);
622
+ const opened = await openWorkspace(rootOutcome.root, overrides, context.roots, {
623
+ allowExecutableConfig: false
624
+ });
592
625
  if (!opened.ok) return { ok: false, outcome: failure(opened.message) };
593
626
  return { ok: true, workspace: opened.workspace };
594
627
  }
@@ -944,10 +977,12 @@ var locateTool = {
944
977
  else if (wants("kind") && entry.kind.toLowerCase().includes(needle)) add(entry, "kind");
945
978
  }
946
979
  if (wants("route")) {
980
+ const matchedPaths = new Set(matches.map((match) => match.path));
947
981
  for (const route of manifest.indexes.routes) {
948
982
  const method = route.methods.find((name) => name.toLowerCase().includes(needle));
949
983
  if (!route.path.toLowerCase().includes(needle) && method === void 0) continue;
950
- if (matches.some((match) => match.path === route.path)) continue;
984
+ if (matchedPaths.has(route.path)) continue;
985
+ matchedPaths.add(route.path);
951
986
  matches.push({
952
987
  path: route.path,
953
988
  part: route.part,
@@ -1140,7 +1175,9 @@ var readTool = {
1140
1175
  fromLine: { type: "integer" },
1141
1176
  returnedLines: { type: "integer" },
1142
1177
  totalLines: { type: "integer" },
1143
- nextFromLine: { type: "integer" }
1178
+ nextFromLine: { type: "integer" },
1179
+ pageable: { type: "boolean" },
1180
+ reason: { type: "string" }
1144
1181
  }
1145
1182
  },
1146
1183
  annotations: READ_ONLY,
@@ -1196,15 +1233,20 @@ var readTool = {
1196
1233
  const window = windowText(section.body, fromLine, lineCount);
1197
1234
  let body = window.text;
1198
1235
  let truncatedByBytes = false;
1236
+ let clippedInsideLine = false;
1199
1237
  if (Buffer.byteLength(body, "utf8") > MAX_RESULT_BYTES) {
1200
1238
  const clipped = truncateToBytes(body, MAX_RESULT_BYTES);
1201
- body = clipped.content;
1202
- const lastBreak = body.lastIndexOf("\n");
1203
- body = lastBreak > 0 ? body.slice(0, lastBreak) : body;
1239
+ const lastBreak = clipped.content.lastIndexOf("\n");
1240
+ if (lastBreak > 0) {
1241
+ body = clipped.content.slice(0, lastBreak);
1242
+ } else {
1243
+ body = clipped.content;
1244
+ clippedInsideLine = true;
1245
+ }
1204
1246
  truncatedByBytes = true;
1205
1247
  }
1206
1248
  const returnedLines = body.length === 0 ? 0 : body.split("\n").length;
1207
- const moreRemain = !window.pastEnd && (window.truncated || truncatedByBytes);
1249
+ const moreRemain = !clippedInsideLine && !window.pastEnd && (window.truncated || truncatedByBytes);
1208
1250
  const header = [
1209
1251
  `${entry.relativePath} \u2014 ${entry.part}, ${entry.layer}/${entry.kind}, ${entry.language}`,
1210
1252
  // The line range is the answer to "where am I in this file", and it is computed from the
@@ -1218,12 +1260,17 @@ var readTool = {
1218
1260
  ] : section.inclusion === "signatures" ? [
1219
1261
  "Signatures: function and method bodies were replaced with `{ /* ... */ }` when the snapshot was generated."
1220
1262
  ] : [],
1221
- window.totalLines === 0 ? "This file is empty." : window.pastEnd ? `This file has ${window.totalLines} line(s); fromLine=${window.fromLine} is past its end.` : `Lines ${window.fromLine}\u2013${window.fromLine + returnedLines - 1} of ${window.totalLines}.`
1263
+ window.totalLines === 0 ? "This file is empty." : window.pastEnd ? `This file has ${window.totalLines} line(s); fromLine=${window.fromLine} is past its end.` : clippedInsideLine ? `Line ${window.fromLine} of ${window.totalLines}: this line is longer than one result can carry, so this page ends mid-line.` : `Lines ${window.fromLine}\u2013${window.fromLine + returnedLines - 1} of ${window.totalLines}.`
1222
1264
  ];
1223
1265
  const lines = [...header, "", body];
1224
1266
  if (moreRemain) {
1225
1267
  const next = window.fromLine + returnedLines;
1226
1268
  lines.push("", `Truncated. Call snapshot_read with fromLine=${next} for the rest.`);
1269
+ } else if (clippedInsideLine) {
1270
+ lines.push(
1271
+ "",
1272
+ "Truncated. The remainder of this line is not reachable through snapshot_read; read the file from disk to see it."
1273
+ );
1227
1274
  }
1228
1275
  return {
1229
1276
  text: lines.join("\n"),
@@ -1237,7 +1284,9 @@ var readTool = {
1237
1284
  fromLine: window.fromLine,
1238
1285
  returnedLines,
1239
1286
  totalLines: window.totalLines,
1240
- truncated: moreRemain,
1287
+ truncated: moreRemain || clippedInsideLine,
1288
+ pageable: !clippedInsideLine,
1289
+ ...clippedInsideLine ? { reason: "line exceeds the result limit; its remainder is not reachable by fromLine" } : {},
1241
1290
  nextFromLine: moreRemain ? window.fromLine + returnedLines : null,
1242
1291
  sha256: entry.hashSha256
1243
1292
  }
@@ -1461,13 +1510,14 @@ var COMMAND_OPTION_SCOPE = {
1461
1510
  "with-dependents",
1462
1511
  "cwd",
1463
1512
  "out-dir",
1464
- "max-part-bytes",
1513
+ // `--large-file-bytes` changes the inclusion mode `explain` reports, so it belongs here.
1514
+ // `--max-part-bytes`, `--max-monolith-bytes`, `--include-monolith`, `--skip-artifacts` and
1515
+ // `--only-artifacts` were accepted and never read: a per-file answer cannot depend on how the
1516
+ // whole snapshot is partitioned, and none of them changes whether this file is included.
1517
+ // Removed rather than implemented, because a flag that parses and does nothing is the defect
1518
+ // this table exists to prevent.
1465
1519
  "large-file-bytes",
1466
- "max-monolith-bytes",
1467
- "include-monolith",
1468
1520
  "include-sensitive-files",
1469
- "skip-artifacts",
1470
- "only-artifacts",
1471
1521
  "no-config",
1472
1522
  "discovery",
1473
1523
  "no-update-check",
@@ -1815,7 +1865,7 @@ function buildAgentContract() {
1815
1865
  type: "string",
1816
1866
  default: "unset",
1817
1867
  appliesTo: optionAppliesTo("max-part-tokens"),
1818
- summary: "Ceiling on a part expressed in tokens. Narrows --max-part-bytes instead of replacing it; the manifest records both units. Minimum 1024."
1868
+ summary: "Ceiling on a part expressed in tokens. Converted to bytes at 4 bytes/token and enforced as that byte ceiling \u2014 the estimate in manifest.parts[].estimatedTokens is not a hard bound, and a warning names any part whose estimate exceeds it. Minimum 1024."
1819
1869
  },
1820
1870
  {
1821
1871
  flag: "--large-file-bytes",
@@ -1850,7 +1900,7 @@ function buildAgentContract() {
1850
1900
  type: "string",
1851
1901
  default: "auto",
1852
1902
  appliesTo: optionAppliesTo("discovery"),
1853
- summary: "How files are discovered: auto (git when usable), git (require git), walk (read the root .gitignore directly; the escape hatch for a .git that cannot be listed)."
1903
+ summary: "How files are discovered: auto (git when usable), git (require git), walk (read .gitignore files directly, including nested ones; the escape hatch for a .git that cannot be listed)."
1854
1904
  },
1855
1905
  {
1856
1906
  flag: "--skip-artifacts",
@@ -1871,7 +1921,7 @@ function buildAgentContract() {
1871
1921
  type: "boolean",
1872
1922
  default: false,
1873
1923
  appliesTo: optionAppliesTo("skeleton"),
1874
- summary: 'Replace function and method bodies with `{ /* ... */ }` in TypeScript/TSX files, keeping signatures and comments. The part records inclusionMode "signatures" for each file it touched.'
1924
+ summary: 'Replace function and method bodies with `{ /* ... */ }` in JS, JSX, TS and TSX files (including .mjs/.cjs; .d.ts files have nothing to collapse), keeping signatures and comments. The part records inclusionMode "signatures" for each file it touched.'
1875
1925
  },
1876
1926
  {
1877
1927
  flag: "--sarif",
@@ -1985,7 +2035,7 @@ function buildAgentContract() {
1985
2035
  type: "boolean",
1986
2036
  default: false,
1987
2037
  appliesTo: optionAppliesTo("autopilot"),
1988
- summary: "Set the project up without asking, then generate: detect the preset, write the config and .gitignore, add the npm scripts and devDependency, install with the project's own package manager, generate. Never overwrites an existing config, and never prompts. Refuses an empty directory (exit 1); contradicts --no-config (exit 2)."
2038
+ summary: "Set the project up without asking, then generate: detect the preset, write the config and .gitignore, add the npm scripts and devDependency, install with the project's own package manager, generate. Autopilot chooses the preset and takes no --preset/--include/--exclude/--install-hook: those belong to `setup` or `init`. Never overwrites an existing config, and never prompts. Refuses an empty directory (exit 1); contradicts --no-config (exit 2)."
1989
2039
  },
1990
2040
  {
1991
2041
  flag: "--install",
@@ -2356,7 +2406,7 @@ function formatBytes2(bytes) {
2356
2406
  async function workspaceFor(context) {
2357
2407
  const root = resolveRoot(void 0, context);
2358
2408
  if (!root.ok) return { error: root.message };
2359
- const opened = await openWorkspace(root.root);
2409
+ const opened = await openWorkspace(root.root, {}, void 0, { allowExecutableConfig: false });
2360
2410
  if (!opened.ok) return { error: opened.message };
2361
2411
  return opened.workspace;
2362
2412
  }
@@ -3033,6 +3083,7 @@ async function runStdioServer(options) {
3033
3083
  });
3034
3084
  return writeChain;
3035
3085
  };
3086
+ const MAX_IN_FLIGHT = 4;
3036
3087
  let inFlight = 0;
3037
3088
  let inputEnded = false;
3038
3089
  let resolveDone = () => void 0;
@@ -3053,9 +3104,31 @@ async function runStdioServer(options) {
3053
3104
  const response = await server.handle(message);
3054
3105
  if (response) await send(response);
3055
3106
  };
3107
+ const rejectOverloaded = (line) => {
3108
+ let id = null;
3109
+ try {
3110
+ const parsed = JSON.parse(line);
3111
+ if (!isJsonObject(parsed)) return;
3112
+ if (typeof parsed.id === "string" || typeof parsed.id === "number") id = parsed.id;
3113
+ else return;
3114
+ } catch {
3115
+ return;
3116
+ }
3117
+ void send(
3118
+ errorResponse(
3119
+ id,
3120
+ ERROR_CODES.overloaded,
3121
+ `The server is already handling ${MAX_IN_FLIGHT} requests; retry this one when it is free.`
3122
+ )
3123
+ );
3124
+ };
3056
3125
  const stopReading = createLineReader(process.stdin, {
3057
3126
  onOverflow: (bytes) => log(`mcp: discarded an oversized message (${bytes} bytes)`),
3058
3127
  onLine: (line) => {
3128
+ if (inFlight >= MAX_IN_FLIGHT) {
3129
+ rejectOverloaded(line);
3130
+ return;
3131
+ }
3059
3132
  inFlight += 1;
3060
3133
  void handleLine(line).finally(() => {
3061
3134
  inFlight -= 1;