@skillit/core 1.5.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/LICENSE +21 -0
- package/README.md +55 -0
- package/dist/audit-formatter.d.ts +36 -0
- package/dist/audit-formatter.d.ts.map +1 -0
- package/dist/audit-formatter.js +173 -0
- package/dist/audit-formatter.js.map +1 -0
- package/dist/audit-score.d.ts +76 -0
- package/dist/audit-score.d.ts.map +1 -0
- package/dist/audit-score.js +490 -0
- package/dist/audit-score.js.map +1 -0
- package/dist/audit-types.d.ts +81 -0
- package/dist/audit-types.d.ts.map +1 -0
- package/dist/audit-types.js +2 -0
- package/dist/audit-types.js.map +1 -0
- package/dist/audit.d.ts +17 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +567 -0
- package/dist/audit.js.map +1 -0
- package/dist/canonical.d.ts +36 -0
- package/dist/canonical.d.ts.map +1 -0
- package/dist/canonical.js +148 -0
- package/dist/canonical.js.map +1 -0
- package/dist/config-renderer.d.ts +16 -0
- package/dist/config-renderer.d.ts.map +1 -0
- package/dist/config-renderer.js +296 -0
- package/dist/config-renderer.js.map +1 -0
- package/dist/config-types.d.ts +144 -0
- package/dist/config-types.d.ts.map +1 -0
- package/dist/config-types.js +2 -0
- package/dist/config-types.js.map +1 -0
- package/dist/docs-scanner.d.ts +40 -0
- package/dist/docs-scanner.d.ts.map +1 -0
- package/dist/docs-scanner.js +176 -0
- package/dist/docs-scanner.js.map +1 -0
- package/dist/examples-scanner.d.ts +39 -0
- package/dist/examples-scanner.d.ts.map +1 -0
- package/dist/examples-scanner.js +221 -0
- package/dist/examples-scanner.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/llms-txt.d.ts +20 -0
- package/dist/llms-txt.d.ts.map +1 -0
- package/dist/llms-txt.js +187 -0
- package/dist/llms-txt.js.map +1 -0
- package/dist/markdown-parser.d.ts +11 -0
- package/dist/markdown-parser.d.ts.map +1 -0
- package/dist/markdown-parser.js +222 -0
- package/dist/markdown-parser.js.map +1 -0
- package/dist/markdown-types.d.ts +48 -0
- package/dist/markdown-types.d.ts.map +1 -0
- package/dist/markdown-types.js +2 -0
- package/dist/markdown-types.js.map +1 -0
- package/dist/readme-parser.d.ts +21 -0
- package/dist/readme-parser.d.ts.map +1 -0
- package/dist/readme-parser.js +137 -0
- package/dist/readme-parser.js.map +1 -0
- package/dist/references-mcp.d.ts +79 -0
- package/dist/references-mcp.d.ts.map +1 -0
- package/dist/references-mcp.js +130 -0
- package/dist/references-mcp.js.map +1 -0
- package/dist/refine/ast-edit.d.ts +21 -0
- package/dist/refine/ast-edit.d.ts.map +1 -0
- package/dist/refine/ast-edit.js +147 -0
- package/dist/refine/ast-edit.js.map +1 -0
- package/dist/refine/index.d.ts +7 -0
- package/dist/refine/index.d.ts.map +1 -0
- package/dist/refine/index.js +6 -0
- package/dist/refine/index.js.map +1 -0
- package/dist/refine/jsdoc-edit.d.ts +4 -0
- package/dist/refine/jsdoc-edit.d.ts.map +1 -0
- package/dist/refine/jsdoc-edit.js +6 -0
- package/dist/refine/jsdoc-edit.js.map +1 -0
- package/dist/refine/loop.d.ts +8 -0
- package/dist/refine/loop.d.ts.map +1 -0
- package/dist/refine/loop.js +98 -0
- package/dist/refine/loop.js.map +1 -0
- package/dist/refine/select-targets.d.ts +5 -0
- package/dist/refine/select-targets.d.ts.map +1 -0
- package/dist/refine/select-targets.js +30 -0
- package/dist/refine/select-targets.js.map +1 -0
- package/dist/refine/types.d.ts +67 -0
- package/dist/refine/types.d.ts.map +1 -0
- package/dist/refine/types.js +2 -0
- package/dist/refine/types.js.map +1 -0
- package/dist/renderer.d.ts +27 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +1244 -0
- package/dist/renderer.js.map +1 -0
- package/dist/tokens.d.ts +14 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +26 -0
- package/dist/tokens.js.map +1 -0
- package/dist/types.d.ts +519 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/writer.d.ts +17 -0
- package/dist/writer.d.ts.map +1 -0
- package/dist/writer.js +313 -0
- package/dist/writer.js.map +1 -0
- package/package.json +54 -0
package/dist/llms-txt.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { estimateTokens } from './tokens.js';
|
|
2
|
+
/** Max description length in llms.txt summary */
|
|
3
|
+
const SUMMARY_DESC_MAX = 150;
|
|
4
|
+
/** Render llms.txt and llms-full.txt from extracted skills */
|
|
5
|
+
export function renderLlmsTxt(skills, options) {
|
|
6
|
+
const summary = renderSummary(skills, options);
|
|
7
|
+
const full = renderFull(skills, options);
|
|
8
|
+
return {
|
|
9
|
+
summary,
|
|
10
|
+
full,
|
|
11
|
+
summaryTokens: estimateTokens(summary),
|
|
12
|
+
fullTokens: estimateTokens(full)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// llms.txt — summary index
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
function renderSummary(skills, options) {
|
|
19
|
+
const lines = [];
|
|
20
|
+
lines.push(`# ${options.projectName}\n`);
|
|
21
|
+
if (options.projectDescription) {
|
|
22
|
+
lines.push(`> ${options.projectDescription}\n`);
|
|
23
|
+
}
|
|
24
|
+
if (skills.length > 1) {
|
|
25
|
+
for (const skill of skills) {
|
|
26
|
+
lines.push(`## ${skill.name}\n`);
|
|
27
|
+
if (skill.description) {
|
|
28
|
+
lines.push(`> ${truncateDescription(skill.description)}\n`);
|
|
29
|
+
}
|
|
30
|
+
renderSummarySections(skill, lines);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (skills.length === 1) {
|
|
34
|
+
renderSummarySections(skills[0], lines);
|
|
35
|
+
}
|
|
36
|
+
return lines.join('\n');
|
|
37
|
+
}
|
|
38
|
+
function renderSummarySections(skill, lines) {
|
|
39
|
+
const primary = [];
|
|
40
|
+
const optional = [];
|
|
41
|
+
// Functions
|
|
42
|
+
for (const fn of skill.functions) {
|
|
43
|
+
const desc = truncateDescription(fn.description);
|
|
44
|
+
primary.push(`- \`${fn.name}\`${desc ? `: ${desc}` : ''}`);
|
|
45
|
+
}
|
|
46
|
+
// Classes
|
|
47
|
+
for (const cls of skill.classes) {
|
|
48
|
+
const desc = truncateDescription(cls.description);
|
|
49
|
+
primary.push(`- \`${cls.name}\`${desc ? `: ${desc}` : ''}`);
|
|
50
|
+
}
|
|
51
|
+
// Variables
|
|
52
|
+
for (const v of skill.variables ?? []) {
|
|
53
|
+
const desc = truncateDescription(v.description);
|
|
54
|
+
primary.push(`- \`${v.name}\`${desc ? `: ${desc}` : ''}`);
|
|
55
|
+
}
|
|
56
|
+
// Types/Interfaces
|
|
57
|
+
for (const t of skill.types) {
|
|
58
|
+
const desc = truncateDescription(t.description);
|
|
59
|
+
optional.push(`- \`${t.name}\`${desc ? `: ${desc}` : ''}`);
|
|
60
|
+
}
|
|
61
|
+
// Enums
|
|
62
|
+
for (const e of skill.enums) {
|
|
63
|
+
const desc = truncateDescription(e.description);
|
|
64
|
+
optional.push(`- \`${e.name}\`${desc ? `: ${desc}` : ''}`);
|
|
65
|
+
}
|
|
66
|
+
if (primary.length > 0) {
|
|
67
|
+
lines.push('### API\n');
|
|
68
|
+
lines.push(...primary);
|
|
69
|
+
lines.push('');
|
|
70
|
+
}
|
|
71
|
+
if (optional.length > 0) {
|
|
72
|
+
lines.push('## Optional\n');
|
|
73
|
+
lines.push('### Types\n');
|
|
74
|
+
lines.push(...optional);
|
|
75
|
+
lines.push('');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
// llms-full.txt — complete API content
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
function renderFull(skills, options) {
|
|
82
|
+
const lines = [];
|
|
83
|
+
lines.push(`# ${options.projectName}\n`);
|
|
84
|
+
if (options.projectDescription) {
|
|
85
|
+
lines.push(`> ${options.projectDescription}\n`);
|
|
86
|
+
}
|
|
87
|
+
for (const skill of skills) {
|
|
88
|
+
if (skills.length > 1) {
|
|
89
|
+
lines.push(`## ${skill.name}\n`);
|
|
90
|
+
if (skill.description)
|
|
91
|
+
lines.push(`${skill.description}\n`);
|
|
92
|
+
}
|
|
93
|
+
// Functions
|
|
94
|
+
for (const fn of skill.functions) {
|
|
95
|
+
lines.push(`### ${fn.name}\n`);
|
|
96
|
+
if (fn.description)
|
|
97
|
+
lines.push(`${fn.description}\n`);
|
|
98
|
+
if (fn.signature) {
|
|
99
|
+
lines.push('```ts', fn.signature, '```\n');
|
|
100
|
+
}
|
|
101
|
+
if (fn.parameters.length > 0) {
|
|
102
|
+
lines.push('**Parameters:**');
|
|
103
|
+
for (const p of fn.parameters) {
|
|
104
|
+
const opt = p.optional ? ' (optional)' : '';
|
|
105
|
+
lines.push(`- \`${p.name}: ${p.type}\`${opt} — ${p.description || ''}`);
|
|
106
|
+
}
|
|
107
|
+
lines.push('');
|
|
108
|
+
}
|
|
109
|
+
if (fn.returnType && fn.returnType !== 'void') {
|
|
110
|
+
lines.push(`**Returns:** \`${fn.returnType}\`\n`);
|
|
111
|
+
}
|
|
112
|
+
if (fn.examples.length > 0) {
|
|
113
|
+
for (const ex of fn.examples) {
|
|
114
|
+
lines.push(ex);
|
|
115
|
+
}
|
|
116
|
+
lines.push('');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Classes
|
|
120
|
+
for (const cls of skill.classes) {
|
|
121
|
+
lines.push(`### ${cls.name}\n`);
|
|
122
|
+
if (cls.description)
|
|
123
|
+
lines.push(`${cls.description}\n`);
|
|
124
|
+
if (cls.constructorSignature) {
|
|
125
|
+
lines.push('```ts', cls.constructorSignature, '```\n');
|
|
126
|
+
}
|
|
127
|
+
if (cls.properties.length > 0) {
|
|
128
|
+
lines.push('**Properties:**');
|
|
129
|
+
for (const p of cls.properties) {
|
|
130
|
+
lines.push(`- \`${p.name}: ${p.type}\` — ${p.description || ''}`);
|
|
131
|
+
}
|
|
132
|
+
lines.push('');
|
|
133
|
+
}
|
|
134
|
+
if (cls.methods.length > 0) {
|
|
135
|
+
lines.push('**Methods:**');
|
|
136
|
+
for (const m of cls.methods) {
|
|
137
|
+
lines.push(`- \`${m.signature}\` — ${m.description || ''}`);
|
|
138
|
+
}
|
|
139
|
+
lines.push('');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Types
|
|
143
|
+
for (const t of skill.types) {
|
|
144
|
+
lines.push(`### ${t.name}\n`);
|
|
145
|
+
if (t.description)
|
|
146
|
+
lines.push(`${t.description}\n`);
|
|
147
|
+
if (t.definition) {
|
|
148
|
+
lines.push('```ts', `type ${t.name} = ${t.definition}`, '```\n');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Enums
|
|
152
|
+
for (const e of skill.enums) {
|
|
153
|
+
lines.push(`### ${e.name}\n`);
|
|
154
|
+
if (e.description)
|
|
155
|
+
lines.push(`${e.description}\n`);
|
|
156
|
+
for (const m of e.members) {
|
|
157
|
+
lines.push(`- \`${m.name}\` = \`${m.value}\` — ${m.description || ''}`);
|
|
158
|
+
}
|
|
159
|
+
lines.push('');
|
|
160
|
+
}
|
|
161
|
+
// Variables
|
|
162
|
+
for (const v of skill.variables ?? []) {
|
|
163
|
+
lines.push(`### ${v.name}\n`);
|
|
164
|
+
if (v.description)
|
|
165
|
+
lines.push(`${v.description}\n`);
|
|
166
|
+
const keyword = v.isConst ? 'const' : 'let';
|
|
167
|
+
lines.push('```ts', `${keyword} ${v.name}: ${v.type}`, '```\n');
|
|
168
|
+
}
|
|
169
|
+
if (skills.length > 1) {
|
|
170
|
+
lines.push('---\n');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return lines.join('\n');
|
|
174
|
+
}
|
|
175
|
+
// ---------------------------------------------------------------------------
|
|
176
|
+
// Helpers
|
|
177
|
+
// ---------------------------------------------------------------------------
|
|
178
|
+
function truncateDescription(desc) {
|
|
179
|
+
if (!desc || desc.length <= SUMMARY_DESC_MAX)
|
|
180
|
+
return desc;
|
|
181
|
+
const firstSentence = desc.match(/^[^.!?]+[.!?]/)?.[0];
|
|
182
|
+
if (firstSentence && firstSentence.length <= SUMMARY_DESC_MAX) {
|
|
183
|
+
return firstSentence;
|
|
184
|
+
}
|
|
185
|
+
return desc.slice(0, SUMMARY_DESC_MAX - 3) + '...';
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=llms-txt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llms-txt.js","sourceRoot":"","sources":["../src/llms-txt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,iDAAiD;AACjD,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAoB7B,8DAA8D;AAC9D,MAAM,UAAU,aAAa,CAAC,MAAwB,EAAE,OAAuB;IAC7E,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzC,OAAO;QACL,OAAO;QACP,IAAI;QACJ,aAAa,EAAE,cAAc,CAAC,OAAO,CAAC;QACtC,UAAU,EAAE,cAAc,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,2BAA2B;AAC3B,8EAA8E;AAE9E,SAAS,aAAa,CAAC,MAAwB,EAAE,OAAuB;IACtE,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC;IACzC,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,kBA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OAAO,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,SAAS,mBAAmB,CAAC,IAAY;IACvC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,IAAI,gBAAgB;QAAE,OAAO,IAAI,CAAC;IAC1D,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACvD,IAAI,aAAa,IAAI,aAAa,CAAC,MAAM,IAAI,gBAAgB,EAAE,CAAC;QAC9D,OAAO,aAAa,CAAC;IACvB,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ParsedMarkdownDoc } from './markdown-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse a markdown document string into a structured `ParsedMarkdownDoc`.
|
|
4
|
+
*
|
|
5
|
+
* @param markdown - Raw markdown source text.
|
|
6
|
+
* @param filePath - File path used for `relativePath`, title fallback, and order fallback.
|
|
7
|
+
*
|
|
8
|
+
* @category Parsing
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseMarkdownDoc(markdown: string, filePath: string): ParsedMarkdownDoc;
|
|
11
|
+
//# sourceMappingURL=markdown-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-parser.d.ts","sourceRoot":"","sources":["../src/markdown-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,qBAAqB,CAAC;AA0N5E;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,iBAAiB,CAqCtF"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// ─── Frontmatter ──────────────────────────────────────────────────────────────
|
|
2
|
+
/**
|
|
3
|
+
* Extract YAML frontmatter from the top of a markdown string.
|
|
4
|
+
* Returns the parsed key-value pairs and the remaining body, or undefined
|
|
5
|
+
* frontmatter when no frontmatter block is present.
|
|
6
|
+
*/
|
|
7
|
+
function extractFrontmatter(markdown) {
|
|
8
|
+
const FM_OPEN = /^---\r?\n/;
|
|
9
|
+
if (!FM_OPEN.test(markdown)) {
|
|
10
|
+
return { frontmatter: undefined, body: markdown };
|
|
11
|
+
}
|
|
12
|
+
const closeIdx = markdown.indexOf('\n---\n', 3);
|
|
13
|
+
if (closeIdx === -1) {
|
|
14
|
+
return { frontmatter: undefined, body: markdown };
|
|
15
|
+
}
|
|
16
|
+
const fmText = markdown.slice(4, closeIdx); // skip leading "---\n"
|
|
17
|
+
const body = markdown.slice(closeIdx + 5); // skip "\n---\n"
|
|
18
|
+
const frontmatter = {};
|
|
19
|
+
for (const line of fmText.split('\n')) {
|
|
20
|
+
const colonIdx = line.indexOf(':');
|
|
21
|
+
if (colonIdx === -1)
|
|
22
|
+
continue;
|
|
23
|
+
const key = line.slice(0, colonIdx).trim();
|
|
24
|
+
if (!key)
|
|
25
|
+
continue;
|
|
26
|
+
let value = line.slice(colonIdx + 1).trim();
|
|
27
|
+
// Strip surrounding quotes
|
|
28
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
29
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
30
|
+
value = value.slice(1, -1);
|
|
31
|
+
}
|
|
32
|
+
// Coerce numeric
|
|
33
|
+
if (value !== '' && !Number.isNaN(Number(value))) {
|
|
34
|
+
frontmatter[key] = Number(value);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
frontmatter[key] = value;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { frontmatter, body };
|
|
41
|
+
}
|
|
42
|
+
// ─── Title ────────────────────────────────────────────────────────────────────
|
|
43
|
+
/** Convert a kebab-case basename (without extension) to Title Case. */
|
|
44
|
+
function filenameToTitle(filePath) {
|
|
45
|
+
const basename = filePath.split('/').pop() ?? filePath;
|
|
46
|
+
const withoutExt = basename.replace(/\.[^.]+$/, '');
|
|
47
|
+
// Strip leading numeric prefix like "01-", "003-"
|
|
48
|
+
const stripped = withoutExt.replace(/^\d+-/, '');
|
|
49
|
+
return stripped
|
|
50
|
+
.split('-')
|
|
51
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
52
|
+
.join(' ');
|
|
53
|
+
}
|
|
54
|
+
/** Extract the text of the first `# heading` from a body string, or undefined. */
|
|
55
|
+
function extractFirstH1(body) {
|
|
56
|
+
for (const line of body.split('\n')) {
|
|
57
|
+
const m = line.match(/^#\s+(.+)/);
|
|
58
|
+
if (m)
|
|
59
|
+
return m[1]?.trim();
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
// ─── Description ─────────────────────────────────────────────────────────────
|
|
64
|
+
/**
|
|
65
|
+
* Extract the first prose paragraph that appears after the first `# heading`.
|
|
66
|
+
* Returns undefined when none found.
|
|
67
|
+
*/
|
|
68
|
+
function extractFirstParagraph(body) {
|
|
69
|
+
const lines = body.split('\n');
|
|
70
|
+
let pastFirstHeading = false;
|
|
71
|
+
const paraLines = [];
|
|
72
|
+
let inPara = false;
|
|
73
|
+
for (const line of lines) {
|
|
74
|
+
// Detect any heading
|
|
75
|
+
if (/^#{1,6}\s/.test(line)) {
|
|
76
|
+
if (!pastFirstHeading) {
|
|
77
|
+
pastFirstHeading = true;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
// Any subsequent heading ends the paragraph search
|
|
81
|
+
if (inPara || pastFirstHeading)
|
|
82
|
+
break;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (!pastFirstHeading)
|
|
86
|
+
continue;
|
|
87
|
+
const trimmed = line.trim();
|
|
88
|
+
if (trimmed === '') {
|
|
89
|
+
if (inPara)
|
|
90
|
+
break; // blank line ends paragraph
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
inPara = true;
|
|
94
|
+
paraLines.push(trimmed);
|
|
95
|
+
}
|
|
96
|
+
if (paraLines.length === 0)
|
|
97
|
+
return undefined;
|
|
98
|
+
return paraLines.join(' ');
|
|
99
|
+
}
|
|
100
|
+
// ─── Sections ─────────────────────────────────────────────────────────────────
|
|
101
|
+
/** Return the heading level (number of leading `#`) or 0 if not a heading. */
|
|
102
|
+
function headingLevel(line) {
|
|
103
|
+
const m = line.match(/^(#{1,6})\s/);
|
|
104
|
+
return m ? (m[1]?.length ?? 0) : 0;
|
|
105
|
+
}
|
|
106
|
+
/** Extract the heading text from a heading line. */
|
|
107
|
+
function headingText(line) {
|
|
108
|
+
return line.replace(/^#{1,6}\s+/, '').trim();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Split content into a prose part and a list of fenced code blocks.
|
|
112
|
+
* Code blocks are stripped from the prose.
|
|
113
|
+
*/
|
|
114
|
+
function splitContentAndCode(raw) {
|
|
115
|
+
const codeBlocks = [];
|
|
116
|
+
const lines = raw.split('\n');
|
|
117
|
+
const proseLines = [];
|
|
118
|
+
let inCode = false;
|
|
119
|
+
let currentBlock = [];
|
|
120
|
+
for (const line of lines) {
|
|
121
|
+
if (!inCode && line.startsWith('```')) {
|
|
122
|
+
inCode = true;
|
|
123
|
+
currentBlock = [line];
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (inCode) {
|
|
127
|
+
if (/^```\s*$/.test(line)) {
|
|
128
|
+
currentBlock.push(line);
|
|
129
|
+
codeBlocks.push(currentBlock.join('\n'));
|
|
130
|
+
currentBlock = [];
|
|
131
|
+
inCode = false;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
currentBlock.push(line);
|
|
135
|
+
}
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
proseLines.push(line);
|
|
139
|
+
}
|
|
140
|
+
// Unclosed code block — treat as a code block anyway
|
|
141
|
+
if (inCode && currentBlock.length > 0) {
|
|
142
|
+
codeBlocks.push(currentBlock.join('\n'));
|
|
143
|
+
}
|
|
144
|
+
return { content: proseLines.join('\n').trim(), codeBlocks };
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Extract all `##`+ level sections from a markdown body.
|
|
148
|
+
* Each section spans from its heading to the next heading of the same or
|
|
149
|
+
* higher level (lower number = higher level).
|
|
150
|
+
*/
|
|
151
|
+
function extractSections(body) {
|
|
152
|
+
const lines = body.split('\n');
|
|
153
|
+
const sections = [];
|
|
154
|
+
const headings = [];
|
|
155
|
+
for (let i = 0; i < lines.length; i++) {
|
|
156
|
+
const lvl = headingLevel(lines[i] ?? '');
|
|
157
|
+
if (lvl >= 2) {
|
|
158
|
+
headings.push({ idx: i, level: lvl, text: headingText(lines[i] ?? '') });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
for (let h = 0; h < headings.length; h++) {
|
|
162
|
+
const current = headings[h];
|
|
163
|
+
// Find the next heading that is at the same or higher level
|
|
164
|
+
let endIdx = lines.length;
|
|
165
|
+
for (let k = h + 1; k < headings.length; k++) {
|
|
166
|
+
if (headings[k].level <= current.level) {
|
|
167
|
+
endIdx = headings[k].idx;
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const rawContent = lines.slice(current.idx + 1, endIdx).join('\n');
|
|
172
|
+
const { content, codeBlocks } = splitContentAndCode(rawContent);
|
|
173
|
+
sections.push({ heading: current.text, level: current.level, content, codeBlocks });
|
|
174
|
+
}
|
|
175
|
+
return sections;
|
|
176
|
+
}
|
|
177
|
+
// ─── Sort order ───────────────────────────────────────────────────────────────
|
|
178
|
+
/** Derive sort order from filename numeric prefix, e.g. "03-setup.md" → 3. */
|
|
179
|
+
function orderFromFilename(filePath) {
|
|
180
|
+
const basename = filePath.split('/').pop() ?? filePath;
|
|
181
|
+
const m = basename.match(/^(\d+)-/);
|
|
182
|
+
return m ? Number(m[1]) : Infinity;
|
|
183
|
+
}
|
|
184
|
+
// ─── Public API ───────────────────────────────────────────────────────────────
|
|
185
|
+
/**
|
|
186
|
+
* Parse a markdown document string into a structured `ParsedMarkdownDoc`.
|
|
187
|
+
*
|
|
188
|
+
* @param markdown - Raw markdown source text.
|
|
189
|
+
* @param filePath - File path used for `relativePath`, title fallback, and order fallback.
|
|
190
|
+
*
|
|
191
|
+
* @category Parsing
|
|
192
|
+
*/
|
|
193
|
+
export function parseMarkdownDoc(markdown, filePath) {
|
|
194
|
+
const { frontmatter, body } = extractFrontmatter(markdown);
|
|
195
|
+
// Title: frontmatter.title > first # heading > filename
|
|
196
|
+
const fmTitle = frontmatter?.['title'] !== undefined && frontmatter['title'] !== ''
|
|
197
|
+
? String(frontmatter['title'])
|
|
198
|
+
: undefined;
|
|
199
|
+
const title = fmTitle ?? extractFirstH1(body) ?? filenameToTitle(filePath);
|
|
200
|
+
// Description: frontmatter.description > first paragraph after first heading
|
|
201
|
+
const fmDescription = frontmatter?.['description'] !== undefined && frontmatter['description'] !== ''
|
|
202
|
+
? String(frontmatter['description'])
|
|
203
|
+
: undefined;
|
|
204
|
+
const description = fmDescription ?? extractFirstParagraph(body);
|
|
205
|
+
// Sections
|
|
206
|
+
const sections = extractSections(body);
|
|
207
|
+
// Order: frontmatter.sidebar_position > filename prefix > Infinity
|
|
208
|
+
const fmOrder = frontmatter?.['sidebar_position'] !== undefined
|
|
209
|
+
? Number(frontmatter['sidebar_position'])
|
|
210
|
+
: undefined;
|
|
211
|
+
const order = fmOrder !== undefined && !Number.isNaN(fmOrder) ? fmOrder : orderFromFilename(filePath);
|
|
212
|
+
return {
|
|
213
|
+
frontmatter,
|
|
214
|
+
title,
|
|
215
|
+
description,
|
|
216
|
+
relativePath: filePath,
|
|
217
|
+
sections,
|
|
218
|
+
rawContent: body,
|
|
219
|
+
order
|
|
220
|
+
};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ACN,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single section extracted from a markdown document, corresponding to one
|
|
3
|
+
* heading and all content that follows it until the next heading.
|
|
4
|
+
*/
|
|
5
|
+
export interface ParsedSection {
|
|
6
|
+
/** The text content of the section heading, without the `#` prefix characters */
|
|
7
|
+
heading: string;
|
|
8
|
+
/** The heading depth: 1 for `#`, 2 for `##`, 3 for `###`, etc. */
|
|
9
|
+
level: number;
|
|
10
|
+
/** All prose content within the section, excluding code blocks */
|
|
11
|
+
content: string;
|
|
12
|
+
/** Source text of every fenced code block found within the section */
|
|
13
|
+
codeBlocks: string[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A fully parsed markdown document with structured metadata and sections.
|
|
17
|
+
*/
|
|
18
|
+
export interface ParsedMarkdownDoc {
|
|
19
|
+
/** Parsed YAML/TOML front-matter key-value pairs, or `undefined` if the document has none */
|
|
20
|
+
frontmatter: Record<string, unknown> | undefined;
|
|
21
|
+
/** Document title, typically derived from the first `#`-level heading or front-matter */
|
|
22
|
+
title: string;
|
|
23
|
+
/** Short description of the document, or `undefined` if none could be determined */
|
|
24
|
+
description: string | undefined;
|
|
25
|
+
/** File path to the document relative to the docs root directory */
|
|
26
|
+
relativePath: string;
|
|
27
|
+
/** Ordered list of sections extracted from the document body */
|
|
28
|
+
sections: ParsedSection[];
|
|
29
|
+
/** Original unmodified markdown source text of the document */
|
|
30
|
+
rawContent: string;
|
|
31
|
+
/** Zero-based sort order used to sequence this document within a collection */
|
|
32
|
+
order: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Configuration options that control how a docs directory is scanned and which
|
|
36
|
+
* markdown files are included in the extraction.
|
|
37
|
+
*/
|
|
38
|
+
export interface DocsExtractionOptions {
|
|
39
|
+
/** Absolute or relative path to the directory containing markdown documentation files */
|
|
40
|
+
docsDir: string;
|
|
41
|
+
/** Glob pattern selecting files to include; when `undefined` all `.md` files are included */
|
|
42
|
+
include: string | undefined;
|
|
43
|
+
/** Glob patterns for files to exclude from extraction; `undefined` means no exclusions */
|
|
44
|
+
exclude: string[] | undefined;
|
|
45
|
+
/** Maximum number of documents to return; `undefined` means no limit */
|
|
46
|
+
maxDocs: number | undefined;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=markdown-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-types.d.ts","sourceRoot":"","sources":["../src/markdown-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,iFAAiF;IACjF,OAAO,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,6FAA6F;IAC7F,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IACjD,yFAAyF;IACzF,KAAK,EAAE,MAAM,CAAC;IACd,oFAAoF;IACpF,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,oEAAoE;IACpE,YAAY,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,+EAA+E;IAC/E,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,yFAAyF;IACzF,OAAO,EAAE,MAAM,CAAC;IAChB,6FAA6F;IAC7F,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,0FAA0F;IAC1F,OAAO,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC9B,wEAAwE;IACxE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-types.js","sourceRoot":"","sources":["../src/markdown-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ParsedReadme } from './audit-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse a README markdown string and extract structured sections.
|
|
4
|
+
*
|
|
5
|
+
* Extraction rules:
|
|
6
|
+
* - **blockquote** – first `> …` line between `# title` and the first `## heading`.
|
|
7
|
+
* - **firstParagraph** – first prose lines before the first `## heading` that are
|
|
8
|
+
* not a heading, badge (`[![`), image (`![`), blockquote, or blank.
|
|
9
|
+
* Consecutive lines are joined with a single space.
|
|
10
|
+
* - **quickStart** – content under `## Quick Start`, `## Usage`, or `## Getting Started`.
|
|
11
|
+
* - **features** – content under `## Features`, `## Key Features`, or `## Highlights`.
|
|
12
|
+
* - **troubleshooting** – content under `## Troubleshooting`, `## Common Issues`, `## Common Errors`,
|
|
13
|
+
* or `## FAQ`.
|
|
14
|
+
*
|
|
15
|
+
* @category Parsing
|
|
16
|
+
* @useWhen
|
|
17
|
+
* - You need structured README sections for audit context or skill enrichment
|
|
18
|
+
* - The audit engine calls this to check for Features and Troubleshooting sections
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseReadme(markdown: string): ParsedReadme;
|
|
21
|
+
//# sourceMappingURL=readme-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readme-parser.d.ts","sourceRoot":"","sources":["../src/readme-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA4CrD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,CAuF1D"}
|