From 8251ac52d607197fe779ec8df49b9ddcea141bc4 Mon Sep 17 00:00:00 2001 From: Adib234 <30782825+Adib234@users.noreply.github.com> Date: Wed, 1 Apr 2026 09:43:45 -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 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/core/src/tools/exit-plan-mode.ts b/packages/core/src/tools/exit-plan-mode.ts index 85f936ee80..f8b535762d 100644 --- a/packages/core/src/tools/exit-plan-mode.ts +++ b/packages/core/src/tools/exit-plan-mode.ts @@ -160,12 +160,13 @@ export class ExitPlanModeInvocation extends BaseToolInvocation< // decision is 'ask_user' let diffContent: string | undefined; try { - let latestVersion = 0; - let version = 1; - while (fs.existsSync(`${resolvedPlanPath}.v${version}`)) { - latestVersion = version; - 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 latestVersion = versions.length > 0 ? Math.max(...versions) : 0; if (latestVersion > 0) { const previousPlanPath = `${resolvedPlanPath}.v${latestVersion}`;