UNPKG

@intellectronica/ruler

Version:

Ruler — apply the same rules to all coding agents

89 lines (88 loc) 3.41 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.CrushAgent = void 0; const fs = __importStar(require("fs/promises")); const path = __importStar(require("path")); class CrushAgent { getIdentifier() { return 'crush'; } getName() { return 'Crush'; } getDefaultOutputPath(projectRoot) { return { instructions: path.join(projectRoot, 'CRUSH.md'), mcp: path.join(projectRoot, '.crush.json'), }; } async applyRulerConfig(concatenatedRules, projectRoot, rulerMcpJson, agentConfig) { const outputPaths = this.getDefaultOutputPath(projectRoot); const instructionsPath = agentConfig?.outputPathInstructions ?? outputPaths['instructions']; const mcpPath = agentConfig?.outputPathConfig ?? outputPaths['mcp']; await fs.writeFile(instructionsPath, concatenatedRules); // Always transform from mcpServers ({ mcpServers: ... }) to { mcp: ... } for Crush let finalMcpConfig = { mcp: {} }; try { const existingMcpConfig = JSON.parse(await fs.readFile(mcpPath, 'utf-8')); if (existingMcpConfig && typeof existingMcpConfig === 'object') { finalMcpConfig = { ...existingMcpConfig, mcp: { ...(existingMcpConfig.mcp || {}), ...(rulerMcpJson?.mcpServers ?? {}), }, }; } else if (rulerMcpJson) { finalMcpConfig = { mcp: (rulerMcpJson?.mcpServers ?? {}), }; } } catch { if (rulerMcpJson) { finalMcpConfig = { mcp: (rulerMcpJson?.mcpServers ?? {}), }; } } if (Object.keys(finalMcpConfig.mcp).length > 0) { await fs.writeFile(mcpPath, JSON.stringify(finalMcpConfig, null, 2)); } } } exports.CrushAgent = CrushAgent;