docspack 0.2.0 → 0.3.0
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/README.md +9 -3
- package/dist/build.d.ts +21 -0
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +138 -24
- package/dist/build.js.map +1 -1
- package/dist/cli.js +74 -131
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +7 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +20 -1
- package/dist/config.js.map +1 -1
- package/dist/db.d.ts +8 -4
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +13 -7
- package/dist/db.js.map +1 -1
- package/dist/doctor.js +1 -1
- package/dist/doctor.js.map +1 -1
- package/dist/eval.d.ts +52 -0
- package/dist/eval.d.ts.map +1 -0
- package/dist/eval.js +101 -0
- package/dist/eval.js.map +1 -0
- package/dist/help.d.ts +31 -0
- package/dist/help.d.ts.map +1 -0
- package/dist/help.js +342 -0
- package/dist/help.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/preview.d.ts.map +1 -1
- package/dist/preview.js +4 -2
- package/dist/preview.js.map +1 -1
- package/dist/search.d.ts +6 -0
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +25 -3
- package/dist/search.js.map +1 -1
- package/dist/spec.d.ts +21 -1
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js +44 -5
- package/dist/spec.js.map +1 -1
- package/dist/stopwords.d.ts +14 -0
- package/dist/stopwords.d.ts.map +1 -0
- package/dist/stopwords.js +121 -0
- package/dist/stopwords.js.map +1 -0
- package/dist/sync.js +1 -1
- package/dist/sync.js.map +1 -1
- package/dist/verify.d.ts +8 -2
- package/dist/verify.d.ts.map +1 -1
- package/dist/verify.js +48 -15
- package/dist/verify.js.map +1 -1
- package/package.json +1 -1
- package/src/build.ts +178 -24
- package/src/cli.ts +91 -138
- package/src/config.ts +35 -5
- package/src/db.ts +13 -7
- package/src/doctor.ts +1 -1
- package/src/eval.ts +149 -0
- package/src/help.ts +382 -0
- package/src/index.ts +20 -0
- package/src/preview.ts +4 -1
- package/src/search.ts +33 -3
- package/src/spec.ts +66 -6
- package/src/stopwords.ts +120 -0
- package/src/sync.ts +1 -1
- package/src/verify.ts +69 -19
package/src/help.ts
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { AGENTS_SNIPPET, FEEDBACK_SNIPPET } from "./snippet.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The help text, per command.
|
|
5
|
+
*
|
|
6
|
+
* `docspack <command> --help` printed the global help, so no flag was discoverable from the CLI
|
|
7
|
+
* at all — `doctor --pedantic`, `ask --max-tokens` and `init --mirror` were findable only by
|
|
8
|
+
* reading the source. That matters more than usual for a tool whose main user is an agent that
|
|
9
|
+
* will not open a browser, and it is why the global page now points at these rather than trying
|
|
10
|
+
* to list every flag of every command in one block.
|
|
11
|
+
*/
|
|
12
|
+
export interface CommandHelp {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
/** The line this command shows in the global help and on the site. */
|
|
15
|
+
readonly summary: string;
|
|
16
|
+
readonly group: "core" | "authoring";
|
|
17
|
+
readonly usage: string;
|
|
18
|
+
/** Flags this command reads, beyond the global ones. */
|
|
19
|
+
readonly options: readonly (readonly [string, string])[];
|
|
20
|
+
readonly detail?: readonly string[];
|
|
21
|
+
readonly examples: readonly string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const LIMIT = 3;
|
|
25
|
+
const MAX_TOKENS = 3000;
|
|
26
|
+
|
|
27
|
+
const QUERY_OPTIONS: readonly (readonly [string, string])[] = [
|
|
28
|
+
["-p, --package <s>", "only packages whose name contains this text"],
|
|
29
|
+
["--limit <n>", `maximum chunks to return (default ${LIMIT})`],
|
|
30
|
+
["--max-tokens <n>", `token ceiling for the result set (default ${MAX_TOKENS})`],
|
|
31
|
+
["--all", "search the whole store, not just this project"],
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
export const COMMANDS: readonly CommandHelp[] = [
|
|
35
|
+
{
|
|
36
|
+
name: "sync",
|
|
37
|
+
summary: "Index the docs packages this project depends on",
|
|
38
|
+
group: "core",
|
|
39
|
+
usage: "docspack sync [options]",
|
|
40
|
+
options: [["--force", "re-index packages already in the store"]],
|
|
41
|
+
detail: [
|
|
42
|
+
"Reads node_modules and indexes every @vendor/docspack and @docspack-community/<name>",
|
|
43
|
+
"package this project declares. Makes no network requests.",
|
|
44
|
+
],
|
|
45
|
+
examples: ["docspack sync", "docspack sync --force"],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "ask",
|
|
49
|
+
summary: "Answer from the local index — the command to give an agent",
|
|
50
|
+
group: "core",
|
|
51
|
+
usage: 'docspack ask "<question>"',
|
|
52
|
+
options: QUERY_OPTIONS,
|
|
53
|
+
detail: [
|
|
54
|
+
"Answers from the installed versions, in the Markdown an agent should read. Exits 0 when",
|
|
55
|
+
"chunks were returned, 3 when a docs package is installed but not indexed, and 4 when",
|
|
56
|
+
"everything installed is indexed and nothing matched.",
|
|
57
|
+
],
|
|
58
|
+
examples: [
|
|
59
|
+
'docspack ask "how do I verify a webhook signature"',
|
|
60
|
+
'docspack ask "webhook signature" --package stripe --limit 5',
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "search",
|
|
65
|
+
summary: "Same index, formatted for a human reading the terminal",
|
|
66
|
+
group: "core",
|
|
67
|
+
usage: "docspack search <query>",
|
|
68
|
+
options: QUERY_OPTIONS,
|
|
69
|
+
detail: ["The same index and ranking as `ask`, printed as a list of hits with a preview."],
|
|
70
|
+
examples: ["docspack search webhook signature"],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "list",
|
|
74
|
+
summary: "Show this project's docs packages and their index state",
|
|
75
|
+
group: "core",
|
|
76
|
+
usage: "docspack list",
|
|
77
|
+
options: [],
|
|
78
|
+
examples: ["docspack list", "docspack list --json"],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "verify",
|
|
82
|
+
summary: "Check the docs still describe the code you installed",
|
|
83
|
+
group: "core",
|
|
84
|
+
usage: "docspack verify [options]",
|
|
85
|
+
options: [["--package-dir <d>", "verify one package directory instead of what is installed"]],
|
|
86
|
+
detail: [
|
|
87
|
+
"Compares the identifiers the chunks name against what the documented libraries declare,",
|
|
88
|
+
"read from their .d.ts files. Nothing you depend on is imported or executed. The libraries",
|
|
89
|
+
'come from the manifest\'s "documents", or from the docspack key when the manifest has none.',
|
|
90
|
+
"Exits 1 when anything was reported.",
|
|
91
|
+
],
|
|
92
|
+
examples: ["docspack verify", "docspack verify --json"],
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "feedback",
|
|
96
|
+
summary: "Record documentation problems: add, list, submit, remove",
|
|
97
|
+
group: "core",
|
|
98
|
+
usage: "docspack feedback <add|list|submit|remove> [options]",
|
|
99
|
+
options: [
|
|
100
|
+
["--chunk <id>", "add: the chunk the problem is in"],
|
|
101
|
+
["--kind <k>", "add: drift, incorrect or missing"],
|
|
102
|
+
["--evidence <text>", "add: the claim, in one line"],
|
|
103
|
+
["--expected <text>", "add: what the documentation led you to expect"],
|
|
104
|
+
["--actual <text>", "add: what happened instead"],
|
|
105
|
+
["--repro <code>", "add: code that demonstrates it"],
|
|
106
|
+
["-p, --package <s>", "submit: only findings from packages matching this text"],
|
|
107
|
+
["--all", "remove: every recorded finding"],
|
|
108
|
+
],
|
|
109
|
+
detail: [
|
|
110
|
+
"Writes to .docspack/feedback.jsonl in this project. Nothing is transmitted: docspack",
|
|
111
|
+
"contains no code that can send a report anywhere.",
|
|
112
|
+
"",
|
|
113
|
+
"`drift` must name the identifier that drifted. `incorrect` and `missing` must carry",
|
|
114
|
+
"--expected, --actual and --repro, so a claim that cannot show its work cannot be",
|
|
115
|
+
"recorded. `submit` prints a prefilled GitHub issue URL for a human to open and file.",
|
|
116
|
+
],
|
|
117
|
+
examples: [
|
|
118
|
+
'docspack feedback add --chunk @acme/docspack@1.4.0/api-auth --kind drift --evidence "client.setKey is not exported; setApiKey is"',
|
|
119
|
+
"docspack feedback list",
|
|
120
|
+
"docspack feedback submit",
|
|
121
|
+
"docspack feedback remove <fingerprint>",
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "mcp",
|
|
126
|
+
summary: "Serve the index over MCP instead, as a long-lived process",
|
|
127
|
+
group: "core",
|
|
128
|
+
usage: "docspack mcp",
|
|
129
|
+
options: [],
|
|
130
|
+
detail: [
|
|
131
|
+
"Serves the same index over the Model Context Protocol, for clients that prefer a tool",
|
|
132
|
+
"definition to a shell command. `query_local_docs` returns exactly what `ask` prints.",
|
|
133
|
+
"stdout is the protocol channel, so nothing else is written to it.",
|
|
134
|
+
],
|
|
135
|
+
examples: ["docspack mcp"],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "sources",
|
|
139
|
+
summary: "List curated sources that `docspack build` can fetch",
|
|
140
|
+
group: "core",
|
|
141
|
+
usage: "docspack sources",
|
|
142
|
+
options: [],
|
|
143
|
+
examples: ["docspack sources", "docspack build hono --name @docspack-community/hono"],
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: "init",
|
|
147
|
+
summary: "Scaffold a documentation package, then build and check it",
|
|
148
|
+
group: "authoring",
|
|
149
|
+
usage: "docspack init [name] [options]",
|
|
150
|
+
options: [
|
|
151
|
+
["-y, --yes", "skip the prompts and use flags plus detected defaults"],
|
|
152
|
+
["--dry-run", "print the file tree and write nothing"],
|
|
153
|
+
["--mirror <id|url>", "bootstrap from a published llms.txt"],
|
|
154
|
+
["--community", "scaffold under @docspack-community"],
|
|
155
|
+
["--template <t>", "full (default) or minimal"],
|
|
156
|
+
["--mode <m>", "standalone or in-repo"],
|
|
157
|
+
["--no-workflow", "skip the release workflow"],
|
|
158
|
+
["--no-build", "scaffold only"],
|
|
159
|
+
["--name <name>", "package name, e.g. @acme/docspack"],
|
|
160
|
+
["--pkg-version <v>", "package version"],
|
|
161
|
+
["--from <dir>", "directory of Markdown to package"],
|
|
162
|
+
["--openapi <file>", "OpenAPI JSON to package"],
|
|
163
|
+
["--out <dir>", "where to scaffold (default: ./docspack)"],
|
|
164
|
+
["--force", "overwrite files that already exist"],
|
|
165
|
+
],
|
|
166
|
+
detail: [
|
|
167
|
+
"Reads the surrounding project first — name, version, a docs directory, an OpenAPI",
|
|
168
|
+
"document, the git remote, the license — and proposes a package built from what it found.",
|
|
169
|
+
],
|
|
170
|
+
examples: [
|
|
171
|
+
"docspack init",
|
|
172
|
+
"docspack init --name @acme/docspack --from ./docs --yes",
|
|
173
|
+
"docspack init --mirror hono --community --yes",
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: "build",
|
|
178
|
+
summary: "Generate the .llms/ payload for publishing",
|
|
179
|
+
group: "authoring",
|
|
180
|
+
usage: "docspack build [source] [options]",
|
|
181
|
+
options: [
|
|
182
|
+
["--from <dir>", "directory of Markdown to package"],
|
|
183
|
+
["--openapi <file>", "OpenAPI JSON to package, one chunk per operation"],
|
|
184
|
+
["--name <name>", "package name, e.g. @acme/docspack"],
|
|
185
|
+
["--pkg-version <v>", "package version"],
|
|
186
|
+
["--out <dir>", "output directory (default: the current directory)"],
|
|
187
|
+
["--pages <n>", "maximum documents to fetch from a remote source"],
|
|
188
|
+
["--max-chunk-tokens <n>", "split a section above this size (default 800)"],
|
|
189
|
+
["--min-chunk-tokens <n>", "pack adjacent sections up to this size before splitting"],
|
|
190
|
+
["--documents <p>", "library this package documents, repeatable: acme@1.4.0"],
|
|
191
|
+
],
|
|
192
|
+
detail: [
|
|
193
|
+
"Splits each document at ## headings, then ###, then paragraphs, until every chunk fits",
|
|
194
|
+
"the budget. --min-chunk-tokens packs the other way first, merging adjacent sections up to",
|
|
195
|
+
"the budget: use it for generated reference, where a heading is a field name and one chunk",
|
|
196
|
+
"per heading is hundreds of chunks too small to answer anything.",
|
|
197
|
+
"",
|
|
198
|
+
"With no flags, settings are read from the docspack key of the package.json in --out.",
|
|
199
|
+
],
|
|
200
|
+
examples: [
|
|
201
|
+
"docspack build",
|
|
202
|
+
"docspack build --from ./docs --name @acme/docspack --pkg-version 1.4.0",
|
|
203
|
+
"docspack build --from ./reference --min-chunk-tokens 400 --max-chunk-tokens 900",
|
|
204
|
+
"docspack build --openapi ./openapi.json",
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: "doctor",
|
|
209
|
+
summary: "Check a package the way the indexer and a reviewer would",
|
|
210
|
+
group: "authoring",
|
|
211
|
+
usage: "docspack doctor [options]",
|
|
212
|
+
options: [
|
|
213
|
+
["--strict", "treat structural warnings as failures"],
|
|
214
|
+
["--pedantic", "--strict, and fail on prose style as well"],
|
|
215
|
+
["--package-dir <d>", "the package to inspect (default: .)"],
|
|
216
|
+
],
|
|
217
|
+
detail: [
|
|
218
|
+
"Errors are packages that will not index. Warnings are packages that will index and",
|
|
219
|
+
"retrieve badly. Prose style is a note unless --pedantic, because writing by hand is not a",
|
|
220
|
+
"reason to block a first publish. Exits 1 when the package is not ready to publish.",
|
|
221
|
+
],
|
|
222
|
+
examples: ["docspack doctor", "docspack doctor --strict", "docspack doctor --json"],
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: "preview",
|
|
226
|
+
summary: "Answer a query from the local package, as an agent would",
|
|
227
|
+
group: "authoring",
|
|
228
|
+
usage: "docspack preview <query> [options]",
|
|
229
|
+
options: [
|
|
230
|
+
["--package-dir <d>", "the package to read (default: .)"],
|
|
231
|
+
["--limit <n>", `maximum chunks to return (default ${LIMIT})`],
|
|
232
|
+
["--max-tokens <n>", `token ceiling for the result set (default ${MAX_TOKENS})`],
|
|
233
|
+
],
|
|
234
|
+
detail: [
|
|
235
|
+
"Indexes the package in memory and answers through the same ranking and token budget an",
|
|
236
|
+
"agent gets. Nothing is published, installed, or written to the global store.",
|
|
237
|
+
],
|
|
238
|
+
examples: ['docspack preview "how do I authenticate"'],
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: "eval",
|
|
242
|
+
summary: "Measure retrieval against a set of questions",
|
|
243
|
+
group: "authoring",
|
|
244
|
+
usage: "docspack eval <queries.json> [options]",
|
|
245
|
+
options: [
|
|
246
|
+
["--package-dir <d>", "the package to read (default: .)"],
|
|
247
|
+
["--limit <n>", `chunks per answer, the window a hit must fall in (default ${LIMIT})`],
|
|
248
|
+
["--max-tokens <n>", `token ceiling for each answer (default ${MAX_TOKENS})`],
|
|
249
|
+
["--min-hit-rate <n>", "exit 1 below this percentage of questions answered"],
|
|
250
|
+
],
|
|
251
|
+
detail: [
|
|
252
|
+
"The evaluation set is a JSON array of questions and the chunk ids that would answer them:",
|
|
253
|
+
"",
|
|
254
|
+
' [{ "query": "how do I verify a webhook signature", "expect": "webhooks-signing" },',
|
|
255
|
+
' { "query": "rate limits", "expect": ["rate-limits", "errors"] }]',
|
|
256
|
+
"",
|
|
257
|
+
"Reports hit rate, top-1 rate and mean answer size — the numbers that settle the chunk",
|
|
258
|
+
"budget, which no structural check can see. With --min-hit-rate it gates a publish on",
|
|
259
|
+
"retrieval quality the way `doctor --strict` gates it on structure.",
|
|
260
|
+
],
|
|
261
|
+
examples: [
|
|
262
|
+
"docspack eval ./eval/queries.json",
|
|
263
|
+
"docspack eval ./eval/queries.json --min-hit-rate 90",
|
|
264
|
+
"docspack eval ./eval/queries.json --limit 1 --json",
|
|
265
|
+
],
|
|
266
|
+
},
|
|
267
|
+
];
|
|
268
|
+
|
|
269
|
+
const GLOBAL_OPTIONS: readonly (readonly [string, string])[] = [
|
|
270
|
+
["--store <path>", "Use a different index"],
|
|
271
|
+
["--cwd <dir>", "Run in a different directory"],
|
|
272
|
+
["--json", "Machine-readable output"],
|
|
273
|
+
["-q, --quiet", "Only print errors"],
|
|
274
|
+
["-h, --help", "Show this help, or a command's help"],
|
|
275
|
+
["-v, --version", "Show the version"],
|
|
276
|
+
];
|
|
277
|
+
|
|
278
|
+
export function findCommandHelp(name: string): CommandHelp | undefined {
|
|
279
|
+
return COMMANDS.find((command) => command.name === name);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const WIDTH = 21;
|
|
283
|
+
|
|
284
|
+
function row([flag, description]: readonly [string, string]): string {
|
|
285
|
+
return ` ${flag.padEnd(WIDTH)} ${description}`;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** The page one command prints for `docspack <command> --help`. */
|
|
289
|
+
export function commandHelpText(command: CommandHelp): string {
|
|
290
|
+
const blocks: string[] = [
|
|
291
|
+
`docspack ${command.name} — ${command.summary}`,
|
|
292
|
+
"",
|
|
293
|
+
"Usage",
|
|
294
|
+
` ${command.usage}`,
|
|
295
|
+
];
|
|
296
|
+
|
|
297
|
+
if (command.detail !== undefined) {
|
|
298
|
+
blocks.push("", ...command.detail.map((line) => (line.length === 0 ? "" : ` ${line}`)));
|
|
299
|
+
}
|
|
300
|
+
if (command.options.length > 0) {
|
|
301
|
+
blocks.push("", "Options", ...command.options.map(row));
|
|
302
|
+
}
|
|
303
|
+
blocks.push(
|
|
304
|
+
"",
|
|
305
|
+
"Global options",
|
|
306
|
+
...GLOBAL_OPTIONS.map(row),
|
|
307
|
+
"",
|
|
308
|
+
"Examples",
|
|
309
|
+
...command.examples.map((example) => ` ${example}`),
|
|
310
|
+
"",
|
|
311
|
+
);
|
|
312
|
+
return blocks.join("\n");
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The global page. It lists the commands and the options that apply to all of them, and points
|
|
317
|
+
* at the per-command pages for the rest — one list of every flag of every command was what made
|
|
318
|
+
* the flags unfindable in the first place.
|
|
319
|
+
*/
|
|
320
|
+
export function globalHelpText(storePath: string, notIndexed: number, noMatch: number): string {
|
|
321
|
+
const group = (which: CommandHelp["group"]): string =>
|
|
322
|
+
COMMANDS.filter((command) => command.group === which)
|
|
323
|
+
.map((command) => row([command.name, command.summary]))
|
|
324
|
+
.join("\n");
|
|
325
|
+
|
|
326
|
+
return `docspack — local, version-locked documentation for AI agents
|
|
327
|
+
|
|
328
|
+
Usage
|
|
329
|
+
docspack <command> [options]
|
|
330
|
+
docspack <command> --help every flag that command takes
|
|
331
|
+
|
|
332
|
+
Commands
|
|
333
|
+
${group("core")}
|
|
334
|
+
|
|
335
|
+
Authoring
|
|
336
|
+
${group("authoring")}
|
|
337
|
+
|
|
338
|
+
How it works
|
|
339
|
+
Documentation ships as npm packages named @vendor/docspack or
|
|
340
|
+
@docspack-community/<name>. Add them to package.json, run \`docspack sync\`, and
|
|
341
|
+
every chunk is indexed into a shared SQLite database with FTS5. Agents query
|
|
342
|
+
that index locally: no network, no scraping, always the installed version.
|
|
343
|
+
|
|
344
|
+
Giving an agent access
|
|
345
|
+
Any agent with a shell can run \`docspack ask\`, so one line in AGENTS.md or
|
|
346
|
+
CLAUDE.md is the whole setup — no server, no per-agent configuration, and
|
|
347
|
+
nothing resident when nobody is asking:
|
|
348
|
+
|
|
349
|
+
${AGENTS_SNIPPET.map((line) => ` ${line}`).join("\n")}
|
|
350
|
+
|
|
351
|
+
Add the block below as well if you want the agent to record documentation
|
|
352
|
+
problems it runs into. It writes to a local file; nothing is sent:
|
|
353
|
+
|
|
354
|
+
${FEEDBACK_SNIPPET.map((line) => ` ${line}`).join("\n")}
|
|
355
|
+
|
|
356
|
+
\`docspack mcp\` serves the same index over the Model Context Protocol for
|
|
357
|
+
clients that prefer a tool definition. Both return identical text.
|
|
358
|
+
|
|
359
|
+
Global options
|
|
360
|
+
${GLOBAL_OPTIONS.map(row).join("\n")}
|
|
361
|
+
|
|
362
|
+
The default index is ${storePath}.
|
|
363
|
+
|
|
364
|
+
Exit codes
|
|
365
|
+
\`ask\` and \`search\` answer with an exit code a script can branch on:
|
|
366
|
+
|
|
367
|
+
0 chunks were returned
|
|
368
|
+
${notIndexed} nothing matched, and a docs package is installed but not indexed —
|
|
369
|
+
run \`docspack sync\`
|
|
370
|
+
${noMatch} nothing matched, and everything installed is already indexed
|
|
371
|
+
1 the command failed; 2 the command was used wrongly
|
|
372
|
+
|
|
373
|
+
Examples
|
|
374
|
+
npx docspack sync
|
|
375
|
+
npx docspack ask "how do I verify a webhook signature"
|
|
376
|
+
npx docspack init
|
|
377
|
+
npx docspack doctor --strict
|
|
378
|
+
npx docspack preview "how do I authenticate"
|
|
379
|
+
npx docspack eval ./eval/queries.json --min-hit-rate 90
|
|
380
|
+
npx docspack feedback submit
|
|
381
|
+
`;
|
|
382
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -32,6 +32,15 @@ export {
|
|
|
32
32
|
type Severity,
|
|
33
33
|
} from "./doctor.js";
|
|
34
34
|
export { DocspackError } from "./errors.js";
|
|
35
|
+
export {
|
|
36
|
+
type EvalCase,
|
|
37
|
+
type EvalCaseResult,
|
|
38
|
+
type EvalOptions,
|
|
39
|
+
type EvalReport,
|
|
40
|
+
evaluatePackage,
|
|
41
|
+
parseEvalSet,
|
|
42
|
+
readEvalSet,
|
|
43
|
+
} from "./eval.js";
|
|
35
44
|
export { type ExportSurface, readExportSurface } from "./exports.js";
|
|
36
45
|
export {
|
|
37
46
|
type AddOptions,
|
|
@@ -46,6 +55,13 @@ export {
|
|
|
46
55
|
readFeedback,
|
|
47
56
|
removeFindings,
|
|
48
57
|
} from "./feedback.js";
|
|
58
|
+
export {
|
|
59
|
+
COMMANDS,
|
|
60
|
+
type CommandHelp,
|
|
61
|
+
commandHelpText,
|
|
62
|
+
findCommandHelp,
|
|
63
|
+
globalHelpText,
|
|
64
|
+
} from "./help.js";
|
|
49
65
|
export { type FetchLike, HttpClient } from "./http.js";
|
|
50
66
|
export { type Detected, detectProject, type PackageManager } from "./init/detect.js";
|
|
51
67
|
export {
|
|
@@ -92,7 +108,9 @@ export {
|
|
|
92
108
|
CHUNKS_DIR,
|
|
93
109
|
type ChunkSpec,
|
|
94
110
|
chunkId,
|
|
111
|
+
type DocumentedLibrary,
|
|
95
112
|
estimateTokens,
|
|
113
|
+
formatDocumentedLibrary,
|
|
96
114
|
isCommunityPackage,
|
|
97
115
|
isDocsPackage,
|
|
98
116
|
isVendorPackage,
|
|
@@ -100,12 +118,14 @@ export {
|
|
|
100
118
|
MANIFEST_FILE,
|
|
101
119
|
type PackageManifest,
|
|
102
120
|
packageId,
|
|
121
|
+
parseDocumentedLibrary,
|
|
103
122
|
parseManifest,
|
|
104
123
|
resolveChunkFile,
|
|
105
124
|
SCHEMA_URL,
|
|
106
125
|
SPEC_URL,
|
|
107
126
|
serializeManifest,
|
|
108
127
|
} from "./spec.js";
|
|
128
|
+
export { STOPWORDS } from "./stopwords.js";
|
|
109
129
|
export {
|
|
110
130
|
type BlockedFinding,
|
|
111
131
|
type BlockedReason,
|
package/src/preview.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { DEFAULT_LIMIT, DEFAULT_MAX_TOKENS, type QueryHit } from "./search.js";
|
|
|
6
6
|
import {
|
|
7
7
|
chunkId,
|
|
8
8
|
estimateTokens,
|
|
9
|
+
formatDocumentedLibrary,
|
|
9
10
|
isCommunityPackage,
|
|
10
11
|
LLMS_DIR,
|
|
11
12
|
MANIFEST_FILE,
|
|
@@ -45,6 +46,7 @@ export async function previewPackage(options: PreviewOptions): Promise<PreviewRe
|
|
|
45
46
|
|
|
46
47
|
const manifest = parseManifest(JSON.parse(raw), `${LLMS_DIR}/${MANIFEST_FILE}`);
|
|
47
48
|
const id = packageId(manifest.name, manifest.version);
|
|
49
|
+
const documents = (manifest.documents ?? []).map(formatDocumentedLibrary);
|
|
48
50
|
|
|
49
51
|
const chunks: IndexedChunk[] = [];
|
|
50
52
|
for (const chunk of manifest.chunks) {
|
|
@@ -58,7 +60,7 @@ export async function previewPackage(options: PreviewOptions): Promise<PreviewRe
|
|
|
58
60
|
chunks.push({
|
|
59
61
|
chunkId: chunkId(id, chunk.id),
|
|
60
62
|
filePath: chunk.file,
|
|
61
|
-
tokens: chunk.tokens
|
|
63
|
+
tokens: chunk.tokens ?? estimateTokens(contents),
|
|
62
64
|
content: contents,
|
|
63
65
|
tags: [...chunk.tags, ...chunk.entities],
|
|
64
66
|
});
|
|
@@ -84,6 +86,7 @@ export async function previewPackage(options: PreviewOptions): Promise<PreviewRe
|
|
|
84
86
|
name: manifest.name,
|
|
85
87
|
version: manifest.version,
|
|
86
88
|
trusted: !isCommunityPackage(manifest.name),
|
|
89
|
+
...(documents.length === 0 ? {} : { documents }),
|
|
87
90
|
}),
|
|
88
91
|
);
|
|
89
92
|
|
package/src/search.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SearchHit, Store } from "./db.js";
|
|
2
2
|
import { discoverPackages } from "./discovery.js";
|
|
3
|
-
import { isCommunityPackage } from "./spec.js";
|
|
3
|
+
import { formatDocumentedLibrary, isCommunityPackage } from "./spec.js";
|
|
4
4
|
|
|
5
5
|
/** Ceiling on how much context one query may return, per the blueprint's context-exhaustion rule. */
|
|
6
6
|
export const DEFAULT_MAX_TOKENS = 3000;
|
|
@@ -25,6 +25,12 @@ export interface QueryHit extends SearchHit {
|
|
|
25
25
|
readonly name: string;
|
|
26
26
|
readonly version: string;
|
|
27
27
|
readonly trusted: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Libraries the package documents, from its manifest. A docs package version cannot always
|
|
30
|
+
* imply this — a monorepo documents many libraries at many versions from one surface — so the
|
|
31
|
+
* answer states it rather than leaving the reader to infer it from the package name.
|
|
32
|
+
*/
|
|
33
|
+
readonly documents?: readonly string[];
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
export interface QueryResult {
|
|
@@ -48,6 +54,16 @@ export async function queryDocs(options: QueryOptions): Promise<QueryResult> {
|
|
|
48
54
|
.filter((pkg) => !options.store.hasPackage(pkg.id))
|
|
49
55
|
.map((pkg) => pkg.id);
|
|
50
56
|
|
|
57
|
+
// Read from the installed manifests rather than the index: the store is a cache of chunk text,
|
|
58
|
+
// and adding a column to it would make every existing store need a rebuild to answer this.
|
|
59
|
+
const documented = new Map<string, readonly string[]>();
|
|
60
|
+
for (const pkg of installed ?? []) {
|
|
61
|
+
const documents = pkg.manifest.documents;
|
|
62
|
+
if (documents !== undefined && documents.length > 0) {
|
|
63
|
+
documented.set(pkg.id, documents.map(formatDocumentedLibrary));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
51
67
|
const hits = options.store
|
|
52
68
|
.search(options.query, {
|
|
53
69
|
...(packageIds === undefined ? {} : { packageIds }),
|
|
@@ -59,7 +75,14 @@ export async function queryDocs(options: QueryOptions): Promise<QueryResult> {
|
|
|
59
75
|
})
|
|
60
76
|
.map((hit): QueryHit => {
|
|
61
77
|
const { name, version } = splitPackageId(hit.packageId);
|
|
62
|
-
|
|
78
|
+
const documents = documented.get(hit.packageId);
|
|
79
|
+
return {
|
|
80
|
+
...hit,
|
|
81
|
+
name,
|
|
82
|
+
version,
|
|
83
|
+
trusted: !isCommunityPackage(name),
|
|
84
|
+
...(documents === undefined ? {} : { documents }),
|
|
85
|
+
};
|
|
63
86
|
});
|
|
64
87
|
|
|
65
88
|
return {
|
|
@@ -90,9 +113,16 @@ export function renderAnswer(result: QueryResult, query: string): string {
|
|
|
90
113
|
|
|
91
114
|
const sections = result.hits.map((hit) => {
|
|
92
115
|
const trust = hit.trusted ? "" : " (community)";
|
|
116
|
+
// Which release the chunk describes, on the line that already carries provenance. An agent
|
|
117
|
+
// otherwise has to assume the docs package version is the library version, which a
|
|
118
|
+
// repository publishing eighteen packages from one docs surface cannot make true.
|
|
119
|
+
const describes =
|
|
120
|
+
hit.documents === undefined || hit.documents.length === 0
|
|
121
|
+
? ""
|
|
122
|
+
: ` · documents ${hit.documents.join(", ")}`;
|
|
93
123
|
return [
|
|
94
124
|
`## ${hit.chunkId}${trust}`,
|
|
95
|
-
`Source: ${hit.name}@${hit.version} — ${hit.filePath}`,
|
|
125
|
+
`Source: ${hit.name}@${hit.version} — ${hit.filePath}${describes}`,
|
|
96
126
|
"",
|
|
97
127
|
hit.content,
|
|
98
128
|
].join("\n");
|
package/src/spec.ts
CHANGED
|
@@ -14,14 +14,27 @@ export interface ChunkSpec {
|
|
|
14
14
|
readonly id: string;
|
|
15
15
|
/** Path relative to the package's `.llms/` directory. */
|
|
16
16
|
readonly file: string;
|
|
17
|
-
|
|
17
|
+
/** Absent means "estimate it". Never 0: an empty chunk is a different problem. */
|
|
18
|
+
readonly tokens?: number;
|
|
18
19
|
readonly tags: readonly string[];
|
|
19
20
|
readonly entities: readonly string[];
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
/** A library release the package documents, e.g. `acme` at `1.4.0`. */
|
|
24
|
+
export interface DocumentedLibrary {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
/** A version or a range, as the author wrote it. Absent when the docs are not release-scoped. */
|
|
27
|
+
readonly version?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
export interface PackageManifest {
|
|
23
31
|
readonly name: string;
|
|
24
32
|
readonly version: string;
|
|
33
|
+
/**
|
|
34
|
+
* What the package documents, which the package's own version cannot always say: a monorepo
|
|
35
|
+
* publishes many libraries at many versions from one documentation surface.
|
|
36
|
+
*/
|
|
37
|
+
readonly documents?: readonly DocumentedLibrary[];
|
|
25
38
|
readonly chunks: readonly ChunkSpec[];
|
|
26
39
|
}
|
|
27
40
|
|
|
@@ -50,6 +63,21 @@ export function chunkId(pkgId: string, chunk: string): string {
|
|
|
50
63
|
return `${pkgId}/${chunk}`;
|
|
51
64
|
}
|
|
52
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Reads `acme`, `acme@1.4.0` or `@acme/sdk@^1.4.0` as a library and an optional version. The
|
|
68
|
+
* separator is the last `@`, since a scope puts one at the start of the name as well.
|
|
69
|
+
*/
|
|
70
|
+
export function parseDocumentedLibrary(spec: string): DocumentedLibrary {
|
|
71
|
+
const at = spec.lastIndexOf("@");
|
|
72
|
+
if (at <= 0) return { name: spec };
|
|
73
|
+
return { name: spec.slice(0, at), version: spec.slice(at + 1) };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** `acme@1.4.0`, or just the name when no version is scoped. The form an answer is labelled with. */
|
|
77
|
+
export function formatDocumentedLibrary(library: DocumentedLibrary): string {
|
|
78
|
+
return library.version === undefined ? library.name : `${library.name}@${library.version}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
53
81
|
/**
|
|
54
82
|
* Resolves a manifest `file` entry inside the package's `.llms/` directory, refusing anything
|
|
55
83
|
* that escapes it. Manifests are third-party input, so this is a security boundary, not a
|
|
@@ -88,6 +116,7 @@ export function parseManifest(raw: unknown, where: string): PackageManifest {
|
|
|
88
116
|
if (typeof version !== "string" || version.length === 0) fail('missing string field "version"');
|
|
89
117
|
if (!Array.isArray(root.chunks)) fail('missing "chunks" array');
|
|
90
118
|
|
|
119
|
+
const documents = parseDocuments(root.documents, fail);
|
|
91
120
|
const seen = new Set<string>();
|
|
92
121
|
const chunks = (root.chunks as unknown[]).map((entry, index): ChunkSpec => {
|
|
93
122
|
if (typeof entry !== "object" || entry === null)
|
|
@@ -106,21 +135,40 @@ export function parseManifest(raw: unknown, where: string): PackageManifest {
|
|
|
106
135
|
return fail(`chunk "${id}" is missing its "file"`);
|
|
107
136
|
}
|
|
108
137
|
|
|
138
|
+
// 0 is refused rather than read as "estimate it": the schema accepts it as a deliberate
|
|
139
|
+
// count, the reader would treat it as absent, and no chunk is genuinely 0 tokens.
|
|
109
140
|
const tokens = chunk.tokens;
|
|
110
|
-
if (tokens !== undefined && (!Number.isInteger(tokens) || (tokens as number) <
|
|
111
|
-
return fail(`chunk "${id}" has an invalid "tokens" value`);
|
|
141
|
+
if (tokens !== undefined && (!Number.isInteger(tokens) || (tokens as number) < 1)) {
|
|
142
|
+
return fail(`chunk "${id}" has an invalid "tokens" value; omit it to have it estimated`);
|
|
112
143
|
}
|
|
113
144
|
|
|
114
145
|
return {
|
|
115
146
|
id,
|
|
116
147
|
file,
|
|
117
|
-
|
|
148
|
+
...(typeof tokens === "number" ? { tokens } : {}),
|
|
118
149
|
tags: stringArray(chunk.tags, `chunk "${id}" field "tags"`, fail),
|
|
119
150
|
entities: stringArray(chunk.entities, `chunk "${id}" field "entities"`, fail),
|
|
120
151
|
};
|
|
121
152
|
});
|
|
122
153
|
|
|
123
|
-
return { name, version, chunks };
|
|
154
|
+
return { name, version, ...(documents === undefined ? {} : { documents }), chunks };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* `["acme@1.4.0", "@acme/sdk@^2"]`. An array even for one library, because that is what the
|
|
159
|
+
* schema declares — a reader that accepts a shape the validator rejects is the same defect as a
|
|
160
|
+
* validator that accepts a value the reader reinterprets.
|
|
161
|
+
*/
|
|
162
|
+
function parseDocuments(
|
|
163
|
+
value: unknown,
|
|
164
|
+
fail: (message: string) => never,
|
|
165
|
+
): readonly DocumentedLibrary[] | undefined {
|
|
166
|
+
if (value === undefined) return undefined;
|
|
167
|
+
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || entry === "")) {
|
|
168
|
+
fail('"documents" must be an array of package names, optionally with a version');
|
|
169
|
+
}
|
|
170
|
+
const specs = value as string[];
|
|
171
|
+
return specs.length === 0 ? undefined : specs.map(parseDocumentedLibrary);
|
|
124
172
|
}
|
|
125
173
|
|
|
126
174
|
function stringArray(
|
|
@@ -135,6 +183,18 @@ function stringArray(
|
|
|
135
183
|
return value as string[];
|
|
136
184
|
}
|
|
137
185
|
|
|
186
|
+
/** Writes the manifest, with `documents` back in the string form the schema declares. */
|
|
138
187
|
export function serializeManifest(manifest: PackageManifest): string {
|
|
139
|
-
|
|
188
|
+
const documents = manifest.documents ?? [];
|
|
189
|
+
return `${JSON.stringify(
|
|
190
|
+
{
|
|
191
|
+
$schema: SCHEMA_URL,
|
|
192
|
+
name: manifest.name,
|
|
193
|
+
version: manifest.version,
|
|
194
|
+
...(documents.length === 0 ? {} : { documents: documents.map(formatDocumentedLibrary) }),
|
|
195
|
+
chunks: manifest.chunks,
|
|
196
|
+
},
|
|
197
|
+
null,
|
|
198
|
+
2,
|
|
199
|
+
)}\n`;
|
|
140
200
|
}
|