diff --git a/src/cli/commands/task.ts b/src/cli/commands/task.ts index 50a9c91..fbebd44 100644 --- a/src/cli/commands/task.ts +++ b/src/cli/commands/task.ts @@ -1,10 +1,6 @@ import { input, select } from '@inquirer/prompts'; -import { join } from 'path'; -import { getEntityDir } from '../../core/paths.js'; -import { getNextId } from '../../core/counter.js'; -import { readEntity, writeEntity } from '../../core/files.js'; -import { TaskSchema, type Task } from '../../core/schema.js'; -import { Index } from '../../core/index.js'; +import { createTask, listTasks, getTask, claimTask, doneTask } from '../../core/services/taskService.js'; +import type { Task } from '../../core/schema.js'; export async function taskCreate(cwd: string, options: Partial = {}): Promise { const title = options.title ?? await input({ message: 'Task title:' }); @@ -19,84 +15,34 @@ export async function taskCreate(cwd: string, options: Partial = {}): Prom }); const priority = options.priority ?? 'medium'; - const now = new Date().toISOString(); - const task: Task = TaskSchema.parse({ - id: getNextId(cwd, 'task'), - title, - description: options.description ?? '', - status: 'open', - priority, - role, - createdAt: now, - updatedAt: now, - }); - - const filePath = join(getEntityDir(cwd, 'tasks'), `${task.id}.md`); - writeEntity(filePath, task, `# ${task.title}\n\n${task.description}`); - - const index = new Index(cwd); - index.upsert(toIndexEntry(task, filePath)); - index.close(); - + const task = createTask(cwd, { title, role, priority }); console.log(`Created ${task.id}: ${task.title}`); } export function taskList(cwd: string, filters?: { status?: string; role?: string }): void { - const index = new Index(cwd); - const tasks = index.list('task', filters); - index.close(); - + const tasks = listTasks(cwd, filters); if (tasks.length === 0) { console.log('No tasks found.'); return; } - for (const t of tasks) { console.log(`${t.id} [${t.status}] (${t.role ?? 'unassigned'}) ${t.title}`); } } export function taskShow(cwd: string, id: string): void { - const filePath = join(getEntityDir(cwd, 'tasks'), `${id}.md`); - const { frontmatter, body } = readEntity(filePath); - console.log(`# ${frontmatter.title}`); - console.log(`Status: ${frontmatter.status} | Role: ${frontmatter.role ?? '-'} | Priority: ${frontmatter.priority}`); + const { task, body } = getTask(cwd, id); + console.log(`# ${task.title}`); + console.log(`Status: ${task.status} | Role: ${task.role ?? '-'} | Priority: ${task.priority}`); console.log('\n' + body); } export function taskClaim(cwd: string, id: string, agentName: string): void { - updateTask(cwd, id, { status: 'in_progress', assignedTo: agentName }); + claimTask(cwd, id, agentName); console.log(`${id} claimed by ${agentName}.`); } export function taskDone(cwd: string, id: string): void { - updateTask(cwd, id, { status: 'done' }); + doneTask(cwd, id); console.log(`${id} marked as done.`); } - -function updateTask(cwd: string, id: string, patch: Partial): void { - const filePath = join(getEntityDir(cwd, 'tasks'), `${id}.md`); - const { frontmatter, body } = readEntity(filePath); - const task = TaskSchema.parse({ ...frontmatter, ...patch, updatedAt: new Date().toISOString() }); - writeEntity(filePath, task, body); - - const index = new Index(cwd); - index.upsert(toIndexEntry(task, filePath)); - index.close(); -} - -function toIndexEntry(task: Task, filePath: string) { - return { - id: task.id, - type: 'task', - title: task.title, - content: `${task.description} ${task.tags.join(' ')}`, - filePath, - createdAt: task.createdAt, - updatedAt: task.updatedAt, - status: task.status, - role: task.role, - assignedTo: task.assignedTo, - tags: JSON.stringify(task.tags), - }; -}