@clarify-labs/cli 0.11.2 → 0.11.4
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/output/cli/mcp/orama-loader.d.ts +3 -2
- package/output/cli.cjs +4 -3
- package/output/cli.cjs.map +1 -1
- package/output/cli.js +4 -3
- package/output/cli.js.map +1 -1
- package/output/{engine-DI8Nd3v0.js → engine-CJmXVTo5.js} +107 -32
- package/output/engine-CJmXVTo5.js.map +1 -0
- package/output/{engine--5unu78V.cjs → engine-Cgc71w13.cjs} +107 -32
- package/output/engine-Cgc71w13.cjs.map +1 -0
- package/output/index.cjs +1 -1
- package/output/index.js +1 -1
- package/output/parsers/markdown/markdown.d.ts +34 -0
- package/output/parsers/markdown/mdx.d.ts +17 -9
- package/output/plugins/mcp-search/orama-index.d.ts +8 -7
- package/package.json +3 -3
- package/output/engine--5unu78V.cjs.map +0 -1
- package/output/engine-DI8Nd3v0.js.map +0 -1
|
@@ -49,6 +49,7 @@ let vite = require("vite");
|
|
|
49
49
|
let zod = require("zod");
|
|
50
50
|
let yaml = require("yaml");
|
|
51
51
|
let node_crypto = require("node:crypto");
|
|
52
|
+
let node_zlib = require("node:zlib");
|
|
52
53
|
let _msgpack_msgpack = require("@msgpack/msgpack");
|
|
53
54
|
let _orama_orama = require("@orama/orama");
|
|
54
55
|
let node_url = require("node:url");
|
|
@@ -115,7 +116,7 @@ function createContentCompileDiagnostic(options) {
|
|
|
115
116
|
return createContentDiagnostic({
|
|
116
117
|
kind: format,
|
|
117
118
|
title: `${label} ${phase} error`,
|
|
118
|
-
message: phase === "syntax" ?
|
|
119
|
+
message: phase === "syntax" ? `This page could not be compiled. Fix the ${label} syntax or component usage above, then reload the route.` : `This page could not be compiled. Fix the ${label} syntax or plugin error below, then reload the route.`,
|
|
119
120
|
error,
|
|
120
121
|
filePath,
|
|
121
122
|
projectRoot,
|
|
@@ -128,19 +129,24 @@ function createContentCompileDiagnostic(options) {
|
|
|
128
129
|
*
|
|
129
130
|
* `rehypePlugins` includes `rehypeShiki`, which loads grammar/WASM assets and
|
|
130
131
|
* is expensive. The real highlighting happens at Vite build time via the
|
|
131
|
-
* `@mdx-js/rollup`
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* "不应在 core 中执行代码高亮".
|
|
132
|
+
* `@mdx-js/rollup` plugin (see `createContentCompilerPlugin` in
|
|
133
|
+
* `core/adapters.ts`), which runs the full remark + rehype pipeline.
|
|
134
|
+
* Re-running it here, during route discovery (Phase 3), would compile every
|
|
135
|
+
* `.mdx` file twice and invoke Shiki once per file per `engine.refresh()` -
|
|
136
|
+
* see ARCHITECTURE.md §2.2 which states "不应在 core 中执行代码高亮".
|
|
137
137
|
*
|
|
138
138
|
* The remark pipeline still runs (shared with the Vite plugin via
|
|
139
|
-
* `remarkPlugins`), so MDX/JSX syntax errors
|
|
140
|
-
* diagnostic is meant to surface ahead of the Vite build
|
|
139
|
+
* `remarkPlugins`), so MDX/JSX syntax errors - the only class of error this
|
|
140
|
+
* diagnostic is meant to surface ahead of the Vite build - are caught. The
|
|
141
141
|
* output is discarded; only the thrown error is used.
|
|
142
|
+
*
|
|
143
|
+
* `.md` files are handled by `compileMarkdownContent` in `markdown.ts`, which
|
|
144
|
+
* mirrors the adapter's markdown compiler semantics (`format: 'md'`, raw HTML
|
|
145
|
+
* allowed). Keep the two compilers separate so each format can evolve its own
|
|
146
|
+
* diagnostic rules without contaminating the other.
|
|
142
147
|
*/
|
|
143
|
-
async function compileMdxContent(content,
|
|
148
|
+
async function compileMdxContent(content, options = {}) {
|
|
149
|
+
const { filePath, projectRoot } = options;
|
|
144
150
|
try {
|
|
145
151
|
await (0, _mdx_js_mdx.compile)(content, {
|
|
146
152
|
jsx: true,
|
|
@@ -271,6 +277,54 @@ function createProjectContentProcessor(plugins, ctx) {
|
|
|
271
277
|
return createContentProcessor((input) => runHooks(plugins, "content:transform", input, ctx));
|
|
272
278
|
}
|
|
273
279
|
//#endregion
|
|
280
|
+
//#region source/parsers/markdown/markdown.ts
|
|
281
|
+
/**
|
|
282
|
+
* Validate Markdown content for diagnostics WITHOUT running the build-time
|
|
283
|
+
* rehype pipeline (Shiki highlighting, slug injection, code-block parsing).
|
|
284
|
+
*
|
|
285
|
+
* `rehypePlugins` includes `rehypeShiki`, which loads grammar/WASM assets and
|
|
286
|
+
* is expensive. The real highlighting happens at Vite build time via the
|
|
287
|
+
* `@mdx-js/rollup` plugin (see `createContentCompilerPlugin` in
|
|
288
|
+
* `core/adapters.ts`), which runs the full remark + rehype pipeline.
|
|
289
|
+
* Re-running it here, during route discovery (Phase 3), would compile every
|
|
290
|
+
* `.md` file twice and invoke Shiki once per file per `engine.refresh()` -
|
|
291
|
+
* see ARCHITECTURE.md §2.2 which states "不应在 core 中执行代码高亮".
|
|
292
|
+
*
|
|
293
|
+
* `format: 'md'` mirrors the adapter's markdown compiler semantics (no JSX,
|
|
294
|
+
* raw HTML allowed via `remarkRehypeOptions`), so the same class of syntax
|
|
295
|
+
* errors that would break the Vite build is surfaced as a diagnostic here
|
|
296
|
+
* instead of leaking out as an opaque
|
|
297
|
+
* `Failed to fetch dynamically imported module` at runtime.
|
|
298
|
+
*
|
|
299
|
+
* MDX files are handled by `compileMdxContent` in `mdx.ts`. Keep the two
|
|
300
|
+
* compilers separate so each format can evolve its own diagnostic rules
|
|
301
|
+
* without contaminating the other.
|
|
302
|
+
*/
|
|
303
|
+
async function compileMarkdownContent(content, options = {}) {
|
|
304
|
+
const { filePath, projectRoot } = options;
|
|
305
|
+
try {
|
|
306
|
+
await (0, _mdx_js_mdx.compile)(content, {
|
|
307
|
+
format: "md",
|
|
308
|
+
jsx: true,
|
|
309
|
+
providerImportSource: "@clarify-labs/renderer",
|
|
310
|
+
remarkPlugins,
|
|
311
|
+
remarkRehypeOptions: { allowDangerousHtml: true }
|
|
312
|
+
});
|
|
313
|
+
return { ok: true };
|
|
314
|
+
} catch (error) {
|
|
315
|
+
return {
|
|
316
|
+
ok: false,
|
|
317
|
+
diagnostic: createContentCompileDiagnostic({
|
|
318
|
+
format: "markdown",
|
|
319
|
+
phase: "syntax",
|
|
320
|
+
error,
|
|
321
|
+
filePath,
|
|
322
|
+
projectRoot
|
|
323
|
+
})
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
//#endregion
|
|
274
328
|
//#region source/parsers/routes/routes.ts
|
|
275
329
|
function kebabToTitle(str) {
|
|
276
330
|
return str.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
@@ -279,8 +333,10 @@ function parseMdxTree(content) {
|
|
|
279
333
|
return remark.remark.parse(content);
|
|
280
334
|
}
|
|
281
335
|
async function compileRouteDiagnostic(content, filePath, baseDir) {
|
|
282
|
-
|
|
283
|
-
|
|
336
|
+
const result = await ((0, node_path.extname)(filePath).toLowerCase() === ".md" ? compileMarkdownContent : compileMdxContent)(content, {
|
|
337
|
+
filePath,
|
|
338
|
+
projectRoot: baseDir
|
|
339
|
+
});
|
|
284
340
|
return result.ok ? void 0 : result.diagnostic;
|
|
285
341
|
}
|
|
286
342
|
/** 从内容中提取第一个 H1 标题 */
|
|
@@ -985,18 +1041,16 @@ var clarifyThemeConfigSchema = zod.z.object({
|
|
|
985
1041
|
tokens: clarifyThemeTokensConfigSchema.optional(),
|
|
986
1042
|
layout: clarifyThemeLayoutConfigSchema.optional()
|
|
987
1043
|
}).strict();
|
|
988
|
-
function featureSchema(shape, defaults) {
|
|
1044
|
+
function featureSchema(shape, defaults, enabledByDefault = true) {
|
|
1045
|
+
const resolvedDefaults = {
|
|
1046
|
+
enabled: enabledByDefault,
|
|
1047
|
+
...defaults
|
|
1048
|
+
};
|
|
989
1049
|
const objectSchema = zod.z.object({
|
|
990
|
-
enabled: zod.z.boolean().default(
|
|
1050
|
+
enabled: zod.z.boolean().default(enabledByDefault),
|
|
991
1051
|
...shape
|
|
992
|
-
}).strict().default(
|
|
993
|
-
|
|
994
|
-
...defaults
|
|
995
|
-
});
|
|
996
|
-
return zod.z.union([zod.z.boolean(), objectSchema]).default({
|
|
997
|
-
enabled: true,
|
|
998
|
-
...defaults
|
|
999
|
-
}).transform((value) => typeof value === "boolean" ? {
|
|
1052
|
+
}).strict().default(resolvedDefaults);
|
|
1053
|
+
return zod.z.union([zod.z.boolean(), objectSchema]).default(resolvedDefaults).transform((value) => typeof value === "boolean" ? {
|
|
1000
1054
|
enabled: value,
|
|
1001
1055
|
...defaults
|
|
1002
1056
|
} : value);
|
|
@@ -1004,7 +1058,7 @@ function featureSchema(shape, defaults) {
|
|
|
1004
1058
|
var clarifyFeaturesConfigSchema = zod.z.object({
|
|
1005
1059
|
search: featureSchema({ mcp: zod.z.boolean().default(true) }, { mcp: true }),
|
|
1006
1060
|
repository: featureSchema(clarifyRepositoryConfigSchema.shape, {}),
|
|
1007
|
-
themeEditor: featureSchema({}, {}),
|
|
1061
|
+
themeEditor: featureSchema({}, {}, false),
|
|
1008
1062
|
openapi: featureSchema({ playground: zod.z.boolean().default(true) }, { playground: true })
|
|
1009
1063
|
}).strict();
|
|
1010
1064
|
var clarifyProjectConfigSchema = zod.z.object({
|
|
@@ -1588,7 +1642,7 @@ function createViteAdapter(engine) {
|
|
|
1588
1642
|
}
|
|
1589
1643
|
var cliPackageVersion = {
|
|
1590
1644
|
name: "@clarify-labs/cli",
|
|
1591
|
-
version: "0.11.
|
|
1645
|
+
version: "0.11.4",
|
|
1592
1646
|
license: "AGPL-3.0-only",
|
|
1593
1647
|
type: "module",
|
|
1594
1648
|
repository: {
|
|
@@ -1970,6 +2024,22 @@ function createMcpSiteConfig(projectConfig, options) {
|
|
|
1970
2024
|
}
|
|
1971
2025
|
//#endregion
|
|
1972
2026
|
//#region source/plugins/mcp-search/orama-index.ts
|
|
2027
|
+
var MSP_MAGIC = new Uint8Array([
|
|
2028
|
+
67,
|
|
2029
|
+
76,
|
|
2030
|
+
65,
|
|
2031
|
+
82,
|
|
2032
|
+
73,
|
|
2033
|
+
70,
|
|
2034
|
+
89,
|
|
2035
|
+
77,
|
|
2036
|
+
83,
|
|
2037
|
+
80,
|
|
2038
|
+
1
|
|
2039
|
+
]);
|
|
2040
|
+
function hasMspMagic(buffer) {
|
|
2041
|
+
return buffer.byteLength >= MSP_MAGIC.byteLength && MSP_MAGIC.every((byte, index) => buffer[index] === byte);
|
|
2042
|
+
}
|
|
1973
2043
|
/**
|
|
1974
2044
|
* Orama schema for the MCP search index.
|
|
1975
2045
|
*
|
|
@@ -2208,17 +2278,22 @@ function guessTitleFromPath(path) {
|
|
|
2208
2278
|
return segments[segments.length - 1].replace(/\.(md|mdx|html)$/, "").replace(/[-_]/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
2209
2279
|
}
|
|
2210
2280
|
/**
|
|
2211
|
-
* Serialize an Orama index to a
|
|
2281
|
+
* Serialize an Orama index to a versioned, Brotli-compressed binary buffer.
|
|
2212
2282
|
*
|
|
2213
|
-
* Uses `save()` to extract the raw index data,
|
|
2214
|
-
*
|
|
2215
|
-
*
|
|
2283
|
+
* Uses `save()` to extract the raw index data, MessagePack-encodes it, then
|
|
2284
|
+
* compresses the payload so source documents are not embedded as contiguous
|
|
2285
|
+
* plaintext. The leading magic bytes identify the container and its version.
|
|
2216
2286
|
*/
|
|
2217
2287
|
function serializeSearchIndex(db) {
|
|
2218
|
-
|
|
2288
|
+
const compressed = (0, node_zlib.brotliCompressSync)((0, _msgpack_msgpack.encode)((0, _orama_orama.save)(db)), { params: { [node_zlib.constants.BROTLI_PARAM_QUALITY]: 9 } });
|
|
2289
|
+
const buffer = new Uint8Array(MSP_MAGIC.byteLength + compressed.byteLength);
|
|
2290
|
+
buffer.set(MSP_MAGIC);
|
|
2291
|
+
buffer.set(compressed, MSP_MAGIC.byteLength);
|
|
2292
|
+
return buffer;
|
|
2219
2293
|
}
|
|
2220
2294
|
/**
|
|
2221
|
-
* Deserialize a
|
|
2295
|
+
* Deserialize a current compressed container or legacy MessagePack buffer
|
|
2296
|
+
* into a ready-to-search Orama index.
|
|
2222
2297
|
*
|
|
2223
2298
|
* The caller must supply the same `defaultLocale` used when the index was
|
|
2224
2299
|
* built, so the tokenizer matches. A mismatch would not corrupt data but
|
|
@@ -2226,7 +2301,7 @@ function serializeSearchIndex(db) {
|
|
|
2226
2301
|
* as a single token instead of split into "文" + "档").
|
|
2227
2302
|
*/
|
|
2228
2303
|
function deserializeSearchIndex(buffer, defaultLocale) {
|
|
2229
|
-
const raw = (0, _msgpack_msgpack.decode)(buffer);
|
|
2304
|
+
const raw = (0, _msgpack_msgpack.decode)(hasMspMagic(buffer) ? (0, node_zlib.brotliDecompressSync)(buffer.subarray(MSP_MAGIC.byteLength)) : buffer);
|
|
2230
2305
|
const db = createMcpSearchIndex(defaultLocale);
|
|
2231
2306
|
(0, _orama_orama.load)(db, raw);
|
|
2232
2307
|
return db;
|
|
@@ -3856,4 +3931,4 @@ Object.defineProperty(exports, "searchMcpIndex", {
|
|
|
3856
3931
|
}
|
|
3857
3932
|
});
|
|
3858
3933
|
|
|
3859
|
-
//# sourceMappingURL=engine
|
|
3934
|
+
//# sourceMappingURL=engine-Cgc71w13.cjs.map
|