-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add llms.txt generation for GitHub Pages deployment #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
304ed6e
Initial plan
Copilot fbc7265
Add llms.txt file generation script and output
Copilot 3d1d2c1
Fix multiline descriptions in llms.txt to be single-line
Copilot a2e8bc2
Add llms.txt documentation to README
Copilot 2d996d8
Address code review feedback: improve code quality
Copilot 7e23ac9
Generate llms.txt in website/public for GitHub Pages
Copilot a2bd4fd
Update eng/generate-llms-txt.mjs
aaronpowell fd509d2
Link skills to SKILL.md files instead of directories
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,254 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import fs from "fs"; | ||
| import path from "path"; | ||
| import { | ||
| AGENTS_DIR, | ||
| INSTRUCTIONS_DIR, | ||
| PROMPTS_DIR, | ||
| SKILLS_DIR, | ||
| ROOT_FOLDER, | ||
| } from "./constants.mjs"; | ||
| import { parseFrontmatter, parseSkillMetadata } from "./yaml-parser.mjs"; | ||
|
|
||
| /** | ||
| * Extracts the name from a file based on its frontmatter or filename | ||
| * @param {string} filePath - Path to the file (or directory for skills) | ||
| * @param {string} fileType - Type of file (agent, prompt, instruction, skill) | ||
| * @returns {string} - The name of the resource | ||
| */ | ||
| function extractName(filePath, fileType) { | ||
| try { | ||
| if (fileType === "skill") { | ||
| // For skills, filePath is the skill directory | ||
| const skillMetadata = parseSkillMetadata(filePath); | ||
| return skillMetadata?.name || path.basename(filePath); | ||
| } | ||
|
|
||
| const frontmatter = parseFrontmatter(filePath); | ||
| if (frontmatter?.name) { | ||
| return frontmatter.name; | ||
| } | ||
|
|
||
| // Fallback to filename | ||
| const basename = path.basename(filePath, path.extname(filePath)); | ||
| return basename | ||
| .replace(/\.(agent|prompt|instructions)$/, "") | ||
| .replace(/[-_]/g, " ") | ||
| .replace(/\b\w/g, (l) => l.toUpperCase()); | ||
| } catch (error) { | ||
| console.error(`Error extracting name from ${filePath}: ${error.message}`); | ||
| const basename = path.basename(filePath, path.extname(filePath)); | ||
| return basename.replace(/[-_]/g, " "); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Extracts the description from a file's frontmatter | ||
| * @param {string} filePath - Path to the file (or directory for skills) | ||
| * @param {string} fileType - Type of file (agent, prompt, instruction, skill) | ||
| * @returns {string} - The description of the resource (single line) | ||
| */ | ||
| function extractDescription(filePath, fileType) { | ||
| try { | ||
| if (fileType === "skill") { | ||
| // For skills, filePath is the skill directory | ||
| const skillMetadata = parseSkillMetadata(filePath); | ||
| const description = skillMetadata?.description || "No description available"; | ||
| // Convert multiline descriptions to single line | ||
| return description.replace(/\s+/g, " ").trim(); | ||
| } | ||
|
|
||
| const frontmatter = parseFrontmatter(filePath); | ||
| const description = frontmatter?.description || "No description available"; | ||
| // Convert multiline descriptions to single line | ||
| return description.replace(/\s+/g, " ").trim(); | ||
| } catch (error) { | ||
| console.error( | ||
| `Error extracting description from ${filePath}: ${error.message}` | ||
| ); | ||
| return "No description available"; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets the relative URL path for a resource | ||
| * @param {string} filePath - Full path to the file | ||
| * @param {string} baseDir - Base directory to calculate relative path from | ||
| * @returns {string} - Relative URL path | ||
| */ | ||
| function getRelativeUrl(filePath, baseDir) { | ||
| const basePath = baseDir || ROOT_FOLDER; | ||
| const relativePath = path.relative(basePath, filePath); | ||
| return relativePath.replace(/\\/g, "/"); | ||
| } | ||
|
|
||
| /** | ||
| * Generates llms.txt content according to the llmstxt.org specification | ||
| * @returns {string} - The llms.txt file content | ||
| */ | ||
| function generateLlmsTxt() { | ||
| let content = ""; | ||
|
|
||
| // H1 header (required) | ||
| content += "# Awesome GitHub Copilot\n\n"; | ||
|
|
||
| // Summary blockquote (optional but recommended) | ||
| content += | ||
| "> A community-driven collection of custom agents, prompts, instructions, and skills to enhance GitHub Copilot experiences across various domains, languages, and use cases.\n\n"; | ||
|
|
||
| // Add overview section | ||
| content += "## Overview\n\n"; | ||
| content += | ||
| "This repository provides resources to customize and enhance GitHub Copilot:\n\n"; | ||
| content += | ||
| "- **Agents**: Specialized GitHub Copilot agents that integrate with MCP servers\n"; | ||
| content += | ||
| "- **Prompts**: Task-specific prompts for code generation and problem-solving\n"; | ||
| content += | ||
| "- **Instructions**: Coding standards and best practices applied to specific file patterns\n"; | ||
| content += | ||
| "- **Skills**: Self-contained folders with instructions and bundled resources for specialized tasks\n\n"; | ||
|
|
||
| // Process Agents | ||
| content += "## Agents\n\n"; | ||
| const agentFiles = fs | ||
| .readdirSync(AGENTS_DIR) | ||
| .filter((file) => file.endsWith(".agent.md")) | ||
| .sort(); | ||
|
|
||
| agentFiles.forEach((file) => { | ||
| const filePath = path.join(AGENTS_DIR, file); | ||
| const name = extractName(filePath, "agent"); | ||
| const description = extractDescription(filePath, "agent"); | ||
| const url = getRelativeUrl(filePath, ROOT_FOLDER); | ||
|
|
||
| content += `- [${name}](${url}): ${description}\n`; | ||
| }); | ||
|
|
||
| content += "\n"; | ||
|
|
||
| // Process Prompts | ||
| content += "## Prompts\n\n"; | ||
| const promptFiles = fs | ||
| .readdirSync(PROMPTS_DIR) | ||
| .filter((file) => file.endsWith(".prompt.md")) | ||
| .sort(); | ||
|
|
||
| promptFiles.forEach((file) => { | ||
| const filePath = path.join(PROMPTS_DIR, file); | ||
| const name = extractName(filePath, "prompt"); | ||
| const description = extractDescription(filePath, "prompt"); | ||
| const url = getRelativeUrl(filePath, ROOT_FOLDER); | ||
|
|
||
| content += `- [${name}](${url}): ${description}\n`; | ||
| }); | ||
|
|
||
| content += "\n"; | ||
|
|
||
| // Process Instructions | ||
| content += "## Instructions\n\n"; | ||
| const instructionFiles = fs | ||
| .readdirSync(INSTRUCTIONS_DIR) | ||
| .filter((file) => file.endsWith(".instructions.md")) | ||
| .sort(); | ||
|
|
||
| instructionFiles.forEach((file) => { | ||
| const filePath = path.join(INSTRUCTIONS_DIR, file); | ||
| const name = extractName(filePath, "instruction"); | ||
| const description = extractDescription(filePath, "instruction"); | ||
| const url = getRelativeUrl(filePath, ROOT_FOLDER); | ||
|
|
||
| content += `- [${name}](${url}): ${description}\n`; | ||
| }); | ||
|
|
||
| content += "\n"; | ||
|
|
||
| // Process Skills | ||
| content += "## Skills\n\n"; | ||
| const skillDirs = fs | ||
| .readdirSync(SKILLS_DIR) | ||
| .filter((item) => { | ||
| const itemPath = path.join(SKILLS_DIR, item); | ||
| return fs.statSync(itemPath).isDirectory(); | ||
| }) | ||
| .sort(); | ||
|
|
||
| skillDirs.forEach((dir) => { | ||
| const skillDirPath = path.join(SKILLS_DIR, dir); | ||
| const skillPath = path.join(skillDirPath, "SKILL.md"); | ||
|
|
||
| if (fs.existsSync(skillPath)) { | ||
| const name = extractName(skillDirPath, "skill"); | ||
| const description = extractDescription(skillDirPath, "skill"); | ||
| const url = getRelativeUrl(skillPath, ROOT_FOLDER); | ||
|
|
||
| content += `- [${name}](${url}): ${description}\n`; | ||
| } else { | ||
|
aaronpowell marked this conversation as resolved.
|
||
| console.warn(`Warning: Skill directory '${dir}' found without SKILL.md file`); | ||
| } | ||
| }); | ||
|
|
||
| content += "\n"; | ||
|
|
||
| // Add documentation links | ||
| content += "## Documentation\n\n"; | ||
| content += | ||
| "- [README.md](README.md): Main documentation and getting started guide\n"; | ||
| content += | ||
| "- [CONTRIBUTING.md](CONTRIBUTING.md): Guidelines for contributing to this repository\n"; | ||
| content += | ||
| "- [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md): Community standards and expectations\n"; | ||
| content += "- [SECURITY.md](SECURITY.md): Security policies and reporting\n"; | ||
| content += "- [AGENTS.md](AGENTS.md): Project overview and setup commands\n\n"; | ||
|
|
||
| // Add repository information | ||
| content += "## Repository\n\n"; | ||
| content += | ||
| "- **GitHub**: https://github.com/github/awesome-copilot\n"; | ||
| content += "- **License**: MIT\n"; | ||
| content += | ||
| "- **Website**: https://github.github.io/awesome-copilot\n"; | ||
|
|
||
| return content; | ||
| } | ||
|
|
||
| /** | ||
| * Main function to generate and write the llms.txt file | ||
| * @param {string} [outputDir] - Optional output directory. Defaults to repository root. | ||
| */ | ||
| function main(outputDir = ROOT_FOLDER) { | ||
| console.log("Generating llms.txt file..."); | ||
|
|
||
| try { | ||
| const content = generateLlmsTxt(); | ||
| const outputPath = path.join(outputDir, "llms.txt"); | ||
|
|
||
| // Ensure output directory exists | ||
| if (!fs.existsSync(outputDir)) { | ||
| fs.mkdirSync(outputDir, { recursive: true }); | ||
| } | ||
|
|
||
| fs.writeFileSync(outputPath, content, "utf8"); | ||
|
|
||
| console.log(`✓ llms.txt generated successfully at ${outputPath}`); | ||
|
|
||
| // Count resources using a helper function | ||
| const countResources = (dirName) => { | ||
| const lines = content.split("\n"); | ||
| return lines.filter((l) => l.startsWith("- [") && l.includes(`${dirName}/`)).length; | ||
| }; | ||
|
|
||
| console.log(` - ${countResources("agents")} agents`); | ||
| console.log(` - ${countResources("prompts")} prompts`); | ||
| console.log(` - ${countResources("instructions")} instructions`); | ||
| console.log(` - ${countResources("skills")} skills`); | ||
| } catch (error) { | ||
| console.error(`Error generating llms.txt: ${error.message}`); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| // Support command-line argument for output directory | ||
| const outputDir = process.argv[2]; | ||
| main(outputDir); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.