No description
  • TypeScript 91.4%
  • HTML 8.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-23 04:28:21 +02:00
.scratch fix(plan): warn instead of blocking closely spaced manual moves 2026-10-22 16:38:51 +02:00
.serena chore: enable Serena TypeScript analysis and refresh project configuration 2026-10-13 06:57:29 +02:00
docs feat(web): consolidate workspace density, layout flow, and coach dock 2026-10-23 03:48:40 +02:00
methodology feat(engine): support ultramarathon distances, unit preferences, and Koop methodology 2026-09-28 11:11:54 +02:00
prototype/intake feat(prototype): add the guided intake prototype 2026-09-21 12:05:17 +02:00
web fix(plan): render drag handles on plan schedule day sessions 2026-10-23 04:28:21 +02:00
workout-library feat(workouts): integrate curated prescriptions with generation and confirmed adaptations 2026-10-16 10:45:14 +02:00
.dockerignore fix(deploy): include workout authoring assets in the container build 2026-10-16 10:48:51 +02:00
.gitignore chore: ignore Serena cache directory 2026-09-28 11:11:18 +02:00
CONTEXT.md docs(workouts): record curated library decisions and release gates 2026-10-16 10:44:26 +02:00
README.md chore(deploy): update default port to 4720 across docker and docs 2026-10-22 05:55:40 +02:00

coach-sci

A personal, self-hosted running coach, built to sit beside Intervals.icu.

Intervals.icu owns the activities, the wellness data, and the calendar. Coach Sci owns the plan and the reviews: it takes a goal race and an athlete profile, instantiates a dated plan from a corpus of published methodology, writes that plan to the Intervals.icu calendar, reviews it weekly as a read-only check-in, and rewrites forward weeks on demand at an audit. The methodology comes from six books whose principles and module numbers are imported into a versioned index, so every prescription and every recommendation names the principle and the author behind it.

The full reasoning is in docs/v4-spec.md, which is decision-complete, and in the wayfinder map at .scratch/coach-sci/map.md, which traces every decision to the ticket that produced it. docs/backlog.md holds everything deferred past version four, and CONTEXT.md is the glossary.

What it does

  • Imports the methodology corpus out of local Markdown into an index of 81 principles and 54 modules, versioned by the hash of its content.
  • Runs a guided intake with one control per field, where free text only accelerates a field that code already found.
  • Instantiates a dated plan from the goal race, the athlete profile, and the methodology composition, with its blocks, its weekly volume band, and its taper.
  • Writes the plan to the Intervals.icu calendar under a deterministic uid in external_id, and adopts the events it already owns.
  • Shows a calendar-shaped plan page where the current week is the athlete sandbox and a move lands immediately, while forward weeks stay stable between audits.
  • Produces the weekly check-in as a read-only report under a strict schema. It never mutates the plan.
  • Runs the on-demand audit: a lever set with precedence tiers, where no lever schedules catch-up work, rewrites an elapsed week, changes a threshold silently, or raises volume past the ramp cap on an audit alone.
  • Splits the audit output into what is applied and what is proposed. The prohibited set, which is the goal race, the macro plan, any re-dating, and any threshold change, arrives as a proposal with an explicit confirm, and the diff is shown before the change lands, with the previous version retained and an undo available.
  • Detects a threshold disagreement between the live anchors and the plan snapshot, and proposes an update through a maximal-effort source, capped at 2 to 3 percent when the test is declined.
  • Runs the interrupt protocol for illness, injury, and travel across its three branches, with progression frozen for as long as it holds.
  • Keeps every number in deterministic code, sends bounded typed judgments to Jev (TypeSafe System One), and sends only prose to OpenAI. Version four publishes no finish-time prediction.
  • Serves one athlete behind one shared password, with no user accounts.

Stack

Next.js 16 (App Router) in TypeScript, React 19, Tailwind 4, Drizzle ORM, Postgres 17, deployed as one container. Bun is the runtime and package manager.

Develop locally

