UNPKG

@jjdenhertog/ai-driven-development

Version:

AI-driven development workflow with learning capabilities for Claude

96 lines 5.34 kB
"use strict"; 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.createSessionReport = createSessionReport; /* eslint-disable max-lines */ const fs_extra_1 = require("fs-extra"); const node_path_1 = require("node:path"); const logger_1 = require("../logger"); const buildSessionReport_1 = require("../session-report/buildSessionReport"); const findTranscriptPath_1 = require("../session-report/findTranscriptPath"); const parseLogFile_1 = require("../session-report/parseLogFile"); const parseTranscriptFile_1 = require("../session-report/parseTranscriptFile"); const saveErrorReport_1 = require("../session-report/saveErrorReport"); function createSessionReport(options) { return __awaiter(this, void 0, void 0, function* () { var _a; const { taskId, taskName, worktreePath, logsDir, exitCode, fileName } = options; const debugLogsPath = (0, node_path_1.join)(worktreePath, 'debug_logs'); const outputPath = (0, node_path_1.join)(logsDir, `${fileName}.json`); (0, fs_extra_1.ensureDirSync)(logsDir); try { // Check if debug logs directory exists if (!(0, fs_extra_1.existsSync)(debugLogsPath)) { (0, logger_1.log)('No debug logs found, creating error report', 'warn'); return yield (0, saveErrorReport_1.saveErrorReport)({ taskId, taskName, errorMessage: 'Debug logs directory not found', outputPath: (0, node_path_1.join)(logsDir, `${fileName}.json`) }); } // Find the first log file const logFiles = (0, fs_extra_1.readdirSync)(debugLogsPath).filter(f => f.endsWith('.jsonl')); if (logFiles.length === 0) { (0, logger_1.log)('No log files found in debug_logs', 'warn'); return yield (0, saveErrorReport_1.saveErrorReport)({ taskId, taskName, errorMessage: 'No log files found in debug_logs directory', outputPath: (0, node_path_1.join)(logsDir, `${fileName}.json`) }); } const logFilePath = (0, node_path_1.join)(debugLogsPath, logFiles[0]); (0, logger_1.log)(`Processing log file: ${logFiles[0]}`, 'info'); // Read and parse the log file const logEntries = (0, parseLogFile_1.parseLogFile)(logFilePath); // Extract session ID from the first valid entry const sessionId = (_a = logEntries.find(entry => entry.sessionId)) === null || _a === void 0 ? void 0 : _a.sessionId; if (!sessionId) { (0, logger_1.log)('Could not find session ID in logs', 'warn'); return yield (0, saveErrorReport_1.saveErrorReport)({ taskId, taskName, errorMessage: 'Session ID not found in logs', outputPath: (0, node_path_1.join)(logsDir, `${fileName}.json`) }); } // Find transcript path from logs const transcriptPath = (0, findTranscriptPath_1.findTranscriptPath)(logEntries); let transcriptEntries = []; if (transcriptPath && (0, fs_extra_1.existsSync)(transcriptPath)) { transcriptEntries = (0, parseTranscriptFile_1.parseTranscriptFile)(transcriptPath); } // Build the session report const report = (0, buildSessionReport_1.buildSessionReport)(sessionId, taskId, taskName, logEntries, transcriptEntries, exitCode); // Save the report (0, fs_extra_1.writeFileSync)(outputPath, JSON.stringify(report, null, 2)); (0, logger_1.log)(`Session report created: ${outputPath}`, 'success'); // Clean up debug logs try { (0, fs_extra_1.rmSync)(debugLogsPath, { recursive: true, force: true }); (0, logger_1.log)('Debug logs cleaned up', 'info'); } catch (cleanupError) { (0, logger_1.log)(`Failed to clean up debug logs: ${String(cleanupError)}`, 'warn'); } return report; } catch (error) { (0, logger_1.log)(`Error creating session report: ${String(error)}`, 'error'); return (0, saveErrorReport_1.saveErrorReport)({ errorMessage: `Failed to create session report: ${error instanceof Error ? error.message : String(error)}`, outputPath }); } }); } //# sourceMappingURL=createSessionReport.js.map