-
Notifications
You must be signed in to change notification settings - Fork 0
Preserve legacy manage_script actions, handle validation levels, and add framing safety check #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve legacy manage_script actions, handle validation levels, and add framing safety check #7
Conversation
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR introduces several backward compatibility improvements and safety enhancements to the Unity MCP project. The primary focus is on restoring deprecated manage_script
actions (read, update, edit) as compatibility aliases while maintaining deprecation warnings to guide users toward newer alternatives. The changes also expand validation level support to include 'standard' and 'comprehensive' options alongside existing 'basic' and 'strict' levels.
Key technical improvements include better CRLF newline handling when mapping line/column positions to string indices - a critical fix for Windows environments where text editors use different line ending conventions. The PR also enhances IDE configuration mismatch detection by ensuring these issues are surfaced even when auto-manage is disabled, improving troubleshooting visibility.
For testing infrastructure, the PR adds a 128MB safety cap for framed response lengths in socket tests to prevent memory exhaustion from corrupted protocol frames. Additionally, Python 3.11 is now explicitly pinned in the Pyright configuration to ensure consistent type checking across different development environments.
These changes integrate well with the existing codebase by preserving API compatibility while gradually encouraging migration to preferred methods. The validation level expansion fits naturally into the existing switch-based validation system in ManageScript.cs.
Important Files Changed
Files Modified (4 files)
Filename | Score | Overview |
---|---|---|
UnityMcpBridge/Editor/Tools/ManageScript.cs | 4/5 | Restores deprecated actions as compatibility aliases with warnings and improves CRLF newline handling |
UnityMcpBridge/Editor/Windows/UnityMcpEditorWindow.cs | 5/5 | Adds IDE configuration mismatch detection when auto-manage is disabled |
UnityMcpBridge/UnityMcpServer~/src/pyrightconfig.json | 5/5 | Pins Python 3.11 version for consistent type checking across environments |
test_unity_socket_framing.py | 4/5 | Adds 128MB safety cap for framed response lengths to prevent memory issues |
Confidence score: 4/5
- This PR is relatively safe to merge with some areas requiring attention due to backward compatibility changes
- Score reflects solid safety improvements and defensive programming, but complexity in ManageScript.cs changes requires careful review
- Pay close attention to ManageScript.cs for potential edge cases in CRLF handling and deprecated action routing
Sequence Diagram
sequenceDiagram
participant User
participant MCP_Client as MCP Client
participant Unity_Bridge as Unity Bridge
participant ManageScript as ManageScript Handler
participant ValidationEngine as Validation Engine
participant FileSystem as File System
participant EditorWindow as Editor Window
User->>MCP_Client: "Request script operation"
MCP_Client->>Unity_Bridge: "Send manage_script command"
alt Framing Protocol Check
Unity_Bridge->>Unity_Bridge: "Check response length limits"
Note over Unity_Bridge: Cap framed response to prevent overflow
end
Unity_Bridge->>ManageScript: "HandleCommand(params)"
ManageScript->>ManageScript: "Extract action, name, path, contents"
ManageScript->>ManageScript: "Validate parameters"
ManageScript->>ManageScript: "TryResolveUnderAssets(path)"
alt Legacy Action Warning
Note over ManageScript: If action is 'read', 'update', or 'edit'
ManageScript->>ManageScript: "Log deprecation warning"
ManageScript->>ManageScript: "Continue with backward compatibility"
end
alt Action: validate
ManageScript->>ManageScript: "Parse validation level (basic/standard/strict/comprehensive)"
ManageScript->>FileSystem: "Read script file"
FileSystem-->>ManageScript: "File contents"
ManageScript->>ValidationEngine: "ValidateScriptSyntax(contents, level)"
alt Roslyn Available
ValidationEngine->>ValidationEngine: "Use Roslyn compiler services"
else Fallback
ValidationEngine->>ValidationEngine: "Use basic structure validation"
end
ValidationEngine-->>ManageScript: "Validation results with diagnostics"
ManageScript-->>Unity_Bridge: "Formatted diagnostics response"
end
alt Action: apply_text_edits
ManageScript->>FileSystem: "Read current file"
FileSystem-->>ManageScript: "Current contents"
ManageScript->>ManageScript: "Check precondition SHA256"
ManageScript->>ManageScript: "Convert line/col to indices (handle CRLF)"
ManageScript->>ManageScript: "Validate edit ranges don't overlap"
ManageScript->>ManageScript: "Apply edits from back to front"
ManageScript->>ManageScript: "Check balanced delimiters"
opt Roslyn Validation
ManageScript->>ValidationEngine: "Parse and validate syntax"
ValidationEngine-->>ManageScript: "Syntax check results"
end
ManageScript->>FileSystem: "Atomic write with temp file"
ManageScript->>ManageScript: "Schedule asset refresh"
end
alt Action: create/update (legacy)
ManageScript->>EditorWindow: "Get validation level from GUI settings"
EditorWindow-->>ManageScript: "Current validation level"
ManageScript->>ValidationEngine: "ValidateScriptSyntax(contents, level)"
ValidationEngine-->>ManageScript: "Validation results"
alt Validation Failed
ManageScript-->>Unity_Bridge: "Error response with details"
else Validation Passed
ManageScript->>FileSystem: "Write script file atomically"
ManageScript->>ManageScript: "Schedule debounced refresh"
ManageScript-->>Unity_Bridge: "Success response"
end
end
Unity_Bridge->>Unity_Bridge: "Apply framing safety check"
Unity_Bridge-->>MCP_Client: "Return response (framed if protocol supports)"
MCP_Client-->>User: "Operation result"
4 files reviewed, no comments
Summary
Testing
pytest -q
https://chatgpt.com/codex/tasks/task_e_68a083d83a108327a0cb602fdeb3b1a7