UNPKG

@gonzui/claude-task-manager

Version:

Task management extension for Claude Code with archiving and history

147 lines 5.84 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; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProgressTracker = void 0; exports.parseProgressContent = parseProgressContent; const fs = __importStar(require("fs-extra")); const chalk_1 = __importDefault(require("chalk")); /** * Parse task.md content into progress numbers. Standalone so callers that hold * content rather than the active task file (e.g. TaskStore listing the stored * tasks) reuse the exact same checkbox/title rules. */ function parseProgressContent(content) { const titleMatch = content.match(/^#\s+(.+)$/m); const title = titleMatch ? titleMatch[1] : 'Untitled Task'; const checkboxPattern = /^[\s]*-\s+\[([ xX])\]\s+(.+)$/gm; const tasks = []; let match; while ((match = checkboxPattern.exec(content)) !== null) { tasks.push({ completed: match[1].toLowerCase() === 'x', text: match[2].trim() }); } const total = tasks.length; const completed = tasks.filter(t => t.completed).length; const percentage = total > 0 ? Math.round((completed / total) * 100) : 0; return { total, completed, percentage, tasks, title }; } class ProgressTracker { constructor(taskFile, i18n) { this.taskFile = taskFile; this.i18n = i18n; } async getProgress() { if (!await fs.pathExists(this.taskFile)) { throw new Error('No task.md file found'); } const content = await fs.readFile(this.taskFile, 'utf8'); return this.parseProgress(content); } /** * Mark the given 1-based checkbox numbers (matching `progress` output order) * as completed or pending and persist the change to task.md. */ async setCompletion(indices, completed) { if (!await fs.pathExists(this.taskFile)) { throw new Error('No task.md file found'); } const content = await fs.readFile(this.taskFile, 'utf8'); const mark = completed ? 'x' : ' '; const requested = new Set(indices); const updated = []; let counter = 0; const checkboxLine = /^([ \t]*-\s+\[)([ xX])(\]\s+.+)$/gm; const newContent = content.replace(checkboxLine, (full, pre, _state, post) => { counter += 1; if (requested.has(counter)) { updated.push(counter); return `${pre}${mark}${post}`; } return full; }); const total = counter; const invalid = indices.filter((n) => n < 1 || n > total); if (updated.length > 0) { await fs.writeFile(this.taskFile, newContent); } return { updated, invalid, result: this.parseProgress(newContent) }; } parseProgress(content) { return parseProgressContent(content); } formatProgressBar(percentage, width = 20) { const filled = Math.round((percentage / 100) * width); const empty = width - filled; const bar = '█'.repeat(filled) + '░'.repeat(empty); return bar; } formatOutput(result) { const lines = []; // Header lines.push(chalk_1.default.blue(`${this.i18n.t('commands.progress.title')} ${result.title}`)); lines.push(''); if (result.total === 0) { lines.push(chalk_1.default.yellow(this.i18n.t('commands.progress.noTasks'))); return lines.join('\n'); } // Progress bar const bar = this.formatProgressBar(result.percentage); const percentColor = result.percentage === 100 ? chalk_1.default.green : result.percentage >= 50 ? chalk_1.default.yellow : chalk_1.default.red; const count = this.i18n.t('commands.progress.count', { completed: result.completed, total: result.total }); lines.push(`${bar} ${percentColor(`${result.percentage}%`)} ${count}`); lines.push(''); // Task list for (const task of result.tasks) { if (task.completed) { lines.push(chalk_1.default.green(` ✅ ${task.text}`)); } else { lines.push(chalk_1.default.gray(` ⬜ ${task.text}`)); } } return lines.join('\n'); } } exports.ProgressTracker = ProgressTracker; //# sourceMappingURL=ProgressTracker.js.map