Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Coach: a way in, and instructions for getting there

Alex4ee9a2abbf18
diff --git a/docs/AI_COACH.md b/docs/AI_COACH.md
index 61f4ff873..1865a0e69 100644
--- a/docs/AI_COACH.md
+++ b/docs/AI_COACH.md
@@ -3,12 +3,56 @@
An optional AI that **designs** a training plan and **revises it from what you actually log**,
running on your own server under your own provider account, off until an admin turns it on.
-> This document grows with the feature. What is described here is what has landed: the server
-> plumbing, the consent and payload boundary, the credential model, the validator and apply
-> path, and the Claude provider with its opt-in packaging. The UI arrives in the PRs that follow.
+> This document grows with the feature, which lands across a sequence of PRs. Anything described
+> here that has not reached your instance yet is visibly absent rather than broken — the Coach
+> only appears at all once an admin has enabled it and a runtime can be reached.
---
+## Turning it on
+
+Nothing here is an environment variable or a restart — the whole point of the admin card is that
+enabling the Coach is a decision you make in the app.
+
+**1. Build the image that has an AI runtime in it.** The default image deliberately has none:
+
+```bash
+API_TARGET=coach docker compose up -d --build api
+```
+
+`--build` matters. With a prebuilt `image:` also set, compose would otherwise pull the default.
+
+**2. Get a credential.** On a trusted machine where you already use Claude Code:
+
+```bash
+claude setup-token
+```
+
+Complete its normal browser sign-in and copy the token it prints. openGym never opens or handles
+that flow — it only ever receives the finished token.
+
+**3. Connect it.** In the app: **Settings → Admin → AI Coach**.
+
+- Toggle the card on.
+- Pick the **Claude (Anthropic)** provider chip.
+- **Add CLI token** → paste the token, and optionally label whose account it is (that label is
+ what both the admin card and each user's Coach screen show when they name the account).
+- **Test the Coach** — a real round trip through the provider with no user data anywhere near it.
+ It reports the runtime version on success, and the provider's own error on failure.
+
+The card also states two things worth reading before anyone uses it: whether jobs actually run
+unprivileged, and which account is being spent.
+
+**4. Use it.** Each person opens **Plan → AI Coach**, agrees to the consent screen — which lists
+exactly what leaves the server, generated from the same module that builds payloads — and then
+either has a plan built from a short intake or asks for a review of what they have logged.
+
+> **On a multi-profile instance, read [Whose account pays](#whose-account-pays) first.** In the
+> default instance mode the credential binds to the first profile that spends it and **every
+> other profile is refused**, by design. That is the right behaviour when one person's personal
+> subscription is behind it — but on a shared box it means one user gets the Coach and the rest
+> get a refusal until per-profile sign-in exists.
+
## Whose account pays
This is the first thing to settle, because it decides what the rest of the feature is allowed
diff --git a/frontend/src/views/Plan.jsx b/frontend/src/views/Plan.jsx
index b35f5c517..e62a27f89 100644
--- a/frontend/src/views/Plan.jsx
+++ b/frontend/src/views/Plan.jsx
@@ -4,13 +4,24 @@ import { DAYN, uid, exCount } from '../lib/format.js'
import { t } from '../lib/i18n.js'
import { dayAssignSheet, loadStarterPlan, planToolsSheet } from '../sheets.jsx'
import Icon from '../components/Icon.jsx'
-import { Button } from '../components/ui.jsx'
+import { Button, Row } from '../components/ui.jsx'
import { glyphOf, DEFAULT_GLYPH } from '../lib/glyphs.js'
+import { DEMO } from '../lib/demo.js'
+import { MOBILE } from '../lib/mobile.js'
+import { coachAvailable } from '../lib/coach.js'
export default function Plan() {
const nav = useNavigate()
const S = useStore(s => s.S)
const update = useStore(s => s.update)
+ const config = useStore(s => s.config)
+ const user = useStore(s => s.user)
+
+ /* The Coach's only entry point in the app. Its screens have existed since the UI landed and
+ nothing linked to them, so the feature was reachable only by typing the URL — enabled,
+ configured, and invisible. The same predicate every other Coach surface uses gates it, so
+ an instance without the feature sees exactly the Plan screen it saw before. */
+ const showCoach = coachAvailable(config, user, { demo: DEMO, mobile: MOBILE })
const addRoutine = () => {
const r = { id: uid(), name: t('New routine'), emoji: DEFAULT_GLYPH, ex: [] }
@@ -23,6 +34,13 @@ export default function Plan() {
<div><h1>{t('Plan')}</h1><div className="sub">{t('Your weekly routine')}</div></div>
<button className="iconbtn" onClick={planToolsSheet} aria-label={t('Share your plan')} title={t('Share your plan')}><Icon name="upload" /></button>
</div>
+ {showCoach && <div className="list" style={{ marginBottom: 10 }}>
+ <Row icon="sparkles" iconTint="var(--acc)" accessory="chevron"
+ title={t('AI Coach')}
+ subtitle={t('Build a plan, or have it reviewed against what you actually logged.')}
+ onClick={() => nav('/coach')} />
+ </div>}
+
<div className="cols"><div>
<h4 className="sec">{t('Week schedule')}</h4>
<div className="list" style={{ display: 'flex', flexDirection: 'column' }}>