Repository navigation
fix(ui): ⌘O opens macOS Documents folder instead of workspace directory - #2056
BillionClaw wants to merge 2 commits into
Conversation
Claude Code integration is now enabled by default (PR manaflow-ai#247, 0.60.0), so the manual hooks configuration in settings.json is no longer needed. Kept OpenAI Codex and OpenCode integration examples which are still relevant. Fixes manaflow-ai#2009.
NSOpenPanel defaults to ~/Documents when directoryURL is not set. Both the command palette "Open Folder" handler and the File menu handler now set panel.directoryURL to the selected workspace's currentDirectory (if it exists and is non-empty), matching the behavior of the terminal panel 'Open in Finder' actions. Fixes manaflow-ai#2010
|
@BillionClaw is attempting to deploy a commit to the Manaflow Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughUpdated the "Open Folder…" command to preselect the currently selected workspace's directory in the macOS file picker, validating the path exists before applying it. Removed Claude Code Hooks documentation section. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Greptile SummaryThis PR fixes the long-standing UX issue where ⌘O / File → Open Folder… always opened macOS's default ~/Documents picker instead of the current workspace's directory. The fix seeds
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Handler as ⌘O / File Menu Handler
participant TM as TabManager
participant FM as FileManager
participant Panel as NSOpenPanel
User->>Handler: Press ⌘O (or File → Open Folder…)
Handler->>TM: selectedWorkspace
alt workspace selected
TM-->>Handler: workspace.currentDirectory
Handler->>Handler: trim whitespace
alt directory non-empty
Handler->>FM: fileExists(atPath: directory)
FM-->>Handler: exists = true/false
alt exists == true
Handler->>Panel: directoryURL = URL(fileURLWithPath: directory)
else not found or empty
Note over Handler,Panel: panel falls back to macOS default
end
end
else no workspace
Note over Handler,Panel: panel falls back to macOS default
end
Handler->>Panel: runModal()
Panel-->>User: Folder picker (seeded to workspace dir)
User->>Panel: Selects folder → OK
Panel-->>Handler: url
Handler->>TM: addWorkspace(workingDirectory: url.path)
Reviews (1): Last reviewed commit: "fix(ui): ⌘O opens macOS Documents folder..." | Re-trigger Greptile |
| if !directory.isEmpty, FileManager.default.fileExists(atPath: directory) { | ||
| panel.directoryURL = URL(fileURLWithPath: directory, isDirectory: true) |
There was a problem hiding this comment.
Verify path is a directory, not just that it exists
FileManager.default.fileExists(atPath:) returns true for both files and directories. If workspace.currentDirectory ever resolves to a file path (e.g., due to a stale workspace record), the URL would still be set as isDirectory: true and passed to NSOpenPanel.directoryURL. Using the isDirectory: variant explicitly confirms the path is a directory before using it:
| if !directory.isEmpty, FileManager.default.fileExists(atPath: directory) { | |
| panel.directoryURL = URL(fileURLWithPath: directory, isDirectory: true) | |
| if !directory.isEmpty, FileManager.default.fileExists(atPath: directory, isDirectory: &isDir), isDir.boolValue { |
Full suggestion (requires adding var isDir: ObjCBool = false before the check):
if let workspace = tabManager.selectedWorkspace {
let directory = workspace.currentDirectory.trimmingCharacters(in: .whitespacesAndNewlines)
var isDir: ObjCBool = false
if !directory.isEmpty, FileManager.default.fileExists(atPath: directory, isDirectory: &isDir), isDir.boolValue {
panel.directoryURL = URL(fileURLWithPath: directory, isDirectory: true)
}
}Same pattern applies to the equivalent block in Sources/cmuxApp.swift.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
Sources/ContentView.swift (1)
5979-5984: Validate that the path is a directory before assigningpanel.directoryURL.At Line 5981,
fileExists(atPath:)also returns true for regular files. That can set a non-directory URL as the panel’s start location and break the intended fallback behavior.Proposed fix
if let workspace = tabManager.selectedWorkspace { let directory = workspace.currentDirectory.trimmingCharacters(in: .whitespacesAndNewlines) - if !directory.isEmpty, FileManager.default.fileExists(atPath: directory) { + var isDirectory: ObjCBool = false + if !directory.isEmpty, + FileManager.default.fileExists(atPath: directory, isDirectory: &isDirectory), + isDirectory.boolValue { panel.directoryURL = URL(fileURLWithPath: directory, isDirectory: true) } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Sources/ContentView.swift` around lines 5979 - 5984, When setting panel.directoryURL from the workspace path (in the block referencing tabManager.selectedWorkspace and workspace.currentDirectory), validate that the path is actually a directory — not just an existing file — before assigning it to panel.directoryURL; use FileManager.fileExists(atPath:isDirectory:) (or URL.resourceValues for .isDirectory) to check the isDirectory flag and only set panel.directoryURL when isDirectory is true so the panel’s fallback behavior remains intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@Sources/cmuxApp.swift`:
- Around line 596-601: The code sets panel.directoryURL whenever the path exists
but doesn't ensure it's a directory; update the check around
activeTabManager.selectedWorkspace -> workspace.currentDirectory so you only set
panel.directoryURL when the path both exists and is a directory (use
FileManager.default.fileExists(atPath:isDirectory:) or equivalent to test
isDirectory and only assign to panel.directoryURL when isDirectory is true),
otherwise leave panel.directoryURL unset to allow default behavior.
---
Nitpick comments:
In `@Sources/ContentView.swift`:
- Around line 5979-5984: When setting panel.directoryURL from the workspace path
(in the block referencing tabManager.selectedWorkspace and
workspace.currentDirectory), validate that the path is actually a directory —
not just an existing file — before assigning it to panel.directoryURL; use
FileManager.fileExists(atPath:isDirectory:) (or URL.resourceValues for
.isDirectory) to check the isDirectory flag and only set panel.directoryURL when
isDirectory is true so the panel’s fallback behavior remains intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 74927850-40ae-4c1b-9a8c-22446427667c
📒 Files selected for processing (3)
Sources/ContentView.swiftSources/cmuxApp.swiftdocs/notifications.md
💤 Files with no reviewable changes (1)
- docs/notifications.md
| if let workspace = activeTabManager.selectedWorkspace { | ||
| let directory = workspace.currentDirectory.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| if !directory.isEmpty, FileManager.default.fileExists(atPath: directory) { | ||
| panel.directoryURL = URL(fileURLWithPath: directory, isDirectory: true) | ||
| } | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify whether `currentDirectory` is guaranteed to always be a directory.
# Expected: assignments/initialization sites should only use directory sources
# (workspace roots, cwd, validated directory paths).
rg -n --type swift -C4 '\b(var|let)\s+currentDirectory\b'
rg -n --type swift -C4 '\bcurrentDirectory\s*='
rg -n --type swift -C4 '\bcurrentDirectory\b.*(URL|path|cwd|workingDirectory)'Repository: manaflow-ai/cmux
Length of output: 10968
Ensure panel.directoryURL is set only for actual directories.
At Line 598, the code checks only path existence. If workspace.currentDirectory is a file path, Line 599 still forces a directory URL and can open from an unexpected location instead of falling back to default behavior.
Proposed fix
if let workspace = activeTabManager.selectedWorkspace {
let directory = workspace.currentDirectory.trimmingCharacters(in: .whitespacesAndNewlines)
- if !directory.isEmpty, FileManager.default.fileExists(atPath: directory) {
+ var isDirectory: ObjCBool = false
+ if !directory.isEmpty,
+ FileManager.default.fileExists(atPath: directory, isDirectory: &isDirectory),
+ isDirectory.boolValue {
panel.directoryURL = URL(fileURLWithPath: directory, isDirectory: true)
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if let workspace = activeTabManager.selectedWorkspace { | |
| let directory = workspace.currentDirectory.trimmingCharacters(in: .whitespacesAndNewlines) | |
| if !directory.isEmpty, FileManager.default.fileExists(atPath: directory) { | |
| panel.directoryURL = URL(fileURLWithPath: directory, isDirectory: true) | |
| } | |
| } | |
| if let workspace = activeTabManager.selectedWorkspace { | |
| let directory = workspace.currentDirectory.trimmingCharacters(in: .whitespacesAndNewlines) | |
| var isDirectory: ObjCBool = false | |
| if !directory.isEmpty, | |
| FileManager.default.fileExists(atPath: directory, isDirectory: &isDirectory), | |
| isDirectory.boolValue { | |
| panel.directoryURL = URL(fileURLWithPath: directory, isDirectory: true) | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@Sources/cmuxApp.swift` around lines 596 - 601, The code sets
panel.directoryURL whenever the path exists but doesn't ensure it's a directory;
update the check around activeTabManager.selectedWorkspace ->
workspace.currentDirectory so you only set panel.directoryURL when the path both
exists and is a directory (use
FileManager.default.fileExists(atPath:isDirectory:) or equivalent to test
isDirectory and only assign to panel.directoryURL when isDirectory is true),
otherwise leave panel.directoryURL unset to allow default behavior.
|
Thanks for the contribution! This has been addressed by #2034 which was just merged. |
⌘O (Open Folder) and the File → Open Folder… menu item both opened an NSOpenPanel
without setting
directoryURL, causing macOS to default to ~/Documents regardless ofthe current workspace.
The fix sets
panel.directoryURLto the selected workspace'scurrentDirectorybefore displaying the panel — the same approach already used by the terminal panel's
"Reveal in Finder" action. If no workspace is selected or the directory is empty/
invalid, the panel falls back to the default behavior.
Changed files:
Sources/ContentView.swift: command palette "Open Folder" handlerSources/cmuxApp.swift: File menu "Open Folder…" handlerFixes #2010
Summary by cubic
Fixes ⌘O and File → Open Folder… so the open dialog starts in the active workspace directory instead of ~/Documents (Fixes #2010). Both the command palette and File menu set NSOpenPanel.directoryURL from the selected workspace when valid, with a safe fallback.
Written for commit 1939f91. Summary will update on new commits.
Summary by CodeRabbit
Improvements
Documentation