Skip to content

Commit 3afca25

Browse files
authored
Merge branch 'main' into feat/recommend-skills-based-on-user-query
2 parents 9cb1a9f + e74c862 commit 3afca25

2 files changed

Lines changed: 53 additions & 22 deletions

File tree

‎shell-plugin/lib/actions/config.zsh‎

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
108111
function _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)

‎shell-plugin/lib/helpers.zsh‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ function _forge_reset() {
5050

5151
# Helper function to find the index of a value in a list (1-based)
5252
# Returns the index if found, 1 otherwise
53-
# Usage: _forge_find_index <output> <value_to_find> [field_number]
54-
# field_number: which field to compare (1 for first field, 2 for second field, etc.)
53+
# Usage: _forge_find_index <output> <value_to_find> [field_number] [field_number2] [value_to_find2]
54+
# field_number: which porcelain column to compare (1-based, using multi-space delimiter)
55+
# field_number2/value_to_find2: optional second column+value for compound matching
5556
# Note: This function expects porcelain output WITH headers and skips the header line
5657
function _forge_find_index() {
5758
local output="$1"
5859
local value_to_find="$2"
59-
local field_number="${3:-1}" # Default to first field if not specified
60+
local field_number="${3:-1}"
61+
local field_number2="${4:-}"
62+
local value_to_find2="${5:-}"
6063

6164
local index=1
6265
local line_num=0
@@ -67,11 +70,18 @@ function _forge_find_index() {
6770
continue
6871
fi
6972

70-
# Extract the specified field for comparison
71-
local field_value=$(echo "$line" | awk "{print \$$field_number}")
73+
local field_value=$(echo "$line" | awk -F ' +' "{print \$$field_number}")
7274
if [[ "$field_value" == "$value_to_find" ]]; then
73-
echo "$index"
74-
return 0
75+
if [[ -n "$field_number2" && -n "$value_to_find2" ]]; then
76+
local field_value2=$(echo "$line" | awk -F ' +' "{print \$$field_number2}")
77+
if [[ "$field_value2" == "$value_to_find2" ]]; then
78+
echo "$index"
79+
return 0
80+
fi
81+
else
82+
echo "$index"
83+
return 0
84+
fi
7585
fi
7686
((index++))
7787
done <<< "$output"

0 commit comments

Comments
 (0)