# CLI and TUI configuration surface

One schema describes every setting; every surface renders it. A new setting is one `SettingSpec` and appears everywhere, with no per-surface code. No setting is web-only.

| Surface | Reaches the schema through |
| --- | --- |
| `openprogram config list`, `get KEY`, `set KEY VALUE` | `get_settings`, `set_setting` |
| `openprogram setup` wizard, `openprogram ports` | `get_settings`, `set_setting` |
| TUI `/config` panel | WebSocket `get_settings`, `set_setting` on the existing `BackendClient` |
| Web pages | REST `/api/settings` |

Code: `openprogram/state/settings.py`, `interfaces/server/ws_actions/settings.py`, `apps/cli/src/components/SettingsPanel.tsx`. Command grammar: [CLI naming convention](https://fzkuji.github.io/OpenProgram/docs/reference/design/cli/naming.html). No new transport or process.

## Commands

| Rule | Behaviour |
| --- | --- |
| Modes are verbs | `openprogram web` launches the web UI, bare `openprogram` launches chat. No `--tui`, `--web` or `--cli`. |
| Container verbs (`programs`, `skills`, `plugins`, `sessions`, `channels`, `memory`, `worker`, `mcp`, `subagent`) | Invoked bare: print the subcommand list and exit non-zero, all through `_need_subcommand(parser)`, because per-dispatcher `print_help()` calls drift |
| Verbs with a real default | `providers` lists pools, `ports` shows the port, `config` lists settings |
| Self-documenting | Every `add_argument` and `add_parser` has `help=`; top-level `--help` has a common-commands epilog |
| `setup` | First-run walk; `setup <section>` jumps to one section, `setup menu` opens the picker |
| `config get`, `config set` | Scriptable, the stable target for documentation; same validated path as a panel edit |

## Schema

```
@dataclass(frozen=True)
class SettingSpec:
    key: str             # stable id, e.g. "ui.web_port"
    path: tuple[str, ...]  # dot-path into config.json
    group: str           # "Ports", "Memory", ...
    label: str
    widget: str          # "number", "toggle", "enum", "text", "json"
    apply: str           # "live" or "next_start"
    default: Any = None
    choices: Callable[[], list[str]] | None = None
    validate: Callable[[Any], str | None] | None = None  # error or None
    help: str = ""
    secret: bool = False
    minimum: int | None = None
```

| Part | Design |
| --- | --- |
| `SETTINGS` | The ordered list; source of truth |
| `get_settings()` | Reads `config.json` once, resolves values, computes `choices()` lazily, masks secrets |
| `set_setting(key, value)` | Validates, then writes through the key's typed helper when one exists (`set_ui_ports` for `ui.*`), else a generic dot-path write. Returns `{applied, value}` or `{error}` |
| Blocked keys | The dot-path write refuses `__proto__`, `constructor`, `prototype` at every level |
| Location | `~/.openprogram/config.json`, through the profile-aware `get_config_path()` |
| Dynamic keys | `tools.disabled.<name>` toggles a tool, live. `providers.*` status rows are read-only |
| Apply | `live`: re-read per use. `next_start`: read once at bind time (`ui.web_port`, `memory.backend`). The surface says so at the moment of the edit |

Per-agent model, effort and skills stay in the agent record, reached through the action rows below.

## TUI panel

`/config`, also from the Ctrl+K palette: a persistent editor over live state, built on `Picker` with group, field and editor levels. Enum fields reuse `Picker`; number and text use `LineInput`.

| Area | Behaviour |
| --- | --- |
| Schema groups | Ports, Models, Memory, Search, Tools, Execution, Security, Voice and the rest of `SETTINGS`, in registry order |
| Action rows | Model, thinking effort, permission mode, theme and Claude accounts launch `/model`, `/effort`, `/permissions`, `/theme`, `/login` instead of duplicating them |
| Ports | `config set` adds the holder from `with_port_owner_note`. The panel reports rather than seizes |
| Theme | Previews on cursor move, rolls back on ESC; no Apply step |
| Providers, channels | Status and an action, never inline secret entry; OAuth is not reimplemented in a text box |
| Keybinds | No settings group: the TUI has no keybind config file |

Ctrl+K renders the slash-command registry (name and description) through the same `Picker`, with keybind hints; `/config`, `/model` and `/theme` surface there uniformly. It changes no grammar.

## Implementation status

Schema, renderers and transport are implemented.
