Skip to content

Commit

Permalink
Fixed aider echo and output error (#198)
Browse files Browse the repository at this point in the history
* Fixed echo and output error

* Fallback to brew install

* Fallback to brew install

* Added no detect urls

* Added resetSession

---------

Co-authored-by: nang-dev <[email protected]>
  • Loading branch information
nang-dev and nang-dev authored Nov 28, 2024
1 parent 3a49f35 commit c92d28f
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 24 deletions.
18 changes: 14 additions & 4 deletions core/llm/llms/AiderLLM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
62 changes: 56 additions & 6 deletions extensions/vscode/src/integrations/aider/aiderProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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"
];


Expand Down Expand Up @@ -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}`);
Expand Down
55 changes: 41 additions & 14 deletions extensions/vscode/src/integrations/aider/aiderUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit c92d28f

Please sign in to comment.