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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Coach: a question asked beside a suggestion leaves the suggestion in place (#660)
Duarte Santos3b9cddfef08a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 92c828701..f4102a919 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -92,6 +92,9 @@ you leave it alone. Handy for deciding whether those legs are really ready (thanlights up, and so does the one you scroll to (#323, thanks @Space-Hermes).- The install tip in About on a Windows or Linux browser points at Chrome's install icon,not at an iPhone's Share menu you don't have.+- The Coach answers questions now. Type "how many sets of dips is that?" in the chat and you get+ an answer in words instead of a whole revised plan, and a suggestion you were asking about is+ still there afterwards (#660, thanks @TheBlackSide243).## v1.4.2 (2026-10-18)diff --git a/api/coach/core/pending.js b/api/coach/core/pending.jsnew file mode 100644index 000000000..ba8d37bfe--- /dev/null+++ b/api/coach/core/pending.js@@ -0,0 +1,13 @@+/* The pending slot: one proposal per profile, waiting for a decision. Shared by the server's job+ queue, the phone's own Coach and the demo, so all three hand back the same thing. Kept apart+ from validate.js so the demo can use it without loading the exercise library. */++/* An answer to a question holds the pending slot only for as long as it takes to read it. A+ question is often about the suggestion on screen ("why one set less?"), so the proposal still+ waiting for a decision rides along on the answer (`prev`) and comes back once it is read.+ Never an older answer, and never one that has run out meanwhile. */+export function waitingProposal(p, now = Date.now()) {+ if (!p) return null;+ if (p.kind === 'ask') return waitingProposal(p.prev, now);+ return p.expiresAt && p.expiresAt < now ? null : p;+}diff --git a/api/coach/jobs.js b/api/coach/jobs.jsindex 72e29a3d3..9bddf90dc 100644--- a/api/coach/jobs.js+++ b/api/coach/jobs.js@@ -23,6 +23,7 @@ import { runPipeline } from './core/pipeline.js';import { extractJSON } from './core/parse.js';import { hashPlan } from './core/plan-hash.js';import { buildPrompt } from './core/prompt.js';+import { waitingProposal } from './core/pending.js';import { handleFor } from './handle.js';import { fetchFor } from './node-fetch.js';import { privilegeRefusal, unprivilegedIds } from './adapters/spawn.js';@@ -395,6 +396,7 @@ async function execute(job) {iteration: job.refine ? (pendingCreate?.iteration || 1) + 1 : 1,// A debrief names the session it read, so the card can show it after the fact....(job.kind === 'debrief' ? { workout: payloadLib.workoutMeta(S, job.workoutId) } : {}),+ ...(job.kind === 'ask' ? { prev: waitingProposal(readUser(job.uid).pending) } : {}),...attempt.result};return finish(job, { outcome: 'ready', pending });@@ -415,10 +417,13 @@ export function resolvePending(uid, { accepted = [], rejected = [], dismissed =outcome: dismissed ? 'dismissed' : 'applied',accepted: accepted.length, rejected: rejected.length, at: Date.now()}].slice(-HISTORY_MAX);- writeUser(uid, { ...rec, pending: null, history });+ // A read answer gives back the proposal it was asked beside (core/pending.js).+ const back = rec.pending.kind === 'ask' ? waitingProposal(rec.pending.prev) : null;+ writeUser(uid, { ...rec, pending: back, history });return { ok: true };}+/* ---------- admin test + boot recovery ---------- *//** A2's "Test the Coach": the real adapter, a trivial round-trip, no user data anywhere near it. */diff --git a/api/test/e2e-apikey.test.js b/api/test/e2e-apikey.test.jsindex 7ec6b8a27..7339ac3c8 100644--- a/api/test/e2e-apikey.test.js+++ b/api/test/e2e-apikey.test.js@@ -149,6 +149,34 @@ test('an overloaded provider is retried and the job still succeeds', async () =>assert.equal(rec.history.at(-1).outcome, 'nochange');});+test('a question asked in the chat comes back as an answer, not a plan (#660)', async () => {+ answerWith = REVIEW_CHANGE;+ await runReview('openai', 'sk-oa-ask', 'u-ask');+ assert.equal(jobs.readUser('u-ask').pending.kind, 'review');+ answerWith = { coach_contract: 1, answer: 'Four sets of dips: three working sets and one warm-up.' };+ seen.length = 0;+ jobs.enqueue('u-ask', { kind: 'ask', note: 'how many sets of dips is that?' });+ await settle('u-ask');+ const job = seen.find(s => s.url === '/v1/chat/completions');+ assert.match(job.body.messages[0].content, /# Task: answer a question/);+ assert.match(JSON.stringify(job.body.messages), /how many sets of dips is that\?/);+ let rec = jobs.readUser('u-ask');+ assert.equal(rec.history.at(-1).outcome, 'ready');+ assert.equal(rec.pending.kind, 'ask');+ assert.equal(rec.pending.answer, 'Four sets of dips: three working sets and one warm-up.');+ assert.equal(rec.pending.changes, undefined, 'an answer carries no change-set');+ // The review that was waiting for a decision is still there once the answer has been read:+ // a question about a suggestion must not throw the suggestion away.+ jobs.resolvePending('u-ask', { accepted: ['ask'] });+ rec = jobs.readUser('u-ask');+ assert.equal(rec.pending?.kind, 'review');+ assert.equal(rec.pending.changes.length, 1);+ assert.equal(rec.history.at(-1).kind, 'ask');+ // Deciding on the review then clears it as before.+ jobs.resolvePending('u-ask', { accepted: ['c1'] });+ assert.equal(jobs.readUser('u-ask').pending, null);+});+test('a wrong key is reported as an auth failure, with the provider\'s reason kept for the admin card', async () => {cfg.reset();cfg.save({ enabled: true, provider: 'anthropic', authMode: 'instance', auth: {}, models: {}, boundUid: {}, log: [],diff --git a/frontend/src/lib/coach-demo.js b/frontend/src/lib/coach-demo.jsindex c9dc8ebc0..9bbd71e0e 100644--- a/frontend/src/lib/coach-demo.js+++ b/frontend/src/lib/coach-demo.js@@ -18,6 +18,7 @@ import { isWarmupRow } from './workout-model.js'import { best1RM } from './onerm.js'import { fmtNum } from './format.js'import { planHash } from './coach.js'+import { waitingProposal } from '../../../api/coach/core/pending.js'import { t } from './i18n.js'const DELAY = 2200 // long enough to see "the Coach is thinking…", short enough to forgive@@ -209,10 +210,10 @@ export const demoDebrief = (S, workoutId) => {// The demo has no model behind it: a question gets a sample answer that says so.export const demoAsk = (S, text) => start('ask', () => ({id: 'demo-ask-' + Date.now().toString(36), kind: 'ask', createdAt: Date.now(), expiresAt: Date.now() + 864e5,- planHash: planHash(S), iteration: 1,+ planHash: planHash(S), iteration: 1, prev: waitingProposal(pending),answer: t('This is the demo, so there is no AI model behind me. On your own server I answer questions like “{0}” with your plan, your last sessions and the workout you are doing right now.', String(text || '').slice(0, 80)),}))-export const demoResolve = () => { pending = null; return { ok: true } }+export const demoResolve = () => { pending = pending?.kind === 'ask' ? waitingProposal(pending.prev) : null; return { ok: true } }export const demoDisclosure = () => ({provider: 'demo', providerLabel: t('the configured AI provider'),categories: ['plan', 'training', 'bodyweight', 'profile', 'prefs'], version: 1diff --git a/frontend/src/lib/coach-demo.test.js b/frontend/src/lib/coach-demo.test.jsindex 902bce3d8..63b7ca1e8 100644--- a/frontend/src/lib/coach-demo.test.js+++ b/frontend/src/lib/coach-demo.test.js@@ -10,7 +10,7 @@// test here starts a job and then drains it. A test that leaves one running would 409 the next.import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'import {- demoStatus, demoPlan, demoReview, demoRefine, demoDebrief, demoResolve, demoCohort, demoDisclosure+ demoStatus, demoPlan, demoReview, demoRefine, demoDebrief, demoAsk, demoResolve, demoCohort, demoDisclosure} from './coach-demo.js'import { EXDB, EXIDX } from './exercises.js'import { planHash, validateProposal, applyChangeSet } from './coach.js'@@ -98,6 +98,18 @@ describe('coach-demo — the job machine', () => {expect(demoStatus()).toEqual({ job: null, pending: null, cap: { used: 0, limit: 0 }, lastError: null })})+ it('a question gets a sample answer, and the review it was asked beside comes back once read (#660)', () => {+ const S = state()+ const review = think(() => demoReview(S))+ const answer = think(() => demoAsk(S, 'why one set less?'))+ expect(answer.kind).toBe('ask')+ expect(answer.answer).toContain('why one set less?')+ demoResolve()+ expect(demoStatus().pending).toBe(review)+ demoResolve()+ expect(demoStatus().pending).toBeNull()+ })+it('a builder that throws ends the job, records the failure, and does not refuse the next request', () => {// Before this a throw inside the timer left `job` at 'running' for ever and every later// request answered 409 until the page was reloaded. Any throw will do; a getter is the onediff --git a/frontend/src/lib/coach-local.js b/frontend/src/lib/coach-local.jsindex e3f7016f1..0312322bb 100644--- a/frontend/src/lib/coach-local.js+++ b/frontend/src/lib/coach-local.js@@ -17,6 +17,7 @@// riding into a backup or a sync.import * as payloadLib from '../../../api/coach/core/payload.js'import { runPipeline } from '../../../api/coach/core/pipeline.js'+import { waitingProposal } from '../../../api/coach/core/pending.js'import { HTTP_PROVIDERS, baseUrlFor } from '../../../api/coach/core/providers.js'import anthropic from '../../../api/coach/core/adapters/anthropic.js'import openai from '../../../api/coach/core/adapters/openai.js'@@ -97,7 +98,12 @@ export const localRefine = async (S, text) => {}export const localDebrief = (S, workoutId) => start(S, 'debrief', { workoutId: workoutId || null })export const localAsk = (S, text, today) => start(S, 'ask', { note: String(text || '').slice(0, 1000), today: today || null })-export async function localResolve() { await saveCoachDevice({ pending: null }); return { ok: true } }+// A read answer gives back the proposal it was asked beside, as the server does.+export async function localResolve() {+ const d = await loadCoachDevice()+ await saveCoachDevice({ pending: d.pending?.kind === 'ask' ? waitingProposal(d.pending.prev) : null })+ return { ok: true }+}export async function localForget() { job = null; lastError = null; await saveCoachDevice({ pending: null, daily: null }); return { ok: true } }export async function localDisclosure() {@@ -171,6 +177,7 @@ async function run(S, kind, opts, d, adapter) {id: job.id, kind, createdAt: Date.now(), expiresAt: Date.now() + PENDING_DAYS * 86400000,planHash: planHash(S), iteration: opts.iteration || 1,...(kind === 'debrief' ? { workout: workoutMetaOf(S, opts.workoutId) } : {}),+ ...(kind === 'ask' ? { prev: waitingProposal((await loadCoachDevice()).pending) } : {}),...attempt.result}await saveCoachDevice({ pending })diff --git a/frontend/src/lib/coach-local.test.js b/frontend/src/lib/coach-local.test.jsindex 1d6358ef1..3e0b4138e 100644--- a/frontend/src/lib/coach-local.test.js+++ b/frontend/src/lib/coach-local.test.js@@ -169,6 +169,23 @@ describe('the Coach on a phone with its own key', () => {expect(device.data.pending).toBeNull()})+ it('answers a question in words, and the review waiting beside it comes back once read (#660)', async () => {+ await local.localReview(state()); await settle()+ expect(device.data.pending.kind).toBe('review')+ wire.answer = chat(JSON.stringify({ coach_contract: 1, answer: 'Two to three minutes between heavy sets.' }))+ await local.localAsk(state(), 'how long should I rest?', null)+ const s = await settle()+ expect(s.pending.kind).toBe('ask')+ expect(s.pending.answer).toBe('Two to three minutes between heavy sets.')+ expect(s.pending.changes).toBeUndefined()+ expect(wire.calls.at(-1).body.messages[1].content).toContain('how long should I rest?')+ await local.localResolve()+ expect(device.data.pending.kind).toBe('review')+ expect(device.data.pending.changes).toHaveLength(1)+ await local.localResolve()+ expect(device.data.pending).toBeNull()+ })+it('creates a plan from an intake, and refines it against the previous bundle', async () => {const plan = { coach_contract: 1, opengym_plan: 1, name: 'P', summary: 's', basedOn: 'b', week: { 1: 'r1', 3: 'r2', 5: 'r1' },routines: [