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

Merged
schmidt.florian merged 16 commits from 1-finaltoken-v1 into master 2026-10-14 22:11:22 +02:00
Owner

Closes #1

What and why

FinalToken v1: a NativeAOT tray app for Windows 11 and CachyOS that tracks Claude Code and Codex usage and limits. It never signs in to a provider and never handles a token: it reads the files the CLIs write and runs claude -p /usage and codex app-server (R1–R7).

  • Core (src/FinalToken.Core):
    • Incremental collectors for Claude transcripts and Codex rollouts.
    • Limit probes through the CLIs.
    • A journaled history store: an idle refresh writes only snapshot.json.
    • The refresh engine, pace math and popup decisions.
    • The snapshot.json contract, settings, and the Stream Deck installer.
  • App (src/FinalToken.App, Avalonia 12.1.4): stats panel with limit bars, pace markers, projections, token totals, hourly and daily charts, limit history, model and project tables and diagnostics. Also tray, settings, stacked non-activating pace popups, single-instance activation, start with the OS, and the Off/Ask/Automatic plugin install.
  • Stream Deck (src/FinalToken.StreamDeck): an SDK v2 NativeAOT plugin (Elgato on Windows, OpenDeck on Linux) with one "Stat" action and six metrics drawn as SVG.
  • CLI finaltoken-cli status [--json] [--no-probe].
  • Tools:
    • tools/publish.py packages all three executables and stamps the plugin version from Directory.Build.props.
    • tools/docs/check_docs.py checks the docs.
    • tools/gitea.sh and tools/agent-review.sh support the review workflow.

The docs (AGENTS.md, docs/requirements.md, docs/decisions.md, docs/agents/review.md, README.md) are new in this PR. One package dependency is new: Avalonia (with CommunityToolkit.Mvvm). It is the NativeAOT-capable cross-platform UI that D8 names. The xUnit v3 AOT package is test-only.

Decisions

Implements D1–D11, all recorded in this PR. Amended during the work, still inside this PR:

  • D5: journaled store, Windows file sharing, 60-day Claude dedupe, local calendar days.
  • D3: which /usage lines are limit lines.
  • D6: probes get UTF-8 pipes, because a GUI host has no console code page.
  • D9: who supplies appPath.

How it was tested

On 9f33dd8 (Windows 11, SDK 10.0.402) unless noted.

Build and checks

  • dotnet build FinalToken.slnx -c Release: 0 warnings, 0 errors.
  • dotnet test --solution FinalToken.slnx -c Release: 198 passed, 0 failed, 0 skipped (Core 141, CLI 9, App 26, StreamDeck 22), twice. The worker ran it 5×, and 20× on the previous head.
  • python -B tools/docs/check_docs.py: 0 errors. python -B tools/docs/test_check_docs.py: 15 passed. python -B tools/test_publish.py: passed.
  • python -B tools/publish.py win-x64: 0 warnings; app 20.5 MB, CLI 4.8 MB, plugin 6.9 MB; manifest 1.0.1.0.

Published app on real data

  • Both providers show their limit windows. Claude was unavailable in the GUI app until 50ac2aa; the cause was the console code page.
  • appPath points at the app. A second start activates the first instance and exits in 1.0 s.
  • Real pace popups stack at the bottom right ("Claude · Ahead … 100% at 16.10.2026 09:17").
  • Native window captures of the panel were checked.

Store

  • First import of this machine's history: 26 s.
  • An idle refresh on frozen sources changes only snapshot.json (about 1 KB); before c2f97e9 it rewrote 19 MB every 60 s.
  • Today's and the week's totals match the first store exactly.

R7 on the local Stream Deck 7.0.3

  • In Automatic mode the app replaced a stale 1.0.0.1 plugin with 1.0.1.0 and restarted Stream Deck.
  • Stream Deck logs Plugin 'de.finalfactory.finaltoken' connected, and the plugin logs registered.
  • The app showed "Plugin installed successfully". Ask mode showed "Version 1.0.1.0 is ready — Update / Not now".

Linux: Arch container (CachyOS base), distro SDK 10.0.112, clang 23

  • Build 0 warnings and all tests on 4f4ed5f (161/161).
  • publish.py linux-x64: NativeAOT app, CLI and plugin.
  • The CLI and the app parse a frozen copy of real Claude and Codex data.
  • The app renders the panel on X11 (Xvfb).

Not verified

  • A real CachyOS KDE Plasma/XWayland session: tray, popup placement, autostart.
  • OpenDeck on Linux.
  • Pressing a physical Stream Deck key, and how the rendered key looks on hardware.
  • Windows autostart through the registry.

One test failed once in 1 of 173 tests on 5c5973a and did not reproduce in 25+ later runs. The tests that use real time were hardened in 15c7e68.

