Skip to content

Conversation

Scriptwonder
Copy link
Collaborator

@Scriptwonder Scriptwonder commented Oct 17, 2025

Fix the JSON installation on Codex in Wizard;
Adding the lines to support Codex CLI on windows temporarily, thanks to openai/codex#4180

Summary by CodeRabbit

  • New Features
    • Enhanced Codex client configuration with dedicated setup handling in the wizard.
    • Added Windows system environment path configuration for Codex servers.
    • Improved configuration block flexibility with support for naming variations.

Fix the JSON installation on Codex in Wizard;
Adding the lines to support Codex CLI on windows temporarily, thanks to openai/codex#4180
Copy link
Contributor

coderabbitai bot commented Oct 17, 2025

Walkthrough

Configuration for the Codex MCP server is now generated as TOML with Windows-specific environment paths exposed via a dedicated block. The setup flow routes Codex clients to a specialized configuration handler, while the TOML builder supports both camelCase and snake_case section naming variants.

Changes

Cohort / File(s) Summary
TOML Configuration Building
UnityMcpBridge/Editor/Helpers/CodexConfigHelper.cs
Enhances BuildCodexServerBlock to construct TOML with startup_timeout_sec = 30 and Windows-specific environment paths (USERPROFILE, APPDATA, LOCALAPPDATA, etc.) under [mcp_servers.unityMCP.env]. Updates UpsertCodexServerBlock to detect and preserve both camelCase and snake_case naming conventions, with logic to handle section replacement and case-insensitive comparison.
Setup Flow Routing
UnityMcpBridge/Editor/Setup/SetupWizardWindow.cs
Routes client configuration to ConfigureCodexClient for Codex MCP types and WriteMcpConfiguration for others, applied in both standard and manual setup paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The TOML building logic introduces case normalization and environment variable gathering requiring careful verification, while the setup routing is straightforward. Mixed complexity across two files with one containing denser logic.

Poem

🐰 With TOML paths now catching the breeze,
And Windows variables gathered with ease,
Both camelCase and snake\_case in play,
Codex finds home in a new config way!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Update to support Codex CLI" directly and clearly describes the main objective of the changeset. The modifications to both CodexConfigHelper.cs and SetupWizardWindow.cs are specifically focused on adding Codex-specific configuration handling, including TOML formatting support and dedicated client configuration logic. The title is concise, specific, and accurately reflects the primary purpose stated in the PR objectives of adding support for Codex CLI on Windows.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
UnityMcpBridge/Editor/Helpers/CodexConfigHelper.cs (3)

90-91: Consider validating hardcoded PowerShell paths before adding to config.

The hardcoded paths for PowerShell and pwsh may not exist on all Windows systems (e.g., older Windows versions without PowerShell 7, or systems with different installation paths). Writing non-existent paths to the configuration could cause issues.

Consider adding existence checks:

                     string powershell = Path.Combine(Environment.SystemDirectory ?? (systemRoot + "\\System32"), "WindowsPowerShell\\v1.0\\powershell.exe");
                     string pwsh = Path.Combine(programFiles, "PowerShell\\7\\pwsh.exe");
+                    
+                    // Only include paths that actually exist
+                    bool powershellExists = File.Exists(powershell);
+                    bool pwshExists = File.Exists(pwsh);

Then conditionally add these to the TOML output:

                     sb.AppendLine($"LOCALAPPDATA = \"{EscapeTomlString(localAppData)}\"");
-                    sb.AppendLine($"POWERSHELL = \"{EscapeTomlString(powershell)}\"");
+                    if (powershellExists)
+                        sb.AppendLine($"POWERSHELL = \"{EscapeTomlString(powershell)}\"");
                     sb.AppendLine($"PROGRAMDATA = \"{EscapeTomlString(programData)}\"");
                     sb.AppendLine($"PROGRAMFILES = \"{EscapeTomlString(programFiles)}\"");
-                    sb.AppendLine($"PWSH = \"{EscapeTomlString(pwsh)}\"");
+                    if (pwshExists)
+                        sb.AppendLine($"PWSH = \"{EscapeTomlString(pwsh)}\"");

114-114: Add logging to catch block for debugging.

The empty catch block with only a comment makes it impossible to diagnose failures in the Windows environment block construction.

Add minimal logging:

             }
-            catch { /* best effort */ }
+            catch (Exception ex) 
+            { 
+                // Best effort - log but don't fail
+                UnityEngine.Debug.LogWarning($"UnityMCP: Failed to build Windows environment block: {ex.Message}");
+            }

74-88: Clarify HOMEPATH derivation logic.

The logic for deriving HOMEPATH from USERPROFILE is correct but confusing. Line 84 uses root.Length - 1 to "keep leading backslash," but the calculation is not immediately obvious.

Consider adding a comment to clarify the substring logic:

                         try
                         {
+                            // For "C:\\Users\\name" with root "C:\\", skip 2 chars to get "\\Users\\name"
                             var root = Path.GetPathRoot(userProfile) ?? string.Empty; // e.g., C:\\
-                            homePath = userProfile.Substring(root.Length - 1); // keep leading backslash
+                            homePath = userProfile.Substring(root.Length - 1);
                         }
                         catch { homePath = "\\"; }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90911aa and 3d9860e.

📒 Files selected for processing (2)
  • UnityMcpBridge/Editor/Helpers/CodexConfigHelper.cs (3 hunks)
  • UnityMcpBridge/Editor/Setup/SetupWizardWindow.cs (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
UnityMcpBridge/Editor/Setup/SetupWizardWindow.cs (1)
UnityMcpBridge/Editor/Helpers/McpConfigurationHelper.cs (3)
  • McpConfigurationHelper (19-296)
  • ConfigureCodexClient (147-221)
  • WriteMcpConfiguration (27-142)
🔇 Additional comments (6)
UnityMcpBridge/Editor/Setup/SetupWizardWindow.cs (2)

629-637: LGTM! Clean routing logic for Codex configuration.

The implementation correctly routes Codex clients to the specialized TOML configuration handler while maintaining the JSON-based configuration for other clients. The null check on the client parameter ensures safe access to mcpType.


653-655: Consistent configuration routing in manual setup flow.

The routing logic mirrors PerformClientConfiguration, ensuring consistent behavior between automated and manual configuration paths.

UnityMcpBridge/Editor/Helpers/CodexConfigHelper.cs (4)

46-52: LGTM! StringBuilder refactor and timeout configuration.

The refactor to StringBuilder improves maintainability, and the addition of startup_timeout_sec = 30 provides a reasonable timeout for the Codex CLI startup process.


133-145: Well-designed casing detection and preference logic.

The implementation correctly detects existing casing conventions and preserves them when upserting the Codex server block. The fallback to checking for a parent [mcpServers] section (line 139) is a reasonable heuristic for inferring preferred casing when the unityMCP section doesn't exist yet.


147-166: Clean helper functions for TOML section handling.

The helper functions provide clear abstractions:

  • IsSection correctly identifies section headers while excluding array-of-tables syntax
  • SectionName extracts the section name safely
  • TargetOrChild handles case-insensitive matching for both camelCase and snake_case variants

168-209: Robust section replacement logic.

The parsing and replacement logic correctly:

  • Identifies target sections and their nested tables (e.g., .env)
  • Replaces the entire target region with the new block
  • Preserves the chosen casing convention
  • Appends the block if no existing section is found

@Scriptwonder Scriptwonder merged commit 4a0e633 into CoplayDev:main Oct 17, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant