burnoff 1.4.1 → 2.1.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.
Files changed (62) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.github/workflows/burnoff-pr-gate.yml +5 -3
  3. package/.github/workflows/burnoff-startup-lint.yml +2 -2
  4. package/CHANGELOG.md +74 -0
  5. package/README.md +187 -213
  6. package/SECURITY.md +38 -0
  7. package/bin/burnoff.mjs +307 -32
  8. package/commands/burnoff.md +6 -4
  9. package/docs/CLAUDE_CODE_PLUGIN.md +29 -28
  10. package/docs/DESIGN_PARTNER_INTAKE.md +3 -3
  11. package/hooks/hook-io.mjs +216 -11
  12. package/hooks/hooks.json +44 -0
  13. package/hooks/post-tool-use.mjs +3 -1
  14. package/hooks/pre-tool-use.mjs +47 -8
  15. package/hooks/session-lifecycle.mjs +24 -3
  16. package/hooks/user-prompt-submit.mjs +98 -0
  17. package/package.json +6 -4
  18. package/scripts/bench-hooks.mjs +34 -3
  19. package/scripts/bench-savings.mjs +318 -0
  20. package/scripts/burnoff-statusline.mjs +138 -6
  21. package/src/ci/ci-gate.mjs +199 -13
  22. package/src/ci/pr-cost.mjs +417 -45
  23. package/src/ci/pr-summary.mjs +467 -0
  24. package/src/cli/audit.mjs +179 -28
  25. package/src/cli/doctor.mjs +32 -6
  26. package/src/cli/hook-health.mjs +9 -1
  27. package/src/cli/init.mjs +226 -39
  28. package/src/cli/preview.mjs +299 -0
  29. package/src/cli/startup-audit/formatter.mjs +248 -0
  30. package/src/cli/startup-audit/jsonc.mjs +601 -0
  31. package/src/cli/startup-audit/mcp-audit.mjs +735 -0
  32. package/src/cli/startup-audit/rules-hygiene.mjs +645 -0
  33. package/src/cli/startup-audit/telemetry-scan.mjs +975 -0
  34. package/src/cli/startup-audit.mjs +451 -2471
  35. package/src/clients/claude-code.mjs +41 -4
  36. package/src/config/catalog.json +295 -0
  37. package/src/config/effort.mjs +145 -0
  38. package/src/config/harness-quirks.mjs +340 -0
  39. package/src/config/loader.mjs +27 -2
  40. package/src/config/policy.mjs +81 -9
  41. package/src/config/pricing.mjs +247 -19
  42. package/src/config/semver.mjs +25 -0
  43. package/src/config/uncached-attribution.mjs +280 -41
  44. package/src/guards/compaction-baton.mjs +248 -0
  45. package/src/guards/loop-breaker.mjs +328 -47
  46. package/src/guards/model-switch-hook.mjs +126 -0
  47. package/src/guards/phase5-detectors.mjs +275 -21
  48. package/src/guards/post-tool-engine.mjs +333 -11
  49. package/src/guards/pre-tool-engine.mjs +607 -45
  50. package/src/guards/prefix-guard.mjs +609 -0
  51. package/src/guards/prompt-guard.mjs +309 -0
  52. package/src/guards/read-clamp.mjs +192 -8
  53. package/src/guards/session-hook.mjs +149 -7
  54. package/src/guards/shell-guard.mjs +56 -5
  55. package/src/guards/snooze.mjs +169 -5
  56. package/src/ipc/daemon.mjs +76 -0
  57. package/src/ipc/fast-client.mjs +165 -4
  58. package/src/ipc/protocol.mjs +16 -3
  59. package/src/storage/antigravity-parser.mjs +16 -2
  60. package/src/storage/file-lock.mjs +16 -3
  61. package/src/storage/jsonl-parser.mjs +133 -22
  62. package/src/storage/telemetry-metrics.mjs +254 -4
@@ -4,9 +4,24 @@
4
4
  * Gemini, and OpenAI telemetry in burnoff.
5
5
  */
6
6
 
7
+ import fs from 'node:fs';
8
+
7
9
  export const RATE_CARD_VERSION = '2026-11-27';
8
10
  export const DEFAULT_UNMAPPED_CACHED_WEIGHT = 0.05;
9
11
  const UPCOMING_NOTICE_WINDOW_MS = 14 * 86_400_000;
12
+ const ANTHROPIC_MIN_CACHEABLE_SOURCE_URL =
13
+ 'https://platform.claude.com/docs/en/build-with-claude/prompt-caching';
14
+ const ANTHROPIC_MIN_CACHEABLE_CHECKED_ON = '2026-11-28';
15
+
16
+ let CATALOG_MODELS = Object.freeze({});
17
+ try {
18
+ const parsed = JSON.parse(fs.readFileSync(new URL('./catalog.json', import.meta.url), 'utf8'));
19
+ if (parsed?.models && typeof parsed.models === 'object') {
20
+ CATALOG_MODELS = Object.freeze(parsed.models);
21
+ }
22
+ } catch {
23
+ // ignore: fallback to built-in RATE_CARD_MODELS if catalog.json is unreadable
24
+ }
10
25
 
