Add setting actions, setting presets, and cmux config set

Merged
TE
2mo ago
+15448-12077

Tools that tweak cmux settings today rewrite ~/.config/cmux/cmux.json with jq or plutil and then call cmux reload-config. That drops comments, can race the Settings window, and skips schema validation. This adds native ways to make those edits.

Setting actions and presets

Two new action types in the actions registry:

{
  "actions": {
    "scroll.cycle":  { "type": "setting", "title": "Cycle Scroll Speed", "path": "terminal.scrollSpeed", "cycle": [1.0, 1.4, 1.8] },
    "editor.wrap":   { "type": "setting", "title": "Toggle Editor Wrap", "path": "fileEditor.wordWrap", "toggle": true },
    "sidebar.quiet": { "type": "settingPreset", "title": "Quiet Sidebar", "preset": "sidebar.quiet", "confirm": true }
  },
  "settingPresets": {
    "sidebar.quiet": { "sidebar": { "showPorts": false, "showPullRequests": false, "showLog": false } }
  }
}
  • A setting action takes a path plus exactly one of set, toggle: true, cycle, or unset: true.
  • toggle and cycle start from the value cmux is using. That's the cmux.json value if the file sets the key; otherwise the value the Settings window stored in UserDefaults; otherwise the schema default. A value that isn't in the cycle list moves to the first entry.
  • unset removes the key from cmux.json, so the Settings window's value (or the default) applies again.
  • A settingPreset action applies settingPresets.<name>, a new global-only top-level key holding a partial cmux.json. Nested objects merge key by key, so a preset only changes the keys it names.
  • These actions work anywhere other actions do: tab bar buttons (by action reference), shortcuts, and the Command Palette. With "confirm": true, cmux asks before saving and shows the equivalent cmux config command.

cmux config get|set|unset|toggle|cycle|preset

cmux config set terminal.scrollSpeed 1.4, cmux config toggle fileEditor.wordWrap, cmux config preset sidebar.quiet, and so on.

  • <value> is parsed as JSON; plain text is stored as a string.
  • get says where the value came from: cmux.json, (set in Settings, not cmux.json), or (default). --json prints path, file, value, configured, source, and default; the write commands print ok, file, and paths.
  • The CLI reads Settings-window values from the enclosing cmux app's defaults domain, the same way it finds that app's socket.
  • The existing sidebar-font-size and surface-tab-bar-font-size keys keep their Ghostty-config behavior.
  • These commands don't need a socket. The running app picks up the change through its file watcher, so there's no new v2 socket method and nothing for the remote relay policy.

One mutation path

The actions and the CLI both call JSONConfigStore.apply(_:liveValues:) in CmuxSettings. JSONConfigStore's internal mutateRoot takes a list of edits computed under the cooperative writer lock, so toggle, cycle, and a preset read and rewrite the same document in one atomic publication. The existing single-path set, reset, and undo go through it unchanged.

Each change is validated before anything is written:

  • The path must be declared by the schema. CmuxConfigSchemaPathLookup in CmuxFoundation walks the embedded schema and also supplies defaults and allowed types.
  • The path must be outside the non-setting sections (actions, commands, ui, settingPresets, ...).
  • The complete result must add no schema issues.

Comments and unrelated keys survive, as with Settings-window writes. Fractions are written as typed (1.4, not the 1.3999999999999999 JSONSerialization prints for a Double), and re-setting the value already stored is a no-op. The validator learned "$ref": "#", so each settingPresets entry validates as a partial cmux.json in cmux config validate and in editors.

Live values. Most settings are stored in UserDefaults and only overridden by cmux.json, so an absent key's "current value" comes from there (CmuxSettingLiveValues). A stored value is only used when it's a scalar of a type the schema allows at that path; lists and maps are often stored as text, so they fall back to the default. Three keys store a different form and have explicit mappings: app.minimalMode (a mode string), app.keepWorkspaceOpenWhenClosingLastSurface (the inverse flag), and terminal.sessionContentMaxWidth (-1 for false). A catalog-wide test fails if another key the resolver accepts stores a default that disagrees with the schema default, so a new transformed key has to get a mapping.

Design choices

  • Trust. A setting action rewrites the global config, so it only runs when declared in the global cmux.json or a pack that config references (the user chose those packs; they inherit its source path). Project configs and project packs can't declare one: the registry drops them and the runner checks the source again before writing. A project config also can't retitle, rebind, or drop the confirm of a global setting action, through an actions override or a tab bar button. Without this, a repository's .cmux/cmux.json could ship a harmless-looking button that sets automation.socketControlMode.
  • confirm is honored on setting and settingPreset actions like other action types. The project-action trust prompt never covers the global config, so this dialog is the only prompt these actions get.
  • Keys containing . (for example a workspaceGroups.byCwd entry for ~/src/app.web) can't be addressed, because paths split on every .; there's deliberately no escaping syntax. Such a path is refused with an error that says so (keyContainsDot) instead of "isn't a cmux setting", when the rejoined key exists in the file or looks like a path. The docs, CLI contract, and cmux-settings skill say this.

If a write is refused or fails, the palette, shortcut, or button shows an alert with the reason, for example an unknown path, a non-boolean toggle, a value outside the schema, or cmux.json that can't be read.

