Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5976,6 +5976,9 @@ struct ContentView: View {
panel.allowsMultipleSelection = false
panel.title = String(localized: "panel.openFolder.title", defaultValue: "Open Folder")
panel.prompt = String(localized: "panel.openFolder.prompt", defaultValue: "Open")
if let currentDir = tabManager.selectedTab?.currentDirectory {
panel.directoryURL = URL(fileURLWithPath: currentDir)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Prefer isDirectory: true for directory URLs

URL(fileURLWithPath:) without an isDirectory argument will inspect the filesystem (or fall back to a heuristic based on the trailing slash) to decide whether to treat the path as a directory. Since currentDirectory is always a directory path, pass isDirectory: true explicitly to guarantee a well-formed directory URL is handed to NSOpenPanel.

Suggested change
panel.directoryURL = URL(fileURLWithPath: currentDir)
panel.directoryURL = URL(fileURLWithPath: currentDir, isDirectory: true)

@cubic-dev-ai cubic-dev-ai Bot Mar 25, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Open-folder panel start directory is derived from an unvalidated path, so empty/invalid values can open the picker in an unexpected location.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Sources/ContentView.swift, line 5980:

<comment>Open-folder panel start directory is derived from an unvalidated path, so empty/invalid values can open the picker in an unexpected location.</comment>

<file context>
@@ -5976,6 +5976,9 @@ struct ContentView: View {
                 panel.title = String(localized: "panel.openFolder.title", defaultValue: "Open Folder")
                 panel.prompt = String(localized: "panel.openFolder.prompt", defaultValue: "Open")
+                if let currentDir = tabManager.selectedTab?.currentDirectory {
+                    panel.directoryURL = URL(fileURLWithPath: currentDir)
+                }
                 if panel.runModal() == .OK, let url = panel.url {
</file context>
Fix with Cubic

}
Comment on lines +5979 to +5981

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Use focused directory + validate path before assigning directoryURL.

Line 5979 currently uses selectedTab?.currentDirectory directly. That can miss the focused panel’s cwd and can also assign invalid/empty paths, which weakens the intended “fallback to system default” behavior.

Suggested fix
-                if let currentDir = tabManager.selectedTab?.currentDirectory {
-                    panel.directoryURL = URL(fileURLWithPath: currentDir)
-                }
+                if let directory = focusedDirectory {
+                    let trimmed = directory.trimmingCharacters(in: .whitespacesAndNewlines)
+                    var isDirectory: ObjCBool = false
+                    if !trimmed.isEmpty,
+                       FileManager.default.fileExists(atPath: trimmed, isDirectory: &isDirectory),
+                       isDirectory.boolValue {
+                        panel.directoryURL = URL(fileURLWithPath: trimmed, 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 - 5981, Replace the direct use
of tabManager.selectedTab?.currentDirectory with the focused panel's cwd (e.g.,
check tabManager.focusedTab?.focusedPanel?.currentDirectory first, then fall
back to tabManager.selectedTab?.currentDirectory), and validate the path before
assigning to panel.directoryURL: ensure the string is non-empty and
FileManager.default.fileExists(atPath:isDirectory:) returns true for a
directory; only then set panel.directoryURL = URL(fileURLWithPath: validPath) so
the system default fallback remains intact when the path is missing or invalid.

if panel.runModal() == .OK, let url = panel.url {
tabManager.addWorkspace(workingDirectory: url.path)
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/cmuxApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,9 @@ struct cmuxApp: App {
panel.allowsMultipleSelection = false
panel.title = String(localized: "menu.file.openFolder.panelTitle", defaultValue: "Open Folder")
panel.prompt = String(localized: "menu.file.openFolder.panelPrompt", defaultValue: "Open")
if let currentDir = activeTabManager.selectedTab?.currentDirectory {
panel.directoryURL = URL(fileURLWithPath: currentDir)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Prefer isDirectory: true for directory URLs

Same note as ContentView.swift: use URL(fileURLWithPath: currentDir, isDirectory: true) to produce a canonical directory URL without a filesystem round-trip.

Suggested change
panel.directoryURL = URL(fileURLWithPath: currentDir)
panel.directoryURL = URL(fileURLWithPath: currentDir, isDirectory: true)

}
Comment on lines +596 to +598

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Validate currentDirectory before assigning panel.directoryURL.

On Line 597, currentDirectory is treated as a guaranteed local folder path. In practice this value can be stale/remote/non-existent, which can make the picker open in an unintended location instead of using the system default fallback.

Suggested fix
-                    if let currentDir = activeTabManager.selectedTab?.currentDirectory {
-                        panel.directoryURL = URL(fileURLWithPath: currentDir)
-                    }
+                    if let currentDir = activeTabManager.selectedTab?.currentDirectory?
+                        .trimmingCharacters(in: .whitespacesAndNewlines),
+                       !currentDir.isEmpty {
+                        let candidateURL = URL(fileURLWithPath: currentDir).standardizedFileURL
+                        var isDirectory: ObjCBool = false
+                        if FileManager.default.fileExists(atPath: candidateURL.path, isDirectory: &isDirectory),
+                           isDirectory.boolValue {
+                            panel.directoryURL = candidateURL
+                        }
+                    }

Based on learnings from Sources/Workspace.swift and Sources/TerminalView.swift, currentDirectory is a raw string updated from terminal-reported paths and is not guaranteed to be a valid local directory.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Sources/cmuxApp.swift` around lines 596 - 598, The code assumes
activeTabManager.selectedTab?.currentDirectory is a valid local folder; instead
verify it before assigning panel.directoryURL: get the currentDirectory string
from activeTabManager.selectedTab?.currentDirectory, check with FileManager
(e.g., FileManager.default.fileExists(atPath:isDirectory:)) that the path exists
and is a directory, and only then set panel.directoryURL = URL(fileURLWithPath:
currentDirectory); if the check fails, do not set panel.directoryURL so the
system default is used. This touches the currentDirectory usage in the code near
activeTabManager.selectedTab?.currentDirectory and the panel.directoryURL
assignment.

if panel.runModal() == .OK, let url = panel.url {
if let appDelegate = AppDelegate.shared {
if appDelegate.addWorkspaceInPreferredMainWindow(
Expand Down