Closes #1 ## What and why FinalToken v1: a NativeAOT tray app for Windows 11 and CachyOS that tracks Claude Code and Codex usage and limits. It never signs in to a provider and never handles a token: it reads the files the CLIs write and runs `claude -p /usage` and `codex app-server` (R1–R7). - **Core** (`src/FinalToken.Core`): - Incremental collectors for Claude transcripts and Codex rollouts. - Limit probes through the CLIs. - A journaled history store: an idle refresh writes only `snapshot.json`. - The refresh engine, pace math and popup decisions. - The `snapshot.json` contract, settings, and the Stream Deck installer. - **App** (`src/FinalToken.App`, Avalonia 12.1.4): stats panel with limit bars, pace markers, projections, token totals, hourly and daily charts, limit history, model and project tables and diagnostics. Also tray, settings, stacked non-activating pace popups, single-instance activation, start with the OS, and the Off/Ask/Automatic plugin install. - **Stream Deck** (`src/FinalToken.StreamDeck`): an SDK v2 NativeAOT plugin (Elgato on Windows, OpenDeck on Linux) with one "Stat" action and six metrics drawn as SVG. - **CLI** `finaltoken-cli status [--json] [--no-probe]`. - **Tools:** - `tools/publish.py` packages all three executables and stamps the plugin version from `Directory.Build.props`. - `tools/docs/check_docs.py` checks the docs. - `tools/gitea.sh` and `tools/agent-review.sh` support the review workflow. The docs (`AGENTS.md`, `docs/requirements.md`, `docs/decisions.md`, `docs/agents/review.md`, `README.md`) are new in this PR. One package dependency is new: Avalonia (with CommunityToolkit.Mvvm). It is the NativeAOT-capable cross-platform UI that D8 names. The xUnit v3 AOT package is test-only. ## Decisions Implements D1–D11, all recorded in this PR. Amended during the work, still inside this PR: - **D5:** journaled store, Windows file sharing, 60-day Claude dedupe, local calendar days. - **D3:** which `/usage` lines are limit lines. - **D6:** probes get UTF-8 pipes, because a GUI host has no console code page. - **D9:** who supplies `appPath`. ## How it was tested On `9f33dd8` (Windows 11, SDK 10.0.402) unless noted. **Build and checks** - `dotnet build FinalToken.slnx -c Release`: 0 warnings, 0 errors. - `dotnet test --solution FinalToken.slnx -c Release`: 198 passed, 0 failed, 0 skipped (Core 141, CLI 9, App 26, StreamDeck 22), twice. The worker ran it 5×, and 20× on the previous head. - `python -B tools/docs/check_docs.py`: 0 errors. `python -B tools/docs/test_check_docs.py`: 15 passed. `python -B tools/test_publish.py`: passed. - `python -B tools/publish.py win-x64`: 0 warnings; app 20.5 MB, CLI 4.8 MB, plugin 6.9 MB; manifest `1.0.1.0`. **Published app on real data** - Both providers show their limit windows. Claude was unavailable in the GUI app until `50ac2aa`; the cause was the console code page. - `appPath` points at the app. A second start activates the first instance and exits in 1.0 s. - Real pace popups stack at the bottom right ("Claude · Ahead … 100% at 16.10.2026 09:17"). - Native window captures of the panel were checked. **Store** - First import of this machine's history: 26 s. - An idle refresh on frozen sources changes only `snapshot.json` (about 1 KB); before `c2f97e9` it rewrote 19 MB every 60 s. - Today's and the week's totals match the first store exactly. **R7 on the local Stream Deck 7.0.3** - In Automatic mode the app replaced a stale `1.0.0.1` plugin with `1.0.1.0` and restarted Stream Deck. - Stream Deck logs `Plugin 'de.finalfactory.finaltoken' connected`, and the plugin logs `registered`. - The app showed "Plugin installed successfully". Ask mode showed "Version 1.0.1.0 is ready — Update / Not now". **Linux: Arch container (CachyOS base), distro SDK 10.0.112, clang 23** - Build 0 warnings and all tests on `4f4ed5f` (161/161). - `publish.py linux-x64`: NativeAOT app, CLI and plugin. - The CLI and the app parse a frozen copy of real Claude and Codex data. - The app renders the panel on X11 (Xvfb). **Not verified** - A real CachyOS KDE Plasma/XWayland session: tray, popup placement, autostart. - OpenDeck on Linux. - Pressing a physical Stream Deck key, and how the rendered key looks on hardware. - Windows autostart through the registry. One test failed once in 1 of 173 tests on `5c5973a` and did not reproduce in 25+ later runs. The tests that use real time were hardened in `15c7e68`.
schmidt.florian added the type/feature label 2026-10-14 21:24:12 +02:00
schmidt.florian added 15 commits 2026-10-14 21:24:13 +02:00
Records R1 to R7 from the developer and the decisions D1 to D11 that the
v1 work builds on, plus the issue, branch and review workflow the agents
follow.

Refs #1
Both the app and the CLI can refresh, so D5 now names one writer at a
time behind a lock file and gives the data directory an override for
tests. D8 says how a second start reaches the running instance without
a socket, which D9 rules out.

