How bytonylee/free-router works
Purpose and entry points
Free Router is a Bun/Node-distributed TypeScript CLI that discovers and benchmarks free AI models from NVIDIA NIM and OpenRouter, then configures a selected model for local AI clients. The executable entry point is src/bin/free-router.ts; it selects interactive TUI mode, help, or the non-interactive --best workflow.
Model catalog and ranking data
Static model capabilities, support metadata, aliases, and rankings are repository-managed data rather than fetched at runtime. The CLI loads and normalizes this catalog to construct provider/model candidates, tiers, context windows, and target compatibility:
• data/model-rankings.json
• data/model-support.json
• src/lib/models.ts
Catalog maintenance is an explicit pipeline: scripts/update-models.ts updates data under the contract in docs/model-sync-data-contract.md, and GitHub automation runs it through .github/workflows/model-catalog-sync.yml.
Configuration and provider boundary
Configuration is persisted in the user home directory (~/.free-router.json, intended mode 0600), while environment variables take precedence for API keys. Provider enablement and UI behavior are centralized in:
• src/lib/config.ts
• src/lib/models.ts
The provider boundary supports NVIDIA NIM and OpenRouter credentials/endpoints. Missing or failing keys remain distinguishable from service/model availability so the UI can direct users to key editing without conflating authentication with ping health.
Ping and live metrics pipeline
The CLI probes candidate model endpoints in parallel, records HTTP status and latency, and derives rolling average latency, uptime, and verdict state. This is the core operational data flow used by both the live interface and best-model selection:
• src/lib/ping.ts
• src/lib/models.ts
• src/lib/utils.ts
Interactive mode repeatedly refreshes these metrics; --best performs fixed rounds and prints only the selected model ID, making stdout suitable for scripts.
Terminal interaction layer
The interactive runtime is an Ink/React terminal application. It owns keyboard-driven filtering, sorting, navigation, refresh cadence, focus-safe redraw behavior, and transitions among workflows:
• src/tui/ink-harness.ts
• src/tui/first-run-app.tsx
• src/tui/settings-app.tsx
src/tui/target-picker-app.tsx is the selection handoff boundary, while src/tui/update-app.tsx handles the in-app global update/restart path.
Target configuration and system effects
After selection, the target picker transforms model/provider metadata into each target’s native configuration, backs up existing files, and may launch OpenCode. Target-specific paths include OpenCode JSON, OpenClaw JSON, and Hermes YAML; plaintext key export is opt-in. The write/launch logic is concentrated in:
• src/lib/targets.ts
• src/tui/target-picker-app.tsx
• src/lib/config.ts
This is the primary side-effect boundary: pings contact external provider APIs; target handoff modifies user configuration files and can spawn OpenCode.
Distribution, website, and release infrastructure
The package is distributed through npm-compatible launchers, with compatibility shims for historical command/package names:
• package.json
• publish/frouter-cli-shim/bin.js
• publish/legacy-scope-shim/bin.js
A separate Vite static site renders catalog-derived content and is deployable to Vercel:
• site/src/main.ts
• site/scripts/build-site.mjs
• site/vercel.json
CI, releases, and governance are GitHub Actions-driven, notably .github/workflows/ci.yml and .github/workflows/release.yml.
Main entry points: free-router.ts Free Router CLI · ink-harness.ts Ink TUI harness · ping.ts Ping metrics · models.ts Model candidates
Components 23
CLI runtime
Interactive and scripted model selection.
- Free Router CLI · Selects TUI, help, or the scripted best-model workflow.
src/bin/free-router.ts - Configuration · Reads user config and environment-overridden API keys.
src/lib/config.ts - Model candidates · Builds provider candidates, tiers, context windows, and compatibility.
src/lib/models.ts - Ping metrics · Parallel endpoint probes derive latency, uptime, and verdicts.
src/lib/ping.ts - Metric utilities · Supports rolling metrics and verdict derivation.
src/lib/utils.ts - Ink TUI harness · Owns live refresh, keyboard interaction, filtering, and navigation.
src/tui/ink-harness.ts - First-run flow
src/tui/first-run-app.tsx - Settings flow · Edits provider credentials and UI settings.
src/tui/settings-app.tsx
Model catalog
Repository-managed provider and capability data.
- Model rankings
data/model-rankings.json - Model support
data/model-support.json - Catalog updater · Updates managed model data under the sync contract.
scripts/update-models.ts - Sync data contract
docs/model-sync-data-contract.md - Catalog sync action
.github/workflows/model-catalog-sync.yml
Target handoff
Selected models become local client configuration.
- Target picker · Transforms a selection into a target-specific configuration request.
src/tui/target-picker-app.tsx - Target writer · Backs up and writes OpenCode/OpenClaw JSON or Hermes YAML; may launch OpenCode.
src/lib/targets.ts
Distribution and release
Package launchers, website, and automation.
- Package manifest · Defines distributed CLI package and launchers.
package.json - Frouter compatibility shim
publish/frouter-cli-shim/bin.js - Legacy scope shim
publish/legacy-scope-shim/bin.js - Catalog website · Renders catalog-derived content for Vercel deployment.
site/src/main.ts - Site builder
site/scripts/build-site.mjs - Vercel deployment
site/vercel.json - CI workflow
.github/workflows/ci.yml - Release workflow
.github/workflows/release.yml
Connections 29
- Free Router CLI → Ink TUI harness: interactive mode
- Free Router CLI → Model candidates: --best selection
- Free Router CLI → Configuration: loads settings
- Configuration → Model candidates: enables providers
- Model rankings → Model candidates: ranking data
- Model support → Model candidates: capabilities and aliases
- Model candidates → Ping metrics: candidate endpoints
- Configuration → Ping metrics: provider credentials
- Metric utilities → Ping metrics: rolling calculations
- Ping metrics → Ink TUI harness: live metrics
- Ping metrics → Free Router CLI: best-model result
- Ink TUI harness → First-run flow: onboarding
- Ink TUI harness → Settings flow: settings
- Ink TUI harness → Target picker: selected model
- Target picker → Target writer: write target config
- Configuration → Target writer: key export policy
- Sync data contract → Catalog updater: governs updates
- Catalog updater → Model rankings: updates
- Catalog updater → Model support: updates
- Catalog sync action → Catalog updater: runs
- Package manifest → Free Router CLI: publishes executable
- Frouter compatibility shim → Free Router CLI: compatibility launch
- Legacy scope shim → Free Router CLI: compatibility launch
- Model rankings → Catalog website: catalog content
- Model support → Catalog website: catalog content
- Site builder → Catalog website: builds
- Vercel deployment → Catalog website: deploys
- CI workflow → Package manifest: validates
- Release workflow → Package manifest: publishes