@gonzui/claude-task-manager
Version:
Task management extension for Claude Code with archiving and history
126 lines • 5.39 kB
JavaScript
;
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.HistoryManager = void 0;
const fs = __importStar(require("fs-extra"));
const path = __importStar(require("path"));
const date_fns_1 = require("date-fns");
const types_1 = require("../types");
class HistoryManager {
constructor(taskFile, archiveDir, i18n) {
this.taskFile = taskFile;
this.archiveDir = archiveDir;
this.i18n = i18n;
}
async getHistory(limit = 10) {
try {
if (!await fs.pathExists(this.archiveDir)) {
return [];
}
const files = await fs.readdir(this.archiveDir);
const taskFiles = files
.filter(file => file.endsWith('_task.md'))
.sort()
.reverse()
.slice(0, limit);
const history = [];
for (const file of taskFiles) {
const filePath = path.join(this.archiveDir, file);
const content = await fs.readFile(filePath, 'utf8');
const stats = await fs.stat(filePath);
const titleMatch = content.match(/# (.+)/);
const title = titleMatch ? titleMatch[1] : 'Untitled';
const date = file.split('_')[0];
history.push({
file,
title,
date,
path: filePath,
size: stats.size
});
}
return history;
}
catch (error) {
throw new types_1.FileSystemError(this.i18n.t('errors.historyFailed', { error: error instanceof Error ? error.message : 'Unknown error' }), this.archiveDir, 'read');
}
}
async getStatus() {
try {
const currentTaskExists = await fs.pathExists(this.taskFile);
let currentTask = null;
let currentTaskSize;
if (currentTaskExists) {
const content = await fs.readFile(this.taskFile, 'utf8');
const stats = await fs.stat(this.taskFile);
const titleMatch = content.match(/# (.+)/);
currentTask = titleMatch ? titleMatch[1] : 'Untitled Task';
currentTaskSize = stats.size;
}
const archiveFiles = await fs.pathExists(this.archiveDir)
? (await fs.readdir(this.archiveDir)).filter(f => f.endsWith('_task.md'))
: [];
let lastRun = null;
let totalExecutions = 0;
if (currentTaskExists) {
const content = await fs.readFile(this.taskFile, 'utf8');
const logMatches = content.match(/## Execution Log - (.+?) \(/g);
if (logMatches && logMatches.length > 0) {
totalExecutions = logMatches.length;
const lastLogMatch = logMatches[logMatches.length - 1];
const timeMatch = lastLogMatch.match(/## Execution Log - (.+?) \(/);
lastRun = timeMatch ? timeMatch[1] : null;
}
}
return {
currentTask,
archivedCount: archiveFiles.length,
lastRun,
totalExecutions,
currentTaskSize
};
}
catch (error) {
throw new types_1.TaskManagerError(this.i18n.t('errors.statusFailed', { error: error instanceof Error ? error.message : 'Unknown error' }), 'GET_STATUS_ERROR');
}
}
async logExecution(result) {
const status = result.success ? ' Success' : ' Failed';
const logEntry = `\n\n## Execution Log - ${(0, date_fns_1.format)(new Date(result.timestamp), 'yyyy-MM-dd HH:mm:ss')} (${result.duration}ms)\n\n**Status:** ${status}\n\n${result.success ? result.output : result.error}\n\n---\n`;
await fs.appendFile(this.taskFile, logEntry);
}
}
exports.HistoryManager = HistoryManager;
//# sourceMappingURL=HistoryManager.js.map