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
mcp: get_week_plan knows the coach week and pins
Boris Kurktchievff48ba618728
diff --git a/mcp/README.md b/mcp/README.mdindex b1f0b7604..f03cbb8a1 100644--- a/mcp/README.md+++ b/mcp/README.md@@ -74,7 +74,7 @@ Nine read-only tools in v1:| `list_routines` | What routines are saved in my profile? (names + exercise counts) || `get_routine` | What does the Push Day routine prescribe? (sets/reps/weight and rest per exercise) || `preview_session` | What will the app actually put on screen when I start this routine — after the progression policy and my history have overridden the plan? |-| `get_week_plan` | What's on my plan this week, including today with any date-specific override? |+| `get_week_plan` | What's planned when: the next seven days with their routines and how each was decided (coach week, a pinned session, an override, the weekday plan), the current coach week when one is running, and the weekday table. || `list_workouts` | Recent sessions — newest first, with dates, sets done/planned, volume, duration, PRs. || `get_workout` | Full set-by-set breakdown of one session, by `workout_id` or by date. On a day with two sessions the date alone returns both ids to pick from rather than guessing at one. || `get_bodyweight` | Weigh-ins with the latest weight, the goal line, and deltas vs goal. |diff --git a/mcp/scripts/check-node-loadable.mjs b/mcp/scripts/check-node-loadable.mjsindex 4400c6e13..61f2f5623 100644--- a/mcp/scripts/check-node-loadable.mjs+++ b/mcp/scripts/check-node-loadable.mjs@@ -22,7 +22,7 @@ const LIB = new URL('../../frontend/src/lib/', import.meta.url)// which one, rather than which import chain.const MODULES = ['i18n-core.js', 'format.js', 'exercises.js', 'exercises-data.js',- 'history.js', 'muscles.js', 'onerm.js', 'progression.js'+ 'history.js', 'muscles.js', 'onerm.js', 'progression.js', 'queue.js']let failed = 0diff --git a/mcp/src/tools.js b/mcp/src/tools.jsindex dd4600aa8..d196b437d 100644--- a/mcp/src/tools.js+++ b/mcp/src/tools.js@@ -7,8 +7,9 @@ import {fmt, setLabel, exLine, muscleName, policyName, friendlyDuration, ratio, muscleOrder} from './labels.js'import {- modeOf, workoutVolume, setsDone, effectiveRoutine, effectiveRoutineId, lastEntryFor+ modeOf, workoutVolume, setsDone, effectiveRoutine, effectiveRoutineIds, lastEntryFor} from '../../frontend/src/lib/history.js'+import { queueView, queueNext, pinState } from '../../frontend/src/lib/queue.js'import { exOr } from '../../frontend/src/lib/exercises.js'import { isWarmupRow } from '../../frontend/src/lib/workout-model.js'import {@@ -153,10 +154,11 @@ export const getRoutine = {}}-/** get_week_plan — what's scheduled each weekday + today. */+/** get_week_plan — what's scheduled each weekday + today, and the coach week when one is running. */+const DAY_NAMES = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']export const getWeekPlan = {name: 'get_week_plan',- description: 'Show the user\'s weekly plan: which routine (if any) is assigned to each weekday, keyed by JS getDay() (Sunday=0, Monday=1, … Saturday=6 — the same convention the openGym state file uses). Also reports today\'s date and what routine applies today, accounting for one-off overrides the user may have set for a specific date (a "rest" override cancels the day).',+ description: 'Show the user\'s training plan. `days` is the authoritative answer to "what is planned when": the next seven dates from today with the routines planned for each (a date can hold several — a combined day) and how each was decided: a coach-week session ("coach"), a session the user pinned to that date ("pinned"), a one-off routine override ("override"), a "rest" override ("rest_override"), the weekday plan ("weekday") or nothing ("rest"). `coach_week` is the current coach week when one is running (a week written by an external planner through the API, never by the app): its sessions are done IN ORDER on whatever days the user trains (no weekday attached), the first undone one is today\'s session, a session can be pinned to a date, and `waiting` means the week starts on `starts_on`. `weekdays` is the user\'s own weekly plan keyed by JS getDay() (Sunday=0 … Saturday=6, the openGym state convention) — in a coach week it holds only the routines the user planned themselves, which ride along beside the coach-week session.',schema: {},handler: () => {const S = getState()@@ -164,25 +166,59 @@ export const getWeekPlan = {const today = new Date()const isoToday = today.getFullYear() + '-' + String(today.getMonth() + 1).padStart(2, '0') + '-' + String(today.getDate()).padStart(2, '0')const todayWd = today.getDay()+ const routines = S.routines || []+ const nameOf = id => routines.find(x => x.id === id)?.name || null+ // A weekday holds a routine-id list (combine routines); older states hold one id.+ const weekdayIds = d => [].concat(S.week?.[d] || []).filter(id => routines.some(x => x.id === id))+ const todayIds = effectiveRoutineIds(S, isoToday, isoToday)+ const view = queueView(S, isoToday)+ // How a date's plan was decided — the same precedence as effectiveRoutineIds, named.+ const plannedBy = (iso, ids) => {+ const ov = S.dayPlan?.[iso]+ if (ov === 'rest') return 'rest_override'+ const pin = pinState(S, ov)+ if (pin === 'open') return 'pinned'+ if (!pin && ov && routines.some(x => x.id === ov)) return 'override'+ if (ids.length && queueNext(S, iso, isoToday) === ids[0]) return 'coach'+ return ids.length ? 'weekday' : 'rest'+ }+ const days = Array.from({ length: 7 }, (_, i) => {+ const d = new Date(today.getFullYear(), today.getMonth(), today.getDate() + i, 12)+ const iso = d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0')+ const ids = effectiveRoutineIds(S, iso, isoToday)+ return { date: iso, weekday: d.getDay(), weekday_name: DAY_NAMES[d.getDay()], routine_ids: ids, routine_names: ids.map(nameOf), planned_by: plannedBy(iso, ids) }+ })return {today: isoToday,+ today_routine_id: todayIds[0] ?? null,+ today_routine_name: todayIds.length ? nameOf(todayIds[0]) : null,+ today_routine_ids: todayIds,+ today_routine_names: todayIds.map(nameOf),+ coach_week: view ? {+ label: view.label,+ starts_on: view.startsOn,+ waiting: view.waiting,+ complete: view.complete,+ // state: done | next (today's session) | pinned (to `pinned_to`) | later+ sessions: view.items.map(i => ({ routine_id: i.id, routine_name: i.name, state: i.state, pinned_to: i.on ?? null }))+ } : null,+ days,weekdays: [0, 1, 2, 3, 4, 5, 6].map(d => {- const rid = S.week?.[d] || null- const r = rid ? (S.routines || []).find(x => x.id === rid) : null+ const ids = weekdayIds(d)// Surface today's override only (not the whole dayPlan dict — usually empty, but might// have grown from repeated "move this day" actions).const overrideForToday = d === todayWd ? (S.dayPlan?.[isoToday] ?? null) : nullreturn {weekday: d,- weekday_name: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][d],- routine_id: rid,- routine_name: r?.name || null,- routine_emoji: r?.emoji || null,+ weekday_name: DAY_NAMES[d],+ routine_ids: ids,+ routine_names: ids.map(nameOf),+ routine_id: ids[0] ?? null,+ routine_name: ids.length ? nameOf(ids[0]) : null,+ routine_emoji: ids.length ? (routines.find(x => x.id === ids[0])?.emoji || null) : null,override_for_today_or_null: overrideForToday}- }),- today_routine_id: effectiveRoutineId(S, isoToday),- today_routine_name: effectiveRoutine(S, isoToday)?.name || null+ })}}}diff --git a/mcp/test/tools.test.js b/mcp/test/tools.test.jsindex 0eb77a959..c7476b356 100644--- a/mcp/test/tools.test.js+++ b/mcp/test/tools.test.js@@ -272,6 +272,112 @@ describe('get_week_plan', () => {})})+/* ---------- get_week_plan — coach week (S.queue) and pins ---------- */++describe('get_week_plan — coach week and pins', () => {+ // Today is the pinned Monday 2026-07-27. The planner's queue reuses the demo routines as its+ // three sessions; the queue was applied that morning.+ const rid = name => S.routines.find(x => x.name === name).id+ const SINCE = () => Date.parse('2026-07-27T08:00:00')+ const coachWeek = (over = {}) => {+ S.queue = { ids: [rid('Push Day'), rid('Pull Day'), rid('Leg Day')], since: SINCE(), startsOn: FAKE_TODAY_ISO, label: 'W1', ...over }+ S.week = {}+ }+ const logged = (name, d = FAKE_TODAY_ISO) => ({ id: 'w-' + name, d, start: SINCE() + 3600000, end: SINCE() + 7200000, routineIds: [rid(name)], routineId: rid(name), name, entries: [] })++ test('without a coach week: coach_week is null, days run seven dates from today by the weekday plan', () => {+ const r = call('get_week_plan')+ expect(r.coach_week).toBeNull()+ expect(r.days.map(d => d.date)).toEqual(['2026-07-27', '2026-07-28', '2026-07-29', '2026-07-30', '2026-07-31', '2026-08-01', '2026-08-02'])+ expect(r.days[0]).toMatchObject({ weekday: 1, weekday_name: 'Monday', routine_names: ['Push Day'], planned_by: 'weekday' })+ expect(r.days[1]).toMatchObject({ routine_ids: [], routine_names: [], planned_by: 'rest' })+ expect(r.days[2]).toMatchObject({ routine_names: ['Pull Day'], planned_by: 'weekday' })+ expect(r.today_routine_ids).toEqual([rid('Push Day')])+ expect(r.today_routine_names).toEqual(['Push Day'])+ })++ test('a weekday holding several routines (combine routines) lists them all; the singular fields keep the first', () => {+ S.week[2] = [rid('Pull Day'), rid('Leg Day')]+ const r = call('get_week_plan')+ const tue = r.weekdays.find(d => d.weekday === 2)+ expect(tue.routine_ids).toEqual([rid('Pull Day'), rid('Leg Day')])+ expect(tue.routine_names).toEqual(['Pull Day', 'Leg Day'])+ expect(tue.routine_id).toBe(rid('Pull Day'))+ expect(tue.routine_name).toBe('Pull Day')+ expect(r.days[1]).toMatchObject({ routine_names: ['Pull Day', 'Leg Day'], planned_by: 'weekday' })+ // …and a legacy single id still reads as a one-item list.+ expect(r.weekdays.find(d => d.weekday === 1).routine_ids).toEqual([rid('Push Day')])+ })++ test('a coach week: today is the first undone session, the other days carry nothing, and the week is described', () => {+ coachWeek()+ const r = call('get_week_plan')+ expect(r.coach_week).toMatchObject({ label: 'W1', starts_on: FAKE_TODAY_ISO, waiting: false, complete: false })+ expect(r.coach_week.sessions.map(x => x.state)).toEqual(['next', 'later', 'later'])+ expect(r.coach_week.sessions.map(x => x.pinned_to)).toEqual([null, null, null])+ expect(r.today_routine_name).toBe('Push Day')+ expect(r.days[0]).toMatchObject({ routine_names: ['Push Day'], planned_by: 'coach' })+ r.days.slice(1).forEach(d => expect(d).toMatchObject({ routine_ids: [], planned_by: 'rest' }))+ // The weekday table is the user's own plan only — empty here.+ r.weekdays.forEach(d => expect(d.routine_ids).toEqual([]))+ })++ test('a done session moves today to the next one; the rest of the week still floats', () => {+ coachWeek()+ S.workouts.push(logged('Push Day'))+ const r = call('get_week_plan')+ expect(r.coach_week.sessions.map(x => x.state)).toEqual(['done', 'next', 'later'])+ expect(r.today_routine_name).toBe('Pull Day')+ expect(r.days[0].planned_by).toBe('coach')+ })++ test('a session pinned to a date sits there, is skipped today, and the pin is fulfilled once done', () => {+ coachWeek()+ S.dayPlan['2026-07-29'] = rid('Leg Day')+ let r = call('get_week_plan')+ expect(r.coach_week.sessions[2]).toMatchObject({ state: 'pinned', pinned_to: '2026-07-29' })+ expect(r.days[2]).toMatchObject({ date: '2026-07-29', routine_names: ['Leg Day'], planned_by: 'pinned' })+ expect(r.today_routine_name).toBe('Push Day')+ // Done early: the pin reads as no override and Wednesday goes back to floating (nothing there).+ S.workouts.push(logged('Leg Day'))+ r = call('get_week_plan')+ expect(r.coach_week.sessions[2].state).toBe('done')+ expect(r.days[2]).toMatchObject({ routine_ids: [], planned_by: 'rest' })+ })++ test('a coach week waiting for its start day: today is the weekday plan, the week says when it starts', () => {+ coachWeek({ startsOn: '2026-08-03' })+ S.week = { 1: rid('Push Day') }+ const r = call('get_week_plan')+ expect(r.coach_week).toMatchObject({ waiting: true, starts_on: '2026-08-03' })+ expect(r.days[0]).toMatchObject({ routine_names: ['Push Day'], planned_by: 'weekday' })+ })++ test('the user\'s own weekday routine rides along beside the coach session', () => {+ coachWeek({ ids: [rid('Push Day'), rid('Pull Day')] })+ S.week = { 1: [rid('Leg Day')] }+ const r = call('get_week_plan')+ expect(r.today_routine_names).toEqual(['Push Day', 'Leg Day'])+ expect(r.today_routine_name).toBe('Push Day')+ expect(r.days[0].planned_by).toBe('coach')+ expect(r.weekdays.find(d => d.weekday === 1).routine_names).toEqual(['Leg Day'])+ })++ test('rest and routine overrides are named as such', () => {+ coachWeek()+ S.dayPlan[FAKE_TODAY_ISO] = 'rest'+ S.dayPlan['2026-07-28'] = rid('Leg Day') // a coach id → a pin, not an override+ let r = call('get_week_plan')+ expect(r.days[0]).toMatchObject({ routine_ids: [], planned_by: 'rest_override' })+ expect(r.days[1].planned_by).toBe('pinned')+ S.queue = null+ S.week = { 1: rid('Push Day') }+ S.dayPlan = { '2026-07-28': rid('Leg Day') }+ r = call('get_week_plan')+ expect(r.days[1]).toMatchObject({ routine_names: ['Leg Day'], planned_by: 'override' })+ })+})+/* ---------- list_workouts ---------- */describe('list_workouts', () => {