Refs #1
check_docs.py verifies local links, anchors and the R and D IDs that
the decisions are cited by. gitea.sh calls the API with GITEA_TOKEN or
the stored git credential, handed to curl on stdin so it never shows in
a process list. agent-review.sh posts a review and sets the
agent-review status, refusing when the PR head moved.

Refs #1
Refs #1
Core implements the CLI-only collectors for Claude and Codex (D2 to D4),
the history store (D5), the refresh engine (D6), pace and popup
decisions (D7, D8), the snapshot contract (D9) and the Stream Deck
installer contract (D11). finaltoken status runs one refresh and prints
the snapshot. The app and plugin projects are placeholders so the
solution file is complete before they are built in parallel.

Refs #1
The store rewrote all of history.json, 19 MB here, on every 60 s
refresh. It now appends each refresh's changes to a journal and compacts
into monthly files and a state checkpoint at 8 MiB, so an idle refresh
writes only snapshot.json. Bucket updates are keyed, unchanged limit
samples are kept at most hourly, Codex replays are bounded by session
totals, and Claude dedupe keys expire after 60 days.

Readers of atomically replaced files allow delete sharing, and the
replace retries briefly, so the Stream Deck plugin reading snapshot.json
cannot make a refresh fail. Claude's <synthetic> entries are skipped,
and repeated diagnostics fold into one entry with a count.

Refs #1
The store now appends changes to a journal and compacts into monthly
files, shares files for readers on Windows, skips unchanged sources and
bounds Claude dedupe to 60 days. D5 says so, and what it gives up.

Refs #1
The plugin is a NativeAOT executable that speaks the Stream Deck SDK v2
WebSocket protocol itself, reads snapshot.json and draws each key as
SVG (D10). The installer finds Elgato Stream Deck or OpenDeck, stages
the shipped plugin beside the installed one, stops a running host,
swaps and rolls back on failure (D11). tools/publish.py publishes the
app, CLI and plugin for win-x64 or linux-x64 into one folder.

Refs #1
Refs #1
Opening the app shows the stats panel: per-provider limit bars with the
pace marker, delta, reset and projection, token totals, hourly and daily
charts, limit history with its pace line, model and project tables and
recent diagnostics (R4, D8). Pace popups stack at the bottom right
without taking focus (R5). The tray, settings, single-instance
activation, start with the OS and the Stream Deck install policy (D11)
are wired to the Core engine. Avalonia 12.1.4 and
CommunityToolkit.Mvvm 8.4.2 are the new packages D8 calls for.

Refs #1
- A GUI-subsystem host has no console code page, so .NET decoded the
  probes' UTF-8 output with code page 0 and Claude's /usage separators
  never matched: Claude showed as unavailable in the app but not in the
  CLI. Probe output is now decoded as UTF-8 and every probe gets valid
  standard handles, with stdin closed unless it is the Codex RPC. A
  GUI-subsystem test host reproduces it.
- The /usage parser stops at the contributing section and only reports
  lines that start like a limit line.
- snapshot.json no longer defaults appPath to the reader's own path. The
  app passes its path to the engine and a CLI refresh keeps it, so a
  Stream Deck key always starts the app (D9, D10).
- The CLI is finaltoken-cli on every platform: FinalToken.exe and
  finaltoken.exe cannot share a folder on Windows.
- Day series follow the local calendar day, as Today does.
- The dev-only migration from the first store format is gone.
- README.md is a short user guide.

Refs #1
D3 says which /usage lines are limit lines, D5 that days follow the
local calendar, D6 that probes get their own UTF-8 pipes because a GUI
host has no console, and D9 who supplies the app path in the snapshot.

Refs #1
The popup showed only the time of a projection two days away, which
read as today; the popup and the panel now share one formatter that adds
the date unless the projection is today. Chart axes used max/4 steps,
which repeated labels for small or empty ranges; they now use whole 1,
2 or 5 steps and an empty chart shows only 0.

Refs #1
D11 replaces an installed plugin only when the shipped manifest is
newer, but the manifest version was kept by hand and still said
1.0.0.1, the version of a test build installed before the snapshot
sharing and appPath fixes, so that stale plugin was never replaced.
Directory.Build.props now holds the only version, 1.0.1; publish.py
stamps it into the shipped manifest and the app shows it in its title.

Tests that waited on real time (file retry, popup expiry) use
controlled timers, and real process waits have wider margins.

Refs #1
With init-only properties, the source-generated reader set a property
missing from settings.json to its default value, not its initializer,
so the file failed validation and every setting fell back to defaults.
Any release that adds a setting would have reset all user settings.
Settings use settable properties now, and the snapshot's version field
too; the other persisted types were checked and keep their defaults.

Refs #1
Author
Owner

Linux check on the PR head 9f33dd8 (Arch container, distro SDK 10.0.112, clang 23):

  • dotnet build: 0 warnings, 0 errors.
  • dotnet test: 198/198.
  • tools/test_publish.py: OK.
  • check_docs: 0 errors.
  • publish.py linux-x64: 0 warnings; plugin version 1.0.1.0; outputs FinalToken, finaltoken-cli and streamdeck/.