Tests

  • Package (CmuxSettings CmuxSettingChangeTests/CmuxSettingReadingTests, CmuxFoundation CmuxConfigSchemaPathLookupTests): comment and unrelated-key preservation; toggle and cycle from configured, live, and default values; refusals that leave the file byte-identical; preset merge and refusals; dotted keys versus typos; short-form fractions and the no-op re-set; the stored-value mappings; and the catalog-wide identity check.
  • App host (cmuxTests/CmuxConfigSettingActionTests): decoding and round-trip, the global-only registry rule, global packs allowed and project packs dropped, confirm reaching both the palette action and the button, a project config unable to relabel or unconfirm a global setting action, and the confirmation dialog's text.

Verification

  • CI on 5456a4a5455 (run https://github.com/manaflow-ai/cmux/actions/runs/36321836181): macOS compile admission passed; the app-host changed-suites job passed, including CmuxConfigSettingActionTests. In swift-package-tests every suite this PR adds or changes passed ("Setting changes applied through JSONConfigStore", "Setting readings", "cmux.json schema path lookup"). The job failed once on SimulatorWorkerClientReplayTests ("Restart releases held input before replaying camera state…"), a package that only runs here because it depends on CmuxFoundation. That test passed in main's last three CI runs and passed when the job was rerun on the same head, so it's a flake. After the rerun, every check in that run is green. Guards, localization, schema parity, and web checks passed.
  • CI on an earlier head (run https://github.com/manaflow-ai/cmux/actions/runs/36310670056) caught the 1.3999999999999999 serialization through the new command-description tests, and run https://github.com/manaflow-ai/cmux/actions/runs/36318285721 caught the sessionContentMaxWidth sentinel through the catalog test; both are fixed above.
  • Fleet build of 5456a4a5455: job 0828a893ed7bde939cc6757d, tag pr-14868-setting-actions-v4, bundle cmux DEV pr-14868-setting-actions-v4.app, artifact sha256:6a11b6d38c8af36d2cb24b2bc8fad7a8f0e73f9a0e00bbac82aef11d3571da46. Built with --backend-mode local, because the shared dev backend isn't reachable from this machine; nothing here touches the backend. publish-hq refuses local-backend builds, so there's no HQ link; the zip and receipts are kept locally.
  • Review: two subagent passes (a full review and a pass over the fixes). Fixed from them: toggle/cycle/get ignoring Settings-window values; project overrides of a global setting action; opaque store errors in the alert; keyContainsDot firing on typos; get --json field names; the schema text that said confirm doesn't apply; the transformed UserDefaults keys; and the no-op re-set of fractions.
  • Before merging: GitHub reports a conflict with main in Resources/Localizable.xcstrings that it can't resolve because it doesn't run the repo's .xcstrings merge driver; scripts/merge-main.sh merges it cleanly (it did for this head). Run it right before merge; the catch-up bot skips fork branches.
  • Localization: 12 new macOS strings (7 in the CmuxFoundation catalog, 5 in the app catalog) in all nine required locales (localization_catalog.py check: 0 parity errors). The six custom-commands docs keys are in all 20 web locales.

Dogfood (not run yet)

GUI dogfood on a fleet or cloud Mac was blocked: the cloud-mac lease joins the tailnet as tag:cmux-loader, which this account's ACL can't reach, and no other GUI host is designated. Checks to run on cmux DEV pr-14868-setting-actions-v4.app (or a newer tag for a later head), with the example config above plus a comment in the file:

  1. Add { "action": "editor.wrap" } and { "action": "scroll.cycle" } to ui.surfaceTabBar.buttons. Click each: word wrap flips in an open file editor, and scroll speed steps 1.0 → 1.4 → 1.8 → 1.0 (check with cmux config get terminal.scrollSpeed). The file keeps its comment and other keys, and writes 1.4, not 1.3999999999999999.
  2. Turn word wrap on in Settings (so cmux.json doesn't set it), then run the toggle from the Command Palette: wrap turns off on the first press.
  3. Run Quiet Sidebar from the palette: the confirm dialog shows cmux config preset sidebar.quiet; Cancel changes nothing, Change hides ports, PRs, and the log in the sidebar.
  4. With the tagged app's bundled CLI: cmux config set terminal.scrollSpeed 1.4, get, toggle fileEditor.wordWrap, cycle terminal.scrollSpeed 1 1.4 1.8, preset sidebar.quiet, unset terminal.scrollSpeed. Each updates the running app without a reload. cmux config set terminal.scrollSpeeed 1 and cmux config set actions.x 1 are refused and the file is byte-identical.
  5. Add a project .cmux/cmux.json with a setting action and an override of editor.wrap ("title": "Run Tests", "confirm": false): the project action isn't offered, and the global one keeps its title and confirm.

Screenshots

CI dogfood tour on merged head e82d0862894: run 36742715771.

Command palette showing the setting action and preset

Dark appearance after running the setting action

Command palette showing the setting preset

Light minimal presentation after running the preset

CLI config get and set output

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added configuration actions for setting, toggling, cycling, and unsetting values, plus applying named presets from tab-bar buttons, shortcuts, and the Command Palette.
    • Added matching cmux config commands to read and change settings. Changes are schema-validated, and existing comments and unrelated configuration are preserved.
    • Setting actions can prompt for confirmation before saving.
  • Documentation
    • Updated CLI and custom-action guides with supported operations, presets, and usage limitations.