From aec5882c8dea240251bc47819bac3727f52e1b50 Mon Sep 17 00:00:00 2001 From: Will Chen Date: Mon, 28 Apr 2025 13:45:32 -0700 Subject: [PATCH] Fix bug in extract codebase that artificially limited to 30 files (#32) --- src/ipc/handlers/app_handlers.ts | 25 ------------------------- src/ipc/ipc_client.ts | 14 -------------- src/utils/codebase.ts | 30 ++++-------------------------- 3 files changed, 4 insertions(+), 65 deletions(-) diff --git a/src/ipc/handlers/app_handlers.ts b/src/ipc/handlers/app_handlers.ts index 4074ea3..25abe1e 100644 --- a/src/ipc/handlers/app_handlers.ts +++ b/src/ipc/handlers/app_handlers.ts @@ -619,31 +619,6 @@ export function registerAppHandlers() { } ); - // Extract codebase information - ipcMain.handle( - "extract-codebase", - async (_, { appId, maxFiles }: { appId: number; maxFiles?: number }) => { - const app = await db.query.apps.findFirst({ - where: eq(apps.id, appId), - }); - - if (!app) { - throw new Error("App not found"); - } - - const appPath = getDyadAppPath(app.path); - - try { - return await extractCodebase(appPath, maxFiles); - } catch (error) { - logger.error(`Error extracting codebase for app ${appId}:`, error); - throw new Error( - `Failed to extract codebase: ${(error as any).message}` - ); - } - } - ); - ipcMain.handle( "edit-app-file", async ( diff --git a/src/ipc/ipc_client.ts b/src/ipc/ipc_client.ts index 8141629..8307bd0 100644 --- a/src/ipc/ipc_client.ts +++ b/src/ipc/ipc_client.ts @@ -431,20 +431,6 @@ export class IpcClient { } } - // Extract codebase information for a given app - public async extractCodebase(appId: number, maxFiles = 30): Promise { - try { - const codebaseInfo = await this.ipcRenderer.invoke("extract-codebase", { - appId, - maxFiles, - }); - return codebaseInfo as string; - } catch (error) { - showError(error); - throw error; - } - } - // Delete an app and all its files public async deleteApp(appId: number): Promise<{ success: boolean }> { try { diff --git a/src/utils/codebase.ts b/src/utils/codebase.ts index 9111680..fcf6441 100644 --- a/src/utils/codebase.ts +++ b/src/utils/codebase.ts @@ -33,18 +33,9 @@ async function isGitIgnored( /** * Recursively walk a directory and collect all relevant files */ -async function collectFiles( - dir: string, - baseDir: string, - maxFiles = 100 -): Promise { +async function collectFiles(dir: string, baseDir: string): Promise { const files: string[] = []; - // Stop if we've reached the file limit - if (files.length >= maxFiles) { - return files; - } - // Check if directory exists if (!fs.existsSync(dir)) { return files; @@ -55,11 +46,6 @@ async function collectFiles( const entries = fs.readdirSync(dir, { withFileTypes: true }); for (const entry of entries) { - // Stop if we've reached the file limit - if (files.length >= maxFiles) { - break; - } - const fullPath = path.join(dir, entry.name); // Skip excluded directories @@ -74,11 +60,7 @@ async function collectFiles( if (entry.isDirectory()) { // Recursively process subdirectories - const subDirFiles = await collectFiles( - fullPath, - baseDir, - maxFiles - files.length - ); + const subDirFiles = await collectFiles(fullPath, baseDir); files.push(...subDirFiles); } else if (entry.isFile()) { // Check file extension and filename @@ -152,19 +134,15 @@ ${content} /** * Extract and format codebase files as a string to be included in prompts * @param appPath - Path to the codebase to extract - * @param maxFiles - Maximum number of files to include (default: 30) * @returns A string containing formatted file contents */ -export async function extractCodebase( - appPath: string, - maxFiles = 30 -): Promise { +export async function extractCodebase(appPath: string): Promise { if (!fs.existsSync(appPath)) { return `# Error: Directory ${appPath} does not exist`; } // Collect all relevant files - const files = await collectFiles(appPath, appPath, maxFiles); + const files = await collectFiles(appPath, appPath); // Sort files to prioritize important files const sortedFiles = sortFilesByImportance(files, appPath);