Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

statusline: color the rate-limit pace notice by expected-lockout severity (#3229)

Maximilian Roos2f0ee196e668
diff --git a/docs/content/claude-code.md b/docs/content/claude-code.md
index 905305df5..cdbd618d6 100644
--- a/docs/content/claude-code.md
+++ b/docs/content/claude-code.md
@@ -109,7 +109,7 @@ Claude Code agents can run in isolated worktrees (`isolation: "worktree"`). By d
<code>~/w/myproject.feature-auth !πŸ€– @<span style='color:#0a0'>+42</span> <span style='color:#a00'>-8</span> <span style='color:#0a0'>↑3</span> <span style='color:#0a0'>⇑1</span> <span style='color:#0a0'>#3035</span> Opus πŸŒ” 65% <span style='color:#a70'>1.4Γ—(10am–3pm)</span></code>
-When Claude Code provides context window usage via stdin JSON, a moon phase gauge appears (πŸŒ•β†’πŸŒ‘ as context fills). A yellow `<n>Γ—(<window>)` segment appears when Claude's 5-hour or weekly rate limit is on track to be hit before reset β€” `1.4Γ—(10am–3pm)` reads as 1.4Γ— the pace that would exactly fill that window. Above 90% used it shows usage instead of pace β€” `93%(10am–3pm)` β€” near the cap, how much is left matters more than how fast it's going.
+When Claude Code provides context window usage via stdin JSON, a moon phase gauge appears (πŸŒ•β†’πŸŒ‘ as context fills). A `<n>Γ—(<window>)` segment appears when Claude's 5-hour or weekly rate limit is on track to be hit before reset β€” `1.4Γ—(10am–3pm)` reads as 1.4Γ— the pace that would exactly fill that window. Its colour deepens with severity β€” dim, then dim-yellow, then yellow β€” as more of the window would be spent locked out at the cap, so a fast pace that would only tip over near the reset stays dim. Above 90% used it shows usage instead of pace β€” `93%(10am–3pm)` β€” near the cap, how much is left matters more than how fast it's going.
<figure class="demo">
<picture>
diff --git a/skills/worktrunk/reference/claude-code.md b/skills/worktrunk/reference/claude-code.md
index 14c6d713f..93f325707 100644
--- a/skills/worktrunk/reference/claude-code.md
+++ b/skills/worktrunk/reference/claude-code.md
@@ -111,7 +111,7 @@ Claude Code agents can run in isolated worktrees (`isolation: "worktree"`). By d
<code>~/w/myproject.feature-auth !πŸ€– @<span style='color:#0a0'>+42</span> <span style='color:#a00'>-8</span> <span style='color:#0a0'>↑3</span> <span style='color:#0a0'>⇑1</span> <span style='color:#0a0'>#3035</span> Opus πŸŒ” 65% <span style='color:#a70'>1.4Γ—(10am–3pm)</span></code>
-When Claude Code provides context window usage via stdin JSON, a moon phase gauge appears (πŸŒ•β†’πŸŒ‘ as context fills). A yellow `<n>Γ—(<window>)` segment appears when Claude's 5-hour or weekly rate limit is on track to be hit before reset β€” `1.4Γ—(10am–3pm)` reads as 1.4Γ— the pace that would exactly fill that window. Above 90% used it shows usage instead of pace β€” `93%(10am–3pm)` β€” near the cap, how much is left matters more than how fast it's going.
+When Claude Code provides context window usage via stdin JSON, a moon phase gauge appears (πŸŒ•β†’πŸŒ‘ as context fills). A `<n>Γ—(<window>)` segment appears when Claude's 5-hour or weekly rate limit is on track to be hit before reset β€” `1.4Γ—(10am–3pm)` reads as 1.4Γ— the pace that would exactly fill that window. Its colour deepens with severity β€” dim, then dim-yellow, then yellow β€” as more of the window would be spent locked out at the cap, so a fast pace that would only tip over near the reset stays dim. Above 90% used it shows usage instead of pace β€” `93%(10am–3pm)` β€” near the cap, how much is left matters more than how fast it's going.
Add to `~/.claude/settings.json`:
diff --git a/src/cli/list.rs b/src/cli/list.rs
index c1a9a2d6b..25270635c 100644
--- a/src/cli/list.rs
+++ b/src/cli/list.rs
@@ -22,7 +22,7 @@ pub enum ListSubcommand {
- `.rate_limits.{five_hour,seven_day}.used_percentage` β€” rate-limit window usage (0–100)
- `.rate_limits.{five_hour,seven_day}.resets_at` β€” window reset time (Unix epoch seconds)
-The pace segment appears only when usage is likely to hit a rate limit before its window resets, and shows the higher-risk window: `2.9Γ—(Tue–Tue 5pm)` reads as 2.9Γ— the pace that would exactly fill that window. Above 90% used it shows usage instead of pace β€” `93%(Tue–Tue 5pm)` β€” near the cap, how much is left matters more than how fast it's going. "Likely" is a Bayesian forecast; early-window bursts don't trigger it. With `-vv`, each window's inputs and projection are logged to `.git/wt/logs/trace.log`.
+The pace segment appears only when usage is likely to hit a rate limit before its window resets, and shows the higher-risk window: `2.9Γ—(Tue–Tue 5pm)` reads as 2.9Γ— the pace that would exactly fill that window. Above 90% used it shows usage instead of pace β€” `93%(Tue–Tue 5pm)` β€” near the cap, how much is left matters more than how fast it's going. "Likely" is a Bayesian forecast; early-window bursts don't trigger it. Its colour deepens with severity β€” dim, then dim-yellow, then yellow β€” as the forecast lockout (how much of the window would be spent capped) grows, so a fast pace that would only tip over near the reset stays dim rather than alarming. With `-vv`, each window's inputs and projection are logged to `.git/wt/logs/trace.log`.
"#)]
Statusline {
/// Output format
diff --git a/src/commands/statusline.rs b/src/commands/statusline.rs
index 5bee2fe35..d700f8a98 100644
--- a/src/commands/statusline.rs
+++ b/src/commands/statusline.rs
@@ -197,6 +197,16 @@ const PRIORITY_RATE_LIMITS: u8 = 3;
// weeks cluster β€” so `Οƒ_7d` is only modestly below `Οƒ_5h`. The values below
// are calibrated by feel; with real `(u, t, resets_at)` traces logged, fit
// them from data and delete this paragraph.
+//
+// ## Two questions, two axes
+//
+// `P(over)` above answers *whether* β€” it gates the segment's appearance. It
+// saturates near 1, so it can't also grade *how bad*: a near-certain cross in
+// the last hour and one halfway through the week both read β‰ˆ1. Severity is a
+// second axis, [`expected_lockout`], which keeps discriminating after
+// `P(over)` has flat-lined; the segment's colour depth comes from it. The two
+// coincide only at the show boundary (`P(over) β‰ˆ 0.5` ⇔ a cross right at the
+// reset ⇔ ~0 lockout) and diverge above it.
// ---------------------------------------------------------------------------
/// Prior parameters for one rate-limit window's pace prediction.
@@ -304,6 +314,32 @@ fn erf(x: f64) -> f64 {
sign * (1.0 - poly * (-x * x).exp())
}
+/// Posterior mean and variance of the long-run rate `Ξ»` after observing
+/// `C(t) = u`. Shared by [`p_over`] (the show/no-show gate) and
+/// [`expected_lockout`] (the colour-severity axis) so the one Bayes update
+/// can't drift between them.
+///
+/// Gaussian-on-Gaussian conjugate update: both precisions live on `Ξ»`. The
+/// data precision is `t/σ²` because observing `C(t) = u` is equivalent to
+/// observing the rate `u/t` with variance `σ²/t`:
+///
+/// ```text
+/// post_prec = prior_prec + data_prec
+/// post_mean = (prior_prec Β· mβ‚€ + data_prec Β· (u/t)) / post_prec
+/// ```
+///
+/// The `data_prec Β· (u/t)` term is rewritten as `u / σ²` so both terms share
+/// a denominator and the multiplication is cheaper. At `t = 0` the data
+/// precision is 0 and this collapses to the prior `(mβ‚€, sβ‚€Β²)`.
+fn posterior_lambda(u: f64, t: f64, p: &WindowPriors) -> (f64, f64) {
+ let sigma2 = p.sigma * p.sigma;
+ let prior_prec = 1.0 / (p.s0 * p.s0);
+ let data_prec = t / sigma2;
+ let post_var = 1.0 / (prior_prec + data_prec);
+ let post_mean = post_var * (p.m0 * prior_prec + u / sigma2);
+ (post_mean, post_var)
+}
+
/// Probability that final usage hits or exceeds the limit (`C(1) β‰₯ 1.0`),
/// given fraction-of-limit-used `u` and fraction-of-window-elapsed `t`.
///
@@ -320,40 +356,146 @@ fn p_over(u: f64, t: f64, p: &WindowPriors) -> f64 {
// window's worth of process noise on top.
(p.m0, p.s0 * p.s0 + p.sigma * p.sigma)
} else {
- // --- Bayes update on `Ξ»` from one observation `C(t) = u` ---
- //
- // Both precisions live on the rate `Ξ»`. The data precision is `t/σ²`
- // because observing `C(t) = u` is equivalent to observing the rate
- // `u/t` with variance `σ²/t`. The posterior is Gaussian with:
- //
- // post_prec = prior_prec + data_prec
- // post_mean = (prior_prec Β· mβ‚€ + data_prec Β· (u/t)) / post_prec
- //
- // The `data_prec Β· (u/t)` term is rewritten as `u / σ²` so both
- // terms share a denominator and the multiplication is cheaper.
- let sigma2 = p.sigma * p.sigma;
- let prior_prec = 1.0 / (p.s0 * p.s0);
- let data_prec = t / sigma2;
- let post_var = 1.0 / (prior_prec + data_prec);
- let post_mean = post_var * (p.m0 * prior_prec + u / sigma2);
-
- // --- Predictive for `C(1) = u + (rate Γ— time remaining) + noise` ---
+ // Posterior on `Ξ»`, then the predictive for
+ // `C(1) = u + (rate Γ— time remaining) + noise`.
//
// Mean: what we've used, plus the posterior rate projected over the
// remaining `(1 - t)` of the window.
//
// Variance has two pieces: uncertainty in the rate estimate
- // propagated over `(1 - t)` (squared because it scales the deterministic
- // drift term), plus accumulated process noise `σ² Β· (1 - t)` over the
- // remaining interval (linear because Brownian variance grows with time).
+ // propagated over `(1 - t)` (squared because it scales the
+ // deterministic drift term), plus accumulated process noise
+ // `σ² Β· (1 - t)` over the remaining interval (linear because Brownian
+ // variance grows with time).
+ let (post_mean, post_var) = posterior_lambda(u, t, p);
let mean = u + post_mean * (1.0 - t);
- let var = post_var * (1.0 - t).powi(2) + sigma2 * (1.0 - t);
+ let var = post_var * (1.0 - t).powi(2) + p.sigma * p.sigma * (1.0 - t);
(mean, var)
};
// Upper tail of the Gaussian predictive at 1.0: `P(C(1) β‰₯ 1)`.
standard_normal_cdf((mean - 1.0) / var.sqrt())
}
+/// Gauss–Hermite nodes and weights (7-point, physicists' convention) for
+/// integrating a smooth function against `N(m, sΒ²)`:
+///
+/// ```text
+/// E[g(Ξ»)] β‰ˆ (1/βˆšΟ€) Β· Ξ£ wα΅’ Β· g(m + √2Β·sΒ·xα΅’)
+/// ```
+///
+/// Seven nodes is ample for a colour-tier decision. The integrand's only
+/// non-smoothness is the lockout kink at `Ξ» = (1βˆ’u)/(1βˆ’t)`; a finer rule
+/// wouldn't move the resulting tier.
+const GAUSS_HERMITE_7: [(f64, f64); 7] = [
+ (-2.651_961_356_835_233, 0.000_971_781_245_100),
+ (-1.673_551_628_767_471, 0.054_515_582_819_127),
+ (-0.816_287_882_858_965, 0.425_607_252_610_128),
+ (0.0, 0.810_264_617_556_807),
+ (0.816_287_882_858_965, 0.425_607_252_610_128),
+ (1.673_551_628_767_471, 0.054_515_582_819_127),
+ (2.651_961_356_835_233, 0.000_971_781_245_100),
+];
+
+/// Expected fraction of the window that will be spent locked out at the cap,
+/// under the posterior on the rate `Ξ»`. This is the colour-severity axis.
+///
+/// Where [`p_over`] decides *whether* the cap is likely to be hit, this grades
+/// *how much of the window* is lost once it is. Given a rate `Ξ»`, the mean
+/// trajectory crosses the cap at `t* = t + (1βˆ’u)/Ξ»`, so the remaining locked-
+/// out fraction is `max(0, 1 βˆ’ t*)`. Averaging that over the posterior
+/// `Ξ» ~ N(posterior_lambda)` is what makes the metric degrade gracefully:
+///
+/// - When a cross is unlikely, most of the posterior mass never reaches the
+/// cap (lockout 0), so the expectation stays near zero and tracks
+/// confidence β€” a thin early-window burst inflates the raw `u/t` pace but
+/// not this.
+/// - When a cross is near-certain, the expectation tracks the deterministic
+/// lockout and keeps discriminating *after* `p_over` has saturated at 1 β€”
+/// "crosses halfway through the week" reads as worse than "crosses in the
+/// last hour", which `p_over` alone cannot tell apart.
+///
+/// A non-positive `Ξ»` never crosses, so its lockout is clamped to 0; without
+/// the clamp the `(1βˆ’u)/Ξ»` term would blow up for the Gaussian's negative
+/// tail.
+fn expected_lockout(u: f64, t: f64, p: &WindowPriors) -> f64 {
+ let remaining = 1.0 - t;
+ if remaining <= 0.0 {
+ return 0.0;
+ }
+ let headroom = (1.0 - u).max(0.0);
+ let (mean, var) = posterior_lambda(u, t, p);
+ let sd = var.sqrt();
+ let mut acc = 0.0;
+ for (x, w) in GAUSS_HERMITE_7 {
+ let lambda = mean + std::f64::consts::SQRT_2 * sd * x;
+ let lockout = if lambda > 0.0 {
+ (remaining - headroom / lambda).max(0.0)
+ } else {
+ 0.0
+ };
+ acc += w * lockout;
+ }
+ acc / std::f64::consts::PI.sqrt()
+}
+
+/// Expected-lockout colour-tier thresholds for the pace segment.
+///
+/// The segment only appears once a cap is likely to be hit ([`p_over`] β‰₯
+/// [`RATE_LIMIT_P_THRESHOLD`]); these grade severity, deepening the colour.
+///
+/// They are cutoffs on the **duration-weighted cost** ([`lockout_cost`]), not
+/// the raw lockout fraction β€” anchored on the 5-hour window, where the weight
+/// is 1 so cost equals the fraction. So for the 5h window `0.10` β‰ˆ a tenth of
+/// the window forfeited and `0.30` β‰ˆ a third (its original calibration is
+/// preserved); a longer window crosses the same cutoff at a proportionally
+/// smaller fraction. Feel-calibrated; tune from real traces once they're
+/// logged.
+const LOCKOUT_DIM_YELLOW: f64 = 0.10;
+const LOCKOUT_YELLOW: f64 = 0.30;
+
+/// Weight an expected-lockout fraction into a cross-window severity *cost*.
+///
+/// The same lockout *fraction* costs very different amounts of real time
+/// across windows: 0.30 of the 5-hour window is 1.5 h forfeited, 0.30 of the
+/// 7-day window is ~50 h (~2 days). Colouring on the raw fraction would treat
+/// those as equally severe. The `√(window/5h)` weight fixes that: a longer
+/// window reaches a given tier at a smaller fraction, so losing real hours of
+/// a week outranks losing the same fraction of five hours.
+///
+/// **Duration drives this, not volatility.** The windows differ 33.6Γ— in
+/// length but only 1.17Γ— in `Οƒ`, and `Οƒ` is already folded into
+/// [`expected_lockout`]'s posterior integral β€” so weighting by `Οƒ` would both
+/// under-separate the windows and double-count uncertainty. `window_secs` is
+/// known exactly, free, and has the right dynamic range.
+///
+/// The exponent is `0.5` (√), not `1.0` (linear): pain is taken to *saturate*
+/// in absolute time β€” the tenth hour of a week forfeited stings less than the
+/// first β€” so a longer window earns somewhat more absolute-time tolerance
+/// before alarming. The 5-hour anchor has weight `√1 = 1`, leaving its
+/// thresholds (and snapshots) unchanged.
+fn lockout_cost(lockout: f64, window_secs: i64) -> f64 {
+ lockout * (window_secs as f64 / FIVE_HOUR_SECS as f64).sqrt()
+}
+
+/// Colour the pace segment by expected-lockout severity, deepening
+/// `dim β†’ dim-yellow β†’ yellow`. The peak is the segment's original flat
+/// yellow; lower-severity-but-still-shown cases are dimmed rather than
+/// recoloured, so the escalation stays within the statusline's
+/// named-ANSI + `dim` vocabulary and respects the terminal theme.
+///
+/// Severity is the duration-weighted [`lockout_cost`], so the threshold a
+/// window must clear scales with its length (see [`LOCKOUT_YELLOW`]).
+fn colorize_pace(body: &str, lockout: f64, window_secs: i64) -> String {
+ let cost = lockout_cost(lockout, window_secs);
+ if cost >= LOCKOUT_YELLOW {
+ color_print::cformat!("<yellow>{body}</>")
+ } else if cost >= LOCKOUT_DIM_YELLOW {
+ color_print::cformat!("<dim,yellow>{body}</>")
+ } else {
+ color_print::cformat!("<dim>{body}</>")
+ }
+}
+
/// 12-hour vs 24-hour clock preference. Carried as a parameter so the
/// formatters stay pure and unit-testable; the env-driven detection lives in
/// [`detect_clock_format`] at the call-site boundary.
@@ -477,12 +619,14 @@ fn select_binding_window(
let elapsed = (now_unix - (r.resets_at - r.window_secs)) as f64 / r.window_secs as f64;
let t = elapsed.clamp(0.0, 1.0);
let p = p_over(u, t, r.priors);
+ let lockout = expected_lockout(u, t.max(0.001), r.priors);
log::debug!(
- "rate-limit {} window: used={:.1}% elapsed={:.1}% pace={:.2}Γ— P(over)={p:.3} (show threshold {RATE_LIMIT_P_THRESHOLD})",
+ "rate-limit {} window: used={:.1}% elapsed={:.1}% pace={:.2}Γ— P(over)={p:.3} lockout={lockout:.3} cost={:.3} (show threshold {RATE_LIMIT_P_THRESHOLD})",
r.name,
u * 100.0,
t * 100.0,
u / t.max(0.001),
+ lockout_cost(lockout, r.window_secs),
);
(p >= RATE_LIMIT_P_THRESHOLD).then_some((p, r))
})
@@ -496,9 +640,10 @@ fn select_binding_window(
/// `1.9Γ—(Mon–Mon 3pm)`. `pace` is the **naive `u/t` ratio**: what the
/// user has actually consumed per unit elapsed window. `1.0Γ—` is on pace
/// to exactly fill the window; `>1.0Γ—` is over-pace. The Bayesian
-/// posterior `m₁` is only used by [`p_over`] to decide whether to show β€”
-/// for the *displayed* number, the raw measurement is more honest, more
-/// transparent, and tracks bursts naturally.
+/// posterior only drives *decisions* β€” whether to show ([`p_over`]) and how
+/// deeply to colour ([`expected_lockout`]); the *displayed* number stays the
+/// raw measurement, which is more honest, more transparent, and tracks
+/// bursts naturally.
///
/// Above [`RATE_LIMIT_NEAR_CAP_PCT`] used, the shape becomes
/// `<used>%(<window_bounds>)` β€” e.g. `93%(10am–3pm)` β€” showing how close
@@ -522,11 +667,20 @@ fn format_rate_limit_segment(readings: &[RateLimitReading], now_unix: i64) -> Op
&chrono::Local,
detect_clock_format(),
);
- // The whole segment is wrapped in yellow because its appearance *is*
- // the warning. Unlike informational segments where color picks out one
- // sub-glyph (`@+1` green, `?` cyan), here the entire string is the
- // "you should look at this" signal.
- Some(color_print::cformat!("<yellow>{reading}({bounds})</>"))
+ // The whole segment is coloured because its appearance *is* the warning β€”
+ // unlike informational segments where colour picks out one sub-glyph
+ // (`@+1` green, `?` cyan), here the entire string is the "you should look
+ // at this" signal. Its *depth* grades severity: expected lockout (how
+ // much of the window will be spent capped) deepens dim β†’ dim-yellow β†’
+ // yellow. The displayed number stays the raw `u/t` pace; only the colour
+ // carries the Bayesian severity, so an early-window burst inflates the
+ // number without lighting up the segment.
+ let lockout = expected_lockout(u, t, r.priors);
+ Some(colorize_pace(
+ &format!("{reading}({bounds})"),
+ lockout,
+ r.window_secs,
+ ))
}
/// Format context usage as a moon phase gauge.
@@ -1411,7 +1565,8 @@ mod tests {
let out =
format_rate_limit_segment(std::slice::from_ref(&r), now).expect("should be visible");
// Strip ANSI before asserting on the visible characters β€” the segment
- // is wrapped in `<yellow>…</>`.
+ // is colour-wrapped (the depth grades severity; see
+ // `test_pace_color_deepens_with_lockout`).
let visible = out.ansi_strip();
assert!(
visible.starts_with("1.3Γ—(") && visible.ends_with(')'),
@@ -1450,6 +1605,99 @@ mod tests {
assert!(format_rate_limit_segment(&[r], now).is_none());
}
+ #[test]
+ fn test_expected_lockout_bounds_and_monotonicity() {
+ // A fraction of the window is always in [0, 1].
+ for &(u, t) in &[
+ (0.10, 0.10),
+ (0.50, 0.40),
+ (0.80, 0.60),
+ (0.95, 0.90),
+ (0.99, 0.99),
+ ] {
+ let l = expected_lockout(u, t, &SEVEN_DAY_PRIORS);
+ assert!(
+ (0.0..=1.0).contains(&l),
+ "lockout out of range at u={u}, t={t}: {l}"
+ );
+ }
+ // More used at the same elapsed β‡’ higher posterior rate and less
+ // headroom β‡’ earlier projected cross β‡’ strictly more lockout.
+ let lo = expected_lockout(0.40, 0.50, &SEVEN_DAY_PRIORS);
+ let hi = expected_lockout(0.80, 0.50, &SEVEN_DAY_PRIORS);
+ assert!(
+ hi > lo,
+ "expected more lockout at higher usage: {lo} vs {hi}"
+ );
+ // Past the reset there is nothing left to lock out.
+ assert_eq!(expected_lockout(1.2, 1.0, &SEVEN_DAY_PRIORS), 0.0);
+ }
+
+ #[test]
+ fn test_expected_lockout_small_for_marginal_cross() {
+ // At the show boundary (P(over) β‰ˆ 0.5) the projected cross lands near
+ // the reset, so the lockout *fraction* stays modest β€” the metric
+ // tracks confidence rather than screaming, the same on either window.
+ // (Whether that reads as mild then depends on the window via
+ // `lockout_cost`.) A 30%@20% seven-day reading is just over the gate.
+ let l = expected_lockout(0.30, 0.20, &SEVEN_DAY_PRIORS);
+ assert!(
+ l < 0.20,
+ "a marginal cross should give a small lockout fraction: {l}"
+ );
+ }
+
+ #[test]
+ fn test_pace_color_deepens_with_lockout() {
+ // Anchor on the 5-hour window, where `lockout_cost`'s weight is 1, so
+ // cost equals the fraction and the tier cutoffs are 0.10 / 0.30.
+ let dim = colorize_pace("X", 0.05, FIVE_HOUR_SECS);
+ let dim_yellow = colorize_pace("X", 0.20, FIVE_HOUR_SECS);
+ let yellow = colorize_pace("X", 0.50, FIVE_HOUR_SECS);
+ // Three distinct renderings of the same text, deepening with severity.
+ assert_ne!(dim, dim_yellow);
+ assert_ne!(dim_yellow, yellow);
+ for s in [&dim, &dim_yellow, &yellow] {
+ assert_eq!(s.ansi_strip(), "X");
+ }
+ // Yellow fg is SGR 33; the faint attribute is SGR 2. The bottom tier
+ // is faint with no colour; the top tier is yellow; the middle is both.
+ assert!(
+ !dim.contains("33"),
+ "dim tier should carry no colour: {dim:?}"
+ );
+ assert!(
+ yellow.contains("33"),
+ "top tier should be yellow: {yellow:?}"
+ );
+ assert!(
+ dim_yellow.contains("33"),
+ "middle tier should be yellow too: {dim_yellow:?}"
+ );
+ }
+
+ #[test]
+ fn test_pace_cost_weights_longer_window_heavier() {
+ // The same lockout fraction is more severe on the longer window. The
+ // 5h window keeps weight 1; the 7d window's √(7d/5h) β‰ˆ 5.8 weight lifts
+ // a fraction that's merely dim on 5h to full yellow on the week.
+ let frac = 0.06;
+ let five_h = colorize_pace("x", frac, FIVE_HOUR_SECS);
+ let seven_d = colorize_pace("x", frac, SEVEN_DAY_SECS);
+ // 5h: cost = 0.06 < 0.10 β†’ dim (no colour). 7d: cost β‰ˆ 0.35 β†’ yellow.
+ assert!(
+ !five_h.contains("33"),
+ "0.06 on 5h should be dim: {five_h:?}"
+ );
+ assert!(
+ seven_d.contains("33"),
+ "0.06 on 7d should be coloured: {seven_d:?}"
+ );
+ // Cost is monotonic in window length, and the 5h anchor is unweighted.
+ assert!(lockout_cost(frac, SEVEN_DAY_SECS) > lockout_cost(frac, FIVE_HOUR_SECS));
+ assert_eq!(lockout_cost(0.3, FIVE_HOUR_SECS), 0.3);
+ }
+
#[test]
fn test_parse_rate_limits_both_windows() {
let v: serde_json::Value = serde_json::from_str(
diff --git a/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_24h_locale.snap b/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_24h_locale.snap
index 5fff0b5ab..485e3cc9d 100644
--- a/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_24h_locale.snap
+++ b/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_24h_locale.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/statusline.rs
expression: out
---
- [PATH] main ^| Opus πŸŒ• 42% 1.3Γ—(10:00–15:00)
+ [PATH] main ^| Opus πŸŒ• 42% 1.3Γ—(10:00–15:00)
diff --git a/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_clock_time.snap b/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_clock_time.snap
index ebcdf2556..efd899924 100644
--- a/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_clock_time.snap
+++ b/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_clock_time.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/statusline.rs
expression: out
---
- [PATH] main ^| Opus πŸŒ• 42% 1.3Γ—(10am–3pm)
+ [PATH] main ^| Opus πŸŒ• 42% 1.3Γ—(10am–3pm)
diff --git a/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_with_minutes.snap b/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_with_minutes.snap
index 368de82b4..fd6d67d08 100644
--- a/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_with_minutes.snap
+++ b/tests/snapshots/integration__integration_tests__statusline__rate_limit_5h_with_minutes.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/statusline.rs
expression: out
---
- [PATH] main ^| Opus πŸŒ• 42% 95%(8:30am–1:30pm)
+ [PATH] main ^| Opus πŸŒ• 42% 95%(8:30am–1:30pm)
diff --git a/tests/snapshots/integration__integration_tests__statusline__rate_limit_with_dirty_worktree_and_context.snap b/tests/snapshots/integration__integration_tests__statusline__rate_limit_with_dirty_worktree_and_context.snap
index 778718038..9192198d4 100644
--- a/tests/snapshots/integration__integration_tests__statusline__rate_limit_with_dirty_worktree_and_context.snap
+++ b/tests/snapshots/integration__integration_tests__statusline__rate_limit_with_dirty_worktree_and_context.snap
@@ -2,4 +2,4 @@
source: tests/integration_tests/statusline.rs
expression: out
---
- [PATH] main ?^| @+1 Opus πŸŒ’ 95% 1.3Γ—(10am–3pm)
+ [PATH] main ?^| @+1 Opus πŸŒ’ 95% 1.3Γ—(10am–3pm)