Linux check on the PR head `9f33dd8` (Arch container, distro SDK 10.0.112, clang 23): - `dotnet build`: 0 warnings, 0 errors. - `dotnet test`: 198/198. - `tools/test_publish.py`: OK. - `check_docs`: 0 errors. - `publish.py linux-x64`: 0 warnings; plugin version `1.0.1.0`; outputs `FinalToken`, `finaltoken-cli` and `streamdeck/`.
Author
Owner

Agent review: fail on 9f33dd8896

Blocking

  1. src/FinalToken.Core/Processes/ProcessRunner.cs:99-113, src/FinalToken.Core/Collectors/LimitProbe.cs:27, src/FinalToken.Core/RefreshEngine.cs:147-149: a Codex app-server that answers account/rateLimits/read with an RPC error (logged out, API-key login) or exits without answering makes ReadResponseAsync throw InvalidDataException. That type is not an IOException, so LimitProbe does not catch it, and neither does the refresh loop. Reproduced on 9f33dd8 with a fake app-server that returns an error for id 2. The probe throws, the engine loop dies on its first tick (0 snapshots in 5 s, Claude included), and StopAsync rethrows at shutdown. The same exception escapes DesktopApp.Run (async void, so "Refresh now" can crash the app) and CliApplication (unhandled crash instead of exit 1). This breaks D2: a logged-out CLI makes its provider "unavailable" and the other provider keeps working. It also breaks the AGENTS.md rule that no exception stops a refresh. Fix: turn RPC errors, early EOF and the output bound into a failed ProbeResult with a reason. Make RunLoopAsync record a diagnostic and keep ticking on any non-cancellation exception, because a corrupt month file (JsonException from GetPartition) and finding 2 kill it the same way. The RPC exchange in ProcessRunner (initialize, initialized, rateLimits/read, error, EOF) has no test. Add tests with a fake app-server child (for example a mode in tests/FinalToken.ProcessHost) for success, an error response and early exit.
  2. src/FinalToken.Core/HistoryStore.cs:241-246: Totals builds local midnight with TimeZoneInfo.ConvertTimeToUtc, which throws ArgumentException when local midnight does not exist. Reproduced on 9f33dd8: Totals throws for Africa/Cairo on 2026-04-24, America/Santiago on 2026-09-06 and Asia/Beirut on 2026-03-29. Totals runs in every refresh, so in those zones that day's refreshes fail and, with finding 1, the loop stops. D5 requires today and the week to follow the local calendar day across DST, and src/FinalToken.Core/AGENTS.md says to use CalendarDays. Fix: derive today's and the week's start through CalendarDays, for example a CalendarDays.Start(DateTime date, zone) overload for the Monday. Add a test in one of those zones; today Totals is only tested with UTC.
  3. src/FinalToken.App/Charts.cs:93: the daily chart labels its axis with time.UtcDateTime, but day keys are local midnights from CalendarDays.Start. East of UTC every label shows the previous day: in Europe/Berlin the 2026-10-14 bucket is labelled 10-13. The tooltip at line 88 uses local time and shows 10-14, so the panel contradicts itself (R4). Fix: format the local date (time.DateTime for the day key). Move the label into Display and cover it with a test that uses a +02:00 zone.

Notes

  • src/FinalToken.StreamDeck/Program.cs:57: PluginSocket.ReceiveAsync throws InvalidDataException for a non-text or oversized frame (Protocol.cs:52), which the outer catch does not handle. The plugin then exits with an unhandled exception instead of logging connection-ended.
  • src/FinalToken.Core/StreamDeck/Installer.cs:10-17: StubPluginInstaller is no longer used, and its comment and src/FinalToken.Core/AGENTS.md:25 ("W3 owns StreamDeck/") describe this PR's worker split rather than the code. Remove the stub and the worker reference.
  • src/FinalToken.App/OsStartup.cs:14: the Linux autostart path ignores XDG_CONFIG_HOME, unlike HostDiscovery (PluginInstaller.cs:171).
  • src/FinalToken.Core/HistoryPersistence.cs:25: scan cursors are never removed. Claude deletes transcripts after 30 days and Codex moves rollouts to archived_sessions, so history.state.json grows with every source file ever seen. Consider pruning cursors whose file is gone.
  • src/FinalToken.App/PanelViewModel.cs:46-55: with a provider filter, every hourly point runs a separate ByModel query that scans whole months. "All history" at hourly resolution may be slow on a long history; worth measuring.
  • src/FinalToken.Core/Processes/CliDiscovery.cs:24: Claude Code installed through npm on Windows (claude.cmd) shows as unavailable. The README could say that the native claude.exe is needed, or name the CLI path setting.

Checked

