@trazum/cli 1.61.1 → 1.62.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/dist/index.js CHANGED
@@ -142,6 +142,14 @@ function parseArgs(argv, t) {
142
142
  * `flags.has(name)` is the wrong test once negation exists: `--no-batch` stores
143
143
  * the key with the value `false`, and `has` would report it as set.
144
144
  */
145
+ /** A numberFlag that is also a fraction: the config's own 0-to-1 rule. */
146
+ function fractionFlag(args, name, fallback, t) {
147
+ const value = numberFlag(args, name, fallback, t);
148
+ if (value > 1) {
149
+ throw new Error(t.errors.fractionFlag(name, String(args.flags.get(name))));
150
+ }
151
+ return value;
152
+ }
145
153
  function boolFlag(args, name, fallback = false) {
146
154
  const raw = args.flags.get(name);
147
155
  return typeof raw === 'boolean' ? raw : fallback;
@@ -221,7 +229,15 @@ function usageFrom(args, config, t, detected) {
221
229
  model,
222
230
  callsPerMonth: numberFlag(args, 'calls', fromConfig.callsPerMonth ?? DEFAULT_USAGE.callsPerMonth, t),
223
231
  avgOutputTokens: numberFlag(args, 'output-tokens', fromConfig.avgOutputTokens ?? DEFAULT_USAGE.avgOutputTokens, t),
224
- cacheHitRate: numberFlag(args, 'cache-hit-rate', fromConfig.cacheHitRate ?? DEFAULT_USAGE.cacheHitRate, t),
232
+ /*
233
+ Bounded above as well as below, because the config already is.
234
+
235
+ `usage.cacheHitRate: 2` in trazum.config.json is refused as "a fraction
236
+ between 0 and 1"; `--cache-hit-rate 2` on the command line was accepted
237
+ and quietly skewed the caching advisory. Two doors to the same value
238
+ cannot disagree about what fits through.
239
+ */
240
+ cacheHitRate: fractionFlag(args, 'cache-hit-rate', fromConfig.cacheHitRate ?? DEFAULT_USAGE.cacheHitRate, t),
225
241
  batchEligible: boolFlag(args, 'batch', fromConfig.batchEligible ?? false),
226
242
  };
227
243
  }