Skip to content

refactor: one debounced watcher for config and scan; core counts the menubar's live numbers - #168

Merged
fylorn merged 1 commit into
mainfrom
refactor/shared-watcher-live
Sep 24, 2026
Merged

fylorn merged 1 commit into
mainfrom
refactor/shared-watcher-live

Conversation

@fylorn

@fylorn fylorn commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Two cleanups.

One debounced watcher (tw-watch, new, layer two)

tw-config/src/watch.rs and tw-scan/src/watch.rs were the same code twice: watch directories without recursing, keep create/modify/remove events, debounce, try_send into an mpsc. They now call one function:

tw_watch::watch(dirs: &[PathBuf], debounce: Duration, relevant: impl Fn(&Path) -> bool + Send + 'static)
    -> Result<(tw_watch::Watch, tokio::sync::mpsc::Receiver<()>), tw_watch::WatchError>

Each caller only says which directories and which paths count (tw-config: the config file's name in its directory, 200 ms; tw-scan: interesting extensions that are not ours, 300 ms). The channel holds at most one pending signal. Watch/WatchError are re-exported from both modules, so callers are unchanged. notify is now a dependency of tw-watch alone. Layer one is untouched (tw-watch is layer two; layer_one test still green).

Core counts the menubar's live numbers (GET /live)

The desktop's src-tauri/src/tally.rs listened to the event stream to count running requests and compute the generation rate, and had to reconcile with /in-flight after joining late or dropping events. The event bus already tracks what is in flight; it now also keeps first-byte times and the last minute of finished requests.

  • ep::Live: GET "/live", () => LiveView
  • LiveView { running: Vec<RunningView>, tokens_per_sec: Option<u32> }
  • RunningView { id, client, client_hint: Option<String>, model, provider, at_ms }, sorted by start (same set as /in-flight)
  • Rate = sum of output tokens / sum of generation time (duration − ttfb) over requests finished in the last 60 s, only finished requests that had response headers; null when none.

Lite follow-up: call /live wherever the menubar collects (refresh_live, and the quit confirmation's count) and delete tally.rs, resync_tally and the tally feeding in the event bridge.

🤖 Generated with Claude Code

…menubar's live numbers

tw-watch: watch a set of directories without recursing, keep create/modify/
remove events whose path passes a filter, debounce a burst into one signal
and drop signals while one is pending. tw-config's config-file watch and
tw-scan's client-surface watch now differ only in which directories and
which paths count; notify is a dependency of tw-watch alone.

GET /live: the running requests (the same set as /in-flight, as small
views sorted by start) and the generation rate over the last minute
(output tokens over time after the first byte, weighted by tokens; null
when nothing finished). The event bus already tracked what is in flight;
it now also keeps first-byte times and recent finishes, so the desktop's
menubar can stop counting requests itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fylorn
fylorn merged commit d6149f0 into main Sep 24, 2026
3 checks passed
@fylorn
fylorn deleted the refactor/shared-watcher-live branch September 24, 2026 07:59
@fylorn fylorn mentioned this pull request Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant