@ai-coach/application
The things you can do with the coach, written once and independent of any model, vault or screen. Each command you type maps to one use case here. A use case says what it needs ("something that can read notes", "a sparring partner", "a judge") as an interface called a port; adapters provide the real implementations and the cli plugs them in. You change this package when a command's flow changes.
What it does not do
- No I/O. No Node built-ins, no SDKs, no files, network or clock. Lint enforces it; anything touching the outside world is a port.
- No learning rules. What a pass, a gap or a review date means lives in
@ai-coach/domain; use cases call those rules. - No adapters and no
scope:vault. Nx boundaries lettype:applicationdepend only on domain, application and util libraries.
Architecture fit
- Scope:
scope:coach - Style:
architecture:hexagonal(type:application) - Depends on:
@ai-coach/domain - Used by:
@ai-coach/cliand everyadapter-*package (which implement its ports)
[cli command] ──▶ [use case] ──▶ domain rules
│
└──▶ ports ◀── adapter-vault-mcp · adapter-ollama · adapter-gemini · adapter-local-state
Internal architecture & rules
- One folder per CLI command group under
src/lib/, the same split as thecliand@ai-coach/domain:source/(Reading,Synthesizing,Grouping),learn/(Generating,Elaborating,Studying),exam/(Review,Sparringand its conversation,Judging),teach/(Teaching),progress/(Climbing) andvault/(Filing). Each use case takes its ports in its constructor, and each folder is re-exported through its ownindex.ts. shared/holds the errors, the note-history helpers andfindBook. Every folder depends only onshared/andports/, never on another command group.- Ports live in
src/lib/ports/, grouped by who provides them:vault.ts,library.ts,models.ts,state.ts. - Errors are user-ready. All errors extend
ApplicationErrorwith a message you can show as is; most use cases fall back sensibly onUnusableReplyErrorinstead of ending your session. - Preview before write. Use cases plan a change, show it, and execute only after confirmation, passing the vault's version hashes back.
- The judge sees only the Tier 2 payload. Judging builds it from the vault and refuses to send it if it doesn't match what was recorded (
PayloadMismatchError). - Test fakes mirror the ports.
src/testing/holds in-memory fakes split likeports/:vault.ts(InMemoryVault),library.ts(InMemoryLibrary),models.ts(scripted partners, judge and classifier) andstate.ts(InMemoryPending,FixedClock), re-exported throughindex.ts. They're for specs only and aren't part of the build. - No comments in source code (DEC-AIC-0011).
Public surface
- Use cases —
Review(coach due,list),Sparring,Judging,Studying,Synthesizing,Climbing,Generating,Elaborating,Grouping,Reading,Teaching, andFiling(coach file,capture,archive,init). The commands guide describes what each command does. - Ports —
NotesRepository,SessionLog,VaultFiling,Library(provided byadapter-vault-mcp);SparringPartner,StudyPartner,StyleClassifier,SynthesisPartner,ElaborationPartner,StructurePartner,TeachPartner(adapter-ollama);Judge(adapter-gemini);PendingJudgements,Clock(adapter-local-state). - Errors —
UnavailableError,UnusableReplyError,VaultRefusedError,NotFoundError,NotSparrableError,ChallengeLeakError,PayloadMismatchError,ContextTooSmallError.
import { Studying } from '@ai-coach/application';
const studying = new Studying({
notes: vault,
partner: studyPartner,
classifier,
rules,
});
const { note, session } = await studying.open(path);
How to extend it
- Describe what the use case needs as a port method in the matching file under
src/lib/ports/. - Write the flow in the folder of the command group that runs it, calling domain rules for every decision and ports for every effect.
- Add the method to the matching fake in
src/testing/and cover the flow in a spec next to the use case. - Run
npm exec nx test @ai-coach/applicationandnpm exec nx lint @ai-coach/application, then implement the port in its adapter.
Running & testing
npm exec nx test @ai-coach/application
npm exec nx lint @ai-coach/application
npm exec nx typecheck @ai-coach/application
npm exec nx build @ai-coach/application
Specs run with Vitest against the in-memory fakes in src/testing/, so they need no model, vault or network.
Key ADRs
- DEC-AIC-0008 — use cases and ports in a hexagonal layer enforced by Nx boundaries.
- DEC-AIC-0004 — only the Tier 2 payload leaves the machine.
- DEC-AIC-0009 — every write is previewed before it runs.
- DEC-AIC-0010 — each layer is tested with fakes instead of real services.