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
Rotation: Start new pass starts now, and Home's today row follows the plan
Duarte Santos05a04496c0be
diff --git a/api/queue.js b/api/queue.jsindex 8d858b1f5..dc4c0c86a 100644--- a/api/queue.js+++ b/api/queue.js@@ -11,7 +11,9 @@// week (on or after `startsOn`) whose merged name (`'A + B'`) names the routine under its current// title. The date bound keeps a past week's workout, which a planner's reused ids and names can// make look identical, from counting. Only finished workouts (`S.workouts`) count; an in-progress-// session never does. Missed sets are the planner's business, not the queue's.+// session never does. Missed sets are the planner's business, not the queue's. A queue with+// `strict: true` (the app's "Start new pass") drops the dated name clause: only a workout started+// at/after `since` counts, so a session logged earlier that day stays the old pass's.//// NEXT RULE (shared with the frontend): once `startsOn` is reached, the day's session is the// first not-done one in slot order — unless pins say otherwise.@@ -33,7 +35,7 @@ function nameParts(w) {function queueDone(S, id, startsOn) {const currentName = (S.routines || []).find(r => r?.id === id)?.name;return (S.workouts || []).some(w => routineIdsOf(w).includes(id)- && ((w.start ?? 0) >= S.queue.since || (String(w.d || '') >= startsOn && nameParts(w).includes(currentName))));+ && ((w.start ?? 0) >= S.queue.since || (S.queue.strict !== true && String(w.d || '') >= startsOn && nameParts(w).includes(currentName))));}// The calendar date of an instant where the USER is. The frontend's fallback for a missing// startsOn is the device's local date of the apply; the closest thing here is the zone thediff --git a/api/test/queue.test.js b/api/test/queue.test.jsindex ce9d5e1f1..8894df196 100644--- a/api/test/queue.test.js+++ b/api/test/queue.test.js@@ -240,3 +240,13 @@ test('queue: a rotation pass hides only the weekdays it covers', () => {// r1 is the queue's own session, so the weekday's r1 adds nothing; r3 is the athlete's own day.assert.equal(effectiveRoutineId(S, '2026-09-14'), 'r1');});++test('queue: a strict pass (the app\'s "Start new pass") ignores a same-named workout from before since', () => {+ const early = { d: '2026-09-07', start: 500, routineIds: ['r1'], name: 'Push' };+ const loose = { ...base, workouts: [early], queue: { ids: ['r1', 'r2'], since: 1000, startsOn: '2026-09-07', label: 'R' } };+ assert.equal(effectiveRoutineId(loose, '2026-09-07'), 'r2'); // dated name clause credits it+ const strict = { ...loose, queue: { ...loose.queue, strict: true } };+ assert.equal(effectiveRoutineId(strict, '2026-09-07'), 'r1');+ const after = { ...strict, workouts: [early, { ...early, start: 2000 }] };+ assert.equal(effectiveRoutineId(after, '2026-09-07'), 'r2');+});diff --git a/frontend/src/lib/queue.js b/frontend/src/lib/queue.jsindex d4c335bad..349e3a272 100644--- a/frontend/src/lib/queue.js+++ b/frontend/src/lib/queue.js@@ -8,6 +8,10 @@// since: number ms epoch of the apply; a workout STARTED at/after it is this week's// startsOn: 'YYYY-MM-DD' local date the queue becomes active (the planner's calendar-week rule)// label: string progress-row title, e.g. 'US W1'+// strict?: true only a workout STARTED at/after `since` counts; the dated name clause of+// the DONE RULE is off. Plan's "Start new pass" sets it: the new pass+// starts at that moment, and a session logged earlier the same day was+// the old pass's, whatever its name says.// rotationId?: string set only by the in-app rotation editor (lib/rotation.js): this pass// is managed here and refills itself when complete. A planner's queue// omits it and is never rewritten by the app.@@ -63,7 +67,7 @@ export const queueOf = S => {// The DONE RULE for one workout and one session — `isDone` asks it across the log.const countsFor = (S, q, w, id) => routineIdsOf(w).includes(id)&& ((w.start ?? 0) >= q.since- || (String(w.d || '') >= q.startsOn && nameParts(w).includes(S.routines.find(r => r.id === id)?.name)))+ || (q.strict !== true && String(w.d || '') >= q.startsOn && nameParts(w).includes(S.routines.find(r => r.id === id)?.name)))const isDone = (S, q, id) => S.workouts.some(w => countsFor(S, q, w, id))/** The week's sessions already done, in slot order. `[]` without a queue. */diff --git a/frontend/src/lib/rotation.js b/frontend/src/lib/rotation.jsindex 0008bcac8..d8a53fa23 100644--- a/frontend/src/lib/rotation.js+++ b/frontend/src/lib/rotation.js@@ -91,6 +91,7 @@ export function saveRotation(s, ids, label, today = todayISO(), now = Date.now()startsOn: prev?.startsOn ?? today,label,rotationId: s.rotation.id,+ ...(prev?.strict === true ? { strict: true } : {}),}// A session dropped from the rotation leaves its future pin behind otherwise — dayPlan then// still resolves that date to a session the queue no longer has (pinState/queue.js).@@ -120,19 +121,18 @@ const lastCreditDay = s => {}/**- * Plan's "Start new pass": throw the current pass away and begin the saved sequence again. From- * today — unless today's own workout closed the pass being replaced, which would otherwise be- * credited twice (see THE ONE-DAY BOUNDARY above).+ * Plan's "Start new pass": throw the current pass away and begin the saved sequence again, right+ * now. Today is its first day, so Home, Start and the day sheet all name its first session as+ * today's, and nothing logged before this moment counts for it (`strict`, queue.js): a session+ * done earlier today was the old pass's, even under the same routine name.*/export function startNewPass(s, today = todayISO(), now = Date.now()) {if (!s.rotation) returnconst ids = rotationIds(s)if (!ids.length) returnconst q = queueOf(s)- const last = lastCreditDay(s)- const startsOn = last && last >= today ? dayAfter(last) : todayif (q) sweepPins(s, q.ids, today)- s.queue = newPass(ids, s.rotation.label || '', s.rotation.id, startsOn, q ? sinceAfter(s, q, now) : now)+ s.queue = { ...newPass(ids, s.rotation.label || '', s.rotation.id, today, q ? sinceAfter(s, q, now) : now), strict: true }}/** Is `ids` some circular ordering of `seq`? (Both already normalized, so ids are unique.) */diff --git a/frontend/src/lib/rotation.test.js b/frontend/src/lib/rotation.test.jsindex 33bda2d31..96dc06655 100644--- a/frontend/src/lib/rotation.test.js+++ b/frontend/src/lib/rotation.test.js@@ -1,6 +1,7 @@import { describe, it, expect } from 'vitest'import { scheduleModeOf, queueRecovery, rotationIds, startPass, saveRotation, startNewPass, stopPass, refillAfter } from './rotation.js'-import { queueRemaining, queueView } from './queue.js'+import { queueNext, queueRemaining, queueView } from './queue.js'+import { effectiveRoutineIds } from './history.js'const routines = [{ id: 'a', name: 'A' }, { id: 'b', name: 'B' }, { id: 'c', name: 'C' }, { id: 'own', name: 'Core' }]const TODAY = '2026-09-12'@@ -100,16 +101,34 @@ describe('editing the sequence', () => {expect(s.dayPlan).toEqual({ '2026-09-11': 'b', '2026-09-14': 'a' })})- it('Start new pass rewinds to today, and to tomorrow when today closed the old one', () => {+ it('Start new pass starts now: today is its first day, and nothing logged before counts', () => {const base = { rotation: { id: 'r1', sequence: ['a', 'b'], label: 'My split' } }const stale = S({ ...base, queue: pass(['a', 'b'], { rotationId: 'r1' }), workouts: [w('a', '2026-09-10'), w('b', '2026-09-10')] })startNewPass(stale, TODAY, NOW)- expect(stale.queue.startsOn).toBe(TODAY)- // …but a pass closed by a workout dated today must not have that same workout credit the new one- const fresh = S({ ...base, queue: pass(['a', 'b'], { rotationId: 'r1' }), workouts: [w('a', '2026-09-10'), w('b', TODAY)] })+ expect(stale.queue).toMatchObject({ startsOn: TODAY, since: NOW, strict: true })+ // Android QA: A was logged today, then "Start new pass". The pass used to wait for tomorrow+ // ("Next pass starts …" over a pass in progress, Home and Start naming different sessions),+ // and A logged earlier today still read as Done by its name.+ const fresh = S({ ...base, queue: pass(['a', 'b'], { rotationId: 'r1' }), workouts: [w('a', TODAY)] })startNewPass(fresh, TODAY, NOW)- expect(fresh.queue.startsOn).toBe('2026-09-13')- expect(fresh.queue.since).toBe(NOW)+ expect(fresh.queue.startsOn).toBe(TODAY)+ const v = queueView(fresh, TODAY)+ expect(v.waiting).toBe(false)+ expect(v.items.map(i => i.state)).toEqual(['next', 'later'])+ expect(queueNext(fresh, TODAY, TODAY)).toBe('a')+ expect(effectiveRoutineIds(fresh, TODAY, TODAY)).toEqual(['a'])+ // a session done after the start moment counts as usual+ fresh.workouts.push(w('a', TODAY, NOW + 60_000))+ expect(queueView(fresh, TODAY).items.map(i => i.state)).toEqual(['done', 'next'])+ expect(effectiveRoutineIds(fresh, TODAY, TODAY)).toEqual(['b'])+ })++ it('an edit keeps a new pass strict', () => {+ const s = S({ rotation: { id: 'r1', sequence: ['a', 'b'], label: 'My split' }, queue: pass(['a', 'b'], { rotationId: 'r1' }), workouts: [w('a', TODAY)] })+ startNewPass(s, TODAY, NOW)+ saveRotation(s, ['b', 'a'], 'My split', TODAY, NOW + 5000)+ expect(s.queue).toMatchObject({ strict: true, since: NOW, startsOn: TODAY })+ expect(queueRemaining(s)).toEqual(['b', 'a'])})it('Start new pass sweeps the old pass\'s future pins — a stale one would otherwise resurface as open on the new pass', () => {diff --git a/frontend/src/views/Home.jsx b/frontend/src/views/Home.jsxindex 8263e93a7..707719229 100644--- a/frontend/src/views/Home.jsx+++ b/frontend/src/views/Home.jsx@@ -46,8 +46,15 @@ export default function Home() {wkStart.setDate(today.getDate() - weekDayOffset(today.getDay(), ws) + weekOffset * 7)const doneDays = new Set(S.workouts.map(w => w.d))// The last session logged for today, if any — what the row below reports instead of asking- // you to start the one you already did. Last wins, so a second session names itself.- const doneToday = S.workouts.filter(w => w.d === todayISO()).at(-1) || null+ // you to start the one you already did. Last wins, so a second session names itself. Only once+ // today's plan is covered, though: a freestyle session on a planned day, or the rotation's+ // first session done when its next one is today's too, leaves the row offering what is still+ // to do, as Start and the progress row already do. A queue session is never "covered" by an+ // earlier workout: the queue only names one it does not count as done yet.+ const loggedToday = S.workouts.filter(w => w.d === todayISO())+ const queueIds = queueOf(S)?.ids || []+ const coveredToday = id => !queueIds.includes(id) && loggedToday.some(w => (Array.isArray(w.routineIds) ? w.routineIds : [w.routineId]).includes(id))+ const doneToday = (todayRoutines.every(r => coveredToday(r.id)) && loggedToday.at(-1)) || nullconst strip = []for (let i = 0; i < 7; i++) {const d = new Date(wkStart); d.setDate(wkStart.getDate() + i)diff --git a/frontend/src/views/Home.queue.test.jsx b/frontend/src/views/Home.queue.test.jsxindex 1098bbc80..e8ebfd346 100644--- a/frontend/src/views/Home.queue.test.jsx+++ b/frontend/src/views/Home.queue.test.jsx@@ -272,3 +272,49 @@ describe('Home — a session pinned to a day', () => {expect(startFlow).toHaveBeenCalledWith(['d1'])})})++// Android QA (1.3.10 rc): the today row reported the last finished session ("Full Body A, Done")+// while the progress row and Start already named the next one for today.+describe('Home — the today row follows today\'s plan, not just the last session', () => {+ const today = todayISO()+ const at = (id, start, name) => ({ id: 'w-' + id + start, d: today, start, end: start + 1000, routineIds: id ? [id] : [], routineId: id, name: name || routines.find(r => r.id === id).name, entries: [] })+ const tag = () => host.querySelector('.today-row .tag')?.textContent++ it('a queue session done today: the row offers the next one, like the progress row', () => {+ setS({ workouts: [at('d1', Date.now() - 3600000)] })+ mount()+ expect(status()).toBe('Next: US W1 D2, today')+ expect(todayTitle()).toBe('US W1 D2')+ expect(tag()).toBe('Start')+ })++ it('a freestyle session on a planned day leaves the plan offered', () => {+ const wd = new Date(today + 'T12:00:00').getDay()+ setS({ queue: null, week: { [wd]: ['own'] }, workouts: [at(null, Date.now() - 3600000, 'Freestyle')] })+ mount()+ expect(todayTitle()).toBe('Core')+ expect(tag()).toBe('Start')+ })++ it('the planned routine done today still reads as done', () => {+ const wd = new Date(today + 'T12:00:00').getDay()+ setS({ queue: null, week: { [wd]: ['own'] }, workouts: [at('own', Date.now() - 3600000)] })+ mount()+ expect(todayTitle()).toBe('Core (done)')+ expect(tag()).toBe('Done')+ })++ it('Start new pass after a session today: the pass runs today, from its first session', () => {+ const now = Date.now()+ setS({+ rotation: { id: 'rot', sequence: ['d1', 'd2', 'd3'], label: 'Rotation' },+ queue: { ids: ['d1', 'd2', 'd3'], since: now - 1000, startsOn: today, label: 'Rotation', rotationId: 'rot', strict: true },+ workouts: [at('d1', now - 3600000)],+ })+ mount()+ expect(chipTexts()).toEqual(['US W1 D1Up next', 'US W1 D2Later', 'US W1 D3Later'])+ expect(status()).toBe('Next: US W1 D1, today')+ expect(todayTitle()).toBe('US W1 D1')+ expect(tag()).toBe('Start')+ })+})