diff --git a/apps/server/src/files/router.ts b/apps/server/src/files/router.ts index 52ced51a..c2a1d633 100644 --- a/apps/server/src/files/router.ts +++ b/apps/server/src/files/router.ts @@ -159,10 +159,6 @@ router.get("/:taskId/file-changes", async (req, res) => { try { const { taskId } = req.params; - console.log( - `[FILE_CHANGES_DEBUG] Route entry - taskId: ${taskId}, timestamp: ${new Date().toISOString()}` - ); - // Validate task exists and get full status const task = await prisma.task.findUnique({ where: { id: taskId }, @@ -178,12 +174,7 @@ router.get("/:taskId/file-changes", async (req, res) => { }, }); - console.log( - `[FILE_CHANGES_DEBUG] Task lookup result - taskId: ${taskId}, found: ${!!task}, status: ${task?.status}, initStatus: ${task?.initStatus}, workspacePath: ${task?.workspacePath}` - ); - if (!task) { - console.log(`[FILE_CHANGES_DEBUG] Task not found - taskId: ${taskId}`); return res.status(404).json({ success: false, error: "Task not found", @@ -192,9 +183,6 @@ router.get("/:taskId/file-changes", async (req, res) => { // Don't return file changes if task is still initializing if (task.status === "INITIALIZING") { - console.log( - `[FILE_CHANGES_DEBUG] Task still initializing - taskId: ${taskId}, returning empty changes` - ); return res.json({ success: true, fileChanges: [], @@ -204,14 +192,7 @@ router.get("/:taskId/file-changes", async (req, res) => { // If task workspace is INACTIVE (cleaned up), use GitHub API if (task.initStatus === "INACTIVE") { - console.log( - `[FILE_CHANGES_DEBUG] Task workspace INACTIVE - taskId: ${taskId}, using GitHub API path` - ); - if (!task.repoFullName || !task.shadowBranch) { - console.log( - `[FILE_CHANGES_DEBUG] Missing GitHub info - taskId: ${taskId}, repoFullName: ${task.repoFullName}, shadowBranch: ${task.shadowBranch}` - ); return res.json({ success: true, fileChanges: [], @@ -219,9 +200,6 @@ router.get("/:taskId/file-changes", async (req, res) => { }); } - console.log( - `[FILE_CHANGES_DEBUG] Calling GitHub API - taskId: ${taskId}, repo: ${task.repoFullName}, base: ${task.baseBranch}, shadow: ${task.shadowBranch}` - ); const { fileChanges, diffStats } = await getGitHubFileChanges( task.repoFullName, task.baseBranch, @@ -229,9 +207,6 @@ router.get("/:taskId/file-changes", async (req, res) => { task.userId ); - console.log( - `[FILE_CHANGES_DEBUG] GitHub API response - taskId: ${taskId}, fileChanges: ${fileChanges.length}, additions: ${diffStats.additions}, deletions: ${diffStats.deletions}` - ); return res.json({ success: true, fileChanges, @@ -240,29 +215,13 @@ router.get("/:taskId/file-changes", async (req, res) => { } // For ACTIVE tasks, use GitService abstraction (handles both local and remote modes) - console.log( - `[FILE_CHANGES_DEBUG] Task ACTIVE - taskId: ${taskId}, using GitService abstraction` - ); - try { const gitService = await createGitService(taskId); - console.log( - `[FILE_CHANGES_DEBUG] GitService created - taskId: ${taskId}, calling getFileChanges with baseBranch: ${task.baseBranch}` - ); const { fileChanges, diffStats } = await gitService.getFileChanges( task.baseBranch ); - console.log( - `[FILE_CHANGES_DEBUG] GitService response - taskId: ${taskId}, fileChanges: ${fileChanges.length}, additions: ${diffStats.additions}, deletions: ${diffStats.deletions}` - ); - - const duration = Date.now() - startTime; - console.log( - `[FILE_CHANGES_DEBUG] Final response - taskId: ${taskId}, fileChanges: ${fileChanges.length}, additions: ${diffStats.additions}, deletions: ${diffStats.deletions}, duration: ${duration}ms` - ); - res.json({ success: true, fileChanges, @@ -276,11 +235,6 @@ router.get("/:taskId/file-changes", async (req, res) => { ); // Fallback to empty response on error - const duration = Date.now() - startTime; - console.log( - `[FILE_CHANGES_DEBUG] Returning empty fallback response - taskId: ${taskId}, duration: ${duration}ms` - ); - res.json({ success: true, fileChanges: [], diff --git a/apps/server/src/utils/git-operations.ts b/apps/server/src/utils/git-operations.ts index ab4e6c5d..dfa8f11e 100644 --- a/apps/server/src/utils/git-operations.ts +++ b/apps/server/src/utils/git-operations.ts @@ -39,45 +39,23 @@ async function getCommittedChanges( now: string, baseBranch: string ) { - const startTime = Date.now(); - console.log( - `[FILE_CHANGES_DEBUG] getCommittedChanges start - baseBranch: ${baseBranch}, workspacePath: ${workspacePath}` - ); - const diffCommand = `git diff --name-status ${baseBranch}...HEAD`; - console.log(`[FILE_CHANGES_DEBUG] Running git diff command: ${diffCommand}`); const { stdout: committedStatusOutput } = await execAsync(diffCommand, { cwd: workspacePath, }); - console.log( - `[FILE_CHANGES_DEBUG] Git diff status output length: ${committedStatusOutput.length}, hasContent: ${!!committedStatusOutput.trim()}` - ); - if (committedStatusOutput.trim()) { - // Detailed diff stats for committed changes const diffStatsCommand = `git diff --numstat ${baseBranch}...HEAD`; - console.log( - `[FILE_CHANGES_DEBUG] Running git numstat command: ${diffStatsCommand}` - ); const { stdout: committedStatsOutput } = await execAsync(diffStatsCommand, { cwd: workspacePath, }); - console.log( - `[FILE_CHANGES_DEBUG] Git numstat output length: ${committedStatsOutput.length}` - ); - // Parse committed changes const statusLines = committedStatusOutput.trim().split("\n"); const statsLines = committedStatsOutput.trim().split("\n"); - console.log( - `[FILE_CHANGES_DEBUG] Parsing committed changes - statusLines: ${statusLines.length}, statsLines: ${statsLines.length}` - ); - // Create a map of filePath -> {additions, deletions} const statsMap = new Map< string, @@ -94,12 +72,7 @@ async function getCommittedChanges( } } - console.log( - `[FILE_CHANGES_DEBUG] Stats map created - entries: ${statsMap.size}` - ); - // Process committed changes - let processedFiles = 0; for (const line of statusLines) { if (!line.trim()) continue; @@ -119,18 +92,7 @@ async function getCommittedChanges( deletions: stats.deletions, createdAt: now, }); - processedFiles++; } - - const duration = Date.now() - startTime; - console.log( - `[FILE_CHANGES_DEBUG] getCommittedChanges completed - processedFiles: ${processedFiles}, duration: ${duration}ms` - ); - } else { - const duration = Date.now() - startTime; - console.log( - `[FILE_CHANGES_DEBUG] getCommittedChanges - no committed changes found, duration: ${duration}ms` - ); } } @@ -139,24 +101,12 @@ async function getUncommittedChanges( allFiles: Map, now: string ) { - const startTime = Date.now(); - console.log( - `[FILE_CHANGES_DEBUG] getUncommittedChanges start - workspacePath: ${workspacePath}` - ); - const statusCommand = "git status --porcelain"; - console.log( - `[FILE_CHANGES_DEBUG] Running git status command: ${statusCommand}` - ); const { stdout: uncommittedOutput } = await execAsync(statusCommand, { cwd: workspacePath, }); - console.log( - `[FILE_CHANGES_DEBUG] Git status output length: ${uncommittedOutput.length}, hasContent: ${!!uncommittedOutput.trim()}` - ); - if (uncommittedOutput.trim()) { const uncommittedLines = uncommittedOutput.trim().split("\n"); const uncommittedFiles: Array<{ @@ -374,10 +324,6 @@ async function getUncommittedChanges( ); // Phase 3: Create file change objects with accurate stats - console.log( - `[FILE_CHANGES_DEBUG] Creating file change objects - uncommittedFiles: ${uncommittedFiles.length}, diffResults: ${diffResults.length}` - ); - for (const { filePath, operation } of uncommittedFiles) { const stats = diffStatsMap.get(filePath) || { additions: 0, @@ -392,16 +338,6 @@ async function getUncommittedChanges( createdAt: now, }); } - - const duration = Date.now() - startTime; - console.log( - `[FILE_CHANGES_DEBUG] getUncommittedChanges completed - processedFiles: ${uncommittedFiles.length}, duration: ${duration}ms` - ); - } else { - const duration = Date.now() - startTime; - console.log( - `[FILE_CHANGES_DEBUG] getUncommittedChanges - no uncommitted changes found, duration: ${duration}ms` - ); } } } @@ -414,87 +350,28 @@ export async function getFileChangesForWorkspace( workspacePath: string, baseBranch: string = "main" ): Promise<{ fileChanges: FileChange[]; diffStats: DiffStats }> { - const startTime = Date.now(); - - console.log( - `[FILE_CHANGES_DEBUG] getFileChangesForWorkspace entry - workspacePath: ${workspacePath}, baseBranch: ${baseBranch}` - ); - if (!(await hasGitRepositoryAtPath(workspacePath))) { - console.log( - `[FILE_CHANGES_DEBUG] No git repository found at ${workspacePath}, returning empty changes` - ); return { fileChanges: [], diffStats: { additions: 0, deletions: 0, totalFiles: 0 }, }; } - console.log( - `[FILE_CHANGES_DEBUG] Git repository confirmed at ${workspacePath}, proceeding with git operations` - ); - try { - console.log( - `[FILE_CHANGES_DEBUG] Refreshing git index - workspacePath: ${workspacePath}` - ); // Refresh git index to ensure consistency after potential checkout operations await execAsync("git update-index --refresh", { cwd: workspacePath }).catch( - (error) => { - console.log( - `[FILE_CHANGES_DEBUG] Git index refresh failed (non-blocking) - workspacePath: ${workspacePath}, error: ${error}` - ); - // Non-blocking - update-index may fail if no changes, which is fine - } + () => {} ); const now = new Date().toISOString(); const allFiles = new Map(); - console.log( - `[FILE_CHANGES_DEBUG] Starting parallel git operations - workspacePath: ${workspacePath}, timestamp: ${now}` - ); - - const commitTime = Date.now(); - const uncommitTime = Date.now(); - await Promise.all([ - getCommittedChanges(workspacePath, allFiles, now, baseBranch).then(() => { - const duration = Date.now() - commitTime; - console.log( - `[FILE_CHANGES_DEBUG] getCommittedChanges completed - workspacePath: ${workspacePath}, duration: ${duration}ms, files: ${Array.from(allFiles.keys()).filter((f) => Array.from(allFiles.values()).find((v) => v.filePath === f)?.createdAt === now).length}` - ); - }), - getUncommittedChanges(workspacePath, allFiles, now).then(() => { - const duration = Date.now() - uncommitTime; - const uncommittedFiles = Array.from(allFiles.values()).filter( - (f) => f.createdAt === now - ); - console.log( - `[FILE_CHANGES_DEBUG] getUncommittedChanges completed - workspacePath: ${workspacePath}, duration: ${duration}ms, uncommitted files: ${uncommittedFiles.length}` - ); - }), + getCommittedChanges(workspacePath, allFiles, now, baseBranch), + getUncommittedChanges(workspacePath, allFiles, now), ]); const fileChanges = Array.from(allFiles.values()); - console.log( - `[FILE_CHANGES_DEBUG] All files aggregated - workspacePath: ${workspacePath}, total files: ${fileChanges.length}` - ); - - // Log detailed file information - fileChanges.forEach((file, index) => { - if (index < 10) { - // Log first 10 files to avoid spam - console.log( - `[FILE_CHANGES_DEBUG] File ${index + 1} - workspacePath: ${workspacePath}, path: ${file.filePath}, operation: ${file.operation}, +${file.additions}/-${file.deletions}` - ); - } - }); - if (fileChanges.length > 10) { - console.log( - `[FILE_CHANGES_DEBUG] ... and ${fileChanges.length - 10} more files - workspacePath: ${workspacePath}` - ); - } const diffStats = fileChanges.reduce( (acc, file) => ({ @@ -505,19 +382,12 @@ export async function getFileChangesForWorkspace( { additions: 0, deletions: 0, totalFiles: 0 } ); - const totalDuration = Date.now() - startTime; - console.log( - `[FILE_CHANGES_DEBUG] getFileChangesForWorkspace completed - workspacePath: ${workspacePath}, totalFiles: ${diffStats.totalFiles}, additions: ${diffStats.additions}, deletions: ${diffStats.deletions}, totalDuration: ${totalDuration}ms` - ); - return { fileChanges, diffStats }; } catch (error) { - const duration = Date.now() - startTime; console.error( - `[FILE_CHANGES_DEBUG] Error getting file changes for workspace ${workspacePath} (duration: ${duration}ms):`, + `Error getting file changes for workspace ${workspacePath}:`, error ); - // Return empty array instead of throwing to avoid breaking the UI return { fileChanges: [], diffStats: { additions: 0, deletions: 0, totalFiles: 0 }, @@ -564,10 +434,6 @@ function mapGitStatusToOperation(status: string): FileChange["operation"] { export async function hasGitRepositoryAtPath( workspacePath: string ): Promise { - console.log( - `[FILE_CHANGES_DEBUG] hasGitRepositoryAtPath check - workspacePath: ${workspacePath}` - ); - try { const { stdout } = await execAsync("git rev-parse --git-dir", { cwd: workspacePath, @@ -576,15 +442,8 @@ export async function hasGitRepositoryAtPath( const gitDir = stdout.trim(); const hasGit = gitDir === `.git`; - console.log( - `[FILE_CHANGES_DEBUG] Git directory check - workspacePath: ${workspacePath}, gitDir: "${gitDir}", hasGit: ${hasGit}` - ); - return hasGit; - } catch (error) { - console.log( - `[FILE_CHANGES_DEBUG] Git repository check failed - workspacePath: ${workspacePath}, error: ${error}` - ); + } catch (_error) { return false; } } diff --git a/apps/server/src/utils/github-file-changes.ts b/apps/server/src/utils/github-file-changes.ts index 40dbae9e..7f9e0e63 100644 --- a/apps/server/src/utils/github-file-changes.ts +++ b/apps/server/src/utils/github-file-changes.ts @@ -17,31 +17,16 @@ export async function getGitHubFileChanges( const apiClient = new GitHubApiClient(); try { - console.log( - `[FILE_CHANGES_DEBUG] GitHub API call start - repo: ${repoFullName}, comparison: ${baseBranch}...${shadowBranch}, userId: ${userId}` - ); - const compareResult = await apiClient.compareBranches( repoFullName, `${baseBranch}...${shadowBranch}`, userId ); - const apiDuration = Date.now() - startTime; - console.log( - `[FILE_CHANGES_DEBUG] GitHub API response received - duration: ${apiDuration}ms, files: ${compareResult.files?.length || 0}, additions: ${compareResult.stats?.additions || 0}, deletions: ${compareResult.stats?.deletions || 0}` - ); - const now = new Date().toISOString(); // Convert GitHub file changes to our FileChange format - const fileChanges: FileChange[] = compareResult.files.map((file, index) => { - if (index < 5) { - // Log first 5 files to avoid spam - console.log( - `[FILE_CHANGES_DEBUG] GitHub file ${index + 1} - path: ${file.filename}, status: ${file.status}, +${file.additions}/-${file.deletions}` - ); - } + const fileChanges: FileChange[] = compareResult.files.map((file) => { return { filePath: file.filename, operation: mapGitHubStatusToOperation(file.status), @@ -51,23 +36,12 @@ export async function getGitHubFileChanges( }; }); - if (compareResult.files.length > 5) { - console.log( - `[FILE_CHANGES_DEBUG] ... and ${compareResult.files.length - 5} more GitHub files` - ); - } - const diffStats: DiffStats = { additions: compareResult.stats.additions, deletions: compareResult.stats.deletions, totalFiles: compareResult.stats.total, }; - const totalDuration = Date.now() - startTime; - console.log( - `[FILE_CHANGES_DEBUG] GitHub file changes processed - totalFiles: ${fileChanges.length}, totalDuration: ${totalDuration}ms` - ); - return { fileChanges, diffStats }; } catch (error) { const duration = Date.now() - startTime;