Repository navigation
TUI: /model slash command opens cached-model picker overlay - #173
Conversation
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.
There was a problem hiding this comment.
💡 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".
| if FModelMenuSelIdx > 0 then | ||
| Dec(FModelMenuSelIdx); | ||
| KEY_DOWN: | ||
| if FModelMenuSelIdx < FModelMenuVisibleN - 1 then |
There was a problem hiding this comment.
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.
Summary
Type
/modelinsidepasclaw tuito pick from the cached/v1/modelsroster for the active session's provider (falls back toCfg.DefaultProviderwhen the session hasn't recorded one)./themepicker; 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 andpasclaw model refresh./modelas a line-based command: bare/modelprints 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
$PASCLAW_HOME/cache/models/<provider>.jsonpopulated bypasclaw 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./v1/modelslookup + cache + onboarding picker #171 Codex P2 contract (two configs sharing a Kind but different APIBase don't collide).FSession.Meta.Model(persisted on the next turn's auto-save). It does NOT touchconfig.json— durable per-user defaults are stillpasclaw model set.OpenThemeMenuandOpenModelMenueach close the other's*MenuOpenflag before opening, so there's never a case where two modals fight for the keys.model show#172 pattern.FModelMenuVisibleNrecords 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 inmodel show#172 fixed in the onboard picker.Test plan
makeclean rebuild succeeds (FPC, mode Delphi)make test— all suites pass includingmodel_discovery_testspasclaw tuiagainst a provider with cached models, type/model, confirm:meta.modelpersists on next turn)/themeand/modelclose each other (mutual exclusion)pasclaw tuiagainst a provider with no cache; type/model, confirm hint flashes/modellists,/model <id>switchesGenerated by Claude Code