Commit 9f33dd88962c1f69730b25cb12b2158c8316b3ce (PR head), first review, full pass. Read the PR body, issue #1 and its comments, the root AGENTS.md, every project AGENTS.md, docs/requirements.md, docs/decisions.md (D1–D11), docs/agents/review.md, .agents/mind/, and the whole diff against origin/master (105 files, +6319). There were no earlier agent reviews.

Ran in a separate worktree on Windows 11:

  • dotnet build FinalToken.slnx -c Release: 0 warnings, 0 errors.
  • dotnet test --solution FinalToken.slnx -c Release: 198 passed, 0 failed, 0 skipped.
  • python -B tools/docs/check_docs.py: 0 errors. python -B tools/docs/test_check_docs.py: 15 passed. python -B tools/test_publish.py: passed.
  • Reproduced findings 1–3 with a throwaway program outside the repo that references FinalToken.Core: a fake Codex app-server returning an RPC error, HistoryStore.Totals in the three zones, and CalendarDays.Start for Europe/Berlin.

Not run: tools/publish.py, Linux, the GUI app, or a real Stream Deck.

**Agent review: fail** on 9f33dd88962c1f69730b25cb12b2158c8316b3ce ## Blocking 1. `src/FinalToken.Core/Processes/ProcessRunner.cs:99-113`, `src/FinalToken.Core/Collectors/LimitProbe.cs:27`, `src/FinalToken.Core/RefreshEngine.cs:147-149`: a Codex app-server that answers `account/rateLimits/read` with an RPC `error` (logged out, API-key login) or exits without answering makes `ReadResponseAsync` throw `InvalidDataException`. That type is not an `IOException`, so `LimitProbe` does not catch it, and neither does the refresh loop. Reproduced on `9f33dd8` with a fake app-server that returns an error for id 2. The probe throws, the engine loop dies on its first tick (0 snapshots in 5 s, Claude included), and `StopAsync` rethrows at shutdown. The same exception escapes `DesktopApp.Run` (async void, so "Refresh now" can crash the app) and `CliApplication` (unhandled crash instead of exit 1). This breaks D2: a logged-out CLI makes its provider "unavailable" and the other provider keeps working. It also breaks the AGENTS.md rule that no exception stops a refresh. Fix: turn RPC errors, early EOF and the output bound into a failed `ProbeResult` with a reason. Make `RunLoopAsync` record a diagnostic and keep ticking on any non-cancellation exception, because a corrupt month file (`JsonException` from `GetPartition`) and finding 2 kill it the same way. The RPC exchange in `ProcessRunner` (initialize, initialized, rateLimits/read, error, EOF) has no test. Add tests with a fake app-server child (for example a mode in `tests/FinalToken.ProcessHost`) for success, an error response and early exit. 2. `src/FinalToken.Core/HistoryStore.cs:241-246`: `Totals` builds local midnight with `TimeZoneInfo.ConvertTimeToUtc`, which throws `ArgumentException` when local midnight does not exist. Reproduced on `9f33dd8`: `Totals` throws for Africa/Cairo on 2026-04-24, America/Santiago on 2026-09-06 and Asia/Beirut on 2026-03-29. `Totals` runs in every refresh, so in those zones that day's refreshes fail and, with finding 1, the loop stops. D5 requires today and the week to follow the local calendar day across DST, and `src/FinalToken.Core/AGENTS.md` says to use `CalendarDays`. Fix: derive today's and the week's start through `CalendarDays`, for example a `CalendarDays.Start(DateTime date, zone)` overload for the Monday. Add a test in one of those zones; today `Totals` is only tested with UTC. 3. `src/FinalToken.App/Charts.cs:93`: the daily chart labels its axis with `time.UtcDateTime`, but day keys are local midnights from `CalendarDays.Start`. East of UTC every label shows the previous day: in Europe/Berlin the 2026-10-14 bucket is labelled `10-13`. The tooltip at line 88 uses local time and shows `10-14`, so the panel contradicts itself (R4). Fix: format the local date (`time.DateTime` for the day key). Move the label into `Display` and cover it with a test that uses a +02:00 zone. ## Notes - `src/FinalToken.StreamDeck/Program.cs:57`: `PluginSocket.ReceiveAsync` throws `InvalidDataException` for a non-text or oversized frame (`Protocol.cs:52`), which the outer catch does not handle. The plugin then exits with an unhandled exception instead of logging `connection-ended`. - `src/FinalToken.Core/StreamDeck/Installer.cs:10-17`: `StubPluginInstaller` is no longer used, and its comment and `src/FinalToken.Core/AGENTS.md:25` ("W3 owns `StreamDeck/`") describe this PR's worker split rather than the code. Remove the stub and the worker reference. - `src/FinalToken.App/OsStartup.cs:14`: the Linux autostart path ignores `XDG_CONFIG_HOME`, unlike `HostDiscovery` (`PluginInstaller.cs:171`). - `src/FinalToken.Core/HistoryPersistence.cs:25`: scan cursors are never removed. Claude deletes transcripts after 30 days and Codex moves rollouts to `archived_sessions`, so `history.state.json` grows with every source file ever seen. Consider pruning cursors whose file is gone. - `src/FinalToken.App/PanelViewModel.cs:46-55`: with a provider filter, every hourly point runs a separate `ByModel` query that scans whole months. "All history" at hourly resolution may be slow on a long history; worth measuring. - `src/FinalToken.Core/Processes/CliDiscovery.cs:24`: Claude Code installed through npm on Windows (`claude.cmd`) shows as unavailable. The README could say that the native `claude.exe` is needed, or name the CLI path setting. ## Checked Commit `9f33dd88962c1f69730b25cb12b2158c8316b3ce` (PR head), first review, full pass. Read the PR body, issue #1 and its comments, the root `AGENTS.md`, every project `AGENTS.md`, `docs/requirements.md`, `docs/decisions.md` (D1–D11), `docs/agents/review.md`, `.agents/mind/`, and the whole diff against `origin/master` (105 files, +6319). There were no earlier agent reviews. Ran in a separate worktree on Windows 11: - `dotnet build FinalToken.slnx -c Release`: 0 warnings, 0 errors. - `dotnet test --solution FinalToken.slnx -c Release`: 198 passed, 0 failed, 0 skipped. - `python -B tools/docs/check_docs.py`: 0 errors. `python -B tools/docs/test_check_docs.py`: 15 passed. `python -B tools/test_publish.py`: passed. - Reproduced findings 1–3 with a throwaway program outside the repo that references `FinalToken.Core`: a fake Codex app-server returning an RPC error, `HistoryStore.Totals` in the three zones, and `CalendarDays.Start` for Europe/Berlin. Not run: `tools/publish.py`, Linux, the GUI app, or a real Stream Deck.
schmidt.florian added 1 commit 2026-10-14 21:50:12 +02:00
Blocking findings:
1. A Codex RPC error or early exit threw past LimitProbe and stopped the
   refresh loop, so Claude stopped updating too (D2). Every probe failure
   is now a failed probe result, the loop records an unexpected tick
   failure and keeps ticking, shutdown cancellation still propagates,
   the app reports failed operations, and the CLI exits 1 instead of
   crashing. Fake app-server modes in the GUI process host test errors,
   EOF and garbage.
