Implement Collections feature for grouping related prompts, instructions, and chat modes (#232)

* Initial plan

* Implement core Collections feature with YAML parsing and README generation

Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>

* Complete Collections feature implementation with validation, tooling, and documentation

Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>

* Update generated README files to include collections instructions

* Fix YAML parsing logic bug: replace impossible condition with proper indentation check

Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>

* Refactor: Extract YAML parser to shared module and improve user experience

Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>

* fixing task and file permissions

* Better args handling

* Adding some more collections

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
Co-authored-by: Aaron Powell <me@aaron-powell.com>
This commit is contained in:
Copilot
2025-09-17 10:15:34 +10:00
committed by GitHub
parent f767285190
commit dfe63f4542
29 changed files with 1434 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
const fs = require("fs");
const path = require("path");
const { parseCollectionYaml } = require("./yaml-parser");
// Template sections for the README
const TEMPLATES = {
@@ -49,9 +50,28 @@ Custom chat modes define specific behaviors and tools for GitHub Copilot Chat, e
- Import the chat mode configuration into your VS Code settings
- Access the installed chat modes through the VS Code Chat interface
- Select the desired chat mode from the available options in VS Code Chat`,
collectionsSection: `## 📦 Collections
Curated collections of related prompts, instructions, and chat modes organized around specific themes, workflows, or use cases.`,
collectionsUsage: `### How to Use Collections
**Browse Collections:**
- Explore themed collections that group related customizations
- Each collection includes prompts, instructions, and chat modes for specific workflows
- Collections make it easy to adopt comprehensive toolkits for particular scenarios
**Install Items:**
- Click install buttons for individual items within collections
- Or browse to the individual files to copy content manually
- Collections help you discover related customizations you might have missed`,
};
// Add error handling utility
/**
* Safe file operation wrapper
*/
function safeFileOperation(operation, filePath, defaultValue = null) {
try {
return operation();
@@ -409,6 +429,110 @@ function generateChatModesSection(chatmodesDir) {
return `${TEMPLATES.chatmodesSection}\n${TEMPLATES.chatmodesUsage}\n\n${chatmodesContent}`;
}
/**
* Generate the collections section with a table of all collections
*/
function generateCollectionsSection(collectionsDir) {
// Check if collections directory exists, create it if it doesn't
if (!fs.existsSync(collectionsDir)) {
console.log("Collections directory does not exist, creating it...");
fs.mkdirSync(collectionsDir, { recursive: true });
}
// Get all collection files
const collectionFiles = fs
.readdirSync(collectionsDir)
.filter((file) => file.endsWith(".collection.yml"))
.sort();
console.log(`Found ${collectionFiles.length} collection files`);
// If no collections, return empty string
if (collectionFiles.length === 0) {
return "";
}
// Create table header
let collectionsContent =
"| Name | Description | Items | Tags |\n| ---- | ----------- | ----- | ---- |\n";
// Generate table rows for each collection file
for (const file of collectionFiles) {
const filePath = path.join(collectionsDir, file);
const collection = parseCollectionYaml(filePath);
if (!collection) {
console.warn(`Failed to parse collection: ${file}`);
continue;
}
const collectionId = collection.id || path.basename(file, ".collection.yml");
const name = collection.name || collectionId;
const description = collection.description || "No description";
const itemCount = collection.items ? collection.items.length : 0;
const tags = collection.tags ? collection.tags.join(", ") : "";
const link = `collections/${collectionId}.md`;
collectionsContent += `| [${name}](${link}) | ${description} | ${itemCount} items | ${tags} |\n`;
}
return `${TEMPLATES.collectionsSection}\n${TEMPLATES.collectionsUsage}\n\n${collectionsContent}`;
}
/**
* Generate individual collection README file
*/
function generateCollectionReadme(collection, collectionId) {
if (!collection || !collection.items) {
return `# ${collectionId}\n\nCollection not found or invalid.`;
}
const name = collection.name || collectionId;
const description = collection.description || "No description provided.";
const tags = collection.tags ? collection.tags.join(", ") : "None";
let content = `# ${name}\n\n${description}\n\n`;
if (collection.tags && collection.tags.length > 0) {
content += `**Tags:** ${tags}\n\n`;
}
content += `## Items in this Collection\n\n`;
content += `| Title | Type | Description |\n| ----- | ---- | ----------- |\n`;
// Sort items based on display.ordering setting
const items = [...collection.items];
if (collection.display?.ordering === "alpha") {
items.sort((a, b) => {
const titleA = extractTitle(path.join(__dirname, a.path));
const titleB = extractTitle(path.join(__dirname, b.path));
return titleA.localeCompare(titleB);
});
}
for (const item of items) {
const filePath = path.join(__dirname, item.path);
const title = extractTitle(filePath);
const description = extractDescription(filePath) || "No description";
const typeDisplay = item.kind === "chat-mode" ? "Chat Mode" :
item.kind === "instruction" ? "Instruction" : "Prompt";
const link = `../${item.path}`;
// Create install badges for each item
const badges = makeBadges(item.path, item.kind === "instruction" ? "instructions" :
item.kind === "chat-mode" ? "mode" : "prompt");
content += `| [${title}](${link})<br />${badges} | ${typeDisplay} | ${description} |\n`;
}
if (collection.display?.show_badge) {
content += `\n---\n*This collection includes ${items.length} curated items for ${name.toLowerCase()}.*`;
}
return content;
}
// Utility: write file only if content changed
function writeFileIfChanged(filePath, content) {
const exists = fs.existsSync(filePath);
@@ -441,11 +565,13 @@ try {
const instructionsDir = path.join(__dirname, "instructions");
const promptsDir = path.join(__dirname, "prompts");
const chatmodesDir = path.join(__dirname, "chatmodes");
const collectionsDir = path.join(__dirname, "collections");
// Compose headers for standalone files by converting section headers to H1
const instructionsHeader = TEMPLATES.instructionsSection.replace(/^##\s/m, "# ");
const promptsHeader = TEMPLATES.promptsSection.replace(/^##\s/m, "# ");
const chatmodesHeader = TEMPLATES.chatmodesSection.replace(/^##\s/m, "# ");
const collectionsHeader = TEMPLATES.collectionsSection.replace(/^##\s/m, "# ");
const instructionsReadme = buildCategoryReadme(
generateInstructionsSection,
@@ -465,11 +591,41 @@ try {
chatmodesHeader,
TEMPLATES.chatmodesUsage
);
// Generate collections README
const collectionsReadme = buildCategoryReadme(
generateCollectionsSection,
collectionsDir,
collectionsHeader,
TEMPLATES.collectionsUsage
);
// Write outputs
// Write category outputs
writeFileIfChanged(path.join(__dirname, "README.instructions.md"), instructionsReadme);
writeFileIfChanged(path.join(__dirname, "README.prompts.md"), promptsReadme);
writeFileIfChanged(path.join(__dirname, "README.chatmodes.md"), chatmodesReadme);
writeFileIfChanged(path.join(__dirname, "README.collections.md"), collectionsReadme);
// Generate individual collection README files
if (fs.existsSync(collectionsDir)) {
console.log("Generating individual collection README files...");
const collectionFiles = fs
.readdirSync(collectionsDir)
.filter((file) => file.endsWith(".collection.yml"));
for (const file of collectionFiles) {
const filePath = path.join(collectionsDir, file);
const collection = parseCollectionYaml(filePath);
if (collection) {
const collectionId = collection.id || path.basename(file, ".collection.yml");
const readmeContent = generateCollectionReadme(collection, collectionId);
const readmeFile = path.join(collectionsDir, `${collectionId}.md`);
writeFileIfChanged(readmeFile, readmeContent);
}
}
}
} catch (error) {
console.error(`Error generating category README files: ${error.message}`);
process.exit(1);