quotacap 0.0.57 → 0.0.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +1 -1
  2. package/dist/adapters/muse.d.ts +1 -1
  3. package/dist/adapters/muse.js +5 -3
  4. package/dist/advisory/engine.js +9 -5
  5. package/dist/advisory/snapshot.js +10 -11
  6. package/dist/cli/advise.d.ts +1 -1
  7. package/dist/cli/advise.js +9 -4
  8. package/dist/cli/models.js +2 -2
  9. package/dist/cli/status.js +2 -2
  10. package/dist/format/markdown.d.ts +1 -1
  11. package/dist/format/markdown.js +11 -8
  12. package/dist/format/rate-limit-wait.d.ts +38 -0
  13. package/dist/format/rate-limit-wait.js +86 -0
  14. package/dist/format/rows.d.ts +46 -6
  15. package/dist/format/rows.js +50 -42
  16. package/dist/format/terminal.d.ts +1 -1
  17. package/dist/format/terminal.js +28 -14
  18. package/dist/format/time.d.ts +19 -0
  19. package/dist/format/time.js +69 -0
  20. package/dist/mcp/server.d.ts +25 -5
  21. package/dist/mcp/server.js +38 -4
  22. package/dist/store/quotas.d.ts +7 -2
  23. package/dist/store/quotas.js +94 -15
  24. package/dist/version.js +1 -1
  25. package/dist/web/src/components/AdviceDrawer.d.ts +3 -1
  26. package/dist/web/src/components/AdviceDrawer.js +25 -4
  27. package/dist/web/src/components/ClosedWeeks.d.ts +4 -1
  28. package/dist/web/src/components/ClosedWeeks.js +17 -5
  29. package/dist/web/src/components/PaceBar.d.ts +26 -25
  30. package/dist/web/src/components/PaceBar.js +57 -119
  31. package/dist/web/src/components/PacingLegend.js +9 -8
  32. package/dist/web/src/components/ProviderCard.js +2 -1
  33. package/dist/web/src/components/ProviderDrawer.d.ts +9 -2
  34. package/dist/web/src/components/ProviderDrawer.js +38 -27
  35. package/dist/web/src/components/ProviderRow.js +2 -1
  36. package/dist/web/src/components/RateLimitNote.d.ts +7 -0
  37. package/dist/web/src/components/RateLimitNote.js +11 -0
  38. package/dist/web/src/components/Recommendation.d.ts +4 -3
  39. package/dist/web/src/components/Recommendation.js +11 -7
  40. package/dist/web/src/components/ResetRail.d.ts +2 -0
  41. package/dist/web/src/components/ResetRail.js +15 -5
  42. package/dist/web/src/components/WindowsRow.d.ts +2 -2
  43. package/dist/web/src/components/WindowsRow.js +3 -13
  44. package/dist/web/src/components/settings/ProvidersPanel.d.ts +3 -2
  45. package/dist/web/src/components/settings/ProvidersPanel.js +4 -1
  46. package/dist/web/src/pages/Onboarding.js +1 -1
  47. package/dist/web/src/state.d.ts +5 -0
  48. package/dist/web/src/state.js +18 -0
  49. package/dist/webAssets.js +1 -1
  50. package/dist/webHtml.js +1 -1
  51. package/package.json +1 -1
  52. package/web/dist/assets/index-DQ2jUHo6.js +13 -0
  53. package/web/dist/assets/index-DSNVHbgI.css +1 -0
  54. package/web/dist/index.html +2 -2
  55. package/web/dist/assets/index-BFBVZ1r_.js +0 -13
  56. package/web/dist/assets/index-Co33DTl5.css +0 -1
@@ -1,11 +1,12 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useRef, useState } from "react";
3
3
  import { ageDuration, displayPlan, providerSubtitle, shortWindowLabel } from "../state.js";
4
- import { Badge, PACE_TIPS, daysToDuration, edgeToken, exclusionDetail, fillToken, forecastLine, isEstimated, isMonthlyBound, monthlyWindowStartIso, paceBadge, paceHeadline, paceFigures, quotaResetsAt, quotaWindowName, quotaWindowStartIso, resetClock, resetDateClock, timeLeft, } from "./PaceBar.js";
4
+ import { Badge, PACE_TIPS, daysToDuration, edgeToken, exclusionDetail, fillToken, forecastLine, isEstimated, isMonthlyBound, monthlyWindowStartIso, paceBadge, paceHeadline, paceFigures, quotaResetsAt, quotaWindowName, quotaWindowStartIso, resetClock, resetDateClock, timeLeft, unusedLine, } from "./PaceBar.js";
5
5
  import { ProviderIcon, providerTint } from "./ProviderIcon.js";
6
6
  import { BurnDown } from "./BurnDown.js";
7
7
  import { ClosedWeeks } from "./ClosedWeeks.js";
8
8
  import { trackFillForPct } from "./WindowsRow.js";
9
+ import { RateLimitNote } from "./RateLimitNote.js";
9
10
  import { laneOf } from "./Recommendation.js";
10
11
  import { renameProvider } from "../api.js";
11
12
  export function exclusionWords(reason) {
@@ -135,6 +136,20 @@ export function paceBasis(provider, asOfMs) {
135
136
  }
136
137
  return "No current reading";
137
138
  }
