diff --git a/.env.example b/.env.example index c3b57fb..bc16929 100644 --- a/.env.example +++ b/.env.example @@ -148,8 +148,10 @@ RP_NAME=openGym # COACH_DISABLED=1 # # COACH_JOB_TIMEOUT_MS gives a job longer than the default five minutes. Only a -# local model on a CPU needs it (Ollama on a small box: ten minutes is normal); -# a hosted API that needs more has a problem. Never goes below one minute. +# local model on a CPU needs it — and normally only for the first request after +# the model server restarts (the api pre-warms the rules cache after that; a +# warm review on a 3B model takes about a minute). A hosted API that needs +# more has a problem. Never goes below one minute. # # COACH_JOB_TIMEOUT_MS=1500000 # diff --git a/docs/AI_COACH.md b/docs/AI_COACH.md index 1fff4e6..eb0c106 100644 --- a/docs/AI_COACH.md +++ b/docs/AI_COACH.md @@ -75,6 +75,33 @@ A key, a model and the account binding described below belong to the provider th entered for. Switching chips does not clear them: the Anthropic key is still there when you come back from trying Gemini, and each chip shows a mark when it holds one. +#### Picking and changing models + +The model field is never a guess: **List models** asks the endpoint what it actually serves. +For an Ollama box that means the admin decides what exists — `ollama pull` anything the +hardware can hold and it appears in the picker on the next refresh; nothing in openGym pins +you to a blessed list. The choice is remembered **per provider**, so trying a cloud model for +a week and coming back to the local one restores exactly what was set before. + +#### Performance on a small box + +The Coach's rules ride as a byte-identical system prompt, so a llama.cpp/Ollama endpoint can +keep them in its prefix cache and only ever re-process the payload — and the api warms that +cache itself at boot and every half hour, so the expensive first read happens off everyone's +clock. Measured on a 4-core, no-GPU VM with `qwen2.5:3b`: a review costs about **a minute** +warm, versus ~8 minutes before the cache and slimmer payload existed. Three things keep it +that way: + +- `OLLAMA_KEEP_ALIVE=-1` and `OLLAMA_NUM_PARALLEL=1` on the Ollama side — an unloaded model + takes its cache with it, and parallel slots split it. +- Give the container room. A ~3B model at Q4 lives happily in 4 GB; a 4B model squeezed into + the same limit does not fail, it *thrashes* — weights fall out of the page cache and + generation drops to ~1 token/s. On a 4–6 GB box, smaller and comfortable wins. +- The endpoint is sent a **JSON schema** with each request (structured outputs), so the shape + of the answer is enforced while it is generated and the repair round is rarely needed. + Servers that reject schemas get plain JSON mode automatically, then no JSON mode — the + validator is the gate either way. + ### With a runtime in the container (Claude Agent SDK, Codex CLI) **1. Build the image that has an AI runtime in it.** The default image deliberately has none: @@ -231,11 +258,12 @@ is a provider problem rather than a prompting problem, and a retry loop against is a bad way to find that out. A job is given five minutes by default, which is generous for any hosted API. A model running -on a CPU behind the compatible endpoint can need more — a 3B model with an 8k prompt takes ten -minutes on a small VM — so `COACH_JOB_TIMEOUT_MS` in `.env` raises it (never below one -minute); the api's own HTTP client waits as long as the job, and the chat says "this can take a -while" rather than promising minutes when the endpoint is a local one. The phone's BYOK mode -does the same on its own: a local endpoint gets 25 minutes there. +on a CPU behind the compatible endpoint can need more — with a warm cache a 3B model answers +in about a minute, but the first job after the model loads pays the full prompt once — so +`COACH_JOB_TIMEOUT_MS` in `.env` raises the budget (never below one minute); the api's own +HTTP client waits as long as the job, and the chat says "this can take a while" rather than +promising minutes when the endpoint is a local one. The phone's BYOK mode does the same on +its own: a local endpoint gets 25 minutes there. The Coach may only touch **routines and the week**. Your training log, your weigh-ins and your settings are not reachable from any change type that exists. diff --git a/frontend/src/admin.css b/frontend/src/admin.css index 98d307b..a1359da 100644 --- a/frontend/src/admin.css +++ b/frontend/src/admin.css @@ -110,3 +110,34 @@ } .adm-iconbtn{width:44px;height:44px;border-radius:12px;font-size:17px} .adm-empty{color:var(--label-3);font-size:13.5px;padding:10px 2px} + +/* ---------- the Coach before setup: a pitch, not a form ---------- */ +.adm-hero{display:flex;flex-direction:column;align-items:flex-start;gap:4px;padding:6px 2px 2px} +.adm-hero-av{ + width:52px;height:52px;border-radius:16px;display:grid;place-items:center;font-size:26px; + background:linear-gradient(135deg,var(--acc),color-mix(in srgb,var(--acc) 55%,var(--teal))); + color:var(--on-acc);margin-bottom:8px;box-shadow:0 8px 24px -8px color-mix(in srgb,var(--acc) 55%,transparent) +} +.adm-hero h2{margin:0 0 4px;font-size:22px;letter-spacing:-.022em} +.adm-hero p{margin:0 0 14px;font-size:14px;line-height:1.5;color:var(--label-2)} +.adm-hero-feats{display:grid;gap:10px;margin-bottom:18px} +.adm-hero-feats>div{display:flex;gap:11px;align-items:flex-start} +.adm-hero-feats .icn{color:var(--acc);font-size:18px;flex:none;margin-top:2px} +.adm-hero-feats span{font-size:13.5px;line-height:1.45;color:var(--label-2)} +.adm-hero-feats b{color:var(--label);font-weight:600} +.adm-hero .btn{width:100%} + +/* ---------- setup progress ---------- */ +.adm-progress{height:5px;border-radius:99px;background:var(--surface-2);overflow:hidden;margin:0 0 10px} +.adm-progress i{display:block;height:100%;border-radius:99px;background:var(--acc);transition:width var(--med) var(--ease)} + +/* ---------- provider chips: clearly idle vs. clearly chosen ---------- */ +.adm-chips .chip{ + background:var(--surface-2);border:1.5px solid transparent;color:var(--label); + font-weight:500;text-transform:none +} +.adm-chips .chip.on{background:var(--acc-soft);border-color:var(--acc);color:var(--acc);font-weight:600} +.adm-chips .chip:active{transform:scale(.97)} + +/* a finished step's summary reads as a receipt, not a control */ +.adm-step.done>summary .adm-step-t span{color:var(--acc)} diff --git a/frontend/src/index.css b/frontend/src/index.css index 9735d0e..80176b8 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -990,3 +990,21 @@ h4.sec{ .exmedia img{height:380px} .hm-wrap{display:flex;flex-direction:column;align-items:center} } + +/* ------------------------------------------------- the Coach entry on Plan -- */ +.coach-cta{ + display:flex;align-items:center;gap:13px;width:100%;text-align:left; + margin-bottom:12px;padding:14px 16px;border-radius:var(--r-card); + background:linear-gradient(135deg,var(--acc-soft),color-mix(in srgb,var(--acc) 6%,var(--surface))); + border:1px solid color-mix(in srgb,var(--acc) 35%,transparent); + transition:transform var(--fast),filter var(--fast) +} +.coach-cta:active{transform:scale(.985);filter:brightness(1.06)} +.coach-cta-av{ + width:42px;height:42px;border-radius:13px;flex:none;display:grid;place-items:center;font-size:21px; + background:var(--acc);color:var(--on-acc);box-shadow:0 6px 18px -6px color-mix(in srgb,var(--acc) 60%,transparent) +} +.coach-cta-t{flex:1;min-width:0;display:flex;flex-direction:column;gap:1px} +.coach-cta-t b{font-size:17px;font-weight:600;letter-spacing:-.015em;color:var(--label)} +.coach-cta-t span{font-size:13px;color:var(--label-2);line-height:1.35} +.coach-cta-chev{color:var(--acc);font-size:15px;flex:none} diff --git a/frontend/src/views/AdminCoach.jsx b/frontend/src/views/AdminCoach.jsx index 247a9e3..1ccb53f 100644 --- a/frontend/src/views/AdminCoach.jsx +++ b/frontend/src/views/AdminCoach.jsx @@ -110,9 +110,30 @@ export default function AdminCoach() { const step3Done = authed const step4Done = !!d.model const step5Done = !!testResult?.ok || !!d.lastSuccess - // Step numbers only count the steps this provider actually shows. + // Step numbers only count the steps this provider actually shows — and like any wizard, + // only the first unfinished step stands open; everything done folds to its summary line. + const flags = [step1Done, ...(needsEndpoint ? [step2Done] : []), ...(hasCredentialStep ? [step3Done] : []), step4Done, step5Done] + const doneCount = flags.filter(Boolean).length + const firstTodo = flags.indexOf(false) let n = 1 + let idx = 0 const num = () => n++ + const stepAt = () => { const i = idx++; return { open: i === (firstTodo === -1 ? -1 : firstTodo), key: i + ':' + (i === firstTodo) } } + + // Off = a quiet, optional feature: one clean pitch and one button, no half-dimmed controls. + if (!d.enabled) return
An optional coach that designs training plans and reviews what people actually log. Off right now — nobody sees it anywhere in the app.
+/v1, no key in the URL.Separate from the read-only bridge above, openGym has an optional AI Coach that can - design a training plan and, later, review what you actually logged and propose changes to - it. Answer a few questions — goal, days a week, session length, equipment, anything to work - around — and it builds a week of routines. Every suggestion carries the evidence behind it, - you approve or reject each one, and you can undo the last set of changes.
-It is off by default. An admin turns it on in Settings → Admin → AI Coach, - picks a provider and pastes a key: Anthropic, OpenAI, Google Gemini, or - any OpenAI-compatible endpoint — Ollama or LM Studio on your own LAN, vLLM, - OpenRouter. These speak plain HTTPS and need nothing beyond the default image. Only the - Claude Agent SDK and the Codex CLI need the bigger build:
-API_TARGET=coach docker compose up -d --build api
- On the phone app, Settings → AI Coach offers two ways in: pair the phone with your - self-hosted instance and the Coach runs there, or bring your own API key and the phone calls - the provider directly, key in the platform's secure storage.
-It runs on your server under your account — there is no openGym - service in the middle, and nothing is sent anywhere until you ask it for something. What - leaves the server is a by-name allowlist (your plan, your logged sets, body weight if you - track it) under a pseudonym; your name, sign-in details and other profiles never do. What - comes back can only touch routines and your weekly schedule, and is applied on your device - after you approve it.
-The Coach is not a doctor or a physiotherapist. If something hurts, ask a professional. - Full details, including exactly what is sent and how credentials are stored: +
Separate from the read-only bridge above, openGym has an optional AI Coach. Answer a + few questions — goal, days a week, session length, equipment, anything to work around — and + it designs a week of routines. Later it reviews what you actually logged and proposes + changes; you can also ask it to look at one workout (a debrief: a score, what went + well, what to watch, what to do next time) or to improve a single routine and leave + the rest alone. If the admin allows it and at least three people opt in, it can show + anonymous medians so you can see how you sit against the others on your instance.
+ +The Coach is a chat. The first visit is a short intake, one question per screen; after + that, every request works the same way:
+It is off by default. An admin turns it on in Settings → Admin → AI Coach and + picks who answers:
+| Anthropic, OpenAI, Google Gemini | Paste an API key from the provider's console. Plain HTTPS from the api process — runs on the default image. |
| OpenAI-compatible endpoint | Any server that speaks the Chat Completions API: Ollama, LM Studio, vLLM, OpenRouter, a gateway of your own. A key only if the endpoint wants one. Also the default image. |
| Claude Agent SDK / Codex CLI | Run a real AI runtime inside the container — the one case that needs the bigger build: API_TARGET=coach docker compose up -d --build api |
A model on your own hardware is just the compatible endpoint with no key. The usual way is + an Ollama container next to openGym:
+# docker-compose.yml — add next to the openGym services (same file = same network)
+ ollama:
+ image: ollama/ollama
+ restart: unless-stopped
+ volumes:
+ - ./data/ollama:/root/.ollama
+ environment:
+ - OLLAMA_KEEP_ALIVE=-1 # keep the model (and its prompt cache) loaded
+ - OLLAMA_NUM_PARALLEL=1
+ mem_limit: 4g
+ docker exec -it <ollama container> ollama pull qwen2.5:3b
+ Then in Settings → Admin → AI Coach: provider OpenAI-compatible endpoint →
+ Base URL http://ollama:11434 → List models → pick the model →
+ Test the Coach. That's the whole setup.
Any model you can pull, you can use. ollama pull whatever you like and
+ it appears under List models — the admin is free to run anything the box can hold,
+ and each provider remembers its own model choice, so switching around never loses one.
+ Honest sizing, from measuring exactly this on a small box:
qwen2.5:3b) fits a 4–6 GB container and
+ answers a review in about a minute on a 4-core CPU once its cache is warm.COACH_JOB_TIMEOUT_MS
+ in .env.A GPU machine elsewhere on your LAN works the same way: run Ollama or LM Studio there and
+ point the Base URL at it, e.g. http://192.168.1.50:11434.
Settings → AI Coach offers two ways in: pair the phone with your self-hosted + instance and the Coach runs there under the rules above, or bring your own API key and the + phone calls the provider directly — same allowlist, same validator, key in the platform's + secure storage, ten runs a day.
+ +Before anyone uses it, a consent screen lists exactly which categories of data leave the
+ server — generated from the same module that builds the payloads, so it cannot drift from
+ what actually happens. The admin can cap runs per person and per instance per day, and
+ COACH_DISABLED=1 in the environment switches the feature off harder than any
+ toggle. The Coach is not a doctor or a physiotherapist — if something hurts, ask a
+ professional. Full details, including exactly what is sent and how credentials are stored:
docs/AI_COACH.md.