scai
Version:
> **AI-powered CLI for local code analysis, commit message suggestions, and natural-language queries.** 100% local, private, GDPR-friendly, made in Denmark/EU with ā¤ļø.
53 lines (52 loc) ⢠1.6 kB
JavaScript
import fs from "fs";
import path from "path";
import { log } from "../utils/log.js";
import { SCAI_HOME, PROMPT_LOG_PATH } from "../constants.js";
/**
* Ensures SCAI_HOME exists before writing logs.
*/
function ensureHomeDir() {
if (!fs.existsSync(SCAI_HOME))
fs.mkdirSync(SCAI_HOME, { recursive: true });
}
/**
* Creates a formatted header for visual clarity in logs.
*/
function formatHeader(title) {
const divider = "=".repeat(68);
return `\n\n${divider}\nš ${title}\n${divider}\n`;
}
/**
* Overwrites the prompt log with a new prompt.
*/
export function logPrompt(prompt) {
try {
ensureHomeDir();
const entry = formatHeader("Prompt Updated") + prompt + "\n";
fs.writeFileSync(PROMPT_LOG_PATH, entry, "utf-8");
log(`š Prompt written to ${PROMPT_LOG_PATH}`);
}
catch (err) {
log("ā Failed to write prompt log:", err);
}
}
/**
* Appends module input/output data to a separate log file.
* Automatically stringifies objects.
*/
export function logInputOutput(stepName, type, content) {
const ioLogPath = path.join(SCAI_HOME, "input_output.log");
try {
ensureHomeDir();
const contentStr = typeof content === "string" ? content.trim() : JSON.stringify(content, null, 2);
const entry = formatHeader(`${type.toUpperCase()} | ${stepName}`) +
contentStr +
"\n" +
"=".repeat(68) +
"\n";
fs.appendFileSync(ioLogPath, entry, "utf-8");
}
catch (err) {
log(`ā Failed to append ${type} for ${stepName}:`, err);
}
}