@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,572 @@
|
|
|
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
|
+
* Symbol tools over one or more loaded libraries: search, describe one symbol, and list members.
|
|
9
|
+
* Output text keeps the shapes agents saw from the stdio MCP servers this service replaces.
|
|
10
|
+
* Groovy symbols (hoist-core) use the same shapes, with a Java-style import line.
|
|
11
|
+
*/
|
|
12
|
+
import { estimateTokens } from '../index/doc-sections.js';
|
|
13
|
+
import { firstSentence } from '../index/search-text.js';
|
|
14
|
+
import { DEFAULT_SEARCH_LIMIT, MAX_SEARCH_LIMIT, MEMBER_SUMMARY_CHARS } from '../index/SymbolSearch.js';
|
|
15
|
+
const MAX_SUMMARY_MEMBERS = 60, MAX_EXTERNAL_LISTED = 40, FULL_DETAIL_MAX_TOKENS = 5000, SUMMARY_TYPE_LENGTH = 80, MAX_TYPE_LENGTH = 200;
|
|
16
|
+
export class SymbolTools {
|
|
17
|
+
libraries;
|
|
18
|
+
constructor(libraries) {
|
|
19
|
+
this.libraries = libraries;
|
|
20
|
+
}
|
|
21
|
+
//------------------------
|
|
22
|
+
// Search
|
|
23
|
+
//------------------------
|
|
24
|
+
search(query, opts = {}) {
|
|
25
|
+
const detail = opts.detail || 'concise', limit = Math.min(Math.max(opts.limit ?? DEFAULT_SEARCH_LIMIT, 1), MAX_SEARCH_LIMIT), perLib = this.libraries.map(lib => ({
|
|
26
|
+
lib,
|
|
27
|
+
res: lib.symbolSearch.search(query, { ...opts, limit })
|
|
28
|
+
})), symbols = perLib
|
|
29
|
+
.flatMap(({ lib, res }) => res.symbols.map(hit => ({ lib, hit })))
|
|
30
|
+
.sort((a, b) => b.hit.score - a.hit.score)
|
|
31
|
+
.slice(0, limit), members = perLib
|
|
32
|
+
.flatMap(({ lib, res }) => res.members.map(hit => ({ lib, hit })))
|
|
33
|
+
.sort((a, b) => b.hit.score - a.hit.score)
|
|
34
|
+
.slice(0, limit), sum = (f) => perLib.reduce((acc, p) => acc + f(p.res), 0), symbolTotal = sum(r => r.symbolTotal), memberTotal = sum(r => r.memberTotal), hiddenSymbols = sum(r => r.hiddenSymbols), hiddenMembers = sum(r => r.hiddenMembers), hiddenExact = perLib.flatMap(({ lib, res }) => res.hiddenExact.map(entry => ({ lib, entry })));
|
|
35
|
+
const lines = [];
|
|
36
|
+
if (!symbols.length && !members.length) {
|
|
37
|
+
lines.push(`No symbols or members matched "${query}". Try one strong keyword - an API name like "GridModel" or "persistWith" (camelCase names match their parts).`);
|
|
38
|
+
}
|
|
39
|
+
if (symbols.length) {
|
|
40
|
+
lines.push(`Symbols (${symbols.length} of ${symbolTotal} matched "${query}"):`);
|
|
41
|
+
symbols.forEach(({ lib, hit }, i) => lines.push(...formatSymbolHit(lib, hit, i, detail)));
|
|
42
|
+
}
|
|
43
|
+
if (members.length) {
|
|
44
|
+
if (lines.length)
|
|
45
|
+
lines.push('');
|
|
46
|
+
lines.push(`Members (${members.length} of ${memberTotal}):`);
|
|
47
|
+
const hintedOwners = new Set();
|
|
48
|
+
members.forEach(({ lib, hit }, i) => {
|
|
49
|
+
lines.push(...formatMemberHit(lib, hit, i, detail, hintedOwners));
|
|
50
|
+
hintedOwners.add(hit.entry.ownerName);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
lines.push('', symbols.length || members.length
|
|
54
|
+
? 'Next: hoist-get-symbol {name} for signature, docs, and a member summary; hoist-get-members {name, filter} for member docs.'
|
|
55
|
+
: 'For concepts and how-tos use hoist-search-docs.');
|
|
56
|
+
hiddenExact.forEach(({ lib, entry: e }) => lines.push(`Hidden exact match: ${e.name} (${e.filePath}) - internal (${lib.symbolSearch.internalDir(e.filePath)}/) code; pass includeInternal: true to see it.`));
|
|
57
|
+
if (hiddenSymbols + hiddenMembers > 0) {
|
|
58
|
+
lines.push(`Hidden: ${plural(hiddenSymbols, 'internal symbol')}, ${plural(hiddenMembers, 'member')} (includeInternal: true shows them).`);
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
text: lines.join('\n'),
|
|
62
|
+
structured: {
|
|
63
|
+
query,
|
|
64
|
+
detail,
|
|
65
|
+
symbolCount: symbols.length,
|
|
66
|
+
symbolTotal,
|
|
67
|
+
memberCount: members.length,
|
|
68
|
+
memberTotal,
|
|
69
|
+
hiddenSymbols,
|
|
70
|
+
hiddenMembers,
|
|
71
|
+
hiddenExact: hiddenExact.map(({ entry: e }) => ({
|
|
72
|
+
name: e.name,
|
|
73
|
+
kind: e.kind,
|
|
74
|
+
filePath: e.filePath
|
|
75
|
+
})),
|
|
76
|
+
symbols: symbols.map(({ lib, hit }) => {
|
|
77
|
+
const ret = {
|
|
78
|
+
...symbolRef(lib, hit.entry),
|
|
79
|
+
summary: hit.summary,
|
|
80
|
+
hasMembers: hit.hasMembers
|
|
81
|
+
};
|
|
82
|
+
if (hit.factory)
|
|
83
|
+
ret.factory = hit.factory;
|
|
84
|
+
if (hit.props)
|
|
85
|
+
ret.props = hit.props;
|
|
86
|
+
if (hit.entry.hint)
|
|
87
|
+
ret.hint = hit.entry.hint;
|
|
88
|
+
if (detail === 'full')
|
|
89
|
+
ret.jsDoc = hit.entry.doc;
|
|
90
|
+
return ret;
|
|
91
|
+
}),
|
|
92
|
+
members: members.map(({ lib, hit }) => {
|
|
93
|
+
const m = hit.entry, ret = {
|
|
94
|
+
name: m.name,
|
|
95
|
+
memberKind: m.memberKind,
|
|
96
|
+
ownerName: m.ownerName,
|
|
97
|
+
library: lib.name,
|
|
98
|
+
sourcePackage: m.sourcePackage,
|
|
99
|
+
filePath: m.filePath,
|
|
100
|
+
isStatic: m.isStatic,
|
|
101
|
+
type: m.type,
|
|
102
|
+
summary: hit.summary,
|
|
103
|
+
decorators: m.decorators ?? []
|
|
104
|
+
};
|
|
105
|
+
if (m.ownerHint)
|
|
106
|
+
ret.ownerHint = m.ownerHint;
|
|
107
|
+
if (m.default != null)
|
|
108
|
+
ret.default = m.default;
|
|
109
|
+
if (detail === 'full')
|
|
110
|
+
ret.jsDoc = m.doc;
|
|
111
|
+
return ret;
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//------------------------
|
|
117
|
+
// Get symbol
|
|
118
|
+
//------------------------
|
|
119
|
+
describe(name, filePath, kind) {
|
|
120
|
+
const found = this.locate(name, filePath, kind);
|
|
121
|
+
if (!found)
|
|
122
|
+
return notFound(name);
|
|
123
|
+
const { lib, decls } = found, [primary, ...others] = decls, companions = lib.findCompanions(primary), alternates = filePath ? [] : lib.findAlternates(name, primary.filePath), members = primary.members;
|
|
124
|
+
const lines = [];
|
|
125
|
+
if (others.length) {
|
|
126
|
+
lines.push(`${decls.length} declarations of "${name}" in ${primary.filePath}: ${decls.map(d => d.kind).join(' and ')}.`, '');
|
|
127
|
+
}
|
|
128
|
+
lines.push(formatSymbolBlock(lib, primary, companions));
|
|
129
|
+
others.forEach(d => lines.push('', '---', '', formatSymbolBlock(lib, d, [])));
|
|
130
|
+
if (members != null)
|
|
131
|
+
lines.push('', formatMemberSummary(lib, members));
|
|
132
|
+
if (alternates.length)
|
|
133
|
+
lines.push('', alternatesNote(name, alternates));
|
|
134
|
+
const hint = (symbolNextHint(primary, companions) + filePathHint(alternates)).trim(), structured = {
|
|
135
|
+
requestedName: name,
|
|
136
|
+
symbol: symbolDetail(lib, primary),
|
|
137
|
+
otherDeclarations: others.map(d => symbolDetail(lib, d)),
|
|
138
|
+
companions: companions.map(c => symbolRef(lib, c)),
|
|
139
|
+
alternates: alternates.map(a => symbolRef(lib, a))
|
|
140
|
+
};
|
|
141
|
+
if (members != null) {
|
|
142
|
+
structured.members = {
|
|
143
|
+
total: members.length,
|
|
144
|
+
shown: Math.min(members.length, MAX_SUMMARY_MEMBERS),
|
|
145
|
+
list: members.slice(0, MAX_SUMMARY_MEMBERS).map(m => {
|
|
146
|
+
const r = {
|
|
147
|
+
name: m.name,
|
|
148
|
+
kind: m.kind,
|
|
149
|
+
signature: memberSignature(lib, m, SUMMARY_TYPE_LENGTH),
|
|
150
|
+
isStatic: m.isStatic
|
|
151
|
+
};
|
|
152
|
+
if (m.inheritedFrom)
|
|
153
|
+
r.inheritedFrom = m.inheritedFrom;
|
|
154
|
+
return r;
|
|
155
|
+
})
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const text = lines.join('\n');
|
|
159
|
+
return { text: hint ? `${text}\n\n${hint}` : text, structured };
|
|
160
|
+
}
|
|
161
|
+
//------------------------
|
|
162
|
+
// Get members
|
|
163
|
+
//------------------------
|
|
164
|
+
members(args) {
|
|
165
|
+
const { name, filePath } = args, filter = args.filter || null, include = args.include || 'all', memberKind = args.memberKind || null;
|
|
166
|
+
let lib = null, symbol = null;
|
|
167
|
+
for (const l of this.libraries) {
|
|
168
|
+
symbol =
|
|
169
|
+
l.findSymbol(name, filePath, 'class') ??
|
|
170
|
+
l.findSymbol(name, filePath, 'interface') ??
|
|
171
|
+
l.findSymbol(name, filePath, 'trait') ??
|
|
172
|
+
l.findSymbol(name, filePath);
|
|
173
|
+
if (symbol) {
|
|
174
|
+
lib = l;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (!symbol || !lib)
|
|
179
|
+
return notFound(name);
|
|
180
|
+
if (symbol.members == null) {
|
|
181
|
+
const kinds = lib.findDeclarations(name, symbol.filePath).map(d => d.kind);
|
|
182
|
+
return {
|
|
183
|
+
isError: true,
|
|
184
|
+
text: `"${name}" is a ${kinds.join(' and ')} (${symbol.filePath}), not a class or interface, so it has no members to list. Use hoist-get-symbol {name: "${name}"} to see its declaration.`
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const owner = symbol, ownerLib = lib, all = owner.members, needle = filter?.toLowerCase(), nameMatches = (n) => !needle || n.toLowerCase().includes(needle), members = all.filter(m => nameMatches(m.name) &&
|
|
188
|
+
(!memberKind || m.kind === memberKind) &&
|
|
189
|
+
(include === 'all' || (include === 'own') === (m.inheritedFrom == null))), allExternal = owner.externalMembers ?? [], totalExternal = allExternal.reduce((acc, g) => acc + g.members.length, 0), extKind = memberKind === 'accessor' ? 'property' : memberKind, external = include === 'own'
|
|
190
|
+
? []
|
|
191
|
+
: allExternal
|
|
192
|
+
.map(g => ({
|
|
193
|
+
...g,
|
|
194
|
+
members: g.members.filter(m => nameMatches(m.name) && (!extKind || m.kind === extKind))
|
|
195
|
+
}))
|
|
196
|
+
.filter(g => g.members.length), alternates = filePath ? [] : ownerLib.findAlternates(name, owner.filePath);
|
|
197
|
+
const filtering = !!(filter || include !== 'all' || memberKind), describeFilter = [
|
|
198
|
+
filter ? `matching "${filter}"` : '',
|
|
199
|
+
include !== 'all' ? `${include} only` : '',
|
|
200
|
+
memberKind
|
|
201
|
+
? `${memberKind === 'property' ? 'properties' : memberKind + 's'} only`
|
|
202
|
+
: ''
|
|
203
|
+
]
|
|
204
|
+
.filter(Boolean)
|
|
205
|
+
.join(', '), externalCount = external.reduce((acc, g) => acc + g.members.length, 0), header = filtering
|
|
206
|
+
? `# ${owner.name} Members ${describeFilter} (${members.length} of ${all.length}${totalExternal ? `, ${externalCount} of ${totalExternal} external` : ''})`
|
|
207
|
+
: `# ${owner.name} Members (${members.length}${totalExternal ? `, plus ${totalExternal} external` : ''})`, headerLines = [header, `Import: ${importLine(ownerLib, owner)}`], own = members.filter(m => !m.inheritedFrom), inherited = members.filter(m => m.inheritedFrom), listed = external.map(g => {
|
|
208
|
+
const generic = g.module === '@types/react' && !filter;
|
|
209
|
+
return {
|
|
210
|
+
declaredIn: g.declaredIn,
|
|
211
|
+
module: g.module,
|
|
212
|
+
total: g.members.length,
|
|
213
|
+
members: generic ? [] : g.members.slice(0, MAX_EXTERNAL_LISTED)
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
const renderBody = (level) => {
|
|
217
|
+
const out = [];
|
|
218
|
+
formatMembersByCategory(ownerLib, own, out, level);
|
|
219
|
+
const bySource = new Map();
|
|
220
|
+
for (const m of inherited) {
|
|
221
|
+
let list = bySource.get(m.inheritedFrom);
|
|
222
|
+
if (!list)
|
|
223
|
+
bySource.set(m.inheritedFrom, (list = []));
|
|
224
|
+
list.push(m);
|
|
225
|
+
}
|
|
226
|
+
for (const [source, ms] of bySource) {
|
|
227
|
+
out.push(`## Inherited from ${source} (${ms.length})`, '');
|
|
228
|
+
formatMembersByCategory(ownerLib, ms, out, level);
|
|
229
|
+
}
|
|
230
|
+
if (!members.length)
|
|
231
|
+
out.push(filtering ? 'No members match.' : 'No members found.', '');
|
|
232
|
+
if (external.length) {
|
|
233
|
+
out.push('## Inherited from types outside hoist-react', '');
|
|
234
|
+
for (const g of listed) {
|
|
235
|
+
const from = g.module ? `${g.declaredIn} (${g.module})` : g.declaredIn;
|
|
236
|
+
if (!g.members.length) {
|
|
237
|
+
out.push(`### ${from} - ${g.total} standard React attributes, not listed`);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
out.push(`### ${from} (${g.total})`);
|
|
241
|
+
g.members.forEach(m => out.push(`- ${m.name}${m.type ? `: ${m.type}` : ''}`));
|
|
242
|
+
if (g.members.length < g.total) {
|
|
243
|
+
out.push(`(${g.total - g.members.length} more not listed)`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
out.push('');
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (alternates.length)
|
|
250
|
+
out.push(alternatesNote(name, alternates), '');
|
|
251
|
+
return out;
|
|
252
|
+
};
|
|
253
|
+
let detail = args.detail || 'full', body = renderBody(detail), note = null;
|
|
254
|
+
if (!args.detail && !filtering && detail === 'full') {
|
|
255
|
+
const fullTokens = estimateTokens([...headerLines, '', ...body].join('\n'));
|
|
256
|
+
if (fullTokens > FULL_DETAIL_MAX_TOKENS) {
|
|
257
|
+
detail = 'summary';
|
|
258
|
+
body = renderBody(detail);
|
|
259
|
+
note = `(one line per member: the full listing is ~${fullTokens.toLocaleString('en-US')} tokens. Narrow it with a filter, or ask for full detail to get complete JSDoc.)`;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
else if (detail === 'summary' && members.length) {
|
|
263
|
+
note = '(one line per member, as requested; full detail gives complete JSDoc)';
|
|
264
|
+
}
|
|
265
|
+
const lines = [...headerLines, ...(note ? [note] : []), '', ...body], hint = `Narrow ${owner.name} with filter (substring), include: "own" | "inherited", or memberKind; detail: "full" forces docs on a long list. A filter also searches external groups marked "not listed".${filePathHint(alternates)}`, filterJson = { include };
|
|
266
|
+
if (filter)
|
|
267
|
+
filterJson.filter = filter;
|
|
268
|
+
if (memberKind)
|
|
269
|
+
filterJson.memberKind = memberKind;
|
|
270
|
+
return {
|
|
271
|
+
text: `${lines.join('\n').trimEnd()}\n\n${hint}`,
|
|
272
|
+
structured: {
|
|
273
|
+
requestedName: name,
|
|
274
|
+
owner: symbolDetail(ownerLib, owner),
|
|
275
|
+
filter: filterJson,
|
|
276
|
+
detail,
|
|
277
|
+
totalMembers: all.length,
|
|
278
|
+
members: members.map(memberJson),
|
|
279
|
+
totalExternal,
|
|
280
|
+
externalMembers: listed,
|
|
281
|
+
alternates: alternates.map(a => symbolRef(ownerLib, a))
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
//------------------------
|
|
286
|
+
// Implementation
|
|
287
|
+
//------------------------
|
|
288
|
+
/** First library whose index has the name, with its declarations. */
|
|
289
|
+
locate(name, filePath, kind) {
|
|
290
|
+
for (const lib of this.libraries) {
|
|
291
|
+
const decls = lib.findDeclarations(name, filePath, kind);
|
|
292
|
+
if (decls.length)
|
|
293
|
+
return { lib, decls };
|
|
294
|
+
}
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
//------------------------
|
|
299
|
+
// Formatting helpers
|
|
300
|
+
//------------------------
|
|
301
|
+
function notFound(name) {
|
|
302
|
+
return {
|
|
303
|
+
text: `Symbol "${name}" not found. Use hoist-search-symbols to find the exact name.`,
|
|
304
|
+
isError: true
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function plural(n, word) {
|
|
308
|
+
return `${n} ${word}${n === 1 ? '' : 's'}`;
|
|
309
|
+
}
|
|
310
|
+
function collapseDoc(doc) {
|
|
311
|
+
return (doc ?? '')
|
|
312
|
+
.split('\n')
|
|
313
|
+
.filter(l => l.trim())
|
|
314
|
+
.join('\n');
|
|
315
|
+
}
|
|
316
|
+
function indentDoc(doc, indent = ' ') {
|
|
317
|
+
return collapseDoc(doc)
|
|
318
|
+
.split('\n')
|
|
319
|
+
.map(l => indent + l)
|
|
320
|
+
.join('\n');
|
|
321
|
+
}
|
|
322
|
+
function truncateType(type, max = MAX_TYPE_LENGTH) {
|
|
323
|
+
const t = type ?? '';
|
|
324
|
+
return t.length > max ? t.slice(0, max) + '...' : t;
|
|
325
|
+
}
|
|
326
|
+
/** Import path and whether it is a package barrel, for a symbol in a library. */
|
|
327
|
+
function resolveImport(lib, e) {
|
|
328
|
+
if (!lib.isTypeScript) {
|
|
329
|
+
return {
|
|
330
|
+
importPath: e.sourcePackage ? `${e.sourcePackage}.${e.name}` : null,
|
|
331
|
+
barrelExport: false
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
if (e.importPath)
|
|
335
|
+
return { importPath: e.importPath, barrelExport: true };
|
|
336
|
+
if (!e.isExported || e.isPromiseExtension)
|
|
337
|
+
return { importPath: null, barrelExport: false };
|
|
338
|
+
return { importPath: `@xh/hoist/${e.filePath.replace(/\.tsx?$/, '')}`, barrelExport: false };
|
|
339
|
+
}
|
|
340
|
+
function hitImport(lib, imp, filePath, isPromise) {
|
|
341
|
+
if (imp.importPath) {
|
|
342
|
+
if (!lib.isTypeScript)
|
|
343
|
+
return imp.importPath;
|
|
344
|
+
return imp.barrelExport ? imp.importPath : `${imp.importPath}; file import`;
|
|
345
|
+
}
|
|
346
|
+
return isPromise
|
|
347
|
+
? 'Promise prototype extension, no import needed'
|
|
348
|
+
: `not exported - ${filePath}`;
|
|
349
|
+
}
|
|
350
|
+
function importLine(lib, d) {
|
|
351
|
+
const imp = resolveImport(lib, d);
|
|
352
|
+
if (!lib.isTypeScript)
|
|
353
|
+
return imp.importPath ? `import ${imp.importPath}` : 'none';
|
|
354
|
+
if (imp.importPath) {
|
|
355
|
+
const line = `import {${d.name}} from '${imp.importPath}';`;
|
|
356
|
+
return imp.barrelExport ? line : `${line} (no package barrel re-exports this symbol)`;
|
|
357
|
+
}
|
|
358
|
+
if (d.isPromiseExtension) {
|
|
359
|
+
return 'none needed - Promise prototype extension, available on every Promise';
|
|
360
|
+
}
|
|
361
|
+
return 'none - not exported from its file';
|
|
362
|
+
}
|
|
363
|
+
function memberLabel(m) {
|
|
364
|
+
return `${m.isStatic ? 'static ' : ''}${m.name}${m.isOptional ? '?' : ''}`;
|
|
365
|
+
}
|
|
366
|
+
function memberSignature(lib, m, typeLength = MAX_TYPE_LENGTH) {
|
|
367
|
+
let sig;
|
|
368
|
+
if (m.kind === 'method') {
|
|
369
|
+
const params = (m.parameters ?? [])
|
|
370
|
+
.map(p => `${p.name}: ${truncateType(p.type, typeLength)}`)
|
|
371
|
+
.join(', '), ret = m.returnType || (lib.isTypeScript ? 'void' : m.type || 'void');
|
|
372
|
+
sig = `${memberLabel(m)}(${params}): ${truncateType(ret, typeLength)}`;
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
sig = `${memberLabel(m)}: ${truncateType(m.type, typeLength)}`;
|
|
376
|
+
}
|
|
377
|
+
return m.default != null ? `${sig} = ${m.default}` : sig;
|
|
378
|
+
}
|
|
379
|
+
function symbolRef(lib, e) {
|
|
380
|
+
return {
|
|
381
|
+
name: e.name,
|
|
382
|
+
kind: e.kind,
|
|
383
|
+
library: lib.name,
|
|
384
|
+
...resolveImport(lib, e),
|
|
385
|
+
sourcePackage: e.sourcePackage,
|
|
386
|
+
filePath: e.filePath,
|
|
387
|
+
exported: e.isExported
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function symbolDetail(lib, d) {
|
|
391
|
+
const ret = { ...symbolRef(lib, d), signature: d.signature, jsDoc: d.doc ?? '' };
|
|
392
|
+
for (const key of [
|
|
393
|
+
'extends',
|
|
394
|
+
'implements',
|
|
395
|
+
'decorators',
|
|
396
|
+
'constructorType',
|
|
397
|
+
'instanceOf'
|
|
398
|
+
]) {
|
|
399
|
+
const v = d[key];
|
|
400
|
+
if (v && (!Array.isArray(v) || v.length))
|
|
401
|
+
ret[key] = v;
|
|
402
|
+
}
|
|
403
|
+
return ret;
|
|
404
|
+
}
|
|
405
|
+
function alternatesNote(name, alternates) {
|
|
406
|
+
if (!alternates.length)
|
|
407
|
+
return '';
|
|
408
|
+
const list = alternates
|
|
409
|
+
.map(a => ` - [${a.kind}] ${a.sourcePackage} (${a.filePath})`)
|
|
410
|
+
.join('\n');
|
|
411
|
+
return `Note: ${alternates.length + 1} symbols named "${name}" exist. Others, selectable by file path:\n${list}`;
|
|
412
|
+
}
|
|
413
|
+
function filePathHint(alternates) {
|
|
414
|
+
return alternates.length
|
|
415
|
+
? ` Select an alternate with filePath: "${alternates[0].filePath}".`
|
|
416
|
+
: '';
|
|
417
|
+
}
|
|
418
|
+
function formatSymbolHit(lib, hit, i, detail) {
|
|
419
|
+
const e = hit.entry, kind = hit.factory || hit.props ? 'component' : e.kind, name = hit.factory ? `${e.name} / ${hit.factory}` : e.name, where = hitImport(lib, resolveImport(lib, e), e.filePath, e.isPromiseExtension === true), props = hit.props ? ` Props: ${hit.props}.` : '', hint = e.hint ? ` [${e.hint}]` : '';
|
|
420
|
+
if (detail === 'full') {
|
|
421
|
+
const ret = [
|
|
422
|
+
`${i + 1}. [${kind}] ${name} (${where}; file: ${e.filePath}; exported: ${e.isExported ? 'yes' : 'no'})${props}${hint}`
|
|
423
|
+
];
|
|
424
|
+
if (e.doc)
|
|
425
|
+
ret.push(indentDoc(e.doc));
|
|
426
|
+
return ret;
|
|
427
|
+
}
|
|
428
|
+
const summary = hit.summary ? ` - ${hit.summary}` : '';
|
|
429
|
+
return [`${i + 1}. [${kind}] ${name} (${where})${summary}${props}${hint}`];
|
|
430
|
+
}
|
|
431
|
+
function formatMemberHit(lib, hit, i, detail, hintedOwners) {
|
|
432
|
+
const m = hit.entry, label = `${m.isStatic ? 'static ' : ''}${m.ownerName}.${m.name}`, dflt = m.default != null ? ` = ${m.default}` : '', ownerHint = m.ownerHint && !hintedOwners.has(m.ownerName)
|
|
433
|
+
? ` [${m.ownerName}: ${m.ownerHint}]`
|
|
434
|
+
: '';
|
|
435
|
+
if (detail === 'full') {
|
|
436
|
+
const isPromise = m.ownerName === 'Promise', imp = isPromise
|
|
437
|
+
? { importPath: null, barrelExport: false }
|
|
438
|
+
: resolveImport(lib, {
|
|
439
|
+
name: m.ownerName,
|
|
440
|
+
filePath: m.filePath,
|
|
441
|
+
importPath: hit.importPath,
|
|
442
|
+
isExported: true,
|
|
443
|
+
sourcePackage: m.sourcePackage
|
|
444
|
+
}), ret = [
|
|
445
|
+
`${i + 1}. [${m.memberKind}] ${label}: ${truncateType(m.type)}${dflt} (${hitImport(lib, imp, m.filePath, isPromise)})${ownerHint}`
|
|
446
|
+
];
|
|
447
|
+
if (m.doc)
|
|
448
|
+
ret.push(indentDoc(m.doc));
|
|
449
|
+
return ret;
|
|
450
|
+
}
|
|
451
|
+
const summary = hit.summary ? ` - ${hit.summary}` : '';
|
|
452
|
+
return [
|
|
453
|
+
`${i + 1}. ${label}: ${truncateType(m.type, SUMMARY_TYPE_LENGTH)}${dflt}${summary}${ownerHint}`
|
|
454
|
+
];
|
|
455
|
+
}
|
|
456
|
+
function formatSymbolBlock(lib, d, companions) {
|
|
457
|
+
const lines = [
|
|
458
|
+
`# ${d.name} (${d.kind})`,
|
|
459
|
+
`Import: ${importLine(lib, d)}`,
|
|
460
|
+
`Package: ${d.sourcePackage}`,
|
|
461
|
+
`File: ${d.filePath}`,
|
|
462
|
+
`Exported: ${d.isExported ? 'yes' : 'no'}`
|
|
463
|
+
];
|
|
464
|
+
if (d.extends)
|
|
465
|
+
lines.push(`Extends: ${d.extends}`);
|
|
466
|
+
if (d.implements?.length)
|
|
467
|
+
lines.push(`Implements: ${d.implements.join(', ')}`);
|
|
468
|
+
if (d.decorators?.length) {
|
|
469
|
+
lines.push(`${lib.isTypeScript ? 'Decorators' : 'Annotations'}: ${d.decorators.map(x => `@${x}`).join(', ')}`);
|
|
470
|
+
}
|
|
471
|
+
if (d.constructorType)
|
|
472
|
+
lines.push(`Constructor: new ${d.name}(config: ${d.constructorType})`);
|
|
473
|
+
if (d.instanceOf)
|
|
474
|
+
lines.push(`Instance of: ${d.instanceOf}`);
|
|
475
|
+
if (companions.length) {
|
|
476
|
+
lines.push(d.kind === 'interface' && d.name.endsWith('Props')
|
|
477
|
+
? `Component: ${companions.map(c => c.name).join(', ')}`
|
|
478
|
+
: `Props: ${companions[0].name}`);
|
|
479
|
+
}
|
|
480
|
+
lines.push('', '## Signature', d.signature);
|
|
481
|
+
if (d.doc)
|
|
482
|
+
lines.push('', '## Documentation', collapseDoc(d.doc));
|
|
483
|
+
return lines.join('\n');
|
|
484
|
+
}
|
|
485
|
+
function formatMemberSummary(lib, members) {
|
|
486
|
+
const own = members.filter(m => !m.inheritedFrom), inherited = members.filter(m => m.inheritedFrom), shown = members.slice(0, MAX_SUMMARY_MEMBERS), lines = [`## Members (${own.length} own, ${inherited.length} inherited)`];
|
|
487
|
+
let lastSource = null;
|
|
488
|
+
for (const m of shown) {
|
|
489
|
+
if (m.inheritedFrom && m.inheritedFrom !== lastSource) {
|
|
490
|
+
lines.push(`### Inherited from ${m.inheritedFrom}`);
|
|
491
|
+
lastSource = m.inheritedFrom;
|
|
492
|
+
}
|
|
493
|
+
lines.push(`- ${memberSignature(lib, m, SUMMARY_TYPE_LENGTH)}`);
|
|
494
|
+
}
|
|
495
|
+
if (members.length > shown.length) {
|
|
496
|
+
lines.push(`(${members.length - shown.length} more members not shown)`);
|
|
497
|
+
}
|
|
498
|
+
if (!members.length)
|
|
499
|
+
lines.push('No members found.');
|
|
500
|
+
return lines.join('\n');
|
|
501
|
+
}
|
|
502
|
+
function symbolNextHint(d, companions) {
|
|
503
|
+
const target = ['class', 'interface', 'trait'].includes(d.kind)
|
|
504
|
+
? d.name
|
|
505
|
+
: (d.instanceOf ?? companions.find(c => c.kind === 'interface')?.name);
|
|
506
|
+
if (!target)
|
|
507
|
+
return '';
|
|
508
|
+
const what = target === d.name
|
|
509
|
+
? 'Full member details'
|
|
510
|
+
: target === d.instanceOf
|
|
511
|
+
? `Members of \`${target}\``
|
|
512
|
+
: `Its props (\`${target}\`)`;
|
|
513
|
+
return `${what}: hoist-get-members {name: "${target}"}; narrow with filter: "<text>", include: "own" | "inherited", or memberKind.`;
|
|
514
|
+
}
|
|
515
|
+
function memberJson(m) {
|
|
516
|
+
const ret = {
|
|
517
|
+
name: m.name,
|
|
518
|
+
kind: m.kind,
|
|
519
|
+
type: m.type,
|
|
520
|
+
isStatic: m.isStatic,
|
|
521
|
+
decorators: m.decorators ?? [],
|
|
522
|
+
jsDoc: m.doc ?? ''
|
|
523
|
+
};
|
|
524
|
+
for (const key of [
|
|
525
|
+
'isOptional',
|
|
526
|
+
'default',
|
|
527
|
+
'parameters',
|
|
528
|
+
'returnType',
|
|
529
|
+
'returns',
|
|
530
|
+
'inheritedFrom'
|
|
531
|
+
]) {
|
|
532
|
+
if (m[key] != null)
|
|
533
|
+
ret[key] = m[key];
|
|
534
|
+
}
|
|
535
|
+
if (m.docInheritedFrom)
|
|
536
|
+
ret.jsDocInheritedFrom = m.docInheritedFrom;
|
|
537
|
+
return ret;
|
|
538
|
+
}
|
|
539
|
+
function formatMember(lib, m, detail) {
|
|
540
|
+
const decorators = m.decorators ?? [], prefix = decorators.length ? decorators.map(d => `@${d}`).join(' ') + ' ' : '', inheritedSuffix = m.inheritedFrom ? ` (inherited from ${m.inheritedFrom})` : '';
|
|
541
|
+
if (detail === 'summary') {
|
|
542
|
+
const summary = firstSentence(m.doc ?? '', MEMBER_SUMMARY_CHARS);
|
|
543
|
+
return `- ${prefix}${memberSignature(lib, m, SUMMARY_TYPE_LENGTH)}${summary ? ` - ${summary}` : ''}${inheritedSuffix}`;
|
|
544
|
+
}
|
|
545
|
+
const lines = [`- ${prefix}${memberSignature(lib, m)}${inheritedSuffix}`];
|
|
546
|
+
if (m.doc)
|
|
547
|
+
lines.push(indentDoc(m.doc));
|
|
548
|
+
const described = (m.parameters ?? []).filter(p => p.description);
|
|
549
|
+
if (described.length) {
|
|
550
|
+
lines.push(' Parameters:');
|
|
551
|
+
described.forEach(p => lines.push(` ${p.name}: ${p.description.split('\n').join('\n ')}`));
|
|
552
|
+
}
|
|
553
|
+
if (m.returns?.description) {
|
|
554
|
+
lines.push(` Returns: ${m.returns.description.split('\n').join('\n ')}`);
|
|
555
|
+
}
|
|
556
|
+
return lines.join('\n');
|
|
557
|
+
}
|
|
558
|
+
function formatMembersByCategory(lib, members, lines, detail) {
|
|
559
|
+
const groups = [
|
|
560
|
+
['Properties', members.filter(m => !m.isStatic && m.kind !== 'method')],
|
|
561
|
+
['Methods', members.filter(m => !m.isStatic && m.kind === 'method')],
|
|
562
|
+
['Static Properties', members.filter(m => m.isStatic && m.kind !== 'method')],
|
|
563
|
+
['Static Methods', members.filter(m => m.isStatic && m.kind === 'method')]
|
|
564
|
+
];
|
|
565
|
+
for (const [title, group] of groups) {
|
|
566
|
+
if (!group.length)
|
|
567
|
+
continue;
|
|
568
|
+
lines.push(`### ${title} (${group.length})`);
|
|
569
|
+
group.forEach(m => lines.push(formatMember(lib, m, detail)));
|
|
570
|
+
lines.push('');
|
|
571
|
+
}
|
|
572
|
+
}
|
package/dist/usage.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** One usage record: an MCP tool call. */
|
|
2
|
+
export interface Usage {
|
|
3
|
+
category: 'MCP';
|
|
4
|
+
/** Tool name or API action. */
|
|
5
|
+
action: string;
|
|
6
|
+
elapsedMs: number;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
/** Write a usage record as a structured log line, `msg: 'usage'`, for log-based reporting. */
|
|
10
|
+
export declare function trackUsage(usage: Usage): void;
|
package/dist/usage.js
ADDED
|
@@ -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
|
+
import { log } from './log.js';
|
|
8
|
+
/** Write a usage record as a structured log line, `msg: 'usage'`, for log-based reporting. */
|
|
9
|
+
export function trackUsage(usage) {
|
|
10
|
+
log.info('usage', usage);
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xh/hoist-docs",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Hoist documentation and API reference for AI coding agents, over MCP",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/xh/hoist-docs.git"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=24"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"hoist-docs": "bin/hoist-docs.mjs"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/cli.d.ts",
|
|
20
|
+
"default": "./dist/cli.js"
|
|
21
|
+
},
|
|
22
|
+
"./docs": {
|
|
23
|
+
"types": "./dist/docs/index.d.ts",
|
|
24
|
+
"default": "./dist/docs/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"bin",
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE.md"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"start": "node src/cli.ts --http --index-dir indexes",
|
|
36
|
+
"dev": "node --watch src/cli.ts --http --index-dir indexes",
|
|
37
|
+
"mcp": "node src/cli.ts",
|
|
38
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
39
|
+
"prepack": "pnpm build",
|
|
40
|
+
"build:react": "node builders/react/cli/build-index.ts",
|
|
41
|
+
"build:core": "builders/core/build-index.sh",
|
|
42
|
+
"typecheck": "tsc",
|
|
43
|
+
"lint": "eslint . && prettier --check .",
|
|
44
|
+
"format": "prettier --write .",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"test:watch": "vitest",
|
|
47
|
+
"build:builder": "pnpm --filter @xh/hoist-docs-builder build"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@modelcontextprotocol/server": "^2.4.0",
|
|
51
|
+
"minisearch": "^7.2.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@modelcontextprotocol/client": "^2.4.0",
|
|
55
|
+
"@types/node": "^24.10.0",
|
|
56
|
+
"@xh/eslint-config": "^8.1.0",
|
|
57
|
+
"eslint": "^10.13.0",
|
|
58
|
+
"eslint-config-prettier": "^10.1.8",
|
|
59
|
+
"prettier": "^3.9.10",
|
|
60
|
+
"typescript": "^7.0.2",
|
|
61
|
+
"vitest": "^5.1.0"
|
|
62
|
+
},
|
|
63
|
+
"packageManager": "pnpm@12.7.0"
|
|
64
|
+
}
|