Skip to main content

@ai-coach/cli

The terminal entry point and composition root for coach. It loads your configuration, wires the real adapters into the application use cases, and drives interactive coaching sessions in the terminal. Touch this package when you change command-line flags, terminal prompts, or how commands are registered.

What it does not do​

  • No coaching rules or scheduling logic. Review intervals, mastery rules, and session state live in @ai-coach/domain and @ai-coach/application.
  • No direct vault file I/O or LLM calls. The CLI reaches your vault only through @ai-coach/adapter-vault-mcp, local models through @ai-coach/adapter-ollama, and the online judge through @ai-coach/adapter-gemini.
  • No cross-scope or unapproved external imports. Enforced by Nx/ESLint: scope:coach cannot import scope:vault or scope:vault-view, and app:cli only allows zod and node:* external imports.

Architecture fit​

  • Scope: scope:coach
  • Style: architecture:hexagonal (type:app, app:cli)
  • Depends on: @ai-coach/domain, @ai-coach/application, @ai-coach/adapter-ollama, @ai-coach/adapter-gemini, @ai-coach/adapter-vault-mcp, @ai-coach/adapter-local-state
  • Used by: Terminal users invoking the coach binary
[Terminal user] ──▶ [@ai-coach/cli] ──▶ [@ai-coach/application] ──▶ [@ai-coach/domain]
│
├──▶ [@ai-coach/adapter-vault-mcp]
├──▶ [@ai-coach/adapter-ollama]
├──▶ [@ai-coach/adapter-gemini]
└──▶ [@ai-coach/adapter-local-state]

Internal architecture & rules​

  • Domain-grouped registry: DOMAINS in src/lib/cli.ts is the single source of truth for command dispatch, domain-scoped help (coach help <domain>), and full --help output. Flat short aliases (such as coach spar, coach read, coach climb) resolve through the same registry. Commands declare whether they require a composed Coach instance (needsCoach: false for vault view).
  • One module per command, grouped by domain: Commands live under src/lib/commands/<domain>/<command>.ts across six domains (progress, source, learn, exam, teach, vault) with colocated *.spec.ts tests.
  • Shared terminal helpers (src/lib/terminal/): Pure terminal primitives with zero dependency on Coach — raw I/O and colors (io.ts), interactive prompts and UsageError (prompts.ts), and pure string formatters (format.ts).
  • App wiring (src/lib/): config.ts loads and validates configuration, and composition.ts wires adapters into use cases with AdapterOverrides so tests can inject fakes. Vault filing previews (previewThenApply, showFilingPlan) live with the vault commands in src/lib/commands/vault/filing.ts.
  • Preview before write & exit codes: Every vault or session write previews its plan and asks for confirmation. CLI argument errors exit 2; known domain, application, usage, config, or offline errors print cleanly and exit 1. Source code carries no comments (DEC-AIC-0011).

Public surface​

  • Progress (coach progress / coach climb): cross-stage overview tracking the seven-step climb across source, learn, exam, and teach.
  • Source (coach source): read, synthesize, group — take in books or articles, distill concept notes, and group concepts.
  • Learn (coach learn): generate, elaborate, study — actively encode concepts and close failed gaps.
  • Exam (coach exam): due, list, spar, judge — inspect due notes, run offline Tier 1 sparring, and run online Tier 2 judging.
  • Teach (coach teach): teach <note> — prove mastery by teaching a naive student and optionally saving a guideline.
  • Vault (coach vault): capture, file, archive, init, view — organize PARA folders and open the browser graph view.
  • Programmatic entry points: run, DOMAINS, COMMANDS, USAGE, formatDomainUsage, composeCoach, loadConfig, Terminal, ProcessTerminal, UsageError.

See the commands guide and configuration guide for full references.

How to extend it​

  1. Create src/lib/commands/<domain>/<name>.ts using shared helpers from src/lib/terminal/, and export it from src/lib/commands/index.ts.
  2. Add a CommandSpec entry under the matching domain in DOMAINS inside src/lib/cli.ts so dispatch, domain help, and --help output stay in sync.
  3. Add a colocated src/lib/commands/<domain>/<name>.spec.ts using a scripted Terminal and stubbed Coach use cases.
  4. Run npm exec -- nx run-many -t lint typecheck test build -p @ai-coach/cli and update commands.md if the user-facing surface changed.

Running & testing​

From the repository root, after building (npm run coach loads .env from the root):

npm run coach -- <domain> <command> [options]

npm run coach # show what is due today (coach exam due)
npm run coach -- source read # read a chapter and take notes
npm run coach -- exam spar --style devil # spar due notes in devil's-advocate style
npm run coach -- progress # inspect the seven-step climb across all stages

See the commands guide for the full command and option reference.

npm exec nx lint @ai-coach/cli
npm exec nx typecheck @ai-coach/cli
npm exec nx test @ai-coach/cli
npm exec nx build @ai-coach/cli

Tests drive commands with a scripted Terminal and stubbed use cases, so they need no vault, Ollama, or Gemini.

Key ADRs​

  • DEC-AIC-0008 — Enforces hexagonal boundaries so the CLI acts as the sole composition root for scope:coach.
  • DEC-AIC-0009 — Establishes the terminal interface and the preview-before-write rule for all mutations.
  • DEC-AIC-0051 — Places @ai-coach/cli in apps/ with scope:coach, architecture:hexagonal, and type:app tags.
  • DEC-AIC-0060 — Defines the eight-section architectural README format and Docusaurus link rules.