chore: add code formatting config and pre-commit hooks (#450)

This commit is contained in:
manjaroblack
2025-08-16 19:08:39 -05:00
committed by GitHub
parent 51284d6ecf
commit ed539432fb
130 changed files with 11886 additions and 10939 deletions

View File

@@ -3,13 +3,13 @@
* Reduces duplication and provides shared methods
*/
const path = require("path");
const fs = require("fs-extra");
const yaml = require("js-yaml");
const chalk = require("chalk").default || require("chalk");
const fileManager = require("./file-manager");
const resourceLocator = require("./resource-locator");
const { extractYamlFromAgent } = require("../../lib/yaml-utils");
const path = require('node:path');
const fs = require('fs-extra');
const yaml = require('js-yaml');
const chalk = require('chalk').default || require('chalk');
const fileManager = require('./file-manager');
const resourceLocator = require('./resource-locator');
const { extractYamlFromAgent } = require('../../lib/yaml-utils');
class BaseIdeSetup {
constructor() {
@@ -27,19 +27,19 @@ class BaseIdeSetup {
}
const allAgents = new Set();
// Get core agents
const coreAgents = await this.getCoreAgentIds(installDir);
coreAgents.forEach(id => allAgents.add(id));
for (const id of coreAgents) allAgents.add(id);
// Get expansion pack agents
const expansionPacks = await this.getInstalledExpansionPacks(installDir);
for (const pack of expansionPacks) {
const packAgents = await this.getExpansionPackAgents(pack.path);
packAgents.forEach(id => allAgents.add(id));
for (const id of packAgents) allAgents.add(id);
}
const result = Array.from(allAgents);
const result = [...allAgents];
this._agentCache.set(cacheKey, result);
return result;
}
@@ -50,14 +50,14 @@ class BaseIdeSetup {
async getCoreAgentIds(installDir) {
const coreAgents = [];
const corePaths = [
path.join(installDir, ".bmad-core", "agents"),
path.join(installDir, "bmad-core", "agents")
path.join(installDir, '.bmad-core', 'agents'),
path.join(installDir, 'bmad-core', 'agents'),
];
for (const agentsDir of corePaths) {
if (await fileManager.pathExists(agentsDir)) {
const files = await resourceLocator.findFiles("*.md", { cwd: agentsDir });
coreAgents.push(...files.map(file => path.basename(file, ".md")));
const files = await resourceLocator.findFiles('*.md', { cwd: agentsDir });
coreAgents.push(...files.map((file) => path.basename(file, '.md')));
break; // Use first found
}
}
@@ -76,13 +76,13 @@ class BaseIdeSetup {
// Use resource locator for efficient path finding
let agentPath = await resourceLocator.getAgentPath(agentId);
if (!agentPath) {
// Check installation-specific paths
const possiblePaths = [
path.join(installDir, ".bmad-core", "agents", `${agentId}.md`),
path.join(installDir, "bmad-core", "agents", `${agentId}.md`),
path.join(installDir, "common", "agents", `${agentId}.md`)
path.join(installDir, '.bmad-core', 'agents', `${agentId}.md`),
path.join(installDir, 'bmad-core', 'agents', `${agentId}.md`),
path.join(installDir, 'common', 'agents', `${agentId}.md`),
];
for (const testPath of possiblePaths) {
@@ -113,7 +113,7 @@ class BaseIdeSetup {
const metadata = yaml.load(yamlContent);
return metadata.agent_name || agentId;
}
} catch (error) {
} catch {
// Fallback to agent ID
}
return agentId;
@@ -129,31 +129,31 @@ class BaseIdeSetup {
}
const expansionPacks = [];
// Check for dot-prefixed expansion packs
const dotExpansions = await resourceLocator.findFiles(".bmad-*", { cwd: installDir });
const dotExpansions = await resourceLocator.findFiles('.bmad-*', { cwd: installDir });
for (const dotExpansion of dotExpansions) {
if (dotExpansion !== ".bmad-core") {
if (dotExpansion !== '.bmad-core') {
const packPath = path.join(installDir, dotExpansion);
const packName = dotExpansion.substring(1); // remove the dot
const packName = dotExpansion.slice(1); // remove the dot
expansionPacks.push({
name: packName,
path: packPath
path: packPath,
});
}
}
// Check other dot folders that have config.yaml
const allDotFolders = await resourceLocator.findFiles(".*", { cwd: installDir });
const allDotFolders = await resourceLocator.findFiles('.*', { cwd: installDir });
for (const folder of allDotFolders) {
if (!folder.startsWith(".bmad-") && folder !== ".bmad-core") {
if (!folder.startsWith('.bmad-') && folder !== '.bmad-core') {
const packPath = path.join(installDir, folder);
const configPath = path.join(packPath, "config.yaml");
const configPath = path.join(packPath, 'config.yaml');
if (await fileManager.pathExists(configPath)) {
expansionPacks.push({
name: folder.substring(1), // remove the dot
path: packPath
name: folder.slice(1), // remove the dot
path: packPath,
});
}
}
@@ -167,13 +167,13 @@ class BaseIdeSetup {
* Get expansion pack agents
*/
async getExpansionPackAgents(packPath) {
const agentsDir = path.join(packPath, "agents");
const agentsDir = path.join(packPath, 'agents');
if (!(await fileManager.pathExists(agentsDir))) {
return [];
}
const agentFiles = await resourceLocator.findFiles("*.md", { cwd: agentsDir });
return agentFiles.map(file => path.basename(file, ".md"));
const agentFiles = await resourceLocator.findFiles('*.md', { cwd: agentsDir });
return agentFiles.map((file) => path.basename(file, '.md'));
}
/**
@@ -183,27 +183,28 @@ class BaseIdeSetup {
const agentContent = await fileManager.readFile(agentPath);
const agentTitle = await this.getAgentTitle(agentId, installDir);
const yamlContent = extractYamlFromAgent(agentContent);
let content = "";
let content = '';
if (format === 'mdc') {
// MDC format for Cursor
content = "---\n";
content += "description: \n";
content += "globs: []\n";
content += "alwaysApply: false\n";
content += "---\n\n";
content = '---\n';
content += 'description: \n';
content += 'globs: []\n';
content += 'alwaysApply: false\n';
content += '---\n\n';
content += `# ${agentId.toUpperCase()} Agent Rule\n\n`;
content += `This rule is triggered when the user types \`@${agentId}\` and activates the ${agentTitle} agent persona.\n\n`;
content += "## Agent Activation\n\n";
content += "CRITICAL: Read the full YAML, start activation to alter your state of being, follow startup section instructions, stay in this being until told to exit this mode:\n\n";
content += "```yaml\n";
content += yamlContent || agentContent.replace(/^#.*$/m, "").trim();
content += "\n```\n\n";
content += "## File Reference\n\n";
const relativePath = path.relative(installDir, agentPath).replace(/\\/g, '/');
content += '## Agent Activation\n\n';
content +=
'CRITICAL: Read the full YAML, start activation to alter your state of being, follow startup section instructions, stay in this being until told to exit this mode:\n\n';
content += '```yaml\n';
content += yamlContent || agentContent.replace(/^#.*$/m, '').trim();
content += '\n```\n\n';
content += '## File Reference\n\n';
const relativePath = path.relative(installDir, agentPath).replaceAll('\\', '/');
content += `The complete agent definition is available in [${relativePath}](mdc:${relativePath}).\n\n`;
content += "## Usage\n\n";
content += '## Usage\n\n';
content += `When the user types \`@${agentId}\`, activate this ${agentTitle} persona and follow all instructions defined in the YAML configuration above.\n`;
} else if (format === 'claude') {
// Claude Code format
@@ -211,7 +212,7 @@ class BaseIdeSetup {
content += `When this command is used, adopt the following agent persona:\n\n`;
content += agentContent;
}
return content;
}
@@ -224,4 +225,4 @@ class BaseIdeSetup {
}
}
module.exports = BaseIdeSetup;
module.exports = BaseIdeSetup;