troxy-cli 1.29.33 → 1.29.35

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "troxy-cli",
3
- "version": "1.29.33",
3
+ "version": "1.29.35",
4
4
  "description": "A secure control layer for AI agents: policies across payments, messages, logins, destructive actions, model usage, and secrets, all enforceable from the CLI",
5
5
  "homepage": "https://troxy.io",
6
6
  "bugs": {
@@ -115,6 +115,24 @@ function troxyCommand(args, paused) {
115
115
  // Whether this session has shown its one "Troxy is active" notice yet.
116
116
  let announced = false;
117
117
 
118
+ // Session savings tracking: cumulative % savings from routing
119
+ let sessionSavingsPercent = 0;
120
+ let routingCount = 0;
121
+
122
+ // Cost ratio of models (relative to Opus=1.0)
123
+ const MODEL_COST = {
124
+ 'claude-haiku-4-5-20251001': 0.3,
125
+ 'claude-sonnet-5-5': 0.6,
126
+ 'claude-opus-5-5': 1.0,
127
+ };
128
+
129
+ function calculateSavings(fromModel, toModel) {
130
+ const fromCost = MODEL_COST[fromModel] || 1.0;
131
+ const toCost = MODEL_COST[toModel] || 1.0;
132
+ if (toCost >= fromCost) return 0; // no savings if routing upward
133
+ return Math.round(((fromCost - toCost) / fromCost) * 100);
134
+ }
135
+
118
136
  // Where the local daemon looks for this session's routing note (see interceptor.js).
119
137
  // Only when installed under ~/.claude/skills, so a --plugin-dir test run never writes
120
138
  // into a real user's folder.
@@ -154,11 +172,16 @@ async function* routeStep($, e, next) {
154
172
  // Main loop only: a subagent keeps whatever model it was given.
155
173
  if (!decision || e.agentId) return yield* next(e);
156
174
  const model = pickModel(decision.score, e.model, decision.tokens);
157
- if (model !== e.model && !announced) {
158
- announced = true;
159
- $.ui.toast('Troxy is active');
160
- }
161
175
  if (model !== e.model) {
176
+ const savings = calculateSavings(e.model, model);
177
+ if (savings > 0) {
178
+ routingCount += 1;
179
+ sessionSavingsPercent = Math.round((sessionSavingsPercent * (routingCount - 1) + savings) / routingCount);
180
+ }
181
+ if (!announced) {
182
+ announced = true;
183
+ $.ui.toast(`Troxy is active · Session: -${sessionSavingsPercent}% saved`);
184
+ }
162
185
  const sid = await $.session.id();
163
186
  const file = modRouteFile($.plugin.root, sid);
164
187
  const key = `${sid}:${e.model}>${model}`;
@@ -181,6 +204,20 @@ export function register(on) {
181
204
  await $.store.set('paused', r.paused);
182
205
  return { text: r.text };
183
206
  });
207
+ // Visual savings bar in terminal output
208
+ on('turn.start', async ($, e, next) => {
209
+ const paused = Boolean(await $.store.get('paused'));
210
+
211
+ if (!paused && routingCount > 0) {
212
+ const barLength = 20;
213
+ const filledLength = Math.round((sessionSavingsPercent / 100) * barLength);
214
+ const emptyLength = barLength - filledLength;
215
+ const bar = '█'.repeat(filledLength) + '░'.repeat(emptyLength);
216
+ console.log(`\n[${bar}] Troxy: -${sessionSavingsPercent}% saved\n`);
217
+ }
218
+
219
+ return next(e);
220
+ });
184
221
  // Routing fails open: a scorer or hook error must never break the session,
185
222
  // it just means the requested model is used as-is.
186
223
  on('prompt.submit', scorePrompt).catch(($, e, next) => { decision = null; return next(e); });