@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.
Files changed (62) hide show
  1. package/LICENSE.md +190 -0
  2. package/README.md +145 -2
  3. package/bin/hoist-docs.mjs +16 -0
  4. package/dist/IndexStore.d.ts +78 -0
  5. package/dist/IndexStore.js +249 -0
  6. package/dist/cli.d.ts +11 -0
  7. package/dist/cli.js +258 -0
  8. package/dist/config.d.ts +17 -0
  9. package/dist/config.js +18 -0
  10. package/dist/docs/index.d.ts +70 -0
  11. package/dist/docs/index.js +101 -0
  12. package/dist/index/DocEntry.d.ts +16 -0
  13. package/dist/index/DocEntry.js +32 -0
  14. package/dist/index/DocIdResolver.d.ts +31 -0
  15. package/dist/index/DocIdResolver.js +159 -0
  16. package/dist/index/DocSearch.d.ts +41 -0
  17. package/dist/index/DocSearch.js +180 -0
  18. package/dist/index/LibraryIndex.d.ts +62 -0
  19. package/dist/index/LibraryIndex.js +153 -0
  20. package/dist/index/SymbolSearch.d.ts +52 -0
  21. package/dist/index/SymbolSearch.js +249 -0
  22. package/dist/index/doc-sections.d.ts +94 -0
  23. package/dist/index/doc-sections.js +260 -0
  24. package/dist/index/search-text.d.ts +78 -0
  25. package/dist/index/search-text.js +140 -0
  26. package/dist/index/types.d.ts +115 -0
  27. package/dist/index/types.js +11 -0
  28. package/dist/libraries.d.ts +57 -0
  29. package/dist/libraries.js +38 -0
  30. package/dist/local/cache.d.ts +25 -0
  31. package/dist/local/cache.js +62 -0
  32. package/dist/local/checkout.d.ts +6 -0
  33. package/dist/local/checkout.js +178 -0
  34. package/dist/local/installed.d.ts +22 -0
  35. package/dist/local/installed.js +99 -0
  36. package/dist/local/maven.d.ts +49 -0
  37. package/dist/local/maven.js +184 -0
  38. package/dist/local/npm.d.ts +24 -0
  39. package/dist/local/npm.js +66 -0
  40. package/dist/local/project.d.ts +26 -0
  41. package/dist/local/project.js +103 -0
  42. package/dist/local/registry.d.ts +15 -0
  43. package/dist/local/registry.js +67 -0
  44. package/dist/local/sources.d.ts +30 -0
  45. package/dist/local/sources.js +50 -0
  46. package/dist/local/tar.d.ts +6 -0
  47. package/dist/local/tar.js +31 -0
  48. package/dist/log.d.ts +10 -0
  49. package/dist/log.js +31 -0
  50. package/dist/mcp.d.ts +23 -0
  51. package/dist/mcp.js +396 -0
  52. package/dist/server.d.ts +15 -0
  53. package/dist/server.js +88 -0
  54. package/dist/tools/DocTools.d.ts +19 -0
  55. package/dist/tools/DocTools.js +245 -0
  56. package/dist/tools/SymbolTools.d.ts +27 -0
  57. package/dist/tools/SymbolTools.js +572 -0
  58. package/dist/tools/types.d.ts +6 -0
  59. package/dist/tools/types.js +7 -0
  60. package/dist/usage.d.ts +10 -0
  61. package/dist/usage.js +11 -0
  62. package/package.json +62 -4
