Keeps a binary and the desktop frontends it feeds from coming apart
  • Rust 98.8%
  • Python 1.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Marc-Etienne Barrut b259562912 [master] chore(release): 0.17.0
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-18 03:41:41 +01:00
.github/workflows [feature/plan-catalog] fix(catalog): the canary reads an ungrouped price whole and opens an issue only for a changed page 2026-11-03 20:35:23 +01:00
assets/providers [feature/more-provider-marks] docs(brands): carry Omarchy's copyright and MIT notice 2026-11-06 23:26:22 +01:00
scripts [feature/plan-catalog] fix(catalog): the canary reads an ungrouped price whole and opens an issue only for a changed page 2026-11-03 20:35:23 +01:00
src [feature/macos-start-time] test(proc): macOS start times are epoch microseconds and end with the process 2026-11-18 03:34:22 +01:00
tests [feature/package-owners] feat: an updater that leaves the TLS provider to the caller 2026-10-11 19:54:38 +02:00
.gitignore [master] feat: the machinery two gauges share, and neither panel needs 2026-09-16 03:11:01 +02:00
Cargo.lock [master] chore(release): 0.17.0 2026-11-18 03:41:41 +01:00
Cargo.toml [master] chore(release): 0.17.0 2026-11-18 03:41:41 +01:00
CHANGELOG.md [master] chore(release): 0.17.0 2026-11-18 03:41:41 +01:00
icon.svg [chore/project-icons] chore: add the project icon 2026-11-07 00:29:15 +01:00
LICENSE Say why this is MIT when TailGauge is GPL (#4) 2026-09-16 20:59:07 +02:00
LICENSE-MIT Say why this is MIT when TailGauge is GPL (#4) 2026-09-16 20:59:07 +02:00
LICENSE-WTFPL Say why this is MIT when TailGauge is GPL (#4) 2026-09-16 20:59:07 +02:00
README.md [feature/macos-start-time] docs: proc::start_time answers on macOS 2026-11-18 03:34:22 +01:00

selvedge

The self-finished edge of a piece of cloth is the bit that stops it unravelling. This is the same idea for a desktop widget that ships as a binary plus the QML and JavaScript that binary feeds: it keeps them from coming apart.

Two projects, TailGauge and TokenGauge, draw a panel on Plasma, GNOME and Omarchy by shelling out to a binary. TokenGauge ships a few more of them - a TUI, a tray, a waybar module - which is why a project here names its binaries rather than its binary. Neither panel has anything to do with the other. What they share is everything around the panel: fetching a release from GitHub, replacing the running binary, and reinstalling the desktop payloads from the same archive so the binary and its frontends can never be a release apart.

That was 1,400 lines in each of them.

What a caller provides

Everything the machinery cannot know, in one value:

const TAILGAUGE: selvedge::Project = selvedge::Project {
    // Primary first: it names the release assets and every alias points at it.
    binaries: &["tailgauge"],
    repo: "Arzaroth/TailGauge",
    repo_env: "TAILGAUGE_REPO",
    version: env!("CARGO_PKG_VERSION"),
    frontends: FRONTENDS,
    // Old names the binary still answers to, kept as symlinks.
    aliases: ALIASES,
    // Old names it does not, removed rather than left to answer.
    legacy: &["tailgauge-update"],
    // How each platform is spelled in the asset names: `linux-x86_64` here,
    // or a table of Rust target triples for a project releasing under those.
    targets: selvedge::SHORT_TARGETS,
    // Windows only: where an MSI records its ProductCode. None means every
    // update replaces in place.
    msi_marker_key: None,
};

version has to come from the caller: env!("CARGO_PKG_VERSION") inside this crate would report this crate's version, which is never what anyone wants.

Then:

let status = selvedge::update::check_cached(&TAILGAUGE, &cache, force)?;
let applied = selvedge::update::apply(&TAILGAUGE, &cache)?;

A release archive may hold its files at the top or inside one directory named after the asset (tailgauge-v1.2.3-linux-x86_64/); either is read.

Who owns the copy on disk

An update replaces the files beside the running binary, which is only right when nobody else keeps a record of them. update::owner says who does, without fetching anything: Homebrew, a macOS app bundle, a distribution's package manager (anything under /usr outside /usr/local, named after the package database it finds), the Nix store, a snap, or the project's MSI. apply refuses all of them with Owner::advice, which says how to upgrade instead, except the MSI, which it hands the upgrade to. A caller that wants to refuse the MSI too, or to refuse before reaching GitHub, asks owner first.

Several plans in one meter

selvedge::plans is the other thing the projects share: adding several subscriptions at one vendor up into one meter. TokenGauge draws it in its panels and remuda on its page, and each used to carry its own copy of the arithmetic, in Rust and in TypeScript.

use selvedge::plans::{pool, Share};

let p = pool(&[
    Share { used: 100.0, weight: 10.0 }, // an Ultra, spent
    Share { used: 100.0, weight: 1.0 },  // a Pro, spent
]).unwrap();
assert_eq!(p.label(), "110% of 110%");

Plans count in units of the largest one, a half rounds to even, a pooled bar fills to Σ used × weight ÷ Σ weight, and a split bar gives each plan the stretch its weight buys, a tenth of the bar at least. Only the numbers are here: the label, the tone and any "estimate" badge are the caller's. It needs no feature and links nothing.

What a plan weighs comes from the catalog below. Which plan a login holds is the caller's to read, except for a Claude Team seat, which both projects read off the same fields and used to read differently. team_seat takes the profile's seatTier and every rate-limit tier the login carries, and calls a seat premium when any tier names an Nx - a premium seat has been reported as team_tier_1, so the seat tier's name alone is not enough. Seat::weight is its multiplier against a Pro, and tier_multiplier the N of a tier such as default_claude_max_20x. That N is not what a Max plan weighs: max_plan names the plan a tier is sold as (_5x is Max, _20x Ultra) and MaxPlan::weight is its weekly allowance against a Pro's, 5 and 10.

What a plan costs and weighs

selvedge::catalog is every plan the projects know, by the id its provider's API names it with, as a list of dated terms: the monthly list price in US dollars and the weight against the provider's base plan (or the plan's own unit when it belongs to another line, such as the X Subscription beside Cursor's and Grok's legacy plans), with its source and the day it was read where one was recorded. A plan changes on a date - OpenAI doubled every Pro tier on 2026-10-29 - so Plan::on(day) gives the term a past week was under and weight(provider, id) the one in force now. The table is src/catalog.json, compiled in; a figure nobody has verified is left out rather than guessed.

scripts/catalog-canary.py fetches each provider's pricing page and compares the dollar figures on it with the ones the catalog last saw there. The Catalog canary workflow runs it daily and opens an issue when a figure moves. A page that fills its prices in with a script cannot be checked this way and is listed as such, and a page that refuses the fetch is reported unread, not changed.

Each provider's mark

selvedge::brands holds every provider's mark and colour, so a provider looks the same in TokenGauge's panels and on remuda's page. A mark is an SVG in currentColor for the caller to tint; a black-and-white brand (Grok, Z.ai, opencode) has no colour and is drawn in the caller's foreground, so it shows on a dark panel and a light page alike. mark_color is what to tint a mark in: Kimi keeps its blue for accents but draws its K in the foreground, beside the blue dot the mark carries itself, and Codex, Cursor and OpenRouter keep their colour for accents and draw their black-and-white marks in the foreground. It needs no feature and links nothing.

let kimi = selvedge::brands::brand("kimi").unwrap();
assert_eq!(kimi.color, Some("#1783FF"));

Where each mark comes from is in assets/providers/NOTICE.

Who spent what

selvedge::usage holds the records remuda writes and TokenGauge reads. remuda switches logins and runs a proxy, so only it knows which login a request spent; TokenGauge reads the CLIs' transcripts and prices them, so only it knows what the request cost. The files between them are a contract, so each one is declared here once, with its writer and its reader:

Module File Written by Read by
usage::ledger <store>/.attribution.jsonl remuda, on a switch, a login change it notices, and each remuda run session TokenGauge, to give each billed request a login
usage::requests <store>/.proxy-requests.jsonl (and .1 once rotated at 8 MiB) remuda's proxy, one line per request TokenGauge, for spend no transcript holds; remuda, for its request views
usage::export stdout of tokengauge --usage-json (--by-hour for rows by the hour) TokenGauge remuda's Usage page, and its Value view by the hour

Ledger::login_at is the rule for a billed request: the login its session ran under when a remuda run claimed it, else the login the CLI's files held at that instant, else nobody. Nothing is guessed backwards: usage from before the ledger's first line stays unattributed. A login is named by account_digest, the first 16 hex digits of its account id's SHA-256, wherever the id itself must not be written down. TokenCounts is TokenGauge's sync wire format, and both sides count tokens in it.

proc::installed finds a sibling binary the way the installers lay it out (PATH, then ~/.local/bin), and proc::start_time tells a live process from a later one handed the same pid, on Linux and macOS. It needs no feature.

The lock

An update takes an exclusive lock on the install directory so one fired from the panel and one fired from a terminal cannot race on the same staging directory. The lock is the kernel's, held on an open descriptor, rather than the existence of a file: a process that is killed closes its descriptors, and the next update proceeds. A lock file that means "locked" while it merely exists survives the crash and blocks every later update until somebody deletes it by hand.

Features

self-update is on by default and is the half that links a network stack: fetching a release, replacing the binary. A caller that only installs payloads and reads a cached check - a GUI that shells out to whoever owns the network - takes the crate with default-features = false and still gets frontend and state.

self-update brings its own TLS provider, aws-lc. A caller already built on another one - ring, say, through iroh or quinn - takes updater instead, which is the same updater with no provider of its own, and installs its provider as the process default before calling it.

Windows

A project installed by an MSI is upgraded by the MSI, because replacing the files underneath it would leave Windows describing a version that is no longer installed. The installer records its ProductCode under msi_marker_key; if it also records InstallDir there, only a copy running from that directory counts as the MSI's. apply returns with installer_launched set and nothing replaced, and the caller must exit promptly: one of the files msiexec is about to replace is the executable running the code.

That path compiles nowhere but Windows, so CI builds and tests there too. The registry parsing it depends on is deliberately not behind cfg, because that is where the mistakes are and a test that only runs on a release runner is a test nobody sees fail.

Tests

The suite drives the whole thing against SAMPLE, a project that does not exist, which is what keeps this crate honest about being machinery rather than one of its callers wearing a different name.

tests/callers.rs is the other half: both real projects, declared the way they declare themselves, and the call sites they use today. The crate came out of one of them and fits that one by construction. TokenGauge ships two binaries where TailGauge ships one, keeps an old name working where TailGauge takes one away, and is MSI-installed on Windows where TailGauge has no Windows at all - so if the surface moves under either of them, that file stops compiling.

Provenance and licence

selvedge is dual-licensed: use it under either the MIT License or the WTFPL, whichever you prefer (SPDX-License-Identifier: MIT OR WTFPL), matching both callers.

The code was extracted from TailGauge and merged with the equivalent half of TokenGauge. Every line that came here was written by one person, who holds the copyright in it and licenses it here under these terms. Nothing was taken from a contributor whose terms this would have to respect, and what either caller is licensed under is a question for that repository rather than a claim worth mirroring here.

No third-party code is vendored. Every dependency is permissive - MIT, Apache-2.0 or dual - and none is copyleft.