@clarify-labs/cli 0.11.1 → 0.11.3

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.
@@ -18,6 +18,8 @@ import { createReadStream, existsSync, mkdirSync, mkdtempSync, readFileSync, rea
18
18
  import { build, loadConfigFromFile } from "vite";
19
19
  import { z } from "zod";
20
20
  import { stringify } from "yaml";
21
+ import { createHash } from "node:crypto";
22
+ import { brotliCompressSync, brotliDecompressSync, constants } from "node:zlib";
21
23
  import { decode, encode } from "@msgpack/msgpack";
22
24
  import { create, insertMultiple, load, save, search } from "@orama/orama";
23
25
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -1556,7 +1558,7 @@ function createViteAdapter(engine) {
1556
1558
  }
1557
1559
  var cliPackageVersion = {
1558
1560
  name: "@clarify-labs/cli",
1559
- version: "0.11.1",
1561
+ version: "0.11.3",
1560
1562
  license: "AGPL-3.0-only",
1561
1563
  type: "module",
1562
1564
  repository: {
@@ -1929,6 +1931,7 @@ function createMcpSiteConfig(projectConfig, options) {
1929
1931
  capabilities: { search: {
1930
1932
  type: "search",
1931
1933
  indexPath: `${prefix}/mcp-search.msp`,
1934
+ indexHash: options.indexHash,
1932
1935
  defaultLocale: projectConfig.locales?.default,
1933
1936
  documentCount: options.documentCount,
1934
1937
  locales: options.locales
@@ -1937,6 +1940,22 @@ function createMcpSiteConfig(projectConfig, options) {
1937
1940
  }
1938
1941
  //#endregion
1939
1942
  //#region source/plugins/mcp-search/orama-index.ts
1943
+ var MSP_MAGIC = new Uint8Array([
1944
+ 67,
1945
+ 76,
1946
+ 65,
1947
+ 82,
1948
+ 73,
1949
+ 70,
1950
+ 89,
1951
+ 77,
1952
+ 83,
1953
+ 80,
1954
+ 1
1955
+ ]);
1956
+ function hasMspMagic(buffer) {
1957
+ return buffer.byteLength >= MSP_MAGIC.byteLength && MSP_MAGIC.every((byte, index) => buffer[index] === byte);
1958
+ }
1940
1959
  /**
1941
1960
  * Orama schema for the MCP search index.
1942
1961
  *
@@ -2175,17 +2194,22 @@ function guessTitleFromPath(path) {
2175
2194
  return segments[segments.length - 1].replace(/\.(md|mdx|html)$/, "").replace(/[-_]/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
2176
2195
  }
2177
2196
  /**
2178
- * Serialize an Orama index to a msgpack binary buffer.
2197
+ * Serialize an Orama index to a versioned, Brotli-compressed binary buffer.
2179
2198
  *
2180
- * Uses `save()` to extract the raw index data, then msgpack-encodes it for a
2181
- * compact binary representation. The same schema + tokenizer must be supplied
2182
- * when loading so query-time tokenization matches indexing-time tokenization.
2199
+ * Uses `save()` to extract the raw index data, MessagePack-encodes it, then
2200
+ * compresses the payload so source documents are not embedded as contiguous
2201
+ * plaintext. The leading magic bytes identify the container and its version.
2183
2202
  */
2184
2203
  function serializeSearchIndex(db) {
2185
- return encode(save(db));
2204
+ const compressed = brotliCompressSync(encode(save(db)), { params: { [constants.BROTLI_PARAM_QUALITY]: 9 } });
2205
+ const buffer = new Uint8Array(MSP_MAGIC.byteLength + compressed.byteLength);
2206
+ buffer.set(MSP_MAGIC);
2207
+ buffer.set(compressed, MSP_MAGIC.byteLength);
2208
+ return buffer;
2186
2209
  }
2187
2210
  /**
2188
- * Deserialize a msgpack binary buffer into a ready-to-search Orama index.
2211
+ * Deserialize a current compressed container or legacy MessagePack buffer
2212
+ * into a ready-to-search Orama index.
2189
2213
  *
2190
2214
  * The caller must supply the same `defaultLocale` used when the index was
2191
2215
  * built, so the tokenizer matches. A mismatch would not corrupt data but
@@ -2193,7 +2217,7 @@ function serializeSearchIndex(db) {
2193
2217
  * as a single token instead of split into "文" + "档").
2194
2218
  */
2195
2219
  function deserializeSearchIndex(buffer, defaultLocale) {
2196
- const raw = decode(buffer);
2220
+ const raw = decode(hasMspMagic(buffer) ? brotliDecompressSync(buffer.subarray(MSP_MAGIC.byteLength)) : buffer);
2197
2221
  const db = createMcpSearchIndex(defaultLocale);
2198
2222
  load(db, raw);
2199
2223
  return db;
@@ -2222,13 +2246,16 @@ function createMcpSearchPlugin() {
2222
2246
  const defaultLocale = ctx.projectConfig.locales?.default;
2223
2247
  const { db, documentCount } = buildSearchIndex(ctx.routes, defaultLocale);
2224
2248
  const locales = collectIndexedLocales(ctx.routes, defaultLocale);
2249
+ const indexBytes = serializeSearchIndex(db);
2250
+ const indexHash = createHash("sha256").update(indexBytes).digest("hex");
2225
2251
  const mcpConfig = createMcpSiteConfig(ctx.projectConfig, {
2226
2252
  documentCount,
2227
- locales
2253
+ locales,
2254
+ indexHash
2228
2255
  });
2229
2256
  const assets = [{
2230
2257
  fileName: `${mcpConfig.capabilities.search?.indexPath.replace(/\/mcp-search\.msp$/, "") ?? ""}/mcp-search.msp`.replace(/^\//, ""),
2231
- source: serializeSearchIndex(db)
2258
+ source: indexBytes
2232
2259
  }, {
2233
2260
  fileName: "mcp.json",
2234
2261
  source: `${JSON.stringify(mcpConfig, null, 2)}\n`
@@ -3761,4 +3788,4 @@ function createClarifyEngine(options = {}) {
3761
3788
  //#endregion
3762
3789
  export { deserializeSearchIndex as a, cliPackageVersionWithCaret as c, createClarifyTempDir as i, createViteAdapter as l, createClarifyEngine as n, searchMcpIndex as o, createClarifyRuntimeAliases as r, cliPackageVersion as s, ClarifyEngine as t, defineConfig as u };
3763
3790
 
3764
- //# sourceMappingURL=engine-CxnKEKv8.js.map
3791
+ //# sourceMappingURL=engine-CrYRJRZT.js.map