UNPKG

taskwerk

Version:

A task management CLI for developers and AI agents working together

158 lines (137 loc) • 5.32 kB
import { Command } from 'commander'; import { existsSync } from 'fs'; import { join } from 'path'; import { TaskwerkAPI } from '../api/taskwerk-api.js'; import { ConfigManager } from '../config/config-manager.js'; import { TaskwerkDatabase } from '../db/database.js'; import { getSchemaVersion } from '../db/schema.js'; import { Logger } from '../logging/logger.js'; export function statusCommand() { const status = new Command('status'); status .description('Show taskwerk repository status') .option('--format <format>', 'Output format (text, json)', 'text') .action(async options => { const logger = new Logger('status'); try { const taskwerkDir = '.taskwerk'; const dbPath = join(taskwerkDir, 'taskwerk.db'); const configPath = join(taskwerkDir, 'config.yml'); // Check if taskwerk is initialized const isInitialized = existsSync(taskwerkDir) && existsSync(dbPath); if (!isInitialized) { if (options.format === 'json') { console.log( JSON.stringify( { initialized: false, message: 'Taskwerk not initialized. Run "taskwerk init" first.', }, null, 2 ) ); } else { console.log('āŒ Taskwerk not initialized'); console.log('\nRun this command to get started:'); console.log(' taskwerk init'); } return; } // Gather system information const api = new TaskwerkAPI(); const configManager = new ConfigManager(); const database = new TaskwerkDatabase(); const db = database.connect(); // Get task statistics const stats = api.getTaskStats(); // Get configuration info const config = configManager.load(); // Get database info const schemaVersion = getSchemaVersion(db); // Get recent tasks const recentTasks = api.listTasks({ limit: 5, order_by: 'updated_at', order_dir: 'DESC', }); database.close(); if (options.format === 'json') { console.log( JSON.stringify( { initialized: true, taskwerk_directory: taskwerkDir, database: { path: dbPath, exists: existsSync(dbPath), schema_version: schemaVersion, }, configuration: { path: configPath, exists: existsSync(configPath), version: config.general?.version, }, statistics: stats, recent_tasks: recentTasks.map(t => ({ id: t.id, name: t.name, status: t.status, updated_at: t.updated_at, })), }, null, 2 ) ); return; } // Text format output console.log('šŸ“Š Taskwerk Status'); console.log('═'.repeat(50)); console.log(`šŸ“ Directory: ${taskwerkDir}`); console.log(`šŸ’¾ Database: ${existsSync(dbPath) ? 'āœ… Connected' : 'āŒ Missing'}`); console.log(`āš™ļø Configuration: ${existsSync(configPath) ? 'āœ… Loaded' : 'āŒ Missing'}`); console.log(`šŸ—ƒļø Schema version: ${schemaVersion}`); console.log('\nšŸ“ˆ Task Statistics:'); console.log(` Total tasks: ${stats.total}`); console.log(` ā³ Todo: ${stats.by_status.todo || 0}`); console.log(` šŸ”„ In Progress: ${stats.in_progress || 0}`); console.log(` 🚫 Blocked: ${stats.by_status.blocked || 0}`); console.log(` āœ… Completed: ${stats.completed || 0}`); console.log(` āŒ Cancelled: ${stats.by_status.cancelled || 0}`); if (stats.overdue > 0) { console.log(` āš ļø Overdue: ${stats.overdue}`); } console.log('\nšŸŽÆ By Priority:'); console.log(` 🚨 Critical: ${stats.by_priority.critical || 0}`); console.log(` šŸ”“ High: ${stats.by_priority.high || 0}`); console.log(` 🟔 Medium: ${stats.by_priority.medium || 0}`); console.log(` šŸ”µ Low: ${stats.by_priority.low || 0}`); if (recentTasks.length > 0) { console.log('\nšŸ“ Recent Activity:'); recentTasks.forEach((task, index) => { const statusEmoji = { 'todo': 'ā³', 'in-progress': 'šŸ”„', 'in_progress': 'šŸ”„', 'blocked': '🚫', 'done': 'āœ…', 'completed': 'āœ…', 'cancelled': 'āŒ', }; const updated = new Date(task.updated_at).toLocaleDateString(); console.log( ` ${index + 1}. ${statusEmoji[task.status] || 'ā³'} ${task.id} - ${task.name} (${updated})` ); }); } console.log('═'.repeat(50)); } catch (error) { logger.error('Failed to get status', error); console.error('āŒ Failed to get status:', error.message); process.exit(1); } }); return status; }