UNPKG

hataraku

Version:

An autonomous coding agent for building AI-powered development tools. The name "Hataraku" (働く) means "to work" in Japanese.

131 lines 5.2 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.TaskHistory = void 0; const fs = __importStar(require("fs/promises")); const path = __importStar(require("path")); const config_paths_1 = require("../config/config-paths"); class TaskHistory { historyDir; constructor() { const paths = (0, config_paths_1.getConfigPaths)(); this.historyDir = paths.logsDir; } async ensureHistoryDir() { await fs.mkdir(this.historyDir, { recursive: true }); } async saveTask(entry) { await this.ensureHistoryDir(); const taskDir = path.join(this.historyDir, entry.taskId); await fs.mkdir(taskDir, { recursive: true }); // Save task metadata const metadataPath = path.join(taskDir, 'metadata.json'); const metadata = { taskId: entry.taskId, timestamp: entry.timestamp, task: entry.task, tokensIn: entry.tokensIn, tokensOut: entry.tokensOut, cacheWrites: entry.cacheWrites, cacheReads: entry.cacheReads, totalCost: entry.totalCost, model: entry.model, mcpServers: entry.debug?.mcpServers }; await fs.writeFile(metadataPath, JSON.stringify(metadata, null, 2)); // Save conversation history const historyPath = path.join(taskDir, 'conversation.json'); await fs.writeFile(historyPath, JSON.stringify(entry.messages, null, 2)); // Save debug information if present if (entry.debug) { const debugPath = path.join(taskDir, 'debug.json'); await fs.writeFile(debugPath, JSON.stringify(entry.debug, null, 2)); } } async getTask(taskId) { try { const taskDir = path.join(this.historyDir, taskId); const metadataPath = path.join(taskDir, 'metadata.json'); const historyPath = path.join(taskDir, 'conversation.json'); const [metadataContent, historyContent, debugContent] = await Promise.all([ fs.readFile(metadataPath, 'utf-8'), fs.readFile(historyPath, 'utf-8'), fs.readFile(path.join(taskDir, 'debug.json'), 'utf-8').catch(() => null) ]); const metadata = JSON.parse(metadataContent); const messages = JSON.parse(historyContent); const debug = debugContent ? JSON.parse(debugContent) : undefined; return { ...metadata, messages, debug }; } catch (error) { return null; } } async listTasks() { await this.ensureHistoryDir(); const tasks = []; try { const taskDirs = await fs.readdir(this.historyDir); for (const taskId of taskDirs) { try { const metadataPath = path.join(this.historyDir, taskId, 'metadata.json'); const metadataContent = await fs.readFile(metadataPath, 'utf-8'); const metadata = JSON.parse(metadataContent); tasks.push({ taskId: metadata.taskId, timestamp: metadata.timestamp, task: metadata.task, }); } catch (error) { // Skip invalid task directories continue; } } } catch (error) { // Return empty array if history directory doesn't exist return []; } // Sort by timestamp, most recent first return tasks.sort((a, b) => b.timestamp - a.timestamp); } } exports.TaskHistory = TaskHistory; //# sourceMappingURL=task-history.js.map