From 226bcf8686097e20dcdb7e6944865dacfd07be64 Mon Sep 17 00:00:00 2001 From: scawful Date: Sat, 4 Oct 2025 19:16:26 -0400 Subject: [PATCH] feat: Add agent folder structure verification and improve CMake cache cleaning - Introduced Test-AgentFolderStructure function to verify the presence of required agent files and check for old structure indicators. - Enhanced Clean-CMakeCache function to provide better error handling and clean additional CMake-generated files. - Updated build process to include agent folder structure checks before CMake configuration. --- scripts/verify-build-environment.ps1 | 121 +++++++++++++++++++++++++-- src/app/editor/agent/agent_editor.cc | 6 ++ 2 files changed, 120 insertions(+), 7 deletions(-) diff --git a/scripts/verify-build-environment.ps1 b/scripts/verify-build-environment.ps1 index 1bf863d8..dcf77fb6 100644 --- a/scripts/verify-build-environment.ps1 +++ b/scripts/verify-build-environment.ps1 @@ -137,15 +137,82 @@ function Test-DependencyCompatibility { return $conflicts.Count -eq 0 } -function Clean-CMakeCache { - Write-Status "Cleaning CMake cache..." "Step" +function Test-AgentFolderStructure { + Write-Status "Verifying agent folder structure..." "Step" + + $agentFiles = @( + "src/app/editor/agent/agent_editor.h", + "src/app/editor/agent/agent_editor.cc", + "src/app/editor/agent/agent_chat_widget.h", + "src/app/editor/agent/agent_chat_widget.cc", + "src/app/editor/agent/agent_chat_history_codec.h", + "src/app/editor/agent/agent_chat_history_codec.cc", + "src/app/editor/agent/agent_collaboration_coordinator.h", + "src/app/editor/agent/agent_collaboration_coordinator.cc", + "src/app/editor/agent/network_collaboration_coordinator.h", + "src/app/editor/agent/network_collaboration_coordinator.cc" + ) + + $oldSystemFiles = @( + "src/app/editor/system/agent_chat_widget.h", + "src/app/editor/system/agent_collaboration_coordinator.h" + ) + + $allPresent = $true + $hasOldStructure = $false + + foreach ($file in $agentFiles) { + $path = Join-Path $PSScriptRoot ".." $file + if (-not (Test-Path $path)) { + Write-Status "Agent file missing: $file" "Error" + $script:issuesFound += "Missing agent file: $file (may need to rebuild)" + $allPresent = $false + } elseif ($Verbose) { + Write-Status "Agent file found: $file" "Success" + } + } + + # Check for old structure (indicates stale cache) + foreach ($file in $oldSystemFiles) { + $path = Join-Path $PSScriptRoot ".." $file + if (Test-Path $path) { + Write-Status "Old agent file still present: $file" "Warning" + $script:warnings += "Old agent structure detected (CMake cache needs cleaning)" + $hasOldStructure = $true + } + } + + if ($allPresent -and -not $hasOldStructure) { + Write-Status "Agent folder structure is correct" "Success" + $script:success += "Agent refactoring structure verified" + } elseif ($hasOldStructure) { + Write-Status "Stale agent files detected - CMake cache should be cleaned" "Warning" + return $false + } + + return $allPresent +} + +function Clean-CMakeCache { + param([switch]$Force) + + Write-Status "Cleaning CMake cache and build directories..." "Step" + + $buildDirs = @("build", "build_test", "build-grpc-test", "build_rooms") + $cleaned = $false - $buildDirs = @("build", "build_test", "build-grpc-test") foreach ($dir in $buildDirs) { $fullPath = Join-Path $PSScriptRoot ".." $dir if (Test-Path $fullPath) { Write-Status "Removing $dir..." "Info" - Remove-Item -Recurse -Force $fullPath -ErrorAction SilentlyContinue + try { + Remove-Item -Recurse -Force $fullPath -ErrorAction Stop + $cleaned = $true + Write-Status " ✓ Removed $dir" "Success" + } catch { + Write-Status " ✗ Failed to remove $dir`: $_" "Error" + $script:warnings += "Could not fully clean $dir (some files may be locked)" + } } } @@ -153,10 +220,36 @@ function Clean-CMakeCache { $vsCache = Join-Path $PSScriptRoot ".." "out" if (Test-Path $vsCache) { Write-Status "Removing Visual Studio CMake cache (out/)..." "Info" - Remove-Item -Recurse -Force $vsCache -ErrorAction SilentlyContinue + try { + Remove-Item -Recurse -Force $vsCache -ErrorAction Stop + $cleaned = $true + Write-Status " ✓ Removed Visual Studio cache" "Success" + } catch { + Write-Status " ✗ Failed to remove Visual Studio cache: $_" "Warning" + } } - Write-Status "CMake cache cleaned" "Success" + # Clean CMake generated files in root + $cmakeFiles = @( + "CMakeCache.txt", + "cmake_install.cmake", + "compile_commands.json" + ) + + foreach ($file in $cmakeFiles) { + $fullPath = Join-Path $PSScriptRoot ".." $file + if (Test-Path $fullPath) { + Write-Status "Removing root $file..." "Info" + Remove-Item -Force $fullPath -ErrorAction SilentlyContinue + } + } + + if ($cleaned) { + Write-Status "CMake cache cleaned successfully" "Success" + $script:success += "Build directories cleaned - fresh build recommended" + } else { + Write-Status "No build directories found to clean" "Info" + } } function Sync-GitSubmodules { @@ -351,7 +444,21 @@ if ($cacheOk) { # Step 6: Check Dependencies Test-DependencyCompatibility -# Step 7: Test CMake Configuration (if requested) +# Step 7: Check Agent Folder Structure +Write-Status "Checking agent folder structure..." "Step" +$agentStructureOk = Test-AgentFolderStructure +if (-not $agentStructureOk) { + Write-Status "Agent folder structure has issues" "Warning" + if ($CleanCache -or $FixIssues) { + Write-Status "Cleaning CMake cache due to structural changes..." "Info" + Clean-CMakeCache + Write-Status "Please rebuild the project after cache cleaning" "Info" + } else { + Write-Status "Run with -CleanCache to fix structural issues" "Info" + } +} + +# Step 8: Test CMake Configuration (if requested) if ($Verbose -or $FixIssues) { Test-CMakeConfiguration } diff --git a/src/app/editor/agent/agent_editor.cc b/src/app/editor/agent/agent_editor.cc index 79242728..63a68319 100644 --- a/src/app/editor/agent/agent_editor.cc +++ b/src/app/editor/agent/agent_editor.cc @@ -103,6 +103,9 @@ absl::StatusOr AgentEditor::HostSession( // Get username from system (could be made configurable) const char* username = std::getenv("USER"); + if (!username) { + username = std::getenv("USERNAME"); // Windows fallback + } if (!username) { username = "unknown"; } @@ -172,6 +175,9 @@ absl::StatusOr AgentEditor::JoinSession( } const char* username = std::getenv("USER"); + if (!username) { + username = std::getenv("USERNAME"); // Windows fallback + } if (!username) { username = "unknown"; }