Repository navigation
CLI: shorter unknown-command errors with suggestions, copy polish #7329
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
f4bd056
CLI: shorter unknown-command errors with suggestions, copy polish
lawrencecchen a2e9e7f
Move command suggestion helpers to CMUXCLI+CommandSuggestions.swift
lawrencecchen 29ed64d
Retrigger CI on WarpBuild runners
lawrencecchen 86bea00
Retrigger CI: display jobs to WarpBuild too
lawrencecchen 181f1b7
select-ci-xcode: never pick a beta Xcode over a stable one
lawrencecchen 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,211 @@ | ||
| import Foundation | ||
|
|
||
| extension CMUXCLI { | ||
| func unknownCommandError(_ command: String) -> CLIError { | ||
| var message = "Unknown command '\(command)'." | ||
| if let suggestion = suggestedCommandName(for: command) { | ||
| message += " Did you mean '\(suggestion)'?" | ||
| } | ||
| message += " Run 'cmux --help' for the full command list." | ||
| return CLIError(message: message, exitCode: 2) | ||
| } | ||
|
|
||
| private func suggestedCommandName(for command: String) -> String? { | ||
| var bestName: String? | ||
| var bestDistance = Int.max | ||
|
|
||
| for candidate in Self.topLevelCommandNames where !candidate.hasPrefix("__") { | ||
| let distance = editDistance(command, candidate) | ||
| guard distance > 0, distance <= 2, distance < candidate.count else { continue } | ||
| if distance < bestDistance || (distance == bestDistance && candidate < (bestName ?? candidate)) { | ||
| bestName = candidate | ||
| bestDistance = distance | ||
| } | ||
| } | ||
|
|
||
| return bestName | ||
| } | ||
|
|
||
| private func editDistance(_ lhs: String, _ rhs: String) -> Int { | ||
| let left = Array(lhs) | ||
| let right = Array(rhs) | ||
| if left.isEmpty { return right.count } | ||
| if right.isEmpty { return left.count } | ||
|
|
||
| var previous = Array(0...right.count) | ||
| var current = Array(repeating: 0, count: right.count + 1) | ||
|
|
||
| for (leftIndex, leftCharacter) in left.enumerated() { | ||
| current[0] = leftIndex + 1 | ||
| for (rightIndex, rightCharacter) in right.enumerated() { | ||
| if leftCharacter == rightCharacter { | ||
| current[rightIndex + 1] = previous[rightIndex] | ||
| } else { | ||
| current[rightIndex + 1] = min(min(previous[rightIndex + 1], current[rightIndex]), previous[rightIndex]) + 1 | ||
| } | ||
| } | ||
| swap(&previous, ¤t) | ||
| } | ||
|
|
||
| return previous[right.count] | ||
| } | ||
|
|
||
| static let topLevelCommandNames: Set<String> = [ | ||
| "__codex-teams-watch", | ||
| "__tmux-compat", | ||
| "agent-hibernation", | ||
| "auth", | ||
| "bind-key", | ||
| "break-pane", | ||
| "browser", | ||
| "browser-back", | ||
| "browser-forward", | ||
| "browser-reload", | ||
| "browser-status", | ||
| "capabilities", | ||
| "capture-pane", | ||
| "claude-hook", | ||
| "claude-teams", | ||
| "clear-history", | ||
| "clear-log", | ||
| "clear-notifications", | ||
| "clear-progress", | ||
| "clear-status", | ||
| "close-surface", | ||
| "close-window", | ||
| "close-workspace", | ||
| "cloud", | ||
| "codex", | ||
| "codex-hook", | ||
| "codex-teams", | ||
| "config", | ||
| "copy-mode", | ||
| "current-window", | ||
| "current-workspace", | ||
| "debug-terminals", | ||
| "detach-tab", | ||
| "diff", | ||
| "disable-browser", | ||
| "dismiss-notification", | ||
| "display-message", | ||
| "docs", | ||
| "drag-surface-to-split", | ||
| "enable-browser", | ||
| "events", | ||
| "feedback", | ||
| "feed", | ||
| "feed-hook", | ||
| "find-window", | ||
| "focus-pane", | ||
| "focus-panel", | ||
| "focus-webview", | ||
| "focus-window", | ||
| "get-url", | ||
| "help", | ||
| "hooks", | ||
| "identify", | ||
| "is-webview-focused", | ||
| "join-pane", | ||
| "jump-to-unread", | ||
| "last-pane", | ||
| "last-window", | ||
| "list-buffers", | ||
| "list-log", | ||
| "list-notifications", | ||
| "list-pane-surfaces", | ||
| "list-panels", | ||
| "list-panes", | ||
| "list-status", | ||
| "list-windows", | ||
| "list-workspaces", | ||
| "log", | ||
| "login", | ||
| "logout", | ||
| "markdown", | ||
| "mark-notification-read", | ||
| "memory", | ||
| "mobile", | ||
| "move-surface", | ||
| "move-tab-to-new-workspace", | ||
| "move-workspace-to-window", | ||
| "navigate", | ||
| "new-pane", | ||
| "new-split", | ||
| "new-surface", | ||
| "new-window", | ||
| "new-workspace", | ||
| "next-window", | ||
| "notify", | ||
| "omc", | ||
| "omo", | ||
| "omx", | ||
| "open", | ||
| "open-browser", | ||
| "open-notification", | ||
| "paste-buffer", | ||
| "ping", | ||
| "pipe-pane", | ||
| "popup", | ||
| "previous-window", | ||
| "read-screen", | ||
| "refresh-surfaces", | ||
| "reload-config", | ||
| "remote-daemon-status", | ||
| "rename-tab", | ||
| "rename-window", | ||
| "rename-workspace", | ||
| "reorder-surface", | ||
| "reorder-workspace", | ||
| "reorder-workspaces", | ||
| "resize-pane", | ||
| "respawn-pane", | ||
| "restore-session", | ||
| "right-sidebar", | ||
| "rpc", | ||
| "select-workspace", | ||
| "send", | ||
| "send-key", | ||
| "send-key-panel", | ||
| "send-panel", | ||
| "set-app-focus", | ||
| "set-buffer", | ||
| "set-hook", | ||
| "set-progress", | ||
| "set-status", | ||
| "settings", | ||
| "setup-hooks", | ||
| "shortcuts", | ||
| "simulate-app-active", | ||
| "sidebar", | ||
| "sidebar-state", | ||
| "split-off", | ||
| "ssh", | ||
| "ssh-pty-attach", | ||
| "ssh-session-attach", | ||
| "ssh-session-cleanup", | ||
| "ssh-session-end", | ||
| "ssh-session-list", | ||
| "ssh-tmux", | ||
| "surface", | ||
| "surface-health", | ||
| "surface-resume", | ||
| "swap-pane", | ||
| "tab-action", | ||
| "themes", | ||
| "top", | ||
| "tree", | ||
| "trigger-flash", | ||
| "unbind-key", | ||
| "uninstall-hooks", | ||
| "version", | ||
| "vm", | ||
| "vm-pty-attach", | ||
| "vm-pty-connect", | ||
| "vm-ssh-attach", | ||
| "wait-for", | ||
| "welcome", | ||
| "workspace", | ||
| "workspace-action", | ||
| "workspace-group", | ||
| ] | ||
| } | ||
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.
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.
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.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
Duplicated source of truth for the command list.
topLevelCommandNamesmust be kept manually in sync with the actual command dispatchswitchstatements incmux.swift. If a command is added/removed there without updating this list, suggestions silently go stale (missing suggestions for new commands, or suggesting removed ones) — a low-severity but easy-to-miss drift.Do you want me to add a regression test that enumerates the real dispatch cases (via reflection/parsing or a shared constant) and asserts parity with
topLevelCommandNames, so drift is caught in CI?🤖 Prompt for AI Agents