This path runs the app from source with hot reload, so it suits editing the code. To run the built app instead, use Deploy, which starts both containers.

Prerequisites: Bun and Docker.

cd web
cp .env.example .env      # fill in APP_PASSWORD and SESSION_SECRET; the provider keys are optional
docker compose up -d postgres
bun install
bun run db:migrate
bun run dev               # http://localhost:4720

db:up starts every service in the compose file, including the app container on host port 4720. For local development with bun run dev, start the postgres service as above.

The methodology index at web/src/lib/methodology/generated.ts is committed. bun run methodology:build regenerates it, and it is needed only after an edit to the Markdown corpus.

Environment variables

web/.env is gitignored. web/.env.example lists all of them. The contract is validated once at startup by web/src/lib/env.ts, so an incomplete environment stops the instance with the failing keys named and no value printed. The provider keys are feature gates: an absent key turns its feature off and leaves the rest of the app usable.

Variable Required Purpose
APP_PASSWORD Yes The shared password, at least 12 characters. It is the only gate on the instance.
SESSION_SECRET Yes Signs the session cookie, at least 32 characters.
DATABASE_URL Yes Postgres connection for the app. In compose this is set by the compose file.
INTERVALS_API_KEY For the platform Server-side only. Without it the Intervals reads and the calendar writes are off.
INTERVALS_ATHLETE_ID For the platform The athlete this instance coaches.
TYPESAFE_API_KEY For the judgments The bounded typed judgments behind the judgment port.
OPENAI_API_KEY For the narratives The check-in and audit prose. Without it an audit refuses to run rather than write its own text.
TEST_DATABASE_URL For the schema suite The database the schema suite migrates and asserts against. Without it that suite skips and the rest of the suite needs no database.

Tests

cd web
bun run test           # the default suite, no network call
bun run test:coverage  # the same suite with the coverage gate
bun run typecheck      # tsc --noEmit
bun run build          # production build

The default suite makes no network call. One suite, the schema suite, migrates a scratch database from TEST_DATABASE_URL and asserts the tables and the retired terms; it skips when that variable is absent, and everything else runs with no database at all.

The suite covers the engine, the methodology loader, the Intervals mapping and rate budget, the intake, the judgment contract, the check-in, the plan view, the settings, the audit, the threshold signature and review, the interrupt protocol, and the auth and environment modules. The coverage gate holds the pure functions and the deterministic mapping code at or above 85 percent on every metric, and pins the fully covered core at 100 percent branch coverage.

One live suite makes real network calls against Intervals.icu. It is skipped by default, excluded from the default run, and it creates and deletes its own calendar events:

bun run test:live      # sets RUN_LIVE_INTERVALS=1

Deploy

cd web
docker compose up -d --build

The image is built in two stages (oven/bun:1 to install and build, oven/bun:1-slim to run). The container applies migrations and then serves on container port 3000, published at http://localhost:4720, beside its own Postgres container on a persistent named volume. docs/deployment.md holds the full posture: the container table, the environment contract, the authentication model, a clean deploy, backup and restore, and the mobile and install notes.

Repository layout

  • web/ — the application. src/lib/ holds the deterministic core (engine, methodology, intake, judgment, check-in, plan, settings, audit, threshold), src/db/ the schema and the client, and src/app/ the screens and the two route handlers.
  • methodology/ — the corpus. principles/ and modules/ hold the Markdown, and README.md holds the schema.
  • prototype/ — a disposable prototype that answered whether the intake surface feels right. It is not the app and shares no code with it.
  • docs/ — the version four spec, the backlog, and the deployment document.
  • .scratch/ — the wayfinder map, its decision tickets, and the sixteen build tickets. A map is frozen once its destination is reached.

Status

The athlete has created a plan and is testing deployment and coach chat. The next milestone is acceptance of the complete coaching cycle, including confirmed changes, calendar delivery, performed-work review, and recovery. docs/release-readiness.md records the decision, success criteria, validation order, and evidence log. Release acceptance is pending. Deferred features are tracked in docs/backlog.md.