burnoff 1.0.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/.github/workflows/burnoff-pr-gate.yml +75 -0
- package/README.md +94 -20
- package/bin/burnoff.mjs +129 -30
- package/hooks/hook-io.mjs +27 -18
- package/hooks/post-tool-use.mjs +33 -26
- package/hooks/pre-tool-use.mjs +43 -41
- package/hooks/session-lifecycle.mjs +40 -0
- package/package.json +8 -5
- package/src/ci/ci-gate.mjs +84 -9
- package/src/ci/pr-cost.mjs +207 -22
- package/src/ci/team-digest.mjs +6 -4
- package/src/cli/audit.mjs +177 -23
- package/src/cli/doctor.mjs +230 -25
- package/src/cli/init.mjs +415 -75
- package/src/cli/startup-audit.mjs +2824 -0
- package/src/clients/antigravity.mjs +285 -0
- package/src/clients/claude-code.mjs +180 -0
- package/src/clients/detect.mjs +64 -0
- package/src/config/catalog.json +188 -45
- package/src/config/loader.mjs +96 -13
- package/src/config/paths.mjs +92 -2
- package/src/config/policy.mjs +103 -17
- package/src/config/pricing.mjs +1033 -0
- package/src/config/uncached-attribution.mjs +719 -0
- package/src/guards/loop-breaker.mjs +267 -24
- package/src/guards/post-tool-engine.mjs +316 -35
- package/src/guards/pre-tool-engine.mjs +389 -130
- package/src/guards/read-clamp.mjs +149 -75
- package/src/guards/session-hook.mjs +207 -0
- package/src/guards/shell-guard.mjs +610 -74
- package/src/ipc/daemon.mjs +50 -8
- package/src/ipc/fast-client.mjs +62 -5
- package/src/ipc/protocol.mjs +1 -1
- package/src/storage/antigravity-parser.mjs +258 -0
- package/src/storage/atomic-io.mjs +2 -2
- package/src/storage/file-lock.mjs +66 -13
- package/src/storage/fts5-archive.mjs +31 -16
- package/src/storage/jsonl-parser.mjs +209 -20
- package/src/storage/ledger.mjs +15 -10
- package/src/storage/sqlite-client.mjs +35 -11
- package/hooks/hooks.json +0 -12
package/src/config/catalog.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": "2026.11.15",
|
|
3
3
|
"catalogVersion": "2026-11-15",
|
|
4
|
-
"source": "
|
|
4
|
+
"source": "OpenRouter /api/v1/models (2026-11-15) & Claude Code 2.1.325 bakedCatalog",
|
|
5
5
|
"dateRead": "2026-11-15",
|
|
6
6
|
"defaultModel": "claude-sonnet-5-5",
|
|
7
7
|
"cacheWriteMultipliers": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"write1h": 2,
|
|
37
37
|
"read": 0.025
|
|
38
38
|
},
|
|
39
|
-
"source": "
|
|
39
|
+
"source": "OpenRouter /api/v1/models",
|
|
40
40
|
"sourceUrl": "https://openrouter.ai/api/v1/models",
|
|
41
41
|
"verifiedAt": "2026-11-15",
|
|
42
42
|
"dateRead": "2026-11-15",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"write1h": 2,
|
|
63
63
|
"read": 0.025
|
|
64
64
|
},
|
|
65
|
-
"source": "
|
|
65
|
+
"source": "OpenRouter /api/v1/models",
|
|
66
66
|
"sourceUrl": "https://openrouter.ai/api/v1/models",
|
|
67
67
|
"verifiedAt": "2026-11-15",
|
|
68
68
|
"dateRead": "2026-11-15",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"write1h": 2,
|
|
89
89
|
"read": 0.1
|
|
90
90
|
},
|
|
91
|
-
"source": "
|
|
91
|
+
"source": "OpenRouter /api/v1/models & Claude Code 2.1.325 bakedCatalog (tier_10_50)",
|
|
92
92
|
"dateRead": "2026-11-15",
|
|
93
93
|
"pricingCliff": null
|
|
94
94
|
},
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"write1h": 2,
|
|
113
113
|
"read": 0.05
|
|
114
114
|
},
|
|
115
|
-
"source": "
|
|
115
|
+
"source": "OpenRouter /api/v1/models",
|
|
116
116
|
"sourceUrl": "https://openrouter.ai/api/v1/models",
|
|
117
117
|
"verifiedAt": "2026-11-15",
|
|
118
118
|
"dateRead": "2026-11-15",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
"write1h": 2,
|
|
139
139
|
"read": 0.05
|
|
140
140
|
},
|
|
141
|
-
"source": "
|
|
141
|
+
"source": "OpenRouter /api/v1/models",
|
|
142
142
|
"sourceUrl": "https://openrouter.ai/api/v1/models",
|
|
143
143
|
"verifiedAt": "2026-11-15",
|
|
144
144
|
"dateRead": "2026-11-15",
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
"write1h": 2,
|
|
165
165
|
"read": 0.1
|
|
166
166
|
},
|
|
167
|
-
"source": "
|
|
167
|
+
"source": "OpenRouter /api/v1/models & Claude Code 2.1.325 bakedCatalog (haiku_55)",
|
|
168
168
|
"dateRead": "2026-11-15",
|
|
169
169
|
"pricingCliff": {
|
|
170
170
|
"thresholdTokens": 100000,
|
|
@@ -307,13 +307,41 @@
|
|
|
307
307
|
"write1h": 2,
|
|
308
308
|
"read": 0.1
|
|
309
309
|
},
|
|
310
|
+
"rateSchedules": [
|
|
311
|
+
{
|
|
312
|
+
"id": "carbon-introductory-pre-2026-12-01",
|
|
313
|
+
"window": "introductory",
|
|
314
|
+
"effectiveFrom": "1970-01-01T00:00:00Z",
|
|
315
|
+
"effectiveUntil": "2026-11-30T23:59:59Z",
|
|
316
|
+
"ratesPer1M": {
|
|
317
|
+
"input": 2,
|
|
318
|
+
"output": 10,
|
|
319
|
+
"write5m": 2,
|
|
320
|
+
"write1h": 2,
|
|
321
|
+
"read": 0.1
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
"id": "carbon-standard-from-2026-12-01",
|
|
326
|
+
"window": "post_introductory",
|
|
327
|
+
"effectiveFrom": "2026-12-01T00:00:00Z",
|
|
328
|
+
"effectiveUntil": null,
|
|
329
|
+
"ratesPer1M": {
|
|
330
|
+
"input": 4,
|
|
331
|
+
"output": 20,
|
|
332
|
+
"write5m": 4,
|
|
333
|
+
"write1h": 4,
|
|
334
|
+
"read": 0.2
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
],
|
|
310
338
|
"multipliers": {
|
|
311
339
|
"write5m": 1,
|
|
312
340
|
"write1h": 1,
|
|
313
341
|
"read": 0.05
|
|
314
342
|
},
|
|
315
343
|
"source": "config/modelCatalog.json",
|
|
316
|
-
"dateRead": "2026-11-
|
|
344
|
+
"dateRead": "2026-11-27",
|
|
317
345
|
"pricingCliff": null
|
|
318
346
|
},
|
|
319
347
|
"gemini-4-argon": {
|
|
@@ -325,19 +353,47 @@
|
|
|
325
353
|
"contextCeiling": 1048576,
|
|
326
354
|
"operationalSoftCeiling": 200000,
|
|
327
355
|
"ratesPer1M": {
|
|
328
|
-
"input":
|
|
329
|
-
"output":
|
|
330
|
-
"write5m":
|
|
331
|
-
"write1h":
|
|
332
|
-
"read": 0.
|
|
356
|
+
"input": 2,
|
|
357
|
+
"output": 10,
|
|
358
|
+
"write5m": 2,
|
|
359
|
+
"write1h": 2,
|
|
360
|
+
"read": 0.1
|
|
333
361
|
},
|
|
362
|
+
"rateSchedules": [
|
|
363
|
+
{
|
|
364
|
+
"id": "argon-introductory-pre-2026-12-01",
|
|
365
|
+
"window": "introductory",
|
|
366
|
+
"effectiveFrom": "1970-01-01T00:00:00Z",
|
|
367
|
+
"effectiveUntil": "2026-11-30T23:59:59Z",
|
|
368
|
+
"ratesPer1M": {
|
|
369
|
+
"input": 2,
|
|
370
|
+
"output": 10,
|
|
371
|
+
"write5m": 2,
|
|
372
|
+
"write1h": 2,
|
|
373
|
+
"read": 0.1
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
"id": "argon-standard-from-2026-12-01",
|
|
378
|
+
"window": "post_introductory",
|
|
379
|
+
"effectiveFrom": "2026-12-01T00:00:00Z",
|
|
380
|
+
"effectiveUntil": null,
|
|
381
|
+
"ratesPer1M": {
|
|
382
|
+
"input": 4,
|
|
383
|
+
"output": 20,
|
|
384
|
+
"write5m": 4,
|
|
385
|
+
"write1h": 4,
|
|
386
|
+
"read": 0.2
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
],
|
|
334
390
|
"multipliers": {
|
|
335
391
|
"write5m": 1,
|
|
336
392
|
"write1h": 1,
|
|
337
393
|
"read": 0.05
|
|
338
394
|
},
|
|
339
395
|
"source": "config/modelCatalog.json",
|
|
340
|
-
"dateRead": "2026-11-
|
|
396
|
+
"dateRead": "2026-11-27",
|
|
341
397
|
"pricingCliff": null
|
|
342
398
|
},
|
|
343
399
|
"gemini-4-neon": {
|
|
@@ -349,11 +405,11 @@
|
|
|
349
405
|
"contextCeiling": 1048576,
|
|
350
406
|
"operationalSoftCeiling": 200000,
|
|
351
407
|
"ratesPer1M": {
|
|
352
|
-
"input":
|
|
353
|
-
"output":
|
|
354
|
-
"write5m":
|
|
355
|
-
"write1h":
|
|
356
|
-
"read": 0.
|
|
408
|
+
"input": 3,
|
|
409
|
+
"output": 15,
|
|
410
|
+
"write5m": 3,
|
|
411
|
+
"write1h": 3,
|
|
412
|
+
"read": 0.15
|
|
357
413
|
},
|
|
358
414
|
"multipliers": {
|
|
359
415
|
"write5m": 1,
|
|
@@ -361,7 +417,7 @@
|
|
|
361
417
|
"read": 0.05
|
|
362
418
|
},
|
|
363
419
|
"source": "config/modelCatalog.json",
|
|
364
|
-
"dateRead": "2026-11-
|
|
420
|
+
"dateRead": "2026-11-27",
|
|
365
421
|
"pricingCliff": null
|
|
366
422
|
},
|
|
367
423
|
"gemini-4-hydrogen": {
|
|
@@ -370,14 +426,19 @@
|
|
|
370
426
|
"shortLabel": "Hydrogen",
|
|
371
427
|
"family": "hydrogen",
|
|
372
428
|
"generation": "4",
|
|
429
|
+
"aliases": [
|
|
430
|
+
"gemini-4-hydrogen-tiered-high",
|
|
431
|
+
"gemini-4-hydrogen-tiered-medium",
|
|
432
|
+
"gemini-4-hydrogen-tiered-low"
|
|
433
|
+
],
|
|
373
434
|
"contextCeiling": 1048576,
|
|
374
435
|
"operationalSoftCeiling": 200000,
|
|
375
436
|
"ratesPer1M": {
|
|
376
|
-
"input":
|
|
377
|
-
"output":
|
|
378
|
-
"write5m":
|
|
379
|
-
"write1h":
|
|
380
|
-
"read": 0.
|
|
437
|
+
"input": 1.5,
|
|
438
|
+
"output": 7.5,
|
|
439
|
+
"write5m": 1.5,
|
|
440
|
+
"write1h": 1.5,
|
|
441
|
+
"read": 0.075
|
|
381
442
|
},
|
|
382
443
|
"multipliers": {
|
|
383
444
|
"write5m": 1,
|
|
@@ -385,7 +446,7 @@
|
|
|
385
446
|
"read": 0.05
|
|
386
447
|
},
|
|
387
448
|
"source": "config/modelCatalog.json",
|
|
388
|
-
"dateRead": "2026-11-
|
|
449
|
+
"dateRead": "2026-11-27",
|
|
389
450
|
"pricingCliff": null
|
|
390
451
|
},
|
|
391
452
|
"gemini-3-8-flash": {
|
|
@@ -397,19 +458,47 @@
|
|
|
397
458
|
"contextCeiling": 1000000,
|
|
398
459
|
"operationalSoftCeiling": 200000,
|
|
399
460
|
"ratesPer1M": {
|
|
400
|
-
"input": 0.
|
|
401
|
-
"output":
|
|
402
|
-
"write5m": 0.
|
|
403
|
-
"write1h": 0.
|
|
404
|
-
"read": 0.
|
|
405
|
-
},
|
|
461
|
+
"input": 0.75,
|
|
462
|
+
"output": 3.75,
|
|
463
|
+
"write5m": 0.75,
|
|
464
|
+
"write1h": 0.75,
|
|
465
|
+
"read": 0.075
|
|
466
|
+
},
|
|
467
|
+
"rateSchedules": [
|
|
468
|
+
{
|
|
469
|
+
"id": "flash-38-pre-2027-01-01",
|
|
470
|
+
"window": "introductory",
|
|
471
|
+
"effectiveFrom": "1970-01-01T00:00:00Z",
|
|
472
|
+
"effectiveUntil": "2026-12-31T23:59:59Z",
|
|
473
|
+
"ratesPer1M": {
|
|
474
|
+
"input": 0.75,
|
|
475
|
+
"output": 3.75,
|
|
476
|
+
"write5m": 0.75,
|
|
477
|
+
"write1h": 0.75,
|
|
478
|
+
"read": 0.075
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
"id": "flash-38-from-2027-01-01",
|
|
483
|
+
"window": "post_introductory",
|
|
484
|
+
"effectiveFrom": "2027-01-01T00:00:00Z",
|
|
485
|
+
"effectiveUntil": null,
|
|
486
|
+
"ratesPer1M": {
|
|
487
|
+
"input": 1.5,
|
|
488
|
+
"output": 7.5,
|
|
489
|
+
"write5m": 1.5,
|
|
490
|
+
"write1h": 1.5,
|
|
491
|
+
"read": 0.15
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
],
|
|
406
495
|
"multipliers": {
|
|
407
496
|
"write5m": 1,
|
|
408
497
|
"write1h": 1,
|
|
409
498
|
"read": 0.1
|
|
410
499
|
},
|
|
411
500
|
"source": "config/modelCatalog.json",
|
|
412
|
-
"dateRead": "2026-11-
|
|
501
|
+
"dateRead": "2026-11-27",
|
|
413
502
|
"pricingCliff": null
|
|
414
503
|
},
|
|
415
504
|
"claude-opus-5": {
|
|
@@ -432,7 +521,7 @@
|
|
|
432
521
|
"write1h": 2,
|
|
433
522
|
"read": 0.1
|
|
434
523
|
},
|
|
435
|
-
"source": "
|
|
524
|
+
"source": "OpenRouter /api/v1/models",
|
|
436
525
|
"dateRead": "2026-11-15",
|
|
437
526
|
"pricingCliff": null
|
|
438
527
|
},
|
|
@@ -456,7 +545,7 @@
|
|
|
456
545
|
"write1h": 2,
|
|
457
546
|
"read": 0.1
|
|
458
547
|
},
|
|
459
|
-
"source": "
|
|
548
|
+
"source": "OpenRouter /api/v1/models",
|
|
460
549
|
"dateRead": "2026-11-15",
|
|
461
550
|
"pricingCliff": null
|
|
462
551
|
},
|
|
@@ -480,7 +569,7 @@
|
|
|
480
569
|
"write1h": 2,
|
|
481
570
|
"read": 0.1
|
|
482
571
|
},
|
|
483
|
-
"source": "
|
|
572
|
+
"source": "OpenRouter /api/v1/models",
|
|
484
573
|
"dateRead": "2026-11-15",
|
|
485
574
|
"pricingCliff": {
|
|
486
575
|
"thresholdTokens": 200000,
|
|
@@ -517,7 +606,7 @@
|
|
|
517
606
|
"write1h": 2,
|
|
518
607
|
"read": 0.1
|
|
519
608
|
},
|
|
520
|
-
"source": "
|
|
609
|
+
"source": "OpenRouter /api/v1/models",
|
|
521
610
|
"dateRead": "2026-11-15",
|
|
522
611
|
"pricingCliff": {
|
|
523
612
|
"thresholdTokens": 200000,
|
|
@@ -554,9 +643,22 @@
|
|
|
554
643
|
"write1h": 2,
|
|
555
644
|
"read": 0.1
|
|
556
645
|
},
|
|
557
|
-
"source": "
|
|
646
|
+
"source": "OpenRouter /api/v1/models",
|
|
558
647
|
"dateRead": "2026-11-15",
|
|
559
|
-
"pricingCliff":
|
|
648
|
+
"pricingCliff": {
|
|
649
|
+
"thresholdTokens": 200000,
|
|
650
|
+
"preCliffWarningTokens": 180000,
|
|
651
|
+
"multiplier": 2,
|
|
652
|
+
"cachedReadMultiplier": 2,
|
|
653
|
+
"outputMultiplier": 1.5,
|
|
654
|
+
"ratesPer1MAboveCliff": {
|
|
655
|
+
"input": 10,
|
|
656
|
+
"output": 37.5,
|
|
657
|
+
"write5m": 12.5,
|
|
658
|
+
"write1h": 20,
|
|
659
|
+
"read": 1
|
|
660
|
+
}
|
|
661
|
+
}
|
|
560
662
|
},
|
|
561
663
|
"claude-opus-4-5": {
|
|
562
664
|
"id": "claude-opus-4-5",
|
|
@@ -578,7 +680,7 @@
|
|
|
578
680
|
"write1h": 2,
|
|
579
681
|
"read": 0.1
|
|
580
682
|
},
|
|
581
|
-
"source": "
|
|
683
|
+
"source": "OpenRouter /api/v1/models",
|
|
582
684
|
"dateRead": "2026-11-15",
|
|
583
685
|
"pricingCliff": null
|
|
584
686
|
},
|
|
@@ -602,7 +704,7 @@
|
|
|
602
704
|
"write1h": 2,
|
|
603
705
|
"read": 0.1
|
|
604
706
|
},
|
|
605
|
-
"source": "
|
|
707
|
+
"source": "OpenRouter /api/v1/models",
|
|
606
708
|
"dateRead": "2026-11-15",
|
|
607
709
|
"pricingCliff": null
|
|
608
710
|
},
|
|
@@ -650,9 +752,22 @@
|
|
|
650
752
|
"write1h": 2,
|
|
651
753
|
"read": 0.1
|
|
652
754
|
},
|
|
653
|
-
"source": "
|
|
755
|
+
"source": "OpenRouter /api/v1/models",
|
|
654
756
|
"dateRead": "2026-11-15",
|
|
655
|
-
"pricingCliff":
|
|
757
|
+
"pricingCliff": {
|
|
758
|
+
"thresholdTokens": 200000,
|
|
759
|
+
"preCliffWarningTokens": 180000,
|
|
760
|
+
"multiplier": 2,
|
|
761
|
+
"cachedReadMultiplier": 2,
|
|
762
|
+
"outputMultiplier": 1.5,
|
|
763
|
+
"ratesPer1MAboveCliff": {
|
|
764
|
+
"input": 6,
|
|
765
|
+
"output": 22.5,
|
|
766
|
+
"write5m": 7.5,
|
|
767
|
+
"write1h": 12,
|
|
768
|
+
"read": 0.6
|
|
769
|
+
}
|
|
770
|
+
}
|
|
656
771
|
},
|
|
657
772
|
"claude-sonnet-4-5": {
|
|
658
773
|
"id": "claude-sonnet-4-5",
|
|
@@ -674,7 +789,7 @@
|
|
|
674
789
|
"write1h": 2,
|
|
675
790
|
"read": 0.1
|
|
676
791
|
},
|
|
677
|
-
"source": "
|
|
792
|
+
"source": "OpenRouter /api/v1/models",
|
|
678
793
|
"dateRead": "2026-11-15",
|
|
679
794
|
"pricingCliff": null
|
|
680
795
|
},
|
|
@@ -722,7 +837,7 @@
|
|
|
722
837
|
"write1h": 2,
|
|
723
838
|
"read": 0.1
|
|
724
839
|
},
|
|
725
|
-
"source": "
|
|
840
|
+
"source": "OpenRouter /api/v1/models",
|
|
726
841
|
"dateRead": "2026-11-15",
|
|
727
842
|
"pricingCliff": null
|
|
728
843
|
},
|
|
@@ -869,6 +984,34 @@
|
|
|
869
984
|
"source": "Claude Code 2.1.325 bakedCatalog (tier_8_40_cache_read_0_20; OpenRouter price unverified)",
|
|
870
985
|
"dateRead": "2026-11-15",
|
|
871
986
|
"pricingCliff": null
|
|
987
|
+
},
|
|
988
|
+
"gpt-6-1-sol": {
|
|
989
|
+
"id": "gpt-6-1-sol",
|
|
990
|
+
"label": "GPT-6.1 Sol",
|
|
991
|
+
"shortLabel": "GPT-6.1 Sol",
|
|
992
|
+
"family": "openai-gpt6",
|
|
993
|
+
"generation": "6.1",
|
|
994
|
+
"aliases": [
|
|
995
|
+
"gpt-6.1-sol",
|
|
996
|
+
"openai/gpt-6.1-sol"
|
|
997
|
+
],
|
|
998
|
+
"contextCeiling": 1048576,
|
|
999
|
+
"operationalSoftCeiling": 200000,
|
|
1000
|
+
"ratesPer1M": {
|
|
1001
|
+
"input": 3,
|
|
1002
|
+
"output": 15,
|
|
1003
|
+
"write5m": 3.75,
|
|
1004
|
+
"write1h": 3.75,
|
|
1005
|
+
"read": 0.15
|
|
1006
|
+
},
|
|
1007
|
+
"multipliers": {
|
|
1008
|
+
"write5m": 1.25,
|
|
1009
|
+
"write1h": 1.25,
|
|
1010
|
+
"read": 0.05
|
|
1011
|
+
},
|
|
1012
|
+
"source": "config/modelCatalog.json",
|
|
1013
|
+
"dateRead": "2026-11-27",
|
|
1014
|
+
"pricingCliff": null
|
|
872
1015
|
}
|
|
873
1016
|
}
|
|
874
1017
|
}
|
package/src/config/loader.mjs
CHANGED
|
@@ -4,18 +4,23 @@ import { getHomeDir } from './paths.mjs';
|
|
|
4
4
|
|
|
5
5
|
const CATALOG_URL = new URL('./catalog.json', import.meta.url);
|
|
6
6
|
let cachedBaseCatalog = null;
|
|
7
|
+
const customCeilingsCache = new Map();
|
|
8
|
+
const CUSTOM_CEILINGS_TTL_MS = 500;
|
|
7
9
|
|
|
8
10
|
export const UNKNOWN_MODEL_ID = 'unknown';
|
|
9
11
|
|
|
10
12
|
export function loadModelCatalog(options = {}) {
|
|
11
13
|
if (!cachedBaseCatalog) {
|
|
12
14
|
const raw = fs.readFileSync(CATALOG_URL, 'utf8');
|
|
13
|
-
cachedBaseCatalog = JSON.parse(raw);
|
|
15
|
+
cachedBaseCatalog = Object.freeze(JSON.parse(raw));
|
|
14
16
|
}
|
|
15
|
-
const cloned = JSON.parse(JSON.stringify(cachedBaseCatalog));
|
|
16
17
|
const customCeilings = options.customCeilings !== undefined
|
|
17
18
|
? options.customCeilings
|
|
18
19
|
: loadCustomCeilings(options);
|
|
20
|
+
if (!customCeilings || typeof customCeilings !== 'object') {
|
|
21
|
+
return cachedBaseCatalog;
|
|
22
|
+
}
|
|
23
|
+
const cloned = JSON.parse(JSON.stringify(cachedBaseCatalog));
|
|
19
24
|
return applyCeilingOverrides(cloned, customCeilings);
|
|
20
25
|
}
|
|
21
26
|
|
|
@@ -75,6 +80,7 @@ function canonicalizeModelToken(rawModelId = '') {
|
|
|
75
80
|
.replace(/\./g, '-')
|
|
76
81
|
.replace(/-v\d+(?::\d+)?$/i, '')
|
|
77
82
|
.replace(/[@-]\d{8}$/i, '')
|
|
83
|
+
.replace(/-tiered-(?:xhigh|extra-high|high|medium|med|low)$/i, '')
|
|
78
84
|
.replace(/-(?:thinking|fast|latest|xhigh|extra-high|high|medium|med|low)$/i, '');
|
|
79
85
|
|
|
80
86
|
const altOrder = s.match(/^claude-([4-9]\d*-\d+)-(opus|sonnet|haiku|fable|mythos)$/);
|
|
@@ -101,35 +107,49 @@ export function loadCustomCeilings(options = {}) {
|
|
|
101
107
|
return options.customCeilings;
|
|
102
108
|
}
|
|
103
109
|
|
|
110
|
+
const cwd = options.cwd || process.cwd();
|
|
111
|
+
const homeDir = options.homeDir || getHomeDir();
|
|
112
|
+
const explicitPath = typeof options.customCeilingsPath === 'string' ? options.customCeilingsPath.trim() : '';
|
|
113
|
+
const cacheKey = `${cwd}|${homeDir}|${explicitPath}`;
|
|
114
|
+
const nowMs = Date.now();
|
|
115
|
+
const cached = customCeilingsCache.get(cacheKey);
|
|
116
|
+
if (cached && nowMs - cached.ts < CUSTOM_CEILINGS_TTL_MS) {
|
|
117
|
+
return cached.value;
|
|
118
|
+
}
|
|
119
|
+
|
|
104
120
|
const candidatePaths = [];
|
|
105
|
-
if (
|
|
106
|
-
candidatePaths.push(
|
|
121
|
+
if (explicitPath) {
|
|
122
|
+
candidatePaths.push(explicitPath);
|
|
107
123
|
}
|
|
108
124
|
|
|
109
|
-
const cwd = options.cwd || process.cwd();
|
|
110
125
|
if (cwd && cwd !== '.') {
|
|
111
126
|
candidatePaths.push(path.join(cwd, '.claude', 'burnoff', 'customCeilings.json'));
|
|
112
127
|
candidatePaths.push(path.join(cwd, 'customCeilings.json'));
|
|
113
128
|
candidatePaths.push(path.join(cwd, '.claude', 'customCeilings.json'));
|
|
114
129
|
}
|
|
115
130
|
|
|
116
|
-
const homeDir = options.homeDir || getHomeDir();
|
|
117
131
|
if (homeDir) {
|
|
118
132
|
candidatePaths.push(path.join(homeDir, '.burnoff', 'customCeilings.json'));
|
|
119
133
|
candidatePaths.push(path.join(homeDir, '.claude', 'customCeilings.json'));
|
|
120
134
|
}
|
|
121
135
|
|
|
136
|
+
let resolved = null;
|
|
122
137
|
for (const candidate of candidatePaths) {
|
|
123
138
|
try {
|
|
124
139
|
if (fs.existsSync(candidate)) {
|
|
125
140
|
const parsed = JSON.parse(fs.readFileSync(candidate, 'utf8'));
|
|
126
|
-
if (parsed && typeof parsed === 'object')
|
|
141
|
+
if (parsed && typeof parsed === 'object') {
|
|
142
|
+
resolved = parsed;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
127
145
|
}
|
|
128
146
|
} catch {
|
|
129
147
|
// ignore: invalid customCeilings override falls back cleanly
|
|
130
148
|
}
|
|
131
149
|
}
|
|
132
|
-
|
|
150
|
+
if (customCeilingsCache.size > 64) customCeilingsCache.clear();
|
|
151
|
+
customCeilingsCache.set(cacheKey, { ts: nowMs, value: resolved });
|
|
152
|
+
return resolved;
|
|
133
153
|
}
|
|
134
154
|
|
|
135
155
|
export function isKnownCatalogModel(rawModelId = '', options = {}) {
|
|
@@ -444,6 +464,41 @@ export function computeTotalPromptTokens(usage = {}) {
|
|
|
444
464
|
return Math.max(computedPromptTokens, explicitSingleTurnTotal);
|
|
445
465
|
}
|
|
446
466
|
|
|
467
|
+
function parseScheduleTimestampMs(rawTs) {
|
|
468
|
+
if (typeof rawTs === 'number' && Number.isFinite(rawTs)) {
|
|
469
|
+
return rawTs > 0 && rawTs < 1e12 ? rawTs * 1000 : rawTs;
|
|
470
|
+
}
|
|
471
|
+
if (rawTs instanceof Date) {
|
|
472
|
+
const ms = rawTs.getTime();
|
|
473
|
+
return Number.isFinite(ms) ? ms : Date.now();
|
|
474
|
+
}
|
|
475
|
+
if (typeof rawTs === 'string' && rawTs.trim()) {
|
|
476
|
+
const parsed = Date.parse(rawTs.trim());
|
|
477
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
478
|
+
}
|
|
479
|
+
return Date.now();
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function isWithinRateSchedule(tsMs, sched) {
|
|
483
|
+
if (!sched || typeof sched !== 'object') return false;
|
|
484
|
+
if (sched.effectiveFrom) {
|
|
485
|
+
const fromMs = Date.parse(sched.effectiveFrom);
|
|
486
|
+
if (Number.isFinite(fromMs) && tsMs < fromMs) return false;
|
|
487
|
+
}
|
|
488
|
+
if (sched.effectiveUntil) {
|
|
489
|
+
const untilStr = String(sched.effectiveUntil).trim();
|
|
490
|
+
const untilMs = Date.parse(untilStr);
|
|
491
|
+
if (Number.isFinite(untilMs)) {
|
|
492
|
+
if (untilStr.endsWith('00:00:00Z')) {
|
|
493
|
+
if (tsMs >= untilMs) return false;
|
|
494
|
+
} else if (tsMs > untilMs + 999) {
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
|
|
447
502
|
export function resolveEffectiveRates(modelId = 'claude-sonnet-5-5', totalPromptTokens = 0, options = {}) {
|
|
448
503
|
const spec = getModelSpec(modelId, options);
|
|
449
504
|
const promptTokens = Math.max(0, Number(totalPromptTokens || 0));
|
|
@@ -453,6 +508,9 @@ export function resolveEffectiveRates(modelId = 'claude-sonnet-5-5', totalPrompt
|
|
|
453
508
|
modelId: UNKNOWN_MODEL_ID,
|
|
454
509
|
rawModelId: spec.rawModelId || String(modelId || '').trim(),
|
|
455
510
|
unknownModel: true,
|
|
511
|
+
unmappedModel: true,
|
|
512
|
+
unmapped_model: true,
|
|
513
|
+
cachedReadWeight: 0.05,
|
|
456
514
|
label: spec.label,
|
|
457
515
|
shortLabel: spec.shortLabel || 'Unknown Model',
|
|
458
516
|
family: 'unknown',
|
|
@@ -470,10 +528,26 @@ export function resolveEffectiveRates(modelId = 'claude-sonnet-5-5', totalPrompt
|
|
|
470
528
|
preCliffWarningTriggered: false,
|
|
471
529
|
cliffThresholdTokens: null,
|
|
472
530
|
cliffMultiplier: 1.0,
|
|
531
|
+
outputIncludesThinking: true,
|
|
473
532
|
advisory: spec.advisory || formatUnknownModelAdvisory(modelId)
|
|
474
533
|
};
|
|
475
534
|
}
|
|
476
535
|
|
|
536
|
+
let baseRates = spec.ratesPer1M;
|
|
537
|
+
let scheduleWindow = 'standard';
|
|
538
|
+
if (Array.isArray(spec.rateSchedules) && spec.rateSchedules.length > 0) {
|
|
539
|
+
const tsMs = parseScheduleTimestampMs(
|
|
540
|
+
options.eventTimestampUtc ?? options.timestampMs ?? options.timestamp ?? null
|
|
541
|
+
);
|
|
542
|
+
const matched =
|
|
543
|
+
spec.rateSchedules.find((s) => isWithinRateSchedule(tsMs, s)) ||
|
|
544
|
+
spec.rateSchedules[spec.rateSchedules.length - 1];
|
|
545
|
+
if (matched?.ratesPer1M) {
|
|
546
|
+
baseRates = matched.ratesPer1M;
|
|
547
|
+
scheduleWindow = matched.window || 'standard';
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
477
551
|
const cliff = spec.pricingCliff || null;
|
|
478
552
|
const cliffTriggered = Boolean(cliff && promptTokens > cliff.thresholdTokens);
|
|
479
553
|
const preCliffWarningTriggered = Boolean(
|
|
@@ -482,14 +556,17 @@ export function resolveEffectiveRates(modelId = 'claude-sonnet-5-5', totalPrompt
|
|
|
482
556
|
|
|
483
557
|
const activeRates = cliffTriggered && cliff.ratesPer1MAboveCliff
|
|
484
558
|
? cliff.ratesPer1MAboveCliff
|
|
485
|
-
:
|
|
559
|
+
: baseRates;
|
|
486
560
|
|
|
487
561
|
return {
|
|
488
562
|
modelId: spec.id,
|
|
489
563
|
unknownModel: false,
|
|
564
|
+
unmappedModel: false,
|
|
565
|
+
unmapped_model: false,
|
|
490
566
|
label: spec.label,
|
|
491
567
|
shortLabel: spec.shortLabel || spec.label,
|
|
492
568
|
family: spec.family,
|
|
569
|
+
pricingWindow: cliffTriggered ? 'above_cliff' : scheduleWindow,
|
|
493
570
|
contextCeiling: spec.contextCeiling,
|
|
494
571
|
operationalSoftCeiling: spec.operationalSoftCeiling,
|
|
495
572
|
inputPer1M: activeRates.input,
|
|
@@ -505,7 +582,8 @@ export function resolveEffectiveRates(modelId = 'claude-sonnet-5-5', totalPrompt
|
|
|
505
582
|
cliffThresholdTokens: cliff ? cliff.thresholdTokens : null,
|
|
506
583
|
cliffMultiplier: cliffTriggered ? cliff.multiplier : 1.0,
|
|
507
584
|
cliffCachedReadMultiplier: cliffTriggered ? (cliff.cachedReadMultiplier ?? cliff.multiplier) : 1.0,
|
|
508
|
-
cliffOutputMultiplier: cliffTriggered ? (cliff.outputMultiplier ?? cliff.multiplier) : 1.0
|
|
585
|
+
cliffOutputMultiplier: cliffTriggered ? (cliff.outputMultiplier ?? cliff.multiplier) : 1.0,
|
|
586
|
+
outputIncludesThinking: spec.outputIncludesThinking !== false
|
|
509
587
|
};
|
|
510
588
|
}
|
|
511
589
|
|
|
@@ -522,6 +600,11 @@ export function calculateTurnCostUSD(usage = {}, options = {}) {
|
|
|
522
600
|
|
|
523
601
|
const rawModel = usage.model || usage.modelId || 'claude-sonnet-5-5';
|
|
524
602
|
const rates = resolveEffectiveRates(rawModel, totalPromptTokens, options);
|
|
603
|
+
const includesThinking =
|
|
604
|
+
usage.outputIncludesThinking !== undefined
|
|
605
|
+
? Boolean(usage.outputIncludesThinking)
|
|
606
|
+
: rates.outputIncludesThinking !== false;
|
|
607
|
+
const billedOutputTokens = includesThinking ? outputTokens : outputTokens + thinkingTokens;
|
|
525
608
|
|
|
526
609
|
if (rates.unknownModel) {
|
|
527
610
|
return {
|
|
@@ -539,7 +622,7 @@ export function calculateTurnCostUSD(usage = {}, options = {}) {
|
|
|
539
622
|
totalPrompt: totalPromptTokens,
|
|
540
623
|
output: outputTokens,
|
|
541
624
|
thinking: thinkingTokens,
|
|
542
|
-
totalOutput:
|
|
625
|
+
totalOutput: billedOutputTokens
|
|
543
626
|
},
|
|
544
627
|
costsUSD: {
|
|
545
628
|
uncachedInput: null,
|
|
@@ -562,7 +645,7 @@ export function calculateTurnCostUSD(usage = {}, options = {}) {
|
|
|
562
645
|
const write5mCostUSD = (write5mTokens / 1_000_000) * rates.write5mPer1M;
|
|
563
646
|
const write1hCostUSD = (write1hTokens / 1_000_000) * rates.write1hPer1M;
|
|
564
647
|
const readCostUSD = (cacheReadTokens / 1_000_000) * rates.readPer1M;
|
|
565
|
-
const outputCostUSD = (
|
|
648
|
+
const outputCostUSD = (billedOutputTokens / 1_000_000) * rates.outputPer1M;
|
|
566
649
|
|
|
567
650
|
const actualCacheSpendUSD = write5mCostUSD + write1hCostUSD + readCostUSD;
|
|
568
651
|
const uncachedCacheEquivalentUSD = ((totalCacheWriteTokens + cacheReadTokens) / 1_000_000) * rates.inputPer1M;
|
|
@@ -584,7 +667,7 @@ export function calculateTurnCostUSD(usage = {}, options = {}) {
|
|
|
584
667
|
totalPrompt: totalPromptTokens,
|
|
585
668
|
output: outputTokens,
|
|
586
669
|
thinking: thinkingTokens,
|
|
587
|
-
totalOutput:
|
|
670
|
+
totalOutput: billedOutputTokens
|
|
588
671
|
},
|
|
589
672
|
costsUSD: {
|
|
590
673
|
uncachedInput: Number(inputCostUSD.toFixed(6)),
|