Skip to content

TUI: /model slash command opens cached-model picker overlay - #173

Merged
FMXExpress merged 2 commits into
mainfrom
claude/tui-slash-model
Jun 7, 2026
Merged

FMXExpress merged 2 commits into
mainfrom
claude/tui-slash-model

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Summary

Type /model inside pasclaw tui to pick from the cached /v1/models roster for the active session's provider (falls back to Cfg.DefaultProvider when the session hasn't recorded one).

  • Delphi build paints a modal overlay — Up/Down navigates, Enter applies, Esc cancels. Same shape as the existing /theme picker; only one overlay is open at a time. The modal's subtitle shows how stale the cache is (e.g. "cached 12 models (refreshed 3 days ago)") so the operator knows whether to drop out and pasclaw model refresh.
  • FPC build exposes /model as a line-based command: bare /model prints the cached list and current selection; /model <id> switches the active model for the running TUI (no cache validation — the operator might know about a model the cache hasn't seen yet).

Design notes

  • No live HTTP from the UI thread. The picker reads $PASCLAW_HOME/cache/models/<provider>.json populated by pasclaw model refresh / pasclaw onboard. An inline fetch would freeze the event loop while we wait on the network. When the cache is empty for the provider, the TUI flashes a hint instead of opening an empty picker.
  • Cache lookup keys on the operator-facing provider Name, matching the PR Model discovery: live /v1/models lookup + cache + onboarding picker #171 Codex P2 contract (two configs sharing a Kind but different APIBase don't collide).
  • Picking a model updates FSession.Meta.Model (persisted on the next turn's auto-save). It does NOT touch config.json — durable per-user defaults are still pasclaw model set.
  • Mutual exclusion between the theme and model overlays — OpenThemeMenu and OpenModelMenu each close the other's *MenuOpen flag before opening, so there's never a case where two modals fight for the keys.
  • Validation cap follows the PR Model picker: re-use existing key on re-onboard + inline preview in model show #172 pattern. FModelMenuVisibleN records the rows actually printed (capped to fit the terminal height + a 20-row hard ceiling); arrow-key bounds and Enter validation check that, not the full roster length. Prevents the "highlight a row that isn't drawn" off-by-one that PR Model picker: re-use existing key on re-onboard + inline preview in model show #172 fixed in the onboard picker.

Test plan

  • make clean rebuild succeeds (FPC, mode Delphi)
  • make test — all suites pass including model_discovery_tests
  • Run pasclaw tui against a provider with cached models, type /model, confirm:
    • Modal opens centred with current model preselected
    • Up/Down navigates within visible window; selection follows when list is paged
    • Enter applies (status flashes "model: ", meta.model persists on next turn)
    • Esc cancels without mutating FModel
    • /theme and /model close each other (mutual exclusion)
  • Run pasclaw tui against a provider with no cache; type /model, confirm hint flashes
  • FPC build: /model lists, /model <id> switches

Generated by Claude Code

Type `/model` inside `pasclaw tui` to pick from the cached /v1/models
roster for the active session's provider (falls back to
Cfg.DefaultProvider). Delphi build paints a modal overlay with
Up/Dn navigation, Enter to apply, Esc to cancel — same shape as the
existing /theme picker. FPC build exposes /model as a line-based
command: bare prints the cached list and current selection, `/model
<id>` switches the active model for the running TUI.

Cache lookup reads $PASCLAW_HOME/cache/models/<provider>.json
populated by `pasclaw model refresh` / `pasclaw onboard` — no live
HTTP from the UI thread. Modal subtitle shows cache freshness so
the operator knows whether to drop out and refresh. Picking a
model updates FSession.Meta.Model (persisted on next turn) but
does not touch config.json — use `pasclaw model set` for that.

Validation cap (FModelMenuVisibleN) follows the PR #172 Codex P2
pattern: arrow-key bounds and Enter validation check rows actually
printed, not full roster length.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19dca961b8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/pkg/tui/PasClaw.TUI.pas Outdated
if FModelMenuSelIdx > 0 then
Dec(FModelMenuSelIdx);
KEY_DOWN:
if FModelMenuSelIdx < FModelMenuVisibleN - 1 then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Allow scrolling through all cached models

When the cached roster has more entries than the visible box can show (for example more than 20 models, or fewer on a short terminal), Down stops at FModelMenuVisibleN - 1, so the picker can never advance beyond the first visible window even though DrawModelMenu is written to scroll the list. This makes later cached models impossible to select from the /model overlay; the bounds check should use the full Length(FModelMenuModels) while the draw code handles windowing.

Useful? React with 👍 / 👎.

Down-key bound was capped at FModelMenuVisibleN - 1 (the visible
window count), so on a roster with more than ~20 cached models —
or fewer on a short terminal — the user couldn't reach anything
past the first page even though DrawModelMenu was already
windowing the printed rows around FModelMenuSelIdx.

Pattern was lifted from the PR #172 onboard-picker fix, but that
picker is line-based and never scrolls — the validation cap there
matches what was printed once. The TUI overlay re-paints every
frame and scrolls, so the bound must be the full roster length.

Drop FModelMenuVisibleN (no remaining users) and bound KEY_DOWN
on Length(FModelMenuModels) - 1.
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