From ee5ab094e2f70c79e894e77594cfbd373c880376 Mon Sep 17 00:00:00 2001 From: Adib234 <30782825+Adib234@users.noreply.github.com> Date: Wed, 1 Apr 2026 09:44:13 -0400 Subject: [PATCH] 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> --- packages/core/src/tools/exit-plan-mode.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/core/src/tools/exit-plan-mode.ts b/packages/core/src/tools/exit-plan-mode.ts index f8b535762d..3b50c70fe5 100644 --- a/packages/core/src/tools/exit-plan-mode.ts +++ b/packages/core/src/tools/exit-plan-mode.ts @@ -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) {