codebase-snapshot 0.20.12 → 0.20.13

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/dist/index.cjs CHANGED
@@ -4202,7 +4202,7 @@ function verifySnapshotSignature(snapshotDir) {
4202
4202
 
4203
4203
  // src/version.ts
4204
4204
  var GENERATOR_NAME = "codebase-snapshot";
4205
- var GENERATOR_VERSION = "0.20.12";
4205
+ var GENERATOR_VERSION = "0.20.13";
4206
4206
  var SCHEMA_VERSION = "3.0.0";
4207
4207
  var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
4208
4208
  function isOurGeneratorName(name) {
@@ -7232,7 +7232,7 @@ function renumberParts(parts, contentFingerprint) {
7232
7232
  }
7233
7233
  const pathLines = included.map((file) => displayPath(file.relativePath));
7234
7234
  const listFence = fenceForText(pathLines.join("\n"), 3);
7235
- const header = [
7235
+ const header2 = [
7236
7236
  `# Codebase Snapshot Part ${zeroPad(index + 1)} of ${zeroPad(total)}`,
7237
7237
  "",
7238
7238
  `- Previous: ${index === 0 ? "none" : nameFor(index)}`,
@@ -7253,7 +7253,7 @@ function renumberParts(parts, contentFingerprint) {
7253
7253
  "## Contents",
7254
7254
  ""
7255
7255
  ].join("\n");
7256
- const assembled = (header + body).replace(/\r\n/g, "\n");
7256
+ const assembled = (header2 + body).replace(/\r\n/g, "\n");
7257
7257
  const estimatedTokens = estimateTokens(assembled);
7258
7258
  const markdown = insertTokenLine(assembled, estimatedTokens);
7259
7259
  const metadata = {
@@ -7439,7 +7439,7 @@ function assembleGroup(group, index, total, contentFingerprint) {
7439
7439
  }
7440
7440
  const pathLines = group.sections.map((s) => displayPath(s.file.relativePath));
7441
7441
  const listFence = fenceForText(pathLines.join("\n"), 3);
7442
- const header = [
7442
+ const header2 = [
7443
7443
  `# Codebase Snapshot Part ${zeroPad(index + 1)} of ${zeroPad(total)}`,
7444
7444
  "",
7445
7445
  `- Previous: ${prev}`,
@@ -7460,7 +7460,7 @@ function assembleGroup(group, index, total, contentFingerprint) {
7460
7460
  "## Contents",
7461
7461
  ""
7462
7462
  ].join("\n");
7463
- const assembled = (header + group.sections.map((s) => s.text).join("")).replace(
7463
+ const assembled = (header2 + group.sections.map((s) => s.text).join("")).replace(
7464
7464
  /\r\n|\r/g,
7465
7465
  "\n"
7466
7466
  );
@@ -8157,10 +8157,10 @@ function headerPaths(value) {
8157
8157
  }
8158
8158
  function diffSectionPaths(body) {
8159
8159
  const paths = /* @__PURE__ */ new Set();
8160
- let header = null;
8160
+ let header2 = null;
8161
8161
  for (const line of body.split("\n")) {
8162
8162
  if (line.startsWith("diff --git ")) {
8163
- header = line.slice("diff --git ".length);
8163
+ header2 = line.slice("diff --git ".length);
8164
8164
  continue;
8165
8165
  }
8166
8166
  if (line.startsWith("+++ ")) {
@@ -8173,8 +8173,8 @@ function diffSectionPaths(body) {
8173
8173
  if (path27 !== null) paths.add(path27);
8174
8174
  }
8175
8175
  }
8176
- if (paths.size === 0 && header !== null) {
8177
- for (const path27 of headerPaths(header)) paths.add(path27);
8176
+ if (paths.size === 0 && header2 !== null) {
8177
+ for (const path27 of headerPaths(header2)) paths.add(path27);
8178
8178
  }
8179
8179
  return [...paths];
8180
8180
  }
@@ -11024,6 +11024,7 @@ var SUPPORTED_PROTOCOL_VERSIONS = [
11024
11024
  ];
11025
11025
  var DEFAULT_LEGACY_PROTOCOL_VERSION = LEGACY_PROTOCOL_VERSIONS[0];
11026
11026
  var ERROR_CODES = {
11027
+ parseError: -32700,
11027
11028
  invalidRequest: -32600,
11028
11029
  methodNotFound: -32601,
11029
11030
  invalidParams: -32602,
@@ -11039,13 +11040,29 @@ var ERROR_CODES = {
11039
11040
  */
11040
11041
  resourceTooLarge: -32e3,
11041
11042
  /**
11042
- * A known resource that this snapshot does not contain.
11043
+ * A known resource that this snapshot does not contain, under a legacy revision.
11043
11044
  *
11044
- * `-32002` is the MCP code for "resource not found". Answering `-32602` ("Unknown resource")
11045
- * for `snapshot://prompt` in a snapshot generated with `--skip-artifacts prompt` told the
11046
- * client its URI was wrong when the artifact had simply been left out.
11045
+ * `-32002` was the resource-not-found code through protocol revision `2025-11-25`. The
11046
+ * `2026-07-28` revision assigns missing resources to `-32602` and says clients SHOULD still
11047
+ * accept `-32002` from older servers. The dispatcher therefore chooses by era: `-32602` for
11048
+ * modern requests and this code for legacy ones. Answering `-32602` for `snapshot://prompt`
11049
+ * in a snapshot generated with `--skip-artifacts prompt` would tell a legacy client its URI
11050
+ * was wrong when the artifact had simply been left out.
11047
11051
  */
11048
11052
  resourceNotFound: -32002,
11053
+ /**
11054
+ * Streamable HTTP headers that are missing, malformed or disagree with the request body.
11055
+ *
11056
+ * Protocol revision `2026-07-28` reserves `-32020` for this. The HTTP status is `400`.
11057
+ */
11058
+ headerMismatch: -32020,
11059
+ /**
11060
+ * The server is at its concurrency limit.
11061
+ *
11062
+ * Implementation-defined range, like `resourceTooLarge`. A typed error rather than silent
11063
+ * queueing or a dropped request: the caller can retry, and knows why.
11064
+ */
11065
+ overloaded: -32001,
11049
11066
  unsupportedProtocolVersion: -32022
11050
11067
  };
11051
11068
  var METHOD3 = {
@@ -14656,7 +14673,7 @@ var readTool = {
14656
14673
  }
14657
14674
  const returnedLines = body.length === 0 ? truncatedByBytes && !clippedInsideLine && window.fromLine <= window.totalLines ? 1 : 0 : body.split("\n").length;
14658
14675
  const moreRemain = !clippedInsideLine && !window.pastEnd && (window.truncated || truncatedByBytes);
14659
- const header = [
14676
+ const header2 = [
14660
14677
  `${entry.relativePath} \u2014 ${entry.part}, ${entry.layer}/${entry.kind}, ${entry.language}`,
14661
14678
  // The line range is the answer to "where am I in this file", and it is computed from the
14662
14679
  // body the window was taken from, so it is just as meaningful for a preview as for a full
@@ -14671,7 +14688,7 @@ var readTool = {
14671
14688
  ] : [],
14672
14689
  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}.`
14673
14690
  ];
14674
- const lines = [...header, "", body];
14691
+ const lines = [...header2, "", body];
14675
14692
  if (moreRemain) {
14676
14693
  const next = window.fromLine + returnedLines;
14677
14694
  lines.push("", `Truncated. Call snapshot_read with fromLine=${next} for the rest.`);
@@ -16572,15 +16589,20 @@ function createMcpServer(options) {
16572
16589
  websiteUrl: options.info.websiteUrl
16573
16590
  });
16574
16591
  const ok = (id, result, modern) => successResponse(id, result, modern, options.info);
16592
+ const cacheable = (result) => ({
16593
+ ...result,
16594
+ cacheScope: "private",
16595
+ ttlMs: 0
16596
+ });
16575
16597
  const cancellations = /* @__PURE__ */ new Map();
16576
16598
  function handleNotification(method, params) {
16577
16599
  if (method === METHOD3.initialized && session.era === "legacy") session.ready = true;
16578
16600
  if (method === "notifications/cancelled") {
16579
- const requestId = params?.requestId;
16580
- if (typeof requestId === "string" || typeof requestId === "number") {
16581
- const cancel = cancellations.get(requestId);
16601
+ const requestId2 = params?.requestId;
16602
+ if (typeof requestId2 === "string" || typeof requestId2 === "number") {
16603
+ const cancel = cancellations.get(requestId2);
16582
16604
  if (cancel !== void 0) {
16583
- cancellations.delete(requestId);
16605
+ cancellations.delete(requestId2);
16584
16606
  cancel();
16585
16607
  }
16586
16608
  }
@@ -16608,15 +16630,11 @@ function createMcpServer(options) {
16608
16630
  function discover(id) {
16609
16631
  return ok(
16610
16632
  id,
16611
- {
16633
+ cacheable({
16612
16634
  supportedVersions: [...SUPPORTED_PROTOCOL_VERSIONS],
16613
16635
  capabilities: capabilities(),
16614
- instructions: options.instructions,
16615
- // The capability set depends on which repository the server was started for, so the answer
16616
- // may be cached only by the client that asked, and not at all after this response.
16617
- cacheScope: "private",
16618
- ttlMs: 0
16619
- },
16636
+ instructions: options.instructions
16637
+ }),
16620
16638
  true
16621
16639
  );
16622
16640
  }
@@ -16630,7 +16648,7 @@ function createMcpServer(options) {
16630
16648
  annotations: tool.annotations,
16631
16649
  _meta: { "codebase-snapshot/cost": tool.cost }
16632
16650
  }));
16633
- return ok(id, { tools }, modern);
16651
+ return ok(id, cacheable({ tools }), modern);
16634
16652
  }
16635
16653
  async function callTool(id, modern, params) {
16636
16654
  const name = params?.name;
@@ -16706,7 +16724,7 @@ function createMcpServer(options) {
16706
16724
  }
16707
16725
  async function listResources(id, modern) {
16708
16726
  const resources = await options.resources.list(options.context);
16709
- return ok(id, { resources }, modern);
16727
+ return ok(id, cacheable({ resources }), modern);
16710
16728
  }
16711
16729
  async function readResource(id, modern, params) {
16712
16730
  const uri = params?.uri;
@@ -16718,7 +16736,12 @@ function createMcpServer(options) {
16718
16736
  contents = await options.resources.read(uri, options.context);
16719
16737
  } catch (error) {
16720
16738
  if (error instanceof ResourceNotFoundError) {
16721
- return errorResponse(id, ERROR_CODES.resourceNotFound, error.message, { uri: error.uri });
16739
+ return errorResponse(
16740
+ id,
16741
+ modern ? ERROR_CODES.invalidParams : ERROR_CODES.resourceNotFound,
16742
+ error.message,
16743
+ { uri: error.uri }
16744
+ );
16722
16745
  }
16723
16746
  if (error instanceof ResourceTooLargeError) {
16724
16747
  options.context.log(
@@ -16735,7 +16758,7 @@ function createMcpServer(options) {
16735
16758
  if (!contents) {
16736
16759
  return errorResponse(id, ERROR_CODES.invalidParams, `Unknown resource "${uri}".`);
16737
16760
  }
16738
- return ok(id, { contents: [contents] }, modern);
16761
+ return ok(id, cacheable({ contents: [contents] }), modern);
16739
16762
  }
16740
16763
  function listPrompts(id, modern) {
16741
16764
  const prompts = options.prompts.map((prompt) => ({
@@ -16744,7 +16767,7 @@ function createMcpServer(options) {
16744
16767
  description: prompt.description,
16745
16768
  arguments: prompt.arguments
16746
16769
  }));
16747
- return ok(id, { prompts }, modern);
16770
+ return ok(id, cacheable({ prompts }), modern);
16748
16771
  }
16749
16772
  function getPrompt(id, modern, params) {
16750
16773
  const name = params?.name;
@@ -16813,7 +16836,7 @@ function createMcpServer(options) {
16813
16836
  case METHOD3.resourcesRead:
16814
16837
  return readResource(id, modern, params);
16815
16838
  case METHOD3.resourceTemplatesList:
16816
- return ok(id, { resourceTemplates: options.resources.templates() }, modern);
16839
+ return ok(id, cacheable({ resourceTemplates: options.resources.templates() }), modern);
16817
16840
  case METHOD3.promptsList:
16818
16841
  return listPrompts(id, modern);
16819
16842
  case METHOD3.promptsGet:
@@ -16918,18 +16941,218 @@ function createServer(options) {
16918
16941
  }
16919
16942
 
16920
16943
  // src/auth.ts
16921
- function parseBearerToken(header) {
16922
- if (typeof header !== "string") return null;
16944
+ function parseBearerToken(header2) {
16945
+ if (typeof header2 !== "string") return null;
16923
16946
  const scheme = "bearer";
16924
- if (header.length <= scheme.length) return null;
16925
- if (header.slice(0, scheme.length).toLowerCase() !== scheme) return null;
16947
+ if (header2.length <= scheme.length) return null;
16948
+ if (header2.slice(0, scheme.length).toLowerCase() !== scheme) return null;
16926
16949
  let index = scheme.length;
16927
- if (header[index] !== " " && header[index] !== " ") return null;
16928
- while (index < header.length && (header[index] === " " || header[index] === " ")) index += 1;
16929
- const token = header.slice(index).trim();
16950
+ if (header2[index] !== " " && header2[index] !== " ") return null;
16951
+ while (index < header2.length && (header2[index] === " " || header2[index] === " ")) index += 1;
16952
+ const token = header2.slice(index).trim();
16930
16953
  return token.length > 0 ? token : null;
16931
16954
  }
16932
16955
 
16956
+ // src/mcp/http-headers.ts
16957
+ var PROTOCOL_HEADER = "mcp-protocol-version";
16958
+ var METHOD_HEADER = "mcp-method";
16959
+ var NAME_HEADER = "mcp-name";
16960
+ var BASE64_PREFIX = "=?base64?";
16961
+ var BASE64_SUFFIX = "?=";
16962
+ var NAMED_METHODS = /* @__PURE__ */ new Set(["tools/call", "resources/read", "prompts/get"]);
16963
+ function requestId(message) {
16964
+ const raw = message.id;
16965
+ return typeof raw === "string" || typeof raw === "number" ? raw : null;
16966
+ }
16967
+ function header(request, name) {
16968
+ const value = request.headers[name];
16969
+ return typeof value === "string" ? value : null;
16970
+ }
16971
+ function isSafeHeaderValue(value) {
16972
+ return /^[\x20-\x7e\t]+$/.test(value);
16973
+ }
16974
+ function decodeMcpHeaderValue(value) {
16975
+ if (!value.startsWith(BASE64_PREFIX)) {
16976
+ return isSafeHeaderValue(value) ? value : null;
16977
+ }
16978
+ if (!value.endsWith(BASE64_SUFFIX)) return null;
16979
+ const encoded = value.slice(BASE64_PREFIX.length, -BASE64_SUFFIX.length);
16980
+ if (encoded.length === 0 || encoded.length % 4 !== 0) return null;
16981
+ if (!/^[A-Za-z0-9+/]*={0,2}$/.test(encoded)) return null;
16982
+ const decoded = Buffer.from(encoded, "base64").toString("utf8");
16983
+ if (Buffer.from(decoded, "utf8").toString("base64") !== encoded) return null;
16984
+ return decoded;
16985
+ }
16986
+ function isModernHttpMessage(request, message) {
16987
+ if (Array.isArray(message)) {
16988
+ return message.some((item) => isModernHttpMessage(request, item));
16989
+ }
16990
+ if (!isJsonObject(message)) return false;
16991
+ if (message.method === "server/discover") return true;
16992
+ const params = isJsonObject(message.params) ? message.params : void 0;
16993
+ const meta = isJsonObject(params?._meta) ? params._meta : void 0;
16994
+ if (meta !== void 0 && (META_KEYS.protocolVersion in meta || META_KEYS.clientCapabilities in meta)) {
16995
+ return true;
16996
+ }
16997
+ return header(request, METHOD_HEADER) !== null || header(request, NAME_HEADER) !== null;
16998
+ }
16999
+ function refuse(id, code, message, data) {
17000
+ return errorResponse(id, code, message, data);
17001
+ }
17002
+ function validateModernHttpHeaders(request, message) {
17003
+ if (!isModernHttpMessage(request, message)) return { modern: false };
17004
+ if (Array.isArray(message)) {
17005
+ return {
17006
+ modern: true,
17007
+ error: refuse(null, ERROR_CODES.invalidRequest, "Batch requests are not supported.")
17008
+ };
17009
+ }
17010
+ if (!isJsonObject(message)) {
17011
+ return {
17012
+ modern: true,
17013
+ error: refuse(null, ERROR_CODES.invalidRequest, "Message is not a JSON object.")
17014
+ };
17015
+ }
17016
+ const id = requestId(message);
17017
+ const method = message.method;
17018
+ const params = isJsonObject(message.params) ? message.params : void 0;
17019
+ if (typeof method !== "string" || method.length === 0) {
17020
+ return {
17021
+ modern: true,
17022
+ error: refuse(id, ERROR_CODES.invalidRequest, 'Message must carry a "method" string.')
17023
+ };
17024
+ }
17025
+ const versionHeader = header(request, PROTOCOL_HEADER);
17026
+ if (versionHeader === null) {
17027
+ return {
17028
+ modern: true,
17029
+ error: refuse(
17030
+ id,
17031
+ ERROR_CODES.headerMismatch,
17032
+ `Header mismatch: ${PROTOCOL_HEADER} is required for a modern request.`
17033
+ )
17034
+ };
17035
+ }
17036
+ if (!isSafeHeaderValue(versionHeader)) {
17037
+ return {
17038
+ modern: true,
17039
+ error: refuse(
17040
+ id,
17041
+ ERROR_CODES.headerMismatch,
17042
+ `Header mismatch: ${PROTOCOL_HEADER} contains invalid characters.`
17043
+ )
17044
+ };
17045
+ }
17046
+ const meta = inspectModernMeta(params);
17047
+ if (meta.kind !== "present") {
17048
+ const missing = meta.kind === "incomplete" ? meta.missing : META_KEYS.protocolVersion;
17049
+ return {
17050
+ modern: true,
17051
+ error: refuse(
17052
+ id,
17053
+ ERROR_CODES.invalidParams,
17054
+ `The request _meta is missing the required key "${missing}".`
17055
+ )
17056
+ };
17057
+ }
17058
+ if (versionHeader !== meta.meta.version) {
17059
+ return {
17060
+ modern: true,
17061
+ error: refuse(
17062
+ id,
17063
+ ERROR_CODES.headerMismatch,
17064
+ `Header mismatch: ${PROTOCOL_HEADER} "${versionHeader}" does not match body value "${meta.meta.version}".`
17065
+ )
17066
+ };
17067
+ }
17068
+ const methodHeader = header(request, METHOD_HEADER);
17069
+ if (methodHeader === null) {
17070
+ return {
17071
+ modern: true,
17072
+ error: refuse(
17073
+ id,
17074
+ ERROR_CODES.headerMismatch,
17075
+ `Header mismatch: ${METHOD_HEADER} is required for a modern request.`
17076
+ )
17077
+ };
17078
+ }
17079
+ if (!isSafeHeaderValue(methodHeader) || methodHeader !== method) {
17080
+ return {
17081
+ modern: true,
17082
+ error: refuse(
17083
+ id,
17084
+ ERROR_CODES.headerMismatch,
17085
+ `Header mismatch: ${METHOD_HEADER} value "${methodHeader}" does not match body value "${method}".`
17086
+ )
17087
+ };
17088
+ }
17089
+ if (NAMED_METHODS.has(method)) {
17090
+ const nameHeader = header(request, NAME_HEADER);
17091
+ if (nameHeader === null) {
17092
+ return {
17093
+ modern: true,
17094
+ error: refuse(
17095
+ id,
17096
+ ERROR_CODES.headerMismatch,
17097
+ `Header mismatch: ${NAME_HEADER} is required for ${method}.`
17098
+ )
17099
+ };
17100
+ }
17101
+ const decoded = decodeMcpHeaderValue(nameHeader);
17102
+ if (decoded === null) {
17103
+ return {
17104
+ modern: true,
17105
+ error: refuse(
17106
+ id,
17107
+ ERROR_CODES.headerMismatch,
17108
+ `Header mismatch: ${NAME_HEADER} contains an invalid value.`
17109
+ )
17110
+ };
17111
+ }
17112
+ const bodyValue = method === "resources/read" ? params?.uri : params?.name;
17113
+ if (typeof bodyValue !== "string") {
17114
+ return {
17115
+ modern: true,
17116
+ error: refuse(
17117
+ id,
17118
+ ERROR_CODES.invalidParams,
17119
+ `${method} requires a "${method === "resources/read" ? "uri" : "name"}" string.`
17120
+ )
17121
+ };
17122
+ }
17123
+ if (decoded !== bodyValue) {
17124
+ return {
17125
+ modern: true,
17126
+ error: refuse(
17127
+ id,
17128
+ ERROR_CODES.headerMismatch,
17129
+ `Header mismatch: ${NAME_HEADER} value "${decoded}" does not match body value "${bodyValue}".`
17130
+ )
17131
+ };
17132
+ }
17133
+ }
17134
+ return { modern: true };
17135
+ }
17136
+ function modernHttpStatus(response) {
17137
+ if (!("error" in response)) return 200;
17138
+ switch (response.error.code) {
17139
+ case ERROR_CODES.headerMismatch:
17140
+ case ERROR_CODES.unsupportedProtocolVersion:
17141
+ case ERROR_CODES.invalidParams:
17142
+ case ERROR_CODES.invalidRequest:
17143
+ case ERROR_CODES.parseError:
17144
+ return 400;
17145
+ case ERROR_CODES.methodNotFound:
17146
+ return 404;
17147
+ case ERROR_CODES.internalError:
17148
+ return 500;
17149
+ case ERROR_CODES.overloaded:
17150
+ return 503;
17151
+ default:
17152
+ return 200;
17153
+ }
17154
+ }
17155
+
16933
17156
  // src/mcp/http.ts
16934
17157
  var DEFAULT_MAX_BODY = 2 * 1024 * 1024;
16935
17158
  var RATE_LIMIT = 60;
@@ -16956,8 +17179,8 @@ function timingSafeEqual2(left, right) {
16956
17179
  return crypto__namespace.timingSafeEqual(a, b);
16957
17180
  }
16958
17181
  function sessionHeader(request) {
16959
- const header = request.headers["mcp-session-id"];
16960
- return typeof header === "string" ? header.trim() : "";
17182
+ const header2 = request.headers["mcp-session-id"];
17183
+ return typeof header2 === "string" ? header2.trim() : "";
16961
17184
  }
16962
17185
  function isObject(value) {
16963
17186
  return value !== null && typeof value === "object" && !Array.isArray(value);
@@ -16968,12 +17191,6 @@ function isToolCall(message) {
16968
17191
  function methodOf(message) {
16969
17192
  return isObject(message) && typeof message.method === "string" ? message.method : null;
16970
17193
  }
16971
- function hasModernMeta(message) {
16972
- const messages = Array.isArray(message) ? message : [message];
16973
- return messages.some(
16974
- (item) => isJsonObject(item) && isJsonObject(item.params) && inspectModernMeta(item.params).kind === "present"
16975
- );
16976
- }
16977
17194
  function createMcpHttpHandler(options) {
16978
17195
  const log = options.log ?? ((line) => process.stderr.write(line + "\n"));
16979
17196
  const token = options.token;
@@ -17099,7 +17316,7 @@ function createMcpHttpHandler(options) {
17099
17316
  return {
17100
17317
  "access-control-allow-origin": allowed,
17101
17318
  vary: "origin",
17102
- "access-control-allow-headers": "authorization, content-type, mcp-protocol-version, mcp-session-id",
17319
+ "access-control-allow-headers": "authorization, content-type, mcp-protocol-version, mcp-session-id, mcp-method, mcp-name",
17103
17320
  // Without this a browser can send the header but cannot read it: mcp-session-id is not a
17104
17321
  // CORS-safelisted response header, so every cross-origin client silently lost its session.
17105
17322
  "access-control-expose-headers": "mcp-session-id",
@@ -17307,6 +17524,12 @@ function createMcpHttpHandler(options) {
17307
17524
  send(response, 400, { error: "JSON-RPC batch is limited to 100 messages" }, cors);
17308
17525
  return;
17309
17526
  }
17527
+ const headers = validateModernHttpHeaders(request, message);
17528
+ if (headers.error !== void 0) {
17529
+ send(response, 400, headers.error, cors);
17530
+ return;
17531
+ }
17532
+ const modern = headers.modern;
17310
17533
  if (batch.length > 1 && rateLimited(request, batch.length - 1)) {
17311
17534
  tooMany(response, cors);
17312
17535
  return;
@@ -17325,6 +17548,8 @@ function createMcpHttpHandler(options) {
17325
17548
  rememberAnonymous(anonymousKey(request), server);
17326
17549
  responseSession = newSessionId();
17327
17550
  rememberSession(responseSession, server, Date.now());
17551
+ } else if (modern) {
17552
+ server = createMcp();
17328
17553
  } else if (supplied !== "") {
17329
17554
  const now = Date.now();
17330
17555
  pruneSessions(now);
@@ -17336,8 +17561,6 @@ function createMcpHttpHandler(options) {
17336
17561
  existing.lastSeen = now;
17337
17562
  server = existing.server;
17338
17563
  responseSession = supplied;
17339
- } else if (hasModernMeta(message)) {
17340
- server = createMcp();
17341
17564
  } else {
17342
17565
  server = fallbackServer(request);
17343
17566
  }
@@ -17361,7 +17584,8 @@ function createMcpHttpHandler(options) {
17361
17584
  send(response, 202, "", sessionHeaders);
17362
17585
  return;
17363
17586
  }
17364
- send(response, 200, Array.isArray(message) ? answers : answers[0], sessionHeaders);
17587
+ const status = modern ? modernHttpStatus(answers[0]) : 200;
17588
+ send(response, status, Array.isArray(message) ? answers : answers[0], sessionHeaders);
17365
17589
  })().catch((error) => {
17366
17590
  log("mcp/http: " + error.message);
17367
17591
  send(response, 500, { jsonrpc: "2.0", id: null, error: { code: -32603, message: "Internal error" } }, cors);
@@ -19383,13 +19607,13 @@ function auditSnapshot(options) {
19383
19607
  const text2 = partTexts.get(part.filename);
19384
19608
  const sections = partSections.get(part.filename);
19385
19609
  if (text2 === void 0 || sections === void 0) continue;
19386
- const header = /^# Codebase Snapshot Part (\d+) of (\d+)$/m.exec(text2);
19387
- if (header !== null) {
19388
- if (Number(header[1]) !== part.index) {
19389
- structureProblems.push(part.filename + " says part " + header[1] + ", the manifest says " + part.index);
19610
+ const header2 = /^# Codebase Snapshot Part (\d+) of (\d+)$/m.exec(text2);
19611
+ if (header2 !== null) {
19612
+ if (Number(header2[1]) !== part.index) {
19613
+ structureProblems.push(part.filename + " says part " + header2[1] + ", the manifest says " + part.index);
19390
19614
  }
19391
- if (Number(header[2]) !== manifest.parts.length) {
19392
- structureProblems.push(part.filename + " says " + header[2] + " parts, the manifest holds " + manifest.parts.length);
19615
+ if (Number(header2[2]) !== manifest.parts.length) {
19616
+ structureProblems.push(part.filename + " says " + header2[2] + " parts, the manifest holds " + manifest.parts.length);
19393
19617
  }
19394
19618
  }
19395
19619
  const filesLine = /^- Files: (\d+)$/m.exec(text2);
package/dist/index.d.cts CHANGED
@@ -565,7 +565,7 @@ declare function validateSnapshot(configInput: ResolvedSnapshotConfig | Snapshot
565
565
  * `package.json` carries the same version; `npm run verify` compares the two.
566
566
  */
567
567
  declare const GENERATOR_NAME = "codebase-snapshot";
568
- declare const GENERATOR_VERSION = "0.20.12";
568
+ declare const GENERATOR_VERSION = "0.20.13";
569
569
  /**
570
570
  * The manifest and ownership-marker schema this build writes and understands.
571
571
  *
package/dist/index.d.ts CHANGED
@@ -565,7 +565,7 @@ declare function validateSnapshot(configInput: ResolvedSnapshotConfig | Snapshot
565
565
  * `package.json` carries the same version; `npm run verify` compares the two.
566
566
  */
567
567
  declare const GENERATOR_NAME = "codebase-snapshot";
568
- declare const GENERATOR_VERSION = "0.20.12";
568
+ declare const GENERATOR_VERSION = "0.20.13";
569
569
  /**
570
570
  * The manifest and ownership-marker schema this build writes and understands.
571
571
  *
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { ARTIFACT_NAMES, CHECK_INTERVAL_MS, CONFIG_KEYS, DEFAULT_ANSWERS, DEFAULT_SECRET_PATTERNS, FAILURE_INTERVAL_MS, GENERATOR_NAME, GENERATOR_VERSION, HOOK_MARKER, LANGUAGE_PROFILES, MIN_MAX_PART_BYTES, MIN_MAX_PART_TOKENS, PACKAGE_LATEST_URL, PRESETS, PromptBack, PromptCancelled, REQUEST_TIMEOUT_MS, SCHEMA_VERSION, UP_TO_DATE_INTERVAL_MS, anchorForPath, appendGitignoreEntries, assertPublicHost, assertReplaceable, assertServerSafeConfig, assertUsableConfigInput, auditSnapshot, buildImportResolver, bytesForTokens, cacheDirectory, cacheFilePath, checkForUpdate, classifyKind, classifyLayer, cloneRepository, collectFiles, compareManifests, configDigest, countInvalidUtf8Bytes, countLines, crc32, decodeText, defineConfig, detectLanguage, detectPreset, displayPath, displayWidth, enforceBudget, estimateTokens, explainPath, fenceForContent, fenceForText, fetchLatestVersion, findSecretInPath, firstRunMessage, formatTokens, formatUpdateNotice, generateProjectTree, generateSarifReport, generateSnapshot, generateSnapshotAsync, getGitInfo, getPreset, gitignorePath, globToRegExp, hasPriorSnapshot, importsChangedFile, importsOfFile, importsOfText, installKind, installPreCommitHook, isBinaryBuffer, isBinaryExtension, isBinaryFile, isEffectivelyEmpty, isInteractive, isNewer, isPrivateHost, isResolvedConfig, isSensitivePath, isSkeletonizable, isTsxFileName, listPresetNames, loadConfigFile, loadConfigFileDetailed, loadManifest, lockPathFor, makeCloneDirectory, markResolvedConfig, matchRule, matchesExclude, normalizeResolvedConfig, parseByteSize, parseRemoteSource, partitionFiles, planFirstRun, profileForPath, releaseAbandonedRun, renderConfig, renderDiffText, renderExplainText, renumberParts, resolveChangedScope, resolveConfig, resolveLatest, resolveSafeOutputDirs, resolveSpecifier, runInit, scanAndRedactSecrets, shouldCheck, skeletonizeTypeScript, startWebServer, stripJsonComments, summarizeJson, summarizeMarkdown, summarizeTypeScriptSource, summarizeWithProfile, supportsTypeScriptImports, tokenAllowedForHost, treeTruncationWarnings, truncatePreview, truncateToBytes, tsconfigPathsFor, updateCommand, validateSnapshot, walkFiles, workerEntry, wrapLines, writeZip } from './chunk-TUKY6KLH.js';
1
+ export { ARTIFACT_NAMES, CHECK_INTERVAL_MS, CONFIG_KEYS, DEFAULT_ANSWERS, DEFAULT_SECRET_PATTERNS, FAILURE_INTERVAL_MS, GENERATOR_NAME, GENERATOR_VERSION, HOOK_MARKER, LANGUAGE_PROFILES, MIN_MAX_PART_BYTES, MIN_MAX_PART_TOKENS, PACKAGE_LATEST_URL, PRESETS, PromptBack, PromptCancelled, REQUEST_TIMEOUT_MS, SCHEMA_VERSION, UP_TO_DATE_INTERVAL_MS, anchorForPath, appendGitignoreEntries, assertPublicHost, assertReplaceable, assertServerSafeConfig, assertUsableConfigInput, auditSnapshot, buildImportResolver, bytesForTokens, cacheDirectory, cacheFilePath, checkForUpdate, classifyKind, classifyLayer, cloneRepository, collectFiles, compareManifests, configDigest, countInvalidUtf8Bytes, countLines, crc32, decodeText, defineConfig, detectLanguage, detectPreset, displayPath, displayWidth, enforceBudget, estimateTokens, explainPath, fenceForContent, fenceForText, fetchLatestVersion, findSecretInPath, firstRunMessage, formatTokens, formatUpdateNotice, generateProjectTree, generateSarifReport, generateSnapshot, generateSnapshotAsync, getGitInfo, getPreset, gitignorePath, globToRegExp, hasPriorSnapshot, importsChangedFile, importsOfFile, importsOfText, installKind, installPreCommitHook, isBinaryBuffer, isBinaryExtension, isBinaryFile, isEffectivelyEmpty, isInteractive, isNewer, isPrivateHost, isResolvedConfig, isSensitivePath, isSkeletonizable, isTsxFileName, listPresetNames, loadConfigFile, loadConfigFileDetailed, loadManifest, lockPathFor, makeCloneDirectory, markResolvedConfig, matchRule, matchesExclude, normalizeResolvedConfig, parseByteSize, parseRemoteSource, partitionFiles, planFirstRun, profileForPath, releaseAbandonedRun, renderConfig, renderDiffText, renderExplainText, renumberParts, resolveChangedScope, resolveConfig, resolveLatest, resolveSafeOutputDirs, resolveSpecifier, runInit, scanAndRedactSecrets, shouldCheck, skeletonizeTypeScript, startWebServer, stripJsonComments, summarizeJson, summarizeMarkdown, summarizeTypeScriptSource, summarizeWithProfile, supportsTypeScriptImports, tokenAllowedForHost, treeTruncationWarnings, truncatePreview, truncateToBytes, tsconfigPathsFor, updateCommand, validateSnapshot, walkFiles, workerEntry, wrapLines, writeZip } from './chunk-GNVRD7XS.js';