MCPcopy Create free account
hub / github.com/adobe/react-spectrum / parseLlmsTxt

Function parseLlmsTxt

packages/dev/s2-docs/scripts/generateAgentSkills.mjs:258–332  ·  view source on GitHub ↗

* Parse llms.txt to get documentation entries.

(llmsTxtPath)

Source from the content-addressed store, hash-verified

256 * Parse llms.txt to get documentation entries.
257 */
258function parseLlmsTxt(llmsTxtPath) {
259 const content = fs.readFileSync(llmsTxtPath, 'utf8');
260 const entries = [];
261 const tree = unified().use(remarkParse).parse(content);
262
263 const toText = node => {
264 if (!node) {
265 return '';
266 }
267 if (node.type === 'text') {
268 return node.value;
269 }
270 if (node.type === 'inlineCode') {
271 return '`' + node.value + '`';
272 }
273 if (Array.isArray(node.children)) {
274 return node.children.map(toText).join('');
275 }
276 return '';
277 };
278
279 const extractEntry = listItem => {
280 const paragraph = listItem.children?.find(child => child.type === 'paragraph');
281 if (!paragraph || !Array.isArray(paragraph.children)) {
282 return null;
283 }
284
285 const linkIndex = paragraph.children.findIndex(child => child.type === 'link');
286 if (linkIndex === -1) {
287 return null;
288 }
289
290 const link = paragraph.children[linkIndex];
291 const title = toText(link).trim();
292 const entryPath = link.url;
293 if (!title || !entryPath) {
294 return null;
295 }
296
297 let description = paragraph.children
298 .slice(linkIndex + 1)
299 .map(toText)
300 .join('')
301 .trim();
302
303 if (description.startsWith(':')) {
304 description = description.slice(1).trim();
305 }
306
307 return {
308 title,
309 path: entryPath,
310 description
311 };
312 };
313
314 const walk = node => {
315 if (!node || !Array.isArray(node.children)) {

Callers 2

generateSkillFunction · 0.85

Calls 2

walkFunction · 0.70
parseMethod · 0.45

Tested by

no test coverage detected