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.

Intake consent also records the provider it names

Duarte Santosb3507bf6eb83
diff --git a/docs/AI_COACH.md b/docs/AI_COACH.md
index 07d03e660..9fb5ce677 100644
--- a/docs/AI_COACH.md
+++ b/docs/AI_COACH.md
@@ -266,7 +266,8 @@ Before the first request that would send anything to an AI provider, the app ask
that names the provider (OpenAI, Anthropic, Google Gemini, or the host of a compatible endpoint),
lists what goes there (the categories above plus whatever you type to the Coach) and says whether
it goes straight from the phone with your key or through your openGym server to the provider its
-admin picked. "Not now" sends nothing. The answer is kept on that device, per provider and host
+admin picked. "Not now" sends nothing. The intake's own consent screen names the same provider
+and list, so agreeing there counts as this yes and a first-timer is asked once. The answer is kept on that device, per provider and host
(`frontend/src/lib/coach-consent.js`), so pointing the Coach somewhere else asks again; the Coach
menu's **AI data sharing** (and Settings → AI Coach on the phone) lists what was allowed and takes
it back. Switching on automatic reviews asks too, and withdrawing the server's provider switches
diff --git a/frontend/src/views/CoachIntake.jsx b/frontend/src/views/CoachIntake.jsx
index 9c59a12e5..fcff2ceae 100644
--- a/frontend/src/views/CoachIntake.jsx
+++ b/frontend/src/views/CoachIntake.jsx
@@ -16,7 +16,8 @@ import { t } from '../lib/i18n.js'
import { DAYN } from '../lib/format.js'
import { EXDB } from '../lib/exercises.js'
import { emptyCoach, coachAvailable, hasConsent, CONSENT_VERSION, CATEGORY_TEXT, appendChat } from '../lib/coach.js'
-import { requestPlan, disclosure, JOB_ERRORS, isDeclined } from '../lib/coach-api.js'
+import { requestPlan, disclosure, JOB_ERRORS, isDeclined, coachVia } from '../lib/coach-api.js'
+import { consentTarget, allowAi } from '../lib/coach-consent.js'
import { DEMO } from '../lib/demo.js'
import { MOBILE } from '../lib/mobile.js'
import { activeProfile } from '../lib/equipment.js'
@@ -89,7 +90,13 @@ export default function CoachIntake() {
const next = () => (last ? finish() : setStep(step + 1))
const back = () => (step ? setStep(step - 1) : nav(editing ? '/coach' : '/plan'))
- const agree = () => {
+ const agree = info => {
+ // This screen just named the provider and listed what goes there, which is the question the
+ // data-sharing sheet asks before the first request (lib/coach-api.js ensureAiConsent). The
+ // yes counts for that provider and host too, so a first-timer is asked once, not twice.
+ // Only when the disclosure arrived: a screen that could not say where to is not a yes to it.
+ const target = !DEMO && consentTarget(info, coachVia())
+ if (target && !target.local) allowAi(target).catch(() => {})
update(s => { s.coach = { ...(s.coach || emptyCoach()), consent: { agreedAt: new Date().toISOString(), version: CONSENT_VERSION } } })
if (reconsentOnly) nav('/coach', { replace: true })
else setStep(step + 1)
@@ -255,7 +262,7 @@ function Consent({ onAgree, onDecline }) {
useEffect(() => { disclosure().then(setInfo).catch(() => {}) }, [])
const who = info?.payer === 'you'
? t('Sent straight to {0} with your own API key. You pay for every request.', info.host || info.providerLabel)
- : t('Sent to {0}, running on this server under the instance owner’s account.', info?.providerLabel || config?.coach?.providerLabel || t('the configured AI provider'))
+ : t('Sent to {0}, running on this server under the instance owner’s account.', (info?.provider === 'compatible' && info.host) || info?.providerLabel || config?.coach?.providerLabel || t('the configured AI provider'))
return <>
<div className="ob-eyebrow">{t('Before we start')}</div>
<h1 className="ob-h">{t('Meet the Coach')}</h1>
@@ -273,7 +280,7 @@ function Consent({ onAgree, onDecline }) {
<div style={{ color: 'var(--yellow)' }}>{t('The Coach is not a doctor or a physiotherapist. If something hurts, ask a professional.')}</div>
</div>
<div className="ob-foot" style={{ flexDirection: 'column' }}>
- <Button variant="primary" onClick={onAgree}>{t('I understand, let’s go')}</Button>
+ <Button variant="primary" onClick={() => onAgree(info)}>{t('I understand, let’s go')}</Button>
<Button onClick={onDecline}>{t('Not now')}</Button>
</div>
</>
diff --git a/frontend/src/views/CoachIntake.test.jsx b/frontend/src/views/CoachIntake.test.jsx
index 05cf99b97..cdf202bfa 100644
--- a/frontend/src/views/CoachIntake.test.jsx
+++ b/frontend/src/views/CoachIntake.test.jsx
@@ -17,6 +17,7 @@ import CoachIntake from './CoachIntake.jsx'
import { requestPlan, disclosure } from '../lib/coach-api.js'
import { CONSENT_VERSION, CATEGORY_TEXT } from '../lib/coach.js'
import { setLang } from '../lib/i18n.js'
+import { consentTarget, hasAiConsent, aiConsents, _resetAiConsent } from '../lib/coach-consent.js'
globalThis.IS_REACT_ACT_ENVIRONMENT = true
@@ -51,6 +52,7 @@ vi.mock('../lib/coach-api.js', () => ({
disclosure: vi.fn(() => Promise.resolve(null)),
JOB_ERRORS: { busy: 'the app’s busy line' },
ensureAiConsent: vi.fn(() => Promise.resolve(true)),
+ coachVia: () => 'server',
isDeclined: e => e?.code === 'declined',
}))
vi.mock('../coach.css', () => ({}))
@@ -144,6 +146,42 @@ describe('CoachIntake — the consent screen', () => {
expect(all('.ob-dot')).toHaveLength(7)
})
+ it('agreeing is also the yes for the provider it names, so the data-sharing sheet does not ask again', async () => {
+ localStorage.clear(); _resetAiConsent()
+ const info = { provider: 'openai', providerLabel: 'OpenAI API', host: 'api.openai.com', categories: ['plan'], payer: 'instance' }
+ vi.mocked(disclosure).mockResolvedValue(info)
+ mount()
+ await settle()
+ tap('button', 'I understand')
+ await settle()
+ expect(await hasAiConsent(consentTarget(info, 'server'))).toBe(true)
+ expect((await aiConsents()).map(c => c.name)).toEqual(['OpenAI'])
+ })
+
+ it('a compatible endpoint is named by its host, and a model on the LAN or an unread disclosure records nothing', async () => {
+ localStorage.clear(); _resetAiConsent()
+ vi.mocked(disclosure).mockResolvedValue({ provider: 'compatible', providerLabel: 'OpenAI-compatible endpoint', host: 'llm.example.org', categories: ['plan'], payer: 'instance' })
+ mount()
+ await settle()
+ expect(host.textContent).toContain('Sent to llm.example.org')
+ act(() => root.unmount()); root = createRoot(host)
+
+ vi.mocked(disclosure).mockResolvedValue({ provider: 'compatible', providerLabel: 'OpenAI-compatible endpoint', host: '192.168.1.20:11434', categories: ['plan'], payer: 'instance' })
+ mount()
+ await settle()
+ tap('button', 'I understand')
+ await settle()
+ act(() => root.unmount()); root = createRoot(host)
+
+ mocks.S = fresh()
+ vi.mocked(disclosure).mockResolvedValue(null)
+ mount()
+ await settle()
+ tap('button', 'I understand')
+ await settle()
+ expect(await aiConsents()).toEqual([])
+ })
+
it('"Not now" writes nothing at all and goes back to the plan', () => {
mount()
tap('button', 'Not now')