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
fix: cascade inherited loads while preserving manual set edits
Space-Hermes145951407a86
diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.jsindex ce3e19b89..20ce9f09f 100644--- a/frontend/src/lib/history.js+++ b/frontend/src/lib/history.js@@ -1,7 +1,7 @@// Pure helpers over the state object S (ported 1:1 from the vanilla app).import { todayISO, isoOf, weekKey, weekStartOf, fmtNum } from './format.js'import { isCardio, isBodyweightEq } from './exercises.js'-import { phaseForSet, modeForSet, modeForEntry, isWarmupRow, normalizeMode, completedVolumeOf, nextDropWeight, splitBurstReps, makeSideSet, isSideSet, syncSideAggregate } from './workout-model.js'+import { phaseForSet, modeForSet, modeForEntry, isWarmupRow, normalizeMode, completedVolumeOf, nextDropWeight, splitBurstReps, makeSideSet, isSideSet, syncSideAggregate, WEIGHT_ORIGIN_MANUAL } from './workout-model.js'const objectOf = value => value && typeof value === 'object' && !Array.isArray(value) ? value : {}// Completed-state-independent work rows whose authoritative mode matches the requested mode.const workRowsForMode = (entry = {}, mode = 'reps') => {@@ -573,16 +573,42 @@ export function streakWeeks(S) {}/**- * Cascade a weight change forward: following sets of the same warm-up flag that are still- * undone take the new value (null deletes the key). Done sets are never rewritten.+ * Cascade an explicit load edit through later inherited rows in the same phase.+ *+ * Missing `weightOrigin` is inherited for compatibility with existing sessions. A row or side+ * marked `manual` is an explicit exception, so it stays put even when it is heavier or lighter.+ * `side` narrows a per-side edit to one limb; without it both limbs are eligible independently.+ * Completed rows (and completed limbs) never get rewritten. Clearing an inherited load removes+ * its `w` key just like a direct edit.*/-export function cascadeWeight(rows, from, value) {- const warm = isWarmupRow(rows[from])+export function cascadeWeight(rows, from, value, side) {+ const source = rows[from]+ if (!source) return rows.slice()+ const warm = isWarmupRow(source)+ const sides = isSideSet(source) ? (side ? [side] : ['L', 'R']) : nullconst next = rows.slice()+ const setWeight = row => {+ const out = { ...row }+ if (value == null) delete out.w+ else out.w = value+ return out+ }+ const setSideWeight = (row, key) => {+ const current = row.sides?.[key]+ if (!current || current.done === true || current.weightOrigin === WEIGHT_ORIGIN_MANUAL) return row+ const nextSide = setWeight(current)+ return syncSideAggregate({ ...row, sides: { ...row.sides, [key]: nextSide } })+ }for (let j = from + 1; j < next.length; j++) {- if (isWarmupRow(next[j]) === warm && !next[j].done) {- if (value == null) delete next[j].w- else next[j].w = value+ const row = next[j]+ if (isWarmupRow(row) !== warm) continue+ if (sides) {+ if (!isSideSet(row)) continue+ let out = row+ for (const key of sides) out = setSideWeight(out, key)+ next[j] = out+ } else if (!isSideSet(row) && !row.done && row.weightOrigin !== WEIGHT_ORIGIN_MANUAL) {+ next[j] = setWeight(row)}}return nextdiff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.jsindex 5fd3edae5..ef716787e 100644--- a/frontend/src/lib/history.test.js+++ b/frontend/src/lib/history.test.js@@ -1,6 +1,6 @@import { describe, it, expect } from 'vitest'import { nextTrainingDay, modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, workSetsDone, setsDone, setsDoneActive, setUnits, doneUnits, setUnitsTotal, pairAdjacent, unpairSuperset, supersetUnits, applyIntensifierPlan, pinnedNoteFor, exNoteFor, effectiveRoutineIds, effectiveRoutines, effectiveRoutineId, effectiveRoutine, lastEntryFor, entryExcluded } from './history.js'-import { makeSideSet, setSideField, toggleSide } from './workout-model.js'+import { makeSideSet, setSideField, toggleSide, WEIGHT_ORIGIN_MANUAL } from './workout-model.js'import { EXDB } from './exercises.js'// Real ids out of the shipped catalogue, so the body-part fallback is exercised for real.@@ -816,6 +816,37 @@ describe('session row helpers', () => {expect('w' in next[2]).toBe(false)})+ it('cascadeWeight lowers inherited rows but keeps an explicitly edited heavier row and done rows', () => {+ const rows = [+ { w: 100, done: false },+ { w: 100, done: false },+ { w: 120, weightOrigin: WEIGHT_ORIGIN_MANUAL, done: false },+ { w: 100, done: true },+ { w: 100, done: false },+ ]+ const next = cascadeWeight(rows, 0, 80)+ expect(next[1].w).toBe(80) // inherited rows follow downward corrections+ expect(next[2].w).toBe(120) // only explicit manual edits are protected+ expect(next[3].w).toBe(100) // performed work is immutable+ expect(next[4].w).toBe(80)+ })++ it('cascadeWeight cascades one per-side lane, preserving manual and completed limbs', () => {+ const inherited = makeSideSet({ w: 20, r: 16 })+ const manualRight = setSideField(makeSideSet({ w: 20, r: 16 }), 'R', 'w', 25)+ manualRight.sides.R.weightOrigin = WEIGHT_ORIGIN_MANUAL+ const partial = toggleSide(makeSideSet({ w: 20, r: 16 }), 'L')+ const rows = [makeSideSet({ w: 20, r: 16 }), inherited, manualRight, partial]+ const next = cascadeWeight(rows, 0, 15, 'L')++ expect(next[1].sides.L.w).toBe(15)+ expect(next[1].sides.R.w).toBe(20)+ expect(next[2].sides.L.w).toBe(15)+ expect(next[2].sides.R.w).toBe(25) // an explicit right-side edit is independent+ expect(next[3].sides.L.w).toBe(20) // completed left side is immutable+ expect(next[3].sides.R.w).toBe(20) // the edit was for the left-side lane only+ })+it('insertWarmupRow inserts before the first work row, ramping toward the work weight', () => {const rows = [{ warmup: true, w: 20, r: 8, done: true },diff --git a/frontend/src/lib/workout-model.js b/frontend/src/lib/workout-model.jsindex 272795489..6af77f506 100644--- a/frontend/src/lib/workout-model.js+++ b/frontend/src/lib/workout-model.js@@ -154,6 +154,11 @@ export function isSideSet(set) {return !!(s.sides && typeof s.sides === 'object' && s.sides.L && s.sides.R)}+// A load explicitly changed by the user is protected from a later cascade. Missing provenance+// means the row was inherited from the preceding load, including rows written before this field+// existed. The marker is deliberately tiny and preserved on a side through aggregate resync.+export const WEIGHT_ORIGIN_MANUAL = 'manual'+/** Includes a completed limb even when its partner is still unchecked. */export const hasCompletedWork = set => isSideSet(set)? set.sides.L.done === true || set.sides.R.done === true@@ -171,6 +176,7 @@ const sideOf = value => {const out = { w: Number(v.w) || 0, r: Number(v.r) || 0, done: v.done === true }if (v.rir != null) out.rir = v.ririf (v.rpe != null) out.rpe = v.rpe+ if (v.weightOrigin === WEIGHT_ORIGIN_MANUAL) out.weightOrigin = WEIGHT_ORIGIN_MANUAL// A side can carry its own intensifier (issue #60): drop-sets and rest-pause bursts are logged// per limb, exactly like the main set, so the same {type, drops, clusters} shape rides on the// side. Reuses the row-level helpers below (addDrop/dropsOf/…), which read this very shape.diff --git a/frontend/src/lib/workout-model.test.js b/frontend/src/lib/workout-model.test.jsindex 0b83cad32..3dbfa1845 100644--- a/frontend/src/lib/workout-model.test.js+++ b/frontend/src/lib/workout-model.test.js@@ -4,7 +4,7 @@ import {setType, isDropSet, isRestPauseSet, dropsOf, clustersOf, extraVolumeOf,addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt,nextDropWeight, nextBurstReps, splitBurstReps,- isSideSet, makeSideSet, syncSideAggregate, setSideField, toggleSide,+ isSideSet, makeSideSet, syncSideAggregate, setSideField, toggleSide, WEIGHT_ORIGIN_MANUAL,addSideDrop, removeSideDropAt, setSideDropAt, addSideCluster, removeSideClusterAt, setSideClusterAt,} from './workout-model.js'@@ -17,6 +17,17 @@ describe('phaseForSet / isWarmupRow', () => {})})+describe('per-side load provenance', () => {+ it('survives aggregate resync when the other side changes', () => {+ const row = makeSideSet({ w: 20, r: 16 })+ row.sides.R.weightOrigin = WEIGHT_ORIGIN_MANUAL+ const next = setSideField(row, 'L', 'w', 15)+ expect(next.sides.L.w).toBe(15)+ expect(next.sides.R.w).toBe(20)+ expect(next.sides.R.weightOrigin).toBe(WEIGHT_ORIGIN_MANUAL)+ })+})+describe('setType / isDropSet / isRestPauseSet', () => {it('defaults to straight for anything without a recognised type', () => {expect(setType({})).toBe('straight')diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsxindex 8e772d080..6822f2160 100644--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@ -19,7 +19,7 @@ import { Button, Check, NumberField } from '../components/ui.jsx'import { nextPrescription, applyPrescription, defaultIncrement, weightIncrement, stepWeight } from '../lib/progression.js'import { progressionGuidance } from '../lib/progression-copy.js'import { glyphOf } from '../lib/glyphs.js'-import { isWarmupRow, isDropSet, isRestPauseSet, dropsOf, clustersOf, addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt, nextDropWeight, nextBurstReps, isSideSet, makeSideSet, setSideField, toggleSide, addSideDrop, removeSideDropAt, setSideDropAt, addSideCluster, removeSideClusterAt, setSideClusterAt } from '../lib/workout-model.js'+import { isWarmupRow, isDropSet, isRestPauseSet, dropsOf, clustersOf, addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt, nextDropWeight, nextBurstReps, isSideSet, makeSideSet, setSideField, toggleSide, addSideDrop, removeSideDropAt, setSideDropAt, addSideCluster, removeSideClusterAt, setSideClusterAt, WEIGHT_ORIGIN_MANUAL } from '../lib/workout-model.js'import { canMoveActiveWorkoutUnit, moveActiveWorkoutUnit } from '../lib/active-workout-order.js'const SWIPE_MIN_DISTANCE = 48@@ -107,7 +107,16 @@ function ExerciseBlock({ entryIdx, compact, dense, onToggle, onToggleSide, onFie// the row's aggregate (r/w/done/effort) in step via the model helper so every other reader// stays right. The done tick goes through onToggleSide → toggle() instead, so ticking a side// still fires the rest timer / auto-advance / workout-complete flow.- const setSide = (i, side, field, v) => mutSet(i, row => setSideField(row, side, field, v))+ const setSide = (i, side, field, v) => {+ if (field !== 'w') return mutSet(i, row => setSideField(row, side, field, v))+ update(s => {+ const e = s.active.entries[entryIdx]+ const row = setSideField(e.sets[i], side, field, v)+ row.sides[side].weightOrigin = WEIGHT_ORIGIN_MANUAL+ e.sets[i] = row+ e.sets = cascadeWeight(e.sets, i, v, side)+ }, true)+ }// Drop/burst edits accept an optional `side` ('L'|'R'): present for a per-side row (edits that// one limb's drop/burst), absent for a straight row (edits the row's own).const removeDrop = (i, di) => mutSet(i, row => isSideSet(row) ? removeSideDropAt(row, di) : removeDropAt(row, di))@@ -587,9 +596,10 @@ function ActiveWorkout() {// what was actually logged — in the session, in history and in a backup.const setField = (idx, i, field, v) => mutEntry(idx, e => {if (v == null) delete e.sets[i][field]; else e.sets[i][field] = v- // Changing a weight cascades to the following sets of the same phase, so a- // heavier bar carries through the set instead of retyping every row.+ // Changing a weight cascades to following inherited sets of the same phase, so a correction+ // carries through without retyping every row while explicit manual exceptions stay put.if (field === 'w') {+ e.sets[i].weightOrigin = WEIGHT_ORIGIN_MANUALe.sets = cascadeWeight(e.sets, i, v)}})