Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed aider echo and output error #198

Merged
merged 5 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
59 changes: 54 additions & 5 deletions extensions/vscode/src/integrations/aider/aiderProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,61 @@ 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`);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using execSync in an async function can block the event loop. Consider using exec or promisify to handle this asynchronously.

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}`);
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 @@ -335,6 +378,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
53 changes: 40 additions & 13 deletions extensions/vscode/src/integrations/aider/aiderUtil.ts
Original file line number Diff line number Diff line change
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