@clarify-labs/cli 0.11.0 → 0.11.2
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/commands/mcp.d.ts +27 -0
- package/output/cli/mcp/orama-loader.d.ts +57 -0
- package/output/cli/mcp/search-server.d.ts +34 -0
- package/output/cli/program.d.ts +0 -1
- package/output/cli.cjs +303 -13
- package/output/cli.cjs.map +1 -1
- package/output/cli.js +304 -14
- package/output/cli.js.map +1 -1
- package/output/core/config/config-schema.d.ts +6 -220
- package/output/core/plugin/hooks.d.ts +0 -1
- package/output/core/runtime/html-template.d.ts +0 -6
- package/output/core/runtime/virtual-modules.d.ts +0 -4
- package/output/{engine-BfkoyVNo.cjs → engine--5unu78V.cjs} +385 -28
- package/output/engine--5unu78V.cjs.map +1 -0
- package/output/{engine-DfF5RJjC.js → engine-DI8Nd3v0.js} +374 -29
- package/output/engine-DI8Nd3v0.js.map +1 -0
- package/output/index.cjs +1 -1
- package/output/index.js +1 -1
- package/output/parsers/routes/routes.d.ts +1 -5
- package/output/plugins/content-artifacts/artifacts.d.ts +0 -2
- package/output/plugins/mcp-search/index.d.ts +15 -0
- package/output/plugins/mcp-search/mcp-config.d.ts +75 -0
- package/output/plugins/mcp-search/orama-index.d.ts +153 -0
- package/output/plugins/openapi/virtual-modules.d.ts +0 -1
- package/output/plugins/page-search/index.d.ts +2 -0
- package/output/types.d.ts +3 -2
- package/package.json +6 -4
- package/output/engine-BfkoyVNo.cjs.map +0 -1
- package/output/engine-DfF5RJjC.js.map +0 -1
- package/output/plugins/search-index/index.d.ts +0 -2
- /package/output/plugins/{search-index → page-search}/search-language.d.ts +0 -0
package/output/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_engine = require("./engine
|
|
2
|
+
const require_engine = require("./engine--5unu78V.cjs");
|
|
3
3
|
exports.ClarifyEngine = require_engine.ClarifyEngine;
|
|
4
4
|
exports.createClarifyEngine = require_engine.createClarifyEngine;
|
|
5
5
|
exports.createViteAdapter = require_engine.createViteAdapter;
|
package/output/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as createViteAdapter, n as createClarifyEngine, t as ClarifyEngine, u as defineConfig } from "./engine-DI8Nd3v0.js";
|
|
2
2
|
export { ClarifyEngine, createClarifyEngine, createViteAdapter, defineConfig };
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import { ContentRoute,
|
|
1
|
+
import { ContentRoute, ClarifyNavigationNode, ClarifyPagesConfig, ClarifyPagesGroup, ClarifyPagesItem, ClarifyRouteIntent, ClarifyTabsConfig, LocalizedNavigation, LocalizedTabbedNavigation, ResolvedClarifyLocalesConfig, TabbedNavigation } from '../../types.js';
|
|
2
2
|
import { ContentProcessor } from '../content/content.js';
|
|
3
3
|
export type FindContentRoutesOptions = {
|
|
4
4
|
contentProcessor?: ContentProcessor;
|
|
5
5
|
};
|
|
6
6
|
export declare function kebabToTitle(str: string): string;
|
|
7
|
-
/** 从 MDX/Markdown 内容中提取 H2/H3 章节 */
|
|
8
|
-
export declare function extractMdxSections(content: string): ContentSection[];
|
|
9
7
|
export declare function normalizePath(path: string): string;
|
|
10
|
-
export declare function openAPITagsPathSegment(tags: string[]): string;
|
|
11
8
|
export declare function basePathFromRef(ref: string): string;
|
|
12
9
|
export declare function openAPIPagePathFromRef(ref: string, tagFilter?: string[], explicitPath?: string): string;
|
|
13
10
|
export declare function routePathFromRef(ref: string, explicitPath?: string): string;
|
|
14
11
|
export declare function virtualModuleIdFromRef(ref: string): string;
|
|
15
12
|
export declare function localizedRoutePath(basePath: string, locale: string, _i18n: ResolvedClarifyLocalesConfig): string;
|
|
16
|
-
export declare function resolveLocalizedText(text: ClarifyLocalizedText | undefined, locale: string, fallbackLocale?: string): string | undefined;
|
|
17
13
|
export declare function findContentRoutes(dir: string, base?: string, options?: FindContentRoutesOptions): Promise<ContentRoute[]>;
|
|
18
14
|
export declare function withAlternates(route: ContentRoute, routes: ContentRoute[], locales: ResolvedClarifyLocalesConfig): ContentRoute;
|
|
19
15
|
export declare function findLocalizedContentRoutes(contentRoot: string, locales?: ResolvedClarifyLocalesConfig, options?: FindContentRoutesOptions): Promise<ContentRoute[]>;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { ContentRoute, ResolvedProjectConfig } from '../../types.js';
|
|
2
|
-
export declare function routeToMarkdownArtifactUrl(routePath: string): string;
|
|
3
|
-
export declare function routeToOpenAPIArtifactUrl(routePath: string): string;
|
|
4
2
|
export declare function attachContentArtifactUrls(routes: ContentRoute[]): void;
|
|
5
3
|
export declare function readRouteContent(route: ContentRoute): string;
|
|
6
4
|
export declare function readRouteArtifactContent(route: ContentRoute): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ClarifyPlugin } from '../../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* MCP search index plugin.
|
|
4
|
+
*
|
|
5
|
+
* Generates the Orama binary index (`mcp-search.msp`) and the MCP site
|
|
6
|
+
* descriptor (`mcp.json`) as build assets consumed by the `clarify mcp`
|
|
7
|
+
* command to serve documentation search to MCP-aware clients (e.g. AI coding
|
|
8
|
+
* assistants).
|
|
9
|
+
*
|
|
10
|
+
* This plugin is independent of `clarify:page-search` (Pagefind), which
|
|
11
|
+
* powers in-browser search. The MCP server runs in Node and needs a
|
|
12
|
+
* self-contained, compact index with CJK-aware tokenization that doesn't
|
|
13
|
+
* depend on the browser-only Pagefind runtime.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createMcpSearchPlugin(): ClarifyPlugin;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ResolvedProjectConfig } from '../../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Descriptor for a single MCP capability surfaced by a Clarify site.
|
|
4
|
+
*
|
|
5
|
+
* Capabilities are intentionally open-ended so future versions can add
|
|
6
|
+
* `resources`, `prompts`, etc. without reshaping the top-level file. Each
|
|
7
|
+
* capability carries its own metadata block; the CLI selects the block(s)
|
|
8
|
+
* it understands and ignores the rest.
|
|
9
|
+
*/
|
|
10
|
+
export type McpCapability = McpSearchCapability;
|
|
11
|
+
/**
|
|
12
|
+
* Full-text search capability backed by an Orama binary index.
|
|
13
|
+
*/
|
|
14
|
+
export type McpSearchCapability = {
|
|
15
|
+
/** Capability discriminator. */
|
|
16
|
+
type: 'search';
|
|
17
|
+
/**
|
|
18
|
+
* Root-relative path to the Orama binary index (`.msp`) produced at build
|
|
19
|
+
* time. Always served from the site root, so it already includes the
|
|
20
|
+
* routePrefix when one is configured.
|
|
21
|
+
*/
|
|
22
|
+
indexPath: string;
|
|
23
|
+
/** SHA-256 hash of the index payload at indexPath, for cache freshness checks. */
|
|
24
|
+
indexHash?: string;
|
|
25
|
+
/** Locale used when the caller does not specify one. Drives tokenizer. */
|
|
26
|
+
defaultLocale?: string;
|
|
27
|
+
/** Number of documents stored in the index. */
|
|
28
|
+
documentCount: number;
|
|
29
|
+
/** Locales present in the index, for surfacing in tool descriptions. */
|
|
30
|
+
locales: string[];
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* MCP server descriptor emitted to `<output>/mcp.json` during build.
|
|
34
|
+
*
|
|
35
|
+
* Consumed by `clarify mcp <url>` to bootstrap a local MCP server that
|
|
36
|
+
* exposes site capabilities (currently full-text search) to LLM clients.
|
|
37
|
+
* The descriptor points the CLI at the Orama binary index (`.msp`) written
|
|
38
|
+
* alongside `mcp.json` and carries the locale metadata needed to reconstruct
|
|
39
|
+
* the tokenizer at runtime.
|
|
40
|
+
*/
|
|
41
|
+
export type McpSiteConfig = {
|
|
42
|
+
/** Schema version of this file. Bumped on breaking shape changes. */
|
|
43
|
+
version: 3;
|
|
44
|
+
site: {
|
|
45
|
+
title?: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
/** Canonical public site URL, if `siteUrl` is configured. */
|
|
48
|
+
url?: string;
|
|
49
|
+
/** Route prefix where the site is mounted. Default: '/'. */
|
|
50
|
+
routePrefix: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Capability map keyed by capability id. The id is stable across builds so
|
|
54
|
+
* clients can address a specific capability (e.g. `search`) even as new
|
|
55
|
+
* ones are added. Only capabilities actually emitted by the build are
|
|
56
|
+
* present; an absent key means the site does not provide that capability.
|
|
57
|
+
*/
|
|
58
|
+
capabilities: {
|
|
59
|
+
search?: McpSearchCapability;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
export type CreateMcpSiteConfigOptions = {
|
|
63
|
+
documentCount: number;
|
|
64
|
+
locales: string[];
|
|
65
|
+
indexHash: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Assemble the MCP site config from build-time metadata.
|
|
69
|
+
*
|
|
70
|
+
* Unlike the previous pagefind-based descriptor, this no longer reads an
|
|
71
|
+
* entry JSON file - the Orama index is a single binary blob, so the caller
|
|
72
|
+
* supplies the document count and locale list directly from the build step
|
|
73
|
+
* that produced the index.
|
|
74
|
+
*/
|
|
75
|
+
export declare function createMcpSiteConfig(projectConfig: ResolvedProjectConfig, options: CreateMcpSiteConfigOptions): McpSiteConfig;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { AnyOrama } from '@orama/orama';
|
|
2
|
+
import { ContentRoute } from '../../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Orama schema for the MCP search index.
|
|
5
|
+
*
|
|
6
|
+
* - `path`, `title`, `description`, `content` are full-text searchable strings.
|
|
7
|
+
* - `locale` is an `enum` so we can use `where: { locale: { eq } }` filters at
|
|
8
|
+
* query time. (`string` fields cannot be filtered in Orama.)
|
|
9
|
+
* - `keywords` is a `string[]` also indexed for full-text matching.
|
|
10
|
+
*/
|
|
11
|
+
export declare const mcpSearchSchema: {
|
|
12
|
+
readonly path: "string";
|
|
13
|
+
readonly title: "string";
|
|
14
|
+
readonly description: "string";
|
|
15
|
+
readonly locale: "enum";
|
|
16
|
+
readonly content: "string";
|
|
17
|
+
readonly keywords: "string[]";
|
|
18
|
+
};
|
|
19
|
+
export type McpSearchDocument = {
|
|
20
|
+
path: string;
|
|
21
|
+
title: string;
|
|
22
|
+
description: string;
|
|
23
|
+
locale: string;
|
|
24
|
+
content: string;
|
|
25
|
+
keywords: string[];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Tokenize text for Orama indexing and querying.
|
|
29
|
+
*
|
|
30
|
+
* CJK locales use `Intl.Segmenter` (word granularity), which splits
|
|
31
|
+
* spaceless scripts into words and individual characters. Latin/whitespace
|
|
32
|
+
* locales fall back to a Unicode-aware split on spaces and punctuation.
|
|
33
|
+
*
|
|
34
|
+
* All tokens are lowercased so queries match regardless of case.
|
|
35
|
+
*/
|
|
36
|
+
export declare function tokenizeForSearch(text: string, locale?: string): string[];
|
|
37
|
+
/**
|
|
38
|
+
* Build an Orama tokenizer component bound to a specific default locale.
|
|
39
|
+
*
|
|
40
|
+
* The tokenizer receives the raw field value and the per-field language hint
|
|
41
|
+
* from Orama (which we don't set per-field, so it falls back to the default
|
|
42
|
+
* language). We resolve the segmenter locale from the default locale at
|
|
43
|
+
* construction time so the same tokenizer handles all documents in a
|
|
44
|
+
* predominantly single-locale index.
|
|
45
|
+
*
|
|
46
|
+
* For multi-locale indexes, the tokenizer is also used at query time. Since
|
|
47
|
+
* the query locale is not known to Orama's tokenizer callback, we use the
|
|
48
|
+
* index's default locale - this is acceptable because:
|
|
49
|
+
* - CJK queries get CJK segmentation (correct)
|
|
50
|
+
* - Latin queries against a CJK-default index still work because Latin
|
|
51
|
+
* text has no word boundaries for CJK segmenters to mis-split; the
|
|
52
|
+
* segmenter passes through Latin words as-is.
|
|
53
|
+
*/
|
|
54
|
+
export declare function createMcpTokenizer(defaultLocale?: string): {
|
|
55
|
+
language: string;
|
|
56
|
+
normalizationCache: Map<string, string>;
|
|
57
|
+
tokenize(raw: unknown, language?: string): string[];
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Compose the searchable text for a route. Shared between the Pagefind
|
|
61
|
+
* (browser) and Orama (MCP) indexing paths so both backends see the same
|
|
62
|
+
* field order and content.
|
|
63
|
+
*/
|
|
64
|
+
export declare function routeSearchContent(route: ContentRoute): string;
|
|
65
|
+
/**
|
|
66
|
+
* Convert a `ContentRoute` into the document shape stored in the Orama index.
|
|
67
|
+
*/
|
|
68
|
+
export declare function routeToSearchDocument(route: ContentRoute, defaultLocale?: string): McpSearchDocument | null;
|
|
69
|
+
/**
|
|
70
|
+
* Create an Orama index pre-configured with the MCP schema and CJK-aware
|
|
71
|
+
* tokenizer. Both the build step and the runtime loader use this so the
|
|
72
|
+
* tokenizer is guaranteed to match between indexing and querying.
|
|
73
|
+
*
|
|
74
|
+
* Annotated as `AnyOrama` (Orama's exported base type) rather than inferred
|
|
75
|
+
* via `ReturnType<typeof create>` because the inference would pull in
|
|
76
|
+
* Orama's internal component types (`DocumentsStore`, `Index`, `Sorter`)
|
|
77
|
+
* which are not exported and break `.d.ts` generation (TS2883).
|
|
78
|
+
*/
|
|
79
|
+
export declare function createMcpSearchIndex(defaultLocale?: string): McpSearchDb;
|
|
80
|
+
/** Orama index instance type for the MCP search schema. */
|
|
81
|
+
export type McpSearchDb = AnyOrama<typeof mcpSearchSchema>;
|
|
82
|
+
/**
|
|
83
|
+
* Insert search documents into an Orama index.
|
|
84
|
+
*/
|
|
85
|
+
export declare function indexSearchDocuments(db: McpSearchDb, documents: McpSearchDocument[]): void;
|
|
86
|
+
/**
|
|
87
|
+
* Build a ready-to-search Orama index from content routes.
|
|
88
|
+
*
|
|
89
|
+
* Filters out bare aliases and empty routes. Returns the populated db.
|
|
90
|
+
*/
|
|
91
|
+
export declare function buildSearchIndex(routes: ContentRoute[], defaultLocale?: string): {
|
|
92
|
+
db: McpSearchDb;
|
|
93
|
+
documentCount: number;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Collect the distinct locale codes that will be present in the Orama index,
|
|
97
|
+
* in stable insertion order. Bare aliases are skipped (they duplicate the
|
|
98
|
+
* default-locale route). Locales with no code fall back to the project
|
|
99
|
+
* default so single-locale sites still surface one locale.
|
|
100
|
+
*/
|
|
101
|
+
export declare function collectIndexedLocales(routes: ContentRoute[], defaultLocale?: string): string[];
|
|
102
|
+
export type McpSearchParams = {
|
|
103
|
+
query: string;
|
|
104
|
+
locale?: string;
|
|
105
|
+
limit?: number;
|
|
106
|
+
};
|
|
107
|
+
export type McpSearchHit = {
|
|
108
|
+
path: string;
|
|
109
|
+
title: string;
|
|
110
|
+
description: string;
|
|
111
|
+
locale: string;
|
|
112
|
+
score: number;
|
|
113
|
+
excerpt: string;
|
|
114
|
+
keywords: string[];
|
|
115
|
+
};
|
|
116
|
+
export type McpSearchResult = {
|
|
117
|
+
hits: McpSearchHit[];
|
|
118
|
+
count: number;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Search an Orama MCP index.
|
|
122
|
+
*
|
|
123
|
+
* Applies an optional locale filter (via the `enum` field) and returns a
|
|
124
|
+
* compact, LLM-friendly hit shape. Excerpts are derived from the matched
|
|
125
|
+
* content: Orama does not return highlighted excerpts, so we synthesize a
|
|
126
|
+
* short window around the first query term occurrence.
|
|
127
|
+
*/
|
|
128
|
+
export declare function searchMcpIndex(db: McpSearchDb, params: McpSearchParams): McpSearchResult;
|
|
129
|
+
/**
|
|
130
|
+
* Serialize an Orama index to a msgpack binary buffer.
|
|
131
|
+
*
|
|
132
|
+
* Uses `save()` to extract the raw index data, then msgpack-encodes it for a
|
|
133
|
+
* compact binary representation. The same schema + tokenizer must be supplied
|
|
134
|
+
* when loading so query-time tokenization matches indexing-time tokenization.
|
|
135
|
+
*/
|
|
136
|
+
export declare function serializeSearchIndex(db: McpSearchDb): Uint8Array;
|
|
137
|
+
/**
|
|
138
|
+
* Deserialize a msgpack binary buffer into a ready-to-search Orama index.
|
|
139
|
+
*
|
|
140
|
+
* The caller must supply the same `defaultLocale` used when the index was
|
|
141
|
+
* built, so the tokenizer matches. A mismatch would not corrupt data but
|
|
142
|
+
* would cause CJK query terms to be tokenized incorrectly (e.g. "文档" left
|
|
143
|
+
* as a single token instead of split into "文" + "档").
|
|
144
|
+
*/
|
|
145
|
+
export declare function deserializeSearchIndex(buffer: Uint8Array, defaultLocale?: string): McpSearchDb;
|
|
146
|
+
/**
|
|
147
|
+
* Write an Orama index to a `.msp` (msgpack) file on disk.
|
|
148
|
+
*/
|
|
149
|
+
export declare function writeSearchIndex(db: McpSearchDb, filePath: string): void;
|
|
150
|
+
/**
|
|
151
|
+
* Read an Orama index from a `.msp` (msgpack) file on disk.
|
|
152
|
+
*/
|
|
153
|
+
export declare function readSearchIndex(filePath: string, defaultLocale?: string): McpSearchDb;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { OpenAPISpec } from '../../types.js';
|
|
2
2
|
export declare const openApiRegistryModuleId = "virtual:clarify/openapi";
|
|
3
3
|
export declare const openApiServerRegistryModuleId = "virtual:clarify/openapi/server";
|
|
4
|
-
export declare const OPENAPI_SPEC_PREFIX = "virtual:clarify/openapi-spec/";
|
|
5
4
|
export declare function specVirtualModuleId(specKey: string): string;
|
|
6
5
|
export declare function generateOpenAPIRegistryModule(openApiSpecs: Record<string, string>): string;
|
|
7
6
|
export declare function generateOpenAPIServerRegistryModule(openApiSpecs: Record<string, OpenAPISpec>): string;
|
package/output/types.d.ts
CHANGED
|
@@ -185,7 +185,8 @@ export type ClarifyFeatureConfig<Options extends object = Record<never, never>>
|
|
|
185
185
|
} & Options);
|
|
186
186
|
export type ClarifyFeaturesConfig = {
|
|
187
187
|
search?: ClarifyFeatureConfig<{
|
|
188
|
-
|
|
188
|
+
/** Whether to emit the MCP search index + descriptor for `clarify mcp`. Default: true. */
|
|
189
|
+
mcp?: boolean;
|
|
189
190
|
}>;
|
|
190
191
|
repository?: ClarifyFeatureConfig<ClarifyRepositoryConfig>;
|
|
191
192
|
themeEditor?: ClarifyFeatureConfig;
|
|
@@ -196,7 +197,7 @@ export type ClarifyFeaturesConfig = {
|
|
|
196
197
|
export type ResolvedClarifyFeaturesConfig = {
|
|
197
198
|
search: {
|
|
198
199
|
enabled: boolean;
|
|
199
|
-
|
|
200
|
+
mcp: boolean;
|
|
200
201
|
};
|
|
201
202
|
repository: {
|
|
202
203
|
enabled: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clarify-labs/cli",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -39,10 +39,13 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@apidevtools/swagger-parser": "^12.1.0",
|
|
42
|
-
"@clarify-labs/renderer": "0.11.
|
|
43
|
-
"@clarify-labs/templates": "0.11.
|
|
42
|
+
"@clarify-labs/renderer": "0.11.2",
|
|
43
|
+
"@clarify-labs/templates": "0.11.2",
|
|
44
44
|
"@mdx-js/mdx": "^3.1.1",
|
|
45
45
|
"@mdx-js/rollup": "^3.1.1",
|
|
46
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
47
|
+
"@msgpack/msgpack": "^3.1.3",
|
|
48
|
+
"@orama/orama": "^3.1.18",
|
|
46
49
|
"@shikijs/rehype": "^4.3.0",
|
|
47
50
|
"@tailwindcss/vite": "^4.3.2",
|
|
48
51
|
"@vitejs/plugin-react": "^6.0.3",
|
|
@@ -61,7 +64,6 @@
|
|
|
61
64
|
"rehype-raw": "^7.0.0",
|
|
62
65
|
"rehype-slug": "^6.0.0",
|
|
63
66
|
"remark": "^15.0.1",
|
|
64
|
-
"remark-gfm": "^4.0.1",
|
|
65
67
|
"shiki": "4.3.0",
|
|
66
68
|
"unist-util-visit": "^5.1.0",
|
|
67
69
|
"vite": "^8.1.4",
|