diff --git a/core/llm/llms/AiderLLM.ts b/core/llm/llms/AiderLLM.ts index 720c489a16..e3a53ba8dd 100644 --- a/core/llm/llms/AiderLLM.ts +++ b/core/llm/llms/AiderLLM.ts @@ -158,6 +158,7 @@ class Aider extends BaseLLM { let responseComplete = false; let potentialCompletion = false; let potentialCompletionTimeout: NodeJS.Timeout | null = null; + let startedListening = false; const escapeDollarSigns = (text: string | undefined) => { if (!text) { @@ -182,6 +183,7 @@ class Aider extends BaseLLM { potentialCompletion = false; } + if (READY_PROMPT_REGEX.test(newOutput)) { // Instead of marking complete immediately, set up potential completion if (!potentialCompletion) { @@ -193,10 +195,18 @@ class Aider extends BaseLLM { } lastProcessedIndex = Aider.aiderProcess?.aiderOutput.length || 0; - yield { - role: "assistant", - content: escapeDollarSigns(newOutput), - }; + + // Start listening once we see a newline-prefixed message + if (!startedListening && newOutput.startsWith('\n')) { + startedListening = true; + } + + if (startedListening) { + yield { + role: "assistant", + content: escapeDollarSigns(newOutput), + }; + } if (Aider.aiderProcess?.state.state === "stopped" || Aider.aiderProcess?.state.state === "crashed") { if (potentialCompletionTimeout) { diff --git a/extensions/vscode/src/integrations/aider/aiderProcess.ts b/extensions/vscode/src/integrations/aider/aiderProcess.ts index 127ad51b42..d21552f3cc 100644 --- a/extensions/vscode/src/integrations/aider/aiderProcess.ts +++ b/extensions/vscode/src/integrations/aider/aiderProcess.ts @@ -29,18 +29,62 @@ export const AIDER_QUESTION_MARKER = "[Yes]\\:"; export const AIDER_END_MARKER = "─────────────────────────────────────"; export const COMPLETION_DELAY = 1500; // 1.5 seconds wait time -function updateAiderVersion() { +async function updateAiderVersion() { try { - if (compareVersions(getAiderVersion(), PEARAI_AIDER_VERSION) != 0) { - console.log(`Upgrading aider-chat to version: ${PEARAI_AIDER_VERSION}`); - execSync(`pipx uninstall aider-chat`); - execSync(`pipx install aider-chat==${PEARAI_AIDER_VERSION}`); + const aiderVersion = getAiderVersion(); + console.log(`Current aider version: ${aiderVersion}`); + + if (compareVersions(aiderVersion, PEARAI_AIDER_VERSION) === 0) { + return; // Already on correct version } + + console.log(`Upgrading aider-chat to version: ${PEARAI_AIDER_VERSION}`); + await updateUsingPackageManager(); } catch (error) { console.error("Error updating Aider version:", error); } } +async function updateUsingPackageManager() { + const updateMethods = [ + { + name: 'pipx reinstall', + command: async () => { + await execSync(`pipx uninstall aider-chat`); + await execSync(`pipx install aider-chat==${PEARAI_AIDER_VERSION}`); + } + }, + { + name: 'pipx upgrade', + command: async () => await execSync(`pipx upgrade aider-chat`) + }, + { + name: 'brew upgrade', + condition: () => IS_MAC || IS_LINUX, + command: async () => await execSync(`brew upgrade aider`) + } + ]; + + for (const method of updateMethods) { + if (method.condition && !method.condition()) { + continue; + } + + try { + await method.command(); + console.log(`Successfully updated using ${method.name}`); + vscode.commands.executeCommand("pearai.aiderResetSession"); + return; + } catch (error) { + console.log(`${method.name} failed:`, error); + // Continue to next method + } + } + + throw new Error('All update methods failed'); +} + + function getAiderVersion(): string { try { const versionOutput = execSync('aider --version').toString().trim(); @@ -78,7 +122,7 @@ export function buildAiderCommand(model: string, accessToken: string | undefined "--map-tokens", "2048", "--subtree-only", "--no-show-release-notes", - // "--no-detect-urls" // TODO: Add with aider update + "--no-detect-urls" ]; @@ -335,6 +379,12 @@ async startAiderChat(model: string, apiKey: string | undefined, isRestarting: bo } }); } + + if (this.aiderProcess.stderr) { + this.aiderProcess.stderr.on('data', (data: Buffer) => { + console.error('Aider process stderr:', data.toString()); + }); + } this.aiderProcess.on('exit', (code, signal) => { console.log(`Aider process exited with code ${code}, signal ${signal}`); diff --git a/extensions/vscode/src/integrations/aider/aiderUtil.ts b/extensions/vscode/src/integrations/aider/aiderUtil.ts index e2dcef1d48..bfa2ae52cb 100644 --- a/extensions/vscode/src/integrations/aider/aiderUtil.ts +++ b/extensions/vscode/src/integrations/aider/aiderUtil.ts @@ -9,7 +9,7 @@ import { isFirstPearAICreatorLaunch } from "../../copySettings"; import { VsCodeWebviewProtocol } from "../../webviewProtocol"; import * as os from "os"; -export const PEARAI_AIDER_VERSION = "0.64.0"; +export const PEARAI_AIDER_VERSION = "0.65.0"; const PLATFORM = process.platform; const IS_WINDOWS = PLATFORM === "win32"; @@ -149,26 +149,53 @@ export async function installAider(core: Core) { vscode.window.showInformationMessage("Installing Aider..."); - let command = ""; + let success = false; + if (IS_WINDOWS) { - command += "python -m pip install pipx;"; - command += "pipx ensurepath;"; - command += `pipx install aider-chat==${PEARAI_AIDER_VERSION};`; - command += `echo "\nAider ${PEARAI_AIDER_VERSION} installation complete."`; + const command = [ + "python -m pip install pipx", + "pipx ensurepath", + `pipx install aider-chat==${PEARAI_AIDER_VERSION}`, + `echo "\nAider ${PEARAI_AIDER_VERSION} installation complete."` + ].join(";"); + + try { + execSync(command); + success = true; + } catch (error) { + console.error("Failed to install Aider via pipx on Windows:", error); + return true; + } } else { - command += "brew install pipx;"; - command += `pipx install aider-chat==${PEARAI_AIDER_VERSION};`; - command += `echo "\nAider ${PEARAI_AIDER_VERSION} installation complete."`; + // For Mac/Linux, try pipx first + try { + const pipxCommand = [ + "brew install pipx", + `pipx install aider-chat==${PEARAI_AIDER_VERSION}`, + `echo "\nAider ${PEARAI_AIDER_VERSION} installation complete."` + ].join(";"); + + execSync(pipxCommand); + success = true; + } catch (pipxError) { + console.log("Failed to install Aider via pipx, trying brew..."); + + // If pipx fails, try installing directly with brew + try { + execSync("brew install aider"); + success = true; + } catch (brewError) { + console.error("Failed to install Aider via brew:", brewError); + return true; + } + } } - try { - execSync(command); + if (success) { core.invoke("llm/startAiderProcess", undefined); return false; - } catch (error) { - console.error("Failed to execute Aider command:", error); - return true; } + return true; } }