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
37 changes: 33 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ reasons behind the design, and the things that have been removed on purpose.
| The session sheet | `app/src/sheet.jsx`, `app/src/sheetparts.jsx` | `SessionSheet` (header, body, footer) and `runnable`; Today (`tabs.jsx`) opens it. `sheetparts.jsx` is what every sheet of a workout shares (#80): `DoneChip`, `useDoneFlip` (the flip and its Undo toast) and `SheetStart` (the one footer action), used by the owner's sheet and `PersonEntrySheet`. The row meta line both use is `app/src/metaline.jsx`. Twins: `mobile/src/features/sheet.tsx`, `sheetparts.tsx`. |
| Prescription editor | `app/src/editor.jsx` | `PrescriptionEditor` (`doing` on the sheet, #79), its blocks and items, `BlockMenu` (a block's ⋯), `blockTag`, `PieceAdder`, `BlockQuota`: the one editor Plan a workout and the sheet share. Block operations are `addBlock`, `renameBlock`, `noteBlock`, `removeBlock`, `moveBlock` in `lib/prescription.js`. Twin: `mobile/src/features/editor.tsx` (the ⋯ is the system action sheet). |
| Day switcher | `app/src/tabs.jsx` (`DaySwitcher`; `dayWords`, `isoShift` in `lib/dates.js`) | ‹ day › in words; Today's title and the rest day's date (§10.9). The phone's is `mobile/src/ui/DayStepper.tsx`. |
| Session history | `app/src/lib/history.js` | `priorSessions`: which earlier entries are THIS workout ("The last 5 times you did this"). A card by its ids (`aka`, `priorIds`); a planned workout by its title or mostly the same exercises; a free-form one by its activity (#74). |
| Session history | `app/src/lib/history.js` | `priorSessions`: which earlier entries are THIS workout ("The last 5 times you did this"), before the one shown in the day list's order (#96: an earlier day, or an earlier session of the same day). A card by its ids (`aka`, `priorIds`); a planned workout by its title or mostly the same exercises; a free-form one by its activity (#74). |
| Toasts | `app/src/toast.jsx`, `app/src/lib/toast.js` | Mobile's API (`pushToast`, `pushError`) on the web: a removal's Undo, a failed save's Retry. |
| Log feed | `app/src/log.jsx` | Newest first; the open sheet is keyed by ID and is `LogSheet`: Today's `SessionSheet`, with no Start (#79). |
| Progress | `app/src/lib/scope.js`, `app/src/lib/metrics.js`, `app/src/progress.jsx` | Charts declare when they apply. |
Expand Down Expand Up @@ -444,9 +444,33 @@ section keeps only the keys `blank()` names, so a removed setting is dropped on
through the owner's store or cache, so logs still never mix on a device. The server
refuses non-owners, acting-as, the owner's own log, and any live entry without
`sharedFrom` (`not-shared`); a sync never writes into an entry they logged themselves.
Those writes fire no habit sync and no push. Taking someone off tombstones their copy
only if they have marked nothing (`hasOwnMarks`; copied lifts with nothing marked on
them are not marks), otherwise it asks. WHOOP/Strava stay off on their side.
Those writes fire no habit sync and no push. **Taking someone off never deletes what
they logged** (#96): a copy they have marked (`hasOwnMarks`; copied lifts with nothing
marked on them are not marks) stays in their log as their own workout, unlinked (the
server flags it not in step); one they never touched is tombstoned. No question either
way: a toast says which, with Undo (`removePerson`, `takeOffWords`, `undoTakeOff`). It
used to tombstone a logged copy after a bare browser confirm, with no Undo. A kept copy
is then theirs: the server stamps it `sharedFrom.off` when the link goes (`flagCopy`,
`withOff`; cleared when a link is back) and refuses the owner's writes to it through the
people route (409 `not-linked`). A copy never linked yet is not refused, because adding
someone writes the copy first and links it second. WHOOP/Strava stay off on their side.
- **A copy shows its person nothing the planner wrote for the owner** (#96): the plan's
`why`, `notes`, `thread`, `ask` and `changed`, and the note on each exercise and set
("3x10 at 95 was RPE 6 last time"), are the owner's (the owner's recovery and weights,
in the owner's words). A share leaves them out (`theirPlan`), and the sheet and the
runner read a plan through `planShown(entry)`, which hides them on any entry with
`sharedFrom`, so copies shared before the share stripped them are covered without
rewriting them. A block's note stays: it is the workout's prose and shared structure.
**Display only**: every write from those screens (the editor on either side, the
runner's added set) goes through `withStoredWords`, which puts each hidden word back
byte for byte, so an edit lands on the stored plan and erases nothing (review 2: the
first version saved the filtered plan and lost the notes for good). What the person
asks the model on their own copy is theirs:
the sheet stamps it `ownWords` (`ownWordsOn`) and such a plan is shown whole.
An older copy's form also reads the activity its plan files it under (`formOut` in
lib/category.js, the form's twin of `filedOut`), so it no longer asks "What kind of
workout was this?" with nothing picked. A removal on the other person's own copy says
the synced line about the owner (`syncedSides`), because it reaches the owner's log too.
- Pinned by `server/sharedsync.test.js`, the `shared workouts:` and `sync:` steps in
`server/http.test.js`, `app/shared.test.js`, and the `SessionSheet(… sharing chip …)`,
`SharePanel(…)`, person bar, `PersonSwitch(…)` and `TheirSide` smoke cases.
Expand Down Expand Up @@ -513,6 +537,11 @@ section keeps only the keys `blank()` names, so a removed setting is dropped on
as "Sam already logged it" / "Sam is running it": not a miss, no Retry. Totals are
read off what is there (`run.circuitTimes`, set per block), never added to. The
shared-sync rule again: logged data is never removed by anyone else's write.
A blank is filled in the shape the CLOCK ran it (#96): the result names how each
exercise was timed (`togetherItems`, `by`), and one counted in reps on the side that
ran it is a count where this side's own timing is blank (`endCircuit` `counted`),
never a hold of the seconds spent on its reps. A side that says reps or seconds
keeps its own shape.
2. **It decides from fresh data.** Someone else's side is re-read from the server right
before it is written and rule 1 applied to THAT, never to a copy on screen that may
hold a write that never landed. This run's key (the clock's `startedAt`,
Expand Down
44 changes: 43 additions & 1 deletion app/circuit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { localIso } from './src/lib/dates.js'
import { liftMeasure, liftSummary } from './src/lib/lifts.js'
import {
shareCircuit, togetherWrite, togetherSides, togetherWords, togetherSaid, applyRun, notePending, pendingFor, retryPending,
shareCircuit, togetherItems, togetherWrite, togetherSides, togetherWords, togetherSaid, applyRun, notePending, pendingFor, retryPending,
sideTaken, PENDING_KEY, STALE_CLOCK_MS,
} from './src/lib/trainer.js'
import { fillOut } from './src/lib/prescription.js'
Expand Down Expand Up @@ -487,6 +487,48 @@ ta('together, finished: both done and ended, the same seconds, one write each, e
assert.deepEqual(togetherSaid('you', [{ id: 'sam', name: 'Sam', status: 'logged' }]).head, 'Logged for you and Sam')
})

ta('together: a count on the side that ran it is a count on the other, even where it arrived blank (#96)', async () => {
const { result: old, owner } = finished()
// How the runner names the exercises now: how the clock ran each one.
const result = { ...old, items: togetherItems(owner.data.plan.blocks[0]) }
assert.deepEqual(result.items.map(x => x.by), ['reps', 'time'])
// Sam's crunch came over the sync blank (no reps, no seconds): the circuit's own timing on Sam's side.
const sam = samOf()
const blankPlan = normalizePrescription({ title: 'Abs', blocks: [{ uid: 'B1', name: 'Abs', circuit: { work: 40, rest: 20, rounds: 2, countIn: 0 }, items: [
{ uid: 'CR', kind: 'lift', name: 'Crunch', exercise: 'crunch', sets: [{}] },
{ uid: 'PL', kind: 'lift', name: 'Plank', exercise: 'plank', sets: [{ seconds: 30 }] },
] }] }, { liftField })
assert.equal(circuitTiming(blankPlan.blocks[0].items[0]).by, 'circuit', 'the fixture is not a blank arrival')
const srv = server({ ...sam, data: { ...sam.data, plan: blankPlan } })
await share(srv, result, owner)
assert.deepEqual(rowsOf(srv.entry), [['crunch', [[null, '', ''], [null, '', '']]], ['plank', [[30, null, ''], [30, null, '']]]],
'the crunches landed as holds of the seconds spent on them')
assert.equal(srv.entry.data.run.sets[blankPlan.blocks[0].items[0].sets[0].id].seconds, undefined)
})

ta('together: a side that holds what the other counted keeps its own shape, seconds (#96 review)', async () => {
const { result: old, owner } = finished()
const result = { ...old, items: togetherItems(owner.data.plan.blocks[0]) }
// The owner counts the crunches; Sam holds them 45 s (a wall sit counted one way, held the other).
const sam = samOf()
const held = normalizePrescription({ title: 'Abs', blocks: [{ uid: 'B1', name: 'Abs', circuit: { work: 40, rest: 20, rounds: 2, countIn: 0 }, items: [
{ uid: 'CR', kind: 'lift', name: 'Crunch', exercise: 'crunch', sets: [{ seconds: 45 }] },
{ uid: 'PL', kind: 'lift', name: 'Plank', exercise: 'plank', sets: [{ seconds: 30 }] },
] }] }, { liftField })
assert.equal(circuitTiming(held.blocks[0].items[0]).by, 'time')
const srv = server({ ...sam, data: { ...sam.data, plan: held } })
await share(srv, result, owner)
assert.deepEqual(rowsOf(srv.entry)[0], ['crunch', [[25, null, ''], [25, null, '']]], 'Sam\'s hold became blank reps')
// And Sam counting what the owner held stays a count.
const counts = normalizePrescription({ title: 'Abs', blocks: [{ uid: 'B1', name: 'Abs', circuit: { work: 40, rest: 20, rounds: 2, countIn: 0 }, items: [
{ uid: 'CR', kind: 'lift', name: 'Crunch', exercise: 'crunch', sets: [{ reps: 15 }] },
{ uid: 'PL', kind: 'lift', name: 'Plank', exercise: 'plank', sets: [{ reps: 10 }] },
] }] }, { liftField })
const srv2 = server({ ...sam, data: { ...sam.data, plan: counts } })
await share(srv2, result, owner)
assert.deepEqual(rowsOf(srv2.entry)[1], ['plank', [[null, '', ''], [null, '', '']]], 'Sam\'s count became a hold')
})

ta('together, stopped early: what was done lands on both, the same, one write', async () => {
// The crunches tapped at 25 s, 20 s rest, then stopped 12 s into the plank.
const { result, owner } = hosted(throughTo(25 + 20 + 12))
Expand Down
28 changes: 28 additions & 0 deletions app/history.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,34 @@ test('times you DID it: not a plan still to come or untouched today, not one mar
assert.deepEqual(dates(priorSessions([...LOGBOOK, ahead, undone], PLANNED, PULL.id)), ['2026-10-20 Pull day', '2026-10-10 Pull day'])
})

test('a past workout’s last times are the ones before it, never after (#96)', () => {
const oct20 = LOGBOOK.find(e => e.date === '2026-10-20')
assert.deepEqual(dates(priorSessions(LOGBOOK, PLANNED, oct20.id)), ['2026-10-10 Pull day'], 'Nov 7’s Pull listed as an earlier time')
// The same day, in the day list's order: the main session, then the extras by id.
const day = (id, slot, name) => ({ ...planned('2026-11-12', name, ['bent-over-row', 'dumbbell-curl', 'pull-up'], {}), id,
data: { ...planned('2026-11-12', name, ['bent-over-row', 'dumbbell-curl', 'pull-up']).data, slot } })
const am = day('daily-2026-11-12', 'main', 'Pull AM')
const pm = day('daily-2026-11-12-planned', 'extra', 'Pull PM')
const late = day('daily-2026-11-12-planned-2', 'extra', 'Pull late')
const log = [...LOGBOOK, am, pm, late]
assert.deepEqual(dates(priorSessions(log, PLANNED, pm.id)).slice(0, 2), ['2026-11-12 Pull AM', '2026-11-07 Pull'], 'earlier today is gone, or not first')
assert.deepEqual(dates(priorSessions(log, PLANNED, late.id)).slice(0, 3), ['2026-11-12 Pull PM', '2026-11-12 Pull AM', '2026-11-07 Pull'])
assert.equal(dates(priorSessions(log, PLANNED, am.id)).some(d => d.startsWith('2026-11-12')), false, 'a later session of the same day listed as before')
// Where both say when they started, that decides: an extra done at seven beats the main one at six in the evening.
const at = (e, iso, how) => ({ ...e, data: { ...e.data, ...(how === 'run' ? { run: { startedAt: Date.parse(iso) } } : { out: { ...e.data.out, whoop: { start: iso } } }) } })
const timed = [...LOGBOOK, at(am, '2026-11-12T18:00:00Z', 'run'), at(pm, '2026-11-12T07:00:00Z', 'whoop'), late]
assert.deepEqual(dates(priorSessions(timed, PLANNED, am.id)).slice(0, 2), ['2026-11-12 Pull PM', '2026-11-07 Pull'], 'the earlier start is not "before"')
assert.equal(dates(priorSessions(timed, PLANNED, pm.id)).some(d => d.startsWith('2026-11-12')), false)
// Untimed itself, the late extra still comes after both by the day list; between them, their times say
// the main one (18:00) is the newer.
assert.deepEqual(dates(priorSessions(timed, PLANNED, late.id)).slice(0, 3), ['2026-11-12 Pull AM', '2026-11-12 Pull PM', '2026-11-07 Pull'])
// A card with no entry to stand on is not bounded.
const board = { id: 'board' }
const e = (date) => ({ id: date, kind: 'daily', date, data: { optId: 'board', done: true, out: {} } })
assert.equal(priorSessions([e('2026-11-01'), e('2026-10-01')], board, null).length, 2)
assert.deepEqual(priorSessions([e('2026-11-01'), e('2026-10-01')], board, '2026-10-01').map(x => x.date), [])
})

test('a card that is not a container is still its own history, renames and splits included', () => {
const board = { id: 'board', aka: ['old-board'], priorIds: ['hard-home'] }
assert.deepEqual(priorIdsOf(board), ['board', 'old-board', 'hard-home'])
Expand Down
Loading
Loading