Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,24 @@ no rebuild. An older plan file may also carry `recommender`, `checkin`, `journal
not hidden. Interval pieces keep their rest.
- **Adding a set copies what was done** (`addSetLike` in the runner, appended, so no ids
renumber).
- **A drop set is a set marked `drop: true`** (`isDropSet` in `lib/lifts.js`), on a logged
row and a plan item alike, in the order done; only a drop carries the key. Every reader
that adds sets up reads it as the reps and weight it was; what changes is its name: it
has no number (`setNumbers`, ↳ on the card, "Drop set" in the runner via `setName`).
Offered on a lift counted in reps only (`canDrop`: no holds, pieces or circuits), on its
own line under the last set once it holds a number. A drop starts blank (lighter by
definition, so copying would be a guess), "Add a set" copies the last WORKING set, and
Copy down and "last time" go like with like. Shared sync carries sets as a count, so the
mark is not structure; a set that crosses where the other side's is a drop arrives as a
blank drop (`dropOf` in `server/sharedsync.js`, `blankLike` in `lib/shared.js`).
- **An exercise's own note is `memo`**, on a logged row and a plan item; the plan item's
`note` stays the planner's read-only cue. A box under the card's head while there is one
(else Note in the foot), stored when the box is left; "last time's note" shows while this
one has none. It is the writer's, like a weight: copies strip it (`noMemo`), the
server's sync never carries it, and a plan for several people drops it (`noLoads`,
`withoutLoads`). The planner may write drop sets and memos (reply schema, HOW TO WRITE
IT); a revision may write, change or clear ('') a memo, and one it left out on an
exercise it kept stays (`keepMemos`, in `lib/prescription.js` and `server/drafts.js`).

### 6.5 Workout mode and the runner

Expand Down
100 changes: 100 additions & 0 deletions app/lifts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import {
weightModeWords, liftFieldIn, weightBoxOf, liftMeasure, measureFor, muscleName, blankSet, canSwitchMeasure,
liftsDone, planLifts, liftedLine, implementChoices,
lastTimeFill, fillLift, lastTimeWhen, withFills, copyDownFills, canCopyDown, unfills, cardKey, cardIdentity, rememberedImplement, defaultImplement, weightUnit, weightMeaning, pickerGroupFor,
isDropSet, setNumbers, workingSets, canDrop, memoText, MEMO_MAX, lastMemo,
} from './src/lib/lifts.js'
import { removalWords } from './src/lib/removal.js'
import { isRepeatable, extraEntryId } from './src/lib/store.js'
import { gateResolver, catalogOf as activityCatalog } from './src/lib/activities.js'
import { levelFor } from './src/lib/level.js'
Expand Down Expand Up @@ -1158,5 +1160,103 @@ check('#111 C F2: "Use" on an untouched card rebuilds last time\'s sets, and onl
eq(lastTimeFill(liftField, card([{ id: 'a' }, { id: 'b' }, { id: 'c' }].map(x => ({ ...x, reps: null, weight: null }))), prior, { grow: true }).some(f => f.add), false)
})

/* ------------------------------------------------------------ drop sets and an exercise's own note */

check('a drop set is a set marked drop: numbered as nothing, the working sets 1, 2', () => {
const sets = [{ reps: 10, weight: 90 }, { reps: 10, weight: 90 }, { reps: 8, weight: 70, drop: true }, { reps: 6, weight: 50, drop: true }]
eq(setNumbers(sets), [1, 2, null, null])
eq(workingSets(sets), 2)
eq(sets.map(isDropSet), [false, false, true, true])
eq(removalWords({ name: 'Curl', sets }, 2, { lastTakesItem: false }), 'Removed a drop set of Curl')
eq(removalWords({ name: 'Curl', sets: [sets[0], sets[2], sets[1]] }, 2, { lastTakesItem: false }), 'Removed set 2 of Curl')
eq(removalWords({ name: 'Curl', sets: sets.slice(0, 2) }, 1, { lastTakesItem: false }), 'Removed set 2 of Curl', 'a list with no drops reads as before')
})

check('adding a drop set: blank, marked; adding a set after one copies the last WORKING set', () => {
const list = [{ uid: 'c1', key: 'curl', sets: [{ reps: '10', weight: '30' }] }]
const dropped = addLiftSet(list, 'c1', { drop: true })
eq(dropped[0].sets, [{ reps: '10', weight: '30' }, { reps: '', weight: '', drop: true }])
eq(addLiftSet(dropped, 'c1')[0].sets.at(-1), { reps: '10', weight: '30' }, 'a new working set copied the drop')
eq(addLiftSet(list, 'c1')[0].sets, [{ reps: '10', weight: '30' }, { reps: '10', weight: '30' }], 'a plain add is as it was')
})

check('volume and sets count a drop set as what it was; the summary says it after the working sets', () => {
const row = { uid: 'c1', key: 'curl', sets: [{ reps: 10, weight: 30 }, { reps: 10, weight: 30 }, { reps: 8, weight: 20, drop: true }] }
eq(liftVolume({ lifts: [row] }), 760)
eq(liftSets({ lifts: [row] }), 3)
eq(liftSummary(row), '2 × 10 @ 30 lb, drop 8 @ 20 lb')
eq(liftSummary({ ...row, sets: [...row.sets, { reps: 6, weight: 10, drop: true }] }), '2 × 10 @ 30 lb, drops 8 @ 20 lb, 6 @ 10 lb')
eq(liftSummary({ ...row, sets: row.sets.slice(0, 2) }), '2 × 10 @ 30 lb', 'no drops reads as before')
})

check('copy down and last time go like with like: working sets to working sets, drops to drops', () => {
const sets = [{ id: 'a', reps: 10, weight: 90 }, { id: 'b', reps: null, weight: null }, { id: 'c', reps: null, weight: null, drop: true }]
eq(copyDownFills(sets, 'a').map(f => f.setId), ['b'], 'a working set copied into a drop')
eq(canCopyDown([sets[0], sets[2]], 0), false, 'Copy down offered over a drop')
const prior = { row: { implement: 'barbell', sets: [{ reps: 10, weight: 95 }, { reps: 8, weight: 95 }, { reps: 7, weight: 65, drop: true }] } }
const card = { kind: 'lift', implement: 'barbell', sets: [{ id: 's0', reps: null, weight: null }, { id: 's1', reps: null, weight: null, drop: true }] }
eq(lastTimeFill(liftField, card, prior).map(f => [f.setId, f.patch.reps, f.patch.weight]), [['s0', 10, 95], ['s1', 7, 65]])
// No drop last time: a drop is left blank, never handed a working set's numbers.
const plain = { row: { implement: 'barbell', sets: [{ reps: 10, weight: 95 }] } }
eq(lastTimeFill(liftField, card, plain).map(f => f.setId), ['s0'])
// Grown from an untouched card, a drop stays a drop and an added set takes no mark of the last.
const grown = lastTimeFill(liftField, { kind: 'lift', implement: 'barbell', sets: [{ id: 's0', reps: null, weight: null }] }, prior, { grow: true })
eq(withFills([{ id: 's0', reps: null, weight: null, drop: true }], grown.filter(f => f.add)).map(x => x.drop === true), [true, false, true])
})

check('a done plan reads its drop sets as the log does (liftsDone); its note is read by lastMemo', () => {
const entry = { id: 'p1', kind: 'daily', date: '2026-11-01', data: { done: true, plan: { blocks: [{ id: 'b0', items: [
{ id: 'b0i0', uid: 'U', kind: 'lift', name: 'Curl', exercise: 'curl', memo: 'slow down', implement: '', sets: [
{ id: 's0', reps: 10, weight: 30 }, { id: 's1', reps: 8, weight: 20, drop: true }] },
] }] } } }
const [row] = liftsDone(entry, '2026-11-08')
eq(row.sets, [{ reps: 10, weight: 30 }, { reps: 8, weight: 20, drop: true }])
eq(lastMemo([entry], 'curl', null, '2026-11-08')?.memo, 'slow down', 'a plan\'s note is not read')
})

check('the last note stays on screen until it is changed, not only the session after it was written', () => {
const day = (date, memo) => ({ id: `d-${date}`, kind: 'daily', date, data: { done: true, out: { lifts: [
{ uid: 'u', key: 'leg-press', name: 'Leg press', ...(memo === undefined ? {} : { memo }), sets: [{ reps: 10, weight: 200 }] }] } } })
const log = [day('2026-11-03', 'seat at 4'), day('2026-11-05'), day('2026-11-07')]
eq(lastMemo(log, 'leg-press', null, '2026-11-08'), { date: '2026-11-03', memo: 'seat at 4' }, 'two sessions on, the note was gone')
eq(lastMemo([...log, day('2026-11-08', 'seat at 5')], 'leg-press', 'd-2026-11-08', '2026-11-08')?.memo, 'seat at 4', 'the entry being edited read as its own last note')
eq(lastMemo([...log, day('2026-11-06', 'seat at 5')], 'leg-press', null, '2026-11-08')?.memo, 'seat at 5', 'not the newest note')
eq(lastMemo(log, 'squat', null, '2026-11-08'), null)
// Cleared in a later session (the box emptied stores ''): it stays gone.
eq(lastMemo([...log, day('2026-11-06', '')], 'leg-press', null, '2026-11-08'), null, 'a cleared note came back')
// On a PLANNED workout, done or not, typed or not: the plan item's '' stays gone too (#120 council R3).
const planned = (date, memo, done) => ({ id: `p-${date}`, kind: 'daily', date, data: { done, plan: { blocks: [{ id: 'b0', items: [
{ id: 'b0i0', kind: 'lift', name: 'Leg press', exercise: 'leg-press', memo, sets: [{ id: 's0', reps: null, weight: null }] }] }] } } })
eq(lastMemo([...log, planned('2026-11-06', '', false)], 'leg-press', null, '2026-11-08'), null, 'Clear on an untouched plan did not stick')
eq(lastMemo([...log, planned('2026-11-06', 'seat at 5', false)], 'leg-press', null, '2026-11-08')?.memo, 'seat at 5')
eq(lastMemo([...log, planned('2026-11-09', 'later', false)], 'leg-press', null, '2026-11-08')?.memo, 'seat at 4', 'a plan for a later day was read')
// A run's logged row with no note, on a plan whose item has one: the item's.
const ran = { ...planned('2026-11-06', 'from the plan', true), data: { ...planned('2026-11-06', 'from the plan', true).data, out: { lifts: [{ uid: 'b0i0', key: 'leg-press', sets: [{ reps: 10, weight: 200 }] }] } } }
eq(lastMemo([...log, ran], 'leg-press', null, '2026-11-08')?.memo, 'from the plan')
})

check('"Use last time" grows a drop blank where the weight means something else, never with a working set\'s weight', () => {
const list = [{ uid: 'u', key: 'curl', implement: 'dumbbell', sets: [{ reps: '', weight: '' }] }]
const fills = [{ setId: '0', patch: { reps: 10 } }, { setId: null, add: true, patch: { reps: 8, drop: true } }]
eq(fillLift(list, 'u', fills)[0].sets, [{ reps: 10, weight: '' }, { reps: 8, weight: '', drop: true }])
})

check('a drop set is offered on a lift counted in reps, never on a hold, a piece or in a circuit', () => {
eq(canDrop({ kind: 'lift', sets: [{ reps: 10, weight: 30 }] }), true)
eq(canDrop({ kind: 'lift', sets: [{ reps: '', weight: '' }] }), true)
eq(canDrop({ kind: 'lift', sets: [{ seconds: 45, weight: null, reps: null }] }), false)
eq(canDrop({ kind: 'lift', measure: 'time', sets: [{ seconds: '', weight: '' }] }), false)
eq(canDrop({ kind: 'interval', sets: [{ reps: 4 }] }), false)
eq(canDrop({ kind: 'lift', sets: [{ reps: 10 }] }, { circuit: true }), false)
})

check('an exercise\'s own note is trimmed and bounded, and patched like anything else on the row', () => {
eq(memoText(' seat at 4 '), 'seat at 4')
eq(memoText('x'.repeat(MEMO_MAX + 20)).length, MEMO_MAX)
eq(memoText(null), '')
const list = [{ uid: 'c1', key: 'curl', sets: [{ reps: '10', weight: '30' }] }]
eq(patchLift(liftField, list, 'c1', { memo: 'seat at 4' })[0], { uid: 'c1', key: 'curl', sets: [{ reps: '10', weight: '30' }], memo: 'seat at 4' })
})

console.log(failed ? `\n${failed} lift/output test(s) failed` : '\nall lift and output tests pass')
process.exit(failed ? 1 : 0)
72 changes: 71 additions & 1 deletion app/prescription.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
splitPrescription, moveItem, isLiftOnly,
blankPrescription, appendPiece, dropEmptyBlocks, patchItem, reviseWeightModes, followWeightModes, patchRunItem,
measureOfItem, addBlock, renameBlock, noteBlock, removeBlock, moveBlock, tickSet, setTicked, itemTicked, firstUnticked,
patchBlock, planProgress, doingMove, setEdited, setLogged, keepTyped, itemProgress,
patchBlock, planProgress, doingMove, setEdited, setLogged, keepTyped, itemProgress, setName, keepMemos,
} from './src/lib/prescription.js'
import { liftVolume, liftsIn, liftSummary, rememberedWeightMode, liftsDone } from './src/lib/lifts.js'
import { createRequire } from 'node:module'
Expand Down Expand Up @@ -1223,4 +1223,74 @@ t('doingMove: the card just finished folds; the card that just became next is re
assert.deepEqual(doingMove({ finished: false, focus: true }, { finished: false, focus: true }), { fold: false, reveal: false })
})

/* ------------------------------------------------------------ drop sets and an exercise's own note */

t('a plan keeps a lift\'s drop sets and the person\'s note through normalising; an interval has no drops', () => {
const p = normalizePrescription({ title: 'Arms', blocks: [{ name: 'Main', items: [
{ kind: 'lift', exercise: KNOWN, memo: ' seat at 4 ', sets: [{ reps: 10, weight: 30 }, { reps: 8, weight: 20, drop: true }, { reps: 6, weight: 10, drop: 'yes' }] },
{ kind: 'interval', name: 'Row', sets: [{ distance: 500, drop: true }] },
] }] }, { liftField })
const [lift, piece] = p.blocks[0].items
assert.equal(lift.memo, 'seat at 4')
assert.deepEqual(lift.sets.map(s => s.drop === true), [false, true, false], 'only drop: true is a drop')
assert.ok(!('drop' in lift.sets[0]), 'a working set grew a key')
assert.ok(!('drop' in piece.sets[0]))
assert.ok(!('memo' in piece), 'no note, no key')
// Never a drop on a hold or a circuit's one set, whatever the model wrote.
const held = normalizePrescription({ blocks: [
{ name: 'Core', items: [{ kind: 'lift', exercise: 'plank', measure: 'time', sets: [{ seconds: 45 }, { seconds: 30, drop: true }] }] },
{ name: 'Circuit', circuit: { work: 40, rest: 20, rounds: 3 }, items: [{ kind: 'lift', exercise: KNOWN, sets: [{ reps: 10, drop: true }] }] },
] }, { liftField })
assert.equal(JSON.stringify(held).includes('"drop"'), false, 'a drop on a hold or in a circuit survived')
})

t('addSet: a drop is blank and marked; another set copies the last working set, never the drop', () => {
const p = normalizePrescription({ blocks: [{ name: 'Main', items: [{ kind: 'lift', exercise: KNOWN, sets: [{ reps: 10, weight: 30 }] }] }] }, { liftField })
const id = p.blocks[0].items[0].id
const d = addSet(p, id, { drop: true })
const sets = d.blocks[0].items[0].sets
assert.deepEqual(sets.map(s => [s.reps, s.weight, s.drop === true]), [[10, 30, false], [null, null, true]])
assert.equal(sets[1].id, `${id}s1`, 'the drop was not given a place')
const next = addSet(d, id).blocks[0].items[0].sets.at(-1)
assert.deepEqual([next.reps, next.weight, 'drop' in next], [10, 30, false])
assert.equal(setName(sets, 0), 'Set 1 of 1')
assert.equal(setName(sets, 1), 'Drop set')
assert.equal(setName([{}, {}], 1, { of: false }), 'Set 2')
})

t('a run writes a drop set as a drop; the note stays the plan item\'s alone', () => {
const p = normalizePrescription({ blocks: [{ name: 'Main', items: [{ kind: 'lift', exercise: KNOWN, memo: 'slow', sets: [{ reps: 10, weight: 30 }, { reps: 8, weight: 20, drop: true }] }] }] }, { liftField })
const [a, b] = p.blocks[0].items[0].sets
const steps = prescriptionSteps(p)
let run = emptyRun(1)
run = markSet(run, steps[0], { reps: 10, weight: 30 }, { at: 1, steps })
run = markSet(run, steps[1], { reps: 7, weight: 20 }, { at: 2, steps })
const [row] = runOutputs(p, run, {}).lifts
assert.ok(!('memo' in row), 'the note was copied into a second box')
assert.deepEqual(row.sets, [{ reps: 10, weight: 30 }, { reps: 7, weight: 20, drop: true }])
assert.ok(a && b)
// The runner's "Add a set" from a drop is another drop, from a working set a working set.
const id = p.blocks[0].items[0].id
assert.equal(addSetLike(p, id, { ...b, reps: 6 }).blocks[0].items[0].sets.at(-1).drop, true)
assert.ok(!('drop' in addSetLike(p, id, a).blocks[0].items[0].sets.at(-1)))
})

t('a model revision writes, changes or clears a note; one it left out on a kept exercise stays', () => {
const before = normalizePrescription({ blocks: [{ name: 'Main', items: [
{ kind: 'lift', exercise: KNOWN, uid: 'A', memo: 'seat at 4', sets: [{ reps: 5 }] },
{ kind: 'lift', exercise: KNOWN, uid: 'B', memo: 'left knee', sets: [{ reps: 5 }] },
{ kind: 'lift', exercise: KNOWN, uid: 'C', memo: 'grip wide', sets: [{ reps: 5 }] },
] }] }, { liftField })
const reply = normalizePrescription({ blocks: [{ name: 'Main', items: [
{ kind: 'lift', exercise: KNOWN, uid: 'A', sets: [{ reps: 6 }] },
{ kind: 'lift', exercise: KNOWN, uid: 'B', memo: '', sets: [{ reps: 6 }] },
{ kind: 'lift', exercise: KNOWN, uid: 'C', memo: 'grip narrow now', sets: [{ reps: 6 }] },
{ kind: 'lift', exercise: KNOWN, memo: 'new one', sets: [{ reps: 8 }, { reps: 6, weight: 20, drop: true }] },
] }] }, { liftField })
const got = reviseWeightModes(before, reply, liftField, []).blocks[0].items
assert.deepEqual(got.map(it => it.memo), ['seat at 4', '', 'grip narrow now', 'new one'])
assert.equal(got[3].sets[1].drop, true, 'the model\'s drop set did not survive')
assert.equal(keepMemos(null, reply), reply)
})

console.log(`prescription: ${pass} checks passed`)
24 changes: 24 additions & 0 deletions app/shared.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ test('a shared copy never carries the owner\'s draftId', () => {
assert.equal(mine.data.plan.draftId, 'd-owner-1', 'the owner\'s own plan lost its draft id')
})

test('a copy keeps the owner\'s drop sets as drops, blank, and never the owner\'s note on an exercise', () => {
// Logged lifts.
const mine = gym([{ ...squat([set(5, 110), { reps: 6, weight: 80, drop: true }]), memo: 'belt on' }])
const copy = sharedCopy(mine, { session: workoutCard })
assert.deepEqual(liftsOf(copy), [squat([B, { ...B, drop: true }])])
// A drop the owner adds later arrives as one.
const later = gym([{ ...squat([set(5, 110), { reps: 6, weight: 80, drop: true }, { reps: 4, weight: 60, drop: true }]), memo: 'belt on' }])
assert.deepEqual(liftsOf(copyExercises(editTheirs(copy, [{ ...squat([set(5, 60), B]), memo: 'hers' }]), later)),
[{ ...squat([set(5, 60), B, { ...B, drop: true }]), memo: 'hers' }])
// A plan.
const pres = { title: 'Arms', blocks: [{ id: 'b0', items: [{ id: 'b0i0', kind: 'lift', name: 'Curl', memo: 'slow', sets: [
{ id: 'b0i0s0', reps: 10, weight: 30 }, { id: 'b0i0s1', reps: 8, weight: 20, drop: true }] }] }] }
const planned = sharedCopy({ ...ride, data: { ...ride.data, optId: 'planned', plan: pres } }, { owner: PEOPLE[0] })
const item = planned.data.plan.blocks[0].items[0]
assert.equal('memo' in item, false, 'the owner\'s note went into Sam\'s plan')
// Another WORKING set of the owner's copies Sam's last working set, never Sam's drop.
const theirs = { ...planned, data: { ...planned.data, plan: { ...planned.data.plan, blocks: [{ ...planned.data.plan.blocks[0], items: [{ ...item,
sets: [{ id: 'b0i0s0', reps: 10, weight: 50 }, { id: 'b0i0s1', reps: 8, weight: 35, drop: true }] }] }] } } }
const more = { ...pres, blocks: [{ ...pres.blocks[0], items: [{ ...pres.blocks[0].items[0], sets: [...pres.blocks[0].items[0].sets, { id: 'b0i0s2', reps: 10, weight: 30 }] }] }] }
const grown = copyExercises(theirs, { ...ride, data: { ...ride.data, optId: 'planned', plan: more } }).data.plan.blocks[0].items[0].sets
assert.deepEqual(grown.map(x => [x.reps, x.weight, x.drop === true]), [[10, 50, false], [8, 35, true], [10, 50, false]])
assert.deepEqual(item.sets.map(x => [x.weight, x.drop === true]), [[null, false], [null, true]])
})

test('a shared copy never carries the owner\'s planner conversation or reasoning', () => {
const pres = { title: 'Legs', why: 'your recovery was low', notes: ['yours'], changed: 'swapped', thread: [{ role: 'you', text: 'too much' }],
blocks: [{ id: 'b0', items: [{ id: 'b0i0', kind: 'lift', name: 'Squat', sets: [{ id: 'b0i0s0', reps: 5, weight: 100 }] }] }] }
Expand Down
Loading
Loading