139
+ /**
140
+ * The rate the verdict and waste are priced at, named once so "forecast
141
+ * pace" in the copy points at a visible figure. Null unless both inputs of
142
+ * the blend exist: with one input the forecast equals a figure already
143
+ * shown in the grid.
144
+ */
145
+ export function forecastBasis(provider) {
146
+ const a = provider.advisory;
147
+ if (!a || isMonthlyBound(provider) || a.burnRate === null)
148
+ return null;
149
+ if (a.recentRate == null || a.baselineRate == null)
150
+ return null;
151
+ return `forecast ${a.burnRate.toFixed(1)}%/day (24h blended with history)`;
152
+ }
138
153
  export function credentialLabel(provider) {
139
154
  const source = provider.quota?.source;
140
155
  if (provider.id === "opencode-go" && source === "api") {
@@ -267,7 +282,7 @@ export function monthlyMeta(provider) {
267
282
  }
268
283
  /**
269
284
  * Drawer verdict band from lane, binding window, and forecast fields.
270
- * Precedence: excluded or monthly-exhausted, monthly-bound, use-more lane,
285
+ * Precedence: excluded or monthly-exhausted, capped, monthly-bound, use-more lane,
271
286
  * ease-off lane or at-risk/watch status, otherwise on track.
272
287
  */
273
288
  export function verdictFor(provider, asOfMs) {
@@ -293,6 +308,11 @@ export function verdictFor(provider, asOfMs) {
293
308
  if (!advisory) {
294
309
  return { tone: "neutral", label: "• On track", detail: forecastLine(provider) };
295
310
  }
311
+ if (advisory.remaining <= 0 || paceBadge(provider) === "Quota exhausted") {
312
+ const reset = quotaResetsAt(provider);
313
+ const clock = reset ? resetClock(reset) : null;
314
+ return { tone: "neutral", label: "• Capped", detail: clock ? `until ${clock}` : "quota fully used" };
315
+ }
296
316
  if (advisory.bindingWindow === "monthly" && advisory.bindingRemaining > 0) {
297
317
  return {
298
318
  tone: "use-more",
@@ -302,28 +322,15 @@ export function verdictFor(provider, asOfMs) {
302
322
  }
303
323
  const lane = laneOf(advisory, provider.exclusionReason);
304
324
  if (lane === "use-more") {
305
- const waste = advisory.wastePct !== null && Number.isFinite(advisory.wastePct)
306
- ? Math.round(advisory.wastePct)
307
- : null;
308
- const quotaReset = quotaResetsAt(provider);
309
- const left = quotaReset && asOfMs !== undefined
310
- ? timeLeft(quotaReset, asOfMs)
311
- : Number.isFinite(advisory.bindingDaysLeft ?? advisory.daysLeft)
312
- ? daysToDuration(advisory.bindingDaysLeft ?? advisory.daysLeft)
313
- : null;
314
- const detail = waste !== null && left
315
- ? `${waste}% waste forecast · resets in ${left}`
316
- : waste !== null
317
- ? `${waste}% waste forecast`
318
- : forecastLine(provider);
325
+ const detail = advisory.wastePct !== null && Number.isFinite(advisory.wastePct)
326
+ ? unusedLine(provider, advisory.wastePct)
327
+ : forecastLine(provider);
319
328
  return { tone: "use-more", label: "↑ Use more", detail };
320
329
  }
321
330
  if (lane === "ease-off" || advisory.status === "at risk" || advisory.status === "watch") {
322
- const detail = advisory.remaining <= 0 || paceBadge(provider) === "Quota exhausted"
323
- ? "quota fully used"
324
- : advisory.daysToExhaust !== null && Number.isFinite(advisory.daysToExhaust)
325
- ? `exhausts in ${daysToDuration(advisory.daysToExhaust)} at current pace`
326
- : paceBadge(provider);
331
+ const detail = advisory.daysToExhaust !== null && Number.isFinite(advisory.daysToExhaust)
332
+ ? `exhausts in ${daysToDuration(advisory.daysToExhaust)} at forecast pace`
333
+ : paceBadge(provider);
327
334
  return { tone: "ease-off", label: "↓ Ease off", detail };
328
335
  }
329
336
  return { tone: "neutral", label: "• On track", detail: forecastLine(provider) };
@@ -342,7 +349,7 @@ export async function submitProviderRename(id, rawDraft, renameFn) {
342
349
  /**
343
350
  * Compact forecast for a drawer limit line. The verdict band and Pace
344
351
  * section carry the full pace story, so the row keeps only the outcome:
345
- * status words and "at current pace" are dropped, and a status-only
352
+ * status words and "at forecast pace" are dropped, and a status-only
346
353
  * headline with no figure is left to the verdict.
347
354
  */
348
355
  export function compactLimitForecast(provider) {
@@ -355,7 +362,7 @@ export function compactLimitForecast(provider) {
355
362
  .replace(/^(Cap risk|Watch) · /, "")
356
363
  .replace(/^Measuring pace · /, "")
357
364
  .replace(/^Exhausted · /, "")
358
- .replace(/ at current pace$/, "");
365
+ .replace(/ at forecast pace$/, "");
359
366
  if (!/\d/.test(text) && text !== "quota fully used")
360
367
  return null;
361
368
  return { ...headline, text };
@@ -481,9 +488,13 @@ export function ProviderDrawer({ provider, asOf, recommendation, onClose, onRena
481
488
  }
482
489
  const showCredential = provider.id === "opencode-go" && provider.quota?.source === "api";
483
490
  const paceFigs = paceFigures(provider.advisory);
484
- const paceBasisLine = provider.advisory && paceFigs.avg === null && paceFigs.recent !== null
485
- ? PACE_TIPS.recent
486
- : paceBasis(provider, asOfMs);
491
+ const forecastNote = forecastBasis(provider);
492
+ const paceBasisLine = [
493
+ provider.advisory && paceFigs.avg === null && paceFigs.recent !== null
494
+ ? PACE_TIPS.recent
495
+ : paceBasis(provider, asOfMs),
496
+ forecastNote,
497
+ ].filter(Boolean).join(" · ");
487
498
  const weeklyResetLine = underlineParts ? (_jsxs("div", { className: "winrow-sub reset-line", children: ["Resets ", _jsx("strong", { children: underlineParts.stamp }), underlineParts.left && (_jsxs(_Fragment, { children: [" ", "\u00B7 in ", _jsx("strong", { children: underlineParts.left })] }))] })) : (_jsx("div", { className: "winrow-sub", children: "Reset not reported" }));
488
499
  const monthlyResetLine = monthlyReset ? (_jsxs("div", { className: "winrow-sub reset-line", children: ["Resets ", _jsx("strong", { children: monthlyReset.stamp }), monthlyReset.left && (_jsxs(_Fragment, { children: [" ", "\u00B7 in ", _jsx("strong", { children: monthlyReset.left })] }))] })) : (_jsx("div", { className: "winrow-sub", children: "Reset not reported" }));
489
500
  const fiveClock = model.fiveHourResetsAt ? resetClock(model.fiveHourResetsAt) : null;
@@ -568,5 +579,5 @@ export function ProviderDrawer({ provider, asOf, recommendation, onClose, onRena
568
579
  setIsEditing(false);
569
580
  setNameDraft(provider.displayName);
570
581
  setRenameError(null);
571
- }, className: "btn btn-quiet btn-sm", style: { flex: "none" }, children: "Cancel" })] }), renameError && (_jsx("span", { style: { fontSize: "var(--t-2)", color: "var(--danger)" }, children: renameError }))] })), provider.builtinName && provider.displayName !== provider.builtinName && (_jsx("div", { className: "sub", style: { marginTop: "2px" }, "data-testid": "provider-builtin-name", children: `Built-in: ${provider.builtinName}` })), _jsx("span", { className: "sub", children: providerSubtitle(provider) ?? sub })] }), _jsx(Badge, { provider: provider, compact: true }), _jsx("button", { className: "drawer-close", type: "button", "aria-label": "Close provider details", onClick: onClose, children: _jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "M6 6l12 12M18 6L6 18" }) }) })] }), _jsxs("div", { className: `verdict ${verdict.tone}`, "data-testid": "drawer-verdict", children: [_jsx("b", { children: verdict.label }), verdict.detail && _jsx("span", { children: verdict.detail })] }), provider.description && _jsx("p", { className: "drawer-desc", children: provider.description }), notes.length > 0 && (_jsxs("section", { className: "dsec", "aria-label": "Notes", children: [_jsx("h3", { children: "Notes" }), _jsx("div", { className: "notes-list", children: notes.map((n) => (_jsxs("div", { className: "note", children: [_jsx("span", { className: `dot ${n.dot}`, "aria-hidden": "true" }), _jsx("span", { children: n.text })] }, n.key))) })] })), _jsxs("section", { className: "dsec", "aria-label": "Limits", children: [_jsx("h3", { children: "Limits" }), provider.quota ? (_jsxs(_Fragment, { children: [monthlyPrimary ? (_jsxs(_Fragment, { children: [monthlyRow, weeklyRow, fiveRow] })) : (_jsxs(_Fragment, { children: [weeklyRow, fiveRow, monthlyRow] })), (anyElapsed || weeklyHatchPct !== null) && (_jsxs("p", { className: "limit-legend", children: [_jsx("span", { className: "legend-label", children: "Legend" }), anyElapsed && (_jsxs("span", { className: "legend-item", children: [_jsx("span", { className: "legend-mark", "aria-hidden": "true" }), "Time elapsed"] })), weeklyHatchPct !== null && (_jsxs("span", { className: "legend-item", children: [_jsx("span", { className: "legend-hatch", "aria-hidden": "true" }), "Projected waste"] }))] }))] })) : (_jsx("p", { className: "cell-s", children: "No readings yet." }))] }), _jsx(BurnDown, { provider: provider, asOf: asOf, basis: paceBasisLine }), _jsx(ClosedWeeks, { closes: provider.lastCloses, windowName: quotaWindowName(provider) }), _jsxs("div", { className: "prov-foot", children: [footText, showCredential && _jsx("span", { className: "cred", children: credentialLabel(provider) })] })] })] }));
582
+ }, className: "btn btn-quiet btn-sm", style: { flex: "none" }, children: "Cancel" })] }), renameError && (_jsx("span", { style: { fontSize: "var(--t-2)", color: "var(--danger)" }, children: renameError }))] })), provider.builtinName && provider.displayName !== provider.builtinName && (_jsx("div", { className: "sub", style: { marginTop: "2px" }, "data-testid": "provider-builtin-name", children: `Built-in: ${provider.builtinName}` })), _jsx("span", { className: "sub", children: providerSubtitle(provider) ?? sub })] }), _jsx(Badge, { provider: provider, compact: true }), _jsx("button", { className: "drawer-close", type: "button", "aria-label": "Close provider details", onClick: onClose, children: _jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "M6 6l12 12M18 6L6 18" }) }) })] }), _jsxs("div", { className: `verdict ${verdict.tone}`, "data-testid": "drawer-verdict", children: [_jsx("b", { children: verdict.label }), verdict.detail && _jsx("span", { children: verdict.detail })] }), _jsx(RateLimitNote, { provider: provider, asOf: asOf }), provider.description && _jsx("p", { className: "drawer-desc", children: provider.description }), notes.length > 0 && (_jsxs("section", { className: "dsec", "aria-label": "Notes", children: [_jsx("h3", { children: "Notes" }), _jsx("div", { className: "notes-list", children: notes.map((n) => (_jsxs("div", { className: "note", children: [_jsx("span", { className: `dot ${n.dot}`, "aria-hidden": "true" }), _jsx("span", { children: n.text })] }, n.key))) })] })), _jsxs("section", { className: "dsec", "aria-label": "Limits", children: [_jsx("h3", { children: "Limits" }), provider.quota ? (_jsxs(_Fragment, { children: [monthlyPrimary ? (_jsxs(_Fragment, { children: [monthlyRow, weeklyRow, fiveRow] })) : (_jsxs(_Fragment, { children: [weeklyRow, fiveRow, monthlyRow] })), (anyElapsed || weeklyHatchPct !== null) && (_jsxs("p", { className: "limit-legend", children: [_jsx("span", { className: "legend-label", children: "Legend" }), anyElapsed && (_jsxs("span", { className: "legend-item", children: [_jsx("span", { className: "legend-mark", "aria-hidden": "true" }), "Time elapsed"] })), weeklyHatchPct !== null && (_jsxs("span", { className: "legend-item", children: [_jsx("span", { className: "legend-hatch", "aria-hidden": "true" }), "Projected waste"] }))] }))] })) : (_jsx("p", { className: "cell-s", children: "No readings yet." }))] }), _jsx(BurnDown, { provider: provider, asOf: asOf, basis: paceBasisLine }), _jsx(ClosedWeeks, { closes: provider.lastCloses, windowName: quotaWindowName(provider) }), _jsxs("div", { className: "prov-foot", children: [footText, showCredential && _jsx("span", { className: "cred", children: credentialLabel(provider) })] })] })] }));
572
583
  }
