Skip to main content

@ai-coach/adapter-local-state

ai-coach's own small memory, kept outside your vault. Sparring works offline but judging needs the internet, so after each sparring session ai-coach notes that the session is waiting for the judge; the next coach judge picks up everything still waiting. This package also tells the coach what day it is. You change it when that local state changes.

What it does not do​

  • No progress or history. Verdicts, gaps and review dates live in the vault's session history; deleting this package's file only means coach judge forgets which sessions are still waiting.
  • No vault access. It never touches your vault folder.
  • Only zod and Node built-ins. Nx boundaries (adapter:local-state) forbid any other external import.

Architecture fit​

  • Scope: scope:coach
  • Style: architecture:hexagonal (type:adapter, adapter:local-state)
  • Depends on: @ai-coach/application (the PendingJudgements and Clock ports), @ai-coach/domain
  • Used by: @ai-coach/cli, in its composition root
[Sparring] ──add──▶ FilePendingJudgements ──▶ pending-judgement.json
[Judging] ──list/remove──┘
[use cases] ──today──▶ SystemClock (or --today)

Internal architecture & rules​

  • One file, src/lib/local-state.ts, with both classes.
  • Where the file lives: stateDir from your configuration, else $XDG_STATE_HOME/ai-coach/, else ~/.local/state/ai-coach/. It's a small readable JSON file: { "sessions": [{ "sessionId", "date", "coachIds" }] }.
  • Writes are safe. The file is replaced in one step, so an interrupted run can't leave it half-written, and a damaged file is reported instead of guessed at.
  • No comments in source code (DEC-AIC-0011).

Public surface​

  • FilePendingJudgements — the PendingJudgements port: list, add and remove sessions waiting for the judge.
  • SystemClock — the Clock port; --today YYYY-MM-DD on the command line makes it pretend another day.
  • localDate — today's date as YYYY-MM-DD in local time.

stateDir and --today are described in the configuration guide.

How to extend it​

  1. Change the port in @ai-coach/application first.
  2. Implement it in src/lib/local-state.ts, keeping the one-step file replace.
  3. Cover it in a spec against a temporary state directory.
  4. Run npm exec nx test @ai-coach/adapter-local-state and npm exec nx lint @ai-coach/adapter-local-state.

Running & testing​

npm exec nx test @ai-coach/adapter-local-state
npm exec nx lint @ai-coach/adapter-local-state
npm exec nx typecheck @ai-coach/adapter-local-state
npm exec nx build @ai-coach/adapter-local-state

The specs use a temporary directory, never your real state folder.

Key ADRs​

  • DEC-AIC-0002 — sparring is offline and judging online, so sessions wait in this queue until judged.
  • DEC-AIC-0007 — progress lives in the vault's history, not in local state.
  • DEC-AIC-0051 — adapters implement application ports behind Nx boundaries.