Replace cap-based estimation with PTY-driven 'claude /usage' parser

The widget now spawns 'claude' via portable-pty, sends /usage, parses the
three rendered bars (Current session / Current week all / Current week
Sonnet), and shows the real percentages in the ring + weekly bars. A
background task refreshes every 5 minutes; the title-bar refresh button
forces an immediate fetch.

Drops the cap-tuning UI and tier card from Settings; adds a 'claude command'
override (e.g. 'wsl.exe -- claude' for Windows-host widgets reading WSL
credentials) and a refresh-interval setting. Fixes title-bar buttons getting
swallowed as drag attempts via data-tauri-drag-region="false".
This commit is contained in:
megaproxy 2026-05-09 01:40:44 +01:00
parent 18e55cd139
commit db9a10a4c2
13 changed files with 656 additions and 166 deletions

View file

@ -5,6 +5,7 @@ use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
use std::sync::Arc;
use crate::cli_usage::CliUsage;
use crate::jsonl::UsageEvent;
use crate::settings::Settings;
use crate::watch::WatcherHandle;
@ -23,6 +24,9 @@ pub struct AppState {
pub files: RwLock<HashMap<PathBuf, FileCache>>,
pub seen_ids: RwLock<HashSet<String>>,
pub settings: RwLock<Settings>,
/// Latest /usage result. Refreshed periodically by a background task,
/// or on-demand via the `refresh_cli_usage` command.
pub cli_usage: RwLock<Option<CliUsage>>,
/// Boxed so we can keep the watcher alive across the whole app lifetime
/// without polluting Tauri's setup hook.
pub watcher: Mutex<Option<WatcherHandle>>,
@ -37,6 +41,7 @@ impl AppState {
files: RwLock::new(HashMap::new()),
seen_ids: RwLock::new(HashSet::new()),
settings: RwLock::new(settings),
cli_usage: RwLock::new(None),
watcher: Mutex::new(None),
})
}