@@ -2,6 +2,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
2
2
  import { Badge, PaceBar, forecastLine, isMonthlyBound, paceLines, resetCellLines, } from "./PaceBar.js";
3
3
  import { lastClose } from "./ClosedWeeks.js";
4
4
  import { WindowsRow } from "./WindowsRow.js";
5
+ import { RateLimitNote } from "./RateLimitNote.js";
5
6
  export function ProviderRow({ provider, recommended, asOf, onSelect, }) {
6
7
  const quota = provider.quota;
7
8
  const advisory = provider.advisory;
@@ -10,7 +11,7 @@ export function ProviderRow({ provider, recommended, asOf, onSelect, }) {
10
11
  const name = provider.displayName;
11
12
  const reset = resetCellLines(provider, asOfMs);
12
13
  const last = lastClose(provider);
13
- return (_jsxs("div", { "data-testid": `provider-row-${provider.id}`, className: `lrow ${recommended ? "is-recommended is-top-pick" : ""}`, onClick: () => onSelect(provider.id), children: [_jsxs("div", { className: "prov", "data-label": "Provider", children: [_jsx("span", { className: "dot", style: { background: `var(--p-${provider.id.split(":")[0]}, var(--surface-raised))` }, "aria-hidden": "true" }), _jsx("span", { children: _jsxs("span", { className: "nm", children: [name, recommended && (_jsx("span", { className: "rec-icon", title: "Recommended for next session", role: "img", "aria-label": "recommended", children: _jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.3", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m12 3-1.9 5.8a2 2 0 0 1-1.3 1.3L3 12l5.8 1.9a2 2 0 0 1 1.3 1.3L12 21l1.9-5.8a2 2 0 0 1 1.3-1.3L21 12l-5.8-1.9a2 2 0 0 1-1.3-1.3z" }) }) }))] }) })] }), _jsx("div", { "data-label": "Used vs elapsed", children: quota ? (_jsxs(_Fragment, { children: [_jsx(PaceBar, { provider: provider, asOf: asOf }), _jsx(WindowsRow, { provider: provider, asOf: asOf, variant: "row" })] })) : "—" }), _jsxs("div", { "data-label": "Reset", className: "reset-cell", children: [_jsx("span", { className: "cell-b", children: reset.top }), reset.bottom && _jsx("span", { className: "cell-s", children: reset.bottom }), last && (_jsxs("span", { className: "cell-s", children: ["last ", isMonthlyBound(provider) ? "month" : "week", " ", last.leftoverPct, "% leftover", last.resetsAtEstimated ? " (est.)" : ""] }))] }), _jsxs("div", { "data-label": "Pace", children: [_jsx(Badge, { provider: provider }), lines.length > 0 && (_jsx("div", { style: { marginTop: 2 }, children: lines.map((l) => (_jsxs("div", { className: "cell-s paceline", title: l.tip, children: [_jsx("span", { children: l.label }), _jsx("span", { className: "cell-b", children: l.value })] }, l.label))) }))] }), _jsx("button", { type: "button", className: "rowbtn", onClick: (e) => {
14
+ return (_jsxs("div", { "data-testid": `provider-row-${provider.id}`, className: `lrow ${recommended ? "is-recommended is-top-pick" : ""}`, onClick: () => onSelect(provider.id), children: [_jsxs("div", { className: "prov", "data-label": "Provider", children: [_jsx("span", { className: "dot", style: { background: `var(--p-${provider.id.split(":")[0]}, var(--surface-raised))` }, "aria-hidden": "true" }), _jsx("span", { children: _jsxs("span", { className: "nm", children: [name, recommended && (_jsx("span", { className: "rec-icon", title: "Recommended for next session", role: "img", "aria-label": "recommended", children: _jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.3", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m12 3-1.9 5.8a2 2 0 0 1-1.3 1.3L3 12l5.8 1.9a2 2 0 0 1 1.3 1.3L12 21l1.9-5.8a2 2 0 0 1 1.3-1.3L21 12l-5.8-1.9a2 2 0 0 1-1.3-1.3z" }) }) }))] }) })] }), _jsx("div", { "data-label": "Used vs elapsed", children: quota ? (_jsxs(_Fragment, { children: [_jsx(PaceBar, { provider: provider, asOf: asOf }), _jsx(RateLimitNote, { provider: provider, asOf: asOf }), _jsx(WindowsRow, { provider: provider, asOf: asOf, variant: "row" })] })) : "—" }), _jsxs("div", { "data-label": "Reset", className: "reset-cell", children: [_jsx("span", { className: "cell-b", children: reset.top }), reset.bottom && _jsx("span", { className: "cell-s", children: reset.bottom }), last && (_jsxs("span", { className: "cell-s", children: ["last ", isMonthlyBound(provider) ? "month" : "week", " ", last.leftoverPct, "% leftover", last.resetsAtEstimated ? " (est.)" : ""] }))] }), _jsxs("div", { "data-label": "Pace", children: [_jsx(Badge, { provider: provider }), lines.length > 0 && (_jsx("div", { style: { marginTop: 2 }, children: lines.map((l) => (_jsxs("div", { className: "cell-s paceline", title: l.tip, children: [_jsx("span", { children: l.label }), _jsx("span", { className: "cell-b", children: l.value })] }, l.label))) }))] }), _jsx("button", { type: "button", className: "rowbtn", onClick: (e) => {
14
15
  e.stopPropagation();
15
16
  onSelect(provider.id);
16
17
  }, children: "Inspect" }), _jsx("span", { className: "sr-only", children: forecastLine(provider) })] }));
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ import type { ProviderView } from "../state.js";
3
+ /** Full short window, with the date and time it clears. Quiet when none is full. */
4
+ export declare function RateLimitNote({ provider, asOf }: {
5
+ provider: ProviderView;
6
+ asOf: string;
7
+ }): React.JSX.Element | null;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { rateLimitWaits } from "../../../src/format/rate-limit-wait.js";
3
+ /** Full short window, with the date and time it clears. Quiet when none is full. */
4
+ export function RateLimitNote({ provider, asOf }) {
5
+ const asOfMs = Date.parse(asOf);
6
+ const now = Number.isFinite(asOfMs) ? new Date(asOfMs) : new Date();
7
+ const waits = rateLimitWaits(provider, now);
8
+ if (waits.length === 0)
9
+ return null;
10
+ return (_jsx("p", { className: "rate-wait", "data-testid": `rate-wait-${provider.id}`, children: waits.map((w) => (_jsx("span", { children: w.text }, w.window))) }));
11
+ }
@@ -2,14 +2,15 @@ import React from "react";
2
2
  import type { AdvisoryView, ExclusionReason, ProviderView, RecommendationView, Urgency } from "../state.js";
3
3
  export type Lane = "use-more" | "ease-off";
4
4
  /**
5
- * Lane membership from server urgency only. Any exclusionReason, or an
6
- * exhausted binding month, keeps the provider out of both lanes; "on track"
7
- * belongs to neither lane.
5
+ * Lane membership from server urgency only. Any exclusionReason, an
6
+ * exhausted binding month, or a fully used quota keeps the provider out of
7
+ * both lanes; "on track" belongs to neither lane.
8
8
  */
9
9
  export declare function laneOf(advisory: {
10
10
  urgency: Urgency;
11
11
  bindingWindow?: "weekly" | "monthly";
12
12
  bindingRemaining?: number;
13
+ remaining?: number;
13
14
  }, exclusionReason: ExclusionReason): Lane | null;
14
15
  export interface LaneMembership {
15
16
  useMore: AdvisoryView[];
@@ -1,11 +1,12 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { ageLabel } from "../state.js";
2
+ import { ageLabel, oldestReadingAt } from "../state.js";
3
3
  import { quotaResetsAt, quotaUsedPct, timeLeft } from "./PaceBar.js";
4
+ import { clockText } from "../../../src/format/time.js";
4
5
  import { ProviderIcon, providerTint } from "./ProviderIcon.js";
5
6
  /**
6
- * Lane membership from server urgency only. Any exclusionReason, or an
7
- * exhausted binding month, keeps the provider out of both lanes; "on track"
8
- * belongs to neither lane.
7
+ * Lane membership from server urgency only. Any exclusionReason, an
8
+ * exhausted binding month, or a fully used quota keeps the provider out of
9
+ * both lanes; "on track" belongs to neither lane.
9
10
  */
10
11
  export function laneOf(advisory, exclusionReason) {
11
12
  if (exclusionReason !== null)
@@ -13,6 +14,9 @@ export function laneOf(advisory, exclusionReason) {
13
14
  // A blocked month vetoes weekly leftover: no lane, exactly like an exclusion.
14
15
  if (advisory.bindingWindow === "monthly" && advisory.bindingRemaining === 0)
15
16
  return null;
17
+ // A capped quota has nothing to ease off from until it resets.
18
+ if (typeof advisory.remaining === "number" && advisory.remaining <= 0)
19
+ return null;
16
20
  switch (advisory.urgency) {
17
21
  case "burn now":
18
22
  case "use soon":
@@ -77,15 +81,15 @@ export function Recommendation({ recommendation, providers, asOf, onSelectProvid
77
81
  const easeLane = easeTint === "tint-cap" ? "l-cap" : easeTint === "tint-watch" ? "l-watch" : "l-ahead";
78
82
  const pick = providers.find((p) => p.id === recommendation.use);
79
83
  const pickReset = pick ? quotaResetsAt(pick) : null;
80
- const pickLeft = pickReset ? timeLeft(pickReset, asOfMs) : null;
84
+ const pickClock = clockText(pickReset, asOfMs);
81
85
  const openAdvice = () => {
82
86
  onViewAdvice?.();
83
87
  };
84
- const head = (_jsxs("div", { className: "section-head", children: [_jsx("h2", { children: "Quota Advice & Pacing" }), _jsxs("span", { className: "note", children: [tracked, " tracked \u00B7 ", ageLabel(asOf)] })] }));
88
+ const head = (_jsxs("div", { className: "section-head", children: [_jsx("h2", { children: "Quota Advice & Pacing" }), _jsxs("span", { className: "note", children: [tracked, " tracked \u00B7 ", ageLabel(oldestReadingAt(providers, asOf))] })] }));
85
89
  if (isClear) {
86
90
  return (_jsxs("section", { "aria-label": "Quota advice and pacing", children: [head, _jsxs("section", { "data-testid": "recommendation", "aria-label": "Recommendation", className: "recwrap is-clear", role: "status", children: [_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M12 22a10 10 0 1 0 0-20 10 10 0 0 0 0 20z" }), _jsx("path", { d: "M8 12.5l2.8 2.8L16 10" })] }), _jsxs("div", { children: [_jsx("b", { children: "No subscription needs priority" }), _jsx("span", { "data-testid": "rec-prose", children: recommendation.reason })] })] })] }));
87
91
  }
88
- return (_jsxs("section", { "aria-label": "Quota advice and pacing", children: [head, _jsxs("section", { "data-testid": "recommendation", "aria-label": "Recommendation", className: "recwrap", role: "status", children: [_jsxs("div", { className: "rec-top", children: [_jsxs("div", { className: "rec-lead", children: [_jsxs("span", { className: "rec-badge", children: [_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m12 3-1.9 5.8a2 2 0 0 1-1.3 1.3L3 12l5.8 1.9a2 2 0 0 1 1.3 1.3L12 21l1.9-5.8a2 2 0 0 1 1.3-1.3L21 12l-5.8-1.9a2 2 0 0 1-1.3-1.3z" }) }), "Recommendation"] }), recommendation.use === "none" ? (_jsx("p", { className: "rec-advice-prose", "data-testid": "rec-prose", children: recommendation.reason })) : (_jsxs("p", { className: "rec-advice-prose", "data-testid": "rec-prose", children: ["Switch to ", _jsx("strong", { children: pick?.displayName ?? recommendation.use }), " next", recommendation.wastePct !== null && recommendation.bindingWindow !== "monthly" ? (_jsxs(_Fragment, { children: [" — ", _jsxs("strong", { children: [Math.round(recommendation.wastePct), "%"] }), " unused quota forecast", pickLeft ? _jsxs(_Fragment, { children: [" to expire in ", _jsx("strong", { children: pickLeft })] }) : null, "."] })) : (_jsxs(_Fragment, { children: [" \u2014 ", recommendation.reason] }))] })), measuring && (_jsx("span", { className: "rec-badge", "data-testid": "rec-measuring", style: {
92
+ return (_jsxs("section", { "aria-label": "Quota advice and pacing", children: [head, _jsxs("section", { "data-testid": "recommendation", "aria-label": "Recommendation", className: "recwrap", role: "status", children: [_jsxs("div", { className: "rec-top", children: [_jsxs("div", { className: "rec-lead", children: [_jsxs("span", { className: "rec-badge", children: [_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m12 3-1.9 5.8a2 2 0 0 1-1.3 1.3L3 12l5.8 1.9a2 2 0 0 1 1.3 1.3L12 21l1.9-5.8a2 2 0 0 1 1.3-1.3L21 12l-5.8-1.9a2 2 0 0 1-1.3-1.3z" }) }), "Recommendation"] }), recommendation.use === "none" ? (_jsx("p", { className: "rec-advice-prose", "data-testid": "rec-prose", children: recommendation.reason })) : (_jsxs("p", { className: "rec-advice-prose", "data-testid": "rec-prose", children: ["Switch to ", _jsx("strong", { children: pick?.displayName ?? recommendation.use }), " next", recommendation.wastePct !== null && recommendation.bindingWindow !== "monthly" ? (_jsxs(_Fragment, { children: [" — ", _jsxs("strong", { children: [Math.round(recommendation.wastePct), "%"] }), " unused at reset", pickClock ? _jsxs(_Fragment, { children: [" (", _jsx("strong", { children: pickClock }), ")"] }) : null, "."] })) : (_jsxs(_Fragment, { children: [" \u2014 ", recommendation.reason] }))] })), measuring && (_jsx("span", { className: "rec-badge", "data-testid": "rec-measuring", style: {
89
93
  background: "var(--ahead-soft)",
90
94
  color: "var(--ahead)",
91
95
  borderColor: "var(--ahead)",
@@ -3,6 +3,8 @@ import type { ProviderView } from "../state.js";
3
3
  export declare const RAIL_DAYS = 7;
4
4
  /** Stem height; every pin sits at tier 0, so the rail never grows. */
5
5
  export declare const STEM_PX = 14;
6
+ /** Below this rail width separate pins collide (phone width), so pins group. */
7
+ export declare const NARROW_RAIL_PX = 480;
6
8
  export interface RailRow {
7
9
  id: string;
8
10
  /** Pill text, used to estimate the width for dodge packing. */
@@ -11,6 +11,10 @@ const WINDOW_CAPACITY = 2;
11
11
  export const STEM_PX = 14;
12
12
  /** Layout width before the rail measures itself (dashboard content max). */
13
13
  const RAIL_REF_PX = 1072;
14
+ /** Below this rail width separate pins collide (phone width), so pins group. */
15
+ export const NARROW_RAIL_PX = 480;
16
+ /** On a narrow rail a collision window spans one pill, not COLLISION_PCT. */
17
+ const NARROW_COLLISION_PX = 100;
14
18
  /** Gap kept between dodged pills. */
15
19
  const DODGE_GAP_PX = 6;
16
20
  /** Computed overlap tolerated before pins dodge; pills may touch slightly. */
@@ -80,11 +84,14 @@ export function placePins(rows, asOf, opts) {
80
84
  candidates.push({ row, resetMs, positionPct: ((resetMs - asOfMs) / RAIL_MS) * 100 });
81
85
  }
82
86
  candidates.sort((a, b) => a.resetMs - b.resetMs);
83
- // Group adjacent candidates into collision windows.
87
+ const width = opts?.railWidthPx && opts.railWidthPx > 0 ? opts.railWidthPx : RAIL_REF_PX;
88
+ // Group adjacent candidates into collision windows. A percentage window
89
+ // shrinks with the rail, so a phone-width rail measures it in pixels.
90
+ const collisionPct = width < NARROW_RAIL_PX ? Math.max(COLLISION_PCT, (NARROW_COLLISION_PX / width) * 100) : COLLISION_PCT;
84
91
  const windows = [];
85
92
  for (const c of candidates) {
86
93
  const last = windows[windows.length - 1];
87
- if (last && c.positionPct - last[0].positionPct < COLLISION_PCT) {
94
+ if (last && c.positionPct - last[0].positionPct < collisionPct) {
88
95
  last.push(c);
89
96
  }
90
97
  else {
@@ -120,7 +127,6 @@ export function placePins(rows, asOf, opts) {
120
127
  const target = item.kind === "pin" ? item.pin : item.cluster;
121
128
  target.band = index % 2 === 0 ? "above" : "below";
122
129
  });
123
- const width = opts?.railWidthPx && opts.railWidthPx > 0 ? opts.railWidthPx : RAIL_REF_PX;
124
130
  const cap = Math.min(MAX_GROUP_SPREAD_PX, width * 0.3);
125
131
  for (const band of ["above", "below"]) {
126
132
  const lane = items
@@ -306,14 +312,18 @@ export function ResetRail({ providers, asOf, onSelectProvider, initialMode, }) {
306
312
  resetsAt: quotaResetsAt(p),
307
313
  estimated: quotaResetEstimated(p),
308
314
  }));
309
- const placement = placePins(rows, new Date(asOfMs), { grouped: mode === "grouped", railWidthPx: railWidth });
315
+ // A phone-width rail cannot fit separate labels; group without
316
+ // overwriting the stored choice, which returns on a wider screen.
317
+ const narrow = railWidth < NARROW_RAIL_PX;
318
+ const shownMode = narrow ? "grouped" : mode;
319
+ const placement = placePins(rows, new Date(asOfMs), { grouped: shownMode === "grouped", railWidthPx: railWidth });
310
320
  const labels = dayLabels(asOfMs);
311
321
  const setModePersist = (next) => {
312
322
  setOpenCluster(null);
313
323
  setMode(next);
314
324
  persistRailMode(next);
315
325
  };
316
- return (_jsxs("section", { "aria-label": "Upcoming resets", children: [_jsxs("div", { className: "section-head", children: [_jsx("h2", { id: "resets-h", children: "Upcoming resets" }), _jsxs("div", { className: "section-head-controls", children: [_jsxs("span", { className: "note", children: ["Next 7 days \u00B7 hover pin for usage \u00B7 click for details \u00B7 ", tzAbbrev(), placement.overflow.length > 0 && (_jsxs("span", { "data-testid": "rail-overflow", title: placement.overflow.map((o) => byId.get(o.id)?.displayName ?? o.id).join(", "), style: { marginLeft: 8, fontWeight: 600, color: "var(--ahead)" }, children: ["+", placement.overflow.length, " beyond rail"] }))] }), _jsxs("div", { "data-testid": "rail-mode", role: "group", "aria-label": "Reset pin grouping", className: "seg", children: [_jsx("button", { type: "button", "aria-pressed": mode === "separate", onClick: () => setModePersist("separate"), children: "Separate" }), _jsx("button", { type: "button", "aria-pressed": mode === "grouped", onClick: () => setModePersist("grouped"), children: "Grouped" })] })] })] }), _jsx("div", { "data-testid": "rail", className: "rail-scroller", tabIndex: 0, role: "region", "aria-label": `Upcoming resets over the next ${RAIL_DAYS} days`, children: _jsxs("div", { className: "rail", ref: railRef, children: [_jsx("div", { className: "rail-grid", "aria-hidden": "true", children: Array.from({ length: RAIL_DAYS }, (_, i) => (_jsx("span", {}, i))) }), _jsx("div", { className: "rail-axis", "aria-hidden": "true" }), _jsx("div", { className: "rail-now", "aria-hidden": "true" }), _jsx("span", { className: "rail-nowlabel", "aria-hidden": "true", children: "Now" }), placement.placed.map((pin) => {
326
+ return (_jsxs("section", { "aria-label": "Upcoming resets", children: [_jsxs("div", { className: "section-head", children: [_jsx("h2", { id: "resets-h", children: "Upcoming resets" }), _jsxs("div", { className: "section-head-controls", children: [_jsxs("span", { className: "note", children: ["Next 7 days \u00B7 hover pin for usage \u00B7 click for details \u00B7 ", tzAbbrev(), placement.overflow.length > 0 && (_jsxs("span", { "data-testid": "rail-overflow", title: placement.overflow.map((o) => byId.get(o.id)?.displayName ?? o.id).join(", "), style: { marginLeft: 8, fontWeight: 600, color: "var(--ahead)" }, children: ["+", placement.overflow.length, " beyond rail"] }))] }), _jsxs("div", { "data-testid": "rail-mode", role: "group", "aria-label": "Reset pin grouping", className: "seg", children: [_jsx("button", { type: "button", "aria-pressed": shownMode === "separate", disabled: narrow, title: narrow ? "Too narrow to separate pins" : undefined, onClick: () => setModePersist("separate"), children: "Separate" }), _jsx("button", { type: "button", "aria-pressed": shownMode === "grouped", onClick: () => setModePersist("grouped"), children: "Grouped" })] })] })] }), _jsx("div", { "data-testid": "rail", className: "rail-scroller", tabIndex: 0, role: "region", "aria-label": `Upcoming resets over the next ${RAIL_DAYS} days`, children: _jsxs("div", { className: "rail", ref: railRef, children: [_jsx("div", { className: "rail-grid", "aria-hidden": "true", children: Array.from({ length: RAIL_DAYS }, (_, i) => (_jsx("span", {}, i))) }), _jsx("div", { className: "rail-axis", "aria-hidden": "true" }), _jsx("div", { className: "rail-now", "aria-hidden": "true" }), _jsx("span", { className: "rail-nowlabel", "aria-hidden": "true", children: "Now" }), placement.placed.map((pin) => {
317
327
  const provider = byId.get(pin.id);
318
328
  const when = provider?.quota ? pinWhen(provider) : provider ? resetCountdown(provider, asOfMs) : "";
319
329
  const pace = provider ? paceBadge(provider) : "";
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import type { ProviderView } from "../state.js";
3
- /** One-unit countdown for a window tag: "7d", "4h" or "40m". Null when passed or unparseable. */
3
+ /** Window tag countdown in the shared form, e.g. "1d 20h". Null when passed or unparseable. */
4
4
  export declare function windowCountdown(resetsAt: string, asOfMs: number): string | null;
5
5
  export interface WindowUnit {
6
6
  win: "five" | "month" | "week";
@@ -10,7 +10,7 @@ export interface WindowUnit {
10
10
  pct: number;
11
11
  /** Presentation-only heat: < 80 none, 80–99 hot, 100 or exhausted full. */
12
12
  heat: "" | "hot" | "full";
13
- /** Tag time outside the pill: "in 7d", or the weekday plus date when the month is exhausted. */
13
+ /** Tag time outside the pill: "in 1d 20h", or the weekday plus date when the month is exhausted. */
14
14
  time: string | null;
15
15
  /** Expanded card track's reset line. */
16
16
  reset: string | null;
@@ -1,19 +1,9 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from "react";
3
- import { resetDateClock, resetDay } from "./PaceBar.js";
4
- const MIN_MS = 60_000;
5
- const HOUR_MS = 60 * MIN_MS;
6
- const DAY_MS = 24 * HOUR_MS;
7
- /** One-unit countdown for a window tag: "7d", "4h" or "40m". Null when passed or unparseable. */
3
+ import { resetDateClock, resetDay, timeLeft } from "./PaceBar.js";
4
+ /** Window tag countdown in the shared form, e.g. "1d 20h". Null when passed or unparseable. */
8
5
  export function windowCountdown(resetsAt, asOfMs) {
9
- const diff = Date.parse(resetsAt) - asOfMs;
10
- if (!Number.isFinite(diff) || diff <= 0)
11
- return null;
12
- if (diff >= DAY_MS)
13
- return `${Math.floor(diff / DAY_MS)}d`;
14
- if (diff >= HOUR_MS)
15
- return `${Math.floor(diff / HOUR_MS)}h`;
16
- return `${Math.max(1, Math.floor(diff / MIN_MS))}m`;
6
+ return timeLeft(resetsAt, asOfMs);
17
7
  }
18
8
  function heatOf(pct, exhausted) {
19
9
  if (exhausted || pct >= 100)
@@ -4,8 +4,9 @@ import type { ProviderView } from "../../state.js";
4
4
  export declare function adapterProviders(providers: ProviderView[]): ProviderView[];
5
5
  export declare function connectionName(id: string): string;
6
6
  export declare function connectionBadge(provider: ProviderView): string;
7
- export type SettingsStatus = "Ready" | "Stale" | "Failed" | "Invalid" | "Reset passed" | "Not reporting";
8
- /** Short status from server exclusion and attempt fields. */
7
+ export type SettingsStatus = "Ready" | "Disabled" | "Stale" | "Failed" | "Invalid" | "Reset passed" | "Not reporting";
8
+ /** Short status from server exclusion and attempt fields. A disabled
9
+ * provider reads Disabled, whatever its last attempt did. */
9
10
  export declare function providerStatus(provider: ProviderView): SettingsStatus;
10
11
  export declare function statusPillClass(status: SettingsStatus): string;
11
12
  export declare function ProvidersPanel({ providers, refreshing, onSetProviderEnabled, }: {
@@ -23,8 +23,11 @@ export function connectionBadge(provider) {
23
23
  const age = ageDuration(provider.ageMs);
24
24
  return age ? `${status} · ${age} ago` : status;
25
25
  }
26
- /** Short status from server exclusion and attempt fields. */
26
+ /** Short status from server exclusion and attempt fields. A disabled
27
+ * provider reads Disabled, whatever its last attempt did. */
27
28
  export function providerStatus(provider) {
29
+ if (!provider.enabled)
30
+ return "Disabled";
28
31
  switch (provider.exclusionReason) {
29
32
  case "stale":
30
33
  return "Stale";
@@ -79,7 +79,7 @@ function SamplePreview() {
79
79
  fontSize: "var(--t-1)",
80
80
  color: "var(--ink-faint)",
81
81
  marginTop: 4,
82
- }, children: [_jsx("span", { children: "start" }), _jsx("span", { children: "time elapsed: 83%" }), _jsx("span", { children: "reset" })] })] }), _jsx("p", { style: { fontSize: "var(--t-2)", color: "var(--ink-soft)", margin: "var(--s3) 0 0" }, children: "Switch to Kimi next \u2014 67% waste in 1.2d" })] }));
82
+ }, children: [_jsx("span", { children: "start" }), _jsx("span", { children: "time elapsed: 83%" }), _jsx("span", { children: "reset" })] })] }), _jsx("p", { style: { fontSize: "var(--t-2)", color: "var(--ink-soft)", margin: "var(--s3) 0 0" }, children: "Switch to Kimi next \u2014 67% unused at reset (Thu 06:00)" })] }));
83
83
  }
84
84
  export function Onboarding({ snapshot, onFirstPoll, polling, pollError, }) {
85
85
  const [step, setStep] = useState(1);
@@ -161,6 +161,11 @@ export declare function displayPlan(plan: string | null | undefined): string | n
161
161
  * short window (grok, manual).
162
162
  */
163
163
  export declare function shortWindowLabel(id: string): string | null;
164
+ /**
165
+ * Fetch time of the oldest reading the advice uses, so the header never
166
+ * claims fresher data than a card's "Updated" line. Falls back to `asOf`.
167
+ */
168
+ export declare function oldestReadingAt(providers: ProviderView[], asOf: string): string;
164
169
  /** "read Xm ago" from the last good snapshot's server timestamp. */
165
170
  export declare function ageLabel(asOf: string, nowMs?: number): string;
166
171
  /** Default poll interval; matches `pollMinutes` in `src/config.ts`. */
@@ -79,6 +79,24 @@ export function shortWindowLabel(id) {
79
79
  return null;
80
80
  }
81
81
  }
82
+ /**
83
+ * Fetch time of the oldest reading the advice uses, so the header never
84
+ * claims fresher data than a card's "Updated" line. Falls back to `asOf`.
85
+ */
86
+ export function oldestReadingAt(providers, asOf) {
87
+ let iso = asOf;
88
+ let oldest = Date.parse(asOf);
89
+ for (const p of providers) {
90
+ if (!p.enabled || p.exclusionReason !== null || !p.quota?.fetchedAt)
91
+ continue;
92
+ const ms = Date.parse(p.quota.fetchedAt);
93
+ if (Number.isFinite(ms) && (!Number.isFinite(oldest) || ms < oldest)) {
94
+ oldest = ms;
95
+ iso = p.quota.fetchedAt;
96
+ }
97
+ }
98
+ return iso;
99
+ }
82
100
  /** "read Xm ago" from the last good snapshot's server timestamp. */
83
101
  export function ageLabel(asOf, nowMs = Date.now()) {
84
102
  const diff = nowMs - Date.parse(asOf);