limitcast 0.8.0 → 0.8.1
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/package.json +1 -1
- package/src/forecast.mjs +28 -4
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ Without a valid license the guard runs as a preview: it allows everything and re
|
|
|
66
66
|
|
|
67
67
|
## How the forecast works
|
|
68
68
|
|
|
69
|
-
Each limit reading is saved to `~/.local/state/limitcast/samples.jsonl` when it changes (kept 8 days). The burn rate is the least-squares slope of percent used over the last hour of the current window, and the runout time is where that line reaches 100%. **AT_RISK** means that happens before the reset; **NEAR** means 95% or more is used. Claude sessions of the same account share one history (matched by window reset times, and usage that only rises), so two accounts used in parallel never mix.
|
|
69
|
+
Each limit reading is saved to `~/.local/state/limitcast/samples.jsonl` when it changes (kept 8 days). The burn rate is the least-squares slope of percent used over the last hour of the current window, and the runout time is where that line reaches 100%. Windows of a day or more (the weekly one) use the average pace over the last full day, idle time included, unless the last hour's pace runs them out within the hour. **AT_RISK** means that happens before the reset; **NEAR** means 95% or more is used. Claude sessions of the same account share one history (matched by window reset times, and usage that only rises), so two accounts used in parallel never mix.
|
|
70
70
|
|
|
71
71
|
## Pricing
|
|
72
72
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "limitcast",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Stretch your Claude Code plan: measure what every session loads before you type, cut what you never use, and stop runaway subagents before they burn your window.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": { "limitcast": "bin/limitcast.mjs" },
|
package/src/forecast.mjs
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
const RESET_JITTER_S = 120; // Codex resets_at drifts by seconds between events
|
|
6
6
|
const RECENT_MS = 60 * 60 * 1000;
|
|
7
7
|
const NEAR_PCT = 95;
|
|
8
|
+
const DAY_MS = 24 * 3600_000;
|
|
9
|
+
const IMMINENT_MS = 60 * 60_000;
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Burn rate and limit forecast for one (src, win) series.
|
|
@@ -22,16 +24,38 @@ export function forecast(samples, now) {
|
|
|
22
24
|
|
|
23
25
|
const window = sorted.filter((s) => Math.abs(s.reset - last.reset) <= RESET_JITTER_S);
|
|
24
26
|
const recent = window.filter((s) => s.t >= now - RECENT_MS);
|
|
25
|
-
const
|
|
26
|
-
const rate = slopePerHour(pts);
|
|
27
|
+
const short = slopePerHour(recent.length >= 2 ? recent : window);
|
|
27
28
|
// NEAR: so close to the limit that one heavy turn can finish it, even with no burn rate to go on yet.
|
|
28
29
|
const calm = last.pct >= NEAR_PCT ? 'NEAR' : 'OK';
|
|
29
|
-
|
|
30
|
+
const runout = (/** @type {number|null} */ r) => (r === null || r <= 0 ? null : last.t + ((100 - last.pct) / r) * 3600_000);
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
let rate = short;
|
|
33
|
+
let wall = runout(short);
|
|
34
|
+
// A multi-day window spans nights and idle days: one busy hour projected across them predicts a runout days
|
|
35
|
+
// early. Use the average pace over the last full day, idle time included, unless the last hour's pace runs
|
|
36
|
+
// the window out within the hour (a burst near the end of the week must still be caught).
|
|
37
|
+
const len = windowMs(last.win);
|
|
38
|
+
if (len >= DAY_MS && !(wall !== null && wall - now <= IMMINENT_MS)) {
|
|
39
|
+
const from = now - DAY_MS;
|
|
40
|
+
// Usage a day ago: 0% if the window began since then, else the last reading before then (or the first one).
|
|
41
|
+
const before = window.filter((s) => s.t <= from);
|
|
42
|
+
const then = resetMs - len >= from ? 0 : (before.at(-1) ?? window[0]).pct;
|
|
43
|
+
rate = (last.pct - then) / 24;
|
|
44
|
+
wall = runout(rate);
|
|
45
|
+
}
|
|
46
|
+
if (wall === null) return { ...base, rate, verdict: calm };
|
|
32
47
|
return { ...base, rate, wall, verdict: wall < resetMs ? 'AT_RISK' : calm };
|
|
33
48
|
}
|
|
34
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Length of a window from its name ("5h", "7d", "90m"), in ms; 0 if unknown.
|
|
52
|
+
* @param {string} win
|
|
53
|
+
*/
|
|
54
|
+
export function windowMs(win) {
|
|
55
|
+
const m = /^(\d+)([mhd])$/.exec(win);
|
|
56
|
+
return m ? Number(m[1]) * { m: 60_000, h: 3600_000, d: DAY_MS }[/** @type {'m'|'h'|'d'} */ (m[2])] : 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
35
59
|
/**
|
|
36
60
|
* Least-squares slope of pct over time, in % per hour.
|
|
37
61
|
* Needs 2+ distinct timestamps spanning at least 5 minutes, or the coarse integer percents are noise.
|