11
26
  export const SUBSCRIPTION_QUOTA_CONSTANTS = Object.freeze({
12
27
  ARGON_CARBON_PER_USD_WEIGHT: 3.0,
@@ -14,7 +29,8 @@ export const SUBSCRIPTION_QUOTA_CONSTANTS = Object.freeze({
14
29
  SDK_CLI_HEADLESS_MULTIPLIER: 1.8,
15
30
  SDK_CLI_IS_HEURISTIC: true,
16
31
  ACP_CUSTOM_AGENT_MULTIPLIER: 4.0,
17
- ACP_CUSTOM_AGENT_AFFECTED_VERSION: '1.5.17'
32
+ ACP_CUSTOM_AGENT_AFFECTED_VERSION: '1.5.17',
33
+ ACP_CUSTOM_AGENT_AFFECTED_VERSIONS: Object.freeze(['1.5.17', '1.5.18'])
18
34
  });
19
35
 
20
36
  export const CATALOG_QUOTA_MULTIPLIERS = Object.freeze({
@@ -61,6 +77,7 @@ export const RATE_CARD_MODELS = Object.freeze({
61
77
  modelId: 'gemini-4-neon',
62
78
  label: 'Gemini 4 Neon',
63
79
  cachedReadWeight: 0.05,
80
+ // Reference: https://ai.google.dev/gemini-api/docs/caching (explicit caching minimum input size)
64
81
  minCacheableTokens: 4096,
65
82
  sharedPoolCeiling: 1048576,
66
83
  cliffThresholdTokens: null,
@@ -211,6 +228,8 @@ export const RATE_CARD_MODELS = Object.freeze({
211
228
  label: 'Claude Opus 5.5',
212
229
  cachedReadWeight: 0.05,
213
230
  minCacheableTokens: 512,
231
+ minCacheableSourceUrl: ANTHROPIC_MIN_CACHEABLE_SOURCE_URL,
232
+ minCacheableCheckedOn: ANTHROPIC_MIN_CACHEABLE_CHECKED_ON,
214
233
  sharedPoolCeiling: 1000000,
215
234
  cliffThresholdTokens: null,
216
235
  outputIncludesThinking: true,
@@ -228,6 +247,8 @@ export const RATE_CARD_MODELS = Object.freeze({
228
247
  label: 'Claude Sonnet 5.5',
229
248
  cachedReadWeight: 0.05,
230
249
  minCacheableTokens: 512,
250
+ minCacheableSourceUrl: ANTHROPIC_MIN_CACHEABLE_SOURCE_URL,
251
+ minCacheableCheckedOn: ANTHROPIC_MIN_CACHEABLE_CHECKED_ON,
231
252
  sharedPoolCeiling: 1000000,
232
253
  cliffThresholdTokens: null,
233
254
  outputIncludesThinking: true,
@@ -244,7 +265,9 @@ export const RATE_CARD_MODELS = Object.freeze({
244
265
  modelId: 'claude-fable-5-1',
245
266
  label: 'Claude Fable 5.1',
246
267
  cachedReadWeight: 0.025,
247
- minCacheableTokens: 1024,
268
+ minCacheableTokens: 512,
269
+ minCacheableSourceUrl: ANTHROPIC_MIN_CACHEABLE_SOURCE_URL,
270
+ minCacheableCheckedOn: ANTHROPIC_MIN_CACHEABLE_CHECKED_ON,
248
271
  sharedPoolCeiling: 1000000,
249
272
  cliffThresholdTokens: null,
250
273
  outputIncludesThinking: true,
@@ -261,7 +284,9 @@ export const RATE_CARD_MODELS = Object.freeze({
261
284
  modelId: 'claude-fable-5-2',
262
285
  label: 'Claude Fable 5.2',
263
286
  cachedReadWeight: 0.025,
264
- minCacheableTokens: 1024,
287
+ minCacheableTokens: 512,
288
+ minCacheableSourceUrl: ANTHROPIC_MIN_CACHEABLE_SOURCE_URL,
289
+ minCacheableCheckedOn: ANTHROPIC_MIN_CACHEABLE_CHECKED_ON,
265
290
  sharedPoolCeiling: 1000000,
266
291
  cliffThresholdTokens: null,
267
292
  outputIncludesThinking: true,
@@ -279,6 +304,8 @@ export const RATE_CARD_MODELS = Object.freeze({
279
304
  label: 'Claude Haiku 5.5',
280
305
  cachedReadWeight: 0.10,
281
306
  minCacheableTokens: 512,
307
+ minCacheableSourceUrl: ANTHROPIC_MIN_CACHEABLE_SOURCE_URL,
308
+ minCacheableCheckedOn: ANTHROPIC_MIN_CACHEABLE_CHECKED_ON,
282
309
  sharedPoolCeiling: 1000000,
283
310
  cliffThresholdTokens: 100000,
284
311
  outputIncludesThinking: true,
@@ -297,7 +324,9 @@ export const RATE_CARD_MODELS = Object.freeze({
297
324
  modelId: 'claude-opus-4-6',
298
325
  label: 'Claude Opus 4.6',
299
326
  cachedReadWeight: 0.10,
300
- minCacheableTokens: 1024,
327
+ minCacheableTokens: 4096,
328
+ minCacheableSourceUrl: ANTHROPIC_MIN_CACHEABLE_SOURCE_URL,
329
+ minCacheableCheckedOn: ANTHROPIC_MIN_CACHEABLE_CHECKED_ON,
301
330
  sharedPoolCeiling: 200000,
302
331
  cliffThresholdTokens: 200000,
303
332
  outputIncludesThinking: true,
@@ -312,11 +341,34 @@ export const RATE_CARD_MODELS = Object.freeze({
312
341
  )
313
342
  ])
314
343
  }),
344
+ 'claude-opus-4-5': Object.freeze({
345
+ modelId: 'claude-opus-4-5',
346
+ label: 'Claude Opus 4.5',
347
+ cachedReadWeight: 0.10,
348
+ minCacheableTokens: 4096,
349
+ minCacheableSourceUrl: ANTHROPIC_MIN_CACHEABLE_SOURCE_URL,
350
+ minCacheableCheckedOn: ANTHROPIC_MIN_CACHEABLE_CHECKED_ON,
351
+ sharedPoolCeiling: 200000,
352
+ cliffThresholdTokens: null,
353
+ outputIncludesThinking: true,
354
+ schedules: Object.freeze([
355
+ freezeSchedule(
356
+ 'claude-opus-4-5-standard',
357
+ null,
358
+ null,
359
+ freezeRates(5.0, 0.50, 25.0, 6.25, 10.0),
360
+ freezeRates(5.0, 0.50, 25.0, 6.25, 10.0),
361
+ freezeRates(5.0, 0.50, 25.0, 6.25, 10.0)
362
+ )
363
+ ])
364
+ }),
315
365
  'claude-sonnet-4-6': Object.freeze({
316
366
  modelId: 'claude-sonnet-4-6',
317
367
  label: 'Claude Sonnet 4.6',
318
368
  cachedReadWeight: 0.10,
319
369
  minCacheableTokens: 1024,
370
+ minCacheableSourceUrl: ANTHROPIC_MIN_CACHEABLE_SOURCE_URL,
371
+ minCacheableCheckedOn: ANTHROPIC_MIN_CACHEABLE_CHECKED_ON,
320
372
  sharedPoolCeiling: 200000,
321
373
  cliffThresholdTokens: 200000,
322
374
  outputIncludesThinking: true,
@@ -335,7 +387,9 @@ export const RATE_CARD_MODELS = Object.freeze({
335
387
  modelId: 'claude-haiku-4-5',
336
388
  label: 'Claude Haiku 4.5',
337
389
  cachedReadWeight: 0.10,
338
- minCacheableTokens: 1024,
390
+ minCacheableTokens: 4096,
391
+ minCacheableSourceUrl: ANTHROPIC_MIN_CACHEABLE_SOURCE_URL,
392
+ minCacheableCheckedOn: ANTHROPIC_MIN_CACHEABLE_CHECKED_ON,
339
393
  sharedPoolCeiling: 200000,
340
394
  cliffThresholdTokens: null,
341
395
  outputIncludesThinking: true,
@@ -352,7 +406,8 @@ export const RATE_CARD_MODELS = Object.freeze({
352
406
  modelId: 'gpt-6.1-sol',
353
407
  label: 'GPT-6.1 Sol',
354
408
  cachedReadWeight: 0.05,
355
- minCacheableTokens: 512,
409
+ // Reference: https://platform.openai.com/docs/guides/prompt-caching (caching starts at 1024 prompt tokens, in 128-token steps)
410
+ minCacheableTokens: 1024,
356
411
  sharedPoolCeiling: 1048576,
357
412
  cliffThresholdTokens: null,
358
413
  outputIncludesThinking: true,
@@ -369,7 +424,8 @@ export const RATE_CARD_MODELS = Object.freeze({
369
424
  modelId: 'gpt-5.4',
370
425
  label: 'GPT-5.4',
371
426
  cachedReadWeight: 0.10,
372
- minCacheableTokens: 512,
427
+ // Reference: https://platform.openai.com/docs/guides/prompt-caching (caching starts at 1024 prompt tokens, in 128-token steps)
428
+ minCacheableTokens: 1024,
373
429
  sharedPoolCeiling: 1050000,
374
430
  cliffThresholdTokens: 272000,
375
431
  outputIncludesThinking: true,
@@ -383,6 +439,101 @@ export const RATE_CARD_MODELS = Object.freeze({
383
439
  freezeRates(5.0, 0.50, 22.5)
384
440
  )
385
441
  ])
442
+ }),
443
+ 'gpt-6.2-astra': Object.freeze({
444
+ modelId: 'gpt-6.2-astra',
445
+ label: 'GPT-6.2 Astra',
446
+ cachedReadWeight: 0.05,
447
+ minCacheableTokens: 512,
448
+ sharedPoolCeiling: 1050000,
449
+ cliffThresholdTokens: 272000,
450
+ outputIncludesThinking: true,
451
+ schedules: Object.freeze([
452
+ freezeSchedule(
453
+ 'gpt-6-2-astra-standard',
454
+ null,
455
+ null,
456
+ freezeRates(8.0, 0.40, 40.0, 10.0, 20.0),
457
+ freezeRates(8.0, 0.40, 40.0, 10.0, 20.0),
458
+ freezeRates(16.0, 0.80, 60.0, 20.0, 40.0)
459
+ )
460
+ ])
461
+ }),
462
+ 'gpt-6.2-sol': Object.freeze({
463
+ modelId: 'gpt-6.2-sol',
464
+ label: 'GPT-6.2 Sol',
465
+ cachedReadWeight: 0.05,
466
+ minCacheableTokens: 512,
467
+ sharedPoolCeiling: 1050000,
468
+ cliffThresholdTokens: 272000,
469
+ outputIncludesThinking: true,
470
+ schedules: Object.freeze([
471
+ freezeSchedule(
472
+ 'gpt-6-2-sol-standard',
473
+ null,
474
+ null,
475
+ freezeRates(2.0, 0.10, 10.0, 2.5, 5.0),
476
+ freezeRates(2.0, 0.10, 10.0, 2.5, 5.0),
477
+ freezeRates(4.0, 0.20, 15.0, 5.0, 10.0)
478
+ )
479
+ ])
480
+ }),
481
+ 'gpt-6.1-terra': Object.freeze({
482
+ modelId: 'gpt-6.1-terra',
483
+ label: 'GPT-6.1 Terra',
484
+ cachedReadWeight: 0.05,
485
+ minCacheableTokens: 512,
486
+ sharedPoolCeiling: 1050000,
487
+ cliffThresholdTokens: 272000,
488
+ outputIncludesThinking: true,
489
+ schedules: Object.freeze([
490
+ freezeSchedule(
491
+ 'gpt-6-1-terra-standard',
492
+ null,
493
+ null,
494
+ freezeRates(1.0, 0.05, 5.0, 1.25, 2.50),
495
+ freezeRates(1.0, 0.05, 5.0, 1.25, 2.50),
496
+ freezeRates(2.0, 0.10, 7.5, 2.50, 5.0)
497
+ )
498
+ ])
499
+ }),
500
+ 'gpt-6-astra': Object.freeze({
501
+ modelId: 'gpt-6-astra',
502
+ label: 'GPT-6 Astra',
503
+ cachedReadWeight: 0.10,
504
+ minCacheableTokens: 512,
505
+ sharedPoolCeiling: 1050000,
506
+ cliffThresholdTokens: 272000,
507
+ outputIncludesThinking: true,
508
+ schedules: Object.freeze([
509
+ freezeSchedule(
510
+ 'gpt-6-astra-standard',
511
+ null,
512
+ null,
513
+ freezeRates(10.0, 1.0, 50.0, 12.5, 25.0),
514
+ freezeRates(10.0, 1.0, 50.0, 12.5, 25.0),
515
+ freezeRates(20.0, 2.0, 75.0, 25.0, 50.0)
516
+ )
517
+ ])
518
+ }),
519
+ 'gpt-6-luna': Object.freeze({
520
+ modelId: 'gpt-6-luna',
521
+ label: 'GPT-6 Luna',
522
+ cachedReadWeight: 0.10,
523
+ minCacheableTokens: 512,
524
+ sharedPoolCeiling: 1050000,
525
+ cliffThresholdTokens: 272000,
526
+ outputIncludesThinking: true,
527
+ schedules: Object.freeze([
528
+ freezeSchedule(
529
+ 'gpt-6-luna-standard',
530
+ null,
531
+ null,
532
+ freezeRates(0.10, 0.01, 0.50, 0.125, 0.25),
533
+ freezeRates(0.10, 0.01, 0.50, 0.125, 0.25),
534
+ freezeRates(0.20, 0.02, 0.75, 0.25, 0.50)
535
+ )
536
+ ])
386
537
  })
387
538
  });
388
539
 
@@ -479,8 +630,31 @@ const DIRECT_ALIASES = Object.freeze({
479
630
  'haiku-5-5': 'claude-haiku-5-5',
480
631
  'haiku-5.5': 'claude-haiku-5-5',
481
632
  haiku: 'claude-haiku-5-5',
633
+ 'claude-opus-4-5': 'claude-opus-4-5',
634
+ 'claude-opus-4.5': 'claude-opus-4-5',
635
+ 'claude-opus-4-5-20251101': 'claude-opus-4-5',
636
+ 'opus-4-5': 'claude-opus-4-5',
637
+ 'opus-4.5': 'claude-opus-4-5',
482
638
  'gpt-6-1-sol': 'gpt-6.1-sol',
483
639
  'gpt-6.1-sol': 'gpt-6.1-sol',
640
+ 'gpt-6-1-terra': 'gpt-6.1-terra',
641
+ 'gpt-6.1-terra': 'gpt-6.1-terra',
642
+ 'openai/gpt-6-1-terra': 'gpt-6.1-terra',
643
+ 'openai/gpt-6.1-terra': 'gpt-6.1-terra',
644
+ 'gpt-6-astra': 'gpt-6-astra',
645
+ 'gpt-6.astra': 'gpt-6-astra',
646
+ 'openai/gpt-6-astra': 'gpt-6-astra',
647
+ 'gpt-6-luna': 'gpt-6-luna',
648
+ 'gpt-6.luna': 'gpt-6-luna',
649
+ 'openai/gpt-6-luna': 'gpt-6-luna',
650
+ 'gpt-6-2-astra': 'gpt-6.2-astra',
651
+ 'gpt-6.2-astra': 'gpt-6.2-astra',
652
+ 'openai/gpt-6-2-astra': 'gpt-6.2-astra',
653
+ 'openai/gpt-6.2-astra': 'gpt-6.2-astra',
654
+ 'gpt-6-2-sol': 'gpt-6.2-sol',
655
+ 'gpt-6.2-sol': 'gpt-6.2-sol',
656
+ 'openai/gpt-6-2-sol': 'gpt-6.2-sol',
657
+ 'openai/gpt-6.2-sol': 'gpt-6.2-sol',
484
658
  'gpt-5-4': 'gpt-5.4',
485
659
  'gpt-5.4': 'gpt-5.4'
486
660
  });
@@ -500,9 +674,15 @@ function detectFamilyFromText(cleanedText) {
500
674
  if (cleanedText.includes('fable-5-1') || cleanedText.includes('fable-5.1')) return 'claude-fable-5-1';
501
675
  if (cleanedText.includes('haiku-5-5') || cleanedText.includes('haiku-5.5')) return 'claude-haiku-5-5';
502
676
  if (cleanedText.includes('opus-4-6') || cleanedText.includes('opus-4.6')) return 'claude-opus-4-6';
677
+ if (cleanedText.includes('opus-4-5') || cleanedText.includes('opus-4.5')) return 'claude-opus-4-5';
503
678
  if (cleanedText.includes('sonnet-4-6') || cleanedText.includes('sonnet-4.6')) return 'claude-sonnet-4-6';
504
679
  if (cleanedText.includes('haiku-4-5') || cleanedText.includes('haiku-4.5')) return 'claude-haiku-4-5';
680
+ if (cleanedText.includes('gpt-6-2-astra') || cleanedText.includes('gpt-6.2-astra')) return 'gpt-6.2-astra';
681
+ if (cleanedText.includes('gpt-6-2-sol') || cleanedText.includes('gpt-6.2-sol')) return 'gpt-6.2-sol';
682
+ if (cleanedText.includes('gpt-6-1-terra') || cleanedText.includes('gpt-6.1-terra')) return 'gpt-6.1-terra';
505
683
  if (cleanedText.includes('gpt-6-1-sol') || cleanedText.includes('gpt-6.1-sol')) return 'gpt-6.1-sol';
684
+ if (cleanedText.includes('gpt-6-astra')) return 'gpt-6-astra';
685
+ if (cleanedText.includes('gpt-6-luna')) return 'gpt-6-luna';
506
686
  if (cleanedText.includes('gpt-5-4') || cleanedText.includes('gpt-5.4')) return 'gpt-5.4';
507
687
  return null;
508
688
  }
@@ -536,6 +716,34 @@ function resolveCanonicalModelId(model, label) {
536
716
  return null;
537
717
  }
538
718
 
719
+ function lookupCatalogEntry(model = '', label = '') {
720
+ for (const rawCandidate of [model, label]) {
721
+ let cleaned = cleanModelString(rawCandidate);
722
+ if (!cleaned) continue;
723
+ const bedrockMatch = cleaned.match(/^(?:[a-z-]+\.)?anthropic\.(claude-.*)$/);
724
+ if (bedrockMatch) cleaned = bedrockMatch[1];
725
+ cleaned = cleaned.replace(/\./g, '-').replace(/-v\d+(?::\d+)?$/i, '');
726
+ const altOrder = cleaned.match(/^claude-([4-9]\d*-\d+)-(opus|sonnet|haiku|fable|mythos)$/);
727
+ if (altOrder) cleaned = `claude-${altOrder[2]}-${altOrder[1]}`;
728
+ const withPrefix = /^(?:opus|sonnet|haiku|fable|mythos)-/.test(cleaned) ? `claude-${cleaned}` : cleaned;
729
+ const expanded = withPrefix === 'claude-opus-4'
730
+ ? 'claude-opus-4-0'
731
+ : (withPrefix === 'claude-sonnet-4' ? 'claude-sonnet-4-0' : withPrefix);
732
+ const aliased = DIRECT_ALIASES[expanded] || expanded;
733
+ if (aliased === 'mythos-preview' || aliased === 'claude-mythos-preview') {
734
+ return {
735
+ minCacheableTokens: 2048,
736
+ minCacheableSourceUrl: ANTHROPIC_MIN_CACHEABLE_SOURCE_URL,
737
+ minCacheableCheckedOn: ANTHROPIC_MIN_CACHEABLE_CHECKED_ON
738
+ };
739
+ }
740
+ if (CATALOG_MODELS[aliased]) return CATALOG_MODELS[aliased];
741
+ if (CATALOG_MODELS[expanded]) return CATALOG_MODELS[expanded];
742
+ if (CATALOG_MODELS[cleaned]) return CATALOG_MODELS[cleaned];
743
+ }
744
+ return null;
745
+ }
746
+
539
747
  /**
540
748
  * Resolves the date-aware rate card entry for a call given `{ model, label, timestampMs, promptTokens, serviceTier }`.
541
749
  */
@@ -549,6 +757,7 @@ export function resolveModelRateCard({
549
757
  const rawModel = String(model || label || '').trim() || 'unknown';
550
758
  const canonicalId = resolveCanonicalModelId(model, label);
551
759
  const entry = canonicalId ? RATE_CARD_MODELS[canonicalId] : null;
760
+ const catalogEntry = lookupCatalogEntry(canonicalId || model, label) || lookupCatalogEntry(model, label);
552
761
  const evalTsMs = toEpochMs(timestampMs, Date.now());
553
762
  const prompt = Math.max(0, Number(promptTokens || 0));
554
763
 
@@ -574,7 +783,9 @@ export function resolveModelRateCard({
574
783
  cliffThresholdTokens: null,
575
784
  inLongContextCliff: false,
576
785
  cliffTriggered: false,
577
- minCacheableTokens: 4096,
786
+ minCacheableTokens: catalogEntry?.minCacheableTokens ?? 4096,
787
+ minCacheableSourceUrl: catalogEntry?.minCacheableSourceUrl ?? null,
788
+ minCacheableCheckedOn: catalogEntry?.minCacheableCheckedOn ?? null,
578
789
  sharedPoolCeiling: null,
579
790
  outputIncludesThinking: true,
580
791
  scheduleId: 'unmapped',
@@ -621,7 +832,9 @@ export function resolveModelRateCard({
621
832
  cliffThresholdTokens: entry.cliffThresholdTokens,
622
833
  inLongContextCliff: cliffActive,
623
834
  cliffTriggered: cliffActive,
624
- minCacheableTokens: entry.minCacheableTokens,
835
+ minCacheableTokens: catalogEntry?.minCacheableTokens ?? entry.minCacheableTokens ?? 4096,
836
+ minCacheableSourceUrl: catalogEntry?.minCacheableSourceUrl ?? entry.minCacheableSourceUrl ?? null,
837
+ minCacheableCheckedOn: catalogEntry?.minCacheableCheckedOn ?? entry.minCacheableCheckedOn ?? null,
625
838
  sharedPoolCeiling: entry.sharedPoolCeiling,
626
839
  outputIncludesThinking: entry.outputIncludesThinking,
627
840
  scheduleId: sched.id,
@@ -682,8 +895,11 @@ export function resolveSubscriptionQuotaWeight({
682
895
  let isHeuristic = false;
683
896
 
684
897
  const trimmedVer = clientVersion ? String(clientVersion).trim() : '';
898
+ const affectedVersions = SUBSCRIPTION_QUOTA_CONSTANTS.ACP_CUSTOM_AGENT_AFFECTED_VERSIONS || [
899
+ SUBSCRIPTION_QUOTA_CONSTANTS.ACP_CUSTOM_AGENT_AFFECTED_VERSION
900
+ ];
685
901
  const acpVersionAffected =
686
- !trimmedVer || trimmedVer === SUBSCRIPTION_QUOTA_CONSTANTS.ACP_CUSTOM_AGENT_AFFECTED_VERSION || trimmedVer.startsWith(SUBSCRIPTION_QUOTA_CONSTANTS.ACP_CUSTOM_AGENT_AFFECTED_VERSION);
902
+ !trimmedVer || affectedVersions.some((v) => trimmedVer === v || trimmedVer.startsWith(v));
687
903
  if (acpCustomAgent === true && acpVersionAffected) {
688
904
  invocationMultiplier *= SUBSCRIPTION_QUOTA_CONSTANTS.ACP_CUSTOM_AGENT_MULTIPLIER;
689
905
  invocationTags.push('acp_custom_agent_4x');
@@ -755,11 +971,13 @@ export function valuateCall(call = {}) {
755
971
 
756
972
  const baseUncachedUnits = uncachedTokens;
757
973
  const cachedEquivalentUnits = cachedTokens * card.cachedReadWeight;
758
- const writeSurchargeUnits = card.unmappedModel || !card.inputPer1M
759
- ? effWrite5m * 0.25 + effWrite1h * 1.0
760
- : effWrite5m * Math.max(0, (card.write5mPer1M / card.inputPer1M) - 1) +
761
- effWrite1h * Math.max(0, (card.write1hPer1M / card.inputPer1M) - 1);
762
- const uncachedEquivalentInputUnits = baseUncachedUnits + cachedEquivalentUnits + writeSurchargeUnits;
974
+ // Cache writes are billed at a multiple of the base input rate (1.25x / 2x on Anthropic), so they
975
+ // contribute their FULL base-input-equivalent weight, not just the premium above the input rate.
976
+ const writeEquivalentUnits = card.unmappedModel || !card.inputPer1M
977
+ ? effWrite5m * 1.25 + effWrite1h * 2.0
978
+ : effWrite5m * (card.write5mPer1M / card.inputPer1M) +
979
+ effWrite1h * (card.write1hPer1M / card.inputPer1M);
980
+ const uncachedEquivalentInputUnits = baseUncachedUnits + cachedEquivalentUnits + writeEquivalentUnits;
763
981
  const catalogWeightedUnits = Number(
764
982
  ((uncachedEquivalentInputUnits / 1_000_000) * quotaWeight.catalogEffortMultiplier * quotaWeight.invocationMultiplier).toFixed(6)
765
983
  );
@@ -780,6 +998,7 @@ export function valuateCall(call = {}) {
780
998
  cachedEquivalentUnits,
781
999
  inputUncachedUsd: null,
782
1000
  inputCachedReadUsd: null,
1001
+ cacheWriteTotalUsd: null,
783
1002
  cacheWriteSurchargeUsd: null,
784
1003
  outputUsd: null,
785
1004
  totalEstimatedUsd: null,
@@ -792,12 +1011,15 @@ export function valuateCall(call = {}) {
792
1011
 
793
1012
  const inputUncachedUsd = (uncachedTokens / 1_000_000) * card.inputPer1M;
794
1013
  const inputCachedReadUsd = (cachedTokens / 1_000_000) * card.cachedReadPer1M;
1014
+ // Full cost of cache writes vs. the premium paid above the base input rate.
1015
+ const cacheWriteTotalUsd =
1016
+ (effWrite5m / 1_000_000) * card.write5mPer1M +
1017
+ (effWrite1h / 1_000_000) * card.write1hPer1M;
795
1018
  const cacheWriteSurchargeUsd =
796
1019
  (effWrite5m / 1_000_000) * Math.max(0, card.write5mPer1M - card.inputPer1M) +
797
- (effWrite1h / 1_000_000) * Math.max(0, card.write1hPer1M - card.inputPer1M) +
798
- ((effWrite5m + effWrite1h) / 1_000_000) * card.inputPer1M;
1020
+ (effWrite1h / 1_000_000) * Math.max(0, card.write1hPer1M - card.inputPer1M);
799
1021
  const outputUsd = (outputTokens / 1_000_000) * card.outputPer1M;
800
- const totalEstimatedUsd = inputUncachedUsd + inputCachedReadUsd + cacheWriteSurchargeUsd + outputUsd;
1022
+ const totalEstimatedUsd = inputUncachedUsd + inputCachedReadUsd + cacheWriteTotalUsd + outputUsd;
801
1023
  const normalizedQuotaBurnUnits = Number((totalEstimatedUsd * quotaWeight.combinedQuotaMultiplier).toFixed(6));
802
1024
 
803
1025
  let cliffSurchargeUsd = 0;
@@ -826,6 +1048,7 @@ export function valuateCall(call = {}) {
826
1048
  cachedEquivalentUnits,
827
1049
  inputUncachedUsd,
828
1050
  inputCachedReadUsd,
1051
+ cacheWriteTotalUsd,
829
1052
  cacheWriteSurchargeUsd,
830
1053
  outputUsd,
831
1054
  totalEstimatedUsd,
@@ -847,6 +1070,7 @@ export function valuateBatch(calls = [], { nowMs = Date.now(), days = 7, entrypo
847
1070
 
848
1071
  let inputUncachedUsd = 0;
849
1072
  let inputCachedReadUsd = 0;
1073
+ let cacheWriteTotalUsd = 0;
850
1074
  let cacheWriteSurchargeUsd = 0;
851
1075
  let outputUsd = 0;
852
1076
  let uncachedEquivalentInputUnits = 0;
@@ -880,6 +1104,7 @@ export function valuateBatch(calls = [], { nowMs = Date.now(), days = 7, entrypo
880
1104
  } else {
881
1105
  inputUncachedUsd += val.inputUncachedUsd;
882
1106
  inputCachedReadUsd += val.inputCachedReadUsd;
1107
+ cacheWriteTotalUsd += val.cacheWriteTotalUsd;
883
1108
  cacheWriteSurchargeUsd += val.cacheWriteSurchargeUsd;
884
1109
  outputUsd += val.outputUsd;
885
1110
  if (val.normalizedQuotaBurnUnits !== null) {
@@ -926,6 +1151,8 @@ export function valuateBatch(calls = [], { nowMs = Date.now(), days = 7, entrypo
926
1151
  const postTotal =
927
1152
  (val.uncachedTokens / 1_000_000) * next.inputPer1M +
928
1153
  (val.cachedTokens / 1_000_000) * next.cachedReadPer1M +
1154
+ (val.write5mTokens / 1_000_000) * (next.write5mPer1M ?? next.inputPer1M) +
1155
+ (val.write1hTokens / 1_000_000) * (next.write1hPer1M ?? next.inputPer1M) +
929
1156
  (val.outputTokens / 1_000_000) * next.outputPer1M;
930
1157
  const deltaUsd = Math.max(0, postTotal - (val.totalEstimatedUsd || 0));
931
1158
  const key = `${card.modelId}|${card.upcomingChange.effectiveFromUtc}`;
@@ -940,7 +1167,7 @@ export function valuateBatch(calls = [], { nowMs = Date.now(), days = 7, entrypo
940
1167
  }
941
1168
  }
942
1169
 
943
- const totalEstimatedUsd = Number((inputUncachedUsd + inputCachedReadUsd + cacheWriteSurchargeUsd + outputUsd).toFixed(2));
1170
+ const totalEstimatedUsd = Number((inputUncachedUsd + inputCachedReadUsd + cacheWriteTotalUsd + outputUsd).toFixed(2));
944
1171
  const cachedShareOfInputSpendPct = uncachedEquivalentInputUnits > 0
945
1172
  ? Number(((cachedEquivalentInputUnits / uncachedEquivalentInputUnits) * 100).toFixed(1))
946
1173
  : 0;
@@ -994,6 +1221,7 @@ export function valuateBatch(calls = [], { nowMs = Date.now(), days = 7, entrypo
994
1221
  totalCatalogWeightedUnits: Number(totalCatalogWeightedUnits.toFixed(4)),
995
1222
  inputUncachedUsd: Number(inputUncachedUsd.toFixed(2)),
996
1223
  inputCachedReadUsd: Number(inputCachedReadUsd.toFixed(2)),
1224
+ cacheWriteTotalUsd: Number(cacheWriteTotalUsd.toFixed(2)),
997
1225
  cacheWriteSurchargeUsd: Number(cacheWriteSurchargeUsd.toFixed(2)),
998
1226
  outputUsd: Number(outputUsd.toFixed(2)),
999
1227
  uncachedEquivalentInputUnits: Math.round(uncachedEquivalentInputUnits),
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @file src/config/semver.mjs
3
+ * Tiny dependency-free `major.minor.patch` comparison shared by the startup audit and hook engines.
4
+ */
5
+
6
+ function parseSemver(v) {
7
+ const m = String(v || '').trim().match(/^v?(\d+)\.(\d+)\.(\d+)/);
8
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
9
+ }
10
+
11
+ /**
12
+ * Returns `-1`, `0`, or `1`, or `null` when either side is not a parseable semver.
13
+ */
14
+ export function compareSemver(a, b) {
15
+ const pa = parseSemver(a);
16
+ const pb = parseSemver(b);
17
+ if (!pa || !pb) return null;
18
+ for (let i = 0; i < 3; i += 1) {
19
+ if (pa[i] < pb[i]) return -1;
20
+ if (pa[i] > pb[i]) return 1;
21
+ }
22
+ return 0;
23
+ }
24
+
25
+ export default { compareSemver };