fix(tasks): sync status to worktree implementation plan to prevent reset (#243) (#323)

Co-authored-by: Black Circle Sentinel <mludlow000@icloud.com>
This commit is contained in:
Alex
2025-12-26 21:19:41 +01:00
committed by GitHub
parent 661e47c341
commit cb6b216534
@@ -554,23 +554,37 @@ export function registerWorktreeHandlers(
}
// Persist the status change to implementation_plan.json
const planPath = path.join(specDir, AUTO_BUILD_PATHS.IMPLEMENTATION_PLAN);
try {
if (existsSync(planPath)) {
const { readFileSync, writeFileSync } = require('fs');
const planContent = readFileSync(planPath, 'utf-8');
const plan = JSON.parse(planContent);
plan.status = newStatus;
plan.planStatus = planStatus;
plan.updated_at = new Date().toISOString();
if (staged) {
plan.stagedAt = new Date().toISOString();
plan.stagedInMainProject = true;
// Issue #243: We must update BOTH the main project's plan AND the worktree's plan (if it exists)
// because ProjectStore prefers the worktree version when deduplicating tasks.
const planPaths = [
path.join(specDir, AUTO_BUILD_PATHS.IMPLEMENTATION_PLAN), // Main project
path.join(worktreePath, AUTO_BUILD_PATHS.IMPLEMENTATION_PLAN) // Worktree
];
const { readFileSync, writeFileSync } = require('fs');
for (const planPath of planPaths) {
try {
if (existsSync(planPath)) {
const planContent = readFileSync(planPath, 'utf-8');
const plan = JSON.parse(planContent);
plan.status = newStatus;
plan.planStatus = planStatus;
plan.updated_at = new Date().toISOString();
if (staged) {
plan.stagedAt = new Date().toISOString();
plan.stagedInMainProject = true;
}
writeFileSync(planPath, JSON.stringify(plan, null, 2));
}
} catch (persistError) {
// Only log error if main plan fails; worktree plan might legitimately be missing or read-only
if (planPath.includes(specDir)) {
console.error('Failed to persist task status to main plan:', persistError);
} else {
debug('Failed to persist task status to worktree plan (non-critical):', persistError);
}
writeFileSync(planPath, JSON.stringify(plan, null, 2));
}
} catch (persistError) {
console.error('Failed to persist task status:', persistError);
}
const mainWindow = getMainWindow();