feat: add FinalToken v1 for Claude and Codex usage (#2)

FinalToken v1: a NativeAOT tray app for Windows 11 and CachyOS that tracks
Claude Code and Codex usage and limits through their CLIs only, with no
provider sign-in and no tokens (R1-R7, D1-D11).

- Core: incremental collectors for Claude transcripts and Codex
  rollouts, limit probes through `claude -p /usage` and
  `codex app-server`, a journaled history store, the refresh engine,
  pace and popup decisions, and the snapshot.json contract.
- App (Avalonia): stats panel with limit bars, pace, projections, token
  totals, charts, limit history and breakdowns; tray, settings,
  non-activating pace popups, single-instance activation, start with
  the OS, and the Off/Ask/Automatic Stream Deck plugin install.
- Stream Deck plugin (SDK v2, NativeAOT) for Elgato and OpenDeck.
- finaltoken-cli, tools/publish.py, the documentation check and the
  agent review workflow.

Closes #1
This commit was merged in pull request #2.
This commit is contained in:
2026-10-14 22:11:19 +02:00
parent 6d67f157a5
commit f8afd11679
106 changed files with 6583 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Threading;
using Avalonia.Styling;
using Avalonia.VisualTree;
using FinalToken.Core;
namespace FinalToken.App;
public sealed class PopupWindow : Window
{
public PopupWindow(string title, string message, Action open, string? installLabel = null, Action? install = null, Action? dismiss = null, IBrush? accent = null)
{
Width = 380; Height = install is null ? 145 : 180;
RequestedThemeVariant = ThemeVariant.Dark;
WindowDecorations = WindowDecorations.None; CanResize = false; Topmost = true; ShowInTaskbar = false; ShowActivated = false;
var body = Ui.Stack(Ui.Text(title, 19), Ui.Text(message));
if (install is not null)
{
var actions = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 12 };
actions.Children.Add(Ui.Button(installLabel ?? "Install", () => { install(); Close(); }));
actions.Children.Add(Ui.Button("Not now", () => { dismiss?.Invoke(); Close(); }));
body.Children.Add(actions);
}
var card = Ui.Card(body); card.Background = Brush.Parse("#202C40");
body.Resources["TextControlForeground"] = Brushes.WhiteSmoke;
foreach (var text in body.Children.OfType<TextBlock>()) text.Foreground = Brushes.WhiteSmoke;
((TextBlock)body.Children[0]).Foreground = accent ?? Brushes.WhiteSmoke;
Content = card;
PointerPressed += (_, e) =>
{
var source = e.Source as Control;
if (source is not Button && source?.FindAncestorOfType<Button>() is null)
{ open(); Close(); e.Handled = true; }
};
}
public static PopupWindow Pace(PopupEvent alert, Action open) => new($"{alert.Provider} · {Display.State(alert.State)}",
$"{alert.Label}: {alert.Delta:+0.0;-0.0;0} points from pace." +
(alert.Projection is { } projection ? $" At this rate: 100% at {Display.Projection(projection)}." : ""), open, accent: PaceBar.Colour(alert.State));
}
public sealed class PopupStack(Action open, TimeProvider? clock = null) : IDisposable
{
private readonly List<PopupWindow> windows = [];
public void Pace(PopupEvent alert) => Show(PopupWindow.Pace(alert, open));
public void Show(PopupWindow window)
{
windows.Add(window);
window.Closed += (_, _) => { windows.Remove(window); Position(); };
window.Show(); Position();
// D8: timer callbacks are off the UI thread; closing always marshals back.
var timer = (clock ?? TimeProvider.System).CreateTimer(_ => Dispatcher.UIThread.Post(window.Close),
null, TimeSpan.FromSeconds(8), Timeout.InfiniteTimeSpan);
window.Closed += (_, _) => timer.Dispose();
}
private void Position()
{
var bottom = 0;
foreach (var window in windows)
{
var screen = window.Screens.Primary;
if (screen is null) continue;
var area = screen.WorkingArea; var scale = screen.Scaling;
bottom += (int)(window.Height * scale) + 12;
window.Position = new PixelPoint(area.Right - (int)(window.Width * scale) - 16, area.Bottom - bottom - 4);
}
}
public void Dispose() { foreach (var window in windows.ToArray()) window.Close(); }
}