Skip to content

feat(tui): wire LLM tier settings and flag config drift on connected tools#34

Merged
akozak-gd merged 7 commits into
mainfrom
feat/tui-mcp-llm-tier-settings
Jul 10, 2026
Merged

feat(tui): wire LLM tier settings and flag config drift on connected tools#34
akozak-gd merged 7 commits into
mainfrom
feat/tui-mcp-llm-tier-settings

Conversation

@akozak-gd

@akozak-gd akozak-gd commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes the TUI LLM model-tier settings actually take effect, lets users set tiers before connecting an AI tool, flags connected tools left on stale config after a Settings change, and shows per-model validity against the active provider catalog. Previously the Settings screen wrote tier keys that nothing read, so configured models were silently ignored.

Entrypoint

Start in mcp_server/tui/config.py where EDITABLE_KEYS is now sourced from services.llm_tiers.LLM_TIER_KEYS, then mcp_server/tui/mcp_clients.py for config_fingerprint and stale_connected_ids, then mcp_server/tui/app.py where ClientSetupScreen and SettingsScreen wire the model-tiers box, the orange drift overlay, and the validation workers. Model validity reuses the existing backend endpoint via services/validate_models.request_model_validation_for.

Diagram

Settings edit ──save──> mcp-config.json (env block)
                              │  connect bakes the whole block into each tool
                              ▼
   Claude (mcp add-json) / Cursor (~/.cursor/mcp.json)   ← fingerprint recorded per client
                              │
   later edit ──> block fingerprint changes ──> connected tool now STALE (orange, reconnect)

tier values ──> POST /api/v1/models/validate ──> per-model valid / invalid / unverified
                              │
        connect box: ✓/✗/• per tier + red note w/ suggestion   |   Settings: ✓/✗ marker per field

Details

The tier-key fix is the core correctness change: the MCP server and backend read LLM_HIGH/MEDIUM/LOW, but the screen wrote LLM_MODEL_*, so save_env now sources the real keys from the shared LLM_TIER_KEYS and purges the dead legacy names (also so they never skew a config fingerprint).

Drift detection exists because connecting bakes the entire env block into each tool, so a later Settings edit does not reach an already-connected tool. A fingerprint of the baked block is stored per client in a new sibling client_configs section of ~/.specflow/config.json (the clients status schema is untouched, no migration). The Claude presence probe deliberately never writes the fingerprint — it confirms the server is registered, not what env it holds, so writing there would silently clear a real drift.

Model validation is best-effort and reuses the existing /api/v1/models/validate endpoint. request_model_validation_for takes explicit tier values because the TUI edits the config file rather than its own process env. Any failure (backend down, catalog unreachable) leaves markers neutral, never a false red. It validates on the connect screen when opened and in Settings on mount and on Enter (not per keystroke), and the did-you-mean suggestion only appears when the backend catalog has a near-match.

One non-obvious layout fix: the Settings marker was correct but rendered off the right edge because the row input did not flex, so .settings-row inputs are now 1fr with a fixed-width marker. No onboarding step was added — onboarding is architecturally .env-only and mcp-config.json does not exist until init runs at the wizard end.

Testing

make unit-tests green (655 passed); new coverage spans the tier-key SSOT and legacy purge, fingerprint/staleness helpers and the orange overlay, connect/probe fingerprint behavior, the Settings drift routing, the validation client and glyph mapping, the validated tiers box and Settings markers, and a regression test that the marker stays within the viewport. ruff clean on all changed files.

akozak-gd added 2 commits July 9, 2026 09:33
…tools

Fix the Settings screen writing dead LLM_MODEL_* keys nothing reads: the
runtime keys now come from services.llm_tiers.LLM_TIER_KEYS (LLM_HIGH/
MEDIUM/LOW) as the single source of truth, with friendly labels and a
save-time purge of the legacy names.

Connecting bakes the whole env block into each AI tool's own config, so a
later Settings edit does not reach an already-connected tool. Record a
fingerprint of the block baked into each client at connect time (new
client_configs section in ~/.specflow/config.json) and surface drift:

