1515"""
1616
1717import json
18- import sys
1918import os
19+ import sys
2020from datetime import date , timedelta
21- from pathlib import Path
2221
23- sys .path .insert (0 , str (Path (__file__ ).parent ))
2422from quota_store import QuotaStore
2523
2624WARN_CRITICAL = int (os .environ .get ("TOKEN_QUOTA_WARN_CRITICAL" , 95 ))
@@ -42,14 +40,7 @@ def main():
4240 pct_daily = (used_daily / effective_daily ) * 100 if effective_daily > 0 else 0
4341
4442 if used_daily >= effective_daily :
45- result = {
46- "decision" : "block" ,
47- "reason" : (
48- f"Daily token quota exceeded.\n "
49- f"Used: { used_daily :,} / { effective_daily :,} tokens ({ pct_daily :.1f} %)\n "
50- f"Quota resets at midnight. Edit TOKEN_QUOTA_DAILY to change the limit."
51- )
52- }
43+ result = {"decision" : "block" , "reason" : (f"Daily token quota exceeded.\n Used: { used_daily :,} / { effective_daily :,} tokens ({ pct_daily :.1f} %)\n Quota resets at midnight. Edit TOKEN_QUOTA_DAILY to change the limit." )}
5344 print (json .dumps (result ))
5445 sys .exit (0 )
5546
@@ -59,14 +50,7 @@ def main():
5950 effective_weekly = store .weekly_limit + snooze
6051 if used_weekly >= effective_weekly :
6152 pct = (used_weekly / effective_weekly ) * 100
62- result = {
63- "decision" : "block" ,
64- "reason" : (
65- f"Weekly token quota exceeded (rolling 7-day window).\n "
66- f"Used: { used_weekly :,} / { effective_weekly :,} tokens ({ pct :.1f} %)\n "
67- f"Edit TOKEN_QUOTA_WEEKLY to change the limit."
68- )
69- }
53+ result = {"decision" : "block" , "reason" : (f"Weekly token quota exceeded (rolling 7-day window).\n Used: { used_weekly :,} / { effective_weekly :,} tokens ({ pct :.1f} %)\n Edit TOKEN_QUOTA_WEEKLY to change the limit." )}
7054 print (json .dumps (result ))
7155 sys .exit (0 )
7256
@@ -76,14 +60,7 @@ def main():
7660 effective_monthly = store .monthly_limit + snooze
7761 if used_monthly >= effective_monthly :
7862 pct = (used_monthly / effective_monthly ) * 100
79- result = {
80- "decision" : "block" ,
81- "reason" : (
82- f"Monthly token quota exceeded.\n "
83- f"Used: { used_monthly :,} / { effective_monthly :,} tokens ({ pct :.1f} %)\n "
84- f"Quota resets on the 1st. Edit TOKEN_QUOTA_MONTHLY to change the limit."
85- )
86- }
63+ result = {"decision" : "block" , "reason" : (f"Monthly token quota exceeded.\n Used: { used_monthly :,} / { effective_monthly :,} tokens ({ pct :.1f} %)\n Quota resets on the 1st. Edit TOKEN_QUOTA_MONTHLY to change the limit." )}
8764 print (json .dumps (result ))
8865 sys .exit (0 )
8966
0 commit comments