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
+75
View File
@@ -0,0 +1,75 @@
#!/usr/bin/env python3
"""D1/D11: publish the three NativeAOT programs and bundle the plugin assets."""
import argparse
import json
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import zipfile
import xml.etree.ElementTree as ET
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('rid', choices=['win-x64', 'linux-x64'])
parser.add_argument('--out', type=Path)
parser.add_argument('--skip-app', action='store_true')
args = parser.parse_args()
root = Path(__file__).resolve().parent.parent
version = ET.parse(root / 'Directory.Build.props').findtext('.//Version')
parts = (version or '').split('.')
if len(parts) != 3 or not all(part.isascii() and part.isdigit() for part in parts):
parser.error('Directory.Build.props must define a three-part numeric Version.')
plugin_version = version + '.0'
output = (args.out or root / 'artifacts' / 'publish' / args.rid).resolve()
output.mkdir(parents=True, exist_ok=True)
if any(output.iterdir()):
parser.error('Output directory must be empty; existing files are never deleted.')
plugin = output / 'streamdeck' / 'de.finalfactory.finaltoken.sdPlugin'
with tempfile.TemporaryDirectory(prefix='finaltoken-publish-') as temporary:
for name in ['App', 'Cli', 'StreamDeck']:
if name == 'App' and args.skip_app:
continue
stage = Path(temporary) / name
subprocess.run(['dotnet', 'publish', str(root / 'src' / ('FinalToken.' + name)),
'-c', 'Release', '-r', args.rid, '-p:PublishAot=true',
'-o', str(stage)], cwd=root, check=True)
destination = plugin if name == 'StreamDeck' else output
destination.mkdir(parents=True, exist_ok=True)
for file in stage.iterdir():
if file.suffix in ['.pdb', '.dbg']:
continue
target = destination / file.name
if target.exists():
if file.is_file() and target.is_file() and file.read_bytes() == target.read_bytes():
continue
raise RuntimeError('Publish outputs collide: ' + str(target))
if file.is_dir():
shutil.copytree(file, target)
else:
shutil.copy2(file, target)
shutil.copytree(root / 'src' / 'FinalToken.StreamDeck' / 'plugin', plugin, dirs_exist_ok=True)
manifest_path = plugin / 'manifest.json'
manifest = json.loads(manifest_path.read_text(encoding='utf-8'))
manifest['Version'] = plugin_version
manifest_path.write_text(json.dumps(manifest, indent=2) + '\n', encoding='utf-8')
archive = output.parent / (output.name + '.zip')
if archive.exists():
raise RuntimeError('Archive already exists: ' + str(archive))
temporary_zip = archive.with_suffix('.zip.tmp')
with zipfile.ZipFile(temporary_zip, 'w', zipfile.ZIP_DEFLATED) as bundle:
for file in sorted(output.rglob('*')):
if file.is_file():
bundle.write(file, file.relative_to(output))
os.replace(temporary_zip, archive)
for file in sorted(output.rglob('*')):
if file.is_file():
print(str(file.relative_to(output)) + ' (' + str(file.stat().st_size) + ' bytes)')
print('Archive: ' + str(archive))
print('Plugin Version: ' + plugin_version)
if __name__ == '__main__':
main()