@jjdenhertog/ai-driven-development
Version:
AI-driven development workflow with learning capabilities for Claude
59 lines • 2.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildSessionReport = buildSessionReport;
const extractUserPrompt_1 = require("./extractUserPrompt");
const extractNotifications_1 = require("./extractNotifications");
const processToolExecutions_1 = require("./processToolExecutions");
const calculateTotalTokens_1 = require("./calculateTotalTokens");
const determineSuccess_1 = require("./determineSuccess");
function buildSessionReport(sessionId, taskId, taskName, logEntries, transcriptEntries, exitCode) {
var _a, _b;
const timeline = [];
// Extract user prompt from transcript
const userPrompt = (0, extractUserPrompt_1.extractUserPrompt)(transcriptEntries) || 'No user prompt found';
// Get start and end times
const startTime = (_a = logEntries[0]) === null || _a === void 0 ? void 0 : _a.timestamp;
const endTime = (_b = logEntries.at(-1)) === null || _b === void 0 ? void 0 : _b.timestamp;
const totalDuration = startTime && endTime ?
new Date(endTime).getTime() - new Date(startTime).getTime() : 0;
// Process notifications from transcript
const notifications = (0, extractNotifications_1.extractNotifications)(transcriptEntries);
// Process tool executions from logs
const toolExecutions = (0, processToolExecutions_1.processToolExecutions)(logEntries);
// Merge timeline events
timeline.push(...notifications, ...toolExecutions);
// Sort timeline by timestamp
timeline.sort((a, b) => {
if (!a.timestamp || !b.timestamp)
return 0;
return new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime();
});
// Extract metadata
const toolsUsed = [...new Set(logEntries
.filter(e => { var _a; return (_a = e.data) === null || _a === void 0 ? void 0 : _a.tool_name; })
.map(e => e.data.tool_name))];
// Determine success based on multiple factors
const successResult = (0, determineSuccess_1.determineSuccess)({
exitCode,
timeline,
transcriptEntries
});
return {
session_id: sessionId,
task_id: taskId,
task_name: taskName,
user_prompt: userPrompt,
start_time: startTime,
end_time: endTime,
total_duration_ms: totalDuration,
success: successResult.success,
success_reason: successResult.reason,
timeline,
metadata: {
exit_code: exitCode,
tools_used: toolsUsed,
total_tokens: (0, calculateTotalTokens_1.calculateTotalTokens)(transcriptEntries)
}
};
}
//# sourceMappingURL=buildSessionReport.js.map