spaider
Version:
Deterministic-first AI code assistant that crawls your codebase to implement changes using open source LLMs
39 lines • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeChanges = void 0;
const utils_1 = require("../lib/utils");
const logger_1 = require("../services/logger");
const writeChanges = async (ctx) => {
if (!ctx.changes) {
throw new Error("Changes must be generated before writing to file");
}
if (ctx.changes.length === 0) {
logger_1.Logger.info("No changes to write to file");
return ctx;
}
const outputFileName = "CHANGES.md";
const outputPath = outputFileName;
logger_1.Logger.info("Writing changes to file", outputPath);
const changesPerFile = ctx.changes.reduce((acc, curr) => {
acc[curr.filePath] = acc[curr.filePath] || [];
acc[curr.filePath].push(curr);
return acc;
}, {});
const formattedFiles = Object.entries(changesPerFile)
.map(([filePath, fileChanges]) => (0, utils_1.formatWriteChanges)(filePath, fileChanges))
.join("\n");
const header = [
"# Code Changes",
"Review the changes and apply manually to your codebase.",
"",
"---",
"",
].join("\n");
const fullContent = header + formattedFiles;
await (0, utils_1.safeWriteFile)(outputPath, fullContent, ctx.projectRoot);
logger_1.Logger.info("Changes written successfully to", outputPath);
ctx.result.createdFiles.push(outputPath);
return ctx;
};
exports.writeChanges = writeChanges;
//# sourceMappingURL=write.js.map