OmniRoute/bin/cli
Diego Rodrigues de Sa e Souza 92715c8f2c
Some checks are pending
Publish Fork Image to GHCR / Build and Push Fork Image (push) Waiting to run
CI / Change Classification (push) Waiting to run
CI / Lint (push) Waiting to run
CI / Quality Ratchet (push) Blocked by required conditions
CI / Quality Gates (Extended) (push) Waiting to run
CI / Docs Sync (Strict) (push) Waiting to run
CI / Docs Lint (prose — advisory) (push) Waiting to run
CI / i18n UI Coverage (push) Waiting to run
CI / i18n Validation (all languages) (push) Waiting to run
CI / PR Test Policy (push) Waiting to run
CI / Build (push) Blocked by required conditions
CI / Package Artifact (push) Blocked by required conditions
CI / Electron Package Smoke (push) Blocked by required conditions
CI / Unit Tests (1/8) (push) Blocked by required conditions
CI / Unit Tests (2/8) (push) Blocked by required conditions
CI / Unit Tests (3/8) (push) Blocked by required conditions
CI / Unit Tests (4/8) (push) Blocked by required conditions
CI / Unit Tests (5/8) (push) Blocked by required conditions
CI / Unit Tests (6/8) (push) Blocked by required conditions
CI / Unit Tests (7/8) (push) Blocked by required conditions
CI / Unit Tests (8/8) (push) Blocked by required conditions
CI / Vitest (MCP / autoCombo / UI components) (push) Blocked by required conditions
CI / Coverage (push) Blocked by required conditions
CI / SonarQube (push) Blocked by required conditions
CI / PR Coverage Comment (push) Blocked by required conditions
CI / E2E Tests (1/9) (push) Blocked by required conditions
CI / E2E Tests (2/9) (push) Blocked by required conditions
CI / E2E Tests (3/9) (push) Blocked by required conditions
CI / E2E Tests (4/9) (push) Blocked by required conditions
CI / E2E Tests (5/9) (push) Blocked by required conditions
CI / E2E Tests (6/9) (push) Blocked by required conditions
CI / E2E Tests (7/9) (push) Blocked by required conditions
CI / E2E Tests (8/9) (push) Blocked by required conditions
CI / E2E Tests (9/9) (push) Blocked by required conditions
CI / Integration Tests (1/2) (push) Blocked by required conditions
CI / Integration Tests (2/2) (push) Blocked by required conditions
CI / Security Tests (push) Blocked by required conditions
CI / CI Dashboard (push) Blocked by required conditions
Publish to Docker Hub / Resolve Docker release metadata (push) Waiting to run
Publish to Docker Hub / Build Docker (linux/amd64) (push) Blocked by required conditions
Publish to Docker Hub / Build Docker (linux/arm64) (push) Blocked by required conditions
Publish to Docker Hub / Publish multi-arch manifests (push) Blocked by required conditions
OpenSSF Scorecard / Scorecard analysis (push) Waiting to run
semgrep / semgrep (push) Waiting to run
Wiki Sync / Sync wiki with docs (push) Waiting to run
Release v3.8.46
Release v3.8.46. Full changelog: CHANGELOG.md → [3.8.46]. Contributor attribution in the CHANGELOG entries.
2026-07-07 13:14:06 -03:00
..
api-commands Release v3.8.35 (#4743) 2026-06-23 17:06:18 -03:00
commands Release v3.8.46 2026-07-07 13:14:06 -03:00
locales Release v3.8.41 (#5327) 2026-06-29 16:51:03 -03:00
runtime Release v3.8.41 (#5327) 2026-06-29 16:51:03 -03:00
schemas feat(cli): padronizar saída emit() — cli-table3/csv-stringify/schema (Fase 1.7) 2026-05-14 23:54:49 -03:00
scripts feat(cli): suporte i18n completo — 42 locales, --lang flag, config lang get/set/list (#2285) 2026-05-15 13:14:14 -03:00
tray Release v3.8.40 2026-06-29 08:40:06 -03:00
tui fix(cli): code-review — C1/C2/C3/I1/I3/I4/I5/m1/m2/m4 2026-05-15 09:48:30 -03:00
tui-components feat(cli): TUI dashboard interativo e menu de interface (Fases 8.10+8.9) 2026-05-15 04:36:21 -03:00
utils fix(cli): bare omniroute (default serve) must provision STORAGE_ENCRYPTION_KEY 2026-06-03 21:08:01 -03:00
api.mjs Release v3.8.30 (#4267) 2026-06-20 07:09:43 -03:00
contexts.mjs Release v3.8.29 (#4126) 2026-06-19 06:49:01 -03:00
CONVENTIONS.md feat(cli): suporte i18n completo — 42 locales, --lang flag, config lang get/set/list (#2285) 2026-05-15 13:14:14 -03:00
data-dir.mjs Release v3.8.34 (#4614) 2026-06-23 03:08:29 -03:00
encryption.mjs Release v3.8.1 (#2441) 2026-05-21 01:29:12 -03:00
i18n.mjs feat(cli): suporte i18n completo — 42 locales, --lang flag, config lang get/set/list (#2285) 2026-05-15 13:14:14 -03:00
io.mjs Release v3.8.32 (#4418) 2026-06-21 08:56:51 -03:00
output.mjs Release v3.8.6 (#2804) 2026-05-29 12:44:29 -03:00
plugins.mjs feat(cli): fase 9.4 — plugin system (omniroute-cmd-*) 2026-05-15 05:11:18 -03:00
program.mjs feat(cli): suporte i18n completo — 42 locales, --lang flag, config lang get/set/list (#2285) 2026-05-15 13:14:14 -03:00
provider-catalog.mjs Release v3.8.0 (#2073) 2026-05-10 00:55:06 -03:00
provider-store.mjs Release/v3.8.0 — full changelog with 660+ commits (#2419) 2026-05-20 02:05:50 -03:00
provider-test.mjs Release v3.8.0 (#2073) 2026-05-10 00:55:06 -03:00
README.md feat(cli): suporte i18n completo — 42 locales, --lang flag, config lang get/set/list (#2285) 2026-05-15 13:14:14 -03:00
runtime.mjs feat(cli): banir SQLite direto — withRuntime + src/lib/db/* modules (Fase 1.5) 2026-05-14 23:41:02 -03:00
settings-store.mjs Release v3.8.0 (#2073) 2026-05-10 00:55:06 -03:00
spinner.mjs feat(cli): fase 8.1/8.6/8.14 — spinner, open, clipboard e environment helpers 2026-05-15 03:00:52 -03:00
sqlite.mjs fix(cli): surface 'omniroute runtime repair' in native-module errors (#3476) (#3828) 2026-06-14 02:02:02 -03:00

bin/cli — OmniRoute CLI internals

This directory contains the CLI runtime, helpers, and commands for the omniroute binary.

Structure

bin/cli/
├── CONVENTIONS.md          ← normative design rules (read this first)
├── README.md               ← this file
├── program.mjs             ← Commander setup — global flags, registerCommands()
├── api.mjs                 ← apiFetch() — all HTTP calls + retry/backoff
├── runtime.mjs             ← withRuntime() — server-first / DB-fallback
├── i18n.mjs                ← t() — i18n helper + locale detection
├── output.mjs              ← emit() — table/json/jsonl/csv + printSuccess/printError
├── io.mjs                  ← ask() / askSecret() — interactive prompts
├── data-dir.mjs            ← resolveDataDir() / resolveStoragePath()
├── sqlite.mjs              ← openOmniRouteDb() — DB bootstrap
├── encryption.mjs          ← encrypt/decrypt credentials
├── provider-catalog.mjs    ← static provider catalog
├── provider-store.mjs      ← DB CRUD for provider_connections
├── provider-test.mjs       ← testProviderApiKey()
├── settings-store.mjs      ← DB CRUD for key_value settings
├── locales/
│   ├── en.json             ← English strings (source of truth, 42+ locales)
│   ├── pt-BR.json          ← Portuguese (Brazil) — fully translated
│   └── {locale}.json       ← 40 additional locales (ar, az, de, es, fr, ja, zh-CN, …)
├── scripts/
│   └── generate-locales.mjs ← scaffold new locale files from config/i18n.json
└── commands/
    ├── setup.mjs
    ├── doctor.mjs
    ├── providers.mjs
    ├── config.mjs          ← includes `config lang get/set/list`
    ├── status.mjs
    ├── logs.mjs
    └── update.mjs

Key helpers

apiFetch(path, opts)api.mjs

All HTTP calls to the OmniRoute server must go through this wrapper.

import { apiFetch } from "./api.mjs";

const res = await apiFetch("/api/health");
if (!res.ok) await res.assertOk(); // throws ApiError with mapped exit code
const data = await res.json();

Options:

  • baseUrl — override base URL (default: OMNIROUTE_BASE_URL env or localhost:20128)
  • apiKey — override API key (default: OMNIROUTE_API_KEY)
  • method, body, headers — standard fetch options
  • timeout — per-attempt ms (default: 30000)
  • retryfalse to disable (default: enabled)
  • retryMax — total attempts (default: 3)
  • verbose — log retry attempts to stderr

withRuntime(fn, opts)runtime.mjs

Provides server-first / DB-fallback transparently.

import { withRuntime } from "./runtime.mjs";

await withRuntime(async (ctx) => {
  if (ctx.kind === "http") {
    const res = await ctx.api("/v1/providers");
    return res.json();
  }
  return ctx.db.prepare("SELECT * FROM provider_connections").all();
});
  • opts.requireServer = true — throws ServerOfflineError (exit 3) if offline
  • opts.preferDb = true — always use DB (skip server check)

t(key, vars)i18n.mjs

Internationalized strings. Catalog loaded from locales/{locale}.json.

import { t } from "./i18n.mjs";

console.log(t("common.serverOffline"));
console.log(t("setup.testFailed", { error: err.message }));

Locale detection order: OMNIROUTE_LANGLC_ALLLC_MESSAGESLANGen.

emit(data, opts)output.mjs

Format-aware output. Reads opts.output to select table/json/jsonl/csv.

import { emit, printError, EXIT_CODES } from "./output.mjs";

emit(providers, { output: opts.output ?? "table" });
printError("Something went wrong");
process.exit(EXIT_CODES.SERVER_OFFLINE);

Locale selection

The CLI displays text in the user's language. Detection order:

  1. --lang <code> flag on the command line
  2. OMNIROUTE_LANG environment variable
  3. System env: LC_ALLLC_MESSAGESLANG
  4. Fallback: en

Set permanently:

omniroute config lang set pt-BR       # saves to ~/.omniroute/.env
omniroute config lang list            # show all 42 available locales
omniroute config lang get             # show currently active locale

One-time override:

omniroute --lang de providers list    # run in German, not persisted
OMNIROUTE_LANG=ja omniroute status    # same effect via env

Adding a new locale: add entry to config/i18n.json, then run:

node bin/cli/scripts/generate-locales.mjs

Adding a new command

  1. Create bin/cli/commands/your-command.mjs
  2. Export registerYourCommand(program) following the Commander pattern
  3. Register in bin/cli/commands/registry.mjs
  4. Add strings to locales/en.json and locales/pt-BR.json
  5. Write test in tests/unit/cli-your-command.test.ts

See CONVENTIONS.md for exit codes, flag naming, output format, and destructive-action rules.