@intellectronica/ruler
Version:
Ruler — apply the same rules to all coding agents
87 lines (86 loc) • 3.25 kB
JavaScript
;
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.AiderAgent = void 0;
const path = __importStar(require("path"));
const FileSystemUtils_1 = require("../core/FileSystemUtils");
const fs = __importStar(require("fs/promises"));
const yaml = __importStar(require("js-yaml"));
/**
* Aider agent adapter (stub implementation).
*/
class AiderAgent {
getIdentifier() {
return 'aider';
}
getName() {
return 'Aider';
}
async applyRulerConfig(concatenatedRules, projectRoot, rulerMcpJson, // eslint-disable-line @typescript-eslint/no-unused-vars
agentConfig) {
const mdPath = agentConfig?.outputPathInstructions ??
this.getDefaultOutputPath(projectRoot).instructions;
await (0, FileSystemUtils_1.backupFile)(mdPath);
await (0, FileSystemUtils_1.writeGeneratedFile)(mdPath, concatenatedRules);
const cfgPath = agentConfig?.outputPathConfig ??
this.getDefaultOutputPath(projectRoot).config;
let doc = {};
try {
await fs.access(cfgPath);
await (0, FileSystemUtils_1.backupFile)(cfgPath);
const raw = await fs.readFile(cfgPath, 'utf8');
doc = (yaml.load(raw) || {});
}
catch {
doc = {};
}
if (!Array.isArray(doc.read)) {
doc.read = [];
}
const name = path.basename(mdPath);
if (!doc.read.includes(name)) {
doc.read.push(name);
}
const yamlStr = yaml.dump(doc);
await (0, FileSystemUtils_1.writeGeneratedFile)(cfgPath, yamlStr);
}
getDefaultOutputPath(projectRoot) {
return {
instructions: path.join(projectRoot, 'ruler_aider_instructions.md'),
config: path.join(projectRoot, '.aider.conf.yml'),
};
}
}
exports.AiderAgent = AiderAgent;