Repository navigation
Add unified surface selection context API #10022
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
+3,401
−66
Merged
Changes from all commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
5269a5a
Test unified surface selection reads
austinywang 932782b
Implement unified surface selection reads
austinywang 2f6ba70
Harden surface selection contracts
austinywang 3caaad1
Use modern SwiftUI change callback
austinywang 64428da
Fix read-selection RPC example
austinywang 8c48965
Mount WebKit selection behavior fixture
austinywang 8f87781
Retain WebKit selections across focus handoff
austinywang 47144ca
Track WebKit selection in the page world
austinywang 6389dd0
Preserve WebKit selections across native focus
austinywang 8af3343
Treat WebKit focus reconciliation as observational
austinywang d8d907f
Exercise WebKit selection callbacks in page world
austinywang e977f30
Probe WebKit selection tracker state
austinywang 79ee7df
Make WebKit selection reads snapshot-only
austinywang 4dbee45
Preserve browser navigation lifecycle in selection test
austinywang 5e76a32
Use local URL for browser selection fixture
austinywang a6e6b68
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang 3cf798d
Stabilize browser portal layout assertions
austinywang ecc564d
Test stale browser selection invalidation
austinywang 4880365
Invalidate stale selections and avoid topology sweeps
austinywang 98c3dc6
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang 866806e
Keep current Ghostty and Bonsplit revisions
austinywang cf10d6b
Bound selection invalidation and polling
austinywang 927ed85
Harden async and relayed selection reads
austinywang 255cb20
Make selection timeout and RPC routing safe
austinywang def4539
Bound terminal and raw RPC selection reads
austinywang a022bcd
Bound shared selection snapshots
austinywang 802370a
Test immutable WebKit selection bridge
austinywang 024b7cf
Harden WebKit selection lifecycle and deadlines
austinywang cecaf84
Harden selection bridge and terminal capture
austinywang 03984fd
Bound WebKit selection extraction
austinywang ce4df2f
Serialize terminal selection reads with teardown
austinywang ef89d3d
Harden selection clearing and Unicode bounds
austinywang d58f9ca
Harden selection routing and WebKit deadlines
austinywang 65aee70
Split surface selection test support
austinywang 577cbb2
Bound selection evaluation and relay ownership
austinywang efac590
Close canceled selection evaluation race
austinywang 6ead2e4
Fix selection timeout script type reference
austinywang a67ecf6
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang 60aa8ff
Align Bonsplit revision with current main APIs
austinywang c0ce9d8
Harden merged surface selection lifecycle
austinywang e7a9e13
Return WebKit selection evaluation results
austinywang 9d923ad
Fix WebKit selection script indentation
austinywang bc8011d
Stabilize browser selection fixture focus transitions
austinywang f464766
Merge current main and preserve selection test wiring
austinywang fd87a8b
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang e5655dd
Merge origin/main into issue-10020-surface-selection-context
austinywang 4bb044b
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang c880b8f
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang 6df52d4
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang 19b4ccb
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang 54ffd3e
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang e0102e2
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang 61b39e7
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang 58fa01d
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang 144afc5
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang cb504dd
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang d284ac4
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang b36a0bb
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang 073aded
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang 15830fc
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang 1b4a36a
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang 7780bd7
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang afbb797
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang 3111744
Preserve browser selections across native focus handoff
austinywang afba5a1
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang b04a102
Make focus handoff regression assertion environment independent
austinywang 728b8e2
Give CLI routing tests a bounded cold-start margin
austinywang f59a6ab
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang 0f1e8aa
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang b43dcdf
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang b7d7eb3
Allow more headroom for hosted CLI routing tests
austinywang abdae7b
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang f34cd66
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
austinywang 3593e6c
Merge remote-tracking branch 'origin/main' into issue-10020-surface-s…
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
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
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,217 @@ | ||
| import Foundation | ||
|
|
||
| extension CMUXCLI { | ||
| func runSurfaceSelectionCommand( | ||
| commandName: String, | ||
| commandArgs: [String], | ||
| client: SocketClient, | ||
| jsonOutput: Bool, | ||
| windowOverride: String?, | ||
| includeContextInPlainOutput: Bool | ||
| ) throws { | ||
| let (workspaceOption, remainingAfterWorkspace) = parseOption( | ||
| commandArgs, | ||
| name: "--workspace" | ||
| ) | ||
| let (surfaceOption, remainingAfterSurface) = parseOption( | ||
| remainingAfterWorkspace, | ||
| name: "--surface" | ||
| ) | ||
| let (windowOption, trailing) = parseOption( | ||
| remainingAfterSurface, | ||
| name: "--window" | ||
| ) | ||
| guard trailing.isEmpty else { | ||
| throw CLIError(message: String( | ||
| format: String( | ||
| localized: "cli.readSelection.error.unexpectedArguments", | ||
| defaultValue: "%@: unexpected arguments: %@" | ||
| ), | ||
| commandName, | ||
| trailing.joined(separator: " ") | ||
| )) | ||
| } | ||
|
|
||
| let windowRaw = windowOption ?? windowOverride | ||
| let workspaceRaw = workspaceOption | ||
| ?? Self.callerWorkspaceForSurfaceHandle(surfaceOption, windowRaw: windowRaw) | ||
| let surfaceRaw = surfaceOption | ||
| ?? (workspaceOption == nil && windowRaw == nil | ||
| ? ProcessInfo.processInfo.environment["CMUX_SURFACE_ID"] | ||
| : nil) | ||
|
|
||
| var params: [String: Any] = [:] | ||
| let windowID = try normalizeWindowHandle(windowRaw, client: client) | ||
| if let windowID { | ||
| params["window_id"] = windowID | ||
| } | ||
| let workspaceID = try normalizeWorkspaceHandle( | ||
| workspaceRaw, | ||
| client: client, | ||
| windowHandle: windowID | ||
| ) | ||
| if let workspaceID { | ||
| params["workspace_id"] = workspaceID | ||
| } | ||
| let surfaceID = try normalizeSurfaceHandle( | ||
| surfaceRaw, | ||
| client: client, | ||
| workspaceHandle: workspaceID, | ||
| windowHandle: windowID | ||
| ) | ||
| if let surfaceID { | ||
| params["surface_id"] = surfaceID | ||
| } | ||
|
|
||
| let payload = try client.sendV2( | ||
| method: "surface.read_selection", | ||
| params: params | ||
| ) | ||
| if jsonOutput { | ||
| print(jsonString(payload)) | ||
| return | ||
| } | ||
| guard (payload["has_selection"] as? Bool) == true else { | ||
| if includeContextInPlainOutput { | ||
| let metadata = surfaceSelectionMetadataLines(payload) | ||
| if !metadata.isEmpty { | ||
| print(metadata.joined(separator: "\n")) | ||
| print("") | ||
| } | ||
| } | ||
| print(String( | ||
| localized: "cli.readSelection.output.noActiveSelection", | ||
| defaultValue: "Has selection: false" | ||
| )) | ||
| return | ||
| } | ||
|
|
||
| let text = (payload["text"] as? String) ?? "" | ||
| guard includeContextInPlainOutput else { | ||
| print(text) | ||
| return | ||
| } | ||
|
|
||
| let metadata = surfaceSelectionMetadataLines(payload) | ||
| if !metadata.isEmpty { | ||
| print(metadata.joined(separator: "\n")) | ||
| print("") | ||
| } | ||
| print(text) | ||
| } | ||
|
|
||
| private func surfaceSelectionMetadataLines( | ||
| _ payload: [String: Any] | ||
| ) -> [String] { | ||
| var lines: [String] = [] | ||
| if let kind = payload["kind"] as? String, !kind.isEmpty { | ||
| lines.append(String( | ||
| format: String( | ||
| localized: "cli.readSelection.output.kind", | ||
| defaultValue: "Kind: %@" | ||
| ), | ||
| kind | ||
| )) | ||
| } | ||
| if let filePath = payload["file_path"] as? String, !filePath.isEmpty { | ||
| lines.append(String( | ||
| format: String( | ||
| localized: "cli.readSelection.output.file", | ||
| defaultValue: "File: %@" | ||
| ), | ||
| filePath | ||
| )) | ||
| } | ||
| if let range = payload["line_range"] as? [String: Any], | ||
| let start = surfaceSelectionLineNumber(range["start"]), | ||
| let end = surfaceSelectionLineNumber(range["end"]) { | ||
| if start == end { | ||
| lines.append(String( | ||
| format: String( | ||
| localized: "cli.readSelection.output.line", | ||
| defaultValue: "Line: %lld" | ||
| ), | ||
| Int64(start) | ||
| )) | ||
| } else { | ||
| lines.append(String( | ||
| format: String( | ||
| localized: "cli.readSelection.output.lines", | ||
| defaultValue: "Lines: %lld-%lld" | ||
| ), | ||
| Int64(start), | ||
| Int64(end) | ||
| )) | ||
| } | ||
| } | ||
| if let url = payload["url"] as? String, !url.isEmpty { | ||
| lines.append(String( | ||
| format: String( | ||
| localized: "cli.readSelection.output.url", | ||
| defaultValue: "URL: %@" | ||
| ), | ||
| url | ||
| )) | ||
| } | ||
| return lines | ||
| } | ||
|
|
||
| private func surfaceSelectionLineNumber(_ value: Any?) -> Int? { | ||
| if let value = value as? Int { | ||
| return value | ||
| } | ||
| return (value as? NSNumber)?.intValue | ||
| } | ||
|
|
||
| static var readSelectionHelp: String { | ||
| String(localized: "cli.help.readSelection", defaultValue: """ | ||
| Usage: cmux read-selection [flags] | ||
|
|
||
| Read the active selection from any selectable surface. Plain output includes source context; --json returns the complete response. | ||
|
|
||
| Flags: | ||
| --workspace <id|ref|index> Target workspace (default: $CMUX_WORKSPACE_ID) | ||
| --surface <id|ref|index> Target surface (default: $CMUX_SURFACE_ID) | ||
| --window <id|ref|index> Window context for workspace/surface refs and indexes | ||
|
|
||
| Example: | ||
| cmux read-selection --surface surface:2 | ||
| cmux read-selection --surface surface:2 --json | ||
| """) | ||
| } | ||
|
|
||
| static var readScreenHelp: String { | ||
| String(localized: "cli.help.readScreen", defaultValue: """ | ||
| Usage: cmux read-screen [flags] | ||
|
|
||
| Read terminal text from a surface as plain text. | ||
|
|
||
| Flags: | ||
| --workspace <id|ref|index> Target workspace (default: $CMUX_WORKSPACE_ID) | ||
| --surface <id|ref|index> Target surface (default: $CMUX_SURFACE_ID) | ||
| --window <id|ref|index> Window context for workspace/surface refs and indexes | ||
| --scrollback Include scrollback (not just visible viewport) | ||
| --lines <n> Limit to the last n lines (implies --scrollback) | ||
| --selection Read only the active selection; cannot be combined with --scrollback or --lines | ||
|
|
||
| Example: | ||
| cmux read-screen | ||
| cmux read-screen --surface surface:2 --scrollback --lines 200 | ||
| cmux read-screen --surface surface:2 --selection | ||
| """) | ||
| } | ||
|
|
||
| static var readSelectionUsageLine: String { | ||
| String( | ||
| localized: "cli.usage.readSelection", | ||
| defaultValue: "read-selection [--workspace <id|ref|index>] [--surface <id|ref|index>] [--window <id|ref|index>]" | ||
| ) | ||
| } | ||
|
|
||
| static var readScreenUsageLine: String { | ||
| String( | ||
| localized: "cli.usage.readScreen", | ||
| defaultValue: "read-screen [--workspace <id|ref|index>] [--surface <id|ref|index>] [--window <id|ref|index>] [--scrollback] [--lines <n>] [--selection]" | ||
| ) | ||
| } | ||
| } | ||
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
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
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
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.