@@ -100,15 +100,20 @@ function _forge_action_provider() {
100100# The picker hides model_id (field 1) and provider_id (field 4) via --with-nth.
101101#
102102# Arguments:
103- # $1 prompt_text - fzf prompt label (e.g. "Model ❯ ")
104- # $2 current_model - model_id to pre-position the cursor on (may be empty)
105- # $3 input_text - optional pre-fill query for fzf
103+ # $1 prompt_text - fzf prompt label (e.g. "Model ❯ ")
104+ # $2 current_model - model_id to pre-position the cursor on (may be empty)
105+ # $3 input_text - optional pre-fill query for fzf
106+ # $4 current_provider - provider value to disambiguate when model names collide (may be empty)
107+ # $5 provider_field - which porcelain field to match the provider against
108+ # (3 for display name, 4 for raw id)
106109#
107110# Outputs the raw selected line to stdout, or nothing if cancelled.
108111function _forge_pick_model() {
109112 local prompt_text=" $1 "
110113 local current_model=" $2 "
111114 local input_text=" $3 "
115+ local current_provider=" ${4:- } "
116+ local provider_field=" ${5:- } "
112117
113118 local output
114119 output=$( $_FORGE_BIN list models --porcelain 2> /dev/null)
@@ -128,7 +133,14 @@ function _forge_pick_model() {
128133 fi
129134
130135 if [[ -n " $current_model " ]]; then
131- local index=$( _forge_find_index " $output " " $current_model " 1)
136+ # Match on both model_id (field 1) and provider to disambiguate
137+ # when the same model name exists across multiple providers
138+ local index
139+ if [[ -n " $current_provider " && -n " $provider_field " ]]; then
140+ index=$( _forge_find_index " $output " " $current_model " 1 " $provider_field " " $current_provider " )
141+ else
142+ index=$( _forge_find_index " $output " " $current_model " 1)
143+ fi
132144 fzf_args+=(--bind=" start:pos($index )" )
133145 fi
134146
@@ -141,11 +153,14 @@ function _forge_action_model() {
141153 local input_text=" $1 "
142154 (
143155 echo
144- local current_model
156+ local current_model current_provider
145157 current_model=$( _forge_exec config get model 2> /dev/null)
158+ # config get provider returns the display name (e.g. "OpenAI"),
159+ # which corresponds to porcelain field 3 (provider display)
160+ current_provider=$( _forge_exec config get provider 2> /dev/null)
146161
147162 local selected
148- selected=$( _forge_pick_model " Model ❯ " " $current_model " " $input_text " )
163+ selected=$( _forge_pick_model " Model ❯ " " $current_model " " $input_text " " $current_provider " 3 )
149164
150165 if [[ -n " $selected " ]]; then
151166 # Field 1 = model_id (raw), field 3 = provider display name,
@@ -157,9 +172,7 @@ function _forge_action_model() {
157172 provider_display=${provider_display// [[:space:]]/ }
158173
159174 # Switch provider first if it differs from the current one
160- # config get provider returns the display name, so compare against that
161- local current_provider
162- current_provider=$( _forge_exec config get provider --porcelain 2> /dev/null)
175+ # current_provider (fetched above) is the display name, compare against that
163176 if [[ -n " $provider_display " && " $provider_display " != " $current_provider " ]]; then
164177 _forge_exec_interactive config set provider " $provider_id "
165178 fi
@@ -175,11 +188,15 @@ function _forge_action_commit_model() {
175188 local input_text=" $1 "
176189 (
177190 echo
178- local current_commit_model
179- current_commit_model=$( _forge_exec config get commit 2> /dev/null | tail -n 1)
191+ # config get commit outputs two lines: provider_id (raw) then model_id
192+ local commit_output current_commit_model current_commit_provider
193+ commit_output=$( _forge_exec config get commit 2> /dev/null)
194+ current_commit_provider=$( echo " $commit_output " | head -n 1)
195+ current_commit_model=$( echo " $commit_output " | tail -n 1)
180196
181197 local selected
182- selected=$( _forge_pick_model " Commit Model ❯ " " $current_commit_model " " $input_text " )
198+ # provider_id from config get commit is the raw id, matching porcelain field 4
199+ selected=$( _forge_pick_model " Commit Model ❯ " " $current_commit_model " " $input_text " " $current_commit_provider " 4)
183200
184201 if [[ -n " $selected " ]]; then
185202 # Field 1 = model_id (raw), field 4 = provider_id (raw)
@@ -200,11 +217,15 @@ function _forge_action_suggest_model() {
200217 local input_text=" $1 "
201218 (
202219 echo
203- local current_suggest_model
204- current_suggest_model=$( _forge_exec config get suggest 2> /dev/null | tail -n 1)
220+ # config get suggest outputs two lines: provider_id (raw) then model_id
221+ local suggest_output current_suggest_model current_suggest_provider
222+ suggest_output=$( _forge_exec config get suggest 2> /dev/null)
223+ current_suggest_provider=$( echo " $suggest_output " | head -n 1)
224+ current_suggest_model=$( echo " $suggest_output " | tail -n 1)
205225
206226 local selected
207- selected=$( _forge_pick_model " Suggest Model ❯ " " $current_suggest_model " " $input_text " )
227+ # provider_id from config get suggest is the raw id, matching porcelain field 4
228+ selected=$( _forge_pick_model " Suggest Model ❯ " " $current_suggest_model " " $input_text " " $current_suggest_provider " 4)
208229
209230 if [[ -n " $selected " ]]; then
210231 # Field 1 = model_id (raw), field 4 = provider_id (raw)
0 commit comments