@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 judgeforgets which sessions are still waiting. - No vault access. It never touches your vault folder.
- Only
zodand 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(thePendingJudgementsandClockports),@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:
stateDirfrom 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— thePendingJudgementsport:list,addandremovesessions waiting for the judge.SystemClock— theClockport;--today YYYY-MM-DDon the command line makes it pretend another day.localDate— today's date asYYYY-MM-DDin local time.
stateDir and --today are described in the configuration guide.
How to extend it
- Change the port in
@ai-coach/applicationfirst. - Implement it in
src/lib/local-state.ts, keeping the one-step file replace. - Cover it in a spec against a temporary state directory.
- Run
npm exec nx test @ai-coach/adapter-local-stateandnpm 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.