saving-token 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -45,18 +45,20 @@ After publication, run:
45
45
  npx saving-token@latest install --agent codex
46
46
  ```
47
47
 
48
- The wrapper supports `install --agent codex` and keeps the interactive menus.
48
+ The wrapper supports `install --agent codex` and `update-models --agent codex`.
49
49
  Use the Bash script directly for `--target`, `--model`, `--reasoning-effort`,
50
50
  or `--yes`.
51
51
 
52
- To refresh only the suggested models in an existing Codex installation, run:
52
+ To choose a new writer model in an existing Codex installation, run:
53
53
 
54
54
  ```bash
55
55
  npx saving-token@latest update-models --agent codex
56
56
  ```
57
57
 
58
- It changes no writer configuration and shows no setup menus. Use the Bash
59
- script with `--update-models --target claude` or `cursor` for those platforms.
58
+ Use **Up/Down** and **Enter** to choose the model. It updates the model list
59
+ and only the writer's model field; it preserves the reasoning effort and shows
60
+ no platform, effort, or confirmation menus. Use the Bash script with
61
+ `--update-models --target claude` or `cursor` for those platforms.
60
62
 
61
63
  ### Installed paths
62
64
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saving-token",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "bin": {
5
5
  "saving-token": "bin/saving-token.cjs"
6
6
  },
@@ -98,7 +98,7 @@ Esc cancels before any files are changed.
98
98
  --model ID Skip the model menu; required without a terminal.
99
99
  --reasoning-effort EFFORT Optional. Omit to use the host's default behavior.
100
100
  --yes Approve installation and displayed replacements.
101
- --update-models Update only model suggestions in an installed Skill.
101
+ --update-models Choose and update the writer model in an installed Skill.
102
102
  -h, --help Show this help.
103
103
 
104
104
  Model suggestions are not an account availability check. Use only models and
@@ -170,6 +170,22 @@ case "$target" in
170
170
  *) fail "Unsupported target '$target'. Expected codex, claude, or cursor." ;;
171
171
  esac
172
172
 
173
+ agent_target="$agent_dir/$agent_file"
174
+
175
+ choose_writer_model() {
176
+ local prompt=$1
177
+ local -a model_options
178
+ local model
179
+
180
+ model_options=()
181
+ for model in "${models[@]}"; do model_options[${#model_options[@]}]="$model|$model"; done
182
+ if choose_menu "$prompt" "${model_options[@]}"; then
183
+ writer_model=$MENU_RESULT
184
+ return 0
185
+ fi
186
+ return 1
187
+ }
188
+
173
189
  update_installed_model_suggestions() {
174
190
  local installed_setup temporary_setup model_line
175
191
 
@@ -205,21 +221,66 @@ update_installed_model_suggestions() {
205
221
  fi
206
222
 
207
223
  mv -f "$temporary_setup" "$installed_setup"
208
- printf 'Updated model suggestions for %s in %s. Writer configuration was not changed.\n' "$target" "$installed_setup"
224
+ printf 'Updated model suggestions for %s in %s.\n' "$target" "$installed_setup"
225
+ }
226
+
227
+ update_writer_model() {
228
+ local temporary_agent model_line cursor_effort line
229
+
230
+ [[ -f "$agent_target" ]] || fail "No writer configuration found at $agent_target. Run install first."
231
+ if [[ "$target" == codex ]]; then
232
+ model_line="model = \"$writer_model\""
233
+ else
234
+ cursor_effort=''
235
+ if [[ "$target" == cursor ]]; then
236
+ while IFS= read -r line || [[ -n "$line" ]]; do
237
+ if [[ "$line" =~ ^model:\ \"[^\"]*(\[effort=[^]]+\])\"$ ]]; then
238
+ cursor_effort=${BASH_REMATCH[1]}
239
+ break
240
+ fi
241
+ done < "$agent_target"
242
+ fi
243
+ model_line="model: \"$writer_model$cursor_effort\""
244
+ fi
245
+
246
+ temporary_agent="$(mktemp "$(dirname -- "$agent_target")/.${agent_file}.XXXXXX")"
247
+ cp -p "$agent_target" "$temporary_agent"
248
+ if ! awk -v target="$target" -v model_line="$model_line" '
249
+ (target == "codex" && $0 ~ /^model = "[^"]*"$/) ||
250
+ (target != "codex" && $0 ~ /^model: "[^"]*"$/) {
251
+ replacements++
252
+ print model_line
253
+ next
254
+ }
255
+ { print }
256
+ END { exit replacements == 1 ? 0 : 1 }
257
+ ' "$agent_target" > "$temporary_agent"; then
258
+ rm -f "$temporary_agent"
259
+ fail "Could not find one model field in $agent_target. Run install to refresh the writer configuration."
260
+ fi
261
+ if cmp -s "$agent_target" "$temporary_agent"; then
262
+ rm -f "$temporary_agent"
263
+ printf 'Writer model for %s is already %s.\n' "$target" "$writer_model"
264
+ return
265
+ fi
266
+
267
+ mv -f "$temporary_agent" "$agent_target"
268
+ printf 'Updated writer model for %s to %s.\n' "$target" "$writer_model"
209
269
  }
210
270
 
211
271
  if [[ "$update_models" == true ]]; then
272
+ [[ -t 0 ]] || fail '--update-models requires a terminal to choose a writer model.'
273
+ if ! choose_writer_model 'Choose a writer model to update:'; then
274
+ cancel_install
275
+ fi
212
276
  update_installed_model_suggestions
277
+ update_writer_model
213
278
  exit 0
214
279
  fi
215
280
 
216
281
  if [[ "$model_was_set" != true ]]; then
217
282
  [[ -t 0 ]] || fail 'Pass --model in non-interactive use.'
218
- model_options=()
219
- for model in "${models[@]}"; do model_options[${#model_options[@]}]="$model|$model"; done
220
- if choose_menu 'Choose a writer model:' "${model_options[@]}"; then
221
- writer_model=$MENU_RESULT
222
- else
283
+ if ! choose_writer_model 'Choose a writer model:'; then
223
284
  cancel_install
224
285
  fi
225
286
  fi
@@ -261,7 +322,6 @@ if [[ "$target" == claude ]]; then
261
322
  fi
262
323
 
263
324
  template_path="$SKILL_SOURCE/assets/$target/$agent_file.template"
264
- agent_target="$agent_dir/$agent_file"
265
325
  distributed_files=(SKILL.md scripts/setup.sh assets/codex/saving-token-writer.toml.template assets/claude/saving-token-writer.md.template assets/cursor/saving-token-writer.md.template)
266
326
  for file in "${distributed_files[@]}"; do
267
327
  [[ -f "$SKILL_SOURCE/$file" ]] || fail "Missing required Skill file: $SKILL_SOURCE/$file"