Skip to main content

@ai-coach/domain

The rules of learning. This package decides what counts as a good explanation, when a round is over, what a pass means and when you'll see an idea again. If you want to change how the coach behaves (how many follow-ups it allows, what counts as copying, how the review schedule grows), this is usually the place.

What it does not do​

  • No I/O, ever. No files, network, clock or Node built-ins; lint enforces it. Dates come in as YYYY-MM-DD strings.
  • No models and no prompts. Models live in the adapters; the rules here hold whatever a model says, so a model can't talk its way past them (the judge's "pass" is overruled when flaws remain).
  • No dependencies. It imports no other workspace package and no npm package.

Architecture fit​

  • Scope: scope:coach
  • Style: architecture:hexagonal (type:domain)
  • Depends on: nothing
  • Used by: @ai-coach/application, @ai-coach/cli, @ai-coach/adapter-ollama, @ai-coach/adapter-gemini, @ai-coach/adapter-local-state, @ai-coach/adapter-vault-mcp
[cli] ──▶ [application use cases] ──▶ [@ai-coach/domain]
[adapters] ─────────────────┘

Internal architecture & rules​

  • One folder per CLI stage under src/lib/, the same split as coach source, learn, exam and teach, each re-exported through its own index.ts:
    • source/ — splitting a chapter into pages and telling a note from a quote (read), reading your bolds, highlights and summaries and checking a concept note before it's written (synthesis), and the structure rules for groups and "builds on" lines (group).
    • learn/ — a generate attempt and its marks (generate), the why, connect and apply answers and their follow-ups (elaborate), and working through a failed round's gaps (study-round).
    • exam/ — the tunable sparring rules, one Tier 1 round, free recall, the judge's verdict rule, what the judge may see (tier2-payload) and the review ladder.
    • teach/ — the scripted student, its misconception and the teach verdict.
    • shared/ — errors, text checks (buzzwords, copying), shared vocabulary, the coaching styles and the climb's seven steps.
  • Stages depend only on shared/, never on each other. Inside a folder, import siblings directly, never the folder's own index.ts.
  • Broken rules throw DomainError with a message you can show the learner as is (a ladder with no steps, a concept note with seven assertions, an empty buzzword).
  • The defaults are what users get. DEFAULT_SPARRING_RULES and DEFAULT_LADDER apply unless the configuration says otherwise.
  • No comments in source code (DEC-AIC-0011).

Public surface​

  • Exam — sparringRules, DEFAULT_SPARRING_RULES, SparringRound, enforceVerdict, tier2Payload, scheduleReview, DEFAULT_LADDER, freeRecallQuestion.
  • Learn — attempt, checkMarks, nextFollowUp, elaborationProblem, StudyRound.
  • Source — readingNote, summaryProblem, extractMarks, conceptDraft, structureProblems.
  • Teach — TeachingLesson, misconceptionProblem.
  • Shared — findBuzzwords, quotesSource, COACHING_STYLES, STYLE_GUIDES, CLIMB_STEPS, DomainError.
import {
scheduleReview,
findBuzzwords,
DEFAULT_BUZZWORDS,
} from '@ai-coach/domain';

scheduleReview({
tier: 1,
verdict: 'pass',
gaps: 0,
date: '2026-10-25',
tier2History: [],
});
// → { nextReview: '2026-10-28', intervalDays: 3, rung: -1 }

findBuzzwords('It just works, seamlessly.', DEFAULT_BUZZWORDS);
// → ['seamlessly', 'just works']

Terms such as spar, the climb and coaching style are in the glossary.

How to extend it​

  1. Put the rule in the folder of the stage that uses it, or in shared/ if several stages do, and export it from that folder's index.ts.
  2. Throw DomainError for input that breaks the rule, with a message fit to show the learner.
  3. Add a spec next to the rule covering normal and edge cases.
  4. Run npm exec nx test @ai-coach/domain and npm exec nx lint @ai-coach/domain.

Running & testing​

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

The specs are plain Vitest unit tests on strings and objects; nothing touches the disk or network.

Key ADRs​