@@ -0,0 +1,153 @@
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
+ import { readFileSync } from 'node:fs';
8
+ import { gunzipSync } from 'node:zlib';
9
+ import { libraryDef } from '../libraries.js';
10
+ import { DocEntry } from './DocEntry.js';
11
+ import { DocIdResolver } from './DocIdResolver.js';
12
+ import { DocSearch } from './DocSearch.js';
13
+ import { SymbolSearch } from './SymbolSearch.js';
14
+ import { SCHEMA_VERSION } from './types.js';
15
+ /**
16
+ * One library version's index file, loaded into memory: its docs, symbols with their members,
17
+ * and the member index. Search indexes over these are built on first use. See
18
+ * docs/index-schema.md for the file format.
19
+ */
20
+ export { DocEntry };
21
+ export class LibraryIndex {
22
+ /** Library id used in tool arguments: `react`, `core`, or a companion id. */
23
+ id;
24
+ /** Package name, e.g. `@xh/hoist`. */
25
+ name;
26
+ version;
27
+ language;
28
+ gitSha;
29
+ builtAt;
30
+ description;
31
+ /** Display name from the built-in library table (`Hoist Chat Kit`), else null. */
32
+ label;
33
+ instructions;
34
+ mcpCategories;
35
+ viewerCategories;
36
+ docs;
37
+ docsById;
38
+ symbols;
39
+ memberIndex;
40
+ resolver;
41
+ /** Symbols keyed by lowercase name, in file order. */
42
+ symbolsByKey = new Map();
43
+ _docSearch = null;
44
+ _symbolSearch = null;
45
+ /**
46
+ * @param opts.trusted - false to drop the index's agent instructions, for an index from outside
47
+ * the `@xh` scope. Default true.
48
+ */
49
+ constructor(json, opts = {}) {
50
+ if (json.schemaVersion !== SCHEMA_VERSION) {
51
+ throw new Error(`Unsupported index schemaVersion ${json.schemaVersion} - expected ${SCHEMA_VERSION}`);
52
+ }
53
+ const lib = json.library;
54
+ this.id = lib.id;
55
+ this.name = lib.name;
56
+ this.version = lib.version;
57
+ this.language = lib.language;
58
+ this.gitSha = lib.gitSha ?? null;
59
+ this.builtAt = lib.builtAt;
60
+ this.description = lib.description ?? null;
61
+ this.label = libraryDef(lib.id)?.label ?? null;
62
+ this.instructions = opts.trusted === false ? null : (lib.instructions ?? null);
63
+ this.mcpCategories = json.docs.mcpCategories ?? [];
64
+ this.viewerCategories = json.docs.viewerCategories ?? [];
65
+ this.docs = json.docs.entries.map(e => new DocEntry(e));
66
+ this.docsById = new Map(this.docs.map(d => [d.id, d]));
67
+ this.symbols = json.symbols ?? [];
68
+ this.memberIndex = json.memberIndex ?? [];
69
+ for (const s of this.symbols) {
70
+ const key = s.name.toLowerCase();
71
+ let list = this.symbolsByKey.get(key);
72
+ if (!list)
73
+ this.symbolsByKey.set(key, (list = []));
74
+ list.push(s);
75
+ }
76
+ this.resolver = new DocIdResolver(this.docs);
77
+ }
78
+ /** Read an index file, gzipped when its name ends in `.gz`. */
79
+ static load(path, opts = {}) {
80
+ return new LibraryIndex(LibraryIndex.readJson(path), opts);
81
+ }
82
+ /** An index file's raw contents, gzipped when its name ends in `.gz`. */
83
+ static readJson(path) {
84
+ let buf = readFileSync(path);
85
+ if (path.endsWith('.gz'))
86
+ buf = gunzipSync(buf);
87
+ return JSON.parse(buf.toString('utf8'));
88
+ }
89
+ get isTypeScript() {
90
+ return this.language === 'typescript';
91
+ }
92
+ get docSearch() {
93
+ return (this._docSearch ??= new DocSearch(this));
94
+ }
95
+ get symbolSearch() {
96
+ return (this._symbolSearch ??= new SymbolSearch(this));
97
+ }
98
+ //------------------------
99
+ // Symbol lookup
100
+ //------------------------
101
+ /** Exact-name lookup, optionally narrowed by file and kind. Prefers exported symbols. */
102
+ findSymbol(name, filePath, kind) {
103
+ const exact = this.named(name).filter(s => !kind || s.kind === kind);
104
+ if (!exact.length)
105
+ return null;
106
+ if (filePath) {
107
+ const rel = normalizePath(filePath);
108
+ return exact.find(s => s.filePath === rel) ?? null;
109
+ }
110
+ return exact.find(s => s.isExported) ?? exact[0];
111
+ }
112
+ /** Every declaration of a name in the file it resolves to, primary first. */
113
+ findDeclarations(name, filePath, kind) {
114
+ const primary = this.findSymbol(name, filePath, kind);
115
+ if (!primary)
116
+ return [];
117
+ if (kind)
118
+ return [primary];
119
+ return [
120
+ primary,
121
+ ...this.named(name).filter(s => s !== primary && s.filePath === primary.filePath)
122
+ ];
123
+ }
124
+ /** Other exported symbols with this name, in other files. */
125
+ findAlternates(name, selectedFilePath) {
126
+ return this.named(name).filter(s => s.isExported &&
127
+ s.filePath !== selectedFilePath &&
128
+ !s.sourcePackage.startsWith('dynamics'));
129
+ }
130
+ /** For a Props interface, its component consts; for a component const, its Props interface. */
131
+ findCompanions(entry) {
132
+ const { name } = entry;
133
+ if (entry.kind === 'interface' && name.endsWith('Props')) {
134
+ const base = name.slice(0, -'Props'.length);
135
+ if (!base)
136
+ return [];
137
+ const camel = base[0].toLowerCase() + base.slice(1);
138
+ return [...new Set([base, camel])].flatMap(n => this.named(n).filter(s => s.kind === 'const' && s.filePath === entry.filePath));
139
+ }
140
+ if (entry.kind === 'const') {
141
+ const props = name[0].toUpperCase() + name.slice(1) + 'Props';
142
+ return this.named(props).filter(s => s.kind === 'interface' && s.filePath === entry.filePath);
143
+ }
144
+ return [];
145
+ }
146
+ /** Symbols with exactly this name, in file order. */
147
+ named(name) {
148
+ return (this.symbolsByKey.get(name.toLowerCase()) ?? []).filter(s => s.name === name);
149
+ }
150
+ }
151
+ function normalizePath(p) {
152
+ return p.replace(/\\/g, '/').replace(/^\.\//, '').replace(/^\/+/, '');
153
+ }
@@ -0,0 +1,52 @@
1
+ import type { LibraryIndex } from './LibraryIndex.ts';
2
+ import type { MemberIndexEntry, SymbolEntry } from './types.ts';
3
+ export declare const DEFAULT_SEARCH_LIMIT = 8, MAX_SEARCH_LIMIT = 20, SUMMARY_CHARS = 160, MEMBER_SUMMARY_CHARS = 160;
4
+ export interface SymbolHit {
5
+ entry: SymbolEntry;
6
+ score: number;
7
+ summary: string;
8
+ hasMembers: boolean;
9
+ /** Element factory folded into this component hit. */
10
+ factory?: string;
11
+ /** Props interface folded into this component hit. */
12
+ props?: string;
13
+ }
14
+ export interface MemberHit {
15
+ entry: MemberIndexEntry;
16
+ score: number;
17
+ summary: string;
18
+ /** Barrel import path of the member's owner, if any. */
19
+ importPath: string | null;
20
+ }
21
+ export interface SymbolSearchOptions {
22
+ kind?: string | null;
23
+ exported?: boolean | null;
24
+ includeInternal?: boolean | null;
25
+ limit?: number | null;
26
+ }
27
+ export interface SymbolSearchResults {
28
+ query: string;
29
+ symbols: SymbolHit[];
30
+ members: MemberHit[];
31
+ symbolTotal: number;
32
+ memberTotal: number;
33
+ hiddenSymbols: number;
34
+ hiddenMembers: number;
35
+ /** Internal symbols the query names exactly, hidden because includeInternal was off. */
36
+ hiddenExact: SymbolEntry[];
37
+ }
38
+ export declare class SymbolSearch {
39
+ private readonly library;
40
+ private readonly symbolIndex;
41
+ private readonly memberIndex;
42
+ private readonly symbolHeads;
43
+ private readonly memberHeads;
44
+ /** Barrel import path of each symbol, keyed by `name|filePath`. */
45
+ private readonly ownerImportPaths;
46
+ constructor(library: LibraryIndex);
47
+ search(query: string, opts?: SymbolSearchOptions): SymbolSearchResults;
48
+ /** The internal directory a file sits in, or null. TypeScript libraries only. */
49
+ internalDir(filePath: string): string | null;
50
+ private isInternal;
51
+ private symbolWeight;
52
+ }
@@ -0,0 +1,249 @@
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
+ * Ranked search over one library's symbols and the members of its indexed classes and
9
+ * interfaces, with MiniSearch (BM25+).
10
+ *
11
+ * Symbols are indexed on name, kind, package, own member names, and doc summary and body; members
12
+ * on owner, name, type, and doc summary and body. Exact name matches are boosted, TypeScript
13
+ * symbols without a package barrel are down-weighted, and a component, its element factory, and
14
+ * its Props interface fold into one hit. Code under impl/, admin/, inspector/, and dynamics/ is
15
+ * hidden unless asked for, but counted so callers can say how much was hidden.
16
+ */
17
+ import MiniSearch, {} from 'minisearch';
18
+ import { createTermProcessor, firstSentence, isRedundantCompoundMatch, queryTerms, rankByCoverage, splitSummary, tokenize } from './search-text.js';
19
+ export const DEFAULT_SEARCH_LIMIT = 8, MAX_SEARCH_LIMIT = 20, SUMMARY_CHARS = 160, MEMBER_SUMMARY_CHARS = 160;
20
+ //------------------------
21
+ // Tuning
22
+ //------------------------
23
+ const SYMBOL_BOOST = { name: 4, kind: 0.3, package: 0.5, members: 1, summary: 1.5, body: 0.4 }, MEMBER_BOOST = { owner: 2, name: 4, type: 0.3, summary: 1.5, body: 0.4 },
24
+ /** Multiplier when the query spells out a hit's whole name. */
25
+ EXACT_NAME_BOOST = 2.5,
26
+ /** Further multiplier for a member hit whose owner the query also names. */
27
+ OWNER_NAMED_BOOST = 1.3,
28
+ /** Weight of `@xh/hoist/kit/` re-exports of third-party libraries. */
29
+ KIT_WEIGHT = 0.5,
30
+ /** Weight of TypeScript symbols that no package barrel re-exports. */
31
+ FILE_IMPORT_WEIGHT = 0.125,
32
+ /** Weight of members whose docs are inherited, so the declaring type ranks first. */
33
+ INHERITED_DOC_WEIGHT = 0.98, INTERNAL_TOP_DIRS = new Set(['admin', 'inspector', 'dynamics']), INTERNAL_SEGMENT = 'impl';
34
+ export class SymbolSearch {
35
+ library;
36
+ symbolIndex;
37
+ memberIndex;
38
+ symbolHeads;
39
+ memberHeads;
40
+ /** Barrel import path of each symbol, keyed by `name|filePath`. */
41
+ ownerImportPaths = new Map();
42
+ constructor(library) {
43
+ this.library = library;
44
+ const symbolProcessor = createTermProcessor();
45
+ this.symbolHeads = symbolProcessor.compoundHeads;
46
+ this.symbolIndex = new MiniSearch({
47
+ fields: ['name', 'kind', 'package', 'members', 'summary', 'body'],
48
+ tokenize,
49
+ processTerm: symbolProcessor.processTerm
50
+ });
51
+ this.symbolIndex.addAll(library.symbols.map((s, id) => {
52
+ const { summary, rest } = splitSummary(s.doc ?? '');
53
+ this.ownerImportPaths.set(`${s.name}|${s.filePath}`, s.importPath ?? null);
54
+ return {
55
+ id,
56
+ name: s.name,
57
+ kind: s.kind,
58
+ package: s.sourcePackage ?? '',
59
+ members: s.memberNames ?? '',
60
+ summary,
61
+ body: rest
62
+ };
63
+ }));
64
+ const memberProcessor = createTermProcessor();
65
+ this.memberHeads = memberProcessor.compoundHeads;
66
+ this.memberIndex = new MiniSearch({
67
+ fields: ['owner', 'name', 'type', 'summary', 'body'],
68
+ tokenize,
69
+ processTerm: memberProcessor.processTerm
70
+ });
71
+ this.memberIndex.addAll(library.memberIndex.map((m, id) => {
72
+ const { summary, rest } = splitSummary(m.doc ?? '');
73
+ return {
74
+ id,
75
+ owner: m.ownerName,
76
+ name: m.name,
77
+ type: m.type ?? '',
78
+ summary,
79
+ body: rest
80
+ };
81
+ }));
82
+ }
83
+ search(query, opts = {}) {
84
+ const terms = queryTerms(query), ret = {
85
+ query,
86
+ symbols: [],
87
+ members: [],
88
+ symbolTotal: 0,
89
+ memberTotal: 0,
90
+ hiddenSymbols: 0,
91
+ hiddenMembers: 0,
92
+ hiddenExact: []
93
+ };
94
+ if (!terms.length)
95
+ return ret;
96
+ const { library } = this, limit = Math.min(Math.max(opts.limit ?? DEFAULT_SEARCH_LIMIT, 1), MAX_SEARCH_LIMIT), includeInternal = opts.includeInternal === true, exportedOnly = opts.exported ?? !includeInternal, querySet = new Set(terms), rawTokens = tokenize(query),
97
+ // Whole names the query spells out: each raw token, and all tokens run together.
98
+ named = new Set([
99
+ ...rawTokens.map(t => t.toLowerCase()),
100
+ rawTokens.join('').toLowerCase()
101
+ ]), q = terms.join(' '), baseOpts = (heads) => ({
102
+ combineWith: 'OR',
103
+ prefix: term => term.length >= 3,
104
+ // No fuzzy matching: API names are exact, camelCase parts and prefixes already
105
+ // give recall for near misses, and fuzzy pulled "current" hits into "currency".
106
+ fuzzy: false,
107
+ tokenize: s => s.split(' '),
108
+ processTerm: t => t,
109
+ boostDocument: (_id, term) => isRedundantCompoundMatch(heads, term, terms, querySet) ? 0 : 1
110
+ });
111
+ //------------------------
112
+ // Symbols
113
+ //------------------------
114
+ // Internal hits are ranked with the rest, then set aside and counted unless requested.
115
+ const allSymbolHits = rankByCoverage(this.symbolIndex.search(q, {
116
+ ...baseOpts(this.symbolHeads),
117
+ boost: SYMBOL_BOOST,
118
+ filter: hit => {
119
+ const e = library.symbols[hit.id];
120
+ return (!opts.kind || e.kind === opts.kind) && (!exportedOnly || e.isExported);
121
+ }
122
+ }), terms.length).map(({ hit, score }) => {
123
+ const entry = library.symbols[hit.id], exact = named.has(entry.name.toLowerCase()), weight = this.symbolWeight(entry.importPath, entry.isPromiseExtension === true);
124
+ return { entry, score: exact ? hit.score * EXACT_NAME_BOOST * weight : score * weight };
125
+ });
126
+ const symbolHits = includeInternal
127
+ ? allSymbolHits
128
+ : allSymbolHits.filter(h => !this.isInternal(h.entry.filePath));
129
+ if (!includeInternal) {
130
+ ret.hiddenExact = allSymbolHits
131
+ .filter(h => this.isInternal(h.entry.filePath) && named.has(h.entry.name.toLowerCase()))
132
+ .map(h => h.entry);
133
+ }
134
+ const merged = mergeComponentHits(symbolHits.sort((a, b) => b.score - a.score || a.entry.name.length - b.entry.name.length));
135
+ //------------------------
136
+ // Members
137
+ //------------------------
138
+ // *Props members are searched only when the query names the component or its Props.
139
+ const allMemberHits = rankByCoverage(this.memberIndex.search(q, {
140
+ ...baseOpts(this.memberHeads),
141
+ boost: MEMBER_BOOST,
142
+ filter: hit => {
143
+ const owner = library.memberIndex[hit.id].ownerName;
144
+ if (!owner.endsWith('Props'))
145
+ return true;
146
+ const lower = owner.toLowerCase();
147
+ return named.has(lower) || named.has(lower.slice(0, -'props'.length));
148
+ }
149
+ }), terms.length).map(({ hit, score }) => {
150
+ const entry = library.memberIndex[hit.id], importPath = this.ownerImportPaths.get(`${entry.ownerName}|${entry.filePath}`) ?? null, exact = named.has(entry.name.toLowerCase());
151
+ let s = (exact ? hit.score * EXACT_NAME_BOOST : score) *
152
+ this.symbolWeight(importPath, entry.ownerName === 'Promise');
153
+ if (exact && named.has(entry.ownerName.toLowerCase()))
154
+ s *= OWNER_NAMED_BOOST;
155
+ if (entry.docInheritedFrom)
156
+ s *= INHERITED_DOC_WEIGHT;
157
+ return { entry, score: s, importPath };
158
+ });
159
+ const visibleMemberHits = includeInternal
160
+ ? allMemberHits
161
+ : allMemberHits.filter(h => !this.isInternal(h.entry.filePath)), seen = new Set(), memberHits = visibleMemberHits
162
+ .filter(({ entry: e }) => {
163
+ const key = `${e.ownerName}.${e.name}:${e.type}`;
164
+ if (seen.has(key))
165
+ return false;
166
+ seen.add(key);
167
+ return true;
168
+ })
169
+ .sort((a, b) => b.score - a.score ||
170
+ a.entry.ownerName.length - b.entry.ownerName.length ||
171
+ a.entry.name.length - b.entry.name.length);
172
+ ret.symbols = merged.slice(0, limit).map(h => ({
173
+ ...h,
174
+ summary: firstSentence(h.entry.doc ?? '', SUMMARY_CHARS),
175
+ hasMembers: ['class', 'interface', 'trait'].includes(h.entry.kind)
176
+ }));
177
+ ret.members = memberHits.slice(0, limit).map(h => ({
178
+ ...h,
179
+ summary: firstSentence(h.entry.doc ?? '', MEMBER_SUMMARY_CHARS)
180
+ }));
181
+ ret.symbolTotal = merged.length;
182
+ ret.memberTotal = memberHits.length;
183
+ ret.hiddenSymbols = allSymbolHits.length - symbolHits.length;
184
+ ret.hiddenMembers = allMemberHits.length - visibleMemberHits.length;
185
+ return ret;
186
+ }
187
+ /** The internal directory a file sits in, or null. TypeScript libraries only. */
188
+ internalDir(filePath) {
189
+ if (!this.library.isTypeScript)
190
+ return null;
191
+ const dirs = filePath.split('/').filter(Boolean).slice(0, -1);
192
+ if (dirs.length && INTERNAL_TOP_DIRS.has(dirs[0]))
193
+ return dirs[0];
194
+ return dirs.includes(INTERNAL_SEGMENT) ? INTERNAL_SEGMENT : null;
195
+ }
196
+ isInternal(filePath) {
197
+ return this.internalDir(filePath) != null;
198
+ }
199
+ symbolWeight(importPath, noImport) {
200
+ if (!this.library.isTypeScript)
201
+ return 1;
202
+ if (!importPath)
203
+ return noImport ? 1 : FILE_IMPORT_WEIGHT;
204
+ return importPath.startsWith('@xh/hoist/kit/') ? KIT_WEIGHT : 1;
205
+ }
206
+ }
207
+ function componentRole(e) {
208
+ if (e.kind === 'const')
209
+ return /^[A-Z]/.test(e.name) ? 'component' : 'factory';
210
+ if (e.kind === 'interface' && e.name.endsWith('Props') && e.name.length > 5)
211
+ return 'props';
212
+ return null;
213
+ }
214
+ /**
215
+ * Fold a component, its element factory and its Props interface into one hit, at the position
216
+ * of the best-ranked of them. The component itself is preferred as the hit's entry.
217
+ */
218
+ function mergeComponentHits(hits) {
219
+ const groups = new Map(), ret = [];
220
+ for (const hit of hits) {
221
+ const e = hit.entry, role = componentRole(e);
222
+ if (!role) {
223
+ ret.push(hit);
224
+ continue;
225
+ }
226
+ const base = role === 'props' ? e.name.slice(0, -'Props'.length) : e.name, key = `${e.filePath}|${base[0].toLowerCase()}${base.slice(1)}`, group = groups.get(key);
227
+ if (!group) {
228
+ const created = { ...hit };
229
+ groups.set(key, created);
230
+ ret.push(created);
231
+ continue;
232
+ }
233
+ const current = componentRole(group.entry);
234
+ if (role === current)
235
+ continue;
236
+ if (role === 'props')
237
+ group.props = e.name;
238
+ else if (role === 'factory')
239
+ group.factory = e.name;
240
+ if (role === 'component' || (role === 'factory' && current === 'props')) {
241
+ if (current === 'props')
242
+ group.props = group.entry.name;
243
+ else if (current === 'factory')
244
+ group.factory = group.entry.name;
245
+ group.entry = e;
246
+ }
247
+ }
248
+ return ret;
249
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Section model for Hoist documentation.
3
+ *
4
+ * Splits a markdown doc into sections at `##` and `###` headings, with any text before the
5
+ * first such heading forming a leading "intro" section. Sections are the unit of search
6
+ * (`DocSearch.ts`) and of targeted reads (`hoist-read-doc` with `section` or `outline`).
7
+ *
8
+ * Headings inside fenced code blocks are ignored. `####` and deeper headings stay inside their
9
+ * containing section. Line numbers are 1-based and inclusive throughout.
10
+ *
11
+ * Reference-style link definitions (`[label]: url`) usually sit at the end of a doc, outside the
12
+ * section that uses them. A section read appends the definitions its links need.
13
+ */
14
+ /** The parts of a doc entry that sectioning needs. */
15
+ export interface SectionedDoc {
16
+ id: string;
17
+ title: string;
18
+ }
19
+ /** A single `##` / `###` section of a doc, or the intro text before the first one. */
20
+ export interface DocSection {
21
+ /** Registry id of the containing doc. */
22
+ docId: string;
23
+ /** 1 for the intro section, 2 or 3 for `##` / `###` sections. */
24
+ level: 1 | 2 | 3;
25
+ /** Heading text with markdown formatting removed. The intro uses the doc's `#` heading. */
26
+ heading: string;
27
+ /** Headings below the doc title, e.g. `['Built-in Model Support', 'GridModel']`. Empty for the intro. */
28
+ path: string[];
29
+ /** Value to pass as `section` to read this section - the path joined with ` > `, or the intro heading. */
30
+ ref: string;
31
+ /** Display path including the doc title, e.g. `Persistence > Built-in Model Support > GridModel`. */
32
+ breadcrumb: string;
33
+ /** First line of the section (its heading line, or line 1 for the intro). */
34
+ startLine: number;
35
+ /** Last line of the section's own text, before the next `##` or `###` heading. */
36
+ endLine: number;
37
+ /**
38
+ * Last line of the section including nested subsections - what a section read returns.
39
+ * Differs from `endLine` only for a `##` section with `###` children.
40
+ */
41
+ extentEndLine: number;
42
+ /** Estimated token count of the full extent (startLine to extentEndLine). */
43
+ tokens: number;
44
+ /** The section's own text, excluding its heading line. Used for indexing and excerpts. */
45
+ body: string;
46
+ }
47
+ /** Outcome of resolving a caller-supplied section name against a doc's sections. */
48
+ export type SectionResolveResult = {
49
+ kind: 'found';
50
+ section: DocSection;
51
+ } | {
52
+ kind: 'ambiguous';
53
+ candidates: DocSection[];
54
+ } | {
55
+ kind: 'unknown';
56
+ suggestions: DocSection[];
57
+ };
58
+ /**
59
+ * Estimate LLM token count for a string at ~4 characters per token. Coarse, but stable and
60
+ * good enough to size reads and keep search output within budget.
61
+ */
62
+ export declare function estimateTokens(text: string): number;
63
+ /** Format a token estimate for display, e.g. `~6,760 tokens`. */
64
+ export declare function formatTokens(tokens: number): string;
65
+ /** Split a doc's markdown content into sections. */
66
+ export declare function parseDocSections(entry: SectionedDoc, content: string): DocSection[];
67
+ /**
68
+ * Return the markdown for a section's full extent, including its heading and subsections. Any
69
+ * reference link definitions the section uses but does not contain are appended at the end.
70
+ */
71
+ export declare function getSectionContent(content: string, section: DocSection): string;
72
+ /** Sections nested within (and including) the given section. */
73
+ export declare function getSubsections(sections: DocSection[], section: DocSection): DocSection[];
74
+ /** A reference link definition line, e.g. `[ts7]: https://...`. Captures the label. */
75
+ export declare const LINK_DEF_RE: RegExp;
76
+ /** Reduce inline (`[text](url)`) and reference (`[text][label]`, `[text][]`) links to their text. */
77
+ export declare function stripLinks(text: string): string;
78
+ /**
79
+ * Resolve a caller-supplied section name to a single section of a doc.
80
+ *
81
+ * Accepts a heading (`GridModel`), a path (`Built-in Model Support > GridModel`), or a full
82
+ * breadcrumb with the doc title as its first segment. Matching ignores case, punctuation, and
83
+ * markdown (`## Mask`, `persistWith`, `XH.confirm()`), and tries tiers in order, returning the
84
+ * first tier with any match:
85
+ * 1. Exact match on the full path (or the intro heading / doc title).
86
+ * 2. Exact match on the trailing segments of a path.
87
+ * 3. Prefix match on the trailing segments.
88
+ * 4. Substring match on the trailing segments.
89
+ *
90
+ * A tier with more than one distinct match is reported as ambiguous rather than guessed.
91
+ */
92
+ export declare function resolveSection(entry: SectionedDoc, sections: DocSection[], input: string): SectionResolveResult;
93
+ /** Split content into lines, dropping the empty entry after a trailing newline. */
94
+ export declare function splitLines(content: string): string[];