| index 209efcb..9b30545 100644 | ||
| --- a/README.md | ||
| +++ b/README.md | ||
| @@ -8,7 +8,7 @@ account list (`antigravity_accounts.json`) and active selection | ||
| 8 | 8 | click. |
| 9 | 9 | |
| 10 | 10 | * `--meta` -> `{"name":"google quota","desc":"Account quotas"}` |
| 11 | -* `--version` -> `plugin_google_quota 1.0.0` | |
| 11 | +* `--version` -> `plugin_google_quota 1.0.1` | |
| 12 | 12 | * Catalog slug `google-quota`, category `devtools` |
| 13 | 13 | * Public source: <https://plugingit.scorpiox.net/scorpiox-bot-plugin-google-quota.git> |
| 14 | 14 | * Prebuilt binaries: <https://dist.scorpiox.net/bot-plugins/google-quota/> |
| @@ -59,7 +59,7 @@ extracted; token strings are never copied or emitted. | ||
| 59 | 59 | All actions accept `X-Bot-Password`, `Authorization: Bearer`, or `?pwd=`. |
| 60 | 60 | |
| 61 | 61 | * `GET ?action=status` — fast local read of configured accounts, `selected`, paths, and `cli_present` |
| 62 | -* `GET ?action=quota` (or `?format=json`) — queries all accounts concurrently and returns Gemini/Claude pool summaries, reset times, per-model buckets, `best_gemini`, and `best_claude` | |
| 62 | +* `GET ?action=quota` (or `?format=json`) — queries all accounts concurrently and returns Gemini/Claude pool summaries, reset times (`reset_time`, `reset_in_seconds`, `reset_in_hours`, `reset_remaining`), per-model buckets, `best_gemini`, and `best_claude` | |
| 63 | 63 | * `GET ?action=quota&account=<email>` — queries a single account |
| 64 | 64 | * `GET/POST ?action=switch&account=<email>` (or JSON body `{"account":"..."}`) — validates the email against `antigravity_accounts.json` and writes `selected_account.txt` |
| 65 | 65 |
| index 58d102f..49f1b9a 100644 | ||
| --- a/plugin.json | ||
| +++ b/plugin.json | ||
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | "slug": "google-quota", |
| 3 | 3 | "id": "plugin_google_quota", |
| 4 | 4 | "title": "Google Account Quotas", |
| 5 | + "version": "1.0.1", | |
| 5 | 6 | "summary": "Zero-dependency Google Antigravity multi-account quota monitor and active-account switcher for your node. Reads the local antigravity_accounts.json and selected_account.txt files, queries per-model quota pools through the node's scorpiox-google-quota CLI, and lets you switch the active account in one click. Holds no OAuth client secret and never prints, logs or returns any refresh or access token.", |
| 6 | 7 | "category": "devtools", |
| 7 | 8 | "license": "MIT", |
| index 97e4490..b1bbb8e 100644 | ||
| --- a/src/plugin_google_quota.c | ||
| +++ b/src/plugin_google_quota.c | ||
| @@ -51,11 +51,13 @@ | ||
| 51 | 51 | #include <ctype.h> |
| 52 | 52 | #include <errno.h> |
| 53 | 53 | #include <stdarg.h> |
| 54 | +#include <time.h> | |
| 54 | 55 | |
| 55 | 56 | #if defined(_WIN32) |
| 56 | 57 | # define WIN32_LEAN_AND_MEAN |
| 57 | 58 | # include <windows.h> |
| 58 | 59 | # include <direct.h> |
| 60 | +# include <fcntl.h> | |
| 59 | 61 | # include <io.h> |
| 60 | 62 | # define popen _popen |
| 61 | 63 | # define pclose _pclose |
| @@ -75,10 +77,9 @@ | ||
| 75 | 77 | |
| 76 | 78 | #define PLUGIN_SLUG "google-quota" |
| 77 | 79 | #define PLUGIN_ID "plugin_google_quota" |
| 78 | -#define PLUGIN_VER "1.0.0" | |
| 80 | +#define PLUGIN_VER "1.0.1" | |
| 79 | 81 | #define PLUGIN_NAME "google quota" |
| 80 | 82 | #define PLUGIN_DESC "Account quotas" |
| 81 | - | |
| 82 | 83 | #define DEFAULT_QUOTA_BIN "scorpiox-google-quota" |
| 83 | 84 | |
| 84 | 85 | #define PATH_SZ 1024 |
| @@ -885,7 +886,7 @@ static void pool_add(pool_summary_t *p, double pct, int exhausted, const char *r | ||
| 885 | 886 | if (!p->present || pct < p->pct) p->pct = pct; |
| 886 | 887 | p->present = 1; |
| 887 | 888 | if (exhausted || pct <= 0.0) p->exhausted = 1; |
| 888 | - if (!p->reset_time[0] && reset && reset[0]) | |
| 889 | + if (reset && reset[0] && (!p->reset_time[0] || strcmp(reset, p->reset_time) < 0)) | |
| 889 | 890 | snprintf(p->reset_time, sizeof(p->reset_time), "%s", reset); |
| 890 | 891 | p->count++; |
| 891 | 892 | } |
| @@ -1186,21 +1187,107 @@ static void emit_error(int code, const char *status, const char *err, const char | ||
| 1186 | 1187 | buf_free(&b); |
| 1187 | 1188 | } |
| 1188 | 1189 | |
| 1189 | -static void emit_pool_json(buf_t *b, const pool_summary_t *p) | |
| 1190 | +static long long days_from_civil(int y, unsigned m, unsigned d) | |
| 1191 | +{ | |
| 1192 | + y -= (m <= 2) ? 1 : 0; | |
| 1193 | + { | |
| 1194 | + long long era = (y >= 0 ? y : y - 399) / 400; | |
| 1195 | + unsigned yoe = (unsigned)(y - era * 400); | |
| 1196 | + unsigned doy = (153U * (m + (m > 2 ? (unsigned)-3 : 9U)) + 2U) / 5U + d - 1U; | |
| 1197 | + unsigned doe = yoe * 365U + yoe / 4U - yoe / 100U + doy; | |
| 1198 | + return era * 146097LL + (long long)doe - 719468LL; | |
| 1199 | + } | |
| 1200 | +} | |
| 1201 | + | |
| 1202 | +static int parse_iso_utc_epoch(const char *iso, long long *out_epoch) | |
| 1203 | +{ | |
| 1204 | + int y = 0, mo = 0, d = 0, hh = 0, mm = 0, ss = 0; | |
| 1205 | + const char *t; | |
| 1206 | + const char *tz; | |
| 1207 | + | |
| 1208 | + if (!iso || !*iso) return 0; | |
| 1209 | + if (sscanf(iso, "%d-%d-%dT%d:%d:%d", &y, &mo, &d, &hh, &mm, &ss) != 6) | |
| 1210 | + return 0; | |
| 1211 | + if (mo < 1 || mo > 12 || d < 1 || d > 31 || | |
| 1212 | + hh < 0 || hh > 23 || mm < 0 || mm > 59 || ss < 0 || ss > 60) | |
| 1213 | + return 0; | |
| 1214 | + t = strchr(iso, 'T'); | |
| 1215 | + if (!t) return 0; | |
| 1216 | + { | |
| 1217 | + long long days = days_from_civil(y, (unsigned)mo, (unsigned)d); | |
| 1218 | + long long epoch = days * 86400LL + (long long)hh * 3600LL + | |
| 1219 | + (long long)mm * 60LL + (long long)ss; | |
| 1220 | + tz = strpbrk(t, "Z+-"); | |
| 1221 | + if (tz && (*tz == '+' || *tz == '-')) { | |
| 1222 | + int oh = 0, om = 0; | |
| 1223 | + if (sscanf(tz + 1, "%2d:%2d", &oh, &om) >= 1) { | |
| 1224 | + long long off = (long long)oh * 3600LL + (long long)om * 60LL; | |
| 1225 | + epoch += (*tz == '+') ? -off : off; | |
| 1226 | + } | |
| 1227 | + } | |
| 1228 | + *out_epoch = epoch; | |
| 1229 | + return 1; | |
| 1230 | + } | |
| 1231 | +} | |
| 1232 | + | |
| 1233 | +static void compute_reset_fields(const char *iso, long long now_epoch, | |
| 1234 | + long long *secs_out, double *hrs_out, | |
| 1235 | + char *rem_out, size_t rem_sz) | |
| 1236 | +{ | |
| 1237 | + long long target = 0; | |
| 1238 | + long long diff; | |
| 1239 | + | |
| 1240 | + if (!iso || !iso[0] || !parse_iso_utc_epoch(iso, &target)) { | |
| 1241 | + *secs_out = -1; | |
| 1242 | + *hrs_out = -1.0; | |
| 1243 | + if (rem_sz) rem_out[0] = '\0'; | |
| 1244 | + return; | |
| 1245 | + } | |
| 1246 | + diff = target - now_epoch; | |
| 1247 | + if (diff <= 0) { | |
| 1248 | + *secs_out = 0; | |
| 1249 | + *hrs_out = 0.0; | |
| 1250 | + snprintf(rem_out, rem_sz, "due"); | |
| 1251 | + return; | |
| 1252 | + } | |
| 1253 | + *secs_out = diff; | |
| 1254 | + *hrs_out = (double)diff / 3600.0; | |
| 1255 | + { | |
| 1256 | + long long hrs = diff / 3600LL; | |
| 1257 | + long long mins = (diff % 3600LL) / 60LL; | |
| 1258 | + if (hrs > 0) | |
| 1259 | + snprintf(rem_out, rem_sz, "%lldh %02lldm", hrs, mins); | |
| 1260 | + else | |
| 1261 | + snprintf(rem_out, rem_sz, "%lldm", mins > 0 ? mins : 1LL); | |
| 1262 | + } | |
| 1263 | +} | |
| 1264 | + | |
| 1265 | +static void emit_pool_json(buf_t *b, const pool_summary_t *p, long long now_epoch) | |
| 1190 | 1266 | { |
| 1267 | + long long rsecs = -1; | |
| 1268 | + double rhrs = -1.0; | |
| 1269 | + char rrem[32] = {0}; | |
| 1270 | + | |
| 1191 | 1271 | if (!p->present) { |
| 1192 | - buf_adds(b, "{\"pct\":-1,\"exhausted\":false,\"reset_time\":\"\",\"count\":0}"); | |
| 1272 | + buf_adds(b, "{\"pct\":-1,\"exhausted\":false,\"reset_time\":\"\"," | |
| 1273 | + "\"reset_in_seconds\":-1,\"reset_in_hours\":-1.00," | |
| 1274 | + "\"reset_remaining\":\"\",\"count\":0}"); | |
| 1193 | 1275 | return; |
| 1194 | 1276 | } |
| 1277 | + compute_reset_fields(p->reset_time, now_epoch, &rsecs, &rhrs, rrem, sizeof(rrem)); | |
| 1195 | 1278 | buf_addf(b, "{\"pct\":%.2f,\"exhausted\":%s,\"reset_time\":", |
| 1196 | 1279 | p->pct, p->exhausted ? "true" : "false"); |
| 1197 | 1280 | buf_json(b, p->reset_time); |
| 1281 | + buf_addf(b, ",\"reset_in_seconds\":%lld,\"reset_in_hours\":%.2f,\"reset_remaining\":", | |
| 1282 | + rsecs, rhrs); | |
| 1283 | + buf_json(b, rrem); | |
| 1198 | 1284 | buf_addf(b, ",\"count\":%d}", p->count); |
| 1199 | 1285 | } |
| 1200 | 1286 | |
| 1201 | 1287 | static void emit_acct_quota_json(buf_t *b, const acct_entry_t *a, const acct_quota_t *q) |
| 1202 | 1288 | { |
| 1203 | 1289 | int i; |
| 1290 | + long long now_epoch = (long long)time(NULL); | |
| 1204 | 1291 | |
| 1205 | 1292 | buf_adds(b, "{\"email\":"); |
| 1206 | 1293 | buf_json(b, a->email); |
| @@ -1223,12 +1310,16 @@ static void emit_acct_quota_json(buf_t *b, const acct_entry_t *a, const acct_quo | ||
| 1223 | 1310 | buf_adds(b, ",\"project\":"); |
| 1224 | 1311 | buf_json(b, q->project); |
| 1225 | 1312 | buf_adds(b, ",\"gemini\":"); |
| 1226 | - emit_pool_json(b, &q->gemini); | |
| 1313 | + emit_pool_json(b, &q->gemini, now_epoch); | |
| 1227 | 1314 | buf_adds(b, ",\"claude\":"); |
| 1228 | - emit_pool_json(b, &q->claude); | |
| 1315 | + emit_pool_json(b, &q->claude, now_epoch); | |
| 1229 | 1316 | buf_adds(b, ",\"models\":["); |
| 1230 | 1317 | for (i = 0; i < q->model_count; i++) { |
| 1231 | 1318 | const model_quota_t *m = &q->models[i]; |
| 1319 | + long long rsecs = -1; | |
| 1320 | + double rhrs = -1.0; | |
| 1321 | + char rrem[32] = {0}; | |
| 1322 | + compute_reset_fields(m->reset_time, now_epoch, &rsecs, &rhrs, rrem, sizeof(rrem)); | |
| 1232 | 1323 | if (i > 0) buf_addc(b, ','); |
| 1233 | 1324 | buf_adds(b, "{\"id\":"); |
| 1234 | 1325 | buf_json(b, m->id); |
| @@ -1237,6 +1328,9 @@ static void emit_acct_quota_json(buf_t *b, const acct_entry_t *a, const acct_quo | ||
| 1237 | 1328 | buf_addf(b, ",\"pct\":%.2f,\"exhausted\":%s,\"reset_time\":", |
| 1238 | 1329 | m->pct, m->exhausted ? "true" : "false"); |
| 1239 | 1330 | buf_json(b, m->reset_time); |
| 1331 | + buf_addf(b, ",\"reset_in_seconds\":%lld,\"reset_in_hours\":%.2f,\"reset_remaining\":", | |
| 1332 | + rsecs, rhrs); | |
| 1333 | + buf_json(b, rrem); | |
| 1240 | 1334 | buf_addc(b, '}'); |
| 1241 | 1335 | } |
| 1242 | 1336 | buf_adds(b, "]}"); |
| @@ -1495,6 +1589,10 @@ int main(int argc, char **argv) | ||
| 1495 | 1589 | const char *qs; |
| 1496 | 1590 | char action[64] = {0}; |
| 1497 | 1591 | |
| 1592 | +#if defined(_WIN32) | |
| 1593 | + _setmode(_fileno(stdout), _O_BINARY); | |
| 1594 | +#endif | |
| 1595 | + | |
| 1498 | 1596 | /* 1. Discovery metadata. Must stay unauthenticated. */ |
| 1499 | 1597 | if ((argc > 1 && strcmp(argv[1], "--meta") == 0) || getenv("SX_PLUGIN_META")) { |
| 1500 | 1598 | puts("{\"name\":\"" PLUGIN_NAME "\",\"desc\":\"" PLUGIN_DESC "\"}"); |
| index 9d356fa..f291e1b 100644 | ||
| --- a/src/ui.html | ||
| +++ b/src/ui.html | ||
| @@ -75,12 +75,13 @@ body{background:var(--bg);color:var(--text);font-family:var(--font);font-size:14 | ||
| 75 | 75 | grid-template-columns:repeat(2,minmax(0,1fr));gap:4px 14px} |
| 76 | 76 | .models.show{display:grid} |
| 77 | 77 | .mrow{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:11.5px;padding:2px 0} |
| 78 | -.mrow .mid{font-family:var(--mono);color:var(--text-2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap} | |
| 78 | +.mrow .mid{font-family:var(--mono);color:var(--text-2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0} | |
| 79 | +.mrow .mright{display:inline-flex;align-items:center;gap:8px;flex:0 0 auto} | |
| 80 | +.mrow .mrst{font-family:var(--mono);font-size:11px;color:var(--text-2);white-space:nowrap} | |
| 79 | 81 | .mrow .mpct{font-family:var(--mono);font-weight:650;flex:0 0 auto} |
| 80 | 82 | .mrow .mpct.ok{color:var(--green)} |
| 81 | 83 | .mrow .mpct.warn{color:var(--orange)} |
| 82 | 84 | .mrow .mpct.bad{color:var(--red)} |
| 83 | -.err-msg{font-size:12px;color:var(--red);padding:4px 0} | |
| 84 | 85 | .empty{padding:18px 16px;text-align:center;color:var(--text-2);font-size:13px} |
| 85 | 86 | .kv{display:grid;grid-template-columns:120px minmax(0,1fr);gap:5px 12px;font-size:12px} |
| 86 | 87 | .kv .k{color:var(--text-2)} |
| @@ -208,18 +209,51 @@ function fmtPct(pool){ | ||
| 208 | 209 | if(pool.pct<0)return 'N/A'; |
| 209 | 210 | return pool.pct.toFixed(1)+'%'; |
| 210 | 211 | } |
| 212 | +function pad2(n){return n<10?('0'+n):String(n);} | |
| 213 | +function fmtClock(ms){ | |
| 214 | + var d=new Date(ms),now=new Date(); | |
| 215 | + var hm=pad2(d.getHours())+':'+pad2(d.getMinutes()); | |
| 216 | + if(d.getFullYear()===now.getFullYear()&&d.getMonth()===now.getMonth()&&d.getDate()===now.getDate())return hm; | |
| 217 | + var mon=d.toLocaleString(undefined,{month:'short'}); | |
| 218 | + return mon+' '+d.getDate()+' '+hm; | |
| 219 | +} | |
| 220 | +function fmtResetShort(iso){ | |
| 221 | + if(!iso)return '-'; | |
| 222 | + var t=Date.parse(iso); | |
| 223 | + if(isNaN(t))return iso; | |
| 224 | + var diff=Math.floor((t-Date.now())/1000); | |
| 225 | + if(diff<=0)return 'due'; | |
| 226 | + var totalH=Math.floor(diff/3600); | |
| 227 | + var m=Math.floor((diff%3600)/60); | |
| 228 | + if(totalH>0)return totalH+'h '+pad2(m)+'m'; | |
| 229 | + return Math.max(1,m)+'m'; | |
| 230 | +} | |
| 211 | 231 | function fmtReset(iso){ |
| 212 | 232 | if(!iso)return 'Reset: -'; |
| 213 | 233 | var t=Date.parse(iso); |
| 214 | 234 | if(isNaN(t))return 'Reset: '+iso; |
| 215 | 235 | var diff=Math.floor((t-Date.now())/1000); |
| 216 | - if(diff<=0)return 'Resets soon'; | |
| 236 | + var clk=fmtClock(t); | |
| 237 | + if(diff<=0)return 'Resets soon · '+clk; | |
| 238 | + var totalH=Math.floor(diff/3600); | |
| 217 | 239 | var d=Math.floor(diff/86400); |
| 218 | 240 | var h=Math.floor((diff%86400)/3600); |
| 219 | 241 | var m=Math.floor((diff%3600)/60); |
| 220 | - if(d>0)return 'Resets in '+d+'d '+h+'h'; | |
| 221 | - if(h>0)return 'Resets in '+h+'h '+m+'m'; | |
| 222 | - return 'Resets in '+Math.max(1,m)+'m'; | |
| 242 | + if(totalH>=24)return 'Resets in '+totalH+'h '+pad2(m)+'m ('+d+'d '+h+'h) · '+clk; | |
| 243 | + if(totalH>0)return 'Resets in '+totalH+'h '+pad2(m)+'m · '+clk; | |
| 244 | + return 'Resets in '+Math.max(1,m)+'m · '+clk; | |
| 245 | +} | |
| 246 | +function refreshResetLabels(){ | |
| 247 | + var els=document.querySelectorAll('[data-reset]'); | |
| 248 | + for(var i=0;i<els.length;i++){ | |
| 249 | + var node=els[i]; | |
| 250 | + var iso=node.getAttribute('data-reset'); | |
| 251 | + if(!iso)continue; | |
| 252 | + var mode=node.getAttribute('data-reset-mode')||'full'; | |
| 253 | + node.textContent=(mode==='short')?fmtResetShort(iso):fmtReset(iso); | |
| 254 | + var t=Date.parse(iso); | |
| 255 | + if(!isNaN(t))node.title='Resets at '+fmtClock(t)+' ('+iso+')'; | |
| 256 | + } | |
| 223 | 257 | } |
| 224 | 258 | function el(tag,cls,txt){ |
| 225 | 259 | var n=document.createElement(tag); |
| @@ -229,18 +263,18 @@ function el(tag,cls,txt){ | ||
| 229 | 263 | } |
| 230 | 264 | |
| 231 | 265 | function computeBest(){ |
| 232 | - var bestG=null,bestGP=-1,bestC=null,bestCP=-1; | |
| 266 | + var bestG=null,bestGP=-1,bestGR='',bestC=null,bestCP=-1,bestCR=''; | |
| 233 | 267 | state.accounts.forEach(function(a){ |
| 234 | 268 | var qd=state.quotas[a.email]; |
| 235 | 269 | if(!qd||!qd.ok)return; |
| 236 | 270 | if(qd.gemini&&!qd.gemini.exhausted&&qd.gemini.pct>bestGP){ |
| 237 | - bestGP=qd.gemini.pct;bestG=a.email; | |
| 271 | + bestGP=qd.gemini.pct;bestG=a.email;bestGR=qd.gemini.reset_time||''; | |
| 238 | 272 | } |
| 239 | 273 | if(qd.claude&&!qd.claude.exhausted&&qd.claude.pct>bestCP){ |
| 240 | - bestCP=qd.claude.pct;bestC=a.email; | |
| 274 | + bestCP=qd.claude.pct;bestC=a.email;bestCR=qd.claude.reset_time||''; | |
| 241 | 275 | } |
| 242 | 276 | }); |
| 243 | - return {gemini:bestG,geminiPct:bestGP,claude:bestC,claudePct:bestCP}; | |
| 277 | + return {gemini:bestG,geminiPct:bestGP,geminiReset:bestGR,claude:bestC,claudePct:bestCP,claudeReset:bestCR}; | |
| 244 | 278 | } |
| 245 | 279 | |
| 246 | 280 | function renderPool(label,pool,loading){ |
| @@ -270,6 +304,12 @@ function renderPool(label,pool,loading){ | ||
| 270 | 304 | fill.className=cls; |
| 271 | 305 | fill.style.width=w.toFixed(1)+'%'; |
| 272 | 306 | rst.textContent=fmtReset(pool.reset_time); |
| 307 | + if(pool.reset_time){ | |
| 308 | + rst.setAttribute('data-reset',pool.reset_time); | |
| 309 | + rst.setAttribute('data-reset-mode','full'); | |
| 310 | + var rt=Date.parse(pool.reset_time); | |
| 311 | + if(!isNaN(rt))rst.title='Resets at '+fmtClock(rt)+' ('+pool.reset_time+')'; | |
| 312 | + } | |
| 273 | 313 | } |
| 274 | 314 | hd.appendChild(pctEl); |
| 275 | 315 | bar.appendChild(fill); |
| @@ -287,12 +327,11 @@ function render(){ | ||
| 287 | 327 | |
| 288 | 328 | $('kpiGemini').textContent=best.gemini?shortEmail(best.gemini):'-'; |
| 289 | 329 | $('kpiGemini').title=best.gemini||''; |
| 290 | - $('kpiGeminiMeta').textContent=best.gemini?(best.geminiPct.toFixed(1)+'% remaining'):(state.loading?'Checking...':'No quota data'); | |
| 330 | + $('kpiGeminiMeta').textContent=best.gemini?(best.geminiPct.toFixed(1)+'% remaining'+(best.geminiReset?(' · resets in '+fmtResetShort(best.geminiReset)):'')):(state.loading?'Checking...':'No quota data'); | |
| 291 | 331 | |
| 292 | 332 | $('kpiClaude').textContent=best.claude?shortEmail(best.claude):'-'; |
| 293 | 333 | $('kpiClaude').title=best.claude||''; |
| 294 | - $('kpiClaudeMeta').textContent=best.claude?(best.claudePct.toFixed(1)+'% remaining'):(state.loading?'Checking...':'No quota data'); | |
| 295 | - | |
| 334 | + $('kpiClaudeMeta').textContent=best.claude?(best.claudePct.toFixed(1)+'% remaining'+(best.claudeReset?(' · resets in '+fmtResetShort(best.claudeReset)):'')):(state.loading?'Checking...':'No quota data'); | |
| 296 | 335 | var wrap=$('accounts'); |
| 297 | 336 | wrap.innerHTML=''; |
| 298 | 337 | if(!state.accounts.length){ |
| @@ -336,8 +375,18 @@ function render(){ | ||
| 336 | 375 | qd.models.forEach(function(m){ |
| 337 | 376 | var row=el('div','mrow'); |
| 338 | 377 | row.appendChild(el('span','mid',m.id)); |
| 378 | + var right=el('span','mright'); | |
| 379 | + if(m.reset_time){ | |
| 380 | + var mr=el('span','mrst',fmtResetShort(m.reset_time)); | |
| 381 | + mr.setAttribute('data-reset',m.reset_time); | |
| 382 | + mr.setAttribute('data-reset-mode','short'); | |
| 383 | + var mt=Date.parse(m.reset_time); | |
| 384 | + if(!isNaN(mt))mr.title='Resets at '+fmtClock(mt)+' ('+m.reset_time+')'; | |
| 385 | + right.appendChild(mr); | |
| 386 | + } | |
| 339 | 387 | var cls=pctClass(m.pct,m.exhausted); |
| 340 | - row.appendChild(el('span','mpct '+cls,m.exhausted?'EXH':(m.pct.toFixed(1)+'%'))); | |
| 388 | + right.appendChild(el('span','mpct '+cls,m.exhausted?'EXH':(m.pct.toFixed(1)+'%'))); | |
| 389 | + row.appendChild(right); | |
| 341 | 390 | mgrid.appendChild(row); |
| 342 | 391 | }); |
| 343 | 392 | card.appendChild(mgrid); |
| @@ -346,7 +395,6 @@ function render(){ | ||
| 346 | 395 | wrap.appendChild(card); |
| 347 | 396 | }); |
| 348 | 397 | } |
| 349 | - | |
| 350 | 398 | function switchAccount(email,btn){ |
| 351 | 399 | btn.disabled=true; |
| 352 | 400 | btn.textContent='Switching...'; |
| @@ -457,6 +505,7 @@ $('themeToggle').onclick=function(){ | ||
| 457 | 505 | window.sxApplyTheme(window.sxTheme()==='dark'?'light':'dark'); |
| 458 | 506 | } |
| 459 | 507 | }; |
| 508 | +setInterval(refreshResetLabels,30000); | |
| 460 | 509 | load(); |
| 461 | 510 | </script> |
| 462 | 511 | </body></html> |
| index e0c2767..eb9099c 100644 | ||
| --- a/src/ui_html.h | ||
| +++ b/src/ui_html.h | ||
| @@ -80,12 +80,13 @@ static const char *UI_HTML = | ||
| 80 | 80 | " grid-template-columns:repeat(2,minmax(0,1fr));gap:4px 14px}\n" |
| 81 | 81 | ".models.show{display:grid}\n" |
| 82 | 82 | ".mrow{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:11.5px;padding:2px 0}\n" |
| 83 | - ".mrow .mid{font-family:var(--mono);color:var(--text-2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n" | |
| 83 | + ".mrow .mid{font-family:var(--mono);color:var(--text-2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}\n" | |
| 84 | + ".mrow .mright{display:inline-flex;align-items:center;gap:8px;flex:0 0 auto}\n" | |
| 85 | + ".mrow .mrst{font-family:var(--mono);font-size:11px;color:var(--text-2);white-space:nowrap}\n" | |
| 84 | 86 | ".mrow .mpct{font-family:var(--mono);font-weight:650;flex:0 0 auto}\n" |
| 85 | 87 | ".mrow .mpct.ok{color:var(--green)}\n" |
| 86 | 88 | ".mrow .mpct.warn{color:var(--orange)}\n" |
| 87 | 89 | ".mrow .mpct.bad{color:var(--red)}\n" |
| 88 | - ".err-msg{font-size:12px;color:var(--red);padding:4px 0}\n" | |
| 89 | 90 | ".empty{padding:18px 16px;text-align:center;color:var(--text-2);font-size:13px}\n" |
| 90 | 91 | ".kv{display:grid;grid-template-columns:120px minmax(0,1fr);gap:5px 12px;font-size:12px}\n" |
| 91 | 92 | ".kv .k{color:var(--text-2)}\n" |
| @@ -213,18 +214,51 @@ static const char *UI_HTML = | ||
| 213 | 214 | " if(pool.pct<0)return 'N/A';\n" |
| 214 | 215 | " return pool.pct.toFixed(1)+'%';\n" |
| 215 | 216 | "}\n" |
| 217 | + "function pad2(n){return n<10?('0'+n):String(n);}\n" | |
| 218 | + "function fmtClock(ms){\n" | |
| 219 | + " var d=new Date(ms),now=new Date();\n" | |
| 220 | + " var hm=pad2(d.getHours())+':'+pad2(d.getMinutes());\n" | |
| 221 | + " if(d.getFullYear()===now.getFullYear()&&d.getMonth()===now.getMonth()&&d.getDate()===now.getDate())return hm;\n" | |
| 222 | + " var mon=d.toLocaleString(undefined,{month:'short'});\n" | |
| 223 | + " return mon+' '+d.getDate()+' '+hm;\n" | |
| 224 | + "}\n" | |
| 225 | + "function fmtResetShort(iso){\n" | |
| 226 | + " if(!iso)return '-';\n" | |
| 227 | + " var t=Date.parse(iso);\n" | |
| 228 | + " if(isNaN(t))return iso;\n" | |
| 229 | + " var diff=Math.floor((t-Date.now())/1000);\n" | |
| 230 | + " if(diff<=0)return 'due';\n" | |
| 231 | + " var totalH=Math.floor(diff/3600);\n" | |
| 232 | + " var m=Math.floor((diff%3600)/60);\n" | |
| 233 | + " if(totalH>0)return totalH+'h '+pad2(m)+'m';\n" | |
| 234 | + " return Math.max(1,m)+'m';\n" | |
| 235 | + "}\n" | |
| 216 | 236 | "function fmtReset(iso){\n" |
| 217 | 237 | " if(!iso)return 'Reset: -';\n" |
| 218 | 238 | " var t=Date.parse(iso);\n" |
| 219 | 239 | " if(isNaN(t))return 'Reset: '+iso;\n" |
| 220 | 240 | " var diff=Math.floor((t-Date.now())/1000);\n" |
| 221 | - " if(diff<=0)return 'Resets soon';\n" | |
| 241 | + " var clk=fmtClock(t);\n" | |
| 242 | + " if(diff<=0)return 'Resets soon · '+clk;\n" | |
| 243 | + " var totalH=Math.floor(diff/3600);\n" | |
| 222 | 244 | " var d=Math.floor(diff/86400);\n" |
| 223 | 245 | " var h=Math.floor((diff%86400)/3600);\n" |
| 224 | 246 | " var m=Math.floor((diff%3600)/60);\n" |
| 225 | - " if(d>0)return 'Resets in '+d+'d '+h+'h';\n" | |
| 226 | - " if(h>0)return 'Resets in '+h+'h '+m+'m';\n" | |
| 227 | - " return 'Resets in '+Math.max(1,m)+'m';\n" | |
| 247 | + " if(totalH>=24)return 'Resets in '+totalH+'h '+pad2(m)+'m ('+d+'d '+h+'h) · '+clk;\n" | |
| 248 | + " if(totalH>0)return 'Resets in '+totalH+'h '+pad2(m)+'m · '+clk;\n" | |
| 249 | + " return 'Resets in '+Math.max(1,m)+'m · '+clk;\n" | |
| 250 | + "}\n" | |
| 251 | + "function refreshResetLabels(){\n" | |
| 252 | + " var els=document.querySelectorAll('[data-reset]');\n" | |
| 253 | + " for(var i=0;i<els.length;i++){\n" | |
| 254 | + " var node=els[i];\n" | |
| 255 | + " var iso=node.getAttribute('data-reset');\n" | |
| 256 | + " if(!iso)continue;\n" | |
| 257 | + " var mode=node.getAttribute('data-reset-mode')||'full';\n" | |
| 258 | + " node.textContent=(mode==='short')?fmtResetShort(iso):fmtReset(iso);\n" | |
| 259 | + " var t=Date.parse(iso);\n" | |
| 260 | + " if(!isNaN(t))node.title='Resets at '+fmtClock(t)+' ('+iso+')';\n" | |
| 261 | + " }\n" | |
| 228 | 262 | "}\n" |
| 229 | 263 | "function el(tag,cls,txt){\n" |
| 230 | 264 | " var n=document.createElement(tag);\n" |
| @@ -234,18 +268,18 @@ static const char *UI_HTML = | ||
| 234 | 268 | "}\n" |
| 235 | 269 | "\n" |
| 236 | 270 | "function computeBest(){\n" |
| 237 | - " var bestG=null,bestGP=-1,bestC=null,bestCP=-1;\n" | |
| 271 | + " var bestG=null,bestGP=-1,bestGR='',bestC=null,bestCP=-1,bestCR='';\n" | |
| 238 | 272 | " state.accounts.forEach(function(a){\n" |
| 239 | 273 | " var qd=state.quotas[a.email];\n" |
| 240 | 274 | " if(!qd||!qd.ok)return;\n" |
| 241 | 275 | " if(qd.gemini&&!qd.gemini.exhausted&&qd.gemini.pct>bestGP){\n" |
| 242 | - " bestGP=qd.gemini.pct;bestG=a.email;\n" | |
| 276 | + " bestGP=qd.gemini.pct;bestG=a.email;bestGR=qd.gemini.reset_time||'';\n" | |
| 243 | 277 | " }\n" |
| 244 | 278 | " if(qd.claude&&!qd.claude.exhausted&&qd.claude.pct>bestCP){\n" |
| 245 | - " bestCP=qd.claude.pct;bestC=a.email;\n" | |
| 279 | + " bestCP=qd.claude.pct;bestC=a.email;bestCR=qd.claude.reset_time||'';\n" | |
| 246 | 280 | " }\n" |
| 247 | 281 | " });\n" |
| 248 | - " return {gemini:bestG,geminiPct:bestGP,claude:bestC,claudePct:bestCP};\n" | |
| 282 | + " return {gemini:bestG,geminiPct:bestGP,geminiReset:bestGR,claude:bestC,claudePct:bestCP,claudeReset:bestCR};\n" | |
| 249 | 283 | "}\n" |
| 250 | 284 | "\n" |
| 251 | 285 | "function renderPool(label,pool,loading){\n" |
| @@ -275,6 +309,12 @@ static const char *UI_HTML = | ||
| 275 | 309 | " fill.className=cls;\n" |
| 276 | 310 | " fill.style.width=w.toFixed(1)+'%';\n" |
| 277 | 311 | " rst.textContent=fmtReset(pool.reset_time);\n" |
| 312 | + " if(pool.reset_time){\n" | |
| 313 | + " rst.setAttribute('data-reset',pool.reset_time);\n" | |
| 314 | + " rst.setAttribute('data-reset-mode','full');\n" | |
| 315 | + " var rt=Date.parse(pool.reset_time);\n" | |
| 316 | + " if(!isNaN(rt))rst.title='Resets at '+fmtClock(rt)+' ('+pool.reset_time+')';\n" | |
| 317 | + " }\n" | |
| 278 | 318 | " }\n" |
| 279 | 319 | " hd.appendChild(pctEl);\n" |
| 280 | 320 | " bar.appendChild(fill);\n" |
| @@ -292,12 +332,11 @@ static const char *UI_HTML = | ||
| 292 | 332 | "\n" |
| 293 | 333 | " $('kpiGemini').textContent=best.gemini?shortEmail(best.gemini):'-';\n" |
| 294 | 334 | " $('kpiGemini').title=best.gemini||'';\n" |
| 295 | - " $('kpiGeminiMeta').textContent=best.gemini?(best.geminiPct.toFixed(1)+'% remaining'):(state.loading?'Checking...':'No quota data');\n" | |
| 335 | + " $('kpiGeminiMeta').textContent=best.gemini?(best.geminiPct.toFixed(1)+'% remaining'+(best.geminiReset?(' · resets in '+fmtResetShort(best.geminiReset)):'')):(state.loading?'Checking...':'No quota data');\n" | |
| 296 | 336 | "\n" |
| 297 | 337 | " $('kpiClaude').textContent=best.claude?shortEmail(best.claude):'-';\n" |
| 298 | 338 | " $('kpiClaude').title=best.claude||'';\n" |
| 299 | - " $('kpiClaudeMeta').textContent=best.claude?(best.claudePct.toFixed(1)+'% remaining'):(state.loading?'Checking...':'No quota data');\n" | |
| 300 | - "\n" | |
| 339 | + " $('kpiClaudeMeta').textContent=best.claude?(best.claudePct.toFixed(1)+'% remaining'+(best.claudeReset?(' · resets in '+fmtResetShort(best.claudeReset)):'')):(state.loading?'Checking...':'No quota data');\n" | |
| 301 | 340 | " var wrap=$('accounts');\n" |
| 302 | 341 | " wrap.innerHTML='';\n" |
| 303 | 342 | " if(!state.accounts.length){\n" |
| @@ -341,8 +380,18 @@ static const char *UI_HTML = | ||
| 341 | 380 | " qd.models.forEach(function(m){\n" |
| 342 | 381 | " var row=el('div','mrow');\n" |
| 343 | 382 | " row.appendChild(el('span','mid',m.id));\n" |
| 383 | + " var right=el('span','mright');\n" | |
| 384 | + " if(m.reset_time){\n" | |
| 385 | + " var mr=el('span','mrst',fmtResetShort(m.reset_time));\n" | |
| 386 | + " mr.setAttribute('data-reset',m.reset_time);\n" | |
| 387 | + " mr.setAttribute('data-reset-mode','short');\n" | |
| 388 | + " var mt=Date.parse(m.reset_time);\n" | |
| 389 | + " if(!isNaN(mt))mr.title='Resets at '+fmtClock(mt)+' ('+m.reset_time+')';\n" | |
| 390 | + " right.appendChild(mr);\n" | |
| 391 | + " }\n" | |
| 344 | 392 | " var cls=pctClass(m.pct,m.exhausted);\n" |
| 345 | - " row.appendChild(el('span','mpct '+cls,m.exhausted?'EXH':(m.pct.toFixed(1)+'%')));\n" | |
| 393 | + " right.appendChild(el('span','mpct '+cls,m.exhausted?'EXH':(m.pct.toFixed(1)+'%')));\n" | |
| 394 | + " row.appendChild(right);\n" | |
| 346 | 395 | " mgrid.appendChild(row);\n" |
| 347 | 396 | " });\n" |
| 348 | 397 | " card.appendChild(mgrid);\n" |
| @@ -351,7 +400,6 @@ static const char *UI_HTML = | ||
| 351 | 400 | " wrap.appendChild(card);\n" |
| 352 | 401 | " });\n" |
| 353 | 402 | "}\n" |
| 354 | - "\n" | |
| 355 | 403 | "function switchAccount(email,btn){\n" |
| 356 | 404 | " btn.disabled=true;\n" |
| 357 | 405 | " btn.textContent='Switching...';\n" |
| @@ -462,6 +510,7 @@ static const char *UI_HTML = | ||
| 462 | 510 | " window.sxApplyTheme(window.sxTheme()==='dark'?'light':'dark');\n" |
| 463 | 511 | " }\n" |
| 464 | 512 | "};\n" |
| 513 | + "setInterval(refreshResetLabels,30000);\n" | |
| 465 | 514 | "load();\n" |
| 466 | 515 | "</script>\n" |
| 467 | 516 | "\002</body></html>\n" |
| index 1169c80..33af6e9 100755 | ||
| --- a/tests/mock_quota.sh | ||
| +++ b/tests/mock_quota.sh | ||
| @@ -21,9 +21,12 @@ fi | ||
| 21 | 21 | |
| 22 | 22 | echo "INFO : ya29.MOCK-TOKEN-MUST-NOT-LEAK" >&2 |
| 23 | 23 | |
| 24 | +RST_CLAUDE="${MOCK_RESET_CLAUDE:-2026-11-25T06:00:00Z}" | |
| 25 | +RST_GEMINI="${MOCK_RESET_GEMINI:-2026-11-25T03:00:00Z}" | |
| 26 | + | |
| 24 | 27 | case "$acct" in |
| 25 | 28 | alpha@example.com) |
| 26 | - cat <<'EOF' | |
| 29 | + cat <<EOF | |
| 27 | 30 | { |
| 28 | 31 | "ok": true, |
| 29 | 32 | "email": "alpha@example.com", |
| @@ -31,10 +34,10 @@ case "$acct" in | ||
| 31 | 34 | "endpoint": "https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota", |
| 32 | 35 | "buckets": [ |
| 33 | 36 | {"tokenType": "WTUS", "modelId": "chat_20706", "remainingFraction": 1}, |
| 34 | - {"resetTime": "2026-11-25T06:00:00Z", "tokenType": "WTUS", "modelId": "claude-opus-4-6-thinking", "remainingFraction": 1}, | |
| 35 | - {"resetTime": "2026-11-25T06:00:00Z", "tokenType": "WTUS", "modelId": "claude-sonnet-4-6", "remainingFraction": 1}, | |
| 36 | - {"resetTime": "2026-11-25T03:00:00Z", "tokenType": "WTUS", "modelId": "gemini-3.8-flash-tiered", "remainingFraction": 0.855}, | |
| 37 | - {"resetTime": "2026-11-25T03:00:00Z", "tokenType": "WTUS", "modelId": "gemini-4-hydrogen-sonar", "remainingFraction": 0.855}, | |
| 37 | + {"resetTime": "$RST_CLAUDE", "tokenType": "WTUS", "modelId": "claude-opus-4-6-thinking", "remainingFraction": 1}, | |
| 38 | + {"resetTime": "$RST_CLAUDE", "tokenType": "WTUS", "modelId": "claude-sonnet-4-6", "remainingFraction": 1}, | |
| 39 | + {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-3.8-flash-tiered", "remainingFraction": 0.855}, | |
| 40 | + {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-4-hydrogen-sonar", "remainingFraction": 0.855}, | |
| 38 | 41 | {"tokenType": "WTUS", "modelId": "tab_flash_lite_preview", "remainingFraction": 1} |
| 39 | 42 | ] |
| 40 | 43 | } |
| @@ -42,16 +45,16 @@ EOF | ||
| 42 | 45 | exit 0 |
| 43 | 46 | ;; |
| 44 | 47 | beta@example.com) |
| 45 | - cat <<'EOF' | |
| 48 | + cat <<EOF | |
| 46 | 49 | { |
| 47 | 50 | "ok": true, |
| 48 | 51 | "email": "beta@example.com", |
| 49 | 52 | "project": "aicode-consumers", |
| 50 | 53 | "endpoint": "https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota", |
| 51 | 54 | "buckets": [ |
| 52 | - {"resetTime": "2026-11-25T08:00:00Z", "tokenType": "WTUS", "modelId": "claude-sonnet-4-6", "remainingFraction": 0.42}, | |
| 53 | - {"resetTime": "2026-11-25T04:00:00Z", "tokenType": "WTUS", "modelId": "gemini-3.8-flash-tiered", "remainingFraction": null}, | |
| 54 | - {"resetTime": "2026-11-25T04:00:00Z", "tokenType": "WTUS", "modelId": "gemini-4-hydrogen-sonar"} | |
| 55 | + {"resetTime": "$RST_CLAUDE", "tokenType": "WTUS", "modelId": "claude-sonnet-4-6", "remainingFraction": 0.42}, | |
| 56 | + {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-3.8-flash-tiered", "remainingFraction": null}, | |
| 57 | + {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-4-hydrogen-sonar"} | |
| 55 | 58 | ] |
| 56 | 59 | } |
| 57 | 60 | EOF |
| index fc73f17..cc47abc 100755 | ||
| --- a/tests/run.sh | ||
| +++ b/tests/run.sh | ||
| @@ -81,8 +81,8 @@ mkdir -p "$FIX/none" "$FIX/empty" "$FIX/full" | ||
| 81 | 81 | chmod +x "$ROOT/tests/mock_quota.sh" |
| 82 | 82 | export GOOGLE_QUOTA_BIN="$ROOT/tests/mock_quota.sh" |
| 83 | 83 | export GOOGLE_ACCESS_TOKEN="ya29.INHERITED-TOKEN-MUST-BE-CLEARED" |
| 84 | - | |
| 85 | -: > "$FIX/empty/antigravity_accounts.json" | |
| 84 | +export MOCK_RESET_CLAUDE=$(python3 -c "from datetime import datetime,timedelta,timezone; print((datetime.now(timezone.utc)+timedelta(hours=2,minutes=15)).strftime('%Y-%m-%dT%H:%M:%SZ'))") | |
| 85 | +export MOCK_RESET_GEMINI=$(python3 -c "from datetime import datetime,timedelta,timezone; print((datetime.now(timezone.utc)+timedelta(hours=144,minutes=30)).strftime('%Y-%m-%dT%H:%M:%SZ'))") | |
| 86 | 86 | |
| 87 | 87 | cat > "$FIX/full/antigravity_accounts.json" <<'EOF' |
| 88 | 88 | [ |
| @@ -102,8 +102,7 @@ META_ENV=$(BOT_PASSWORD=secret-pass SX_PLUGIN_META=1 $BIN) | ||
| 102 | 102 | check "SX_PLUGIN_META=1 works without auth" '{"name":"google quota","desc":"Account quotas"}' "$META_ENV" |
| 103 | 103 | |
| 104 | 104 | VER=$($BIN --version) |
| 105 | -check "--version prints plugin id and version" "plugin_google_quota 1.0.0" "$VER" | |
| 106 | - | |
| 105 | +check "--version prints plugin id and version" "plugin_google_quota 1.0.1" "$VER" | |
| 107 | 106 | UNAUTH=$(BOT_PASSWORD=secret-pass QUERY_STRING="action=status" $BIN) |
| 108 | 107 | check "missing password returns 401" "Status: 401 Unauthorized" "$UNAUTH" |
| 109 | 108 | |
| @@ -135,15 +134,14 @@ json_ok "missing CLI sets cli_present false" "$ST_NOCLI" "d['ok'] is True and d[ | ||
| 135 | 134 | # ---------------------------------------------------------------- quota |
| 136 | 135 | section "quota" |
| 137 | 136 | Q_ONE=$(GOOGLE_ACCOUNTS_FILE="$FIX/full/antigravity_accounts.json" api "action=quota&account=alpha@example.com") |
| 138 | -json_ok "single account quota parses gemini and claude pools" "$Q_ONE" \ | |
| 139 | - "d['ok'] is True and d['account']['ok'] is True and abs(d['account']['gemini']['pct'] - 85.5) < 0.01 and abs(d['account']['claude']['pct'] - 100.0) < 0.01 and len(d['account']['models']) == 4" | |
| 137 | +json_ok "single account quota parses gemini and claude pools and remaining hours" "$Q_ONE" \ | |
| 138 | + "d['ok'] is True and d['account']['ok'] is True and abs(d['account']['gemini']['pct'] - 85.5) < 0.01 and abs(d['account']['claude']['pct'] - 100.0) < 0.01 and len(d['account']['models']) == 4 and d['account']['gemini']['reset_in_seconds'] > 500000 and d['account']['gemini']['reset_in_hours'] > 140 and 'h ' in d['account']['gemini']['reset_remaining'] and d['account']['claude']['reset_in_seconds'] > 7000 and 'h ' in d['account']['claude']['reset_remaining'] and all('reset_remaining' in m and 'reset_in_hours' in m for m in d['account']['models'])" | |
| 140 | 139 | check_not "single quota never leaks token" "MOCK-TOKEN" "$Q_ONE" |
| 141 | 140 | check_not "single quota never leaks refresh token" "MOCK-REFRESH-TOKEN" "$Q_ONE" |
| 142 | 141 | |
| 143 | 142 | Q_EXH=$(GOOGLE_ACCOUNTS_FILE="$FIX/full/antigravity_accounts.json" api "action=quota&account=beta@example.com") |
| 144 | -json_ok "null/missing remainingFraction marks gemini pool exhausted" "$Q_EXH" \ | |
| 145 | - "d['ok'] is True and d['account']['gemini']['exhausted'] is True and d['account']['gemini']['pct'] == 0.0 and abs(d['account']['claude']['pct'] - 42.0) < 0.01" | |
| 146 | - | |
| 143 | +json_ok "null/missing remainingFraction marks gemini pool exhausted with reset remaining" "$Q_EXH" \ | |
| 144 | + "d['ok'] is True and d['account']['gemini']['exhausted'] is True and d['account']['gemini']['pct'] == 0.0 and abs(d['account']['claude']['pct'] - 42.0) < 0.01 and d['account']['gemini']['reset_in_hours'] > 140 and 'h ' in d['account']['gemini']['reset_remaining']" | |
| 147 | 145 | Q_ALL=$(GOOGLE_ACCOUNTS_FILE="$FIX/full/antigravity_accounts.json" api "action=quota") |
| 148 | 146 | json_ok "all-accounts quota aggregates best_gemini, best_claude, and broken account" "$Q_ALL" \ |
| 149 | 147 | "d['ok'] is True and d['count'] == 3 and d['best_gemini'] == 'alpha@example.com' and d['best_claude'] == 'alpha@example.com' and d['accounts'][2]['ok'] is False" |
| @@ -182,11 +180,13 @@ check "HTML includes bot theme prepaint" "bot_theme" "$HTML" | ||
| 182 | 180 | check "HTML includes theme handoff" "sx-theme-request" "$HTML" |
| 183 | 181 | check "HTML uses two-route API helper" "plugin_google_quota" "$HTML" |
| 184 | 182 | check "HTML hub proxy URL uses &action= separator" "'/plugins?plugin='+encodeURIComponent(HUB)+'&'" "$HTML" |
| 183 | +check "HTML formats total remaining hours even >= 24h" "totalH>=24" "$HTML" | |
| 184 | +check "HTML renders per-model reset remaining hours" "fmtResetShort" "$HTML" | |
| 185 | +check "HTML includes live reset countdown attributes" "data-reset" "$HTML" | |
| 185 | 186 | check "HTML hides theme toggle in embed mode" "embed-hide" "$HTML" |
| 186 | 187 | check_not "HTML loads no CDN script" "<script src=" "$HTML" |
| 187 | 188 | check_not "HTML references no external host script" "cdnjs" "$HTML" |
| 188 | 189 | check_not "HTML makes no outbound fetch to googleapis" "googleapis.com" "$HTML" |
| 189 | - | |
| 190 | 190 | printf '%s' "$HTML" > "$FIX/page.html" |
| 191 | 191 | if python3 - "$FIX/page.html" <<'PY' |
| 192 | 192 | import re, sys |
| 193 | 193 |
| index 209efcb..9b30545 100644 | index 209efcb..9b30545 100644 | ||
| --- a/README.md | --- a/README.md | ||
| +++ b/README.md | +++ b/README.md | ||
| @@ -8,7 +8,7 @@ account list (`antigravity_accounts.json`) and active selection | @@ -8,7 +8,7 @@ account list (`antigravity_accounts.json`) and active selection | ||
| 8 | click. | 8 | click. |
| 9 | 9 | ||
| 10 | * `--meta` -> `{"name":"google quota","desc":"Account quotas"}` | 10 | * `--meta` -> `{"name":"google quota","desc":"Account quotas"}` |
| 11 | -* `--version` -> `plugin_google_quota 1.0.0` | 11 | +* `--version` -> `plugin_google_quota 1.0.1` |
| 12 | * Catalog slug `google-quota`, category `devtools` | 12 | * Catalog slug `google-quota`, category `devtools` |
| 13 | * Public source: <https://plugingit.scorpiox.net/scorpiox-bot-plugin-google-quota.git> | 13 | * Public source: <https://plugingit.scorpiox.net/scorpiox-bot-plugin-google-quota.git> |
| 14 | * Prebuilt binaries: <https://dist.scorpiox.net/bot-plugins/google-quota/> | 14 | * Prebuilt binaries: <https://dist.scorpiox.net/bot-plugins/google-quota/> |
| @@ -59,7 +59,7 @@ extracted; token strings are never copied or emitted. | @@ -59,7 +59,7 @@ extracted; token strings are never copied or emitted. | ||
| 59 | All actions accept `X-Bot-Password`, `Authorization: Bearer`, or `?pwd=`. | 59 | All actions accept `X-Bot-Password`, `Authorization: Bearer`, or `?pwd=`. |
| 60 | 60 | ||
| 61 | * `GET ?action=status` — fast local read of configured accounts, `selected`, paths, and `cli_present` | 61 | * `GET ?action=status` — fast local read of configured accounts, `selected`, paths, and `cli_present` |
| 62 | -* `GET ?action=quota` (or `?format=json`) — queries all accounts concurrently and returns Gemini/Claude pool summaries, reset times, per-model buckets, `best_gemini`, and `best_claude` | 62 | +* `GET ?action=quota` (or `?format=json`) — queries all accounts concurrently and returns Gemini/Claude pool summaries, reset times (`reset_time`, `reset_in_seconds`, `reset_in_hours`, `reset_remaining`), per-model buckets, `best_gemini`, and `best_claude` |
| 63 | * `GET ?action=quota&account=<email>` — queries a single account | 63 | * `GET ?action=quota&account=<email>` — queries a single account |
| 64 | * `GET/POST ?action=switch&account=<email>` (or JSON body `{"account":"..."}`) — validates the email against `antigravity_accounts.json` and writes `selected_account.txt` | 64 | * `GET/POST ?action=switch&account=<email>` (or JSON body `{"account":"..."}`) — validates the email against `antigravity_accounts.json` and writes `selected_account.txt` |
| 65 | 65 |
| index 58d102f..49f1b9a 100644 | index 58d102f..49f1b9a 100644 | ||
| --- a/plugin.json | --- a/plugin.json | ||
| +++ b/plugin.json | +++ b/plugin.json | ||
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | "slug": "google-quota", | 2 | "slug": "google-quota", |
| 3 | "id": "plugin_google_quota", | 3 | "id": "plugin_google_quota", |
| 4 | "title": "Google Account Quotas", | 4 | "title": "Google Account Quotas", |
| 5 | + "version": "1.0.1", | ||
| 5 | "summary": "Zero-dependency Google Antigravity multi-account quota monitor and active-account switcher for your node. Reads the local antigravity_accounts.json and selected_account.txt files, queries per-model quota pools through the node's scorpiox-google-quota CLI, and lets you switch the active account in one click. Holds no OAuth client secret and never prints, logs or returns any refresh or access token.", | 6 | "summary": "Zero-dependency Google Antigravity multi-account quota monitor and active-account switcher for your node. Reads the local antigravity_accounts.json and selected_account.txt files, queries per-model quota pools through the node's scorpiox-google-quota CLI, and lets you switch the active account in one click. Holds no OAuth client secret and never prints, logs or returns any refresh or access token.", |
| 6 | "category": "devtools", | 7 | "category": "devtools", |
| 7 | "license": "MIT", | 8 | "license": "MIT", |
| index 97e4490..b1bbb8e 100644 | index 97e4490..b1bbb8e 100644 | ||
| --- a/src/plugin_google_quota.c | --- a/src/plugin_google_quota.c | ||
| +++ b/src/plugin_google_quota.c | +++ b/src/plugin_google_quota.c | ||
| @@ -51,11 +51,13 @@ | @@ -51,11 +51,13 @@ | ||
| 51 | #include <ctype.h> | 51 | #include <ctype.h> |
| 52 | #include <errno.h> | 52 | #include <errno.h> |
| 53 | #include <stdarg.h> | 53 | #include <stdarg.h> |
| 54 | +#include <time.h> | ||
| 54 | 55 | ||
| 55 | #if defined(_WIN32) | 56 | #if defined(_WIN32) |
| 56 | # define WIN32_LEAN_AND_MEAN | 57 | # define WIN32_LEAN_AND_MEAN |
| 57 | # include <windows.h> | 58 | # include <windows.h> |
| 58 | # include <direct.h> | 59 | # include <direct.h> |
| 60 | +# include <fcntl.h> | ||
| 59 | # include <io.h> | 61 | # include <io.h> |
| 60 | # define popen _popen | 62 | # define popen _popen |
| 61 | # define pclose _pclose | 63 | # define pclose _pclose |
| @@ -75,10 +77,9 @@ | @@ -75,10 +77,9 @@ | ||
| 75 | 77 | ||
| 76 | #define PLUGIN_SLUG "google-quota" | 78 | #define PLUGIN_SLUG "google-quota" |
| 77 | #define PLUGIN_ID "plugin_google_quota" | 79 | #define PLUGIN_ID "plugin_google_quota" |
| 78 | -#define PLUGIN_VER "1.0.0" | 80 | +#define PLUGIN_VER "1.0.1" |
| 79 | #define PLUGIN_NAME "google quota" | 81 | #define PLUGIN_NAME "google quota" |
| 80 | #define PLUGIN_DESC "Account quotas" | 82 | #define PLUGIN_DESC "Account quotas" |
| 81 | - | ||
| 82 | #define DEFAULT_QUOTA_BIN "scorpiox-google-quota" | 83 | #define DEFAULT_QUOTA_BIN "scorpiox-google-quota" |
| 83 | 84 | ||
| 84 | #define PATH_SZ 1024 | 85 | #define PATH_SZ 1024 |
| @@ -885,7 +886,7 @@ static void pool_add(pool_summary_t *p, double pct, int exhausted, const char *r | @@ -885,7 +886,7 @@ static void pool_add(pool_summary_t *p, double pct, int exhausted, const char *r | ||
| 885 | if (!p->present || pct < p->pct) p->pct = pct; | 886 | if (!p->present || pct < p->pct) p->pct = pct; |
| 886 | p->present = 1; | 887 | p->present = 1; |
| 887 | if (exhausted || pct <= 0.0) p->exhausted = 1; | 888 | if (exhausted || pct <= 0.0) p->exhausted = 1; |
| 888 | - if (!p->reset_time[0] && reset && reset[0]) | 889 | + if (reset && reset[0] && (!p->reset_time[0] || strcmp(reset, p->reset_time) < 0)) |
| 889 | snprintf(p->reset_time, sizeof(p->reset_time), "%s", reset); | 890 | snprintf(p->reset_time, sizeof(p->reset_time), "%s", reset); |
| 890 | p->count++; | 891 | p->count++; |
| 891 | } | 892 | } |
| @@ -1186,21 +1187,107 @@ static void emit_error(int code, const char *status, const char *err, const char | @@ -1186,21 +1187,107 @@ static void emit_error(int code, const char *status, const char *err, const char | ||
| 1186 | buf_free(&b); | 1187 | buf_free(&b); |
| 1187 | } | 1188 | } |
| 1188 | 1189 | ||
| 1189 | -static void emit_pool_json(buf_t *b, const pool_summary_t *p) | 1190 | +static long long days_from_civil(int y, unsigned m, unsigned d) |
| 1191 | +{ | ||
| 1192 | + y -= (m <= 2) ? 1 : 0; | ||
| 1193 | + { | ||
| 1194 | + long long era = (y >= 0 ? y : y - 399) / 400; | ||
| 1195 | + unsigned yoe = (unsigned)(y - era * 400); | ||
| 1196 | + unsigned doy = (153U * (m + (m > 2 ? (unsigned)-3 : 9U)) + 2U) / 5U + d - 1U; | ||
| 1197 | + unsigned doe = yoe * 365U + yoe / 4U - yoe / 100U + doy; | ||
| 1198 | + return era * 146097LL + (long long)doe - 719468LL; | ||
| 1199 | + } | ||
| 1200 | +} | ||
| 1201 | + | ||
| 1202 | +static int parse_iso_utc_epoch(const char *iso, long long *out_epoch) | ||
| 1203 | +{ | ||
| 1204 | + int y = 0, mo = 0, d = 0, hh = 0, mm = 0, ss = 0; | ||
| 1205 | + const char *t; | ||
| 1206 | + const char *tz; | ||
| 1207 | + | ||
| 1208 | + if (!iso || !*iso) return 0; | ||
| 1209 | + if (sscanf(iso, "%d-%d-%dT%d:%d:%d", &y, &mo, &d, &hh, &mm, &ss) != 6) | ||
| 1210 | + return 0; | ||
| 1211 | + if (mo < 1 || mo > 12 || d < 1 || d > 31 || | ||
| 1212 | + hh < 0 || hh > 23 || mm < 0 || mm > 59 || ss < 0 || ss > 60) | ||
| 1213 | + return 0; | ||
| 1214 | + t = strchr(iso, 'T'); | ||
| 1215 | + if (!t) return 0; | ||
| 1216 | + { | ||
| 1217 | + long long days = days_from_civil(y, (unsigned)mo, (unsigned)d); | ||
| 1218 | + long long epoch = days * 86400LL + (long long)hh * 3600LL + | ||
| 1219 | + (long long)mm * 60LL + (long long)ss; | ||
| 1220 | + tz = strpbrk(t, "Z+-"); | ||
| 1221 | + if (tz && (*tz == '+' || *tz == '-')) { | ||
| 1222 | + int oh = 0, om = 0; | ||
| 1223 | + if (sscanf(tz + 1, "%2d:%2d", &oh, &om) >= 1) { | ||
| 1224 | + long long off = (long long)oh * 3600LL + (long long)om * 60LL; | ||
| 1225 | + epoch += (*tz == '+') ? -off : off; | ||
| 1226 | + } | ||
| 1227 | + } | ||
| 1228 | + *out_epoch = epoch; | ||
| 1229 | + return 1; | ||
| 1230 | + } | ||
| 1231 | +} | ||
| 1232 | + | ||
| 1233 | +static void compute_reset_fields(const char *iso, long long now_epoch, | ||
| 1234 | + long long *secs_out, double *hrs_out, | ||
| 1235 | + char *rem_out, size_t rem_sz) | ||
| 1236 | +{ | ||
| 1237 | + long long target = 0; | ||
| 1238 | + long long diff; | ||
| 1239 | + | ||
| 1240 | + if (!iso || !iso[0] || !parse_iso_utc_epoch(iso, &target)) { | ||
| 1241 | + *secs_out = -1; | ||
| 1242 | + *hrs_out = -1.0; | ||
| 1243 | + if (rem_sz) rem_out[0] = '\0'; | ||
| 1244 | + return; | ||
| 1245 | + } | ||
| 1246 | + diff = target - now_epoch; | ||
| 1247 | + if (diff <= 0) { | ||
| 1248 | + *secs_out = 0; | ||
| 1249 | + *hrs_out = 0.0; | ||
| 1250 | + snprintf(rem_out, rem_sz, "due"); | ||
| 1251 | + return; | ||
| 1252 | + } | ||
| 1253 | + *secs_out = diff; | ||
| 1254 | + *hrs_out = (double)diff / 3600.0; | ||
| 1255 | + { | ||
| 1256 | + long long hrs = diff / 3600LL; | ||
| 1257 | + long long mins = (diff % 3600LL) / 60LL; | ||
| 1258 | + if (hrs > 0) | ||
| 1259 | + snprintf(rem_out, rem_sz, "%lldh %02lldm", hrs, mins); | ||
| 1260 | + else | ||
| 1261 | + snprintf(rem_out, rem_sz, "%lldm", mins > 0 ? mins : 1LL); | ||
| 1262 | + } | ||
| 1263 | +} | ||
| 1264 | + | ||
| 1265 | +static void emit_pool_json(buf_t *b, const pool_summary_t *p, long long now_epoch) | ||
| 1190 | { | 1266 | { |
| 1267 | + long long rsecs = -1; | ||
| 1268 | + double rhrs = -1.0; | ||
| 1269 | + char rrem[32] = {0}; | ||
| 1270 | + | ||
| 1191 | if (!p->present) { | 1271 | if (!p->present) { |
| 1192 | - buf_adds(b, "{\"pct\":-1,\"exhausted\":false,\"reset_time\":\"\",\"count\":0}"); | 1272 | + buf_adds(b, "{\"pct\":-1,\"exhausted\":false,\"reset_time\":\"\"," |
| 1273 | + "\"reset_in_seconds\":-1,\"reset_in_hours\":-1.00," | ||
| 1274 | + "\"reset_remaining\":\"\",\"count\":0}"); | ||
| 1193 | return; | 1275 | return; |
| 1194 | } | 1276 | } |
| 1277 | + compute_reset_fields(p->reset_time, now_epoch, &rsecs, &rhrs, rrem, sizeof(rrem)); | ||
| 1195 | buf_addf(b, "{\"pct\":%.2f,\"exhausted\":%s,\"reset_time\":", | 1278 | buf_addf(b, "{\"pct\":%.2f,\"exhausted\":%s,\"reset_time\":", |
| 1196 | p->pct, p->exhausted ? "true" : "false"); | 1279 | p->pct, p->exhausted ? "true" : "false"); |
| 1197 | buf_json(b, p->reset_time); | 1280 | buf_json(b, p->reset_time); |
| 1281 | + buf_addf(b, ",\"reset_in_seconds\":%lld,\"reset_in_hours\":%.2f,\"reset_remaining\":", | ||
| 1282 | + rsecs, rhrs); | ||
| 1283 | + buf_json(b, rrem); | ||
| 1198 | buf_addf(b, ",\"count\":%d}", p->count); | 1284 | buf_addf(b, ",\"count\":%d}", p->count); |
| 1199 | } | 1285 | } |
| 1200 | 1286 | ||
| 1201 | static void emit_acct_quota_json(buf_t *b, const acct_entry_t *a, const acct_quota_t *q) | 1287 | static void emit_acct_quota_json(buf_t *b, const acct_entry_t *a, const acct_quota_t *q) |
| 1202 | { | 1288 | { |
| 1203 | int i; | 1289 | int i; |
| 1290 | + long long now_epoch = (long long)time(NULL); | ||
| 1204 | 1291 | ||
| 1205 | buf_adds(b, "{\"email\":"); | 1292 | buf_adds(b, "{\"email\":"); |
| 1206 | buf_json(b, a->email); | 1293 | buf_json(b, a->email); |
| @@ -1223,12 +1310,16 @@ static void emit_acct_quota_json(buf_t *b, const acct_entry_t *a, const acct_quo | @@ -1223,12 +1310,16 @@ static void emit_acct_quota_json(buf_t *b, const acct_entry_t *a, const acct_quo | ||
| 1223 | buf_adds(b, ",\"project\":"); | 1310 | buf_adds(b, ",\"project\":"); |
| 1224 | buf_json(b, q->project); | 1311 | buf_json(b, q->project); |
| 1225 | buf_adds(b, ",\"gemini\":"); | 1312 | buf_adds(b, ",\"gemini\":"); |
| 1226 | - emit_pool_json(b, &q->gemini); | 1313 | + emit_pool_json(b, &q->gemini, now_epoch); |
| 1227 | buf_adds(b, ",\"claude\":"); | 1314 | buf_adds(b, ",\"claude\":"); |
| 1228 | - emit_pool_json(b, &q->claude); | 1315 | + emit_pool_json(b, &q->claude, now_epoch); |
| 1229 | buf_adds(b, ",\"models\":["); | 1316 | buf_adds(b, ",\"models\":["); |
| 1230 | for (i = 0; i < q->model_count; i++) { | 1317 | for (i = 0; i < q->model_count; i++) { |
| 1231 | const model_quota_t *m = &q->models[i]; | 1318 | const model_quota_t *m = &q->models[i]; |
| 1319 | + long long rsecs = -1; | ||
| 1320 | + double rhrs = -1.0; | ||
| 1321 | + char rrem[32] = {0}; | ||
| 1322 | + compute_reset_fields(m->reset_time, now_epoch, &rsecs, &rhrs, rrem, sizeof(rrem)); | ||
| 1232 | if (i > 0) buf_addc(b, ','); | 1323 | if (i > 0) buf_addc(b, ','); |
| 1233 | buf_adds(b, "{\"id\":"); | 1324 | buf_adds(b, "{\"id\":"); |
| 1234 | buf_json(b, m->id); | 1325 | buf_json(b, m->id); |
| @@ -1237,6 +1328,9 @@ static void emit_acct_quota_json(buf_t *b, const acct_entry_t *a, const acct_quo | @@ -1237,6 +1328,9 @@ static void emit_acct_quota_json(buf_t *b, const acct_entry_t *a, const acct_quo | ||
| 1237 | buf_addf(b, ",\"pct\":%.2f,\"exhausted\":%s,\"reset_time\":", | 1328 | buf_addf(b, ",\"pct\":%.2f,\"exhausted\":%s,\"reset_time\":", |
| 1238 | m->pct, m->exhausted ? "true" : "false"); | 1329 | m->pct, m->exhausted ? "true" : "false"); |
| 1239 | buf_json(b, m->reset_time); | 1330 | buf_json(b, m->reset_time); |
| 1331 | + buf_addf(b, ",\"reset_in_seconds\":%lld,\"reset_in_hours\":%.2f,\"reset_remaining\":", | ||
| 1332 | + rsecs, rhrs); | ||
| 1333 | + buf_json(b, rrem); | ||
| 1240 | buf_addc(b, '}'); | 1334 | buf_addc(b, '}'); |
| 1241 | } | 1335 | } |
| 1242 | buf_adds(b, "]}"); | 1336 | buf_adds(b, "]}"); |
| @@ -1495,6 +1589,10 @@ int main(int argc, char **argv) | @@ -1495,6 +1589,10 @@ int main(int argc, char **argv) | ||
| 1495 | const char *qs; | 1589 | const char *qs; |
| 1496 | char action[64] = {0}; | 1590 | char action[64] = {0}; |
| 1497 | 1591 | ||
| 1592 | +#if defined(_WIN32) | ||
| 1593 | + _setmode(_fileno(stdout), _O_BINARY); | ||
| 1594 | +#endif | ||
| 1595 | + | ||
| 1498 | /* 1. Discovery metadata. Must stay unauthenticated. */ | 1596 | /* 1. Discovery metadata. Must stay unauthenticated. */ |
| 1499 | if ((argc > 1 && strcmp(argv[1], "--meta") == 0) || getenv("SX_PLUGIN_META")) { | 1597 | if ((argc > 1 && strcmp(argv[1], "--meta") == 0) || getenv("SX_PLUGIN_META")) { |
| 1500 | puts("{\"name\":\"" PLUGIN_NAME "\",\"desc\":\"" PLUGIN_DESC "\"}"); | 1598 | puts("{\"name\":\"" PLUGIN_NAME "\",\"desc\":\"" PLUGIN_DESC "\"}"); |
| index 9d356fa..f291e1b 100644 | index 9d356fa..f291e1b 100644 | ||
| --- a/src/ui.html | --- a/src/ui.html | ||
| +++ b/src/ui.html | +++ b/src/ui.html | ||
| @@ -75,12 +75,13 @@ body{background:var(--bg);color:var(--text);font-family:var(--font);font-size:14 | @@ -75,12 +75,13 @@ body{background:var(--bg);color:var(--text);font-family:var(--font);font-size:14 | ||
| 75 | grid-template-columns:repeat(2,minmax(0,1fr));gap:4px 14px} | 75 | grid-template-columns:repeat(2,minmax(0,1fr));gap:4px 14px} |
| 76 | .models.show{display:grid} | 76 | .models.show{display:grid} |
| 77 | .mrow{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:11.5px;padding:2px 0} | 77 | .mrow{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:11.5px;padding:2px 0} |
| 78 | -.mrow .mid{font-family:var(--mono);color:var(--text-2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap} | 78 | +.mrow .mid{font-family:var(--mono);color:var(--text-2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0} |
| 79 | +.mrow .mright{display:inline-flex;align-items:center;gap:8px;flex:0 0 auto} | ||
| 80 | +.mrow .mrst{font-family:var(--mono);font-size:11px;color:var(--text-2);white-space:nowrap} | ||
| 79 | .mrow .mpct{font-family:var(--mono);font-weight:650;flex:0 0 auto} | 81 | .mrow .mpct{font-family:var(--mono);font-weight:650;flex:0 0 auto} |
| 80 | .mrow .mpct.ok{color:var(--green)} | 82 | .mrow .mpct.ok{color:var(--green)} |
| 81 | .mrow .mpct.warn{color:var(--orange)} | 83 | .mrow .mpct.warn{color:var(--orange)} |
| 82 | .mrow .mpct.bad{color:var(--red)} | 84 | .mrow .mpct.bad{color:var(--red)} |
| 83 | -.err-msg{font-size:12px;color:var(--red);padding:4px 0} | ||
| 84 | .empty{padding:18px 16px;text-align:center;color:var(--text-2);font-size:13px} | 85 | .empty{padding:18px 16px;text-align:center;color:var(--text-2);font-size:13px} |
| 85 | .kv{display:grid;grid-template-columns:120px minmax(0,1fr);gap:5px 12px;font-size:12px} | 86 | .kv{display:grid;grid-template-columns:120px minmax(0,1fr);gap:5px 12px;font-size:12px} |
| 86 | .kv .k{color:var(--text-2)} | 87 | .kv .k{color:var(--text-2)} |
| @@ -208,18 +209,51 @@ function fmtPct(pool){ | @@ -208,18 +209,51 @@ function fmtPct(pool){ | ||
| 208 | if(pool.pct<0)return 'N/A'; | 209 | if(pool.pct<0)return 'N/A'; |
| 209 | return pool.pct.toFixed(1)+'%'; | 210 | return pool.pct.toFixed(1)+'%'; |
| 210 | } | 211 | } |
| 212 | +function pad2(n){return n<10?('0'+n):String(n);} | ||
| 213 | +function fmtClock(ms){ | ||
| 214 | + var d=new Date(ms),now=new Date(); | ||
| 215 | + var hm=pad2(d.getHours())+':'+pad2(d.getMinutes()); | ||
| 216 | + if(d.getFullYear()===now.getFullYear()&&d.getMonth()===now.getMonth()&&d.getDate()===now.getDate())return hm; | ||
| 217 | + var mon=d.toLocaleString(undefined,{month:'short'}); | ||
| 218 | + return mon+' '+d.getDate()+' '+hm; | ||
| 219 | +} | ||
| 220 | +function fmtResetShort(iso){ | ||
| 221 | + if(!iso)return '-'; | ||
| 222 | + var t=Date.parse(iso); | ||
| 223 | + if(isNaN(t))return iso; | ||
| 224 | + var diff=Math.floor((t-Date.now())/1000); | ||
| 225 | + if(diff<=0)return 'due'; | ||
| 226 | + var totalH=Math.floor(diff/3600); | ||
| 227 | + var m=Math.floor((diff%3600)/60); | ||
| 228 | + if(totalH>0)return totalH+'h '+pad2(m)+'m'; | ||
| 229 | + return Math.max(1,m)+'m'; | ||
| 230 | +} | ||
| 211 | function fmtReset(iso){ | 231 | function fmtReset(iso){ |
| 212 | if(!iso)return 'Reset: -'; | 232 | if(!iso)return 'Reset: -'; |
| 213 | var t=Date.parse(iso); | 233 | var t=Date.parse(iso); |
| 214 | if(isNaN(t))return 'Reset: '+iso; | 234 | if(isNaN(t))return 'Reset: '+iso; |
| 215 | var diff=Math.floor((t-Date.now())/1000); | 235 | var diff=Math.floor((t-Date.now())/1000); |
| 216 | - if(diff<=0)return 'Resets soon'; | 236 | + var clk=fmtClock(t); |
| 237 | + if(diff<=0)return 'Resets soon · '+clk; | ||
| 238 | + var totalH=Math.floor(diff/3600); | ||
| 217 | var d=Math.floor(diff/86400); | 239 | var d=Math.floor(diff/86400); |
| 218 | var h=Math.floor((diff%86400)/3600); | 240 | var h=Math.floor((diff%86400)/3600); |
| 219 | var m=Math.floor((diff%3600)/60); | 241 | var m=Math.floor((diff%3600)/60); |
| 220 | - if(d>0)return 'Resets in '+d+'d '+h+'h'; | 242 | + if(totalH>=24)return 'Resets in '+totalH+'h '+pad2(m)+'m ('+d+'d '+h+'h) · '+clk; |
| 221 | - if(h>0)return 'Resets in '+h+'h '+m+'m'; | 243 | + if(totalH>0)return 'Resets in '+totalH+'h '+pad2(m)+'m · '+clk; |
| 222 | - return 'Resets in '+Math.max(1,m)+'m'; | 244 | + return 'Resets in '+Math.max(1,m)+'m · '+clk; |
| 245 | +} | ||
| 246 | +function refreshResetLabels(){ | ||
| 247 | + var els=document.querySelectorAll('[data-reset]'); | ||
| 248 | + for(var i=0;i<els.length;i++){ | ||
| 249 | + var node=els[i]; | ||
| 250 | + var iso=node.getAttribute('data-reset'); | ||
| 251 | + if(!iso)continue; | ||
| 252 | + var mode=node.getAttribute('data-reset-mode')||'full'; | ||
| 253 | + node.textContent=(mode==='short')?fmtResetShort(iso):fmtReset(iso); | ||
| 254 | + var t=Date.parse(iso); | ||
| 255 | + if(!isNaN(t))node.title='Resets at '+fmtClock(t)+' ('+iso+')'; | ||
| 256 | + } | ||
| 223 | } | 257 | } |
| 224 | function el(tag,cls,txt){ | 258 | function el(tag,cls,txt){ |
| 225 | var n=document.createElement(tag); | 259 | var n=document.createElement(tag); |
| @@ -229,18 +263,18 @@ function el(tag,cls,txt){ | @@ -229,18 +263,18 @@ function el(tag,cls,txt){ | ||
| 229 | } | 263 | } |
| 230 | 264 | ||
| 231 | function computeBest(){ | 265 | function computeBest(){ |
| 232 | - var bestG=null,bestGP=-1,bestC=null,bestCP=-1; | 266 | + var bestG=null,bestGP=-1,bestGR='',bestC=null,bestCP=-1,bestCR=''; |
| 233 | state.accounts.forEach(function(a){ | 267 | state.accounts.forEach(function(a){ |
| 234 | var qd=state.quotas[a.email]; | 268 | var qd=state.quotas[a.email]; |
| 235 | if(!qd||!qd.ok)return; | 269 | if(!qd||!qd.ok)return; |
| 236 | if(qd.gemini&&!qd.gemini.exhausted&&qd.gemini.pct>bestGP){ | 270 | if(qd.gemini&&!qd.gemini.exhausted&&qd.gemini.pct>bestGP){ |
| 237 | - bestGP=qd.gemini.pct;bestG=a.email; | 271 | + bestGP=qd.gemini.pct;bestG=a.email;bestGR=qd.gemini.reset_time||''; |
| 238 | } | 272 | } |
| 239 | if(qd.claude&&!qd.claude.exhausted&&qd.claude.pct>bestCP){ | 273 | if(qd.claude&&!qd.claude.exhausted&&qd.claude.pct>bestCP){ |
| 240 | - bestCP=qd.claude.pct;bestC=a.email; | 274 | + bestCP=qd.claude.pct;bestC=a.email;bestCR=qd.claude.reset_time||''; |
| 241 | } | 275 | } |
| 242 | }); | 276 | }); |
| 243 | - return {gemini:bestG,geminiPct:bestGP,claude:bestC,claudePct:bestCP}; | 277 | + return {gemini:bestG,geminiPct:bestGP,geminiReset:bestGR,claude:bestC,claudePct:bestCP,claudeReset:bestCR}; |
| 244 | } | 278 | } |
| 245 | 279 | ||
| 246 | function renderPool(label,pool,loading){ | 280 | function renderPool(label,pool,loading){ |
| @@ -270,6 +304,12 @@ function renderPool(label,pool,loading){ | @@ -270,6 +304,12 @@ function renderPool(label,pool,loading){ | ||
| 270 | fill.className=cls; | 304 | fill.className=cls; |
| 271 | fill.style.width=w.toFixed(1)+'%'; | 305 | fill.style.width=w.toFixed(1)+'%'; |
| 272 | rst.textContent=fmtReset(pool.reset_time); | 306 | rst.textContent=fmtReset(pool.reset_time); |
| 307 | + if(pool.reset_time){ | ||
| 308 | + rst.setAttribute('data-reset',pool.reset_time); | ||
| 309 | + rst.setAttribute('data-reset-mode','full'); | ||
| 310 | + var rt=Date.parse(pool.reset_time); | ||
| 311 | + if(!isNaN(rt))rst.title='Resets at '+fmtClock(rt)+' ('+pool.reset_time+')'; | ||
| 312 | + } | ||
| 273 | } | 313 | } |
| 274 | hd.appendChild(pctEl); | 314 | hd.appendChild(pctEl); |
| 275 | bar.appendChild(fill); | 315 | bar.appendChild(fill); |
| @@ -287,12 +327,11 @@ function render(){ | @@ -287,12 +327,11 @@ function render(){ | ||
| 287 | 327 | ||
| 288 | $('kpiGemini').textContent=best.gemini?shortEmail(best.gemini):'-'; | 328 | $('kpiGemini').textContent=best.gemini?shortEmail(best.gemini):'-'; |
| 289 | $('kpiGemini').title=best.gemini||''; | 329 | $('kpiGemini').title=best.gemini||''; |
| 290 | - $('kpiGeminiMeta').textContent=best.gemini?(best.geminiPct.toFixed(1)+'% remaining'):(state.loading?'Checking...':'No quota data'); | 330 | + $('kpiGeminiMeta').textContent=best.gemini?(best.geminiPct.toFixed(1)+'% remaining'+(best.geminiReset?(' · resets in '+fmtResetShort(best.geminiReset)):'')):(state.loading?'Checking...':'No quota data'); |
| 291 | 331 | ||
| 292 | $('kpiClaude').textContent=best.claude?shortEmail(best.claude):'-'; | 332 | $('kpiClaude').textContent=best.claude?shortEmail(best.claude):'-'; |
| 293 | $('kpiClaude').title=best.claude||''; | 333 | $('kpiClaude').title=best.claude||''; |
| 294 | - $('kpiClaudeMeta').textContent=best.claude?(best.claudePct.toFixed(1)+'% remaining'):(state.loading?'Checking...':'No quota data'); | 334 | + $('kpiClaudeMeta').textContent=best.claude?(best.claudePct.toFixed(1)+'% remaining'+(best.claudeReset?(' · resets in '+fmtResetShort(best.claudeReset)):'')):(state.loading?'Checking...':'No quota data'); |
| 295 | - | ||
| 296 | var wrap=$('accounts'); | 335 | var wrap=$('accounts'); |
| 297 | wrap.innerHTML=''; | 336 | wrap.innerHTML=''; |
| 298 | if(!state.accounts.length){ | 337 | if(!state.accounts.length){ |
| @@ -336,8 +375,18 @@ function render(){ | @@ -336,8 +375,18 @@ function render(){ | ||
| 336 | qd.models.forEach(function(m){ | 375 | qd.models.forEach(function(m){ |
| 337 | var row=el('div','mrow'); | 376 | var row=el('div','mrow'); |
| 338 | row.appendChild(el('span','mid',m.id)); | 377 | row.appendChild(el('span','mid',m.id)); |
| 378 | + var right=el('span','mright'); | ||
| 379 | + if(m.reset_time){ | ||
| 380 | + var mr=el('span','mrst',fmtResetShort(m.reset_time)); | ||
| 381 | + mr.setAttribute('data-reset',m.reset_time); | ||
| 382 | + mr.setAttribute('data-reset-mode','short'); | ||
| 383 | + var mt=Date.parse(m.reset_time); | ||
| 384 | + if(!isNaN(mt))mr.title='Resets at '+fmtClock(mt)+' ('+m.reset_time+')'; | ||
| 385 | + right.appendChild(mr); | ||
| 386 | + } | ||
| 339 | var cls=pctClass(m.pct,m.exhausted); | 387 | var cls=pctClass(m.pct,m.exhausted); |
| 340 | - row.appendChild(el('span','mpct '+cls,m.exhausted?'EXH':(m.pct.toFixed(1)+'%'))); | 388 | + right.appendChild(el('span','mpct '+cls,m.exhausted?'EXH':(m.pct.toFixed(1)+'%'))); |
| 389 | + row.appendChild(right); | ||
| 341 | mgrid.appendChild(row); | 390 | mgrid.appendChild(row); |
| 342 | }); | 391 | }); |
| 343 | card.appendChild(mgrid); | 392 | card.appendChild(mgrid); |
| @@ -346,7 +395,6 @@ function render(){ | @@ -346,7 +395,6 @@ function render(){ | ||
| 346 | wrap.appendChild(card); | 395 | wrap.appendChild(card); |
| 347 | }); | 396 | }); |
| 348 | } | 397 | } |
| 349 | - | ||
| 350 | function switchAccount(email,btn){ | 398 | function switchAccount(email,btn){ |
| 351 | btn.disabled=true; | 399 | btn.disabled=true; |
| 352 | btn.textContent='Switching...'; | 400 | btn.textContent='Switching...'; |
| @@ -457,6 +505,7 @@ $('themeToggle').onclick=function(){ | @@ -457,6 +505,7 @@ $('themeToggle').onclick=function(){ | ||
| 457 | window.sxApplyTheme(window.sxTheme()==='dark'?'light':'dark'); | 505 | window.sxApplyTheme(window.sxTheme()==='dark'?'light':'dark'); |
| 458 | } | 506 | } |
| 459 | }; | 507 | }; |
| 508 | +setInterval(refreshResetLabels,30000); | ||
| 460 | load(); | 509 | load(); |
| 461 | </script> | 510 | </script> |
| 462 | </body></html> | 511 | </body></html> |
| index e0c2767..eb9099c 100644 | index e0c2767..eb9099c 100644 | ||
| --- a/src/ui_html.h | --- a/src/ui_html.h | ||
| +++ b/src/ui_html.h | +++ b/src/ui_html.h | ||
| @@ -80,12 +80,13 @@ static const char *UI_HTML = | @@ -80,12 +80,13 @@ static const char *UI_HTML = | ||
| 80 | " grid-template-columns:repeat(2,minmax(0,1fr));gap:4px 14px}\n" | 80 | " grid-template-columns:repeat(2,minmax(0,1fr));gap:4px 14px}\n" |
| 81 | ".models.show{display:grid}\n" | 81 | ".models.show{display:grid}\n" |
| 82 | ".mrow{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:11.5px;padding:2px 0}\n" | 82 | ".mrow{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:11.5px;padding:2px 0}\n" |
| 83 | - ".mrow .mid{font-family:var(--mono);color:var(--text-2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n" | 83 | + ".mrow .mid{font-family:var(--mono);color:var(--text-2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}\n" |
| 84 | + ".mrow .mright{display:inline-flex;align-items:center;gap:8px;flex:0 0 auto}\n" | ||
| 85 | + ".mrow .mrst{font-family:var(--mono);font-size:11px;color:var(--text-2);white-space:nowrap}\n" | ||
| 84 | ".mrow .mpct{font-family:var(--mono);font-weight:650;flex:0 0 auto}\n" | 86 | ".mrow .mpct{font-family:var(--mono);font-weight:650;flex:0 0 auto}\n" |
| 85 | ".mrow .mpct.ok{color:var(--green)}\n" | 87 | ".mrow .mpct.ok{color:var(--green)}\n" |
| 86 | ".mrow .mpct.warn{color:var(--orange)}\n" | 88 | ".mrow .mpct.warn{color:var(--orange)}\n" |
| 87 | ".mrow .mpct.bad{color:var(--red)}\n" | 89 | ".mrow .mpct.bad{color:var(--red)}\n" |
| 88 | - ".err-msg{font-size:12px;color:var(--red);padding:4px 0}\n" | ||
| 89 | ".empty{padding:18px 16px;text-align:center;color:var(--text-2);font-size:13px}\n" | 90 | ".empty{padding:18px 16px;text-align:center;color:var(--text-2);font-size:13px}\n" |
| 90 | ".kv{display:grid;grid-template-columns:120px minmax(0,1fr);gap:5px 12px;font-size:12px}\n" | 91 | ".kv{display:grid;grid-template-columns:120px minmax(0,1fr);gap:5px 12px;font-size:12px}\n" |
| 91 | ".kv .k{color:var(--text-2)}\n" | 92 | ".kv .k{color:var(--text-2)}\n" |
| @@ -213,18 +214,51 @@ static const char *UI_HTML = | @@ -213,18 +214,51 @@ static const char *UI_HTML = | ||
| 213 | " if(pool.pct<0)return 'N/A';\n" | 214 | " if(pool.pct<0)return 'N/A';\n" |
| 214 | " return pool.pct.toFixed(1)+'%';\n" | 215 | " return pool.pct.toFixed(1)+'%';\n" |
| 215 | "}\n" | 216 | "}\n" |
| 217 | + "function pad2(n){return n<10?('0'+n):String(n);}\n" | ||
| 218 | + "function fmtClock(ms){\n" | ||
| 219 | + " var d=new Date(ms),now=new Date();\n" | ||
| 220 | + " var hm=pad2(d.getHours())+':'+pad2(d.getMinutes());\n" | ||
| 221 | + " if(d.getFullYear()===now.getFullYear()&&d.getMonth()===now.getMonth()&&d.getDate()===now.getDate())return hm;\n" | ||
| 222 | + " var mon=d.toLocaleString(undefined,{month:'short'});\n" | ||
| 223 | + " return mon+' '+d.getDate()+' '+hm;\n" | ||
| 224 | + "}\n" | ||
| 225 | + "function fmtResetShort(iso){\n" | ||
| 226 | + " if(!iso)return '-';\n" | ||
| 227 | + " var t=Date.parse(iso);\n" | ||
| 228 | + " if(isNaN(t))return iso;\n" | ||
| 229 | + " var diff=Math.floor((t-Date.now())/1000);\n" | ||
| 230 | + " if(diff<=0)return 'due';\n" | ||
| 231 | + " var totalH=Math.floor(diff/3600);\n" | ||
| 232 | + " var m=Math.floor((diff%3600)/60);\n" | ||
| 233 | + " if(totalH>0)return totalH+'h '+pad2(m)+'m';\n" | ||
| 234 | + " return Math.max(1,m)+'m';\n" | ||
| 235 | + "}\n" | ||
| 216 | "function fmtReset(iso){\n" | 236 | "function fmtReset(iso){\n" |
| 217 | " if(!iso)return 'Reset: -';\n" | 237 | " if(!iso)return 'Reset: -';\n" |
| 218 | " var t=Date.parse(iso);\n" | 238 | " var t=Date.parse(iso);\n" |
| 219 | " if(isNaN(t))return 'Reset: '+iso;\n" | 239 | " if(isNaN(t))return 'Reset: '+iso;\n" |
| 220 | " var diff=Math.floor((t-Date.now())/1000);\n" | 240 | " var diff=Math.floor((t-Date.now())/1000);\n" |
| 221 | - " if(diff<=0)return 'Resets soon';\n" | 241 | + " var clk=fmtClock(t);\n" |
| 242 | + " if(diff<=0)return 'Resets soon · '+clk;\n" | ||
| 243 | + " var totalH=Math.floor(diff/3600);\n" | ||
| 222 | " var d=Math.floor(diff/86400);\n" | 244 | " var d=Math.floor(diff/86400);\n" |
| 223 | " var h=Math.floor((diff%86400)/3600);\n" | 245 | " var h=Math.floor((diff%86400)/3600);\n" |
| 224 | " var m=Math.floor((diff%3600)/60);\n" | 246 | " var m=Math.floor((diff%3600)/60);\n" |
| 225 | - " if(d>0)return 'Resets in '+d+'d '+h+'h';\n" | 247 | + " if(totalH>=24)return 'Resets in '+totalH+'h '+pad2(m)+'m ('+d+'d '+h+'h) · '+clk;\n" |
| 226 | - " if(h>0)return 'Resets in '+h+'h '+m+'m';\n" | 248 | + " if(totalH>0)return 'Resets in '+totalH+'h '+pad2(m)+'m · '+clk;\n" |
| 227 | - " return 'Resets in '+Math.max(1,m)+'m';\n" | 249 | + " return 'Resets in '+Math.max(1,m)+'m · '+clk;\n" |
| 250 | + "}\n" | ||
| 251 | + "function refreshResetLabels(){\n" | ||
| 252 | + " var els=document.querySelectorAll('[data-reset]');\n" | ||
| 253 | + " for(var i=0;i<els.length;i++){\n" | ||
| 254 | + " var node=els[i];\n" | ||
| 255 | + " var iso=node.getAttribute('data-reset');\n" | ||
| 256 | + " if(!iso)continue;\n" | ||
| 257 | + " var mode=node.getAttribute('data-reset-mode')||'full';\n" | ||
| 258 | + " node.textContent=(mode==='short')?fmtResetShort(iso):fmtReset(iso);\n" | ||
| 259 | + " var t=Date.parse(iso);\n" | ||
| 260 | + " if(!isNaN(t))node.title='Resets at '+fmtClock(t)+' ('+iso+')';\n" | ||
| 261 | + " }\n" | ||
| 228 | "}\n" | 262 | "}\n" |
| 229 | "function el(tag,cls,txt){\n" | 263 | "function el(tag,cls,txt){\n" |
| 230 | " var n=document.createElement(tag);\n" | 264 | " var n=document.createElement(tag);\n" |
| @@ -234,18 +268,18 @@ static const char *UI_HTML = | @@ -234,18 +268,18 @@ static const char *UI_HTML = | ||
| 234 | "}\n" | 268 | "}\n" |
| 235 | "\n" | 269 | "\n" |
| 236 | "function computeBest(){\n" | 270 | "function computeBest(){\n" |
| 237 | - " var bestG=null,bestGP=-1,bestC=null,bestCP=-1;\n" | 271 | + " var bestG=null,bestGP=-1,bestGR='',bestC=null,bestCP=-1,bestCR='';\n" |
| 238 | " state.accounts.forEach(function(a){\n" | 272 | " state.accounts.forEach(function(a){\n" |
| 239 | " var qd=state.quotas[a.email];\n" | 273 | " var qd=state.quotas[a.email];\n" |
| 240 | " if(!qd||!qd.ok)return;\n" | 274 | " if(!qd||!qd.ok)return;\n" |
| 241 | " if(qd.gemini&&!qd.gemini.exhausted&&qd.gemini.pct>bestGP){\n" | 275 | " if(qd.gemini&&!qd.gemini.exhausted&&qd.gemini.pct>bestGP){\n" |
| 242 | - " bestGP=qd.gemini.pct;bestG=a.email;\n" | 276 | + " bestGP=qd.gemini.pct;bestG=a.email;bestGR=qd.gemini.reset_time||'';\n" |
| 243 | " }\n" | 277 | " }\n" |
| 244 | " if(qd.claude&&!qd.claude.exhausted&&qd.claude.pct>bestCP){\n" | 278 | " if(qd.claude&&!qd.claude.exhausted&&qd.claude.pct>bestCP){\n" |
| 245 | - " bestCP=qd.claude.pct;bestC=a.email;\n" | 279 | + " bestCP=qd.claude.pct;bestC=a.email;bestCR=qd.claude.reset_time||'';\n" |
| 246 | " }\n" | 280 | " }\n" |
| 247 | " });\n" | 281 | " });\n" |
| 248 | - " return {gemini:bestG,geminiPct:bestGP,claude:bestC,claudePct:bestCP};\n" | 282 | + " return {gemini:bestG,geminiPct:bestGP,geminiReset:bestGR,claude:bestC,claudePct:bestCP,claudeReset:bestCR};\n" |
| 249 | "}\n" | 283 | "}\n" |
| 250 | "\n" | 284 | "\n" |
| 251 | "function renderPool(label,pool,loading){\n" | 285 | "function renderPool(label,pool,loading){\n" |
| @@ -275,6 +309,12 @@ static const char *UI_HTML = | @@ -275,6 +309,12 @@ static const char *UI_HTML = | ||
| 275 | " fill.className=cls;\n" | 309 | " fill.className=cls;\n" |
| 276 | " fill.style.width=w.toFixed(1)+'%';\n" | 310 | " fill.style.width=w.toFixed(1)+'%';\n" |
| 277 | " rst.textContent=fmtReset(pool.reset_time);\n" | 311 | " rst.textContent=fmtReset(pool.reset_time);\n" |
| 312 | + " if(pool.reset_time){\n" | ||
| 313 | + " rst.setAttribute('data-reset',pool.reset_time);\n" | ||
| 314 | + " rst.setAttribute('data-reset-mode','full');\n" | ||
| 315 | + " var rt=Date.parse(pool.reset_time);\n" | ||
| 316 | + " if(!isNaN(rt))rst.title='Resets at '+fmtClock(rt)+' ('+pool.reset_time+')';\n" | ||
| 317 | + " }\n" | ||
| 278 | " }\n" | 318 | " }\n" |
| 279 | " hd.appendChild(pctEl);\n" | 319 | " hd.appendChild(pctEl);\n" |
| 280 | " bar.appendChild(fill);\n" | 320 | " bar.appendChild(fill);\n" |
| @@ -292,12 +332,11 @@ static const char *UI_HTML = | @@ -292,12 +332,11 @@ static const char *UI_HTML = | ||
| 292 | "\n" | 332 | "\n" |
| 293 | " $('kpiGemini').textContent=best.gemini?shortEmail(best.gemini):'-';\n" | 333 | " $('kpiGemini').textContent=best.gemini?shortEmail(best.gemini):'-';\n" |
| 294 | " $('kpiGemini').title=best.gemini||'';\n" | 334 | " $('kpiGemini').title=best.gemini||'';\n" |
| 295 | - " $('kpiGeminiMeta').textContent=best.gemini?(best.geminiPct.toFixed(1)+'% remaining'):(state.loading?'Checking...':'No quota data');\n" | 335 | + " $('kpiGeminiMeta').textContent=best.gemini?(best.geminiPct.toFixed(1)+'% remaining'+(best.geminiReset?(' · resets in '+fmtResetShort(best.geminiReset)):'')):(state.loading?'Checking...':'No quota data');\n" |
| 296 | "\n" | 336 | "\n" |
| 297 | " $('kpiClaude').textContent=best.claude?shortEmail(best.claude):'-';\n" | 337 | " $('kpiClaude').textContent=best.claude?shortEmail(best.claude):'-';\n" |
| 298 | " $('kpiClaude').title=best.claude||'';\n" | 338 | " $('kpiClaude').title=best.claude||'';\n" |
| 299 | - " $('kpiClaudeMeta').textContent=best.claude?(best.claudePct.toFixed(1)+'% remaining'):(state.loading?'Checking...':'No quota data');\n" | 339 | + " $('kpiClaudeMeta').textContent=best.claude?(best.claudePct.toFixed(1)+'% remaining'+(best.claudeReset?(' · resets in '+fmtResetShort(best.claudeReset)):'')):(state.loading?'Checking...':'No quota data');\n" |
| 300 | - "\n" | ||
| 301 | " var wrap=$('accounts');\n" | 340 | " var wrap=$('accounts');\n" |
| 302 | " wrap.innerHTML='';\n" | 341 | " wrap.innerHTML='';\n" |
| 303 | " if(!state.accounts.length){\n" | 342 | " if(!state.accounts.length){\n" |
| @@ -341,8 +380,18 @@ static const char *UI_HTML = | @@ -341,8 +380,18 @@ static const char *UI_HTML = | ||
| 341 | " qd.models.forEach(function(m){\n" | 380 | " qd.models.forEach(function(m){\n" |
| 342 | " var row=el('div','mrow');\n" | 381 | " var row=el('div','mrow');\n" |
| 343 | " row.appendChild(el('span','mid',m.id));\n" | 382 | " row.appendChild(el('span','mid',m.id));\n" |
| 383 | + " var right=el('span','mright');\n" | ||
| 384 | + " if(m.reset_time){\n" | ||
| 385 | + " var mr=el('span','mrst',fmtResetShort(m.reset_time));\n" | ||
| 386 | + " mr.setAttribute('data-reset',m.reset_time);\n" | ||
| 387 | + " mr.setAttribute('data-reset-mode','short');\n" | ||
| 388 | + " var mt=Date.parse(m.reset_time);\n" | ||
| 389 | + " if(!isNaN(mt))mr.title='Resets at '+fmtClock(mt)+' ('+m.reset_time+')';\n" | ||
| 390 | + " right.appendChild(mr);\n" | ||
| 391 | + " }\n" | ||
| 344 | " var cls=pctClass(m.pct,m.exhausted);\n" | 392 | " var cls=pctClass(m.pct,m.exhausted);\n" |
| 345 | - " row.appendChild(el('span','mpct '+cls,m.exhausted?'EXH':(m.pct.toFixed(1)+'%')));\n" | 393 | + " right.appendChild(el('span','mpct '+cls,m.exhausted?'EXH':(m.pct.toFixed(1)+'%')));\n" |
| 394 | + " row.appendChild(right);\n" | ||
| 346 | " mgrid.appendChild(row);\n" | 395 | " mgrid.appendChild(row);\n" |
| 347 | " });\n" | 396 | " });\n" |
| 348 | " card.appendChild(mgrid);\n" | 397 | " card.appendChild(mgrid);\n" |
| @@ -351,7 +400,6 @@ static const char *UI_HTML = | @@ -351,7 +400,6 @@ static const char *UI_HTML = | ||
| 351 | " wrap.appendChild(card);\n" | 400 | " wrap.appendChild(card);\n" |
| 352 | " });\n" | 401 | " });\n" |
| 353 | "}\n" | 402 | "}\n" |
| 354 | - "\n" | ||
| 355 | "function switchAccount(email,btn){\n" | 403 | "function switchAccount(email,btn){\n" |
| 356 | " btn.disabled=true;\n" | 404 | " btn.disabled=true;\n" |
| 357 | " btn.textContent='Switching...';\n" | 405 | " btn.textContent='Switching...';\n" |
| @@ -462,6 +510,7 @@ static const char *UI_HTML = | @@ -462,6 +510,7 @@ static const char *UI_HTML = | ||
| 462 | " window.sxApplyTheme(window.sxTheme()==='dark'?'light':'dark');\n" | 510 | " window.sxApplyTheme(window.sxTheme()==='dark'?'light':'dark');\n" |
| 463 | " }\n" | 511 | " }\n" |
| 464 | "};\n" | 512 | "};\n" |
| 513 | + "setInterval(refreshResetLabels,30000);\n" | ||
| 465 | "load();\n" | 514 | "load();\n" |
| 466 | "</script>\n" | 515 | "</script>\n" |
| 467 | "\002</body></html>\n" | 516 | "\002</body></html>\n" |
| index 1169c80..33af6e9 100755 | index 1169c80..33af6e9 100755 | ||
| --- a/tests/mock_quota.sh | --- a/tests/mock_quota.sh | ||
| +++ b/tests/mock_quota.sh | +++ b/tests/mock_quota.sh | ||
| @@ -21,9 +21,12 @@ fi | @@ -21,9 +21,12 @@ fi | ||
| 21 | 21 | ||
| 22 | echo "INFO : ya29.MOCK-TOKEN-MUST-NOT-LEAK" >&2 | 22 | echo "INFO : ya29.MOCK-TOKEN-MUST-NOT-LEAK" >&2 |
| 23 | 23 | ||
| 24 | +RST_CLAUDE="${MOCK_RESET_CLAUDE:-2026-11-25T06:00:00Z}" | ||
| 25 | +RST_GEMINI="${MOCK_RESET_GEMINI:-2026-11-25T03:00:00Z}" | ||
| 26 | + | ||
| 24 | case "$acct" in | 27 | case "$acct" in |
| 25 | alpha@example.com) | 28 | alpha@example.com) |
| 26 | - cat <<'EOF' | 29 | + cat <<EOF |
| 27 | { | 30 | { |
| 28 | "ok": true, | 31 | "ok": true, |
| 29 | "email": "alpha@example.com", | 32 | "email": "alpha@example.com", |
| @@ -31,10 +34,10 @@ case "$acct" in | @@ -31,10 +34,10 @@ case "$acct" in | ||
| 31 | "endpoint": "https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota", | 34 | "endpoint": "https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota", |
| 32 | "buckets": [ | 35 | "buckets": [ |
| 33 | {"tokenType": "WTUS", "modelId": "chat_20706", "remainingFraction": 1}, | 36 | {"tokenType": "WTUS", "modelId": "chat_20706", "remainingFraction": 1}, |
| 34 | - {"resetTime": "2026-11-25T06:00:00Z", "tokenType": "WTUS", "modelId": "claude-opus-4-6-thinking", "remainingFraction": 1}, | 37 | + {"resetTime": "$RST_CLAUDE", "tokenType": "WTUS", "modelId": "claude-opus-4-6-thinking", "remainingFraction": 1}, |
| 35 | - {"resetTime": "2026-11-25T06:00:00Z", "tokenType": "WTUS", "modelId": "claude-sonnet-4-6", "remainingFraction": 1}, | 38 | + {"resetTime": "$RST_CLAUDE", "tokenType": "WTUS", "modelId": "claude-sonnet-4-6", "remainingFraction": 1}, |
| 36 | - {"resetTime": "2026-11-25T03:00:00Z", "tokenType": "WTUS", "modelId": "gemini-3.8-flash-tiered", "remainingFraction": 0.855}, | 39 | + {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-3.8-flash-tiered", "remainingFraction": 0.855}, |
| 37 | - {"resetTime": "2026-11-25T03:00:00Z", "tokenType": "WTUS", "modelId": "gemini-4-hydrogen-sonar", "remainingFraction": 0.855}, | 40 | + {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-4-hydrogen-sonar", "remainingFraction": 0.855}, |
| 38 | {"tokenType": "WTUS", "modelId": "tab_flash_lite_preview", "remainingFraction": 1} | 41 | {"tokenType": "WTUS", "modelId": "tab_flash_lite_preview", "remainingFraction": 1} |
| 39 | ] | 42 | ] |
| 40 | } | 43 | } |
| @@ -42,16 +45,16 @@ EOF | @@ -42,16 +45,16 @@ EOF | ||
| 42 | exit 0 | 45 | exit 0 |
| 43 | ;; | 46 | ;; |
| 44 | beta@example.com) | 47 | beta@example.com) |
| 45 | - cat <<'EOF' | 48 | + cat <<EOF |
| 46 | { | 49 | { |
| 47 | "ok": true, | 50 | "ok": true, |
| 48 | "email": "beta@example.com", | 51 | "email": "beta@example.com", |
| 49 | "project": "aicode-consumers", | 52 | "project": "aicode-consumers", |
| 50 | "endpoint": "https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota", | 53 | "endpoint": "https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota", |
| 51 | "buckets": [ | 54 | "buckets": [ |
| 52 | - {"resetTime": "2026-11-25T08:00:00Z", "tokenType": "WTUS", "modelId": "claude-sonnet-4-6", "remainingFraction": 0.42}, | 55 | + {"resetTime": "$RST_CLAUDE", "tokenType": "WTUS", "modelId": "claude-sonnet-4-6", "remainingFraction": 0.42}, |
| 53 | - {"resetTime": "2026-11-25T04:00:00Z", "tokenType": "WTUS", "modelId": "gemini-3.8-flash-tiered", "remainingFraction": null}, | 56 | + {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-3.8-flash-tiered", "remainingFraction": null}, |
| 54 | - {"resetTime": "2026-11-25T04:00:00Z", "tokenType": "WTUS", "modelId": "gemini-4-hydrogen-sonar"} | 57 | + {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-4-hydrogen-sonar"} |
| 55 | ] | 58 | ] |
| 56 | } | 59 | } |
| 57 | EOF | 60 | EOF |
| index fc73f17..cc47abc 100755 | index fc73f17..cc47abc 100755 | ||
| --- a/tests/run.sh | --- a/tests/run.sh | ||
| +++ b/tests/run.sh | +++ b/tests/run.sh | ||
| @@ -81,8 +81,8 @@ mkdir -p "$FIX/none" "$FIX/empty" "$FIX/full" | @@ -81,8 +81,8 @@ mkdir -p "$FIX/none" "$FIX/empty" "$FIX/full" | ||
| 81 | chmod +x "$ROOT/tests/mock_quota.sh" | 81 | chmod +x "$ROOT/tests/mock_quota.sh" |
| 82 | export GOOGLE_QUOTA_BIN="$ROOT/tests/mock_quota.sh" | 82 | export GOOGLE_QUOTA_BIN="$ROOT/tests/mock_quota.sh" |
| 83 | export GOOGLE_ACCESS_TOKEN="ya29.INHERITED-TOKEN-MUST-BE-CLEARED" | 83 | export GOOGLE_ACCESS_TOKEN="ya29.INHERITED-TOKEN-MUST-BE-CLEARED" |
| 84 | - | 84 | +export MOCK_RESET_CLAUDE=$(python3 -c "from datetime import datetime,timedelta,timezone; print((datetime.now(timezone.utc)+timedelta(hours=2,minutes=15)).strftime('%Y-%m-%dT%H:%M:%SZ'))") |
| 85 | -: > "$FIX/empty/antigravity_accounts.json" | 85 | +export MOCK_RESET_GEMINI=$(python3 -c "from datetime import datetime,timedelta,timezone; print((datetime.now(timezone.utc)+timedelta(hours=144,minutes=30)).strftime('%Y-%m-%dT%H:%M:%SZ'))") |
| 86 | 86 | ||
| 87 | cat > "$FIX/full/antigravity_accounts.json" <<'EOF' | 87 | cat > "$FIX/full/antigravity_accounts.json" <<'EOF' |
| 88 | [ | 88 | [ |
| @@ -102,8 +102,7 @@ META_ENV=$(BOT_PASSWORD=secret-pass SX_PLUGIN_META=1 $BIN) | @@ -102,8 +102,7 @@ META_ENV=$(BOT_PASSWORD=secret-pass SX_PLUGIN_META=1 $BIN) | ||
| 102 | check "SX_PLUGIN_META=1 works without auth" '{"name":"google quota","desc":"Account quotas"}' "$META_ENV" | 102 | check "SX_PLUGIN_META=1 works without auth" '{"name":"google quota","desc":"Account quotas"}' "$META_ENV" |
| 103 | 103 | ||
| 104 | VER=$($BIN --version) | 104 | VER=$($BIN --version) |
| 105 | -check "--version prints plugin id and version" "plugin_google_quota 1.0.0" "$VER" | 105 | +check "--version prints plugin id and version" "plugin_google_quota 1.0.1" "$VER" |
| 106 | - | ||
| 107 | UNAUTH=$(BOT_PASSWORD=secret-pass QUERY_STRING="action=status" $BIN) | 106 | UNAUTH=$(BOT_PASSWORD=secret-pass QUERY_STRING="action=status" $BIN) |
| 108 | check "missing password returns 401" "Status: 401 Unauthorized" "$UNAUTH" | 107 | check "missing password returns 401" "Status: 401 Unauthorized" "$UNAUTH" |
| 109 | 108 | ||
| @@ -135,15 +134,14 @@ json_ok "missing CLI sets cli_present false" "$ST_NOCLI" "d['ok'] is True and d[ | @@ -135,15 +134,14 @@ json_ok "missing CLI sets cli_present false" "$ST_NOCLI" "d['ok'] is True and d[ | ||
| 135 | # ---------------------------------------------------------------- quota | 134 | # ---------------------------------------------------------------- quota |
| 136 | section "quota" | 135 | section "quota" |
| 137 | Q_ONE=$(GOOGLE_ACCOUNTS_FILE="$FIX/full/antigravity_accounts.json" api "action=quota&account=alpha@example.com") | 136 | Q_ONE=$(GOOGLE_ACCOUNTS_FILE="$FIX/full/antigravity_accounts.json" api "action=quota&account=alpha@example.com") |
| 138 | -json_ok "single account quota parses gemini and claude pools" "$Q_ONE" \ | 137 | +json_ok "single account quota parses gemini and claude pools and remaining hours" "$Q_ONE" \ |
| 139 | - "d['ok'] is True and d['account']['ok'] is True and abs(d['account']['gemini']['pct'] - 85.5) < 0.01 and abs(d['account']['claude']['pct'] - 100.0) < 0.01 and len(d['account']['models']) == 4" | 138 | + "d['ok'] is True and d['account']['ok'] is True and abs(d['account']['gemini']['pct'] - 85.5) < 0.01 and abs(d['account']['claude']['pct'] - 100.0) < 0.01 and len(d['account']['models']) == 4 and d['account']['gemini']['reset_in_seconds'] > 500000 and d['account']['gemini']['reset_in_hours'] > 140 and 'h ' in d['account']['gemini']['reset_remaining'] and d['account']['claude']['reset_in_seconds'] > 7000 and 'h ' in d['account']['claude']['reset_remaining'] and all('reset_remaining' in m and 'reset_in_hours' in m for m in d['account']['models'])" |
| 140 | check_not "single quota never leaks token" "MOCK-TOKEN" "$Q_ONE" | 139 | check_not "single quota never leaks token" "MOCK-TOKEN" "$Q_ONE" |
| 141 | check_not "single quota never leaks refresh token" "MOCK-REFRESH-TOKEN" "$Q_ONE" | 140 | check_not "single quota never leaks refresh token" "MOCK-REFRESH-TOKEN" "$Q_ONE" |
| 142 | 141 | ||
| 143 | Q_EXH=$(GOOGLE_ACCOUNTS_FILE="$FIX/full/antigravity_accounts.json" api "action=quota&account=beta@example.com") | 142 | Q_EXH=$(GOOGLE_ACCOUNTS_FILE="$FIX/full/antigravity_accounts.json" api "action=quota&account=beta@example.com") |
| 144 | -json_ok "null/missing remainingFraction marks gemini pool exhausted" "$Q_EXH" \ | 143 | +json_ok "null/missing remainingFraction marks gemini pool exhausted with reset remaining" "$Q_EXH" \ |
| 145 | - "d['ok'] is True and d['account']['gemini']['exhausted'] is True and d['account']['gemini']['pct'] == 0.0 and abs(d['account']['claude']['pct'] - 42.0) < 0.01" | 144 | + "d['ok'] is True and d['account']['gemini']['exhausted'] is True and d['account']['gemini']['pct'] == 0.0 and abs(d['account']['claude']['pct'] - 42.0) < 0.01 and d['account']['gemini']['reset_in_hours'] > 140 and 'h ' in d['account']['gemini']['reset_remaining']" |
| 146 | - | ||
| 147 | Q_ALL=$(GOOGLE_ACCOUNTS_FILE="$FIX/full/antigravity_accounts.json" api "action=quota") | 145 | Q_ALL=$(GOOGLE_ACCOUNTS_FILE="$FIX/full/antigravity_accounts.json" api "action=quota") |
| 148 | json_ok "all-accounts quota aggregates best_gemini, best_claude, and broken account" "$Q_ALL" \ | 146 | json_ok "all-accounts quota aggregates best_gemini, best_claude, and broken account" "$Q_ALL" \ |
| 149 | "d['ok'] is True and d['count'] == 3 and d['best_gemini'] == 'alpha@example.com' and d['best_claude'] == 'alpha@example.com' and d['accounts'][2]['ok'] is False" | 147 | "d['ok'] is True and d['count'] == 3 and d['best_gemini'] == 'alpha@example.com' and d['best_claude'] == 'alpha@example.com' and d['accounts'][2]['ok'] is False" |
| @@ -182,11 +180,13 @@ check "HTML includes bot theme prepaint" "bot_theme" "$HTML" | @@ -182,11 +180,13 @@ check "HTML includes bot theme prepaint" "bot_theme" "$HTML" | ||
| 182 | check "HTML includes theme handoff" "sx-theme-request" "$HTML" | 180 | check "HTML includes theme handoff" "sx-theme-request" "$HTML" |
| 183 | check "HTML uses two-route API helper" "plugin_google_quota" "$HTML" | 181 | check "HTML uses two-route API helper" "plugin_google_quota" "$HTML" |
| 184 | check "HTML hub proxy URL uses &action= separator" "'/plugins?plugin='+encodeURIComponent(HUB)+'&'" "$HTML" | 182 | check "HTML hub proxy URL uses &action= separator" "'/plugins?plugin='+encodeURIComponent(HUB)+'&'" "$HTML" |
| 183 | +check "HTML formats total remaining hours even >= 24h" "totalH>=24" "$HTML" | ||
| 184 | +check "HTML renders per-model reset remaining hours" "fmtResetShort" "$HTML" | ||
| 185 | +check "HTML includes live reset countdown attributes" "data-reset" "$HTML" | ||
| 185 | check "HTML hides theme toggle in embed mode" "embed-hide" "$HTML" | 186 | check "HTML hides theme toggle in embed mode" "embed-hide" "$HTML" |
| 186 | check_not "HTML loads no CDN script" "<script src=" "$HTML" | 187 | check_not "HTML loads no CDN script" "<script src=" "$HTML" |
| 187 | check_not "HTML references no external host script" "cdnjs" "$HTML" | 188 | check_not "HTML references no external host script" "cdnjs" "$HTML" |
| 188 | check_not "HTML makes no outbound fetch to googleapis" "googleapis.com" "$HTML" | 189 | check_not "HTML makes no outbound fetch to googleapis" "googleapis.com" "$HTML" |
| 189 | - | ||
| 190 | printf '%s' "$HTML" > "$FIX/page.html" | 190 | printf '%s' "$HTML" > "$FIX/page.html" |
| 191 | if python3 - "$FIX/page.html" <<'PY' | 191 | if python3 - "$FIX/page.html" <<'PY' |
| 192 | import re, sys | 192 | import re, sys |
| 193 | 193 |