Fix #3075: accept named colors in cmux.json and degrade gracefully on parse errors

Closed
AU
2mo ago
+205-7

Summary

Fixes #3075. Before this PR, a single command in cmux.json with a named color (e.g. "color": "Indigo") caused the entire config file to be silently rejected — no commands loaded, cmux reload-config returned OK, and the sidebar showed no error. The decoder only accepted #RRGGBB hex strings, and one rejected command failed the whole top-level JSONDecoder().decode(CmuxConfigFile.self, ...) call.

Two-part fix:

  • Accept named palette colors. CmuxWorkspaceDefinition now resolves the color field via a new resolveColor(_:) helper that accepts either a 6-digit hex (with/without #) or a case-insensitive match against WorkspaceTabColorSettings.defaultPalette (Red, Navy, Indigo, Purple, Charcoal, ...). "Indigo" now resolves to #283593.
  • Degrade gracefully on parse errors. New CmuxConfigFile.parseLenient(_:) decodes each command independently. One malformed command (bad color, bad layout, missing fields, etc.) no longer poisons its siblings — it is returned as a warning alongside the commands that did load. CmuxConfigStore.parseConfig now uses this path and logs each warning via NSLog so misconfigured entries are visible.

This matches the issue's expected behavior: "Both commands appear, or at minimum Echo still appears and a parse warning is logged."

Two-commit structure (per project policy)

  1. First commit adds failing regression tests only (named-color resolution + lenient parsing). CI should be red.
  2. Second commit adds the fix. CI should be green.

Repro (from the issue)

{
  "commands": [
    {
      "name": "Indigo Workspace",
      "workspace": { "name": "Indigo", "color": "Indigo" }
    },
    { "name": "Echo", "command": "echo hi" }
  ]
}
  • Before: neither command appeared; no error shown.
  • After: both commands appear; the Indigo workspace uses #283593. If the color were a typo like "Indigoo", only that command is skipped (with a logged warning), and Echo still appears.

Test plan

  • CI: unit tests in cmuxTests/CmuxConfigTests.swift pass on the fix commit.
  • CI: the first commit fails the new tests (proves the tests exercise the bug).
  • Manual: place the repro cmux.json in the project root, cmux reload-config, confirm both commands appear in the command palette with the Indigo color on the workspace.
  • Manual: swap "Indigo" for "NotARealColor" and confirm Echo still appears in the palette and the system log shows a [CmuxConfig] Skipped command warning.

[!NOTE]
Medium Risk
Changes config decoding behavior and error handling, which can affect which commands load from user cmux.json files. Risk is mitigated by added unit tests covering named colors and partial-failure parsing.

Overview
Fixes cmux.json regressions by accepting named palette colors (e.g. "Indigo", case-insensitive) for workspace color, resolving them to normalized hex.

Updates config loading to degrade gracefully on per-command decode failures via CmuxConfigFile.parseLenient, so malformed commands are skipped with logged warnings while valid sibling commands still load, instead of rejecting the entire file.

Reviewed by Cursor Bugbot for commit 62b87418c2da090af5915e4416351ea684c919a1. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • New Features

    • Added support for named workspace colors (e.g., "Indigo", "Navy") with case-insensitive matching.
  • Bug Fixes

    • Configuration parsing is now more resilient; invalid individual commands no longer prevent the entire configuration from loading, with warnings logged for skipped items.
  • Tests

    • Added test coverage for named color resolution and lenient parsing behavior.

Summary by cubic

Fix #3075 by accepting named palette colors in cmux.json and making config loading tolerant. A bad command no longer drops the whole file; valid commands still load and a warning is logged.

  • Bug Fixes
    • Color resolution: CmuxWorkspaceDefinition.resolveColor accepts 6-digit hex (with/without #) and case-insensitive names from WorkspaceTabColorSettings.defaultPalette (e.g. "Indigo" -> #283593).
    • Lenient loading: CmuxConfigFile.parseLenient decodes commands independently and returns warnings; CmuxConfigStore.parseConfig uses it and logs each warning via NSLog.