Fix bug in extract codebase that artificially limited to 30 files (#32)

This commit is contained in:
Will Chen
2025-04-28 13:45:32 -07:00
committed by GitHub
parent e65b80bcfa
commit aec5882c8d
3 changed files with 4 additions and 65 deletions

View File

@@ -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( ipcMain.handle(
"edit-app-file", "edit-app-file",
async ( async (

View File

@@ -431,20 +431,6 @@ export class IpcClient {
} }
} }
// Extract codebase information for a given app
public async extractCodebase(appId: number, maxFiles = 30): Promise<string> {
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 // Delete an app and all its files
public async deleteApp(appId: number): Promise<{ success: boolean }> { public async deleteApp(appId: number): Promise<{ success: boolean }> {
try { try {

View File

@@ -33,18 +33,9 @@ async function isGitIgnored(
/** /**
* Recursively walk a directory and collect all relevant files * Recursively walk a directory and collect all relevant files
*/ */
async function collectFiles( async function collectFiles(dir: string, baseDir: string): Promise<string[]> {
dir: string,
baseDir: string,
maxFiles = 100
): Promise<string[]> {
const files: string[] = []; const files: string[] = [];
// Stop if we've reached the file limit
if (files.length >= maxFiles) {
return files;
}
// Check if directory exists // Check if directory exists
if (!fs.existsSync(dir)) { if (!fs.existsSync(dir)) {
return files; return files;
@@ -55,11 +46,6 @@ async function collectFiles(
const entries = fs.readdirSync(dir, { withFileTypes: true }); const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) { 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); const fullPath = path.join(dir, entry.name);
// Skip excluded directories // Skip excluded directories
@@ -74,11 +60,7 @@ async function collectFiles(
if (entry.isDirectory()) { if (entry.isDirectory()) {
// Recursively process subdirectories // Recursively process subdirectories
const subDirFiles = await collectFiles( const subDirFiles = await collectFiles(fullPath, baseDir);
fullPath,
baseDir,
maxFiles - files.length
);
files.push(...subDirFiles); files.push(...subDirFiles);
} else if (entry.isFile()) { } else if (entry.isFile()) {
// Check file extension and filename // Check file extension and filename
@@ -152,19 +134,15 @@ ${content}
/** /**
* Extract and format codebase files as a string to be included in prompts * Extract and format codebase files as a string to be included in prompts
* @param appPath - Path to the codebase to extract * @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 * @returns A string containing formatted file contents
*/ */
export async function extractCodebase( export async function extractCodebase(appPath: string): Promise<string> {
appPath: string,
maxFiles = 30
): Promise<string> {
if (!fs.existsSync(appPath)) { if (!fs.existsSync(appPath)) {
return `# Error: Directory ${appPath} does not exist`; return `# Error: Directory ${appPath} does not exist`;
} }
// Collect all relevant files // Collect all relevant files
const files = await collectFiles(appPath, appPath, maxFiles); const files = await collectFiles(appPath, appPath);
// Sort files to prioritize important files // Sort files to prioritize important files
const sortedFiles = sortFilesByImportance(files, appPath); const sortedFiles = sortFilesByImportance(files, appPath);