foldkit-plus 0.17.0 → 0.18.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 +155 -28
- package/dist/cli.mjs +10389 -35
- package/dist/cli.mjs.map +1 -1
- package/dist/docs.d.mts +89 -0
- package/dist/docs.d.mts.map +1 -0
- package/dist/docs.mjs +290 -0
- package/dist/docs.mjs.map +1 -0
- package/dist/project.d.mts +45 -0
- package/dist/project.d.mts.map +1 -0
- package/dist/project.mjs +205 -0
- package/dist/project.mjs.map +1 -0
- package/dist/remote/testing.d.mts +1 -0
- package/dist/remote/testing.mjs +2 -0
- package/dist/setup.d.mts +35 -7
- package/dist/setup.d.mts.map +1 -1
- package/dist/setup.mjs +148 -24
- package/dist/setup.mjs.map +1 -1
- package/dist/testing/peer.d.mts +8 -0
- package/dist/testing/peer.d.mts.map +1 -0
- package/dist/testing/peer.mjs +19 -0
- package/dist/testing/peer.mjs.map +1 -0
- package/dist/testing/playwright.d.mts +49 -0
- package/dist/testing/playwright.d.mts.map +1 -0
- package/dist/testing/playwright.mjs +171 -0
- package/dist/testing/playwright.mjs.map +1 -0
- package/dist/testing/workers.d.mts +103 -0
- package/dist/testing/workers.d.mts.map +1 -0
- package/dist/testing/workers.mjs +320 -0
- package/dist/testing/workers.mjs.map +1 -0
- package/package.json +89 -58
package/dist/docs.d.mts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Option } from "effect";
|
|
2
|
+
/** One Markdown document as it is installed. */
|
|
3
|
+
export interface Doc {
|
|
4
|
+
/** What `--list` takes: a package's name without `foldkit-`, or a skill file's name. */
|
|
5
|
+
readonly topic: string;
|
|
6
|
+
/** Where it comes from and at which version: `foldkit-remote@0.18.1 README.md`. */
|
|
7
|
+
readonly label: string;
|
|
8
|
+
readonly path: string;
|
|
9
|
+
readonly text: string;
|
|
10
|
+
}
|
|
11
|
+
/** One heading and the text under it, up to the next heading of any depth. */
|
|
12
|
+
export interface Section {
|
|
13
|
+
readonly doc: Doc;
|
|
14
|
+
/** The heading and those it sits under, outermost first. */
|
|
15
|
+
readonly headings: ReadonlyArray<string>;
|
|
16
|
+
readonly depth: number;
|
|
17
|
+
/** The heading's line, from 1. */
|
|
18
|
+
readonly line: number;
|
|
19
|
+
/** GitHub's anchor for the heading. */
|
|
20
|
+
readonly anchor: string;
|
|
21
|
+
readonly body: ReadonlyArray<string>;
|
|
22
|
+
}
|
|
23
|
+
/** A declaration in a `.d.mts`: its doc comment and its signature. */
|
|
24
|
+
export interface Declaration {
|
|
25
|
+
/** The installed package's topic, as its README's. */
|
|
26
|
+
readonly topic: string;
|
|
27
|
+
/** `foldkit-remote@0.18.1`. */
|
|
28
|
+
readonly origin: string;
|
|
29
|
+
readonly path: string;
|
|
30
|
+
readonly line: number;
|
|
31
|
+
readonly comment: ReadonlyArray<string>;
|
|
32
|
+
readonly signature: ReadonlyArray<string>;
|
|
33
|
+
}
|
|
34
|
+
/** A document's sections in order. Text above its first heading belongs to none. */
|
|
35
|
+
export declare const sectionsOf: (doc: Doc) => ReadonlyArray<Section>;
|
|
36
|
+
/** Whether a query names a symbol (`Data.preload`, `RemoteData`) rather than a topic. */
|
|
37
|
+
export declare const isSymbol: (query: string) => boolean;
|
|
38
|
+
export interface Ranked {
|
|
39
|
+
readonly section: Section;
|
|
40
|
+
readonly score: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sections by BM25 over their words, a heading's words counted three times,
|
|
44
|
+
* plus a bonus where the whole query appears as written (a symbol in code,
|
|
45
|
+
* a phrase in a heading). Sections that share no word with the query are
|
|
46
|
+
* left out; ties keep document order.
|
|
47
|
+
*/
|
|
48
|
+
export declare const rank: (sections: ReadonlyArray<Section>, query: string) => ReadonlyArray<Ranked>;
|
|
49
|
+
/**
|
|
50
|
+
* What `symbol` declares in one `.d.mts`. `Remote` gives its declaration, and
|
|
51
|
+
* an object or interface as the names of its members, which is what answers
|
|
52
|
+
* "does it have X?". `Remote.make` gives that member of `Remote`. When the
|
|
53
|
+
* qualifier is declared nowhere (`Data`, a value an application makes), every
|
|
54
|
+
* member called `preload` is a candidate: the caller ranks them by document.
|
|
55
|
+
*/
|
|
56
|
+
export declare const declarationsIn: (file: {
|
|
57
|
+
readonly topic: string;
|
|
58
|
+
readonly origin: string;
|
|
59
|
+
readonly path: string;
|
|
60
|
+
readonly text: string;
|
|
61
|
+
}, symbol: string) => ReadonlyArray<Declaration>;
|
|
62
|
+
export interface Answer {
|
|
63
|
+
readonly query: string;
|
|
64
|
+
readonly declarations: ReadonlyArray<Declaration>;
|
|
65
|
+
readonly sections: ReadonlyArray<Ranked>;
|
|
66
|
+
/** How many documents were searched, for an answer that found nothing. */
|
|
67
|
+
readonly searched: number;
|
|
68
|
+
}
|
|
69
|
+
export declare const RESULTS = 3;
|
|
70
|
+
/**
|
|
71
|
+
* The answer to `docs <query>`: the best sections, and a symbol's
|
|
72
|
+
* declarations, those of the package whose section ranks highest first.
|
|
73
|
+
*/
|
|
74
|
+
export declare const answer: (docs: ReadonlyArray<Doc>, query: string, declarations: (symbol: string) => ReadonlyArray<Declaration>) => Answer;
|
|
75
|
+
/** Whether the answer found anything: a query that did not is a failure to report. */
|
|
76
|
+
export declare const found: (result: Answer) => boolean;
|
|
77
|
+
/** The answer as Markdown, for an agent's context or a terminal. */
|
|
78
|
+
export declare const answerText: (result: Answer) => string;
|
|
79
|
+
/** The answer as JSON, for a program. */
|
|
80
|
+
export declare const answerJson: (result: Answer) => string;
|
|
81
|
+
/**
|
|
82
|
+
* `--list`: with no topic, every installed document; with one, the headings
|
|
83
|
+
* of each document on it as an outline. A topic nothing installed covers is
|
|
84
|
+
* `none`, for the caller to report with the topics there are.
|
|
85
|
+
*/
|
|
86
|
+
export declare const outlineText: (docs: ReadonlyArray<Doc>, topic: Option.Option<string>) => Option.Option<string>;
|
|
87
|
+
/** The topics there are, for a `--list` of one that is not. */
|
|
88
|
+
export declare const topicsOf: (docs: ReadonlyArray<Doc>) => string[];
|
|
89
|
+
//# sourceMappingURL=docs.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs.d.mts","names":[],"sources":["../src/docs.ts"],"mappings":";;iBASiB;;WAEN;;WAEA;WACA;WACA;;;iBAIM;WACN,KAAK;;WAEL,UAAU;WACV;;WAEA;;WAEA;WACA,MAAM;;;iBAIA;;WAEN;;WAEA;WACA;WACA;WACA,SAAS;WACT,WAAW;;;qBAcT,aAAU,KAAS,QAAM,cAAc;;qBAiEvC,WAAQ;iBAGJ;WACN,SAAS;WACT;;;;;;;;qBAWE,OAAI,UAAc,cAAc,UAAQ,kBAAkB,cAAc;;;;;;;;qBA4FxE,iBAAc;WAEd;WACA;WACA;WACA;GACV,mBAEA,cAAc;iBA2DA;WACN;WACA,cAAc,cAAc;WAC5B,UAAU,cAAc;;WAExB;;qBAGE;;;;;qBAOA,SAAM,MACX,cAAc,MAAI,eACX,eACE,mBAAmB,cAAc,iBAC/C;;qBAmBU,QAAK,QAAY;;qBAIjB,aAAU,QAAY;;qBAyBtB,aAAU,QAAY;;;;;;qBAwBtB,cAAW,MAAU,cAAc,MAAI,OAAS,OAAO,mBAAc,OAAA;;qBAoCrE,WAAQ,MAAU,cAAc"}
|
package/dist/docs.mjs
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { Option } from "effect";
|
|
2
|
+
// src/docs.ts
|
|
3
|
+
/**
|
|
4
|
+
* What `npx foldkit-plus docs` answers with: sections of the Markdown that the
|
|
5
|
+
* installed packages and skill ship, ranked against a query, and the
|
|
6
|
+
* declarations a symbol names in their `.d.mts`. Pure: `project.ts` reads the
|
|
7
|
+
* files and passes them in, so a test can give any documents.
|
|
8
|
+
*/
|
|
9
|
+
const HEADING = /^(#{1,6})\s+(.*?)\s*#*\s*$/;
|
|
10
|
+
const FENCE = /^\s*(`{3,}|~{3,})/;
|
|
11
|
+
/** GitHub's slug: lowercase, punctuation dropped, spaces to hyphens. */
|
|
12
|
+
const slug = (heading) => heading.toLowerCase().replace(/[^\p{L}\p{N} _-]/gu, "").replace(/ /g, "-");
|
|
13
|
+
/** A document's sections in order. Text above its first heading belongs to none. */
|
|
14
|
+
const sectionsOf = (doc) => {
|
|
15
|
+
const lines = doc.text.split(/\r?\n/);
|
|
16
|
+
const sections = [];
|
|
17
|
+
const open = [];
|
|
18
|
+
const anchors = /* @__PURE__ */ new Map();
|
|
19
|
+
let fence = "";
|
|
20
|
+
let body = [];
|
|
21
|
+
lines.forEach((text, index) => {
|
|
22
|
+
const marker = FENCE.exec(text)?.[1];
|
|
23
|
+
if (marker !== void 0 && (fence === "" || marker[0] === fence[0] && marker.length >= fence.length)) fence = fence === "" ? marker : "";
|
|
24
|
+
const heading = fence === "" ? HEADING.exec(text) : null;
|
|
25
|
+
if (heading === null || marker !== void 0) {
|
|
26
|
+
body.push(text);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const depth = heading[1].length;
|
|
30
|
+
const title = heading[2];
|
|
31
|
+
while (open.length > 0 && open[open.length - 1].depth >= depth) open.pop();
|
|
32
|
+
open.push({
|
|
33
|
+
depth,
|
|
34
|
+
heading: title
|
|
35
|
+
});
|
|
36
|
+
const base = slug(title);
|
|
37
|
+
const seen = anchors.get(base) ?? 0;
|
|
38
|
+
anchors.set(base, seen + 1);
|
|
39
|
+
body = [];
|
|
40
|
+
sections.push({
|
|
41
|
+
doc,
|
|
42
|
+
headings: open.map((each) => each.heading),
|
|
43
|
+
depth,
|
|
44
|
+
line: index + 1,
|
|
45
|
+
anchor: seen === 0 ? base : `${base}-${seen}`,
|
|
46
|
+
body
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
return sections.map((section) => ({
|
|
50
|
+
...section,
|
|
51
|
+
body: trimBlank(section.body)
|
|
52
|
+
}));
|
|
53
|
+
};
|
|
54
|
+
const trimBlank = (lines) => {
|
|
55
|
+
let start = 0;
|
|
56
|
+
let end = lines.length;
|
|
57
|
+
while (start < end && lines[start].trim() === "") start++;
|
|
58
|
+
while (end > start && lines[end - 1].trim() === "") end--;
|
|
59
|
+
return lines.slice(start, end);
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* A word as the ranking compares it: lowercase, with a plural, tense or `-ly`
|
|
63
|
+
* ending dropped, so `deletes`, `deleted` and `delete` meet. Deliberately
|
|
64
|
+
* small: it is only a key two words are compared by, never shown.
|
|
65
|
+
*/
|
|
66
|
+
const stem = (word) => {
|
|
67
|
+
const ending = /(?:ing|ed|es|ly|s|e)$/.exec(word);
|
|
68
|
+
return ending !== null && word.length - ending[0].length >= 4 ? word.slice(0, -ending[0].length) : word;
|
|
69
|
+
};
|
|
70
|
+
const words = (text) => (text.toLowerCase().match(/[\p{L}\p{N}_$]+/gu) ?? []).map(stem);
|
|
71
|
+
/** Whether a query names a symbol (`Data.preload`, `RemoteData`) rather than a topic. */
|
|
72
|
+
const isSymbol = (query) => /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(query) && /[.A-Z]/.test(query);
|
|
73
|
+
const HEADING_WEIGHT = 3;
|
|
74
|
+
/**
|
|
75
|
+
* Sections by BM25 over their words, a heading's words counted three times,
|
|
76
|
+
* plus a bonus where the whole query appears as written (a symbol in code,
|
|
77
|
+
* a phrase in a heading). Sections that share no word with the query are
|
|
78
|
+
* left out; ties keep document order.
|
|
79
|
+
*/
|
|
80
|
+
const rank = (sections, query) => {
|
|
81
|
+
const terms = [...new Set(words(query))];
|
|
82
|
+
if (terms.length === 0) return [];
|
|
83
|
+
const counted = sections.map((section) => {
|
|
84
|
+
const counts = /* @__PURE__ */ new Map();
|
|
85
|
+
const add = (word, by) => counts.set(word, (counts.get(word) ?? 0) + by);
|
|
86
|
+
const heading = section.headings[section.headings.length - 1] ?? "";
|
|
87
|
+
words(heading).forEach((word) => add(word, HEADING_WEIGHT));
|
|
88
|
+
const body = words(section.body.join("\n"));
|
|
89
|
+
body.forEach((word) => add(word, 1));
|
|
90
|
+
return {
|
|
91
|
+
section,
|
|
92
|
+
counts,
|
|
93
|
+
length: body.length + HEADING_WEIGHT * words(heading).length
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
const average = counted.reduce((sum, each) => sum + each.length, 0) / Math.max(counted.length, 1);
|
|
97
|
+
const idf = new Map(terms.map((term) => {
|
|
98
|
+
const holding = counted.filter((each) => each.counts.has(term)).length;
|
|
99
|
+
return [term, Math.log(1 + (counted.length - holding + .5) / (holding + .5))];
|
|
100
|
+
}));
|
|
101
|
+
const phrase = query.trim().toLowerCase().replace(/\s+/g, " ");
|
|
102
|
+
const weight = terms.reduce((sum, term) => sum + idf.get(term), 0);
|
|
103
|
+
const k = 1.2;
|
|
104
|
+
const b = .75;
|
|
105
|
+
return counted.map(({ section, counts, length }) => {
|
|
106
|
+
const score = terms.reduce((sum, term) => {
|
|
107
|
+
const tf = counts.get(term) ?? 0;
|
|
108
|
+
return sum + idf.get(term) * tf * 2.2 / (tf + k * (.25 + b * length / average));
|
|
109
|
+
}, 0);
|
|
110
|
+
const bonus = (section.headings[section.headings.length - 1] ?? "").toLowerCase().includes(phrase) ? 2 * weight : section.body.join("\n").toLowerCase().replace(/\s+/g, " ").includes(phrase) ? weight : 0;
|
|
111
|
+
return {
|
|
112
|
+
section,
|
|
113
|
+
score: score === 0 ? 0 : score + bonus
|
|
114
|
+
};
|
|
115
|
+
}).filter((each) => each.score > 0).sort((x, y) => y.score - x.score);
|
|
116
|
+
};
|
|
117
|
+
const literal = (name) => name.replaceAll("$", "\\$");
|
|
118
|
+
const DECLARED = (name) => new RegExp(`^(?:export )?declare (?:abstract )?(?:const|let|function|class|interface|type|namespace|enum) ${literal(name)}(?:\\$\\d+)?\\b`);
|
|
119
|
+
const MEMBER = (name) => new RegExp(`^ (?:readonly |static )*${literal(name)}\\??\\s*[<(:]`);
|
|
120
|
+
const NAME = /^ (?:readonly |static )*([A-Za-z_$][\w$]*)\??\s*[<(:]/;
|
|
121
|
+
/** The doc comment that ends on the line above `at`, at `indent`. */
|
|
122
|
+
const commentAbove = (lines, at, indent) => {
|
|
123
|
+
const above = lines[at - 1]?.trim() ?? "";
|
|
124
|
+
if (above !== "*/" && !(above.startsWith("/**") && above.endsWith("*/"))) return [];
|
|
125
|
+
let start = at - 1;
|
|
126
|
+
while (start > 0 && !lines[start].trimStart().startsWith("/**")) start--;
|
|
127
|
+
return lines.slice(start, at).map((line) => line.slice(indent.length));
|
|
128
|
+
};
|
|
129
|
+
/** Lines from `at` until its brackets close on a `;` or `,`, at most `limit`. */
|
|
130
|
+
const statement = (lines, at, limit = 25) => {
|
|
131
|
+
const taken = [];
|
|
132
|
+
let depth = 0;
|
|
133
|
+
for (let index = at; index < lines.length && taken.length < limit; index++) {
|
|
134
|
+
const line = lines[index];
|
|
135
|
+
taken.push(line);
|
|
136
|
+
depth += (line.match(/[({[]/g) ?? []).length - (line.match(/[)}\]]/g) ?? []).length;
|
|
137
|
+
if (depth <= 0 && /[;,]\s*$/.test(line)) return taken;
|
|
138
|
+
}
|
|
139
|
+
return [...taken, " …"];
|
|
140
|
+
};
|
|
141
|
+
/** The block a top-level declaration opens, as its first line and its members' names. */
|
|
142
|
+
const outline = (lines, at) => {
|
|
143
|
+
const first = lines[at];
|
|
144
|
+
if (!/\{\s*$/.test(first)) return statement(lines, at);
|
|
145
|
+
const members = [];
|
|
146
|
+
for (let index = at + 1; index < lines.length && !/^\}/.test(lines[index]); index++) {
|
|
147
|
+
const name = NAME.exec(lines[index])?.[1];
|
|
148
|
+
if (name !== void 0 && !members.includes(name)) members.push(name);
|
|
149
|
+
}
|
|
150
|
+
return [
|
|
151
|
+
first,
|
|
152
|
+
` // members: ${members.join(", ")}`,
|
|
153
|
+
"}"
|
|
154
|
+
];
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* What `symbol` declares in one `.d.mts`. `Remote` gives its declaration, and
|
|
158
|
+
* an object or interface as the names of its members, which is what answers
|
|
159
|
+
* "does it have X?". `Remote.make` gives that member of `Remote`. When the
|
|
160
|
+
* qualifier is declared nowhere (`Data`, a value an application makes), every
|
|
161
|
+
* member called `preload` is a candidate: the caller ranks them by document.
|
|
162
|
+
*/
|
|
163
|
+
const declarationsIn = (file, symbol) => {
|
|
164
|
+
const lines = file.text.split(/\r?\n/);
|
|
165
|
+
const parts = symbol.split(".");
|
|
166
|
+
const last = parts[parts.length - 1];
|
|
167
|
+
const found = (line, indent, signature) => ({
|
|
168
|
+
topic: file.topic,
|
|
169
|
+
origin: file.origin,
|
|
170
|
+
path: file.path,
|
|
171
|
+
line: line + 1,
|
|
172
|
+
comment: commentAbove(lines, line, indent),
|
|
173
|
+
signature: signature.map((each) => each.slice(indent.length))
|
|
174
|
+
});
|
|
175
|
+
if (parts.length === 1) {
|
|
176
|
+
const declared = DECLARED(last);
|
|
177
|
+
return lines.flatMap((line, at) => declared.test(line) ? [found(at, "", outline(lines, at))] : []);
|
|
178
|
+
}
|
|
179
|
+
const owner = DECLARED(parts[parts.length - 2]);
|
|
180
|
+
const member = MEMBER(last);
|
|
181
|
+
const owners = lines.flatMap((line, at) => owner.test(line) ? [at] : []);
|
|
182
|
+
const inside = owners.flatMap((start) => {
|
|
183
|
+
const hits = [];
|
|
184
|
+
for (let at = start + 1; at < lines.length && !/^\}/.test(lines[at]); at++) if (member.test(lines[at])) hits.push(found(at, " ", statement(lines, at)));
|
|
185
|
+
return hits;
|
|
186
|
+
});
|
|
187
|
+
if (owners.length > 0) return inside;
|
|
188
|
+
return lines.flatMap((line, at) => member.test(line) ? [found(at, " ", statement(lines, at))] : []);
|
|
189
|
+
};
|
|
190
|
+
/** How a section is cited: where it is, so a reader can open the rest. */
|
|
191
|
+
const citation = (section) => `${section.doc.label} › ${section.headings.join(" › ")} (${section.doc.path}:${section.line}, #${section.anchor})`;
|
|
192
|
+
/** A section's text for a reader, its body cut at `lines` with where the rest is. */
|
|
193
|
+
const sectionText = (section, lines) => {
|
|
194
|
+
const shown = section.body.slice(0, lines);
|
|
195
|
+
const fences = shown.filter((line) => FENCE.test(line)).length;
|
|
196
|
+
return [
|
|
197
|
+
`## ${section.headings[section.headings.length - 1]}`,
|
|
198
|
+
"",
|
|
199
|
+
`From ${citation(section)}`,
|
|
200
|
+
"",
|
|
201
|
+
...shown,
|
|
202
|
+
...fences % 2 === 1 ? ["```"] : [],
|
|
203
|
+
...section.body.length > lines ? ["", `… ${section.body.length - lines} more lines at ${section.doc.path}:${section.line + lines + 1}`] : []
|
|
204
|
+
].join("\n");
|
|
205
|
+
};
|
|
206
|
+
const RESULTS = 3;
|
|
207
|
+
const BODY_LINES = 60;
|
|
208
|
+
/**
|
|
209
|
+
* The answer to `docs <query>`: the best sections, and a symbol's
|
|
210
|
+
* declarations, those of the package whose section ranks highest first.
|
|
211
|
+
*/
|
|
212
|
+
const answer = (docs, query, declarations) => {
|
|
213
|
+
const ranked = rank(docs.flatMap(sectionsOf), query);
|
|
214
|
+
const standing = (topic) => {
|
|
215
|
+
const at = ranked.findIndex((each) => each.section.doc.topic === topic);
|
|
216
|
+
return at === -1 ? ranked.length : at;
|
|
217
|
+
};
|
|
218
|
+
return {
|
|
219
|
+
query,
|
|
220
|
+
declarations: isSymbol(query) ? [...declarations(query)].sort((x, y) => standing(x.topic) - standing(y.topic)).slice(0, 3) : [],
|
|
221
|
+
sections: ranked.slice(0, 3),
|
|
222
|
+
searched: docs.length
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
/** Whether the answer found anything: a query that did not is a failure to report. */
|
|
226
|
+
const found = (result) => result.sections.length > 0 || result.declarations.length > 0;
|
|
227
|
+
/** The answer as Markdown, for an agent's context or a terminal. */
|
|
228
|
+
const answerText = (result) => found(result) ? [
|
|
229
|
+
`# ${result.query}`,
|
|
230
|
+
...result.declarations.length === 0 ? [] : [
|
|
231
|
+
"",
|
|
232
|
+
"## Declarations",
|
|
233
|
+
...result.declarations.flatMap((each) => [
|
|
234
|
+
"",
|
|
235
|
+
`From ${each.origin} (${each.path}:${each.line})`,
|
|
236
|
+
"",
|
|
237
|
+
"```ts",
|
|
238
|
+
...each.comment,
|
|
239
|
+
...each.signature,
|
|
240
|
+
"```"
|
|
241
|
+
])
|
|
242
|
+
],
|
|
243
|
+
...result.sections.flatMap((each) => ["", sectionText(each.section, BODY_LINES)]),
|
|
244
|
+
""
|
|
245
|
+
].join("\n") : `Nothing in the ${result.searched} installed documents matches "${result.query}". Try other words, or \`npx foldkit-plus docs --list\` for what is installed.\n`;
|
|
246
|
+
/** The answer as JSON, for a program. */
|
|
247
|
+
const answerJson = (result) => `${JSON.stringify({
|
|
248
|
+
query: result.query,
|
|
249
|
+
declarations: result.declarations,
|
|
250
|
+
sections: result.sections.map(({ section, score }) => ({
|
|
251
|
+
source: section.doc.label,
|
|
252
|
+
path: section.doc.path,
|
|
253
|
+
line: section.line,
|
|
254
|
+
anchor: section.anchor,
|
|
255
|
+
headings: section.headings,
|
|
256
|
+
score: Math.round(score * 100) / 100,
|
|
257
|
+
text: section.body.join("\n")
|
|
258
|
+
}))
|
|
259
|
+
}, null, 2)}\n`;
|
|
260
|
+
/**
|
|
261
|
+
* `--list`: with no topic, every installed document; with one, the headings
|
|
262
|
+
* of each document on it as an outline. A topic nothing installed covers is
|
|
263
|
+
* `none`, for the caller to report with the topics there are.
|
|
264
|
+
*/
|
|
265
|
+
const outlineText = (docs, topic) => Option.match(topic, {
|
|
266
|
+
onNone: () => Option.some([
|
|
267
|
+
"# Installed documents",
|
|
268
|
+
"",
|
|
269
|
+
...docs.map((doc) => `- \`${doc.topic}\`: ${doc.label} (${doc.path})`),
|
|
270
|
+
"",
|
|
271
|
+
"Outline one with `npx foldkit-plus docs --list <topic>`.",
|
|
272
|
+
""
|
|
273
|
+
].join("\n")),
|
|
274
|
+
onSome: (wanted) => {
|
|
275
|
+
const matching = docs.filter((doc) => doc.topic === wanted);
|
|
276
|
+
return matching.length === 0 ? Option.none() : Option.some(matching.flatMap((doc) => [
|
|
277
|
+
`# ${doc.label}`,
|
|
278
|
+
"",
|
|
279
|
+
doc.path,
|
|
280
|
+
"",
|
|
281
|
+
...sectionsOf(doc).map((section) => `${" ".repeat(section.depth - 1)}- ${section.headings[section.headings.length - 1]} (line ${section.line})`),
|
|
282
|
+
""
|
|
283
|
+
]).join("\n"));
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
/** The topics there are, for a `--list` of one that is not. */
|
|
287
|
+
const topicsOf = (docs) => [...new Set(docs.map((doc) => doc.topic))];
|
|
288
|
+
export { RESULTS, answer, answerJson, answerText, declarationsIn, found, isSymbol, outlineText, rank, sectionsOf, topicsOf };
|
|
289
|
+
|
|
290
|
+
//# sourceMappingURL=docs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs.mjs","names":[],"sources":["../src/docs.ts"],"sourcesContent":["/**\n * What `npx foldkit-plus docs` answers with: sections of the Markdown that the\n * installed packages and skill ship, ranked against a query, and the\n * declarations a symbol names in their `.d.mts`. Pure: `project.ts` reads the\n * files and passes them in, so a test can give any documents.\n */\nimport { Option } from 'effect'\n\n/** One Markdown document as it is installed. */\nexport interface Doc {\n /** What `--list` takes: a package's name without `foldkit-`, or a skill file's name. */\n readonly topic: string\n /** Where it comes from and at which version: `foldkit-remote@0.18.1 README.md`. */\n readonly label: string\n readonly path: string\n readonly text: string\n}\n\n/** One heading and the text under it, up to the next heading of any depth. */\nexport interface Section {\n readonly doc: Doc\n /** The heading and those it sits under, outermost first. */\n readonly headings: ReadonlyArray<string>\n readonly depth: number\n /** The heading's line, from 1. */\n readonly line: number\n /** GitHub's anchor for the heading. */\n readonly anchor: string\n readonly body: ReadonlyArray<string>\n}\n\n/** A declaration in a `.d.mts`: its doc comment and its signature. */\nexport interface Declaration {\n /** The installed package's topic, as its README's. */\n readonly topic: string\n /** `foldkit-remote@0.18.1`. */\n readonly origin: string\n readonly path: string\n readonly line: number\n readonly comment: ReadonlyArray<string>\n readonly signature: ReadonlyArray<string>\n}\n\nconst HEADING = /^(#{1,6})\\s+(.*?)\\s*#*\\s*$/\nconst FENCE = /^\\s*(`{3,}|~{3,})/\n\n/** GitHub's slug: lowercase, punctuation dropped, spaces to hyphens. */\nconst slug = (heading: string) =>\n heading\n .toLowerCase()\n .replace(/[^\\p{L}\\p{N} _-]/gu, '')\n .replace(/ /g, '-')\n\n/** A document's sections in order. Text above its first heading belongs to none. */\nexport const sectionsOf = (doc: Doc): ReadonlyArray<Section> => {\n const lines = doc.text.split(/\\r?\\n/)\n const sections: Array<Section> = []\n const open: Array<{ depth: number; heading: string }> = []\n const anchors = new Map<string, number>()\n let fence = ''\n let body: Array<string> = []\n lines.forEach((text, index) => {\n const marker = FENCE.exec(text)?.[1]\n // A fence closes on a marker of its own character at least as long as the opening.\n if (\n marker !== undefined &&\n (fence === '' || (marker[0] === fence[0] && marker.length >= fence.length))\n ) {\n fence = fence === '' ? marker : ''\n }\n const heading = fence === '' ? HEADING.exec(text) : null\n if (heading === null || marker !== undefined) {\n body.push(text)\n return\n }\n const depth = heading[1]!.length\n const title = heading[2]!\n while (open.length > 0 && open[open.length - 1]!.depth >= depth) open.pop()\n open.push({ depth, heading: title })\n const base = slug(title)\n const seen = anchors.get(base) ?? 0\n anchors.set(base, seen + 1)\n body = []\n sections.push({\n doc,\n headings: open.map(each => each.heading),\n depth,\n line: index + 1,\n anchor: seen === 0 ? base : `${base}-${seen}`,\n body,\n })\n })\n return sections.map(section => ({ ...section, body: trimBlank(section.body) }))\n}\n\nconst trimBlank = (lines: ReadonlyArray<string>) => {\n let start = 0\n let end = lines.length\n while (start < end && lines[start]!.trim() === '') start++\n while (end > start && lines[end - 1]!.trim() === '') end--\n return lines.slice(start, end)\n}\n\n/**\n * A word as the ranking compares it: lowercase, with a plural, tense or `-ly`\n * ending dropped, so `deletes`, `deleted` and `delete` meet. Deliberately\n * small: it is only a key two words are compared by, never shown.\n */\nconst stem = (word: string) => {\n const ending = /(?:ing|ed|es|ly|s|e)$/.exec(word)\n return ending !== null && word.length - ending[0].length >= 4\n ? word.slice(0, -ending[0].length)\n : word\n}\n\nconst words = (text: string): ReadonlyArray<string> =>\n (text.toLowerCase().match(/[\\p{L}\\p{N}_$]+/gu) ?? []).map(stem)\n\n/** Whether a query names a symbol (`Data.preload`, `RemoteData`) rather than a topic. */\nexport const isSymbol = (query: string) =>\n /^[A-Za-z_$][\\w$]*(?:\\.[A-Za-z_$][\\w$]*)*$/.test(query) && /[.A-Z]/.test(query)\n\nexport interface Ranked {\n readonly section: Section\n readonly score: number\n}\n\nconst HEADING_WEIGHT = 3\n\n/**\n * Sections by BM25 over their words, a heading's words counted three times,\n * plus a bonus where the whole query appears as written (a symbol in code,\n * a phrase in a heading). Sections that share no word with the query are\n * left out; ties keep document order.\n */\nexport const rank = (sections: ReadonlyArray<Section>, query: string): ReadonlyArray<Ranked> => {\n const terms = [...new Set(words(query))]\n if (terms.length === 0) return []\n const counted = sections.map(section => {\n const counts = new Map<string, number>()\n const add = (word: string, by: number) => counts.set(word, (counts.get(word) ?? 0) + by)\n const heading = section.headings[section.headings.length - 1] ?? ''\n words(heading).forEach(word => add(word, HEADING_WEIGHT))\n const body = words(section.body.join('\\n'))\n body.forEach(word => add(word, 1))\n return { section, counts, length: body.length + HEADING_WEIGHT * words(heading).length }\n })\n const average = counted.reduce((sum, each) => sum + each.length, 0) / Math.max(counted.length, 1)\n const idf = new Map(\n terms.map(term => {\n const holding = counted.filter(each => each.counts.has(term)).length\n return [term, Math.log(1 + (counted.length - holding + 0.5) / (holding + 0.5))] as const\n }),\n )\n const phrase = query.trim().toLowerCase().replace(/\\s+/g, ' ')\n const weight = terms.reduce((sum, term) => sum + idf.get(term)!, 0)\n const k = 1.2\n const b = 0.75\n return counted\n .map(({ section, counts, length }) => {\n const score = terms.reduce((sum, term) => {\n const tf = counts.get(term) ?? 0\n return sum + (idf.get(term)! * tf * (k + 1)) / (tf + k * (1 - b + (b * length) / average))\n }, 0)\n const heading = (section.headings[section.headings.length - 1] ?? '').toLowerCase()\n const bonus = heading.includes(phrase)\n ? 2 * weight\n : section.body.join('\\n').toLowerCase().replace(/\\s+/g, ' ').includes(phrase)\n ? weight\n : 0\n return { section, score: score === 0 ? 0 : score + bonus }\n })\n .filter(each => each.score > 0)\n .sort((x, y) => y.score - x.score)\n}\n\n// A name `isSymbol` passed holds no regex syntax but `$`.\nconst literal = (name: string) => name.replaceAll('$', '\\\\$')\nconst DECLARED = (name: string) =>\n new RegExp(\n `^(?:export )?declare (?:abstract )?(?:const|let|function|class|interface|type|namespace|enum) ${literal(name)}(?:\\\\$\\\\d+)?\\\\b`,\n )\nconst MEMBER = (name: string) =>\n new RegExp(`^ (?:readonly |static )*${literal(name)}\\\\??\\\\s*[<(:]`)\nconst NAME = /^ (?:readonly |static )*([A-Za-z_$][\\w$]*)\\??\\s*[<(:]/\n\n/** The doc comment that ends on the line above `at`, at `indent`. */\nconst commentAbove = (lines: ReadonlyArray<string>, at: number, indent: string) => {\n const above = lines[at - 1]?.trim() ?? ''\n if (above !== '*/' && !(above.startsWith('/**') && above.endsWith('*/'))) return []\n let start = at - 1\n while (start > 0 && !lines[start]!.trimStart().startsWith('/**')) start--\n return lines.slice(start, at).map(line => line.slice(indent.length))\n}\n\n/** Lines from `at` until its brackets close on a `;` or `,`, at most `limit`. */\nconst statement = (lines: ReadonlyArray<string>, at: number, limit = 25) => {\n const taken: Array<string> = []\n let depth = 0\n for (let index = at; index < lines.length && taken.length < limit; index++) {\n const line = lines[index]!\n taken.push(line)\n depth += (line.match(/[({[]/g) ?? []).length - (line.match(/[)}\\]]/g) ?? []).length\n if (depth <= 0 && /[;,]\\s*$/.test(line)) return taken\n }\n return [...taken, ' …']\n}\n\n/** The block a top-level declaration opens, as its first line and its members' names. */\nconst outline = (lines: ReadonlyArray<string>, at: number) => {\n const first = lines[at]!\n if (!/\\{\\s*$/.test(first)) return statement(lines, at)\n const members: Array<string> = []\n for (let index = at + 1; index < lines.length && !/^\\}/.test(lines[index]!); index++) {\n const name = NAME.exec(lines[index]!)?.[1]\n if (name !== undefined && !members.includes(name)) members.push(name)\n }\n return [first, ` // members: ${members.join(', ')}`, '}']\n}\n\n/**\n * What `symbol` declares in one `.d.mts`. `Remote` gives its declaration, and\n * an object or interface as the names of its members, which is what answers\n * \"does it have X?\". `Remote.make` gives that member of `Remote`. When the\n * qualifier is declared nowhere (`Data`, a value an application makes), every\n * member called `preload` is a candidate: the caller ranks them by document.\n */\nexport const declarationsIn = (\n file: {\n readonly topic: string\n readonly origin: string\n readonly path: string\n readonly text: string\n },\n symbol: string,\n): ReadonlyArray<Declaration> => {\n const lines = file.text.split(/\\r?\\n/)\n const parts = symbol.split('.')\n const last = parts[parts.length - 1]!\n const found = (line: number, indent: string, signature: ReadonlyArray<string>): Declaration => ({\n topic: file.topic,\n origin: file.origin,\n path: file.path,\n line: line + 1,\n comment: commentAbove(lines, line, indent),\n signature: signature.map(each => each.slice(indent.length)),\n })\n if (parts.length === 1) {\n const declared = DECLARED(last)\n return lines.flatMap((line, at) =>\n declared.test(line) ? [found(at, '', outline(lines, at))] : [],\n )\n }\n const owner = DECLARED(parts[parts.length - 2]!)\n const member = MEMBER(last)\n const owners = lines.flatMap((line, at) => (owner.test(line) ? [at] : []))\n const inside = owners.flatMap(start => {\n const hits: Array<Declaration> = []\n for (let at = start + 1; at < lines.length && !/^\\}/.test(lines[at]!); at++) {\n if (member.test(lines[at]!)) hits.push(found(at, ' ', statement(lines, at)))\n }\n return hits\n })\n if (owners.length > 0) return inside\n return lines.flatMap((line, at) =>\n member.test(line) ? [found(at, ' ', statement(lines, at))] : [],\n )\n}\n\n/** How a section is cited: where it is, so a reader can open the rest. */\nconst citation = (section: Section) =>\n `${section.doc.label} › ${section.headings.join(' › ')} (${section.doc.path}:${section.line}, #${section.anchor})`\n\n/** A section's text for a reader, its body cut at `lines` with where the rest is. */\nconst sectionText = (section: Section, lines: number) => {\n const shown = section.body.slice(0, lines)\n // An open fence would swallow the note below it.\n const fences = shown.filter(line => FENCE.test(line)).length\n return [\n `## ${section.headings[section.headings.length - 1]}`,\n '',\n `From ${citation(section)}`,\n '',\n ...shown,\n ...(fences % 2 === 1 ? ['```'] : []),\n ...(section.body.length > lines\n ? [\n '',\n `… ${section.body.length - lines} more lines at ${section.doc.path}:${section.line + lines + 1}`,\n ]\n : []),\n ].join('\\n')\n}\n\nexport interface Answer {\n readonly query: string\n readonly declarations: ReadonlyArray<Declaration>\n readonly sections: ReadonlyArray<Ranked>\n /** How many documents were searched, for an answer that found nothing. */\n readonly searched: number\n}\n\nexport const RESULTS = 3\nconst BODY_LINES = 60\n\n/**\n * The answer to `docs <query>`: the best sections, and a symbol's\n * declarations, those of the package whose section ranks highest first.\n */\nexport const answer = (\n docs: ReadonlyArray<Doc>,\n query: string,\n declarations: (symbol: string) => ReadonlyArray<Declaration>,\n): Answer => {\n const ranked = rank(docs.flatMap(sectionsOf), query)\n const standing = (topic: string) => {\n const at = ranked.findIndex(each => each.section.doc.topic === topic)\n return at === -1 ? ranked.length : at\n }\n return {\n query,\n declarations: isSymbol(query)\n ? [...declarations(query)]\n .sort((x, y) => standing(x.topic) - standing(y.topic))\n .slice(0, RESULTS)\n : [],\n sections: ranked.slice(0, RESULTS),\n searched: docs.length,\n }\n}\n\n/** Whether the answer found anything: a query that did not is a failure to report. */\nexport const found = (result: Answer) =>\n result.sections.length > 0 || result.declarations.length > 0\n\n/** The answer as Markdown, for an agent's context or a terminal. */\nexport const answerText = (result: Answer): string =>\n found(result)\n ? [\n `# ${result.query}`,\n ...(result.declarations.length === 0\n ? []\n : [\n '',\n '## Declarations',\n ...result.declarations.flatMap(each => [\n '',\n `From ${each.origin} (${each.path}:${each.line})`,\n '',\n '```ts',\n ...each.comment,\n ...each.signature,\n '```',\n ]),\n ]),\n ...result.sections.flatMap(each => ['', sectionText(each.section, BODY_LINES)]),\n '',\n ].join('\\n')\n : `Nothing in the ${result.searched} installed documents matches \"${result.query}\". Try other words, or \\`npx foldkit-plus docs --list\\` for what is installed.\\n`\n\n/** The answer as JSON, for a program. */\nexport const answerJson = (result: Answer) =>\n `${JSON.stringify(\n {\n query: result.query,\n declarations: result.declarations,\n sections: result.sections.map(({ section, score }) => ({\n source: section.doc.label,\n path: section.doc.path,\n line: section.line,\n anchor: section.anchor,\n headings: section.headings,\n score: Math.round(score * 100) / 100,\n text: section.body.join('\\n'),\n })),\n },\n null,\n 2,\n )}\\n`\n\n/**\n * `--list`: with no topic, every installed document; with one, the headings\n * of each document on it as an outline. A topic nothing installed covers is\n * `none`, for the caller to report with the topics there are.\n */\nexport const outlineText = (docs: ReadonlyArray<Doc>, topic: Option.Option<string>) =>\n Option.match(topic, {\n onNone: () =>\n Option.some(\n [\n '# Installed documents',\n '',\n ...docs.map(doc => `- \\`${doc.topic}\\`: ${doc.label} (${doc.path})`),\n '',\n 'Outline one with `npx foldkit-plus docs --list <topic>`.',\n '',\n ].join('\\n'),\n ),\n onSome: wanted => {\n const matching = docs.filter(doc => doc.topic === wanted)\n return matching.length === 0\n ? Option.none()\n : Option.some(\n matching\n .flatMap(doc => [\n `# ${doc.label}`,\n '',\n doc.path,\n '',\n ...sectionsOf(doc).map(\n section =>\n `${' '.repeat(section.depth - 1)}- ${section.headings[section.headings.length - 1]} (line ${section.line})`,\n ),\n '',\n ])\n .join('\\n'),\n )\n },\n })\n\n/** The topics there are, for a `--list` of one that is not. */\nexport const topicsOf = (docs: ReadonlyArray<Doc>) => [...new Set(docs.map(doc => doc.topic))]\n"],"mappings":";;;;;;;;AA2CA,MAAM,UAAU;AAChB,MAAM,QAAQ;;AAGd,MAAM,QAAQ,YACZ,QACG,YAAY,CAAC,CACb,QAAQ,sBAAsB,EAAE,CAAC,CACjC,QAAQ,MAAM,GAAG;;AAGtB,MAAa,cAAc,QAAqC;CAC9D,MAAM,QAAQ,IAAI,KAAK,MAAM,OAAO;CACpC,MAAM,WAA2B,CAAC;CAClC,MAAM,OAAkD,CAAC;CACzD,MAAM,0BAAU,IAAI,IAAoB;CACxC,IAAI,QAAQ;CACZ,IAAI,OAAsB,CAAC;CAC3B,MAAM,SAAS,MAAM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AG,SAAS,QAAQ,KAAK,EAC9G;GACA;EACF,CAAC,CAAC,CACD,KAAK,IAAI,CACd;CACN;AACF,CAAC;;AAGH,MAAa,YAAY,SAA6B,CAAC,GAAG,IAAI,IAAI,KAAK,KAAI,QAAO,IAAI,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Declaration, Doc } from "./docs.mjs";
|
|
2
|
+
import { Manager, Project } from "./setup.mjs";
|
|
3
|
+
import { Option } from "effect";
|
|
4
|
+
export declare const readManifest: (path: string) => {
|
|
5
|
+
readonly name?: string | undefined;
|
|
6
|
+
readonly version?: string | undefined;
|
|
7
|
+
readonly dependencies?: {
|
|
8
|
+
readonly [x: string]: string;
|
|
9
|
+
} | undefined;
|
|
10
|
+
readonly devDependencies?: {
|
|
11
|
+
readonly [x: string]: string;
|
|
12
|
+
} | undefined;
|
|
13
|
+
readonly peerDependencies?: {
|
|
14
|
+
readonly [x: string]: string;
|
|
15
|
+
} | undefined;
|
|
16
|
+
readonly setup?: {
|
|
17
|
+
readonly effect: string;
|
|
18
|
+
readonly foldkit: string;
|
|
19
|
+
} | undefined;
|
|
20
|
+
};
|
|
21
|
+
/** The project in `folder`, if it is one. */
|
|
22
|
+
export declare const projectIn: (folder: string) => Option.Option<Project>;
|
|
23
|
+
/**
|
|
24
|
+
* The project's package manager by its lockfile, here or in a project folder
|
|
25
|
+
* above (a workspace keeps one at its root), else the one running this.
|
|
26
|
+
*/
|
|
27
|
+
export declare const managerIn: (folder: string) => Manager;
|
|
28
|
+
/** A failure the reader can act on, printed as its message alone. */
|
|
29
|
+
export declare class Refusal extends Error {}
|
|
30
|
+
/** The Foldkit Plus packages a manifest names: its own `foldkit-*` dependencies and peers. */
|
|
31
|
+
export declare const familyOf: (manifest: ReturnType<typeof readManifest>) => ReadonlyArray<string>;
|
|
32
|
+
/** What `docs` reads for a project: its documents, and a way to look a symbol up in its types. */
|
|
33
|
+
export interface Library {
|
|
34
|
+
readonly docs: ReadonlyArray<Doc>;
|
|
35
|
+
readonly declarations: (symbol: string) => ReadonlyArray<Declaration>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The documents of what is installed in `folder`: the README of each Foldkit
|
|
39
|
+
* Plus package Node would load there, and the skill's files if it is
|
|
40
|
+
* installed. `family` is the packages this CLI knows of; an installed
|
|
41
|
+
* `foldkit-plus` adds those it knows. Refuses a folder with no project, a
|
|
42
|
+
* package the project names but has not installed, and a project with none.
|
|
43
|
+
*/
|
|
44
|
+
export declare const libraryIn: (folder: string, family: ReadonlyArray<string>) => Library;
|
|
45
|
+
//# sourceMappingURL=project.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.d.mts","names":[],"sources":["../src/project.ts"],"mappings":";;;qBAqBa,eAAY;;;;;;;;;;;;;;;;;;qBAuCZ,YAAS,mBAAqB,OAAO,OAAO;;;;;qBAoB5C,YAAS,mBAAqB;;qBAmB9B,gBAAgB;;qBAGhB,WAAQ,UAAc,kBAAkB,kBAAgB;;iBAuDpD;WACN,MAAM,cAAc;WACpB,eAAe,mBAAmB,cAAc;;;;;;;;;qBAU9C,YAAS,gBAAkB,QAAU,0BAAwB"}
|