@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,245 @@
|
|
|
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
|
+
* Documentation tools over one or more loaded libraries: search, list, and read. Output text
|
|
9
|
+
* keeps the shapes agents saw from the stdio MCP servers this service replaces.
|
|
10
|
+
*
|
|
11
|
+
* Doc ids from libraries other than hoist-react are qualified with the library id
|
|
12
|
+
* (`core:docs/caching.md`), since hoist-react and hoist-core both have e.g. `docs/README.md`.
|
|
13
|
+
* Unqualified ids resolve against hoist-react first.
|
|
14
|
+
*/
|
|
15
|
+
import { DEFAULT_SEARCH_LIMIT, MAX_SEARCH_LIMIT } from '../index/DocSearch.js';
|
|
16
|
+
import { estimateTokens, formatTokens, getSectionContent, getSubsections, resolveSection, splitLines } from '../index/doc-sections.js';
|
|
17
|
+
/** Full reads above this size carry a note pointing to `section` and `outline`. */
|
|
18
|
+
const LARGE_DOC_TOKENS = 3000;
|
|
19
|
+
export function qualifiedId(lib, docId) {
|
|
20
|
+
return lib.id === 'react' ? docId : `${lib.id}:${docId}`;
|
|
21
|
+
}
|
|
22
|
+
export class DocTools {
|
|
23
|
+
/** Libraries in scope for this call, hoist-react first. */
|
|
24
|
+
libraries;
|
|
25
|
+
constructor(libraries) {
|
|
26
|
+
this.libraries = libraries;
|
|
27
|
+
}
|
|
28
|
+
//------------------------
|
|
29
|
+
// Search
|
|
30
|
+
//------------------------
|
|
31
|
+
search(query, category, limit) {
|
|
32
|
+
const max = Math.min(Math.max(limit ?? DEFAULT_SEARCH_LIMIT, 1), MAX_SEARCH_LIMIT), results = this.libraries
|
|
33
|
+
.flatMap(lib => lib.docSearch.search(query, category, max).map(r => ({ lib, r })))
|
|
34
|
+
.sort((a, b) => b.r.score - a.r.score)
|
|
35
|
+
.slice(0, max);
|
|
36
|
+
let text;
|
|
37
|
+
if (!results.length) {
|
|
38
|
+
text = `No sections matched "${query}". Try two or three keywords, using the names the docs use (e.g. "persistWith", "XH.confirm").`;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const lines = [
|
|
42
|
+
`${results.length} section${results.length > 1 ? 's' : ''} matched "${query}":`,
|
|
43
|
+
''
|
|
44
|
+
];
|
|
45
|
+
results.forEach(({ lib, r }, i) => {
|
|
46
|
+
const s = r.section;
|
|
47
|
+
lines.push(`${i + 1}. ${s.breadcrumb}${this.libraryLabel(lib)}`);
|
|
48
|
+
lines.push(` id: ${qualifiedId(lib, r.entry.id)} | section: "${s.ref}" | L${s.startLine}-${s.extentEndLine} | ${formatTokens(s.tokens)}`);
|
|
49
|
+
lines.push(` ${r.excerpt}`);
|
|
50
|
+
lines.push('');
|
|
51
|
+
});
|
|
52
|
+
text =
|
|
53
|
+
lines.join('\n').trimEnd() +
|
|
54
|
+
"\n\nRead a result with hoist-read-doc {id, section}, or list a doc's sections with {id, outline: true}.";
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
text,
|
|
58
|
+
structured: {
|
|
59
|
+
query,
|
|
60
|
+
resultCount: results.length,
|
|
61
|
+
results: results.map(({ lib, r }) => searchResultJson(lib, r))
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Tags hits from libraries other than hoist-react when several are in scope. */
|
|
66
|
+
libraryLabel(lib) {
|
|
67
|
+
return this.libraries.length > 1 && lib.id !== 'react' ? ` [${lib.name}]` : '';
|
|
68
|
+
}
|
|
69
|
+
//------------------------
|
|
70
|
+
// List
|
|
71
|
+
//------------------------
|
|
72
|
+
list(category) {
|
|
73
|
+
const cat = category || 'all', lines = [], entries = [];
|
|
74
|
+
for (const lib of this.libraries) {
|
|
75
|
+
const inScope = lib.docs.filter(d => cat === 'all' || d.mcpCategory === cat), header = lib.id === 'react' ? 'Hoist Documentation' : `${lib.name} ${lib.version}`;
|
|
76
|
+
lines.push(`${header} (${inScope.length} documents):\n`);
|
|
77
|
+
for (const c of lib.mcpCategories) {
|
|
78
|
+
const inCat = inScope.filter(d => d.mcpCategory === c.id);
|
|
79
|
+
if (!inCat.length)
|
|
80
|
+
continue;
|
|
81
|
+
lines.push(`## ${c.title} (${inCat.length} doc${inCat.length > 1 ? 's' : ''})`);
|
|
82
|
+
inCat.forEach(d => lines.push(`- ${qualifiedId(lib, d.id)}: ${d.description}`));
|
|
83
|
+
lines.push('');
|
|
84
|
+
}
|
|
85
|
+
inScope.forEach(d => entries.push({
|
|
86
|
+
id: qualifiedId(lib, d.id),
|
|
87
|
+
title: d.title,
|
|
88
|
+
library: lib.name,
|
|
89
|
+
category: d.mcpCategory,
|
|
90
|
+
description: d.description
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
const categories = new Map();
|
|
94
|
+
this.libraries
|
|
95
|
+
.flatMap(l => l.mcpCategories)
|
|
96
|
+
.forEach(c => {
|
|
97
|
+
if (!categories.has(c.id))
|
|
98
|
+
categories.set(c.id, c.title);
|
|
99
|
+
});
|
|
100
|
+
return {
|
|
101
|
+
text: lines.join('\n') +
|
|
102
|
+
'Read a doc with hoist-read-doc {id} - add section: "<heading>" for one section, or outline: true for its headings. The hoist://docs/{id} resource also serves full docs.',
|
|
103
|
+
structured: {
|
|
104
|
+
categoryFilter: cat,
|
|
105
|
+
totalCount: entries.length,
|
|
106
|
+
entries,
|
|
107
|
+
categories: [...categories].map(([id, title]) => ({ id, title })),
|
|
108
|
+
libraries: this.libraries.map(l => ({
|
|
109
|
+
name: l.name,
|
|
110
|
+
version: l.version,
|
|
111
|
+
docCount: l.docs.length
|
|
112
|
+
}))
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//------------------------
|
|
117
|
+
// Read
|
|
118
|
+
//------------------------
|
|
119
|
+
/** Resolve an id - qualified (`core:...`) or not - against the libraries in scope. */
|
|
120
|
+
locate(id) {
|
|
121
|
+
const raw = (id ?? '').trim(), colon = raw.indexOf(':');
|
|
122
|
+
if (colon > 0) {
|
|
123
|
+
const lib = this.libraries.find(l => l.id === raw.slice(0, colon));
|
|
124
|
+
if (lib)
|
|
125
|
+
return { lib, resolution: lib.resolver.resolve(raw.slice(colon + 1)) };
|
|
126
|
+
}
|
|
127
|
+
let firstMiss = null;
|
|
128
|
+
for (const lib of this.libraries) {
|
|
129
|
+
const resolution = lib.resolver.resolve(raw);
|
|
130
|
+
if (resolution.kind !== 'unknown')
|
|
131
|
+
return { lib, resolution };
|
|
132
|
+
firstMiss ??= { lib, resolution };
|
|
133
|
+
}
|
|
134
|
+
return firstMiss;
|
|
135
|
+
}
|
|
136
|
+
read(id, section, outline = false) {
|
|
137
|
+
const located = this.locate(id);
|
|
138
|
+
if (!located || located.resolution.kind === 'unknown') {
|
|
139
|
+
const suggestions = located?.resolution.kind === 'unknown'
|
|
140
|
+
? located.resolution.suggestions.map(s => qualifiedId(located.lib, s))
|
|
141
|
+
: [];
|
|
142
|
+
const tail = suggestions.length
|
|
143
|
+
? `Did you mean one of: ${suggestions.map(s => `"${s}"`).join(', ')}?`
|
|
144
|
+
: 'Call hoist-list-docs to see valid IDs, or hoist-search-docs to find one by keyword.';
|
|
145
|
+
return { text: `Unknown document ID: "${id}". ${tail}`, isError: true };
|
|
146
|
+
}
|
|
147
|
+
const { lib } = located, { entry } = located.resolution, content = entry.markdown, canonical = qualifiedId(lib, entry.id), base = {
|
|
148
|
+
id: canonical,
|
|
149
|
+
title: entry.title,
|
|
150
|
+
category: entry.mcpCategory,
|
|
151
|
+
library: lib.name
|
|
152
|
+
};
|
|
153
|
+
if (canonical !== id)
|
|
154
|
+
base.matchedAs = id;
|
|
155
|
+
if (!section && !outline) {
|
|
156
|
+
const tokens = estimateTokens(content), note = tokens > LARGE_DOC_TOKENS
|
|
157
|
+
? `This doc is ${formatTokens(tokens)}. Pass outline: true to list its sections, or section: "<heading>" to read one.\n\n`
|
|
158
|
+
: '';
|
|
159
|
+
return { text: note + content, structured: { ...base, tokens, content } };
|
|
160
|
+
}
|
|
161
|
+
const { sections } = entry;
|
|
162
|
+
let target = null;
|
|
163
|
+
if (section) {
|
|
164
|
+
const found = resolveSection(entry, sections, section);
|
|
165
|
+
if (found.kind !== 'found') {
|
|
166
|
+
return {
|
|
167
|
+
text: formatSectionMiss(canonical, sections, section, found),
|
|
168
|
+
isError: true
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
target = found.section;
|
|
172
|
+
}
|
|
173
|
+
if (outline) {
|
|
174
|
+
const outlined = target ? getSubsections(sections, target) : sections, lines = [
|
|
175
|
+
`Outline of ${canonical} (${entry.title}, ${formatTokens(estimateTokens(content))}, ${splitLines(content).length} lines):`,
|
|
176
|
+
''
|
|
177
|
+
];
|
|
178
|
+
outlined.forEach(s => lines.push(`${s.level === 3 ? ' ' : ''}- ${s.heading} L${s.startLine}-${s.extentEndLine} ${formatTokens(s.tokens)}`));
|
|
179
|
+
lines.push('', 'Read one with section: "<heading>". Use "<parent> > <heading>" when a heading repeats.');
|
|
180
|
+
return {
|
|
181
|
+
text: lines.join('\n'),
|
|
182
|
+
structured: {
|
|
183
|
+
...base,
|
|
184
|
+
tokens: target ? target.tokens : estimateTokens(content),
|
|
185
|
+
outline: outlined.map(s => ({
|
|
186
|
+
section: s.ref,
|
|
187
|
+
heading: s.heading,
|
|
188
|
+
level: s.level,
|
|
189
|
+
startLine: s.startLine,
|
|
190
|
+
endLine: s.extentEndLine,
|
|
191
|
+
tokens: s.tokens
|
|
192
|
+
}))
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const t = target, body = getSectionContent(content, t);
|
|
197
|
+
return {
|
|
198
|
+
text: `[${canonical} | ${t.breadcrumb} | L${t.startLine}-${t.extentEndLine} | ${formatTokens(t.tokens)}]\n\n${body}`,
|
|
199
|
+
structured: {
|
|
200
|
+
...base,
|
|
201
|
+
tokens: t.tokens,
|
|
202
|
+
content: body,
|
|
203
|
+
section: {
|
|
204
|
+
section: t.ref,
|
|
205
|
+
breadcrumb: t.breadcrumb,
|
|
206
|
+
startLine: t.startLine,
|
|
207
|
+
endLine: t.extentEndLine
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
//------------------------
|
|
214
|
+
// Implementation
|
|
215
|
+
//------------------------
|
|
216
|
+
function searchResultJson(lib, r) {
|
|
217
|
+
return {
|
|
218
|
+
id: qualifiedId(lib, r.entry.id),
|
|
219
|
+
library: lib.name,
|
|
220
|
+
section: r.section.ref,
|
|
221
|
+
breadcrumb: r.section.breadcrumb,
|
|
222
|
+
category: r.entry.mcpCategory,
|
|
223
|
+
startLine: r.section.startLine,
|
|
224
|
+
endLine: r.section.extentEndLine,
|
|
225
|
+
tokens: r.section.tokens,
|
|
226
|
+
score: Math.round(r.score * 10) / 10,
|
|
227
|
+
excerpt: r.excerpt
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function formatSectionMiss(docId, sections, input, result) {
|
|
231
|
+
const lines = [];
|
|
232
|
+
if (result.kind === 'ambiguous') {
|
|
233
|
+
lines.push(`Section "${input}" matches ${result.candidates.length} sections in ${docId}. Pass the full path of one:`);
|
|
234
|
+
result.candidates.forEach(c => lines.push(`- "${c.ref}"`));
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
lines.push(`No section "${input}" in ${docId}.`);
|
|
238
|
+
if (result.suggestions.length) {
|
|
239
|
+
lines.push(`Did you mean one of: ${result.suggestions.map(s => `"${s.ref}"`).join(', ')}?`);
|
|
240
|
+
}
|
|
241
|
+
lines.push('', 'Sections:');
|
|
242
|
+
sections.forEach(s => lines.push(`${s.level === 3 ? ' ' : ''}- ${s.heading}`));
|
|
243
|
+
}
|
|
244
|
+
return lines.join('\n');
|
|
245
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LibraryIndex } from '../index/LibraryIndex.ts';
|
|
2
|
+
import type { MemberKind, SymbolKind } from '../index/types.ts';
|
|
3
|
+
import type { ToolOutput } from './types.ts';
|
|
4
|
+
export interface SymbolSearchArgs {
|
|
5
|
+
kind?: string | null;
|
|
6
|
+
exported?: boolean | null;
|
|
7
|
+
includeInternal?: boolean | null;
|
|
8
|
+
detail?: string | null;
|
|
9
|
+
limit?: number | null;
|
|
10
|
+
}
|
|
11
|
+
export interface MembersArgs {
|
|
12
|
+
name: string;
|
|
13
|
+
filePath?: string | null;
|
|
14
|
+
filter?: string | null;
|
|
15
|
+
include?: string | null;
|
|
16
|
+
memberKind?: MemberKind | null;
|
|
17
|
+
detail?: string | null;
|
|
18
|
+
}
|
|
19
|
+
export declare class SymbolTools {
|
|
20
|
+
readonly libraries: LibraryIndex[];
|
|
21
|
+
constructor(libraries: LibraryIndex[]);
|
|
22
|
+
search(query: string, opts?: SymbolSearchArgs): ToolOutput;
|
|
23
|
+
describe(name: string, filePath?: string | null, kind?: SymbolKind | null): ToolOutput;
|
|
24
|
+
members(args: MembersArgs): ToolOutput;
|
|
25
|
+
/** First library whose index has the name, with its declarations. */
|
|
26
|
+
private locate;
|
|
27
|
+
}
|