qianwen-cli Architecture

@qianwenai/qianwen-cli — dual-mode Node CLI (REPL + one-shot)

qianwen-cli — local Node ≥18 process (bundled ESM binary) auth + credentials (encrypted at rest) User Terminal · CI · Agent bin/qianwen.ts dual-mode entry REPL ↔ one-shot Presentation View-models · Output · UI (Ink) pure / no I/O Commands Commander action handlers 9 domains Services createServices() root shared per run API layer base-client → api-client → cli-facade Backend API cli.qianwenai.com flat-parameter Model CDN alioth.alicdn.com OAuth Device Flow t.qianwenai.com Auth gate auth/credentials.ts ensureAuthenticated Credential store keychain · crypto-store Config ~/.qianwen flat-parameter render ensureAuth device flow model-map Legend External Frontend Backend Cloud Security Database

Dual-mode entry

  • • No-arg invocation → Ink REPL (src/repl.ts)
  • • Args → one-shot, ANSI-free for pipes / CI / agents
  • • Mode tracked in utils/runtime-mode.ts (isReplMode())

Layered flow

  • • commands → services → api → backend (no skipped layers)
  • • createServices() is the single composition root, built once per run
  • • Sub-services shared so caches (FreetierService quota) survive across calls

Auth & credentials

  • • OAuth Device Flow via auth/login-flow.ts
  • • OS keychain storage with encrypted-file fallback (no native binding)
  • • ensureAuthenticated() gates every API call before transport

Protocol & output

  • • Flat-parameter protocol: product + action constants in types/api-routes.ts
  • • Wire-format adapters in api/adapters/ → domain types in types/
  • • Format priority: --format → config → TTY (table | JSON); stable { error: { code, message, exit_code } }