fix(#657): create backup before STATE.md regeneration

/gsd:health --repair now creates a timestamped backup
(STATE.md.bak-YYYY-MM-DDTHH-MM-SS) before overwriting STATE.md,
preventing accidental data loss of accumulated context.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Lex Christopherson
2026-02-19 12:21:04 -06:00
parent 8fd7d0b635
commit bf2f57105f

View File

@@ -3830,6 +3830,13 @@ function cmdValidateHealth(cwd, options, raw) {
break;
}
case 'regenerateState': {
// Create timestamped backup before overwriting
if (fs.existsSync(statePath)) {
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
const backupPath = `${statePath}.bak-${timestamp}`;
fs.copyFileSync(statePath, backupPath);
repairActions.push({ action: 'backupState', success: true, path: backupPath });
}
// Generate minimal STATE.md from ROADMAP.md structure
const milestone = getMilestoneInfo(cwd);
let stateContent = `# Session State\n\n`;