@xh/hoist-docs 0.0.0-stage → 0.0.1
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/LICENSE.md +190 -0
- package/README.md +145 -2
- package/bin/hoist-docs.mjs +16 -0
- package/dist/IndexStore.d.ts +78 -0
- package/dist/IndexStore.js +249 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +258 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.js +18 -0
- package/dist/docs/index.d.ts +70 -0
- package/dist/docs/index.js +101 -0
- package/dist/index/DocEntry.d.ts +16 -0
- package/dist/index/DocEntry.js +32 -0
- package/dist/index/DocIdResolver.d.ts +31 -0
- package/dist/index/DocIdResolver.js +159 -0
- package/dist/index/DocSearch.d.ts +41 -0
- package/dist/index/DocSearch.js +180 -0
- package/dist/index/LibraryIndex.d.ts +62 -0
- package/dist/index/LibraryIndex.js +153 -0
- package/dist/index/SymbolSearch.d.ts +52 -0
- package/dist/index/SymbolSearch.js +249 -0
- package/dist/index/doc-sections.d.ts +94 -0
- package/dist/index/doc-sections.js +260 -0
- package/dist/index/search-text.d.ts +78 -0
- package/dist/index/search-text.js +140 -0
- package/dist/index/types.d.ts +115 -0
- package/dist/index/types.js +11 -0
- package/dist/libraries.d.ts +57 -0
- package/dist/libraries.js +38 -0
- package/dist/local/cache.d.ts +25 -0
- package/dist/local/cache.js +62 -0
- package/dist/local/checkout.d.ts +6 -0
- package/dist/local/checkout.js +178 -0
- package/dist/local/installed.d.ts +22 -0
- package/dist/local/installed.js +99 -0
- package/dist/local/maven.d.ts +49 -0
- package/dist/local/maven.js +184 -0
- package/dist/local/npm.d.ts +24 -0
- package/dist/local/npm.js +66 -0
- package/dist/local/project.d.ts +26 -0
- package/dist/local/project.js +103 -0
- package/dist/local/registry.d.ts +15 -0
- package/dist/local/registry.js +67 -0
- package/dist/local/sources.d.ts +30 -0
- package/dist/local/sources.js +50 -0
- package/dist/local/tar.d.ts +6 -0
- package/dist/local/tar.js +31 -0
- package/dist/log.d.ts +10 -0
- package/dist/log.js +31 -0
- package/dist/mcp.d.ts +23 -0
- package/dist/mcp.js +396 -0
- package/dist/server.d.ts +15 -0
- package/dist/server.js +88 -0
- package/dist/tools/DocTools.d.ts +19 -0
- package/dist/tools/DocTools.js +245 -0
- package/dist/tools/SymbolTools.d.ts +27 -0
- package/dist/tools/SymbolTools.js +572 -0
- package/dist/tools/types.d.ts +6 -0
- package/dist/tools/types.js +7 -0
- package/dist/usage.d.ts +10 -0
- package/dist/usage.js +11 -0
- package/package.json +62 -4
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file belongs to Hoist, an application development toolkit
|
|
3
|
+
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
|
|
4
|
+
*
|
|
5
|
+
* Copyright © 2026 Extremely Heavy Industries Inc.
|
|
6
|
+
*/
|
|
7
|
+
//------------------------------------------------------------------
|
|
8
|
+
// Tokens
|
|
9
|
+
//------------------------------------------------------------------
|
|
10
|
+
/**
|
|
11
|
+
* Estimate LLM token count for a string at ~4 characters per token. Coarse, but stable and
|
|
12
|
+
* good enough to size reads and keep search output within budget.
|
|
13
|
+
*/
|
|
14
|
+
export function estimateTokens(text) {
|
|
15
|
+
return Math.ceil(text.length / 4);
|
|
16
|
+
}
|
|
17
|
+
/** Format a token estimate for display, e.g. `~6,760 tokens`. */
|
|
18
|
+
export function formatTokens(tokens) {
|
|
19
|
+
return `~${tokens.toLocaleString('en-US')} tokens`;
|
|
20
|
+
}
|
|
21
|
+
//------------------------------------------------------------------
|
|
22
|
+
// Parsing
|
|
23
|
+
//------------------------------------------------------------------
|
|
24
|
+
const FENCE_RE = /^\s*(```|~~~)/, HEADING_RE = /^(#{1,3})\s+(.+?)(?:\s+#+)?\s*$/;
|
|
25
|
+
/** Split a doc's markdown content into sections. */
|
|
26
|
+
export function parseDocSections(entry, content) {
|
|
27
|
+
const lines = splitLines(content), headings = [];
|
|
28
|
+
let inFence = false, h1 = null, h1Line = 0;
|
|
29
|
+
lines.forEach((line, i) => {
|
|
30
|
+
if (FENCE_RE.test(line)) {
|
|
31
|
+
inFence = !inFence;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (inFence)
|
|
35
|
+
return;
|
|
36
|
+
const match = HEADING_RE.exec(line);
|
|
37
|
+
if (!match)
|
|
38
|
+
return;
|
|
39
|
+
const level = match[1].length, text = cleanHeading(match[2]);
|
|
40
|
+
if (level === 1) {
|
|
41
|
+
if (h1 == null) {
|
|
42
|
+
h1 = text;
|
|
43
|
+
h1Line = i + 1;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
headings.push({ level, text, line: i + 1 });
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const lastLine = lines.length, sections = [], firstHeadingLine = headings[0]?.line ?? lastLine + 1;
|
|
51
|
+
// Intro: everything before the first `##` / `###` heading.
|
|
52
|
+
if (firstHeadingLine > 1) {
|
|
53
|
+
const heading = h1 ?? entry.title, endLine = firstHeadingLine - 1;
|
|
54
|
+
sections.push({
|
|
55
|
+
docId: entry.id,
|
|
56
|
+
level: 1,
|
|
57
|
+
heading,
|
|
58
|
+
path: [],
|
|
59
|
+
ref: heading,
|
|
60
|
+
breadcrumb: entry.title,
|
|
61
|
+
startLine: 1,
|
|
62
|
+
endLine,
|
|
63
|
+
extentEndLine: endLine,
|
|
64
|
+
tokens: estimateTokens(sliceLines(lines, 1, endLine)),
|
|
65
|
+
body: lines
|
|
66
|
+
.slice(0, endLine)
|
|
67
|
+
.filter((_, i) => i + 1 !== h1Line)
|
|
68
|
+
.join('\n')
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
let currentH2 = null;
|
|
72
|
+
headings.forEach((h, idx) => {
|
|
73
|
+
const level = h.level, endLine = (headings[idx + 1]?.line ?? lastLine + 1) - 1;
|
|
74
|
+
if (level === 2)
|
|
75
|
+
currentH2 = h.text;
|
|
76
|
+
const path = level === 3 && currentH2 ? [currentH2, h.text] : [h.text];
|
|
77
|
+
// A `##` section's extent runs to the next `##`; a `###` ends at the next heading.
|
|
78
|
+
let extentEndLine = endLine;
|
|
79
|
+
if (level === 2) {
|
|
80
|
+
const nextH2 = headings.slice(idx + 1).find(it => it.level === 2);
|
|
81
|
+
extentEndLine = (nextH2?.line ?? lastLine + 1) - 1;
|
|
82
|
+
}
|
|
83
|
+
sections.push({
|
|
84
|
+
docId: entry.id,
|
|
85
|
+
level,
|
|
86
|
+
heading: h.text,
|
|
87
|
+
path,
|
|
88
|
+
ref: path.join(' > '),
|
|
89
|
+
breadcrumb: [entry.title, ...path].join(' > '),
|
|
90
|
+
startLine: h.line,
|
|
91
|
+
endLine,
|
|
92
|
+
extentEndLine,
|
|
93
|
+
tokens: estimateTokens(sliceLines(lines, h.line, extentEndLine)),
|
|
94
|
+
body: sliceLines(lines, h.line + 1, endLine)
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
return sections;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Return the markdown for a section's full extent, including its heading and subsections. Any
|
|
101
|
+
* reference link definitions the section uses but does not contain are appended at the end.
|
|
102
|
+
*/
|
|
103
|
+
export function getSectionContent(content, section) {
|
|
104
|
+
const lines = splitLines(content), body = sliceLines(lines, section.startLine, section.extentEndLine).trimEnd(), used = referencedLabels(body), defs = [...parseLinkDefinitions(lines).entries()]
|
|
105
|
+
.filter(([label, def]) => {
|
|
106
|
+
const inSection = def.line >= section.startLine && def.line <= section.extentEndLine;
|
|
107
|
+
return used.has(label) && !inSection;
|
|
108
|
+
})
|
|
109
|
+
.map(([, def]) => def.text);
|
|
110
|
+
return defs.length ? `${body}\n\n${defs.join('\n')}` : body;
|
|
111
|
+
}
|
|
112
|
+
/** Sections nested within (and including) the given section. */
|
|
113
|
+
export function getSubsections(sections, section) {
|
|
114
|
+
return sections.filter(s => s.startLine >= section.startLine && s.startLine <= section.extentEndLine);
|
|
115
|
+
}
|
|
116
|
+
//------------------------------------------------------------------
|
|
117
|
+
// Links
|
|
118
|
+
//------------------------------------------------------------------
|
|
119
|
+
/** A reference link definition line, e.g. `[ts7]: https://...`. Captures the label. */
|
|
120
|
+
export const LINK_DEF_RE = /^ {0,3}\[([^\]]+)\]:\s*\S/;
|
|
121
|
+
const INLINE_LINK_RE = /\[([^\]]+)\]\([^)]*\)/g, REF_LINK_RE = /\[([^\]]+)\]\[([^\]]*)\]/g;
|
|
122
|
+
/** Reduce inline (`[text](url)`) and reference (`[text][label]`, `[text][]`) links to their text. */
|
|
123
|
+
export function stripLinks(text) {
|
|
124
|
+
return text.replace(INLINE_LINK_RE, '$1').replace(REF_LINK_RE, '$1');
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Reference link definitions outside fenced code, keyed by normalized label. The first
|
|
128
|
+
* definition of a label wins, as in CommonMark.
|
|
129
|
+
*/
|
|
130
|
+
function parseLinkDefinitions(lines) {
|
|
131
|
+
const ret = new Map();
|
|
132
|
+
let inFence = false;
|
|
133
|
+
lines.forEach((text, i) => {
|
|
134
|
+
if (FENCE_RE.test(text)) {
|
|
135
|
+
inFence = !inFence;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const match = inFence ? null : LINK_DEF_RE.exec(text);
|
|
139
|
+
if (!match)
|
|
140
|
+
return;
|
|
141
|
+
const label = normalizeLabel(match[1]);
|
|
142
|
+
if (!ret.has(label))
|
|
143
|
+
ret.set(label, { line: i + 1, text });
|
|
144
|
+
});
|
|
145
|
+
return ret;
|
|
146
|
+
}
|
|
147
|
+
/** Normalized labels of the `[text][label]` and `[text][]` links in some markdown. */
|
|
148
|
+
function referencedLabels(markdown) {
|
|
149
|
+
return new Set([...markdown.matchAll(REF_LINK_RE)].map(m => normalizeLabel(m[2] || m[1])));
|
|
150
|
+
}
|
|
151
|
+
/** Match labels as CommonMark does - ignoring case and runs of whitespace. */
|
|
152
|
+
function normalizeLabel(label) {
|
|
153
|
+
return label.trim().replace(/\s+/g, ' ').toLowerCase();
|
|
154
|
+
}
|
|
155
|
+
//------------------------------------------------------------------
|
|
156
|
+
// Resolution
|
|
157
|
+
//------------------------------------------------------------------
|
|
158
|
+
/**
|
|
159
|
+
* Resolve a caller-supplied section name to a single section of a doc.
|
|
160
|
+
*
|
|
161
|
+
* Accepts a heading (`GridModel`), a path (`Built-in Model Support > GridModel`), or a full
|
|
162
|
+
* breadcrumb with the doc title as its first segment. Matching ignores case, punctuation, and
|
|
163
|
+
* markdown (`## Mask`, `persistWith`, `XH.confirm()`), and tries tiers in order, returning the
|
|
164
|
+
* first tier with any match:
|
|
165
|
+
* 1. Exact match on the full path (or the intro heading / doc title).
|
|
166
|
+
* 2. Exact match on the trailing segments of a path.
|
|
167
|
+
* 3. Prefix match on the trailing segments.
|
|
168
|
+
* 4. Substring match on the trailing segments.
|
|
169
|
+
*
|
|
170
|
+
* A tier with more than one distinct match is reported as ambiguous rather than guessed.
|
|
171
|
+
*/
|
|
172
|
+
export function resolveSection(entry, sections, input) {
|
|
173
|
+
let segments = splitSectionInput(input);
|
|
174
|
+
if (segments.length === 0)
|
|
175
|
+
return { kind: 'unknown', suggestions: [] };
|
|
176
|
+
const intro = sections.find(s => s.level === 1), titleKeys = [normalize(entry.title), normalize(intro?.heading ?? '')].filter(Boolean);
|
|
177
|
+
// A single segment naming the doc itself addresses the intro.
|
|
178
|
+
if (segments.length === 1 && titleKeys.includes(segments[0])) {
|
|
179
|
+
const exact = sections.filter(s => s.level > 1 && normalize(s.heading) === segments[0]);
|
|
180
|
+
if (exact.length === 0 && intro)
|
|
181
|
+
return { kind: 'found', section: intro };
|
|
182
|
+
}
|
|
183
|
+
// Tolerate a leading doc-title segment, as shown in search breadcrumbs.
|
|
184
|
+
if (segments.length > 1 && titleKeys.includes(segments[0]))
|
|
185
|
+
segments = segments.slice(1);
|
|
186
|
+
const addressable = sections.filter(s => s.level > 1), keyed = addressable.map(s => ({ s, keys: s.path.map(normalize) })), tiers = [
|
|
187
|
+
keys => keys.length === segments.length && tailMatches(keys, (k, q) => k === q),
|
|
188
|
+
keys => tailMatches(keys, (k, q) => k === q),
|
|
189
|
+
keys => tailMatches(keys, (k, q) => k.startsWith(q)),
|
|
190
|
+
keys => tailMatches(keys, (k, q) => k.includes(q))
|
|
191
|
+
];
|
|
192
|
+
function tailMatches(keys, cmp) {
|
|
193
|
+
if (keys.length < segments.length)
|
|
194
|
+
return false;
|
|
195
|
+
const tail = keys.slice(keys.length - segments.length);
|
|
196
|
+
return tail.every((k, i) => cmp(k, segments[i]));
|
|
197
|
+
}
|
|
198
|
+
for (const tier of tiers) {
|
|
199
|
+
const matches = keyed.filter(it => tier(it.keys)).map(it => it.s);
|
|
200
|
+
if (matches.length === 1)
|
|
201
|
+
return { kind: 'found', section: matches[0] };
|
|
202
|
+
if (matches.length > 1) {
|
|
203
|
+
// Identical breadcrumbs cannot be told apart by name - take the first.
|
|
204
|
+
const distinct = new Set(matches.map(m => m.ref));
|
|
205
|
+
if (distinct.size === 1)
|
|
206
|
+
return { kind: 'found', section: matches[0] };
|
|
207
|
+
return { kind: 'ambiguous', candidates: matches };
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return { kind: 'unknown', suggestions: suggestSections(sections, input) };
|
|
211
|
+
}
|
|
212
|
+
//------------------------------------------------------------------
|
|
213
|
+
// Implementation
|
|
214
|
+
//------------------------------------------------------------------
|
|
215
|
+
/** Strip inline markdown from heading text: backticks, emphasis, links, trailing anchors. */
|
|
216
|
+
function cleanHeading(raw) {
|
|
217
|
+
return stripLinks(raw.replace(/\s*\{#[^}]*\}\s*$/, ''))
|
|
218
|
+
.replace(/[`*]/g, '')
|
|
219
|
+
.trim();
|
|
220
|
+
}
|
|
221
|
+
/** Split content into lines, dropping the empty entry after a trailing newline. */
|
|
222
|
+
export function splitLines(content) {
|
|
223
|
+
const lines = content.split('\n');
|
|
224
|
+
if (lines.at(-1) === '')
|
|
225
|
+
lines.pop();
|
|
226
|
+
return lines;
|
|
227
|
+
}
|
|
228
|
+
function sliceLines(lines, start, end) {
|
|
229
|
+
return lines.slice(start - 1, end).join('\n');
|
|
230
|
+
}
|
|
231
|
+
/** Lowercase and drop everything but letters and digits. */
|
|
232
|
+
function normalize(s) {
|
|
233
|
+
return s.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, '');
|
|
234
|
+
}
|
|
235
|
+
/** Split `A > B` (also `›` / `»`) into normalized segments, dropping empties. */
|
|
236
|
+
function splitSectionInput(input) {
|
|
237
|
+
return (input ?? '')
|
|
238
|
+
.split(/\s*[>›»]\s*/)
|
|
239
|
+
.map(normalize)
|
|
240
|
+
.filter(Boolean);
|
|
241
|
+
}
|
|
242
|
+
/** Up to 5 sections whose headings share the most words with the input. */
|
|
243
|
+
function suggestSections(sections, input) {
|
|
244
|
+
const words = (input ?? '')
|
|
245
|
+
.toLowerCase()
|
|
246
|
+
.split(/[^\p{L}\p{N}]+/u)
|
|
247
|
+
.filter(w => w.length > 1);
|
|
248
|
+
if (words.length === 0)
|
|
249
|
+
return [];
|
|
250
|
+
return sections
|
|
251
|
+
.filter(s => s.level > 1)
|
|
252
|
+
.map(s => {
|
|
253
|
+
const key = normalize(s.ref);
|
|
254
|
+
return { s, score: words.filter(w => key.includes(w)).length };
|
|
255
|
+
})
|
|
256
|
+
.filter(it => it.score > 0)
|
|
257
|
+
.sort((a, b) => b.score - a.score)
|
|
258
|
+
.slice(0, 5)
|
|
259
|
+
.map(it => it.s);
|
|
260
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text pipeline shared by the doc search index (`DocSearch.ts`) and the symbol search index
|
|
3
|
+
* (`SymbolSearch.ts`), so a query is processed the same way whichever index it hits.
|
|
4
|
+
*
|
|
5
|
+
* Terms are split on punctuation and camelCase (`persistWith` indexes as `persistwith`,
|
|
6
|
+
* `persist`, and `with`), lowercased, filtered against a stop-word list, and lightly stemmed.
|
|
7
|
+
* Also provides the two ranking helpers both indexes use: coverage-scaled OR combination and
|
|
8
|
+
* the compound-head guard that stops a prefix match from counting a camelCase identifier twice.
|
|
9
|
+
*/
|
|
10
|
+
import type { SearchResult } from 'minisearch';
|
|
11
|
+
export declare const STOP_WORDS: Set<string>;
|
|
12
|
+
/** Split on anything other than letters and digits, preserving case for camelCase splitting. */
|
|
13
|
+
export declare function tokenize(text: string): string[];
|
|
14
|
+
/**
|
|
15
|
+
* Expand a raw token into index terms: the whole token lowercased, plus its camelCase parts
|
|
16
|
+
* (`persistWith` → `persistwith`, `persist`, `with`). Drops stop words and single characters,
|
|
17
|
+
* then stems what remains.
|
|
18
|
+
*/
|
|
19
|
+
export declare function processTerm(token: string): string[];
|
|
20
|
+
/** Tokenize and process a query the same way indexed text is processed. */
|
|
21
|
+
export declare function queryTerms(query: string): string[];
|
|
22
|
+
export interface SplitToken {
|
|
23
|
+
whole: string | null;
|
|
24
|
+
parts: string[];
|
|
25
|
+
/** Whole and parts, de-duplicated - the index terms for this token. */
|
|
26
|
+
terms: string[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Split a raw token into its processed whole and, for a camelCase compound, its processed
|
|
30
|
+
* parts. Either may be filtered out as a stop word or single character.
|
|
31
|
+
*/
|
|
32
|
+
export declare function splitToken(token: string): SplitToken;
|
|
33
|
+
/**
|
|
34
|
+
* Light suffix stemmer, applied identically at index and query time. Folds plurals and common
|
|
35
|
+
* verb/noun endings so `confirmation` matches `confirm` and `columns` matches `column`. Prefix
|
|
36
|
+
* matching at query time covers the reverse direction (`config` → `configuration`).
|
|
37
|
+
*/
|
|
38
|
+
export declare function stem(term: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* A MiniSearch `processTerm` that also records, for every camelCase compound it indexes, the
|
|
41
|
+
* compound's leading part (`showfeedbackdialog` → `show`). See {@link isRedundantCompoundMatch}.
|
|
42
|
+
*/
|
|
43
|
+
export interface TermProcessor {
|
|
44
|
+
processTerm: (token: string) => string[];
|
|
45
|
+
/** Indexed compound terms mapped to their leading part. */
|
|
46
|
+
compoundHeads: Map<string, string>;
|
|
47
|
+
}
|
|
48
|
+
export declare function createTermProcessor(): TermProcessor;
|
|
49
|
+
/**
|
|
50
|
+
* True when `term` is a prefix or fuzzy match onto a compound identifier whose leading part
|
|
51
|
+
* the query already matches (`show` → `showFeedbackDialog`). The part is indexed on its own,
|
|
52
|
+
* so counting the compound too only favors identifier-dense text. Callers return a boost of 0
|
|
53
|
+
* for such a match.
|
|
54
|
+
*/
|
|
55
|
+
export declare function isRedundantCompoundMatch(compoundHeads: Map<string, string>, term: string, terms: string[], querySet: Set<string>): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Rank OR-combined hits by BM25 score scaled by the share of query terms each hit matches.
|
|
58
|
+
* This prefers hits matching every term (as AND would) without letting a weak all-term match
|
|
59
|
+
* outrank a strong match on most terms (as strict AND-then-OR does).
|
|
60
|
+
*/
|
|
61
|
+
export declare function rankByCoverage<T extends SearchResult>(hits: T[], termCount: number): Array<{
|
|
62
|
+
hit: T;
|
|
63
|
+
score: number;
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Split a JSDoc description into its first sentence and the rest. `{@link X}` references are
|
|
67
|
+
* unwrapped to their display text, whitespace is collapsed, and a paragraph break also ends the
|
|
68
|
+
* first sentence.
|
|
69
|
+
*/
|
|
70
|
+
export declare function splitSummary(jsDoc: string): {
|
|
71
|
+
summary: string;
|
|
72
|
+
rest: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* First sentence of a JSDoc description, trimmed to at most `maxChars` at a word boundary.
|
|
76
|
+
* Used for the one-line-per-hit search output.
|
|
77
|
+
*/
|
|
78
|
+
export declare function firstSentence(jsDoc: string, maxChars: number): string;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file belongs to Hoist, an application development toolkit
|
|
3
|
+
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
|
|
4
|
+
*
|
|
5
|
+
* Copyright © 2026 Extremely Heavy Industries Inc.
|
|
6
|
+
*/
|
|
7
|
+
export const STOP_WORDS = new Set(('a about after all also an and any are as at be been but by can could do does doing ' +
|
|
8
|
+
'during each for from had has have how i if in into is it its just me my of on or our ' +
|
|
9
|
+
'should so some such than that the their them then there these they this those to too ' +
|
|
10
|
+
'up us via was we were what when where which while who why will with would you your ' +
|
|
11
|
+
'hoist use used uses using want need way').split(' '));
|
|
12
|
+
//------------------------------------------------------------------
|
|
13
|
+
// Tokenizing and term processing
|
|
14
|
+
//------------------------------------------------------------------
|
|
15
|
+
/** Split on anything other than letters and digits, preserving case for camelCase splitting. */
|
|
16
|
+
export function tokenize(text) {
|
|
17
|
+
return text.split(/[^\p{L}\p{N}]+/u).filter(Boolean);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Expand a raw token into index terms: the whole token lowercased, plus its camelCase parts
|
|
21
|
+
* (`persistWith` → `persistwith`, `persist`, `with`). Drops stop words and single characters,
|
|
22
|
+
* then stems what remains.
|
|
23
|
+
*/
|
|
24
|
+
export function processTerm(token) {
|
|
25
|
+
return splitToken(token).terms;
|
|
26
|
+
}
|
|
27
|
+
/** Tokenize and process a query the same way indexed text is processed. */
|
|
28
|
+
export function queryTerms(query) {
|
|
29
|
+
return [...new Set(tokenize(query ?? '').flatMap(processTerm))];
|
|
30
|
+
}
|
|
31
|
+
/** Memoized by raw token - vocabulary repeats heavily, so this roughly halves build time. */
|
|
32
|
+
const SPLIT_CACHE = new Map();
|
|
33
|
+
/**
|
|
34
|
+
* Split a raw token into its processed whole and, for a camelCase compound, its processed
|
|
35
|
+
* parts. Either may be filtered out as a stop word or single character.
|
|
36
|
+
*/
|
|
37
|
+
export function splitToken(token) {
|
|
38
|
+
let ret = SPLIT_CACHE.get(token);
|
|
39
|
+
if (ret)
|
|
40
|
+
return ret;
|
|
41
|
+
const keep = (t) => (t.length < 2 || STOP_WORDS.has(t) ? null : stem(t)), rawParts = /[A-Z]/.test(token)
|
|
42
|
+
? token.split(/(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/)
|
|
43
|
+
: [token], parts = rawParts.length > 1
|
|
44
|
+
? rawParts.map(p => keep(p.toLowerCase())).filter((p) => p != null)
|
|
45
|
+
: [];
|
|
46
|
+
const whole = keep(token.toLowerCase());
|
|
47
|
+
ret = { whole, parts, terms: [...new Set(whole ? [whole, ...parts] : parts)] };
|
|
48
|
+
SPLIT_CACHE.set(token, ret);
|
|
49
|
+
return ret;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Light suffix stemmer, applied identically at index and query time. Folds plurals and common
|
|
53
|
+
* verb/noun endings so `confirmation` matches `confirm` and `columns` matches `column`. Prefix
|
|
54
|
+
* matching at query time covers the reverse direction (`config` → `configuration`).
|
|
55
|
+
*/
|
|
56
|
+
export function stem(term) {
|
|
57
|
+
if (term.length < 4 || /\d/.test(term))
|
|
58
|
+
return term;
|
|
59
|
+
let t = term;
|
|
60
|
+
if (t.endsWith('ies') && t.length > 4)
|
|
61
|
+
t = t.slice(0, -3) + 'y';
|
|
62
|
+
else if (t.endsWith('sses'))
|
|
63
|
+
t = t.slice(0, -2);
|
|
64
|
+
else if (t.endsWith('s') && !/(ss|us|is)$/.test(t))
|
|
65
|
+
t = t.slice(0, -1);
|
|
66
|
+
for (const suffix of ['ation', 'ing', 'ed']) {
|
|
67
|
+
if (t.endsWith(suffix) && t.length - suffix.length >= 4) {
|
|
68
|
+
t = t.slice(0, -suffix.length);
|
|
69
|
+
// Undouble a trailing consonant left by -ing/-ed (`mapped` → `map`), except l/s/z.
|
|
70
|
+
if (suffix !== 'ation' && /([^aeiouylsz])\1$/.test(t))
|
|
71
|
+
t = t.slice(0, -1);
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return t;
|
|
76
|
+
}
|
|
77
|
+
export function createTermProcessor() {
|
|
78
|
+
const compoundHeads = new Map();
|
|
79
|
+
return {
|
|
80
|
+
compoundHeads,
|
|
81
|
+
processTerm: token => {
|
|
82
|
+
const { whole, parts } = splitToken(token);
|
|
83
|
+
if (whole && parts.length)
|
|
84
|
+
compoundHeads.set(whole, parts[0]);
|
|
85
|
+
return processTerm(token);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* True when `term` is a prefix or fuzzy match onto a compound identifier whose leading part
|
|
91
|
+
* the query already matches (`show` → `showFeedbackDialog`). The part is indexed on its own,
|
|
92
|
+
* so counting the compound too only favors identifier-dense text. Callers return a boost of 0
|
|
93
|
+
* for such a match.
|
|
94
|
+
*/
|
|
95
|
+
export function isRedundantCompoundMatch(compoundHeads, term, terms, querySet) {
|
|
96
|
+
const head = compoundHeads.get(term);
|
|
97
|
+
return !!head && !querySet.has(term) && terms.some(t => head.startsWith(t));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Rank OR-combined hits by BM25 score scaled by the share of query terms each hit matches.
|
|
101
|
+
* This prefers hits matching every term (as AND would) without letting a weak all-term match
|
|
102
|
+
* outrank a strong match on most terms (as strict AND-then-OR does).
|
|
103
|
+
*/
|
|
104
|
+
export function rankByCoverage(hits, termCount) {
|
|
105
|
+
return hits
|
|
106
|
+
.map(hit => ({ hit, score: (hit.score * new Set(hit.queryTerms).size) / termCount }))
|
|
107
|
+
.sort((a, b) => b.score - a.score);
|
|
108
|
+
}
|
|
109
|
+
//------------------------------------------------------------------
|
|
110
|
+
// Summaries
|
|
111
|
+
//------------------------------------------------------------------
|
|
112
|
+
/** Sentence-ending punctuation not preceded by a common abbreviation. */
|
|
113
|
+
const SENTENCE_END_RE = /(?<!\b(?:e\.g|i\.e|vs|etc|cf))[.!?](?=\s|$)/;
|
|
114
|
+
/**
|
|
115
|
+
* Split a JSDoc description into its first sentence and the rest. `{@link X}` references are
|
|
116
|
+
* unwrapped to their display text, whitespace is collapsed, and a paragraph break also ends the
|
|
117
|
+
* first sentence.
|
|
118
|
+
*/
|
|
119
|
+
export function splitSummary(jsDoc) {
|
|
120
|
+
const text = (jsDoc ?? '').trim();
|
|
121
|
+
if (!text)
|
|
122
|
+
return { summary: '', rest: '' };
|
|
123
|
+
const paragraph = text.split(/\n\s*\n/)[0], firstPara = unwrapLinks(paragraph).replace(/\s+/g, ' ').trim(), end = SENTENCE_END_RE.exec(firstPara), cut = end ? end.index + 1 : firstPara.length, summary = firstPara.slice(0, cut).trim(), restOfPara = firstPara.slice(cut).trim(), restParas = unwrapLinks(text.slice(paragraph.length)).replace(/\s+/g, ' ').trim();
|
|
124
|
+
return { summary, rest: [restOfPara, restParas].filter(Boolean).join(' ') };
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* First sentence of a JSDoc description, trimmed to at most `maxChars` at a word boundary.
|
|
128
|
+
* Used for the one-line-per-hit search output.
|
|
129
|
+
*/
|
|
130
|
+
export function firstSentence(jsDoc, maxChars) {
|
|
131
|
+
const { summary } = splitSummary(jsDoc);
|
|
132
|
+
if (summary.length <= maxChars)
|
|
133
|
+
return summary;
|
|
134
|
+
const cut = summary.slice(0, maxChars), space = cut.lastIndexOf(' ');
|
|
135
|
+
return (space > maxChars / 2 ? cut.slice(0, space) : cut) + '...';
|
|
136
|
+
}
|
|
137
|
+
/** `{@link Foo}` → `Foo`, `{@link Foo|text}` and `{@link Foo text}` → `text`. */
|
|
138
|
+
function unwrapLinks(text) {
|
|
139
|
+
return text.replace(/\{@link(?:code|plain)?\s+([^}|\s]+)(?:\s*\|\s*|\s+)?([^}]*)\}/g, (_, target, label) => label.trim() || target);
|
|
140
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shapes of an index file, as written by each library's index builder. See
|
|
3
|
+
* docs/index-schema.md for the full description of each field.
|
|
4
|
+
*/
|
|
5
|
+
export declare const SCHEMA_VERSION = 1;
|
|
6
|
+
export interface IndexFile {
|
|
7
|
+
schemaVersion: number;
|
|
8
|
+
library: LibraryInfo;
|
|
9
|
+
docs: {
|
|
10
|
+
mcpCategories?: Category[];
|
|
11
|
+
viewerCategories?: Category[];
|
|
12
|
+
entries: DocEntryJson[];
|
|
13
|
+
};
|
|
14
|
+
symbols?: SymbolEntry[];
|
|
15
|
+
memberIndex?: MemberIndexEntry[];
|
|
16
|
+
}
|
|
17
|
+
export interface LibraryInfo {
|
|
18
|
+
/** Short id used in tool arguments: `react`, `core`, or a companion id. */
|
|
19
|
+
id: string;
|
|
20
|
+
/** Package name, e.g. `@xh/hoist`. */
|
|
21
|
+
name: string;
|
|
22
|
+
version: string;
|
|
23
|
+
language: 'typescript' | 'groovy';
|
|
24
|
+
gitSha?: string;
|
|
25
|
+
builtAt: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
instructions?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface Category {
|
|
30
|
+
id: string;
|
|
31
|
+
title: string;
|
|
32
|
+
}
|
|
33
|
+
export interface DocEntryJson {
|
|
34
|
+
id: string;
|
|
35
|
+
title: string;
|
|
36
|
+
mcpCategory: string;
|
|
37
|
+
viewerCategory: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
keywords?: string[];
|
|
40
|
+
aliases?: string[];
|
|
41
|
+
markdown?: string;
|
|
42
|
+
}
|
|
43
|
+
export type SymbolKind = 'class' | 'interface' | 'type' | 'function' | 'const' | 'enum' | 'trait' | 'annotation';
|
|
44
|
+
export type MemberKind = 'property' | 'method' | 'accessor' | 'field';
|
|
45
|
+
export interface Parameter {
|
|
46
|
+
name: string;
|
|
47
|
+
type: string;
|
|
48
|
+
description?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface Member {
|
|
51
|
+
name: string;
|
|
52
|
+
kind: MemberKind;
|
|
53
|
+
type: string;
|
|
54
|
+
isStatic: boolean;
|
|
55
|
+
isOptional?: boolean;
|
|
56
|
+
isAbstract?: boolean;
|
|
57
|
+
visibility?: string;
|
|
58
|
+
decorators?: string[];
|
|
59
|
+
doc?: string;
|
|
60
|
+
default?: string;
|
|
61
|
+
parameters?: Parameter[];
|
|
62
|
+
returnType?: string;
|
|
63
|
+
returns?: {
|
|
64
|
+
type: string;
|
|
65
|
+
description: string;
|
|
66
|
+
};
|
|
67
|
+
inheritedFrom?: string;
|
|
68
|
+
docInheritedFrom?: string;
|
|
69
|
+
}
|
|
70
|
+
export interface ExternalMemberGroup {
|
|
71
|
+
declaredIn: string;
|
|
72
|
+
module: string | null;
|
|
73
|
+
members: Array<{
|
|
74
|
+
name: string;
|
|
75
|
+
kind: string;
|
|
76
|
+
type?: string;
|
|
77
|
+
}>;
|
|
78
|
+
}
|
|
79
|
+
export interface SymbolEntry {
|
|
80
|
+
name: string;
|
|
81
|
+
kind: SymbolKind;
|
|
82
|
+
filePath: string;
|
|
83
|
+
sourcePackage: string;
|
|
84
|
+
category?: string;
|
|
85
|
+
isExported: boolean;
|
|
86
|
+
isAbstract?: boolean;
|
|
87
|
+
importPath?: string | null;
|
|
88
|
+
isPromiseExtension?: boolean;
|
|
89
|
+
doc?: string;
|
|
90
|
+
hint?: string;
|
|
91
|
+
memberNames?: string;
|
|
92
|
+
signature: string;
|
|
93
|
+
extends?: string;
|
|
94
|
+
implements?: string[];
|
|
95
|
+
decorators?: string[];
|
|
96
|
+
constructorType?: string;
|
|
97
|
+
instanceOf?: string;
|
|
98
|
+
members?: Member[];
|
|
99
|
+
externalMembers?: ExternalMemberGroup[];
|
|
100
|
+
}
|
|
101
|
+
export interface MemberIndexEntry {
|
|
102
|
+
name: string;
|
|
103
|
+
memberKind: MemberKind;
|
|
104
|
+
ownerName: string;
|
|
105
|
+
ownerHint?: string;
|
|
106
|
+
filePath: string;
|
|
107
|
+
sourcePackage: string;
|
|
108
|
+
isStatic: boolean;
|
|
109
|
+
type: string;
|
|
110
|
+
doc?: string;
|
|
111
|
+
docInheritedFrom?: string;
|
|
112
|
+
default?: string;
|
|
113
|
+
decorators?: string[];
|
|
114
|
+
parameters?: Parameter[];
|
|
115
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file belongs to Hoist, an application development toolkit
|
|
3
|
+
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
|
|
4
|
+
*
|
|
5
|
+
* Copyright © 2026 Extremely Heavy Industries Inc.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Shapes of an index file, as written by each library's index builder. See
|
|
9
|
+
* docs/index-schema.md for the full description of each field.
|
|
10
|
+
*/
|
|
11
|
+
export const SCHEMA_VERSION = 1;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in libraries: XH's own. Each ships its index with itself - inside its npm package, or
|
|
3
|
+
* beside its jar on Maven - so the tool can serve any library that does, listed here or not. This
|
|
4
|
+
* table adds what only XH's libraries get: labels and display order, where the local tool finds
|
|
5
|
+
* their versions (including in their own checkouts), which libraries a project cannot do without,
|
|
6
|
+
* and how a gateway fetches them on demand. Plain data, so the browser-safe docs library can import
|
|
7
|
+
* it.
|
|
8
|
+
*
|
|
9
|
+
* Order matters: it is the display order, and hoist-react comes first, so its doc ids win when
|
|
10
|
+
* unqualified.
|
|
11
|
+
*/
|
|
12
|
+
export interface LibraryDef {
|
|
13
|
+
/** Short id, used in tool arguments, doc id prefixes (`core:`) and index file names. */
|
|
14
|
+
id: string;
|
|
15
|
+
/** Display name, e.g. `Hoist React`. */
|
|
16
|
+
label: string;
|
|
17
|
+
/** Repo name, used as the docs viewer's source id, e.g. `hoist-react`. */
|
|
18
|
+
source: string;
|
|
19
|
+
/** Package name: an npm name, or Maven coordinates for hoist-core. */
|
|
20
|
+
packageName: string;
|
|
21
|
+
/**
|
|
22
|
+
* Maven coordinates, for a library that ships its index beside its jar as the `docs-index`
|
|
23
|
+
* artifact. Absent for npm libraries, which ship it inside their package.
|
|
24
|
+
*/
|
|
25
|
+
maven?: {
|
|
26
|
+
group: string;
|
|
27
|
+
artifact: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* How an app's version is found: the installed npm package of that name, or a property in
|
|
31
|
+
* `gradle.properties`.
|
|
32
|
+
*/
|
|
33
|
+
installed: {
|
|
34
|
+
npm: string;
|
|
35
|
+
} | {
|
|
36
|
+
gradleProperty: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* How a checkout of the library itself is recognized: the `name` in its `package.json`, or the
|
|
40
|
+
* `rootProject.name` in its `settings.gradle`.
|
|
41
|
+
*/
|
|
42
|
+
checkout: {
|
|
43
|
+
packageName: string;
|
|
44
|
+
} | {
|
|
45
|
+
gradleProject: string;
|
|
46
|
+
versionProperty: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* True for libraries an app is not expected to use without being asked: served only when
|
|
50
|
+
* found installed, never as a default in another library's checkout, and skipped with a
|
|
51
|
+
* warning when its index cannot be found.
|
|
52
|
+
*/
|
|
53
|
+
optional?: boolean;
|
|
54
|
+
}
|
|
55
|
+
export declare const LIBRARIES: LibraryDef[];
|
|
56
|
+
/** The built-in library with this id, if any. */
|
|
57
|
+
export declare function libraryDef(id: string): LibraryDef | undefined;
|