quotacap 0.0.58 → 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.
- package/README.md +1 -1
- package/dist/adapters/muse.d.ts +1 -1
- package/dist/adapters/muse.js +5 -3
- package/dist/advisory/engine.js +9 -5
- package/dist/advisory/snapshot.js +10 -11
- package/dist/cli/advise.d.ts +1 -1
- package/dist/cli/advise.js +6 -2
- package/dist/cli/models.js +2 -2
- package/dist/cli/status.js +2 -2
- package/dist/format/markdown.js +5 -5
- package/dist/format/rate-limit-wait.d.ts +3 -3
- package/dist/format/rate-limit-wait.js +8 -26
- package/dist/format/rows.d.ts +40 -6
- package/dist/format/rows.js +48 -42
- package/dist/format/terminal.js +12 -11
- package/dist/format/time.d.ts +19 -0
- package/dist/format/time.js +69 -0
- package/dist/mcp/server.d.ts +25 -5
- package/dist/mcp/server.js +36 -3
- package/dist/store/quotas.d.ts +7 -2
- package/dist/store/quotas.js +94 -15
- package/dist/version.js +1 -1
- package/dist/web/src/components/AdviceDrawer.d.ts +3 -1
- package/dist/web/src/components/AdviceDrawer.js +25 -4
- package/dist/web/src/components/ClosedWeeks.d.ts +4 -1
- package/dist/web/src/components/ClosedWeeks.js +17 -5
- package/dist/web/src/components/PaceBar.d.ts +26 -25
- package/dist/web/src/components/PaceBar.js +57 -119
- package/dist/web/src/components/PacingLegend.js +9 -8
- package/dist/web/src/components/ProviderDrawer.d.ts +9 -2
- package/dist/web/src/components/ProviderDrawer.js +36 -26
- package/dist/web/src/components/Recommendation.d.ts +4 -3
- package/dist/web/src/components/Recommendation.js +11 -7
- package/dist/web/src/components/ResetRail.d.ts +2 -0
- package/dist/web/src/components/ResetRail.js +15 -5
- package/dist/web/src/components/WindowsRow.d.ts +2 -2
- package/dist/web/src/components/WindowsRow.js +3 -13
- package/dist/web/src/components/settings/ProvidersPanel.d.ts +3 -2
- package/dist/web/src/components/settings/ProvidersPanel.js +4 -1
- package/dist/web/src/pages/Onboarding.js +1 -1
- package/dist/web/src/state.d.ts +5 -0
- package/dist/web/src/state.js +18 -0
- package/dist/webAssets.js +1 -1
- package/dist/webHtml.js +1 -1
- package/package.json +1 -1
- package/web/dist/assets/index-DQ2jUHo6.js +13 -0
- package/web/dist/assets/index-DSNVHbgI.css +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-CnAonL1R.css +0 -1
- package/web/dist/assets/index-DGCyW-uy.js +0 -13
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ No setup ceremony: config is provisioned on first use, and bare `quotacap` is th
|
|
|
70
70
|
|
|
71
71
|
Use `"command": "npx", "args": ["quotacap", "mcp"]` when installed via npm only.
|
|
72
72
|
|
|
73
|
-
Tools: `get_quotas`, `get_recommendation`, `forecast`.
|
|
73
|
+
Tools: `get_quotas`, `get_recommendation`, `forecast`, `get_models`. `get_recommendation` returns the pick, its reason, and each other provider's state, availability and reset; pass `verbose: true` for every quota, advisory and model list.
|
|
74
74
|
|
|
75
75
|
## HTTP API
|
|
76
76
|
|
package/dist/adapters/muse.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface RecoveryDeps {
|
|
|
29
29
|
*/
|
|
30
30
|
export declare function recoverSubscription(deps: RecoveryDeps): Promise<ParsedQuota>;
|
|
31
31
|
export declare function museProbeDir(): string;
|
|
32
|
-
export declare function parseMusePlan(
|
|
32
|
+
export declare function parseMusePlan(text: string): string;
|
|
33
33
|
export declare function parseMuseQuotaExhausted(text: string, plan?: string, now?: Date): ParsedQuota | null;
|
|
34
34
|
export declare function parseMuseTui(text: string, now?: Date, dims?: Partial<GridDims>): ParsedQuota;
|
|
35
35
|
export declare const museAdapter: {
|
package/dist/adapters/muse.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { parseResetText } from "./parse.js";
|
|
5
|
-
import { runPty } from "./pty.js";
|
|
5
|
+
import { runPty, stripAnsi } from "./pty.js";
|
|
6
6
|
import { parseScreens } from "./vt.js";
|
|
7
7
|
import { adapterSignal, trackedExecFile } from "../runtime/spawn.js";
|
|
8
8
|
import { attachEvidence, getErrorEvidence } from "../diagnostics/failure.js";
|
|
@@ -89,8 +89,10 @@ export async function recoverSubscription(deps) {
|
|
|
89
89
|
export function museProbeDir() {
|
|
90
90
|
return path.join(process.env.QUOTACAP_HOME ?? os.homedir(), ".quotacap", "muse-probe");
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
// The recovery path hands over raw stdout, so escape codes are stripped here
|
|
93
|
+
// and the match stops at the panel's box-drawing border.
|
|
94
|
+
export function parseMusePlan(text) {
|
|
95
|
+
const planMatch = stripAnsi(text).match(/Subscription\s*·\s*Muse Code\s+(.+?)(?:\s{2,}|\s*[\u2500-\u257F]|\r?\n|$)/i);
|
|
94
96
|
return planMatch ? planMatch[1].trim() : "unknown";
|
|
95
97
|
}
|
|
96
98
|
export function parseMuseQuotaExhausted(text, plan = "unknown", now = new Date()) {
|
package/dist/advisory/engine.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MIN_PACE_SPAN_DAYS, BLEND_K, RISK_MARGIN, GATE_TOL, paceTube } from "./types.js";
|
|
2
|
+
import { durationFromDays, unusedAtReset } from "../format/time.js";
|
|
2
3
|
const DAY_MS = 86400000;
|
|
3
4
|
/**
|
|
4
5
|
* Pace from a single reading.
|
|
@@ -160,7 +161,10 @@ export function computeAdvisory(q, recent, baseline, now = new Date(), exhausted
|
|
|
160
161
|
const estimated = q.resetsAtEstimated === true;
|
|
161
162
|
const gate = elapsed !== null && !estimated && q.weeklyPct >= elapsed * (1 - GATE_TOL);
|
|
162
163
|
const aheadOfElapsed = elapsed !== null && !estimated && q.weeklyPct > elapsed * (1 + GATE_TOL);
|
|
163
|
-
|
|
164
|
+
// Waste never assumes a pace slower than the one measured now: the blend
|
|
165
|
+
// may lean on a quieter history, but a provider whose 24h rate already
|
|
166
|
+
// spends its remainder has nothing spare to recommend.
|
|
167
|
+
const wastePct = Math.max(0, remaining - Math.max(recent ?? 0, burnRate) * daysLeft);
|
|
164
168
|
const daysToExhaust = burnRate > 0 ? remaining / burnRate : Infinity;
|
|
165
169
|
const over = daysToExhaust < daysLeft * (1 - RISK_MARGIN);
|
|
166
170
|
const missFrac = Number.isFinite(daysToExhaust) ? Math.abs(daysToExhaust - daysLeft) / daysLeft : Infinity;
|
|
@@ -231,8 +235,8 @@ export function recommend(quotas, _task, paceByProvider = new Map(), now = new D
|
|
|
231
235
|
return {
|
|
232
236
|
use: use.provider,
|
|
233
237
|
reason: use.bindingWindow === "monthly"
|
|
234
|
-
? `${Math.round(use.bindingRemaining)}% of month left in ${use.bindingDaysLeft
|
|
235
|
-
:
|
|
238
|
+
? `${Math.round(use.bindingRemaining)}% of month left in ${durationFromDays(use.bindingDaysLeft)}`
|
|
239
|
+
: unusedAtReset(use.wastePct, quotas.find(q => q.provider === use.provider)?.resetsAt, now.getTime()),
|
|
236
240
|
wastePct: rankWaste(use),
|
|
237
241
|
idealRate: use.idealRate,
|
|
238
242
|
recommendationBasis: "known-waste",
|
|
@@ -248,8 +252,8 @@ export function recommend(quotas, _task, paceByProvider = new Map(), now = new D
|
|
|
248
252
|
return {
|
|
249
253
|
use: use.provider,
|
|
250
254
|
reason: use.bindingWindow === "monthly"
|
|
251
|
-
? `Measuring pace; ${Math.round(use.bindingRemaining)}% of month left with ${use.bindingDaysLeft
|
|
252
|
-
: `Measuring pace; ${Math.round(use.remaining)}% remains with ${use.daysLeft
|
|
255
|
+
? `Measuring pace; ${Math.round(use.bindingRemaining)}% of month left with ${durationFromDays(use.bindingDaysLeft)} until reset`
|
|
256
|
+
: `Measuring pace; ${Math.round(use.remaining)}% remains with ${durationFromDays(use.daysLeft)} until reset`,
|
|
253
257
|
wastePct: null,
|
|
254
258
|
idealRate: use.idealRate,
|
|
255
259
|
recommendationBasis: "unknown-headroom",
|
|
@@ -52,12 +52,12 @@ export function buildSnapshot(db, opts) {
|
|
|
52
52
|
const unionIds = Array.from(new Set([...opts.enabledProviders, ...storedIds])).sort((a, b) => a.localeCompare(b));
|
|
53
53
|
const burnRates = getBurnRates(db, asOfMs);
|
|
54
54
|
const exhaustedTimestamps = getExhaustedTimestamps(db, asOfMs);
|
|
55
|
-
const history = getHistoryBaseline(db);
|
|
55
|
+
const history = getHistoryBaseline(db, 4, quotaMap);
|
|
56
56
|
const catalogMap = getCatalogs(db);
|
|
57
57
|
const providerSnapshots = [];
|
|
58
58
|
const eligibleQuotas = [];
|
|
59
59
|
const paceByProvider = new Map();
|
|
60
|
-
const
|
|
60
|
+
const eligibleAdvisories = [];
|
|
61
61
|
for (const id of unionIds) {
|
|
62
62
|
const quota = quotaMap.get(id) ?? null;
|
|
63
63
|
let attempt = attemptMap.get(id) ?? null;
|
|
@@ -149,10 +149,9 @@ export function buildSnapshot(db, opts) {
|
|
|
149
149
|
if (quota?.resetsAtEstimated) {
|
|
150
150
|
evidence.push("estimated-reset");
|
|
151
151
|
}
|
|
152
|
-
if (advisory) {
|
|
153
|
-
allValidAdvisories.push(advisory);
|
|
154
|
-
}
|
|
155
152
|
if (enabled && quota !== null && exclusionReason === null) {
|
|
153
|
+
if (advisory)
|
|
154
|
+
eligibleAdvisories.push(advisory);
|
|
156
155
|
eligibleQuotas.push(quota);
|
|
157
156
|
if (pace)
|
|
158
157
|
paceByProvider.set(id, pace);
|
|
@@ -178,11 +177,11 @@ export function buildSnapshot(db, opts) {
|
|
|
178
177
|
evidence,
|
|
179
178
|
exclusionReason,
|
|
180
179
|
advisory,
|
|
181
|
-
lastCloses: getWindowCloses(db, id, 4, closeWindow),
|
|
180
|
+
lastCloses: getWindowCloses(db, id, 4, closeWindow, quota),
|
|
182
181
|
catalog,
|
|
183
182
|
});
|
|
184
183
|
}
|
|
185
|
-
// 2. Recommendation: ranked from eligible providers only; advisories cover
|
|
184
|
+
// 2. Recommendation: ranked from eligible providers only; advisories cover the same rows
|
|
186
185
|
let recommendation;
|
|
187
186
|
if (!eligibleQuotas.length) {
|
|
188
187
|
recommendation = {
|
|
@@ -196,7 +195,7 @@ export function buildSnapshot(db, opts) {
|
|
|
196
195
|
catalogStatus: "unfetched",
|
|
197
196
|
catalogFetchedAt: null,
|
|
198
197
|
alternatives: [],
|
|
199
|
-
advisories:
|
|
198
|
+
advisories: eligibleAdvisories,
|
|
200
199
|
};
|
|
201
200
|
}
|
|
202
201
|
else {
|
|
@@ -204,8 +203,8 @@ export function buildSnapshot(db, opts) {
|
|
|
204
203
|
const chosenProvider = eligibleQuotas.find((q) => q.provider === rec.use);
|
|
205
204
|
let reason = rec.reason;
|
|
206
205
|
if (chosenProvider?.resetsAtEstimated) {
|
|
207
|
-
if (reason.includes("
|
|
208
|
-
reason = reason.replace("
|
|
206
|
+
if (reason.includes("unused at reset")) {
|
|
207
|
+
reason = reason.replace("unused at reset", "unused at estimated reset");
|
|
209
208
|
}
|
|
210
209
|
else if (reason.includes("until reset")) {
|
|
211
210
|
reason = reason.replace("until reset", "until estimated reset");
|
|
@@ -228,7 +227,7 @@ export function buildSnapshot(db, opts) {
|
|
|
228
227
|
catalogStatus: rec.use === "none" ? "unfetched" : pickCatalog.status,
|
|
229
228
|
catalogFetchedAt: pickCatalog.fetchedAt,
|
|
230
229
|
alternatives: alternativesWithCatalog,
|
|
231
|
-
advisories:
|
|
230
|
+
advisories: eligibleAdvisories,
|
|
232
231
|
};
|
|
233
232
|
}
|
|
234
233
|
return {
|
package/dist/cli/advise.d.ts
CHANGED
package/dist/cli/advise.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// advise: which provider to use next, over the shared projection. The
|
|
2
|
+
// hidden --task flag is still accepted and validated for old scripts, but it
|
|
3
|
+
// never changes the ranking, so help no longer offers it.
|
|
4
|
+
import { Option } from "commander";
|
|
1
5
|
import { projectRecommendationResponse } from "../advisory/snapshot.js";
|
|
2
6
|
import { renderRecommendationSummary } from "../format/markdown.js";
|
|
3
7
|
import { validateTask } from "../advisory/validate.js";
|
|
@@ -37,9 +41,9 @@ export function registerAdviseCommand(program, deps) {
|
|
|
37
41
|
(() => refreshUpdateCache({ channel: detectChannel(), current: VERSION }));
|
|
38
42
|
program
|
|
39
43
|
.command("advise")
|
|
40
|
-
.description("show which provider to use next
|
|
44
|
+
.description("show which provider to use next")
|
|
41
45
|
.option("--json", "machine-readable output")
|
|
42
|
-
.
|
|
46
|
+
.addOption(new Option("--task <t>").default("any").hideHelp())
|
|
43
47
|
.action(async (o) => {
|
|
44
48
|
// Task validation precedes any I/O: a bogus task never touches the
|
|
45
49
|
// network, config, or database.
|
package/dist/cli/models.js
CHANGED
|
@@ -40,11 +40,11 @@ function printTable(list) {
|
|
|
40
40
|
});
|
|
41
41
|
const maxProv = Math.max(8, ...rows.map((r) => r.prov.length));
|
|
42
42
|
const maxLeft = Math.max(8, ...rows.map((r) => r.leftover.length));
|
|
43
|
-
const maxStat = Math.max(
|
|
43
|
+
const maxStat = Math.max("CATALOG".length, ...rows.map((r) => r.status.length));
|
|
44
44
|
const header = [
|
|
45
45
|
"PROVIDER".padEnd(maxProv),
|
|
46
46
|
"LEFTOVER".padEnd(maxLeft),
|
|
47
|
-
"
|
|
47
|
+
"CATALOG".padEnd(maxStat),
|
|
48
48
|
"MODELS",
|
|
49
49
|
].join(" ");
|
|
50
50
|
const lines = rows.map((r) => [r.prov.padEnd(maxProv), r.leftover.padEnd(maxLeft), r.status.padEnd(maxStat), r.ids].join(" "));
|
package/dist/cli/status.js
CHANGED
|
@@ -2,7 +2,7 @@ import { projectQuotasResponse } from "../advisory/snapshot.js";
|
|
|
2
2
|
import { ensureConfig, getDbPath } from "../config.js";
|
|
3
3
|
import { renderCompact, renderNarrow, renderWide } from "../format/terminal.js";
|
|
4
4
|
import { renderIssues } from "../format/issues.js";
|
|
5
|
-
import { assertValidSortKey } from "../format/rows.js";
|
|
5
|
+
import { COMPACT_LEGEND, assertValidSortKey } from "../format/rows.js";
|
|
6
6
|
import { createServiceClient } from "../runtime/client.js";
|
|
7
7
|
import { VERSION } from "../version.js";
|
|
8
8
|
import { isServiceManaged, runServiceCommand } from "../service/index.js";
|
|
@@ -25,7 +25,7 @@ export function registerStatusCommand(program, deps) {
|
|
|
25
25
|
.command("status")
|
|
26
26
|
.description("show quota status (service when reachable, stored readings otherwise)")
|
|
27
27
|
.option("--json", "machine-readable output")
|
|
28
|
-
.option("--compact",
|
|
28
|
+
.option("--compact", `one-line statusline (${COMPACT_LEGEND})`)
|
|
29
29
|
.option("--ascii", "ASCII glyphs without color")
|
|
30
30
|
.option("--sort <key>", "row order: recommended|reset-asc|reset-desc|used-desc|used-asc", "recommended")
|
|
31
31
|
.option("--verbose", "show provider failure guidance and diagnostics")
|
package/dist/format/markdown.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { rateLimitWaitLines } from "./rate-limit-wait.js";
|
|
2
|
-
import { buildRow, sortProviders } from "./rows.js";
|
|
2
|
+
import { buildRow, shownProviders, sortProviders, useName } from "./rows.js";
|
|
3
3
|
function esc(cell) {
|
|
4
4
|
return cell.replace(/\|/g, "\\|").replace(/[\r\n]+/g, " ");
|
|
5
5
|
}
|
|
6
6
|
export function renderMarkdownTable(snapshot, now) {
|
|
7
7
|
const use = snapshot.recommendation.use;
|
|
8
|
-
const sorted = sortProviders(snapshot.providers, "recommended", use);
|
|
8
|
+
const sorted = sortProviders(shownProviders(snapshot.providers), "recommended", use);
|
|
9
9
|
const lines = sorted.map((p) => {
|
|
10
10
|
const row = buildRow(p, now);
|
|
11
11
|
const name = p.id === use && use !== "none" ? `★ ${p.displayName}` : p.displayName;
|
|
@@ -22,8 +22,8 @@ export function renderMarkdownTable(snapshot, now) {
|
|
|
22
22
|
}
|
|
23
23
|
export function renderRecommendationSummary(snapshot, now = new Date(snapshot.asOf)) {
|
|
24
24
|
const rec = snapshot.recommendation;
|
|
25
|
-
const waits = rateLimitWaitLines(snapshot.providers, now);
|
|
26
|
-
return [`${
|
|
25
|
+
const waits = rateLimitWaitLines(shownProviders(snapshot.providers), now);
|
|
26
|
+
return [`${useName(snapshot)}: ${rec.reason}`, ...waits].join("\n");
|
|
27
27
|
}
|
|
28
28
|
export function renderModelsMarkdownTable(models) {
|
|
29
29
|
const lines = models.map((m) => {
|
|
@@ -34,7 +34,7 @@ export function renderModelsMarkdownTable(models) {
|
|
|
34
34
|
return `| ${esc(name)} | ${leftover} | ${esc(status)} | ${esc(ids)} |`;
|
|
35
35
|
});
|
|
36
36
|
return [
|
|
37
|
-
"| Provider | Leftover |
|
|
37
|
+
"| Provider | Leftover | Catalog | Models |",
|
|
38
38
|
"|---|---|---|---|",
|
|
39
39
|
...lines,
|
|
40
40
|
].join("\n");
|
|
@@ -4,7 +4,7 @@ export interface RateLimitWait {
|
|
|
4
4
|
label: "5h limit" | "Weekly limit";
|
|
5
5
|
/** Reported finish instant. Null when the provider did not report one. */
|
|
6
6
|
resetsAt: string | null;
|
|
7
|
-
/**
|
|
7
|
+
/** Shared clock, e.g. "Thu 18:59" within a week, else "Thu 23 Oct 18:59". */
|
|
8
8
|
until: string | null;
|
|
9
9
|
text: string;
|
|
10
10
|
}
|
|
@@ -23,8 +23,8 @@ export interface RateLimitSource {
|
|
|
23
23
|
monthlyKind?: "included" | null;
|
|
24
24
|
} | null;
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
27
|
-
export declare function limitStamp(iso: string): string | null;
|
|
26
|
+
/** The shared clock: "Thu 18:59" within a week of `nowMs`, else "Thu 23 Oct 18:59". */
|
|
27
|
+
export declare function limitStamp(iso: string, nowMs?: number): string | null;
|
|
28
28
|
/**
|
|
29
29
|
* Short windows that are full while the reset-window quota still has room.
|
|
30
30
|
* A 5h window on any plan, and the week on a plan whose quota resets monthly.
|
|
@@ -1,27 +1,9 @@
|
|
|
1
1
|
// A full short window the user has to wait out. Presentation only:
|
|
2
2
|
// pace, forecast, and which provider to use next stay on the reset window.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export function limitStamp(iso) {
|
|
8
|
-
const ms = Date.parse(iso);
|
|
9
|
-
if (!Number.isFinite(ms))
|
|
10
|
-
return null;
|
|
11
|
-
const when = new Date(ms);
|
|
12
|
-
const weekday = part(when, { weekday: "short" }, "weekday");
|
|
13
|
-
const month = part(when, { month: "short" }, "month");
|
|
14
|
-
const day = part(when, { day: "numeric" }, "day");
|
|
15
|
-
const time = new Intl.DateTimeFormat("en-US", {
|
|
16
|
-
hour: "2-digit",
|
|
17
|
-
minute: "2-digit",
|
|
18
|
-
hourCycle: "h23",
|
|
19
|
-
}).formatToParts(when);
|
|
20
|
-
const hour = time.find((p) => p.type === "hour")?.value ?? "";
|
|
21
|
-
const minute = time.find((p) => p.type === "minute")?.value ?? "";
|
|
22
|
-
if (!weekday || !month || !day || !hour || !minute)
|
|
23
|
-
return null;
|
|
24
|
-
return `${weekday} ${month} ${day} ${hour.padStart(2, "0")}:${minute.padStart(2, "0")}`;
|
|
3
|
+
import { clockText } from "./time.js";
|
|
4
|
+
/** The shared clock: "Thu 18:59" within a week of `nowMs`, else "Thu 23 Oct 18:59". */
|
|
5
|
+
export function limitStamp(iso, nowMs) {
|
|
6
|
+
return clockText(iso, nowMs);
|
|
25
7
|
}
|
|
26
8
|
function instant(iso) {
|
|
27
9
|
if (!iso)
|
|
@@ -40,9 +22,9 @@ function includedMonth(q) {
|
|
|
40
22
|
function monthExhausted(q) {
|
|
41
23
|
return q.monthlyStatus === "exhausted" || (typeof q.monthlyPct === "number" && q.monthlyPct >= 100);
|
|
42
24
|
}
|
|
43
|
-
function waitFor(window, label, iso) {
|
|
25
|
+
function waitFor(window, label, iso, nowMs) {
|
|
44
26
|
const resetsAt = instant(iso) === null ? null : iso ?? null;
|
|
45
|
-
const until = resetsAt ? limitStamp(resetsAt) : null;
|
|
27
|
+
const until = resetsAt ? limitStamp(resetsAt, nowMs) : null;
|
|
46
28
|
return {
|
|
47
29
|
window,
|
|
48
30
|
label,
|
|
@@ -73,10 +55,10 @@ export function rateLimitWaits(source, now) {
|
|
|
73
55
|
const waits = [];
|
|
74
56
|
const five = q.fiveHourPct ?? q.sessionPct;
|
|
75
57
|
if (typeof five === "number" && five >= 100 && stillOpen(q.fiveHourResetsAt, nowMs)) {
|
|
76
|
-
waits.push(waitFor("five-hour", "5h limit", q.fiveHourResetsAt));
|
|
58
|
+
waits.push(waitFor("five-hour", "5h limit", q.fiveHourResetsAt, nowMs));
|
|
77
59
|
}
|
|
78
60
|
if (monthly && weekFull && stillOpen(q.resetsAt, nowMs)) {
|
|
79
|
-
waits.push(waitFor("weekly", "Weekly limit", q.resetsAt));
|
|
61
|
+
waits.push(waitFor("weekly", "Weekly limit", q.resetsAt, nowMs));
|
|
80
62
|
}
|
|
81
63
|
waits.sort((a, b) => {
|
|
82
64
|
const am = instant(a.resetsAt);
|
package/dist/format/rows.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ProviderSnapshot } from "../advisory/types.js";
|
|
1
|
+
import type { Advisory, ProviderSnapshot } from "../advisory/types.js";
|
|
2
2
|
export type StateWord = "On track" | "Behind pace" | "Ahead of pace" | "Cap risk" | "Watch" | "Measuring" | "Not reporting" | "Monthly exhausted" | "Quota exhausted";
|
|
3
3
|
export type RailCell = "used" | "tick" | "unused";
|
|
4
4
|
export type SortKey = "recommended" | "reset-asc" | "reset-desc" | "used-desc" | "used-asc";
|
|
5
|
-
export type CompactSuffix = "" | "
|
|
5
|
+
export type CompactSuffix = "" | "<" | ">" | "~" | "!" | "x" | "?" | "-";
|
|
6
6
|
export interface Row {
|
|
7
7
|
id: string;
|
|
8
8
|
state: StateWord;
|
|
@@ -28,11 +28,29 @@ export declare const SORT_KEYS: SortKey[];
|
|
|
28
28
|
* elapsed, and pace read it. Weekly-bound rows fall back to the weekly
|
|
29
29
|
* fields unchanged; rate-limit windows never drive these figures.
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The fields the state word and the binding helpers read. Structural, so
|
|
33
|
+
* the dashboard's ProviderView feeds the same table as the CLI snapshot.
|
|
34
|
+
*/
|
|
35
|
+
export interface StateSource {
|
|
36
|
+
exclusionReason: string | null;
|
|
37
|
+
advisory: (Pick<Advisory, "bindingWindow" | "bindingRemaining" | "remaining" | "status" | "urgency"> & {
|
|
38
|
+
closeToReset?: boolean;
|
|
39
|
+
aheadOfElapsed?: boolean | null;
|
|
40
|
+
}) | null;
|
|
41
|
+
quota: {
|
|
42
|
+
weeklyPct?: number;
|
|
43
|
+
usedPct?: number;
|
|
44
|
+
monthlyKind?: string;
|
|
45
|
+
monthlyPct?: number;
|
|
46
|
+
monthlyResetsAt?: string;
|
|
47
|
+
} | null;
|
|
48
|
+
}
|
|
49
|
+
export declare function isMonthlyBound(ps: StateSource): boolean;
|
|
32
50
|
/** Reset instant of the quota window, or null without a quota reading. */
|
|
33
51
|
export declare function bindingResetsAt(ps: ProviderSnapshot): string | null;
|
|
34
52
|
/** Used percent of the quota window. Null without a quota reading. */
|
|
35
|
-
export declare function bindingUsedPct(ps:
|
|
53
|
+
export declare function bindingUsedPct(ps: StateSource): number | null;
|
|
36
54
|
/**
|
|
37
55
|
* Binding leftover for a raw quota without an advisory (model catalogs):
|
|
38
56
|
* the same scarcer-headroom rule the engine applies, so the catalog
|
|
@@ -61,9 +79,25 @@ export declare function countdownText(ps: ProviderSnapshot, now: Date): string;
|
|
|
61
79
|
export declare function elapsedPct(ps: ProviderSnapshot, now: Date): number | null;
|
|
62
80
|
export declare function usedPctOf(ps: ProviderSnapshot): number | null;
|
|
63
81
|
export declare function railCells(ps: ProviderSnapshot, now: Date): RailCell[];
|
|
64
|
-
export declare function stateWord(ps:
|
|
82
|
+
export declare function stateWord(ps: StateSource): StateWord;
|
|
65
83
|
export declare function forecastText(ps: ProviderSnapshot, now: Date): string;
|
|
66
|
-
export declare
|
|
84
|
+
export declare const COMPACT_LEGEND = "no mark on track, < behind, > ahead, ~ watch, ! cap risk, x exhausted, ? measuring, - not reporting";
|
|
85
|
+
export declare function compactSuffix(ps: StateSource): CompactSuffix;
|
|
86
|
+
/**
|
|
87
|
+
* Providers a human surface lists: the enabled ones, as the dashboard
|
|
88
|
+
* shows them. JSON keeps every provider with its exclusion reason.
|
|
89
|
+
*/
|
|
90
|
+
export declare function shownProviders(providers: ProviderSnapshot[]): ProviderSnapshot[];
|
|
91
|
+
/** Display name of the recommended provider, or "none". */
|
|
92
|
+
export declare function useName(snapshot: {
|
|
93
|
+
recommendation: {
|
|
94
|
+
use: string;
|
|
95
|
+
};
|
|
96
|
+
providers: Array<{
|
|
97
|
+
id: string;
|
|
98
|
+
displayName: string;
|
|
99
|
+
}>;
|
|
100
|
+
}): string;
|
|
67
101
|
export declare function assertValidSortKey(key: string): asserts key is SortKey;
|
|
68
102
|
export declare function sortProviders(providers: ProviderSnapshot[], key: string, use: string): ProviderSnapshot[];
|
|
69
103
|
export declare function paceText(ps: ProviderSnapshot, now?: Date): string;
|
package/dist/format/rows.js
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
import { rateLimitWaits } from "./rate-limit-wait.js";
|
|
2
|
+
import { dayText, durationFromDays, durationText, unusedAtReset } from "./time.js";
|
|
2
3
|
export const RAIL_CELLS = 20;
|
|
3
4
|
export const SORT_KEYS = ["recommended", "reset-asc", "reset-desc", "used-desc", "used-asc"];
|
|
4
5
|
const DAY_MS = 86400000;
|
|
5
|
-
const HOUR_MS = 3600000;
|
|
6
|
-
const MIN_MS = 60000;
|
|
7
6
|
function msOf(iso) {
|
|
8
7
|
if (!iso)
|
|
9
8
|
return null;
|
|
10
9
|
const ms = new Date(iso).getTime();
|
|
11
10
|
return Number.isNaN(ms) ? null : ms;
|
|
12
11
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Quota-window resolution, mirroring the dashboard helpers: the advisory
|
|
15
|
-
* binding window rations the account, so standalone resets, usage,
|
|
16
|
-
* elapsed, and pace read it. Weekly-bound rows fall back to the weekly
|
|
17
|
-
* fields unchanged; rate-limit windows never drive these figures.
|
|
18
|
-
*/
|
|
19
12
|
export function isMonthlyBound(ps) {
|
|
20
13
|
return (ps.advisory?.bindingWindow === "monthly" &&
|
|
21
14
|
ps.quota?.monthlyKind === "included" &&
|
|
@@ -94,23 +87,17 @@ export function bindingAvgPace(ps, now) {
|
|
|
94
87
|
export function weeklyPctOf(q) {
|
|
95
88
|
return q?.weeklyPct ?? q?.usedPct;
|
|
96
89
|
}
|
|
97
|
-
//
|
|
98
|
-
// spans read 1m so a live window never prints 0m.
|
|
90
|
+
// Countdown in the shared floored form ("6d 23h", "5h 12m", "45m").
|
|
99
91
|
export function fmtDuration(ms) {
|
|
100
|
-
|
|
101
|
-
return `${Math.floor(ms / DAY_MS)}d`;
|
|
102
|
-
if (ms >= 90 * MIN_MS)
|
|
103
|
-
return `${Math.floor(ms / HOUR_MS)}h`;
|
|
104
|
-
return `${Math.max(1, Math.floor(ms / MIN_MS))}m`;
|
|
92
|
+
return durationText(ms);
|
|
105
93
|
}
|
|
106
94
|
// Short weekday plus calendar date of an ISO instant in the locked English
|
|
107
|
-
// copy, e.g. "Tue Sep
|
|
108
|
-
// ("unused until Tue Sep
|
|
95
|
+
// copy, e.g. "Tue 15 Sep". Pinned to en-US: the sentence it feeds
|
|
96
|
+
// ("unused until Tue 15 Sep") is English, so a non-English machine must not
|
|
109
97
|
// print localized parts inside it. A bare weekday scans as this coming week,
|
|
110
98
|
// which misreads a monthly reset sitting weeks out.
|
|
111
99
|
export function dayOf(iso) {
|
|
112
|
-
|
|
113
|
-
return `${when.toLocaleDateString("en-US", { weekday: "short" })} ${when.toLocaleDateString("en-US", { day: "numeric", month: "short" })}`;
|
|
100
|
+
return dayText(iso);
|
|
114
101
|
}
|
|
115
102
|
export function countdownText(ps, now) {
|
|
116
103
|
const resetsMs = msOf(bindingResetsAt(ps));
|
|
@@ -245,25 +232,31 @@ export function forecastText(ps, now) {
|
|
|
245
232
|
text = "Exhausted";
|
|
246
233
|
}
|
|
247
234
|
else if (adv.paceSource === "unknown" || adv.burnRate === null) {
|
|
248
|
-
text = `Measuring pace; ${Math.round(adv.remaining)}% remains with ${adv.daysLeft
|
|
235
|
+
text = `Measuring pace; ${Math.round(adv.remaining)}% remains with ${durationFromDays(adv.daysLeft)} until reset`;
|
|
249
236
|
}
|
|
250
|
-
else if (adv.status === "watch") {
|
|
237
|
+
else if (adv.status === "at risk" || adv.status === "watch") {
|
|
238
|
+
const word = adv.status === "at risk" ? "cap risk" : "watch";
|
|
251
239
|
text =
|
|
252
240
|
adv.daysToExhaust !== null && Number.isFinite(adv.daysToExhaust)
|
|
253
|
-
? `Exhausts in ${adv.daysToExhaust
|
|
254
|
-
:
|
|
241
|
+
? `Exhausts in ${durationFromDays(adv.daysToExhaust)} — ${word}`
|
|
242
|
+
: `Near the cap — ${word}`;
|
|
243
|
+
}
|
|
244
|
+
else if (adv.closeToReset === true) {
|
|
245
|
+
// Same words as the dashboard (LANDS_NEAR_FULL in web PaceBar.tsx).
|
|
246
|
+
text = "Lands near 100% at reset";
|
|
255
247
|
}
|
|
256
|
-
else if (adv.wastePct !== null && adv.wastePct
|
|
257
|
-
text =
|
|
248
|
+
else if (adv.wastePct !== null && Math.round(adv.wastePct) >= 1) {
|
|
249
|
+
text = unusedAtReset(adv.wastePct, bindingResetsAt(ps), now.getTime());
|
|
258
250
|
}
|
|
259
251
|
else {
|
|
260
|
-
|
|
252
|
+
// Same words as the dashboard (NO_SPARE in web PaceBar.tsx).
|
|
253
|
+
text = "No spare quota at 24h pace";
|
|
261
254
|
}
|
|
262
255
|
// Engine estimate vocabulary, mirroring the snapshot reason transform.
|
|
263
256
|
// A monthly quota forecast never carries the weekly estimate flag.
|
|
264
257
|
if (!isMonthlyBound(ps) && ps.quota?.resetsAtEstimated) {
|
|
265
|
-
if (text.includes("
|
|
266
|
-
text = text.replace("
|
|
258
|
+
if (text.includes("unused at reset"))
|
|
259
|
+
text = text.replace("unused at reset", "unused at estimated reset");
|
|
267
260
|
else if (text.includes("until reset"))
|
|
268
261
|
text = text.replace("until reset", "until estimated reset");
|
|
269
262
|
else if (!text.includes("estimated"))
|
|
@@ -271,21 +264,34 @@ export function forecastText(ps, now) {
|
|
|
271
264
|
}
|
|
272
265
|
return text;
|
|
273
266
|
}
|
|
274
|
-
// Compact
|
|
275
|
-
//
|
|
267
|
+
// Compact glyph: one per state word, so the statusline never folds two
|
|
268
|
+
// states into one mark. COMPACT_LEGEND is printed in `status --help`.
|
|
269
|
+
const COMPACT_GLYPHS = {
|
|
270
|
+
"On track": "",
|
|
271
|
+
"Behind pace": "<",
|
|
272
|
+
"Ahead of pace": ">",
|
|
273
|
+
Watch: "~",
|
|
274
|
+
"Cap risk": "!",
|
|
275
|
+
"Quota exhausted": "x",
|
|
276
|
+
"Monthly exhausted": "x",
|
|
277
|
+
Measuring: "?",
|
|
278
|
+
"Not reporting": "-",
|
|
279
|
+
};
|
|
280
|
+
export const COMPACT_LEGEND = "no mark on track, < behind, > ahead, ~ watch, ! cap risk, x exhausted, ? measuring, - not reporting";
|
|
276
281
|
export function compactSuffix(ps) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
282
|
+
return COMPACT_GLYPHS[stateWord(ps)];
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Providers a human surface lists: the enabled ones, as the dashboard
|
|
286
|
+
* shows them. JSON keeps every provider with its exclusion reason.
|
|
287
|
+
*/
|
|
288
|
+
export function shownProviders(providers) {
|
|
289
|
+
return providers.filter((p) => p.enabled !== false);
|
|
290
|
+
}
|
|
291
|
+
/** Display name of the recommended provider, or "none". */
|
|
292
|
+
export function useName(snapshot) {
|
|
293
|
+
const use = snapshot.recommendation.use;
|
|
294
|
+
return snapshot.providers.find((p) => p.id === use)?.displayName ?? use;
|
|
289
295
|
}
|
|
290
296
|
export function assertValidSortKey(key) {
|
|
291
297
|
if (!SORT_KEYS.includes(key)) {
|
package/dist/format/terminal.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildRow, compactSuffix, isMonthlyBound, sortProviders, weeklyPctOf, } from "./rows.js";
|
|
1
|
+
import { buildRow, compactSuffix, shownProviders, useName, isMonthlyBound, sortProviders, weeklyPctOf, } from "./rows.js";
|
|
2
2
|
import { rateLimitWaits } from "./rate-limit-wait.js";
|
|
3
3
|
const GAP = " ";
|
|
4
4
|
const MIN_PROV_WIDTH = 12;
|
|
@@ -75,10 +75,11 @@ export function renderWide(snapshot, opts) {
|
|
|
75
75
|
const g = opts.ascii ? ASCII : UNICODE;
|
|
76
76
|
const color = !!opts.color && !opts.ascii;
|
|
77
77
|
const use = snapshot.recommendation.use;
|
|
78
|
-
const sorted = sortProviders(snapshot.providers, opts.sort ?? "recommended", use);
|
|
79
|
-
const width = provWidthFor(snapshot.providers.map((p) => p.displayName));
|
|
78
|
+
const sorted = sortProviders(shownProviders(snapshot.providers), opts.sort ?? "recommended", use);
|
|
79
|
+
const width = provWidthFor(shownProviders(snapshot.providers).map((p) => p.displayName));
|
|
80
80
|
const rows = sorted.map((p) => ({ p, row: buildRow(p, opts.now) }));
|
|
81
81
|
const paceWidth = Math.max("PACE (%/DAY)".length, ...rows.map(({ row }) => row.pace.length));
|
|
82
|
+
const resetsWidth = Math.max("RESETS".length, ...rows.map(({ row }) => row.countdown.length));
|
|
82
83
|
const paint = (s, code) => (color ? `${code}${s}${RESET}` : s);
|
|
83
84
|
const resetsIndent = " ".repeat(width + GAP.length + 6 + GAP.length + 8 + GAP.length + paceWidth + GAP.length + 20 + GAP.length);
|
|
84
85
|
const leftoverLine = (p) => {
|
|
@@ -95,7 +96,7 @@ export function renderWide(snapshot, opts) {
|
|
|
95
96
|
"ELAPSED".padStart(8),
|
|
96
97
|
"PACE (%/DAY)".padEnd(paceWidth),
|
|
97
98
|
"USED VS TIME".padEnd(20),
|
|
98
|
-
"RESETS".padEnd(
|
|
99
|
+
"RESETS".padEnd(resetsWidth),
|
|
99
100
|
"STATE".padEnd(19),
|
|
100
101
|
"FORECAST",
|
|
101
102
|
].join(GAP);
|
|
@@ -106,7 +107,7 @@ export function renderWide(snapshot, opts) {
|
|
|
106
107
|
const elapsed = (row.elapsedPct === null ? g.dash : `${row.elapsedPct}%`).padStart(8);
|
|
107
108
|
const pace = (opts.ascii ? asciiText(row.pace) : row.pace).padEnd(paceWidth);
|
|
108
109
|
const rail = renderRail(row.railCells, g, row.state, color);
|
|
109
|
-
const countdown = (opts.ascii ? asciiText(row.countdown) : row.countdown).padEnd(
|
|
110
|
+
const countdown = (opts.ascii ? asciiText(row.countdown) : row.countdown).padEnd(resetsWidth);
|
|
110
111
|
const state = row.state.padEnd(19);
|
|
111
112
|
const forecast = opts.ascii ? asciiText(row.forecast) : row.forecast;
|
|
112
113
|
const wait = row.wait
|
|
@@ -131,8 +132,8 @@ export function renderNarrow(snapshot, opts) {
|
|
|
131
132
|
const g = opts.ascii ? ASCII : UNICODE;
|
|
132
133
|
const color = !!opts.color && !opts.ascii;
|
|
133
134
|
const use = snapshot.recommendation.use;
|
|
134
|
-
const sorted = sortProviders(snapshot.providers, opts.sort ?? "recommended", use);
|
|
135
|
-
const width = provWidthFor(snapshot.providers.map((p) => p.displayName));
|
|
135
|
+
const sorted = sortProviders(shownProviders(snapshot.providers), opts.sort ?? "recommended", use);
|
|
136
|
+
const width = provWidthFor(shownProviders(snapshot.providers).map((p) => p.displayName));
|
|
136
137
|
const lines = [];
|
|
137
138
|
for (const p of sorted) {
|
|
138
139
|
const row = buildRow(p, opts.now);
|
|
@@ -164,13 +165,13 @@ export function renderNarrow(snapshot, opts) {
|
|
|
164
165
|
// Takes the fixed clock for signature parity; compact shows no ages.
|
|
165
166
|
export function renderCompact(snapshot, now = new Date()) {
|
|
166
167
|
const use = snapshot.recommendation.use;
|
|
167
|
-
const sorted = sortProviders(snapshot.providers, "recommended", use);
|
|
168
|
+
const sorted = sortProviders(shownProviders(snapshot.providers), "recommended", use);
|
|
168
169
|
const entries = sorted
|
|
169
170
|
.filter((p) => p.quota !== null)
|
|
170
171
|
.map((p) => {
|
|
171
172
|
const u = weeklyPctOf(p.quota);
|
|
172
173
|
const used = typeof u === "number" && Number.isFinite(u) ? String(Math.round(u)) : "?";
|
|
173
|
-
return `[${p.
|
|
174
|
+
return `[${p.displayName}:${used}%${compactSuffix(p)}]`;
|
|
174
175
|
});
|
|
175
176
|
if (entries.length === 0)
|
|
176
177
|
return "(use: none)";
|
|
@@ -178,8 +179,8 @@ export function renderCompact(snapshot, now = new Date()) {
|
|
|
178
179
|
const found = rateLimitWaits(p, now);
|
|
179
180
|
if (found.length === 0)
|
|
180
181
|
return [];
|
|
181
|
-
return [`${p.
|
|
182
|
+
return [`${p.displayName} ${found.map((w) => w.text).join(", ")}`];
|
|
182
183
|
});
|
|
183
|
-
const base = `${entries.join(" | ")} (use: ${
|
|
184
|
+
const base = `${entries.join(" | ")} (use: ${useName(snapshot)})`;
|
|
184
185
|
return waits.length === 0 ? base : `${base} (wait: ${waits.join("; ")})`;
|
|
185
186
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Floored duration: "6d 23h" from one day up, "5h 12m" from one hour up,
|
|
3
|
+
* else "45m". Sub-minute spans read "1m" so a live window never prints 0m.
|
|
4
|
+
*/
|
|
5
|
+
export declare function durationText(ms: number): string;
|
|
6
|
+
/** Duration from fractional days, for engine fields such as daysLeft. */
|
|
7
|
+
export declare function durationFromDays(days: number): string;
|
|
8
|
+
/**
|
|
9
|
+
* Wall-clock instant: "Sat 14:46" within 7 days of `nowMs`, where the
|
|
10
|
+
* weekday is unambiguous, else "Sun 22 Nov 23:05". Without `nowMs` the
|
|
11
|
+
* dated form is used. Null when unparseable.
|
|
12
|
+
*/
|
|
13
|
+
export declare function clockText(iso: string | null | undefined, nowMs?: number): string | null;
|
|
14
|
+
/** Calendar date without the weekday or clock, e.g. "22 Nov". Empty when unparseable. */
|
|
15
|
+
export declare function dateText(iso: string | null | undefined): string;
|
|
16
|
+
/** Weekday plus calendar date, e.g. "Sun 22 Nov". */
|
|
17
|
+
export declare function dayText(iso: string | null | undefined): string;
|
|
18
|
+
/** The one waste sentence: "16% unused at reset (Fri 13:14)". */
|
|
19
|
+
export declare function unusedAtReset(wastePct: number, resetsAt: string | null | undefined, nowMs?: number): string;
|