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
+6
View File
@@ -0,0 +1,6 @@
# CLI
NativeAOT console host for D1, D5, D6 and D9. Exit codes: success 0, failure 1, usage 2.
Assembly/executable name is `finaltoken-cli` on every platform, beside the `FinalToken` app.
A busy store is read-only. Keep argument parsing in CliApplication for tests.
Pass no app path to RefreshEngine; preserve the desktop path from an existing snapshot.
Run `dotnet test --project tests/FinalToken.Cli.Tests -c Release` from the root.
+1
View File
@@ -0,0 +1 @@
@AGENTS.md
+52
View File
@@ -0,0 +1,52 @@
using System.Globalization;
using System.Text.Json;
using FinalToken.Core;
namespace FinalToken.Cli;
public static class CliApplication
{
public static async Task<int> RunAsync(string[] args, TextWriter output, TextWriter error,
string? dataDirectory = null, Func<string, RefreshEngine>? engineFactory = null, CancellationToken cancellationToken = default)
{
if (args.Length == 0 || args[0] != "status" || args.Skip(1).Any(a => a is not ("--json" or "--no-probe")) ||
args.Skip(1).Distinct().Count() != args.Length - 1)
{ await error.WriteLineAsync("Usage: finaltoken-cli status [--json] [--no-probe]"); return 2; }
try
{
var directory = dataDirectory ?? DataPaths.DataDirectory;
using var storeLock = StoreLock.TryAcquire(directory);
Snapshot snapshot;
if (storeLock is null)
{
await error.WriteLineAsync("Store is in use; reading the existing snapshot without refreshing.");
var result = SnapshotFile.Read(directory);
if (result.Snapshot is not { } existing) { await error.WriteLineAsync(result.Error); return 1; }
if (result.IsStale) await error.WriteLineAsync("Snapshot is stale.");
snapshot = existing;
}
else
{
await using var engine = engineFactory?.Invoke(directory) ?? new RefreshEngine(directory);
snapshot = await engine.RefreshNowAsync(args.Contains("--no-probe"), cancellationToken);
foreach (var diagnostic in engine.RecentDiagnostics)
await error.WriteLineAsync($"{diagnostic.Code} (x{diagnostic.Count}, last {diagnostic.Time:O}): {diagnostic.Summary}");
}
if (args.Contains("--json")) await output.WriteLineAsync(JsonSerializer.Serialize(snapshot, CoreJsonContext.Default.Snapshot));
else
{
await output.WriteLineAsync($"FinalToken {snapshot.MadeAt:O}");
foreach (var provider in snapshot.Providers)
{
await output.WriteLineAsync($"{provider.Provider}: {provider.Status} {provider.Reason}");
await output.WriteLineAsync($" Tokens today: {provider.Today.Total}; session: {provider.Session?.Total.ToString(CultureInfo.InvariantCulture) ?? "unknown"}; week: {provider.Week.Total}");
foreach (var window in provider.Windows)
await output.WriteLineAsync(FormattableString.Invariant($" {window.Window.Label}: {window.Window.UsedPercent:0.##}% used; resets {window.Window.ResetsAt:O}; {window.Pace.State}; delta {window.Pace.Delta:0.##}; sampled {window.Window.SampleTime:O}"));
}
}
return 0;
}
catch (Exception)
{ await error.WriteLineAsync("FinalToken could not complete the refresh or read the snapshot."); return 1; }
}
}
+8
View File
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<AssemblyName>finaltoken-cli</AssemblyName>
<PublishAot>true</PublishAot>
</PropertyGroup>
<ItemGroup><ProjectReference Include="../FinalToken.Core/FinalToken.Core.csproj" /></ItemGroup>
</Project>
+3
View File
@@ -0,0 +1,3 @@
using FinalToken.Cli;
return await CliApplication.RunAsync(args, Console.Out, Console.Error);