Update packages/core/src/tools/exit-plan-mode.ts

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
Adib234
2026-04-01 09:44:13 -04:00
committed by GitHub
parent 8251ac52d6
commit ee5ab094e2
+8 -6
View File
@@ -270,12 +270,14 @@ Read and follow the plan strictly during implementation.`,
};
} else {
try {
let version = 1;
let backupPath = `${resolvedPlanPath}.v${version}`;
while (fs.existsSync(backupPath)) {
version++;
backupPath = `${resolvedPlanPath}.v${version}`;
}
const files = await fsPromises.readdir(path.dirname(resolvedPlanPath));
const base = path.basename(resolvedPlanPath);
const versions = files
.filter((f) => f.startsWith(`${base}.v`))
.map((f) => parseInt(f.slice(base.length + 2), 10))
.filter((v) => !isNaN(v));
const nextVersion = (versions.length > 0 ? Math.max(...versions) : 0) + 1;
const backupPath = `${resolvedPlanPath}.v${nextVersion}`;
const content = await fsPromises.readFile(resolvedPlanPath, 'utf8');
await fsPromises.writeFile(backupPath, content, 'utf8');
} catch (err) {