diff --git a/src/aggregator/index.ts b/src/aggregator/index.ts index 5deb268..cb64d1d 100644 --- a/src/aggregator/index.ts +++ b/src/aggregator/index.ts @@ -538,10 +538,11 @@ export class BacklogAggregator { return Response.json({ error: "Task not found" }, { status: 404 }); } - // Find the task file path - const tasksDir = join(projectPath, "backlog", "tasks"); - const taskFileName = `${taskId}.md`; - const taskFilePath = join(tasksDir, taskFileName); + // Use the stored file path from when the task was loaded + const taskFilePath = task.filePath; + if (!taskFilePath) { + return Response.json({ error: "Task file path not found" }, { status: 404 }); + } // Read the current task file let content: string; @@ -695,12 +696,15 @@ created_date: '${dateStr}' return Response.json({ error: "Task not found" }, { status: 404 }); } - // Find the task file path - const tasksDir = join(projectPath, "backlog", "tasks"); + // Use the stored file path from when the task was loaded + const taskFilePath = task.filePath; + if (!taskFilePath) { + return Response.json({ error: "Task file path not found" }, { status: 404 }); + } + + // Build archive path preserving the original filename const archiveDir = join(projectPath, "backlog", "archive", "tasks"); - const taskFileName = `${taskId}.md`; - const taskFilePath = join(tasksDir, taskFileName); - const archiveFilePath = join(archiveDir, taskFileName); + const archiveFilePath = join(archiveDir, basename(taskFilePath)); // Ensure archive directory exists try { @@ -754,10 +758,11 @@ created_date: '${dateStr}' return Response.json({ error: "Task not found" }, { status: 404 }); } - // Find the task file path - const tasksDir = join(projectPath, "backlog", "tasks"); - const taskFileName = `${taskId}.md`; - const taskFilePath = join(tasksDir, taskFileName); + // Use the stored file path from when the task was loaded + const taskFilePath = task.filePath; + if (!taskFilePath) { + return Response.json({ error: "Task file path not found" }, { status: 404 }); + } // Delete the file try {