2. Totals converted local midnight directly and threw where midnight
   does not exist (Cairo, Santiago, Beirut). Today and the week start
   through CalendarDays now.
3. Daily chart labels used UTC dates for local-day buckets; labels and
   tooltips now share the local date.

Review notes fixed as well: Claude Code installed with npm on Windows is
found through its native binary or cli.js; the plugin ends cleanly on a
bad host frame; Linux autostart honours XDG_CONFIG_HOME; the unused stub
installer and the worker names in docs are gone.

Refs #1
Author
Owner

Author reply to the first agent review. All three blocking findings are fixed in fd30dfc, each with failing regression tests first:

  1. Codex RPC failure: ReviewRegressionTests.RpcChildFailuresBecomeFailedProbes and EngineKeepsUpdatingClaudeWhenCodexFails, with fake app-server modes for error, EOF and garbage; BackgroundLoopRecoversAfterCorruptMonthAndStopsCleanly; CLI exit 1. With the published CLI and a fake codex that answers with an RPC error: exit 0, Claude Available with fresh windows, Codex Unavailable.
  2. Missing local midnight: TotalsSurviveMissingLocalMidnight (Cairo 2026-04-24, Santiago 2026-09-06, Beirut 2026-03-29) and WeekCanStartOnAMondayWithNoMidnight.
  3. Daily chart dates: DailyChartLabelAndTooltipUseTheBucketsLocalDate, plus a headless tooltip check.

Notes fixed in the same commit: Claude npm discovery on Windows, plugin bad-frame handling, XDG_CONFIG_HOME, and removal of the unused stub and worker names. Deferred: scan-cursor pruning and per-hour model queries under a provider filter.

Checked on fd30dfc (Windows): dotnet build 0 warnings; dotnet test 224/224 in three runs; check_docs 0 errors; test_publish.py OK.

**Author reply to the first agent review.** All three blocking findings are fixed in `fd30dfc`, each with failing regression tests first: 1. **Codex RPC failure:** `ReviewRegressionTests.RpcChildFailuresBecomeFailedProbes` and `EngineKeepsUpdatingClaudeWhenCodexFails`, with fake app-server modes for error, EOF and garbage; `BackgroundLoopRecoversAfterCorruptMonthAndStopsCleanly`; CLI exit 1. With the published CLI and a fake `codex` that answers with an RPC error: exit 0, Claude Available with fresh windows, Codex Unavailable. 2. **Missing local midnight:** `TotalsSurviveMissingLocalMidnight` (Cairo 2026-04-24, Santiago 2026-09-06, Beirut 2026-03-29) and `WeekCanStartOnAMondayWithNoMidnight`. 3. **Daily chart dates:** `DailyChartLabelAndTooltipUseTheBucketsLocalDate`, plus a headless tooltip check. Notes fixed in the same commit: Claude npm discovery on Windows, plugin bad-frame handling, `XDG_CONFIG_HOME`, and removal of the unused stub and worker names. Deferred: scan-cursor pruning and per-hour model queries under a provider filter. Checked on `fd30dfc` (Windows): `dotnet build` 0 warnings; `dotnet test` 224/224 in three runs; check_docs 0 errors; `test_publish.py` OK.
Author
Owner

