@jjdenhertog/ai-driven-development
Version:
AI-driven development workflow with learning capabilities for Claude
59 lines • 1.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.logCommand = logCommand;
const fs_extra_1 = require("fs-extra");
const node_fs_1 = require("node:fs");
const node_path_1 = require("node:path");
function logCommand() {
// Get log configuration
const logDir = process.env.AIDEV_LOG_DIR || (0, node_path_1.join)(process.cwd(), 'debug_logs');
// Ensure log directory exists
(0, fs_extra_1.ensureDirSync)(logDir);
const timestamp = new Date().toISOString();
let inputData = '';
let sessionId = process.env.AIDEV_SESSION_ID || new Date().toISOString().replace(/[.:]/g, '-');
// Read from stdin
try {
inputData = (0, node_fs_1.readFileSync)(0, 'utf8');
}
catch (_err) {
// If we can't read stdin, just log with empty data
}
// Try to extract sessionId from Claude hook data
if (inputData) {
try {
const hookData = JSON.parse(inputData);
if (hookData.session_id) {
sessionId = hookData.session_id;
}
}
catch (_parseErr) {
// If parsing fails, we'll use the default sessionId
}
}
// Define the log file path using the sessionId
const logFile = (0, node_path_1.join)(logDir, `session-${sessionId}.jsonl`);
// Create log entry
let parsedData = {};
try {
parsedData = inputData ? JSON.parse(inputData) : {};
}
catch (_err) {
parsedData = { raw: inputData };
}
const logEntry = {
timestamp,
type: 'raw',
sessionId,
data: parsedData,
inputData: inputData || '(empty)'
};
// Append to log file
try {
(0, node_fs_1.appendFileSync)(logFile, `${JSON.stringify(logEntry)}\n`);
}
catch (_err) {
// Silent fail if we can't write to log file
}
}
//# sourceMappingURL=log.js.map