core: publish self-hosted weekly dashboard and Proxmox deployment (#20)
Reuse existing weekly/reset analysis in an authenticated dashboard and local official CLI workers. Add safe Proxmox installation and updates, account-attributed history, and MIT distribution. Provider credentials stay owned by each CLI. Closes #19
This commit was merged in pull request #20.
This commit is contained in:
@@ -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