Agent review: pass on fd30dfcea4

Blocking

None.

Notes

  • src/FinalToken.Core/RefreshEngine.cs:135,151,215: a tick that throws never sets lastRefresh, so the 1 s timer retries the whole refresh (scan, totals, save) every second while the failure persists, for example with a corrupt current-month partition. Probes stay limited by lastProbe, and the diagnostic folds, so this costs CPU and disk rather than correctness. The same was true before for IOException. Consider a backoff, for example setting lastRefresh on failure or retrying after RefreshInterval.
  • src/FinalToken.Core/Processes/CliDiscovery.cs:44-47: the npm layout for Claude Code on Windows (node_modules/@anthropic-ai/claude-code/bin/claude.exe, else cli.js with node.exe) is checked only against hand-written fixtures. No npm install of Claude Code exists on the review machine, so it was not checked against a real package. Worth one check on a real npm i -g @anthropic-ai/claude-code install before release.
  • src/FinalToken.App/PanelViewModel.cs:71-74: the daily tooltip uses the g format, so it shows the bucket's start time (14.10.2026 00:00, or 01:00 on a gap day). A date-only format would read better for a day bucket.
  • Deferred from the first review (author's choice, still open): scan-cursor pruning (HistoryPersistence.cs) and the per-point ByModel queries under a provider filter (PanelViewModel.cs:46-55).

Checked

Re-review of commit fd30dfcea4e525bf77f6790ddd05da04c31df8a2 (PR head). The last failed review covered 9f33dd8; the only author commit since then is fd30dfc (git log -p --no-merges ^9f33dd8 ^origin/master fd30dfc).

Read the PR body, issue #1 and its comments, the first agent review and the author's reply, the root AGENTS.md, src/FinalToken.Core/AGENTS.md, the touched test projects' AGENTS.md, docs/agents/review.md, and the whole fd30dfc diff, plus ProcessRunner, RefreshEngine, LimitProbe, CalendarDays, HistoryStore.Totals/TokenSeries, PanelViewModel, Charts, DesktopApp.Run, CliApplication and CliDiscovery in full or around the change.

Blocking findings of the first review:

  1. Codex RPC failure stops the loop: fixed. LimitProbe turns every non-cancellation failure into a failed ProbeResult with fixed metadata. Shutdown cancellation is still rethrown, and a failure that races shutdown is covered. ProcessRunner's finally still kills and reaps the child. RunLoopAsync records refresh-failed and keeps ticking. DesktopApp.Run and CliApplication catch everything without exposing message text. Tests: RpcChildFailuresBecomeFailedProbes runs a real child for success, init error, error, EOF, garbage, wrong shape and output bound. The success case proves the ProcessHost binary is present, so the failure cases are not vacuous. Also EngineKeepsUpdatingClaudeWhenCodexFails, BackgroundLoopRecoversAfterCorruptMonthAndStopsCleanly, the two cancellation tests, and UnexpectedRefreshFailureReturnsOneWithoutExceptionText.
  2. Totals throws on a missing local midnight: fixed. It now uses the new CalendarDays.Start(DateTime, zone), which shares the gap/overlap policy. Every CalendarDays.Start call site was checked: the new overload does not re-bind any existing caller that passed a DateTimeOffset. Tests cover Cairo, Santiago and Beirut, plus a custom zone whose Monday has no midnight.
  3. Daily chart labels in UTC: fixed. Day keys from TokenSeries carry the local offset from CalendarDays.Start, and ChartValue keeps it through QueryHistory. Label and tooltip now share Display.ChartTime. Only the daily chart (PanelWindow.cs:82) uses a one-day interval; hourly and limit charts keep LocalDateTime. Covered by a +02:00 unit test and a headless tooltip check.

The fixed review notes (plugin bad-frame handling, XDG_CONFIG_HOME, stub removal, worker names in docs, npm Claude discovery) were read; no new problems except the npm note above.

Ran in a separate worktree on Windows 11 (SDK from global.json):

  • dotnet build FinalToken.slnx -c Release: 0 warnings, 0 errors.
  • dotnet test --solution FinalToken.slnx -c Release: 224 passed, 0 failed, 0 skipped.
  • python -B tools/docs/check_docs.py: 0 errors. python -B tools/docs/test_check_docs.py: 15 passed. python -B tools/test_publish.py: passed.

Not run: tools/publish.py, Linux, the GUI app by hand, a real npm Claude install, or a real Stream Deck.

**Agent review: pass** on fd30dfcea4e525bf77f6790ddd05da04c31df8a2 ## Blocking None. ## Notes - `src/FinalToken.Core/RefreshEngine.cs:135,151,215`: a tick that throws never sets `lastRefresh`, so the 1 s timer retries the whole refresh (scan, totals, save) every second while the failure persists, for example with a corrupt current-month partition. Probes stay limited by `lastProbe`, and the diagnostic folds, so this costs CPU and disk rather than correctness. The same was true before for `IOException`. Consider a backoff, for example setting `lastRefresh` on failure or retrying after `RefreshInterval`. - `src/FinalToken.Core/Processes/CliDiscovery.cs:44-47`: the npm layout for Claude Code on Windows (`node_modules/@anthropic-ai/claude-code/bin/claude.exe`, else `cli.js` with `node.exe`) is checked only against hand-written fixtures. No npm install of Claude Code exists on the review machine, so it was not checked against a real package. Worth one check on a real `npm i -g @anthropic-ai/claude-code` install before release. - `src/FinalToken.App/PanelViewModel.cs:71-74`: the daily tooltip uses the `g` format, so it shows the bucket's start time (`14.10.2026 00:00`, or `01:00` on a gap day). A date-only format would read better for a day bucket. - Deferred from the first review (author's choice, still open): scan-cursor pruning (`HistoryPersistence.cs`) and the per-point `ByModel` queries under a provider filter (`PanelViewModel.cs:46-55`). ## Checked Re-review of commit `fd30dfcea4e525bf77f6790ddd05da04c31df8a2` (PR head). The last failed review covered `9f33dd8`; the only author commit since then is `fd30dfc` (`git log -p --no-merges ^9f33dd8 ^origin/master fd30dfc`). Read the PR body, issue #1 and its comments, the first agent review and the author's reply, the root `AGENTS.md`, `src/FinalToken.Core/AGENTS.md`, the touched test projects' `AGENTS.md`, `docs/agents/review.md`, and the whole `fd30dfc` diff, plus `ProcessRunner`, `RefreshEngine`, `LimitProbe`, `CalendarDays`, `HistoryStore.Totals`/`TokenSeries`, `PanelViewModel`, `Charts`, `DesktopApp.Run`, `CliApplication` and `CliDiscovery` in full or around the change. Blocking findings of the first review: 1. **Codex RPC failure stops the loop:** fixed. `LimitProbe` turns every non-cancellation failure into a failed `ProbeResult` with fixed metadata. Shutdown cancellation is still rethrown, and a failure that races shutdown is covered. `ProcessRunner`'s `finally` still kills and reaps the child. `RunLoopAsync` records `refresh-failed` and keeps ticking. `DesktopApp.Run` and `CliApplication` catch everything without exposing message text. Tests: `RpcChildFailuresBecomeFailedProbes` runs a real child for success, init error, error, EOF, garbage, wrong shape and output bound. The success case proves the ProcessHost binary is present, so the failure cases are not vacuous. Also `EngineKeepsUpdatingClaudeWhenCodexFails`, `BackgroundLoopRecoversAfterCorruptMonthAndStopsCleanly`, the two cancellation tests, and `UnexpectedRefreshFailureReturnsOneWithoutExceptionText`. 2. **`Totals` throws on a missing local midnight:** fixed. It now uses the new `CalendarDays.Start(DateTime, zone)`, which shares the gap/overlap policy. Every `CalendarDays.Start` call site was checked: the new overload does not re-bind any existing caller that passed a `DateTimeOffset`. Tests cover Cairo, Santiago and Beirut, plus a custom zone whose Monday has no midnight. 3. **Daily chart labels in UTC:** fixed. Day keys from `TokenSeries` carry the local offset from `CalendarDays.Start`, and `ChartValue` keeps it through `QueryHistory`. Label and tooltip now share `Display.ChartTime`. Only the daily chart (`PanelWindow.cs:82`) uses a one-day interval; hourly and limit charts keep `LocalDateTime`. Covered by a +02:00 unit test and a headless tooltip check. The fixed review notes (plugin bad-frame handling, `XDG_CONFIG_HOME`, stub removal, worker names in docs, npm Claude discovery) were read; no new problems except the npm note above. Ran in a separate worktree on Windows 11 (SDK from `global.json`): - `dotnet build FinalToken.slnx -c Release`: 0 warnings, 0 errors. - `dotnet test --solution FinalToken.slnx -c Release`: 224 passed, 0 failed, 0 skipped. - `python -B tools/docs/check_docs.py`: 0 errors. `python -B tools/docs/test_check_docs.py`: 15 passed. `python -B tools/test_publish.py`: passed. Not run: `tools/publish.py`, Linux, the GUI app by hand, a real npm Claude install, or a real Stream Deck.
schmidt.florian merged commit f8afd11679 into master 2026-10-14 22:11:22 +02:00
schmidt.florian deleted branch 1-finaltoken-v1 2026-10-14 22:11:24 +02:00
Sign in to join this conversation.