MCP: die zweite Einheit an einem Tag ist erreichbar, und ein leeres 1RM sagt warum
Zwei Befunde aus dem Parity-Durchlauf gegen echte Daten. Die Arithmetik stimmte ueberall (rund 120 Werte gegen eine unabhaengige Nachrechnung, null Abweichung) — diese beiden nicht. get_workout nahm `.find(x => x.d === date)`. Wer morgens hebt und abends laeuft, hat zwei Einheiten am selben Datum, und die zweite war ueber gar keinen Weg erreichbar: es gab nirgends eine id, und die Frage nach dem Lauf bekam die Zahlen des Zugtrainings — vollkommen selbstbewusst vorgetragen. list_workouts liefert jetzt `id`, get_workout nimmt `workout_id` oder `date`, und bei zwei Treffern am selben Tag antwortet es mit beiden zur Auswahl statt zu raten. Und `best: null` hatte zwei gegensaetzliche Ursachen in einer Form: nie trainiert, oder immer ueber der 12-Wiederholungs-Grenze. Eine Wade, die seit Monaten mit 15ern im Log steht, las sich damit als "keine Aufzeichnungen". no_estimate_reason unterscheidet die beiden, und formula_note steht jetzt auch auf diesem Zweig — bisher gab es die Erklaerung nur in der PR-Tabelle. Drei Regressionstests dazu (36 statt 33), mcp/README zu get_workout nachgezogen.
This commit is contained in:
1 parent
e007f76d43
commit
551b072c54
3 files changed
+104
-6
No files matched your search
+1
-1
@@ -75,7 +75,7 @@ Eight read-only tools in v1:
|
||||
| `get_routine` | What does the Push Day routine prescribe? (sets/reps/weight per exercise) |
|
||||
| `get_week_plan` | What's on my plan this week, including today with any date-specific override? |
|
||||
| `list_workouts` | Recent sessions — newest first, with dates, sets done/planned, volume, duration, PRs. |
|
||||
| `get_workout` | Full set-by-set breakdown of one date's session. |
|
||||
| `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. |
|
||||
| `estimate_1rm` | All-time best 1RM for an exercise + the trend, or a PR table across all exercises. |
|
||||
| `muscle_balance` | Which muscles I've trained this week/month/all-time, ranked + which I've neglected. |
|
||||
|
||||
+49
-5
@@ -189,6 +189,10 @@ export const listWorkouts = {
|
||||
total_count: all.length,
|
||||
returned_count: filtered.length,
|
||||
workouts: filtered.map(w => ({
|
||||
// The only thing that identifies a session uniquely. Two workouts on one day is
|
||||
// ordinary — a lifting session and an evening run — and without an id here the second
|
||||
// one cannot be asked about at all.
|
||||
id: w.id || null,
|
||||
date: w.d,
|
||||
routine_id: w.routineId || null,
|
||||
routine_name: w.name || null,
|
||||
@@ -215,14 +219,44 @@ function plannedSets(w) {
|
||||
/** get_workout — full entry/set breakdown for one date. */
|
||||
export const getWorkout = {
|
||||
name: 'get_workout',
|
||||
description: 'Get the full breakdown of one workout: every exercise, its mode (reps/time/cardio), the target, and per-set labels (e.g. "5 @ 60 kg", "1:30 · 20 kg"). Use list_workouts first if you don\'t know the exact date.',
|
||||
schema: { date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).describe('The workout date as YYYY-MM-DD') },
|
||||
handler: ({ date }) => {
|
||||
description: 'Get the full breakdown of one workout: every exercise, its mode (reps/time/cardio), the target, and per-set labels (e.g. "5 @ 60 kg", "1:30 · 20 kg"). Identify it by workout_id (from list_workouts) or by date. Use list_workouts first if you don\'t know either.',
|
||||
schema: {
|
||||
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe('The workout date as YYYY-MM-DD. If two sessions share that date, the answer lists them instead and asks for a workout_id.'),
|
||||
workout_id: z.string().min(1).optional().describe('The id from list_workouts. Preferred: it names one session even on a day with two.')
|
||||
},
|
||||
handler: ({ date, workout_id }) => {
|
||||
const S = getState()
|
||||
if (!S) return noState()
|
||||
const w = (S.workouts || []).find(x => x.d === date)
|
||||
if (!w) { const e = new Error(`no workout on ${date}`); e.code = 'ENOENT'; throw e }
|
||||
const workouts = S.workouts || []
|
||||
let w
|
||||
if (workout_id) {
|
||||
w = workouts.find(x => x.id === workout_id)
|
||||
if (!w) { const e = new Error(`no workout with id ${workout_id}`); e.code = 'ENOENT'; throw e }
|
||||
} else if (date) {
|
||||
const sameDay = workouts.filter(x => x.d === date)
|
||||
if (!sameDay.length) { const e = new Error(`no workout on ${date}`); e.code = 'ENOENT'; throw e }
|
||||
// Answering with the first of two is how a question about the evening run gets the
|
||||
// morning's lifting numbers, stated with total confidence. Say there are two instead.
|
||||
if (sameDay.length > 1) {
|
||||
return {
|
||||
ambiguous: true,
|
||||
date,
|
||||
message: `${sameDay.length} workouts were logged on ${date} — call get_workout again with one of these workout_id values.`,
|
||||
workouts: sameDay.map(x => ({
|
||||
id: x.id || null,
|
||||
routine_name: x.name || null,
|
||||
sets_done: setsDone(x),
|
||||
volume: workoutVolume(x),
|
||||
duration: x.end && x.start ? friendlyDuration(x.end - x.start) : null
|
||||
}))
|
||||
}
|
||||
}
|
||||
w = sameDay[0]
|
||||
} else {
|
||||
const e = new Error('get_workout needs either workout_id or date'); e.code = 'EINVAL'; throw e
|
||||
}
|
||||
return {
|
||||
id: w.id || null,
|
||||
date: w.d,
|
||||
routine_id: w.routineId || null,
|
||||
routine_name: w.name || null,
|
||||
@@ -286,11 +320,21 @@ export const estimate1rm = {
|
||||
const ex = exOr(exercise_id)
|
||||
const best = best1RM(S, exercise_id, f)
|
||||
const series = e1rmSeries(S, exercise_id, f)
|
||||
// A null best has two very different causes: never trained, or trained only above the
|
||||
// rep cap. Without saying which, an exercise logged for years at 15 reps reads as "no
|
||||
// records for calf raise" — a confident statement about the opposite of the truth.
|
||||
const trainedAtAll = (S.workouts || []).some(w =>
|
||||
(w.entries || []).some(e => e.id === exercise_id && (e.sets || []).some(s => s.done)))
|
||||
// w/r (not weight/reps) matches pr_table and entry-view — every set in the API surface uses the same couple.
|
||||
return {
|
||||
exercise: { id: exercise_id, name: ex.n, body_part: ex.bp || null },
|
||||
formula: f,
|
||||
formula_note: `Estimates use the ${f} formula. Cap at ${REP_CAP} reps applies; r=1 is treated as the measurement, not an estimate.`,
|
||||
best: best ? { est: best.est, w: best.w, r: best.r, date: best.d } : null,
|
||||
no_estimate_reason: best ? null
|
||||
: trainedAtAll
|
||||
? `This exercise has logged sets, but none of them qualify: every set was above the ${REP_CAP}-rep cap, or carried no weight. That is not the same as never having trained it.`
|
||||
: 'No completed sets logged for this exercise.',
|
||||
trend: series.map(p => ({ date: p.d, est: p.y, w: p.w, r: p.r }))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,6 +267,32 @@ describe('get_workout', () => {
|
||||
expect(() => call('get_workout', { date: '1900-01-01' })).toThrow()
|
||||
})
|
||||
|
||||
test('two sessions on one day are both reachable, and the date alone never picks one silently', () => {
|
||||
// Lifting in the morning, a run in the evening: ordinary, and it used to make the second
|
||||
// session unreachable while questions about it were answered with the first one's numbers.
|
||||
const day = '2026-07-26'
|
||||
S.workouts.push(
|
||||
{ id: 'w-morning', d: day, name: 'Pull', start: 1000, end: 1000 + 40 * 60000, vol: 0, prs: [], entries: [] },
|
||||
{ id: 'w-evening', d: day, name: 'Cardio', start: 2000, end: 2000 + 55 * 60000, vol: 0, prs: [], entries: [] }
|
||||
)
|
||||
_seedStateForTests(S)
|
||||
|
||||
const amb = call('get_workout', { date: day })
|
||||
expect(amb.ambiguous).toBe(true)
|
||||
expect(amb.workouts.map(w => w.id).sort()).toEqual(['w-evening', 'w-morning'])
|
||||
|
||||
// Each is retrievable by the id the ambiguous answer handed back.
|
||||
expect(call('get_workout', { workout_id: 'w-evening' }).routine_name).toBe('Cardio')
|
||||
expect(call('get_workout', { workout_id: 'w-morning' }).routine_name).toBe('Pull')
|
||||
// And list_workouts carries the id, or nothing above could ask for one.
|
||||
expect(call('list_workouts', {}).workouts.every(w => 'id' in w)).toBe(true)
|
||||
})
|
||||
|
||||
test('an unknown workout_id is an error, not the wrong workout', () => {
|
||||
expect(() => call('get_workout', { workout_id: 'nope' })).toThrow()
|
||||
expect(() => call('get_workout', {})).toThrow()
|
||||
})
|
||||
|
||||
test('renders reps/time/cardio set labels in the lib format on a synthetic workout', () => {
|
||||
// The starter routine has only reps-mode exercises — synthesise a workout that includes a
|
||||
// timed plank and a cardio row so the label rendering is actually exercised.
|
||||
@@ -389,6 +415,7 @@ describe('estimate_1rm', () => {
|
||||
|
||||
test('exercises with no reps-mode history get null best + empty trend (not a 0 estimate)', () => {
|
||||
S.workouts = []
|
||||
_seedStateForTests(S)
|
||||
const r = call('estimate_1rm', { exercise_id: LEG_PRESS_ID })
|
||||
expect(r.best).toBeNull()
|
||||
expect(r.trend).toEqual([])
|
||||
@@ -396,6 +423,33 @@ describe('estimate_1rm', () => {
|
||||
expect(table).toEqual([])
|
||||
})
|
||||
|
||||
test('a null estimate says which kind of null it is', () => {
|
||||
// "Never trained" and "trained, but always above the rep cap" are opposite facts that both
|
||||
// arrive as best: null. Undistinguished, the second one reads as the first and an assistant
|
||||
// reports "no records" for an exercise in the log every week.
|
||||
S.workouts = [{
|
||||
id: 'w-highrep', d: '2026-07-26', name: 'Accessories', start: 1000, end: 1000 + 20 * 60000,
|
||||
vol: 0, prs: [],
|
||||
entries: [{
|
||||
id: LEG_PRESS_ID, target: { sets: 2, reps: 20, mode: 'reps' },
|
||||
sets: [{ w: 40, r: 20, done: true }, { w: 40, r: 18, done: true }]
|
||||
}]
|
||||
}]
|
||||
_seedStateForTests(S)
|
||||
|
||||
const capped = call('estimate_1rm', { exercise_id: LEG_PRESS_ID })
|
||||
expect(capped.best).toBeNull()
|
||||
expect(capped.no_estimate_reason).toMatch(/above the \d+-rep cap/)
|
||||
|
||||
// An exercise that genuinely has no sets must not borrow that explanation.
|
||||
const never = call('estimate_1rm', { exercise_id: '0684' })
|
||||
expect(never.best).toBeNull()
|
||||
expect(never.no_estimate_reason).toMatch(/No completed sets/)
|
||||
|
||||
// And the cap is stated on this branch at all, which it never used to be.
|
||||
expect(capped.formula_note).toMatch(/Cap at/)
|
||||
})
|
||||
|
||||
test('all three formulas are accepted', () => {
|
||||
['epley', 'brzycki', 'lombardi'].forEach(f => {
|
||||
const r = call('estimate_1rm', { exercise_id: LEG_PRESS_ID, formula: f })
|
||||
|
||||
Reference in new issue
Block a user