Repository navigation
Add an off switch for agent messages (global, per agent, per workspace) #16551
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
11 commits
Select commit
Hold shift + click to select a range
61a56c5
agent messages: add an off switch (global, per agent, per workspace)
teamleaderleo 112bcc7
agent-messages: close the toggle race and keep shown messages delivered
teamleaderleo 98d9a56
Merge remote-tracking branch 'origin/main' into feat-agent-message-of…
teamleaderleo 7a91e41
Merge remote-tracking branch 'origin/main' into feat-agent-message-of…
teamleaderleo f976c98
Merge remote-tracking branch 'origin/main' into feat-agent-message-of…
teamleaderleo 9b59264
Merge remote-tracking branch 'origin/main' into feat-agent-message-of…
teamleaderleo a3a5486
agent-messages: say when a surface's workspace is off, and fail only …
teamleaderleo 1d147ec
Merge remote-tracking branch 'origin/main' into feat-agent-message-of…
teamleaderleo 3da33b4
Merge remote-tracking branch 'origin/main' into feat-agent-message-of…
teamleaderleo 91b6333
Merge remote-tracking branch 'origin/main' into feat-agent-message-of…
teamleaderleo 1c17408
agent-messages: keep the string catalog in main's order
teamleaderleo 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import Foundation | ||
|
|
||
| /// `cmux agent messages [on|off|status] [<target>] [--workspace]`: turns agent | ||
| /// messages off or on for one surface or workspace through | ||
| /// `agent.message.settings`. The app-wide switch is `agentMessages.enabled`. | ||
| extension CMUXCLI { | ||
| static var agentMessagesHelp: String { | ||
| String(localized: "cli.help.agentMessages", defaultValue: """ | ||
| Usage: cmux agent messages [on|off|status] [<target>] [--workspace] [--json] | ||
|
|
||
| Turn agent messages off or on for one agent, or show whether it gets | ||
| them. Turning messages off for an agent refuses new messages to it and | ||
| marks the ones already queued for it as failed. | ||
|
|
||
| <target> is resolved like cmux agent message: a workspace or surface id | ||
| or ref, or a workspace title. Without one, the command applies to the | ||
| surface it runs in. --workspace applies to every surface in the | ||
| workspace instead. | ||
|
|
||
| Without --workspace, a workspace target means the one agent surface it | ||
| resolves to now. That surface stays off even if a different surface | ||
| becomes the workspace's agent later. | ||
|
|
||
| To turn agent messages off everywhere, set agentMessages.enabled to | ||
| false in ~/.config/cmux/cmux.json or turn off Settings > Automation > | ||
| Agent Messages. | ||
|
|
||
| Examples: | ||
| cmux agent messages off | ||
| cmux agent messages on workspace:3 | ||
| cmux agent messages off --workspace cmux-remote-status | ||
| """) | ||
| } | ||
|
|
||
| /// Per-verb help for `cmux agent <verb> --help`, or `nil` for verbs that | ||
| /// use the `cmux agent` family text. | ||
| static func agentSubcommandHelp(_ verb: String?) -> String? { | ||
| switch verb?.lowercased() { | ||
| case "message", "msg": return agentMessageHelp | ||
| case "inbox": return agentInboxHelp | ||
| case "messages": return agentMessagesHelp | ||
| default: return nil | ||
| } | ||
| } | ||
|
|
||
| /// Parsed `cmux agent messages` arguments. | ||
| struct AgentMessagesSettingArguments: Equatable { | ||
| /// `nil` reads the current setting. | ||
| var enabled: Bool? | ||
| var target: String? | ||
| var workspace: Bool | ||
| } | ||
|
|
||
| static func parseAgentMessagesSettingArguments(_ args: [String]) throws -> AgentMessagesSettingArguments { | ||
| var parsed = AgentMessagesSettingArguments(enabled: nil, target: nil, workspace: false) | ||
| var words: [String] = [] | ||
| for arg in args { | ||
| switch arg { | ||
| case "--json": continue | ||
| case "--workspace": parsed.workspace = true | ||
| default: | ||
| guard !arg.hasPrefix("--") else { throw CLIError(message: agentMessagesHelp) } | ||
| words.append(arg) | ||
| } | ||
| } | ||
| if let verb = words.first?.lowercased(), ["on", "off", "status"].contains(verb) { | ||
| parsed.enabled = verb == "status" ? nil : verb == "on" | ||
| words.removeFirst() | ||
| } | ||
| guard words.count <= 1 else { throw CLIError(message: agentMessagesHelp) } | ||
| parsed.target = words.first | ||
| return parsed | ||
| } | ||
|
|
||
| func runAgentMessagesSetting(_ args: [String], client: SocketClient, jsonOutput: Bool) throws { | ||
| let parsed = try Self.parseAgentMessagesSettingArguments(args) | ||
| var params: [String: Any] = ["scope": parsed.workspace ? "workspace" : "surface"] | ||
| if let enabled = parsed.enabled { params["enabled"] = enabled } | ||
| if let target = parsed.target { params["target"] = target } | ||
| let env = ProcessInfo.processInfo.environment | ||
| if let surface = env["CMUX_SURFACE_ID"], !surface.isEmpty { params["surface_id"] = surface } | ||
| if let workspace = env["CMUX_WORKSPACE_ID"], !workspace.isEmpty { params["workspace_id"] = workspace } | ||
|
|
||
| let payload = try client.sendV2(method: "agent.message.settings", params: params) | ||
| if jsonOutput { | ||
| print(jsonString(payload)) | ||
| return | ||
| } | ||
| let ref = payload["ref"] as? String ?? "?" | ||
| let title = payload["workspace_title"] as? String ?? "" | ||
| let label = title.isEmpty ? ref : "\(ref) (\(title))" | ||
| let format = payload["receiving"] as? Bool == false | ||
| ? String(localized: "cli.agentMessages.off", defaultValue: "Messages to %@ are off.") | ||
| : String(localized: "cli.agentMessages.on", defaultValue: "Messages to %@ are on.") | ||
| print(String(format: format, label)) | ||
| if payload["workspace_receiving"] as? Bool == false { | ||
| print(String( | ||
| localized: "cli.agentMessages.workspaceOff", | ||
| defaultValue: "Its workspace has messages off, so it receives none." | ||
| )) | ||
| } | ||
| if payload["messages_enabled"] as? Bool == false { | ||
| print(String( | ||
| localized: "cli.agentMessages.globalOff", | ||
| defaultValue: "Agent messages are turned off for all of cmux (agentMessages.enabled is 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
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.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Fix the
String(format:)call that uses a localized format string without an%@check.String(localized:defaultValue:)takes aString.LocalizationValue. The format"Messages to %@ are off."is a plain literal in the default value. The catalog entry may reorder or omit%@in a translation.String(format: format, label)then readslabelas a C vararg. AStringpassed asCVarArgwith%@works in Foundation on macOS. The call can still crash if a translation uses a different specifier, such as%d. Interpolatelabelinside the localized string instead. This removes the runtime format step.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents