@alexgreensh/token-optimizer 5.13.75 → 5.13.76

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.
Files changed (84) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/hooks/module_runner.py +1 -1
  4. package/hooks/posttooluse_runner.py +7 -9
  5. package/hooks/run.py +5 -1
  6. package/hooks/stop_runner.py +15 -56
  7. package/hooks/userpromptsubmit_runner.py +29 -4
  8. package/package.json +1 -1
  9. package/skills/token-optimizer/assets/dashboard.html +30 -14
  10. package/skills/token-optimizer/assets/savings_story.js +103 -27
  11. package/skills/token-optimizer/references/agent-prompts.md +2 -0
  12. package/skills/token-optimizer/references/implementation-playbook.md +1 -0
  13. package/skills/token-optimizer/scripts/_measure/__init__.py +1 -1
  14. package/skills/token-optimizer/scripts/_measure/apply_safe.py +512 -0
  15. package/skills/token-optimizer/scripts/_measure/audit.py +9 -20
  16. package/skills/token-optimizer/scripts/_measure/autocompact_advice.py +455 -0
  17. package/skills/token-optimizer/scripts/_measure/cache_policy.py +82 -127
  18. package/skills/token-optimizer/scripts/_measure/cli.py +10 -24
  19. package/skills/token-optimizer/scripts/_measure/cold_guard.py +777 -0
  20. package/skills/token-optimizer/scripts/_measure/continuity.py +45 -4
  21. package/skills/token-optimizer/scripts/_measure/counted_closes.py +398 -0
  22. package/skills/token-optimizer/scripts/_measure/counted_headline.py +112 -0
  23. package/skills/token-optimizer/scripts/_measure/dashboard.py +14 -6
  24. package/skills/token-optimizer/scripts/_measure/feature_health.py +6 -0
  25. package/skills/token-optimizer/scripts/_measure/keepwarm_auto.py +452 -0
  26. package/skills/token-optimizer/scripts/_measure/keepwarm_economics.py +8 -4
  27. package/skills/token-optimizer/scripts/_measure/keepwarm_safety.py +548 -24
  28. package/skills/token-optimizer/scripts/_measure/limit_units.py +463 -0
  29. package/skills/token-optimizer/scripts/_measure/local_adapt.py +192 -0
  30. package/skills/token-optimizer/scripts/_measure/mod_action_booking.py +71 -14
  31. package/skills/token-optimizer/scripts/_measure/next_actions.py +420 -0
  32. package/skills/token-optimizer/scripts/_measure/poc_commands.py +44 -0
  33. package/skills/token-optimizer/scripts/_measure/prefix_cost.py +215 -0
  34. package/skills/token-optimizer/scripts/_measure/pt_resume_cues.py +46 -0
  35. package/skills/token-optimizer/scripts/_measure/quality_archive.py +7 -10
  36. package/skills/token-optimizer/scripts/_measure/savings.py +75 -81
  37. package/skills/token-optimizer/scripts/_measure/savings_headline.py +17 -21
  38. package/skills/token-optimizer/scripts/_measure/savings_story.py +8 -1
  39. package/skills/token-optimizer/scripts/_measure/session_store_spool.py +119 -78
  40. package/skills/token-optimizer/scripts/_measure/status_bar_refresh.py +38 -3
  41. package/skills/token-optimizer/scripts/_measure/structural_ledger.py +1 -1
  42. package/skills/token-optimizer/scripts/_measure/subscription_audits.py +725 -0
  43. package/skills/token-optimizer/scripts/_measure/transcript_backfill.py +1 -1
  44. package/skills/token-optimizer/scripts/_measure/transcript_stream.py +8 -2
  45. package/skills/token-optimizer/scripts/antigravity_install.py +3 -0
  46. package/skills/token-optimizer/scripts/archive_result.py +16 -28
  47. package/skills/token-optimizer/scripts/archive_verify.py +1 -1
  48. package/skills/token-optimizer/scripts/bash_compress.py +156 -176
  49. package/skills/token-optimizer/scripts/bash_compress_hook.py +218 -174
  50. package/skills/token-optimizer/scripts/bash_search_results.py +189 -9
  51. package/skills/token-optimizer/scripts/bash_whitelist.py +6 -1
  52. package/skills/token-optimizer/scripts/benchmark.py +11 -13
  53. package/skills/token-optimizer/scripts/big_noncode_read.py +998 -0
  54. package/skills/token-optimizer/scripts/build_output_compress.py +103 -8
  55. package/skills/token-optimizer/scripts/builtin_tool_compress.py +716 -0
  56. package/skills/token-optimizer/scripts/cloud_kit.py +1 -1
  57. package/skills/token-optimizer/scripts/codex_doctor.py +1 -1
  58. package/skills/token-optimizer/scripts/command_compress_extra.py +955 -0
  59. package/skills/token-optimizer/scripts/compact_markers.py +129 -0
  60. package/skills/token-optimizer/scripts/copilot_install.py +3 -0
  61. package/skills/token-optimizer/scripts/cursor_install.py +7 -0
  62. package/skills/token-optimizer/scripts/devin_source.py +5 -5
  63. package/skills/token-optimizer/scripts/emit_safety_gate.py +518 -0
  64. package/skills/token-optimizer/scripts/fixtures/b2_more_commands.json +142 -0
  65. package/skills/token-optimizer/scripts/fixtures/b5_more_savings.json +26 -0
  66. package/skills/token-optimizer/scripts/fixtures/builtin_tools.json +103 -0
  67. package/skills/token-optimizer/scripts/fixtures/c7_review_ratchet.json +52 -0
  68. package/skills/token-optimizer/scripts/fixtures/large_output_policy.json +55 -0
  69. package/skills/token-optimizer/scripts/go_cargo_test_compress.py +493 -0
  70. package/skills/token-optimizer/scripts/grok_install.py +3 -0
  71. package/skills/token-optimizer/scripts/hermes_doctor.py +4 -1
  72. package/skills/token-optimizer/scripts/hermes_install.py +10 -1
  73. package/skills/token-optimizer/scripts/hook_fastpath.py +94 -0
  74. package/skills/token-optimizer/scripts/hook_runtime.py +6 -2
  75. package/skills/token-optimizer/scripts/large_output_policy.py +431 -0
  76. package/skills/token-optimizer/scripts/measure.py +10 -12
  77. package/skills/token-optimizer/scripts/pipe_file_compress.py +900 -0
  78. package/skills/token-optimizer/scripts/pipeline_analyzer.py +15 -1
  79. package/skills/token-optimizer/scripts/post_run_classify.py +2 -2
  80. package/skills/token-optimizer/scripts/preserved_reinject.py +20 -3
  81. package/skills/token-optimizer/scripts/process_identity.py +66 -0
  82. package/skills/token-optimizer/scripts/read_cache.py +51 -60
  83. package/skills/token-optimizer/scripts/statusline.js +21 -3
  84. package/skills/token-optimizer/scripts/visibility_rule.py +536 -0
