feat: automatically create tasks.json when missing (Task #68)

This commit implements automatic tasks.json file creation when it doesn't exist:

- When tasks.json is missing or invalid, create a new one with { tasks: [] }
- Allows adding tasks immediately after initializing a project without parsing a PRD
- Replaces error with informative feedback about file creation
- Enables smoother workflow for new projects or directories

This change improves user experience by removing the requirement to parse a PRD
before adding the first task to a newly initialized project. Closes #494
This commit is contained in:
Eyal Toledano
2025-05-22 01:18:27 -04:00
parent 5e9bc28abe
commit 34df2c8bbd
6 changed files with 34 additions and 70 deletions

View File

@@ -146,10 +146,18 @@ async function addTask(
try {
// Read the existing tasks
const data = readJSON(tasksPath);
let data = readJSON(tasksPath);
// If tasks.json doesn't exist or is invalid, create a new one
if (!data || !data.tasks) {
report('Invalid or missing tasks.json.', 'error');
throw new Error('Invalid or missing tasks.json.');
report('tasks.json not found or invalid. Creating a new one.', 'info');
// Create default tasks data structure
data = {
tasks: []
};
// Ensure the directory exists and write the new file
writeJSON(tasksPath, data);
report('Created new tasks.json file with empty tasks array.', 'info');
}
// Find the highest task ID to determine the next ID