- ClientSetupScreen renders a connected-but-stale client in orange with a
  reconnect affordance; pressing enter re-bakes and clears the flag.
- SettingsScreen warns and routes to the connect screen when a runtime
  change leaves connected tools on stale config.
- 'm' on the connect screen opens tier settings before connecting.

Probe deliberately never writes the fingerprint (it confirms presence, not
env); a dropped connection forgets it. Correct the module docstring that
claimed edits propagate to every client.
Drop EDITABLE_LABELS and render the raw env keys (LLM_HIGH/MEDIUM/LOW,
WORKSPACE_COUNT, ...) so the Settings screen matches what appears in
mcp-config.json verbatim.
@akozak-gd akozak-gd marked this pull request as ready for review July 9, 2026 07:47
Comment thread mcp_server/tui/app.py
# keep them working but out of the footer. The footer carries navigation.
Binding("d", "show_config", "raw config", show=False),
Binding("v", "recheck", "re-scan", show=False),
Binding("m", "edit_tiers", "model tiers", show=False),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit small to notice.

I liked your idea of a info box at the bottom explaining

you are on models ..... now, and press "m" to change them.
Notice: changes in MCP servers take effect in the harness sandbox from the next run, not current one (in case its already running)

Comment thread mcp_server/tui/app.py
self._set_status(client.client_id, mcp_clients.ClientStatus.NOT_CONFIGURED)
self._render_detail()

def _is_stale(self, client_id: str, status: mcp_clients.ClientStatus) -> bool:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this app.py is getting extremely long. Maybe its a good idea to start splitting into tui/settings_logic.py and tui/components.py and others

As such _is_stale is pretty specific

Comment thread mcp_server/tui/app.py
akozak-gd added 4 commits July 9, 2026 14:59
Add a persistent footer note to ClientSetupScreen listing the model tiers a
connect would bake in (blank tier = backend default), the 'm' affordance to
change them, and the standing caveat that a tier change reaches the sandbox
only from the next run — a generation already in progress keeps its models.
Makes the previously easy-to-miss 'm' binding discoverable.
Replace the plain one-line tiers note with a titled Panel on the connect
screen: a tier/model/purpose grid (high → planning & KB init, medium → code
generation, low → simple steps) plus the 'm' affordance and the next-run
caveat. Blank tiers show as the backend default.
Surface per-model validity in the TUI using the existing
/api/v1/models/validate endpoint. Add request_model_validation_for(), which
validates explicit LLM_* values from the local config block (the TUI edits
mcp-config.json, not its own env, so the env-based path does not fit).

Connect screen: a background worker validates on open and re-renders the
tiers box with a per-tier glyph (✓ available / ✗ unsupported / • unchecked),
tints each model, and lists invalid models with the backend's suggestion.
Settings: each tier field carries a live ✓/✗ marker updated on mount and on
submit. Both are best-effort — a missing backend or unreachable catalog
leaves everything neutral, never red.
The per-tier ✓/✗ marker was correctly set but rendered off the right edge:
the row's Input did not flex, so label+input already overflowed the viewport
and the trailing marker landed past it. Make .settings-row inputs 1fr and give
the marker a fixed width so it always stays visible. Add a regression test
asserting the marker region falls within the viewport.
@akozak-gd akozak-gd requested a review from awrobel-gd July 9, 2026 13:41
Comment thread mcp_server/services/validate_models.py Outdated
awrobel-gd
awrobel-gd previously approved these changes Jul 9, 2026

@awrobel-gd awrobel-gd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one follow-up comment

Address review: apply_llm_tier_overrides mutated its argument in place (a
hidden side effect). Add pure llm_tier_overrides_from_env() that returns the
overrides, and keep apply_llm_tier_overrides as a thin in-place wrapper for
generation_orchestrator (which accumulates several field groups into one form).
request_model_validation now passes the returned dict directly — no mutation.
Behavior is byte-identical, so the backend request is unchanged.
@akozak-gd akozak-gd merged commit 3eab694 into main Jul 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants