taskwerk
Version:
A task management CLI for developers and AI agents working together
158 lines (137 loc) ⢠5.32 kB
JavaScript
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;
}