core: add self-hosted weekly dashboard and machine workers
Reuse the existing weekly pace, reset history and daily budgets across multiple machines without multiplying shared account quota. Coordinate profile-bound official CLI logins through transient authorization responses while keeping provider credentials local to each CLI. Release as version 1.2.0. Refs #19
This commit is contained in:
+54
-4
@@ -7,7 +7,7 @@ the IDs instead of restating the text. The requirements (R1 to R7) are in
|
||||
|
||||
## D1 — .NET 10, C# 14 and NativeAOT for win-x64 and linux-x64
|
||||
|
||||
**Decision.** Every shipped executable (the app, the CLI and the Stream Deck plugin) targets
|
||||
**Decision.** Every shipped executable (the app, the CLI, Stream Deck plugin and optional web/worker hosts) targets
|
||||
`net10.0` with C# 14 and publishes NativeAOT for `win-x64` and `linux-x64`. `global.json` asks
|
||||
for SDK 10.0.100 or newer within 10.0 (`rollForward: latestFeature`), so the SDK from CachyOS's
|
||||
package manager works too. Builds treat warnings as errors and run the trim and AOT analyzers.
|
||||
@@ -20,8 +20,10 @@ serialization, binding or loading, or runtime code generation.
|
||||
|
||||
## D2 — The CLIs are the only interface to a provider
|
||||
|
||||
**Decision.** FinalToken never reads, stores, logs or sends a credential (OAuth token, API key,
|
||||
cookie). It never opens a provider login and never calls a provider's HTTP API itself. It reads
|
||||
**Decision.** FinalToken never reads, stores, logs or sends a provider access/refresh token,
|
||||
API key or cookie. It can invoke an official CLI login and transiently relay the browser's
|
||||
authorization response to that exact pending process ([D14](#d14--self-hosted-dashboard-and-workers)).
|
||||
It never calls a provider's HTTP API itself. It reads
|
||||
the files the CLIs write and runs the installed `claude` and `codex` executables as child
|
||||
processes, which use their own login. It never opens credential files such as
|
||||
`~/.claude/.credentials.json` or `~/.codex/auth.json`, or the OS keychain. Only counts, model
|
||||
@@ -32,6 +34,7 @@ working.
|
||||
**Why.** R2, R3.
|
||||
|
||||
**Gives up.** Whatever the CLIs do not expose, and limit data while a CLI is not installed.
|
||||
Login coordination needs the installed CLI's supported flow; no central credential pool is possible.
|
||||
|
||||
## D3 — Claude data sources
|
||||
|
||||
@@ -299,7 +302,8 @@ week's start and the id of the limit window it follows (`weekStart`, `weekWindow
|
||||
the current instance of the provider's weekly limit: its longest window over a day whose label
|
||||
names no model family. Without one, it is the local calendar week from Monday, and `weekWindow`
|
||||
is absent. The DTOs and their source-generated JSON context live in `FinalToken.Core`, shared by
|
||||
the app, the CLI and the Stream Deck plugin. Nothing listens on a socket or runs an HTTP server. A reader treats a
|
||||
the app, the CLI and the Stream Deck plugin. The optional separate dashboard/worker hosts use
|
||||
[D14](#d14--self-hosted-dashboard-and-workers); the desktop app itself has no server. A reader treats a
|
||||
snapshot older than three refresh intervals as stale. The app gives the engine its own path; a
|
||||
CLI refresh keeps the path already in the snapshot, and a snapshot without one has none, so a
|
||||
reader never mistakes its own path for the app's.
|
||||
@@ -310,6 +314,52 @@ calendar week (developer feedback, 2026-10-18).
|
||||
|
||||
**Gives up.** Updates faster than the reader's poll interval.
|
||||
|
||||
## D14 — Self-hosted dashboard and workers
|
||||
|
||||
**Decision.** Add a separate ASP.NET Core slim/NativeAOT-compatible server and an outbound .NET
|
||||
worker per OS user, following the developer's direction in
|
||||
[#19](https://git.finalfactory.de/FinalFactory/FinalToken/issues/19).
|
||||
|
||||
- Account ids, expected emails and machine/profile bindings are configured by the operator.
|
||||
The server has a dashboard access key and distinct per-machine keys. Browser sessions are
|
||||
HttpOnly, SameSite cookies with CSRF checks; remote access uses HTTPS. A worker cannot select
|
||||
another machine's identity or execute arbitrary remote commands.
|
||||
- The dashboard calls Core's D7, D12 and D13 APIs. No second forecasting implementation is added.
|
||||
Local settings remain local; the newest quota observation's profile supplies the pace threshold,
|
||||
hidden windows and freshness interval. Account timezone controls calendar days. No working-hour
|
||||
forecast is added. Old/expired limits are displayed but have no current forecast.
|
||||
- Quota is the newest observed account/window value, never the sum across machines. Consumption
|
||||
uses Claude response ids and ordered Codex session cumulative counts across machine copies.
|
||||
Conflicting event metadata is excluded with a warning. Raw metadata history and observations
|
||||
survive offline clients and restarts; messages and project paths are not exported.
|
||||
- Old hourly history cannot be deduplicated after aggregation. An optional designated source and
|
||||
fixed UTC-hour cutoff import it once; identified source events own the interval after the cutoff.
|
||||
Historical profile/account attribution is an operator assertion; identity probes cannot prove
|
||||
which account produced older transcripts. Use a separate profile/data directory per account.
|
||||
- A login is bound to browser session, machine, OS user, config profile, worker boot and a
|
||||
15-minute maximum attempt deadline. That deadline is not a provider credential expiry.
|
||||
Claude uses `auth login --claudeai` and manual code relay through stdin; Codex uses
|
||||
`login --device-auth`. The CLI exchanges and stores its own credentials. A status probe verifies
|
||||
the resulting email. Unknown identity or account mismatch cannot be reported as success.
|
||||
Responses, URLs and device codes live only in pending-session memory and are not logged.
|
||||
- Cancellation, timeout, worker restart and concurrent attempts have explicit outcomes.
|
||||
No remote localhost callback forwarding or private provider endpoint is implemented.
|
||||
CLI output/flow changes fail visibly and may require terminal login on that machine.
|
||||
- The worker reuses the local store and scanner. Claude's legacy D3 print-mode quota probe is
|
||||
opt-in: current official documentation does not promise that slash commands in print mode are
|
||||
a supported quota API. Without it, existing observations remain available and age to stale.
|
||||
Codex uses D4's CLI app-server and rollout fallback. No provider HTTP API is added.
|
||||
|
||||
**Why.** R8, and the developer's clarification that the browser authorization response must
|
||||
travel through FinalToken to the CLI, without being stored. D7's analysis answers whether the
|
||||
remaining allowance will last through the actual reset; token prices alone cannot answer it.
|
||||
|
||||
**Gives up.** Automatic remote callbacks, provider-token sharing, automatic account switching,
|
||||
unverified identities, universal login lifetimes, and exact cross-machine attribution of old
|
||||
hourly buckets. The metadata inventory currently has a 100,000-record per-profile export bound;
|
||||
the collector retains prior data and reports failure when full. This version uses atomic JSON
|
||||
inventories, not an unbounded fleet database. See [operation and limits](web-dashboard.md).
|
||||
|
||||
## D10 — Stream Deck plugin
|
||||
|
||||
**Decision.** The plugin's UUID is `de.finalfactory.finaltoken`, its folder
|
||||
|
||||
@@ -4,11 +4,15 @@ Set by schmidt.florian on 2026-10-14 ([#1](https://git.finalfactory.de/FinalFact
|
||||
Each requirement has a stable ID. [Decisions](decisions.md) say how FinalToken meets them.
|
||||
|
||||
- **R1** NativeAOT on the newest .NET. Cross-platform: at least Windows 11 and CachyOS.
|
||||
- **R2** No sign-in to an AI provider inside the app and no API key or OAuth token. Data comes
|
||||
through the providers' command-line tools.
|
||||
- **R2** Provider credentials stay owned by the installed command-line tools. FinalToken can
|
||||
coordinate their official login and transiently relay an authorization response to the exact
|
||||
pending CLI process. It never stores or distributes provider access/refresh tokens or API keys.
|
||||
- **R3** Supported providers: at least Codex and Claude.
|
||||
- **R4** Opening the app shows a comprehensive stats panel, history included.
|
||||
- **R5** Small, non-intrusive popups remind the user when usage runs ahead of or behind the pace
|
||||
of a limit.
|
||||
- **R6** A Stream Deck plugin shows selected stats on its buttons.
|
||||
- **R7** The app installs or updates the Stream Deck plugin automatically, as the user chooses.
|
||||
- **R8** An authenticated self-hosted dashboard combines the user's Windows/Linux machines,
|
||||
keeping weekly sustainability central, account quota separate from deduplicated consumption,
|
||||
and measured, estimated, unknown and stale values distinct. See [D14](decisions.md#d14--self-hosted-dashboard-and-workers).
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
# Self-hosted dashboard and workers
|
||||
|
||||
The web dashboard leads with “will my allowance last until reset?” It uses Core's existing
|
||||
[D7 analysis](decisions.md#d7--pace), daily budgets, measured/estimated burn-up, recent-rate forecast,
|
||||
[reset history](decisions.md#d12--reset-history) and dated API list-price estimates.
|
||||
There is no inference gateway. Coding traffic continues through the user's own coding CLIs.
|
||||
|
||||
## Run locally
|
||||
|
||||
For automatic CT creation from a Proxmox host, use the [Proxmox install/update script](proxmox.md).
|
||||
|
||||
Build from the repository root:
|
||||
|
||||
```text
|
||||
dotnet build FinalToken.slnx -c Release
|
||||
```
|
||||
|
||||
Create an operator-owned `server.json` outside the source tree. Account ids represent one actual
|
||||
provider subscription/account. Bind every profile using the same account to the same id.
|
||||
Do not merge separate provider organizations/workspaces simply because their email is the same:
|
||||
this version verifies email, not organization entitlement. Use distinct account ids/profiles.
|
||||
|
||||
```json
|
||||
{
|
||||
"accounts": [
|
||||
{ "id": "personal-claude", "provider": "Claude", "label": "Personal Claude", "expectedEmail": "[email protected]", "timeZone": "Europe/Berlin" },
|
||||
{ "id": "personal-codex", "provider": "Codex", "label": "Personal Codex", "expectedEmail": "[email protected]", "timeZone": "Europe/Berlin" }
|
||||
],
|
||||
"machines": [
|
||||
{ "id": "desktop", "label": "Desktop", "osUser": "your-os-user", "profiles": [
|
||||
{ "id": "claude", "accountId": "personal-claude" },
|
||||
{ "id": "codex", "accountId": "personal-codex" }
|
||||
] }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Set `FINALTOKEN_SERVER_CONFIG` to that file, `FINALTOKEN_SERVER_DATA` to a writable data directory,
|
||||
`FINALTOKEN_DASHBOARD_KEY` to a random key of at least 32 characters and
|
||||
`FINALTOKEN_MACHINE_desktop` to a different random key of at least 32 characters.
|
||||
For example generate keys with your password manager or `openssl rand -hex 32`.
|
||||
Do not put keys in source control, command arguments, URLs or screenshots.
|
||||
|
||||
Start the server from the repository root:
|
||||
|
||||
```text
|
||||
dotnet run --project src/FinalToken.Web -c Release --no-build
|
||||
```
|
||||
|
||||
By default it listens on `http://127.0.0.1:5187`. Open exactly that URL and enter the dashboard key.
|
||||
For a remote deployment, set `FINALTOKEN_PUBLIC_ORIGIN` to the public HTTPS origin and run a TLS
|
||||
reverse proxy that preserves its Host header, or configure HTTPS directly in Kestrel.
|
||||
`ASPNETCORE_URLS` changes the listening address. Do not expose a plain HTTP listener to a remote
|
||||
network. No forwarded-header trust is enabled automatically. Restrict direct backend access;
|
||||
the reverse proxy must not log request bodies or authorization headers. Login URLs/codes are
|
||||
deliberately absent from server logs and disk state. TLS termination sees the transient code.
|
||||
Keys authorize all profiles on their configured machine; use service-account file/environment
|
||||
permissions and a private network/firewall. Rotate a machine key on both ends to revoke it.
|
||||
|
||||
## Configure each worker
|
||||
|
||||
Run one worker under the OS user that owns the official CLIs. It cannot switch OS users remotely.
|
||||
Use absolute paths in `worker.json`; a profile's `configDirectory` is the existing `.claude` or
|
||||
`.codex` directory (or the relevant environment override), and `dataDirectory` is its existing
|
||||
FinalToken history/settings directory. Use a separate data/config/state directory per account.
|
||||
|
||||
```json
|
||||
{
|
||||
"machineId": "desktop",
|
||||
"serverUrl": "http://127.0.0.1:5187",
|
||||
"stateDirectory": "<absolute worker metadata directory>",
|
||||
"profiles": [
|
||||
{ "id": "claude", "provider": "Claude", "expectedEmail": "[email protected]", "configDirectory": "<absolute Claude config directory>", "dataDirectory": "<absolute existing FinalToken data directory>" },
|
||||
{ "id": "codex", "provider": "Codex", "expectedEmail": "[email protected]", "configDirectory": "<absolute Codex config directory>", "dataDirectory": "<absolute separate FinalToken data directory>" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
JSON backslashes must be escaped on Windows, or use forward slashes. `cliPath` is an optional
|
||||
local executable override; ordinary native/npm CLI discovery reuses the desktop code.
|
||||
Set `FINALTOKEN_WORKER_KEY` to the server's key for this machine. Start from the repository root:
|
||||
|
||||
```text
|
||||
dotnet run --project src/FinalToken.Worker -c Release --no-build -- <absolute worker.json path>
|
||||
```
|
||||
|
||||
Remote worker URLs require HTTPS. Workers only make outbound connections; no worker port is open.
|
||||
Use the OS service manager/Task Scheduler for unattended startup, under the intended user with
|
||||
the CLI on PATH. A Linux/LXC worker needs .NET 10 (or a future locally built NativeAOT binary),
|
||||
installed official CLIs, writable profile directories, outbound HTTPS and any CLI keychain
|
||||
requirements. It needs no desktop/X11. Actual Linux/LXC operation has not been exercised here.
|
||||
The existing release ZIP tool does not package the new hosts yet; source builds and the
|
||||
[Proxmox installer](proxmox.md) are the supported setup paths.
|
||||
|
||||
## History, account identity and settings
|
||||
|
||||
The worker acquires the normal store lock before refreshing the existing store. When the desktop
|
||||
app owns it, the worker reads existing observations and independently scans metadata using its
|
||||
own cursors. It does not replace the user's existing settings. Both provider settings may remain
|
||||
in an older desktop store; for two worker profiles, point one at that existing store and give
|
||||
the other a new directory. Shared-provider historical import can use a read-only copy made while
|
||||
the desktop is stopped. Never run two writers against a copied active journal.
|
||||
|
||||
Source metadata is durably saved before export cursor advancement. The server persists received
|
||||
metadata and last-seen state atomically; offline data remains visible. Claude response ids dedupe
|
||||
across transcripts, resumed copies and machines. Codex session ids/timestamps are merged before
|
||||
calculating cumulative increases. Conflicting response/counter metadata is excluded with a
|
||||
warning. A source copied under a different session id cannot be recognized as the same session.
|
||||
Per-machine attribution of a shared session is inherently ambiguous; the dashboard shows configured
|
||||
profiles/health, while consumption charts show the deduplicated account total.
|
||||
|
||||
Existing hourly history has no response identities. To import older history without overlapping
|
||||
identified records, add these account fields to `server.json`:
|
||||
|
||||
```json
|
||||
{ "legacyMachine": "desktop", "legacyProfile": "claude", "historyBefore": "2026-11-01T00:00:00Z" }
|
||||
```
|
||||
|
||||
This is a fragment to merge into one account entry. Choose one source and a fixed whole UTC hour
|
||||
within the still-available source logs. Before it, use that source's hourly buckets once; after
|
||||
it, use identified events only. Missing source logs after the cutoff produce incomplete history,
|
||||
not reconstructed guesses. Account assignment of older logs is an operator assertion. Never
|
||||
reuse a profile directory for another account; configure a new profile instead.
|
||||
For Codex sessions without a cumulative sample before the cutoff, the first available total
|
||||
has an unknown migration baseline and is omitted with a warning. Later increases still count.
|
||||
This can omit a new session's first use too; supplying complete pre-cutoff session history or
|
||||
avoiding legacy import is preferable to counting potentially imported usage twice.
|
||||
|
||||
The newest account/window observation wins; quotas are never added. Its profile's existing
|
||||
threshold, hidden-window settings and probe interval control that window. A sample older than
|
||||
three probe intervals, an expired reset, offline source or unhealthy login withholds forecasts.
|
||||
The account timezone controls days/DST. There is no working-hour schedule in existing D7.
|
||||
API list-price values are labelled estimates; unknown models stay unpriced, and prices never
|
||||
imply guaranteed subscription capacity.
|
||||
|
||||
## Official login coordination
|
||||
|
||||
Select a machine/profile under **Machines & official CLI logins**, then **Log in / renew**.
|
||||
Verify its OS user and expected email before opening the official authorization page.
|
||||
|
||||
- Claude: the worker invokes `claude auth login --claudeai --email <expected email>` with the
|
||||
selected `CLAUDE_CONFIG_DIR`. When the CLI prints its manual-code prompt, paste the browser's
|
||||
authorization code into the dashboard. It travels transiently to that exact process's stdin.
|
||||
There is no automatic forwarding of a desktop browser's localhost callback to a worker.
|
||||
- Codex: the worker invokes `codex login --device-auth` with the selected `CODEX_HOME`, displays
|
||||
the CLI's official URL/device code and lets the CLI poll/exchange/store locally. Device auth
|
||||
must be enabled for that account/workspace. No remote localhost callback is needed.
|
||||
- FinalToken verifies the resulting email with `claude auth status --json` or Codex app-server
|
||||
`account/read`. A CLI exit code alone is not success. A mismatch may already have replaced that
|
||||
profile's CLI login; FinalToken flags it and excludes new collection. Log in again with the
|
||||
correct account. It does not copy, revert or auto-switch credentials.
|
||||
|
||||
Only the initiating browser session can inspect/respond/cancel its pending login. One attempt
|
||||
per machine/profile is allowed. Cancellation and the 15-minute deadline kill the process tree;
|
||||
worker restart invalidates pending routing. A server restart loses memory-only attempts; the
|
||||
worker's local deadline still cancels its CLI. Closing the dialog does not cancel a login:
|
||||
press **Cancel login** first if that is intended. Access/refresh tokens, API keys, cookies and
|
||||
credential files are never sent through FinalToken. The authorization code necessarily passes
|
||||
through browser/server/worker memory; it is never deliberately persisted or logged.
|
||||
|
||||
Provider login health is observed, not a fabricated 30-day expiry. The official CLI owns refresh.
|
||||
The real manual Claude stdin handoff and real provider authorization still need an interactive
|
||||
test with the installed CLI version. If redirected stdin is unsupported, cancel and run the login
|
||||
in the selected machine's terminal. Synthetic CLI integration tests exercise the implementation,
|
||||
not a provider's live service or changing terminal behavior.
|
||||
|
||||
## Provider usage limitations
|
||||
|
||||
Codex quota comes through its CLI app-server/rollout integration (D4). Claude's existing D3
|
||||
`-p /usage` probe is a legacy integration; current official docs do not establish it as a
|
||||
supported non-interactive quota API. Worker profiles default `enableLegacyClaudeProbe` to false.
|
||||
Existing Claude observations can be read but become stale; current subscription allowance may
|
||||
remain unknown. Enable the legacy probe only after verifying that your installed CLI resolves
|
||||
it locally without a model request. No private OAuth usage endpoint was added. Tokens are still
|
||||
collected locally from supported log parsers after identity verification.
|
||||
|
||||
The metadata inventory currently exports at most 100,000 source records, 30,000 quota samples
|
||||
and 100,000 legacy hourly/model points per profile. Requests are capped at 32 MiB. Full inventory
|
||||
exchange favors small personal fleets; it is not a streaming fleet database. When bounds or
|
||||
collection fail, previous metadata is retained and collection failure is shown. Server history
|
||||
has no automatic retention/deletion UI. Back up its metadata directory and the worker state.
|
||||
|
||||
Official references checked 2026-11-14:
|
||||
|
||||
- [Claude authentication and manual code handoff](https://code.claude.com/docs/en/authentication)
|
||||
- [Claude CLI auth commands](https://code.claude.com/docs/en/cli-reference)
|
||||
- [Codex authentication](https://learn.chatgpt.com/docs/auth?surface=cli)
|
||||
- [Codex CLI flags](https://learn.chatgpt.com/docs/cli/reference)
|
||||
- [Official Codex device-code implementation](https://github.com/openai/codex/blob/main/codex-rs/login/src/device_code_auth.rs)
|
||||
- [Official Codex app-server account identity](https://github.com/openai/codex/blob/main/codex-rs/app-server/README.md)
|
||||
|
||||
## Verification
|
||||
|
||||
Run from the repository root:
|
||||
|
||||
```text
|
||||
dotnet build FinalToken.slnx -c Release
|
||||
dotnet test --solution FinalToken.slnx -c Release
|
||||
python -B tools/test_web_dashboard.py
|
||||
python -B tools/docs/check_docs.py
|
||||
node --check src/FinalToken.Web/wwwroot/app.js
|
||||
```
|
||||
|
||||
The Python check launches the real web/worker executables with a synthetic C# CLI and temporary
|
||||
profiles. It tests HTTP authentication/CSRF/session isolation, Claude code relay, Codex device
|
||||
flow, cancellation, account mismatch, deduplicated history and absence of login payloads in
|
||||
server state. `--serve-fixture` starts the same provider-free setup for local visual inspection.
|
||||
It never invokes the installed Claude or Codex CLIs. NativeAOT publishing and live provider
|
||||
authorization require separate verification; analyzers/build success alone do not prove them.
|
||||
Reference in New Issue
Block a user