fix: forecast windows that are ahead early in their window (D7)
agent-review agent review: pass

The reach date, the dotted forecast and the popup warning showed only
for Claude. Codex had reset its week ten hours before and stood at
39 %, ahead by 33 points, but every forecast shared a gate that
opened only after 10 % of the window. Nothing in the forecast paths
was provider-specific; Codex was just the window early in its week.

The gate now also opens as soon as the window is ahead, with the
configured threshold, so it never disagrees with the chip. Average,
recent and popup forecasts all use it. Until forecasts start, the
tile and the window chart say when they will.

Refs #5
This commit is contained in:
Florian Schmidt
2026-10-15 18:58:06 +02:00
parent 5b42cb8c98
commit 33458a40ed
11 changed files with 180 additions and 21 deletions
+7 -3
View File
@@ -5,7 +5,7 @@ using FinalToken.Core;
namespace FinalToken.App;
public sealed class BurnUpChart(LimitChart chart) : Control
public sealed class BurnUpChart(LimitChart chart) : Decorator
{
private Rect plot;
private double? crosshair;
@@ -13,6 +13,10 @@ public sealed class BurnUpChart(LimitChart chart) : Control
protected override void OnInitialized()
{
base.OnInitialized(); Height = 240; ToolTip.SetShowDelay(this, 0);
if (chart.Window is { } snapshot && Display.ForecastWaiting(snapshot, chart.Now) is { } waiting)
Child = new TextBlock { Text = waiting, FontSize = 12, Foreground = Ui.Colour("Muted", Ui.Dark(this)),
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Top, Margin = new Thickness(42, 40, 16, 0) };
PointerMoved += (_, e) =>
{
if (chart.Analysis is not { } analysis || !plot.Contains(e.GetPosition(this))) return;
@@ -27,7 +31,7 @@ public sealed class BurnUpChart(LimitChart chart) : Control
{
if (current.ReachedOrigin == UseOrigin.Estimated)
{ used = 100; source = "Limit reached (estimated)"; }
else if (chart.Window is { } window && LimitAnalysis.AverageUseAtReset(window.Window, chart.Now) is { } forecast)
else if (chart.Window is { } window && LimitAnalysis.AverageUseAtReset(window.Window, chart.Now, window.Pace) is { } forecast)
{
used = window.Window.UsedPercent + (forecast - window.Window.UsedPercent) * (time - chart.Now).TotalSeconds / (current.Reset - chart.Now).TotalSeconds;
source = "Average forecast";
@@ -68,7 +72,7 @@ public sealed class BurnUpChart(LimitChart chart) : Control
if (data.Previous is { } previous)
using (context.PushOpacity(.2)) DrawSeries(previous, true);
DrawSeries(instance, false);
if (instance.ReachedLimit is null && LimitAnalysis.AverageUseAtReset(snapshot.Window, chart.Now) is { } average && instance.Reset > chart.Now)
if (instance.ReachedLimit is null && LimitAnalysis.AverageUseAtReset(snapshot.Window, chart.Now, snapshot.Pace) is { } average && instance.Reset > chart.Now)
context.DrawLine(new Pen(colour, 2, new DashStyle([1, 3], 0)), new(X(chart.Now), Y(snapshot.Window.UsedPercent)), new(plot.Right, Y(average)));
var nowX = X(chart.Now);
if (nowX >= plot.Left && nowX <= plot.Right) context.DrawLine(new Pen(muted, 1, new DashStyle([3, 3], 0)), new(nowX, plot.Top), new(nowX, plot.Bottom));