Repository navigation
Route terminal file URL links to the OS #7122
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f7c5343
Add failing file URL routing regression
austinywang d1758fe
Route terminal file URL links externally
austinywang 663dce8
Address file URL routing policy review
austinywang bac1e07
Address Greptile file URL routing feedback
austinywang c62a007
Cover hosted terminal file URL targets
austinywang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...xTerminalCore/Sources/CmuxTerminalCore/LinkRouting/TerminalOpenURLFileRoutingPolicy.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| public import Foundation | ||
|
|
||
| /// Decides whether a terminal open-URL target may be handled by cmux's file UI. | ||
| public struct TerminalOpenURLFileRoutingPolicy: Sendable { | ||
| /// Creates the file-routing policy. | ||
| public init() {} | ||
|
|
||
| /// Returns whether cmux may attempt to open the target in its file preview UI. | ||
| /// | ||
| /// The caller still owns settings, file existence, workspace locality, and | ||
| /// split creation checks. This policy only answers whether the raw terminal | ||
| /// open-URL payload represents a local file shape that cmux is allowed to | ||
| /// intercept before the normal URL routing decision. | ||
| /// | ||
| /// - Parameters: | ||
| /// - rawOpenURLValue: The raw open-URL payload from the terminal runtime. | ||
| /// - target: The parsed terminal link target. | ||
| public func shouldAttemptCmuxFileRouting( | ||
| rawOpenURLValue: String, | ||
| target: TerminalOpenURLTarget | ||
| ) -> Bool { | ||
| guard !hasExplicitURLScheme(rawOpenURLValue) else { return false } | ||
| guard target.url.isFileURL else { return false } | ||
| return isLocalFileURL(target.url) | ||
| } | ||
|
|
||
| private func hasExplicitURLScheme(_ rawValue: String) -> Bool { | ||
| let trimmed = rawValue.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| guard let scheme = URL(string: trimmed)?.scheme else { return false } | ||
| return !scheme.isEmpty | ||
| } | ||
|
|
||
| private func isLocalFileURL(_ url: URL) -> Bool { | ||
| url.host?.isEmpty ?? true | ||
|
austinywang marked this conversation as resolved.
|
||
| } | ||
| } | ||
57 changes: 57 additions & 0 deletions
57
.../CmuxTerminalCore/Tests/CmuxTerminalCoreTests/TerminalOpenURLFileRoutingPolicyTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import Foundation | ||
| import Testing | ||
| import CmuxTerminalCore | ||
|
|
||
| @Suite struct TerminalOpenURLFileRoutingPolicyTests { | ||
| private let policy = TerminalOpenURLFileRoutingPolicy() | ||
|
|
||
| @Test func explicitFileSchemeBypassesCmuxFileRouting() throws { | ||
| let url = try #require(URL(string: "file:///Users/dev/out/ab_cosyvoice_emo.wav")) | ||
| #expect( | ||
| policy.shouldAttemptCmuxFileRouting( | ||
| rawOpenURLValue: url.absoluteString, | ||
| target: .external(url) | ||
| ) == false | ||
| ) | ||
| } | ||
|
|
||
| @Test func localhostFileSchemeBypassesCmuxFileRouting() throws { | ||
| let url = try #require(URL(string: "file://localhost/Users/dev/out/ab_cosyvoice_emo.wav")) | ||
| #expect( | ||
| policy.shouldAttemptCmuxFileRouting( | ||
| rawOpenURLValue: url.absoluteString, | ||
| target: .external(url) | ||
| ) == false | ||
| ) | ||
| } | ||
|
|
||
| @Test func hostedFileTargetBypassesCmuxFileRoutingEvenWithoutRawScheme() throws { | ||
| let url = try #require(URL(string: "file://remote-host/Users/dev/out/ab_cosyvoice_emo.wav")) | ||
| #expect( | ||
| policy.shouldAttemptCmuxFileRouting( | ||
| rawOpenURLValue: "/Users/dev/out/ab_cosyvoice_emo.wav", | ||
| target: .external(url) | ||
| ) == false | ||
| ) | ||
| } | ||
|
|
||
| @Test func absolutePathCanStillUseCmuxFileRouting() { | ||
| let url = URL(fileURLWithPath: "/Users/dev/project/README.md") | ||
| #expect( | ||
| policy.shouldAttemptCmuxFileRouting( | ||
| rawOpenURLValue: "/Users/dev/project/README.md", | ||
| target: .external(url) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test func nonFileTargetsBypassCmuxFileRouting() throws { | ||
| let url = try #require(URL(string: "https://example.com/audio.wav")) | ||
| #expect( | ||
| policy.shouldAttemptCmuxFileRouting( | ||
| rawOpenURLValue: url.absoluteString, | ||
| target: .embeddedBrowser(url) | ||
| ) == false | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.