Expand description
Local credential detection — the seed for auto-enabling vendors.
A fresh install shows the four default vendors and nothing else, even when
the machine already carries a Cursor login, a Kiro database, a gh OAuth
session, or a KILO_API_KEY. This module answers “which vendors could
fetch right now with what is already on disk?” cheaply enough to run at
every frontend start, and turns the answer into a minimal edit of
config.toml: enabled = true for the vendors that have credentials and
are not enabled yet. It never writes false and never removes anything —
the config stays the user’s own.
Two pieces, mirroring OpenUsage’s hasLocalCredentials +
FirstRunSeeder/NewProviderSeeder:
has_local_credentialsis the per-vendor probe. Files, sqlite, saved keys, env vars, local port discovery — never the network, never a token refresh, never a cache directory or lock file. It reuses the same resolversbuild_outcomereads through, so “detected” means “the fetch would at least find its credential”.DetectStateremembers which vendors have already been considered, so a vendor the user deliberately disabled after it was auto-enabled stays disabled: it is only ever auto-enabled the first time it is seen. New vendors added by an upgrade are not inknownand get their one chance.planis the pure decision;run_onceis the whole cycle.
Structs§
- Detect
Plan - What one detection pass decided.
- Detect
Report - What one full
run_once_withcycle did — the CLI’s report and the serialized shape ofdetect --json(vendors as slugs, no secrets). - Detect
State - Which vendors detection has already had its one look at. Persisted as
JSON next to the vendor caches; a vendor in
knownis never auto-enabled again, so a user’s laterenabled = falsesticks.
Functions§
- default_
state_ path <cache dir>/ai-usagebar/detect.json— beside the per-vendor caches, because it is derived state that can be deleted to re-run detection.- format_
report - Human-readable
detectoutput.config_hintis where the enables were written, shown only when something was enabled. - has_
local_ credentials - Cheap, local-only probe: files, sqlite, saved keys, env vars. Never the
network.
truemeans the vendor’s fetch would find a credential — not that the credential is still valid, which only the wire can tell. - plan
- The pure decision. Candidates are
allminusstate.known, or every vendor inallwhenforce. A candidate is enabled whenprobesays it has credentials and the config doesn’t already enable it.knownbecomes the union of the old set andall, inVendorId::allorder, deduped — so a vendor is considered once per install, and once more perforce. - run_cli
ai-usagebar detect [--all] [--json]: one-shot local credential detection as a command, so any frontend (or the user) can run it at startup. Uses the real config and state paths — tests go throughrun_once_withandformat_reportinstead.- run_
once - One full detection cycle: load the config (
config_path, or the resolved default), load the state atstate_path, plan withhas_local_credentials, write the enables into the config, save the state, and return what was enabled. - run_
once_ report run_oncekeeping the wholeDetectReport— what thedetectsubcommand prints. Same real probe, samecatch_unwindguard.- run_
once_ with run_once_reportwith the probe injected — the test seam, so the cycle’s config write and state bookkeeping can be exercised without a probe that reads this machine’s real credential files.