@@ -1,7 +1,7 @@
1
1
  // Savings story (U9): the Savings tab, top to bottom. Savings are big and
2
2
  // confident; the measured / estimated breakdown lives only in the folds.
3
- // 1. Hero band: three huge numbers (30-day total with routing included,
4
- // saved since install with routing included, tokens kept out of context).
3
+ // 1. Hero band: the stored since-install total and its correction, with
4
+ // the moving period and potential savings alongside it.
5
5
  // 2. Transformation (when the payload says ok) and "Your limits go further".
6
6
  // 3. Still on the table: computable opportunities per period, warm accent,
7
7
  // each with one action. Never part of a savings total.
@@ -91,8 +91,9 @@ function savingsStoryBands(data) {
91
91
  { key: 'output_reread', label: 'Shorter answers, not re-read', usd: outputInEst, tok: orr.tokens_saved,
92
92
  on: outputInEst > 0,
93
93
  why: orr.control_net == null && orr.available ? 'Not yet compared against sessions without the nudge.' : '' },
94
- { key: 'other', label: 'Other estimates', usd: num(as.estimated_usd) - outputInEst - trimInEst, tok: reloadTok,
95
- on: Math.abs(num(as.estimated_usd) - outputInEst - trimInEst) > 0,
94
+ { key: 'autocompact_window_estimated', label: 'Earlier auto-compact', usd: num(est.autocompact_window_estimated), tok: num((s.autocompact_window_estimated || {}).tokens_saved), on: num(est.autocompact_window_estimated) !== 0 },
95
+ { key: 'other', label: 'Other estimates', usd: num(as.estimated_usd) - outputInEst - trimInEst - num(est.autocompact_window_estimated), tok: reloadTok,
96
+ on: Math.abs(num(as.estimated_usd) - outputInEst - trimInEst - num(est.autocompact_window_estimated)) > 0,
96
97
  why: 'Loops stopped, sub-agent output, handovers and restores.' }
97
98
  ];
98
99
  function live(rows) {
@@ -128,8 +129,7 @@ function savingsStoryHtml(data, extras) {
128
129
  var days = Number(s.period_days) || 30;
129
130
  var out = '';
130
131
 
131
- // ---- 1. Hero: three huge numbers. The breakdown lives only in the folds. ----
132
- // Measured and estimated savings, plus the routing estimate, are one number.
132
+ // ---- 1. Hero: the stored lifetime amount leads. The split stays in the fold. ----
133
133
  // Setup cleanup recorded by the trim ledger sits inside logged_usd (the
134
134
  // structural pool always has), so it is its own row, taken out of
135
135
  // "Context removed" once.
@@ -139,8 +139,9 @@ function savingsStoryHtml(data, extras) {
139
139
  var routing30 = has(mr.realized_cost_usd) ? num(mr.realized_cost_usd) : num(as.routing_usd);
140
140
  if (!(routing30 > 0)) routing30 = 0;
141
141
  var bigTotal = totalUsd + routing30;
142
+ var overall = s.overall_headline;
142
143
  function sum(rows, k) { return rows.reduce(function(a, r) { return a + num(r[k]); }, 0); }
143
- if (measured.length || estimated.length) {
144
+ if (overall || measured.length || estimated.length) {
144
145
  function cents(rows) { return rows.reduce(function(n, r) { return n + Math.round(num(r.usd) * 100); }, 0); }
145
146
  function table(title, rows) {
146
147
  if (!rows.length) return '';
@@ -153,10 +154,35 @@ function savingsStoryHtml(data, extras) {
153
154
  var carry = s.lean_resume_carry || {};
154
155
  var incomplete = cp.pricing_complete === false || as.reread_pricing_complete === false;
155
156
  var archive = (s.by_category || {}).tool_archive;
157
+ var builtinGrep = (s.by_category || {}).builtin_grep;
158
+ var builtinGlob = (s.by_category || {}).builtin_glob;
159
+ var bigRead = (s.by_category || {}).big_read_preview;
160
+ var bigReadLabel = ((s.category_labels || {}).big_read_preview) || 'Big non-code read previews';
156
161
  var bashExpand = (s.by_category || {}).bash_archive_reexpand;
157
162
  var bashNet = Object.keys(s.by_category || {}).reduce(function(n, k) {
158
- return n + ((/^bash_/.test(k) || k === 'build_output_compress' || k === 'crossturn_dedup') ? num((s.by_category[k] || {}).cost_saved_usd) : 0);
163
+ return n + ((/^bash_/.test(k) || /^cmd_/.test(k) || k === 'build_output_compress' || k === 'crossturn_dedup' || k === 'pipe_compress' || k === 'large_output_policy') ? num((s.by_category[k] || {}).cost_saved_usd) : 0);
159
164
  }, 0);
165
+ var catFallback = {
166
+ crossturn_dedup: 'Cross-turn dedup',
167
+ bash_search_noise_fold: 'Bash search noise folding',
168
+ tool_archive: 'Tool replacements',
169
+ bash_compress_pipeline: 'Bash compress (pipelines)',
170
+ bash_compress_search: 'Bash compress (search results)',
171
+ build_output_compress: 'Build output compression',
172
+ large_output_policy: 'Large Bash output policy'
173
+ };
174
+ var catRows = Object.keys(s.by_category || {}).filter(function(k) {
175
+ var v = s.by_category[k];
176
+ return v && (num(v.tokens_saved) > 0 || num(v.events) > 0) && k !== 'structural_savings';
177
+ }).sort(function(a, b) {
178
+ return num((s.by_category[b] || {}).tokens_saved) - num((s.by_category[a] || {}).tokens_saved);
179
+ }).map(function(k) {
180
+ var v = s.by_category[k] || {};
181
+ var lbl = v.label || catFallback[k] || k;
182
+ return '<li>' + esc(lbl) + ': ' + tok(v.tokens_saved) + ' tokens (' + count(v.events) + ' events' +
183
+ (num(v.cost_saved_usd) > 0 ? ', ' + savingsCents(v.cost_saved_usd) : '') + ')</li>';
184
+ }).join('');
185
+ var catBreakdown = catRows ? '<p><strong>Measured breakdown by feature</strong></p><ul>' + catRows + '</ul>' : '';
160
186
  var basis = savingsRoutingBasis(data);
161
187
  var routingRow = routing30 > 0 ? '<p><strong>Estimated, model routing, ' + savingsCents(routing30) + '</strong></p><ul><li>Model routing: ' + savingsCents(routing30) + '. ' +
162
188
  esc(basis.lead) + ' Your current work priced at that mix, against what it actually cost.</li></ul>' : '';
@@ -188,14 +214,19 @@ function savingsStoryHtml(data, extras) {
188
214
  var method = (mr.routing_enabled === false ? '<p>Routing off</p>' : '') + '<p><strong>Last ' + days + ' days, ' + savingsCents(allCents / 100) + '</strong>: measured ' + savingsCents(cents(measured) / 100) +
189
215
  ', estimated ' + savingsCents(cents(estimated) / 100) + (routing30 > 0 ? ', routing ' + savingsCents(routing30) : '') + '.</p>' +
190
216
  table('Measured, counted event by event', measured) +
217
+ catBreakdown +
191
218
  table('Estimated, sized by a documented method', estimated) +
192
219
  routingRow +
193
220
  setupDetail +
194
221
  (num((s.progressive_disclosure || {}).full_bash_fetches) > 0 ? '<p>Full command output fetched from the archive: ' + count(s.progressive_disclosure.full_bash_fetches) + ' outputs, about ' + tok(s.progressive_disclosure.full_bash_tokens) + ' tokens. This does not establish whether a command would otherwise have been re-run.</p>' : '') +
195
222
  (num((s.keepwarm_estimated || {}).manual_pings) ? '<p>Manual warm-ups from the Claude Code mod: ' + count(s.keepwarm_estimated.manual_pings) + '. Their cost is included in the estimated keep-warm net.</p>' : '') +
223
+ (num((s.cold_guard_estimated || {}).events) ? '<p>Cold-session guard: ' + savingsCents(s.cold_guard_estimated.cost_saved_usd) + ' (estimated, net of handover writes).</p>' : '') +
196
224
  (num((s.mod_compaction_actions || {}).events) + num(((s.by_category || {}).mod_clean || {}).events) + num(((s.by_category || {}).mod_clean_first || {}).events) ? '<p>Clean-up from the Claude Code mod: ' + count(num((s.mod_compaction_actions || {}).events) || (num(((s.by_category || {}).mod_clean || {}).events) + num(((s.by_category || {}).mod_clean_first || {}).events))) + ' actions. Compaction cost is deducted; later reads are counted through the next compaction, with one observed cache rebuild for clean-up first' + (num((s.mod_compaction_actions || {}).unpriced_events) ? '; ' + count(s.mod_compaction_actions.unpriced_events) + ' actions are not yet priced' : '') + '.</p>' : '') +
197
225
  (num((s.mod_fresh_estimated || {}).events) ? '<p>Start fresh from the Claude Code mod: ' + count(s.mod_fresh_estimated.events) + ' actions. Estimated continuation value (old context less a rough handoff estimate; persistent setup may remain; median of comparable earlier sessions, capped at 10 turns): ' + (num(s.mod_fresh_estimated.unpriced_events) === num(s.mod_fresh_estimated.events) ? 'not yet available' : usd(s.mod_fresh_estimated.cost_saved_usd || 0)) + (num((as.estimates_usd || {}).mod_fresh_estimated) === 0 && num(s.mod_fresh_estimated.cost_saved_usd) > 0 ? ', shown separately to avoid overlap with handovers' : '') + (num(s.mod_fresh_estimated.unpriced_events) ? '; some actions need more history' : '') + '.</p>' : '') +
198
226
  (archive ? '<p>Tool archive, net of re-expands: ' + usd(archive.cost_saved_usd) + ' once, before repeat-reads.</p>' : '') +
227
+ (builtinGrep && num(builtinGrep.tokens_saved) > 0 ? '<p>' + esc(builtinGrep.label || 'Built-in Grep compression') + ': ' + tok(builtinGrep.tokens_saved) + ' tokens (' + usd(builtinGrep.cost_saved_usd) + ') across ' + count(builtinGrep.events) + ' calls, before repeat-reads.</p>' : '') +
228
+ (builtinGlob && num(builtinGlob.tokens_saved) > 0 ? '<p>' + esc(builtinGlob.label || 'Built-in Glob compression') + ': ' + tok(builtinGlob.tokens_saved) + ' tokens (' + usd(builtinGlob.cost_saved_usd) + ') across ' + count(builtinGlob.events) + ' calls, before repeat-reads.</p>' : '') +
229
+ (bigRead && num(bigRead.events) > 0 ? '<p>' + esc(bigReadLabel) + ': ' + count(bigRead.events) + ' preview' + (num(bigRead.events) === 1 ? '' : 's') + ', ' + tok(bigRead.tokens_saved) + ' tokens (' + usd(bigRead.cost_saved_usd) + ' once, before repeat-reads).</p>' : '') +
199
230
  (bashExpand ? '<p>Bash compression, net of re-expands: ' + usd(bashNet) + ' once, before repeat-reads.</p>' : '') +
200
231
  (num((as.estimates_usd || {}).expand_overhead) ? '<p>Estimated expand-command overhead: ' + usd(as.estimates_usd.expand_overhead) + '.</p>' : '') +
201
232
  (num((as.estimates_usd || {}).handover_rerun) > 0 ? '<p>Continuity handovers, ' + usd(as.estimates_usd.handover_rerun) + ' (estimated): sessions resumed from a saved checkpoint re-read fewer stale files than sessions that started cold, and that gap is counted here.</p>' : '') +
@@ -244,24 +275,27 @@ function savingsStoryHtml(data, extras) {
244
275
  if (SIh && SIh.measured > 0) tipSinceLines.push({ html: 'Measured: ' + usd(SIh.measured) });
245
276
  if (SIh && SIh.estimated > 0) tipSinceLines.push({ html: 'Estimated: ' + usd(SIh.estimated) });
246
277
  if (SIh && SIh.routing > 0) tipSinceLines.push({ html: 'Model routing (estimate): ' + usd(SIh.routing) });
278
+ var lifetimeLabel = '<span class="st-mega__unit">saved since you installed';
279
+ var hasDailyClose = Object.prototype.hasOwnProperty.call(s, 'overall_headline');
280
+ var oldSince = !hasDailyClose && SIh && SIh.all > 0
281
+ ? '<div class="st-mega__item"><button type="button" class="st-mega st-mega--usd st-tip" aria-describedby="st-tip-since">' + usd(SIh.all) + '</button>' +
282
+ tipCard('st-tip-since', 'Since ' + esc(SIh.date || 'install'), tipSinceLines) +
283
+ lifetimeLabel + soFar(soFarAll) + '</span></div>' : '';
284
+ var rolling = hasDailyClose
285
+ ? '<div class="st-mega__item"><strong>' + usd(bigTotal) + '</strong><span class="st-mega__unit">Last ' + days + ' days (moves as days roll off)</span></div>'
286
+ : '<div class="st-mega__item"><button type="button" class="st-mega st-mega--usd st-tip" aria-describedby="st-tip-total">' + usd(bigTotal) + '</button>' +
287
+ tipCard('st-tip-total', 'What makes up ' + usd(bigTotal), tipTotalLines) +
288
+ '<span class="st-mega__unit">saved in the last ' + days + ' days' + soFar(soFar30) + '</span></div>';
247
289
  out += '<div class="card st-hero">' +
248
290
  '<h2 class="st-h">What Token Optimizer saved</h2>' +
249
291
  '<div class="st-mega__row st-mega__row--hero">' +
250
- (has(mr.routing_enabled) ? (SIh && SIh.all > 0 ? '<div class="st-mega__item"><button type="button" class="st-mega st-mega--usd st-tip" aria-describedby="st-tip-since">' + usd(SIh.all) + '</button>' +
251
- tipCard('st-tip-since', 'Since ' + esc(SIh.date || 'install'), tipSinceLines) +
252
- '<span class="st-mega__unit">saved since you installed' + soFar(soFarAll) + '</span></div>' : '') + '<div class="st-mega__item"><button type="button" class="st-mega st-mega--usd st-tip" aria-describedby="st-tip-total">' + usd(bigTotal) + '</button>' +
253
- tipCard('st-tip-total', 'What makes up ' + usd(bigTotal), tipTotalLines) +
254
- '<span class="st-mega__unit">saved in the last ' + days + ' days' + soFar(soFar30) + '</span></div>' : '<div class="st-mega__item"><button type="button" class="st-mega st-mega--usd st-tip" aria-describedby="st-tip-total">' + usd(bigTotal) + '</button>' +
255
- tipCard('st-tip-total', 'What makes up ' + usd(bigTotal), tipTotalLines) +
256
- '<span class="st-mega__unit">saved in the last ' + days + ' days' + soFar(soFar30) + '</span></div>' + (SIh && SIh.all > 0 ? '<div class="st-mega__item"><button type="button" class="st-mega st-mega--usd st-tip" aria-describedby="st-tip-since">' + usd(SIh.all) + '</button>' +
257
- tipCard('st-tip-since', 'Since ' + esc(SIh.date || 'install'), tipSinceLines) +
258
- '<span class="st-mega__unit">saved since you installed' + soFar(soFarAll) + '</span></div>' : '')) +
292
+ (overall ? savingsOverallAmount(overall) + rolling : (has(mr.routing_enabled) ? oldSince + rolling : rolling + oldSince)) +
259
293
  (totalTok > 0 ? '<div class="st-mega__item"><button type="button" class="st-mega st-mega--tok st-tip" aria-describedby="st-tip-tokens">' + tok(totalTok) + '</button>' +
260
294
  tipCard('st-tip-tokens', tok(totalTok) + ' tokens kept out of context', tipTokLines) +
261
295
  '<span class="st-mega__unit">tokens kept out of context in ' + days + ' days' + soFar(cp.remeasuring === true) + '</span></div>' : '') +
262
296
  '</div>' +
263
297
  (soFar30 || soFarAll ? '<p class="st-lead st-progress">Updating your history after an upgrade' + (left > 0 ? ' (' + count(left) + ' session' + (left === 1 ? '' : 's') + ' left)' : '') + '. These totals are in progress and will change when it finishes.</p>' : '') +
264
- f.fold('How this is calculated', method + (SIh && SIh.all > 0 ? savingsSinceInstallBody(data, SIh) : '')) +
298
+ f.fold('How this is calculated', method + (SIh && SIh.all > 0 ? savingsSinceInstallBody(data, SIh) : '') + savingsCountedSplit(s)) +
265
299
  '</div>';
266
300
  }
267
301
 
@@ -290,6 +324,40 @@ function savingsStoryHtml(data, extras) {
290
324
  return out ? '<section class="st" aria-label="What Token Optimizer saved">' + out + '</section>' : '';
291
325
  }
292
326
 
327
+ function savingsOverallAmount(overall) {
328
+ var f = savingsStoryFmt();
329
+ var change = overall.last_correction;
330
+ var note = change ? String(change.reason).replace(/\.$/, '') + ' (' +
331
+ f.day(change.date) + ', ' + (change.delta_usd > 0 ? '+' : '') + savingsCents(change.delta_usd) + ').' : '';
332
+ return '<div class="st-mega__item"><span class="st-mega st-mega--usd">' +
333
+ f.usd(overall.usd) + '</span><span class="st-mega__unit">saved since you installed</span>' +
334
+ (note ? '<p class="st-sub">' + esc(note) + '</p>' : '') +
335
+ (overall.rechecking ? '<p class="st-sub">Rechecking an earlier savings figure.</p>' : '') + '</div>';
336
+ }
337
+
338
+ function savingsCountedSplit(savings) {
339
+ var counted = savings.counted_headline;
340
+ if (!counted || !counted.since) return '';
341
+ var date = new Date(counted.since + 'T00:00:00').toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
342
+ return '<p>Counted since ' + esc(date) + ' ' + savingsCents(counted.usd) + ' in context removals and repeat reads.' +
343
+ (counted.last_correction ? ' ' + esc(counted.last_correction.reason) : '') + '</p>';
344
+ }
345
+
346
+ function savingsOverallFallback(data) {
347
+ var s = data.savings || {}, overall = s.overall_headline, f = savingsStoryFmt();
348
+ if (!overall) return '';
349
+ var si = savingsSinceInstall(data), action = s.action_savings || {};
350
+ return '<div class="card st-hero">' + savingsOverallAmount(overall) +
351
+ '<p>Last ' + (Number(s.period_days) || 30) + ' days (moves as days roll off) <strong>' +
352
+ f.usd(f.num(action.total_usd) + Math.max(0, f.num(action.routing_usd))) + '</strong></p>' +
353
+ f.fold('How this is calculated', (si ? savingsSinceInstallBody(data, si) : '') + savingsCountedSplit(s)) + '</div>';
354
+ }
355
+
356
+ function savingsLimitsLifetime(data) {
357
+ var headline = ((data.savings || {}).overall_headline || {}).display;
358
+ return headline ? '<p class="st-sub">' + esc(headline.long) + '</p>' : '';
359
+ }
360
+
293
361
  // "Apr to Jul" (years added when they differ or are needed), or ''.
294
362
  function savingsMonthRange(period, joiner) {
295
363
  period = period || {};
@@ -316,9 +384,12 @@ function savingsSinceInstallBody(data, SI) {
316
384
  var basis = savingsRoutingBasis(data);
317
385
  var period = savingsMonthRange(ai.routing_majority_period, ' to ');
318
386
  var since = SI.date ? esc_(SI.date) : 'install';
319
- var split = '<p><strong>Since ' + since + ', ' + savingsCents(SI.all) + '</strong></p><ul>' +
387
+ var overall = s.overall_headline;
388
+ var updated = overall && Math.abs(overall.usd - SI.all) >= 0.005;
389
+ var split = '<p><strong>' + (updated ? 'Latest breakdown since ' : 'Since ') + since +
390
+ (updated ? '' : ', ' + savingsCents(SI.all)) + '</strong></p><ul>' +
320
391
  (SI.measured > 0 ? '<li>Measured: ' + savingsCents(SI.measured) + '. Context removed, cheaper cache writes and re-reads avoided, counted event by event.</li>' : '') +
321
- (SI.estimated > 0 ? '<li>Estimated: ' + savingsCents(SI.estimated) + '. Setup cleanup from archives, handovers and other documented estimates.</li>' : '') +
392
+ (SI.estimated > 0 ? (overall ? '<li>Estimated (can move) ' : '<li>Estimated: ') + savingsCents(SI.estimated) + '. Setup cleanup from archives, handovers and other documented estimates.</li>' : '') +
322
393
  (SI.routing > 0 ? '<li>Model routing, estimated: ' + savingsCents(SI.routing) + '. ' + esc_(basis.lead) + (period ? ' Most of it from ' + esc_(period) + '.' : '') + '</li>' : '') +
323
394
  (mr.routing_enabled === false ? '<li>Routing off</li>' : '') + '</ul>';
324
395
  var alt = SI.routing > 0 && basis.kind === 'stated' && has(ai.routing_measured_baseline_opus_share) && has(ai.routing_measured_baseline_realized_cost_usd)
@@ -465,11 +536,13 @@ function savingsLimitWindows(rw, ratio, versus) {
465
536
  function savingsLimitsHtml(data) {
466
537
  var f = savingsStoryFmt(), num = f.num;
467
538
  var rw = (data && data.runway) || null;
468
- if (!rw || typeof rw !== 'object') return '';
539
+ var warm = typeof keepwarmNetHtml === 'function' ? keepwarmNetHtml(data) : '';
540
+ var warmCard = warm ? '<div class="card st-card"><h2 class="st-h">Keep-warm and your limits</h2>' + warm + '</div>' : '';
541
+ if (!rw || typeof rw !== 'object') return warmCard;
469
542
  var ba = ((data && data.savings) || {}).before_after || {};
470
543
  var actual = num(ba.actual_monthly_usd), before = num(ba.counterfactual_monthly_usd);
471
544
  var ratio = ba.transformation_state === 'ok' && actual > 0 && before > actual ? before / actual : 0;
472
- if (!(ratio > 1)) return '';
545
+ if (!(ratio > 1)) return warmCard;
473
546
  var pctGain = Math.round((ratio - 1) * 100);
474
547
  // Weekly window first; the 5-hour window is the fallback when no weekly
475
548
  // reading exists. Live meter readings beat the last stored one.
@@ -522,8 +595,8 @@ function savingsLimitsHtml(data) {
522
595
  '<p class="st-lead">more work fits in your weekly limit</p>' +
523
596
  '</div>' +
524
597
  '<div class="st-limits__body">' +
525
- bars +
526
- '<p class="st-sub">' + esc(basis) + '</p>' +
598
+ bars + warm +
599
+ '<p class="st-sub">' + esc(basis) + '</p>' + savingsLimitsLifetime(data) +
527
600
  (win && !live.length ? '<p class="st-sub">Last reading from your meter history.</p>' : '') +
528
601
  f.fold('How this is calculated', method) +
529
602
  '</div></div>';
@@ -566,7 +639,7 @@ function savingsOnTableHtml(data, extras) {
566
639
  }
567
640
  var changeWord = rows.length === 1 ? 'this change' : (rows.length === 2 ? 'these two changes' : 'these ' + rows.length + ' changes');
568
641
  return '<div class="card st-table">' +
569
- '<h2 class="st-h">Still on the table</h2>' +
642
+ '<h2 class="st-h">' + (s.overall_headline ? 'Could save (not saved yet)' : 'Still on the table') + '</h2>' +
570
643
  '<div class="st-table__body"><p class="st-mega__item st-mega__item--card">' +
571
644
  '<span class="st-mega st-mega--route st-mega--card">' + usd(total) + '</span><span class="st-mega__unit">more every ' + days + ' days if you make ' + changeWord + '</span></p>' +
572
645
  '<div class="st-table__rows"><ul class="st-rows st-rows--card">' + rows.map(function(r) {
@@ -637,7 +710,9 @@ function savingsSinceInstall(data) {
637
710
  if (!parts.length) return null;
638
711
  var date = si.install_date ? new Date(si.install_date + 'T00:00:00').toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }) : '';
639
712
  var base = parts.reduce(function(a, p) { return a + num(p[1]); }, 0);
640
- var routing = has(ai.routing_usd) ? num(ai.routing_usd) : num(c.routing_estimated) + num(c.routing_measured);
713
+ var routing = (has(c.routing_estimated) || has(c.routing_measured))
714
+ ? num(c.routing_estimated) + num(c.routing_measured)
715
+ : (has(ai.routing_usd) ? num(ai.routing_usd) : 0);
641
716
  if (!(routing > 0)) routing = 0;
642
717
  var all = has(ai.total_usd) ? num(ai.total_usd) : base + routing;
643
718
  var estimated = num(ai.estimated_usd);
@@ -733,7 +808,8 @@ function savingsLedgerHtml(data) {
733
808
  out += '<h3 class="ts-section-label st-gap">Since you installed' + (SI.date ? ' on ' + esc(SI.date) : '') + ' (' + f.count(SI.days) + ' days)</h3><ul class="st-rows">' +
734
809
  SI.parts.map(function(p) { return row(p[0], p[1], 0); }).join('') +
735
810
  (SI.routing ? row(savingsRoutingBasis(data).ledger, SI.routing, 0) : '') +
736
- '<li><span><strong>Total</strong></span><span class="st-v"><strong>' + cents(SI.all) + '</strong></span></li></ul>';
811
+ (s.overall_headline && Math.abs(s.overall_headline.usd - SI.all) >= 0.005 ? '' :
812
+ '<li><span><strong>Total</strong></span><span class="st-v"><strong>' + cents(SI.all) + '</strong></span></li>') + '</ul>';
737
813
  }
738
814
  var cp = s.counted_period || {};
739
815
  if (cp.pricing_note) out += '<p>' + esc(cp.pricing_note) + '</p>';
@@ -402,6 +402,7 @@ Output file: {COORD_PATH}/audit/advanced.md
402
402
  9. **settings.json env block audit**:
403
403
  - Read ~/.claude/settings.json and check env block for token-relevant vars:
404
404
  - CLAUDE_AUTOCOMPACT_PCT_OVERRIDE (report value; documented — % of the compact window used when compaction fires, lower compacts earlier)
405
+ - autoCompactWindow (recommended from your own sessions, applied only with your approval)
405
406
  - CLAUDE_CODE_MAX_THINKING_TOKENS (report value)
406
407
  - CLAUDE_CODE_MAX_OUTPUT_TOKENS (report value)
407
408
  - MAX_MCP_OUTPUT_TOKENS (report value)
@@ -513,6 +514,7 @@ Output file: {COORD_PATH}/audit/advanced.md
513
514
  | Variable | Value | Default | Note |
514
515
  |----------|-------|---------|------|
515
516
  | CLAUDE_AUTOCOMPACT_PCT_OVERRIDE | [value or not set] | not set | Documented; reported if set, never removed |
517
+ | autoCompactWindow | [value or not set] | automatic | Recommended from your own sessions, applied only with your approval |
516
518
  | CLAUDE_CODE_MAX_THINKING_TOKENS | [value or not set] | 10,000 | |
517
519
  | CLAUDE_CODE_MAX_OUTPUT_TOKENS | [value or not set] | 16,384 | |
518
520
  | MAX_MCP_OUTPUT_TOKENS | [value or not set] | 25,000 | |
@@ -247,6 +247,7 @@ Audit settings.json env block and help user tune token-relevant variables.
247
247
  | Variable | Current | Default | Recommendation |
248
248
  |---------------------------------|---------|---------|----------------|
249
249
  | CLAUDE_AUTOCOMPACT_PCT_OVERRIDE | user choice | unset | Percent of the compact window used when compaction fires; lower compacts earlier. Reported, never changed |
250
+ | autoCompactWindow | user choice | automatic | Recommended from your own sessions, applied only with your approval |
250
251
  | MAX_THINKING_TOKENS | not set | unset (adaptive models pick their own depth) | Default is fine |
251
252
  | ENABLE_TOOL_SEARCH | unset | unset (MCP tools deferred) | Good (active) |
252
253
  ```
@@ -13,7 +13,7 @@ DEFERRED_MODULES = ('audit', 'dashboard', 'sessions', 'savings', 'cli')
13
13
  RUNTIME_SOURCES = ('__init__.py', '_compat.py') + tuple(name + '.py' for name in DOMAIN_MODULES) + ('dashboard_history.py', 'weekly_activity.py', 'headline.py', 'counted_position.py', 'counted_pricing_v5.py', 'transcript_backfill.py', 'counted_subagents.py', 'lean_resume_threshold.py', 'output_reread.py', 'session_effect.py', 'structural_ledger.py', 'structural_archives.py', 'structural_listing.py', 'structural_report.py', 'structural_seed.py', 'structural_value.py', 'rework_metrics.py', 'session_best.py', 'savings_story.py', 'savings_headline.py', 'counted_orphans.py', 'counted_cap.py', 'archive_void_evidence.py', 'cost_per_message_trend.py', 'lean_resume_receivers.py', 'routing_period.py', 'fixture_context.py', 'transcript_product.py', 'periphery_exposure.py', 'structure_funnel.py', 'setup_attachment_counter.py', 'first_read_outcomes.py', 'setup_budget_monitor.py', 'setup_connector_ledger.py', 'first_call_context.py', 'timestamp_cache.py', 'token_type_split.py', 'evidence_parallel.py', 'ttl_period.py', 'first_read_revive.py', 'mcp_archive_tripwire.py', 'compaction_survival.py', 'archive_void_codex.py', 'compression_fixture_void.py', 'feature_health.py', 'archive_health.py', 'coverage_report.py', 'file_refetch.py', 'holdout_report.py', 'structural_dedupe.py', 'setup_step.py', 'baseline_provenance.py', 'own_price_card.py', 'transcript_stream.py', 'checkpoint_direction.py', 'checkpoint_retention.py')
14
14
  RUNTIME_SOURCES += ('keepwarm_safety.py', 'keepwarm_economics.py', 'keepwarm_linux.py', 'mod_action_booking.py', 'mod_action_diagnostics.py', 'mod_action_selftest.py', 'install_baseline.py', 'routing_credit.py', 'mod_compaction_booking.py', 'mod_fresh_booking.py', 'quality_continuity.py', 'quality_checkpoint.py', 'codex_quality.py', 'lease_candidate_cleanup.py', 'session_store_spool.py', 'upgrade_drain_control.py', 'compression_scan_checkpoint.py', 'status_bar_lock.py', 'session_flush_lock.py', 'context_reset_marker.py', 'holdout_fallback.py', 'dashboard_heal_claim.py', 'config_cache.py', 'setup_observation_cache.py', 'status_bar_refresh.py', 'routing_default.py', 'pilot_report.py',)
15
15
  RUNTIME_SOURCES += ('nudge_followthrough.py', 'runway_all_in.py',)
16
- RUNTIME_SOURCES += ('session_activity.py', 'routing_savings.py',)
16
+ RUNTIME_SOURCES += ('session_activity.py', 'routing_savings.py', 'pt_resume_cues.py', 'subscription_audits.py', 'limit_units.py', 'local_adapt.py', 'prefix_cost.py', 'poc_commands.py', 'counted_closes.py', 'counted_headline.py', 'apply_safe.py', 'autocompact_advice.py', 'cold_guard.py', 'keepwarm_auto.py', 'next_actions.py',)
17
17
  # Set True by hooks/userpromptsubmit_runner.py right before `import measure`,
18
18
  # which consumes it. That process never patches or enumerates the facade.
19
19
  HOOK_IMPORT = False