@jjdenhertog/ai-driven-development
Version:
AI-driven development workflow with learning capabilities for Claude
71 lines • 2.86 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
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() {
return __awaiter(this, void 0, void 0, function* () {
// 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=logCommand.js.map