MCP: fixes from review (cardio mode, dead code, Stryker drop, docs)
· entryView was passing `e.target || { id: e.id }` to modeOf, which
doesn't put id on the target when target exists — so a cardio config
saved as {sets, min, speed} (no mode, no id) fell through to 'reps'
and the label came back as "0×0". Now uses the same pattern every
app call site uses (Workout.jsx, Stats.jsx, progression.js):
modeOf({ ...(e.target || {}), id: e.id }). Same fix applied to the
setLabel call right below. Added a regression test using a real
cardio exercise id with a target that has no mode key — would have
caught the original bug.
· requireIso/ISO/fmt/friendlyDate/MUSCLES were unused (zod regexes
cover ISO validation at the SDK layer). Removed, along with the
misplaced comment that described requireIso but sat above entryView.
· estimate_1rm's exercise_id schema description referenced
search_exercises (v1.5) which doesn't exist yet — an LLM reading
the schema would try to call it. Dropped the reference; the
Roadmap section in mcp/README.md drops the same mention.
· resolveUid threw "set OPENGYM_UID to one of: " (empty list) when
there were zero state files but multiple users in db.json — the
files array was empty so files.join(', ') rendered nothing. Now
falls back to the db.json user ids in that branch.
· Dropped Stryker entirely. The MCP SDK's 93 transitive runtime
packages are tolerable since mcp/ is opt-in and never enters
Docker, but a second test toolchain for a 39% mutation score
wasn't carrying its weight next to the plain vitest suite.
Removed .stryker.conf.json, the two Stryker devDeps, the
mutation:test script, the .gitignore entries, and the README
section. mcp/ now has a single devDep (vitest); 0 vulnerabilities
(was 2 moderate).
· CONTRIBUTING.md layout block + a one-line cross-reference in
README.md's Tech section pointing at mcp/README.md, so people can
actually find it.
92 frontend + 33 MCP tests pass.
This commit is contained in:
1 parent
6aaf2a3eea
commit
09949686c2
10 files changed
+173
-2029
No files matched your search
@@ -13,8 +13,3 @@ frontend/dist/
|
||||
node_modules/
|
||||
*.log
|
||||
.DS_Store
|
||||
|
||||
# Mutation-testing artifacts (mcp/) — reports/ is the HTML output, .stryker-tmp/ holds the
|
||||
# backing copy used by `inPlace` mode during a run. Both regenerated on every `stryker run`.
|
||||
mcp/reports/
|
||||
mcp/.stryker-tmp/
|
||||
@@ -12,6 +12,9 @@ api/ backend — server.js (Node, no framework), one dependency (@simplewe
|
||||
web/ multi-stage Dockerfile (builds frontend → nginx) + nginx.conf (serves app, proxies /api).
|
||||
media/ exercise img/gif (gitignored, fetched at runtime).
|
||||
docs/ self-hosting guide.
|
||||
mcp/ optional Model Context Protocol server — read-only stdio bridge for LLM apps
|
||||
(Claude Desktop, Cursor, …) to query a user's workouts/1RM/muscle balance. Not in
|
||||
the Docker build; only runs when an LLM client spawns it. See mcp/README.md.
|
||||
```
|
||||
|
||||
## Running for development
|
||||
|
||||
@@ -179,6 +179,10 @@ lives in pure functions under `frontend/src/lib/` with tests next to them: `npm
|
||||
`frontend/`. Vitest is a dev dependency; the app itself ships no runtime dependencies beyond
|
||||
React, the router and Zustand.
|
||||
|
||||
The same pure helpers power an optional MCP server (`mcp/`) that lets an LLM client like
|
||||
Claude Desktop read your data over stdio — see [mcp/README.md](mcp/README.md). Opt-in, not
|
||||
in the Docker build.
|
||||
|
||||
## Contributing
|
||||
|
||||
Issues and PRs welcome — see [CONTRIBUTING.md](CONTRIBUTING.md). Good first issues: more starter
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
{
|
||||
"$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
|
||||
"packageManager": "npm",
|
||||
"testRunner": "vitest",
|
||||
"vitest": {
|
||||
"configFile": "vitest.config.js",
|
||||
"related": false
|
||||
},
|
||||
"coverageAnalysis": "perTest",
|
||||
"mutate": [
|
||||
"src/state.js",
|
||||
"src/labels.js",
|
||||
"src/tools.js"
|
||||
],
|
||||
"testFiles": [
|
||||
"test/**/*.test.js"
|
||||
],
|
||||
"inPlace": true,
|
||||
"ignorePatterns": [],
|
||||
"thresholds": {
|
||||
"high": 80,
|
||||
"low": 60,
|
||||
"break": 0
|
||||
},
|
||||
"reporters": ["html", "progress", "clear-text"],
|
||||
"concurrency": 2,
|
||||
"disableTypeChecks": true,
|
||||
"cleanTempDir": true
|
||||
}
|
||||
+2
-19
@@ -119,28 +119,11 @@ missing routine, zero-workout history, no synced state, superset links, three 1R
|
||||
tools see consistent values regardless of when the suite runs. The pure lib functions have
|
||||
their own 92 tests in `frontend/src/lib/*.test.js`.
|
||||
|
||||
## Mutation testing
|
||||
|
||||
```bash
|
||||
cd mcp && npm run mutation:test
|
||||
```
|
||||
|
||||
[Stryker](https://stryker-mutator.io) 9.6.1 against the three MCP-only modules in `src/`
|
||||
(`frontend/src/lib/` is excluded — it has its own 92-test suite). Config at
|
||||
`.stryker.conf.json`. Run uses `inPlace: true` so the test file's relative imports
|
||||
`../../frontend/src/lib/*.js` keep resolving; Stryker keeps a backup in `.stryker-tmp/`
|
||||
during the run and restores on exit.
|
||||
|
||||
Baseline: 39% mutation score (333 killed / 330 survived / 184 no-coverage). Most of the
|
||||
survivors are zod schema string literals; the bulk of the no-coverage debt lives in
|
||||
`state.js` (file watching, multi-user resolution, mtime fallback). HTML report at
|
||||
`mcp/reports/mutation/mutation.html` (gitignored, regenerated per run).
|
||||
|
||||
## Roadmap
|
||||
|
||||
- **Done (Phase 1):** read-only stdio, 8 tools, direct `./data` access.
|
||||
- **Phase 1.5:** `progression_next` (what does the policy prescribe next?) + `search_exercises`
|
||||
(search the catalog). No new deps; small surface area.
|
||||
- **Phase 1.5:** a `progression_next` tool (what does the policy prescribe next?). No new
|
||||
deps; small surface area.
|
||||
- **Phase 2:** read+write over stdio. Requires a long-lived token auth path minted from the
|
||||
admin dashboard (new `./data/tokens.json`) and a write-lock against the web UI's read-modify-
|
||||
write of `state-<uid>.json`. Tools: `log_workout`, `add_bodyweight`, `edit_routine`,
|
||||
|
||||
Generated
+130
-1959
File diff suppressed because it is too large.
Load diff
+1
-4
@@ -11,16 +11,13 @@
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node src/index.js",
|
||||
"test": "vitest run",
|
||||
"mutation:test": "stryker run"
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/sdk": "^1.0.4",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@stryker-mutator/core": "^9.6.1",
|
||||
"@stryker-mutator/vitest-runner": "^9.6.1",
|
||||
"vitest": "^4.1.10"
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,12 @@ function resolveUid() {
|
||||
reloadDb()
|
||||
if (_db.users.length === 1) return _db.users[0].id
|
||||
if (_db.users.length === 0) throw new Error(`no openGym users found in ${path.join(DATA_DIR, 'db.json')} — sign in at least once on a device`)
|
||||
// Multiple users in db.json but no state files yet — list their ids, not the (empty)
|
||||
// files list. Hit when accounts exist but none has signed in on a device.
|
||||
throw new Error(
|
||||
`multiple openGym users found — set OPENGYM_UID to one of: ${_db.users.map(u => u.id).join(', ')}\n` +
|
||||
` (look them up in ${path.join(DATA_DIR, 'db.json')} under "users"[].id)`
|
||||
)
|
||||
}
|
||||
throw new Error(
|
||||
`multiple openGym users found — set OPENGYM_UID to one of: ${files.join(', ')}\n` +
|
||||
|
||||
+9
-13
@@ -4,7 +4,7 @@
|
||||
import { z } from 'zod'
|
||||
import { getState, getUser } from './state.js'
|
||||
import {
|
||||
fmt, setLabel, exLine, muscleName, policyName, friendlyDate, friendlyDuration, ratio, muscleOrder
|
||||
setLabel, exLine, muscleName, policyName, friendlyDuration, ratio, muscleOrder
|
||||
} from './labels.js'
|
||||
import {
|
||||
modeOf, workoutVolume, setsDone, effectiveRoutine, effectiveRoutineId
|
||||
@@ -13,21 +13,17 @@ import { EXIDX, exOr } from '../../frontend/src/lib/exercises.js'
|
||||
import {
|
||||
estimate1RM, best1RM, e1rmSeries, FORMULAS, DEFAULT_FORMULA, REP_CAP
|
||||
} from '../../frontend/src/lib/onerm.js'
|
||||
import { loadOfWorkouts, rankOf, levelsOf, MUSCLES } from '../../frontend/src/lib/muscles.js'
|
||||
import { loadOfWorkouts, rankOf, levelsOf } from '../../frontend/src/lib/muscles.js'
|
||||
|
||||
/* ---------- helpers ---------- */
|
||||
|
||||
const ISO = /^\d{4}-\d{2}-\d{2}$/
|
||||
function requireIso(v, name) {
|
||||
const s = typeof v === 'string' ? v : ''
|
||||
if (s && !ISO.test(s)) throw new Error(`${name} must be YYYY-MM-DD (got ${JSON.stringify(v)})`)
|
||||
return s || null
|
||||
}
|
||||
|
||||
// Drops ISO dates so an LLM passing 'yesterday' is rejected.
|
||||
function entryView(e, S) {
|
||||
const ex = exOr(e.id)
|
||||
const mode = modeOf(e.target || { id: e.id })
|
||||
// Spread id into the cfg the way every call site in the app does (Workout.jsx, Stats.jsx,
|
||||
// progression.js) — the sheet saves a cardio target as {sets, min, speed} with no id and no
|
||||
// mode, so modeOf needs the id to fall through to isCardio(id).
|
||||
const cfg = { ...(e.target || {}), id: e.id }
|
||||
const mode = modeOf(cfg)
|
||||
return {
|
||||
id: e.id,
|
||||
name: ex.n,
|
||||
@@ -36,7 +32,7 @@ function entryView(e, S) {
|
||||
target: e.target || null,
|
||||
sets: (e.sets || []).map(s => ({
|
||||
done: !!s.done,
|
||||
label: setLabel(e.id, { ...s, done: undefined }, e.target || { id: e.id }),
|
||||
label: setLabel(e.id, { ...s, done: undefined }, cfg),
|
||||
w: Number(s.w) || 0,
|
||||
r: Number(s.r) || 0,
|
||||
sec: Number(s.sec) || 0,
|
||||
@@ -279,7 +275,7 @@ export const estimate1rm = {
|
||||
name: 'estimate_1rm',
|
||||
description: `Estimate one-rep max using Epley, Brzycki or Lombardi formulas. If an exercise_id is given, returns the all-time best estimate for that exercise with the source set (weight × reps + date) and the trend across history. If no exercise_id is given, returns a PR table across all reps-mode exercises (sorted highest first). Refuses to guess above ${REP_CAP} reps — above that, formulas diverge past 10% and "work capacity" is read instead of "maximal strength".`,
|
||||
schema: {
|
||||
exercise_id: z.string().optional().describe('An exercise id from list_routines, get_workout entries, or search_exercises (v1.5). If omitted, returns a full PR table.'),
|
||||
exercise_id: z.string().optional().describe('An exercise id from list_routines or get_workout entries. If omitted, returns a full PR table.'),
|
||||
formula: z.enum(['epley', 'brzycki', 'lombardi']).optional().describe(`Formula to use. Defaults to ${DEFAULT_FORMULA}.`)
|
||||
},
|
||||
handler: ({ exercise_id, formula }) => {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// (rest-day override, missing routine, zero-workout history, no synced state, superset links).
|
||||
import { describe, beforeAll, afterAll, beforeEach, test, expect, vi } from 'vitest'
|
||||
import { buildDemoState } from '../../frontend/src/lib/demoSeed.js'
|
||||
import { EXDB } from '../../frontend/src/lib/exercises.js'
|
||||
import { _seedStateForTests } from '../src/state.js'
|
||||
import { TOOLS } from '../src/tools.js'
|
||||
|
||||
@@ -281,6 +282,23 @@ describe('get_workout', () => {
|
||||
expect(w.entries[2].sets[0].label).toBe('1:30 · 20') // weighted plank
|
||||
expect(w.entries[3].sets[0].label).toBe('20 min @ 8 km/h') // cardio
|
||||
})
|
||||
|
||||
test('infers cardio mode from the exercise id when the target has no mode key', () => {
|
||||
// Reproduces the review bug: the sheet saves a cardio target as {sets, min, speed} with
|
||||
// no mode and no id. modeOf must fall through to isCardio(id), which needs the id on the
|
||||
// cfg — entryView has to spread id into the cfg the way every app call site does.
|
||||
const CARDIO_ID = EXDB.find(e => e.bp === 'cardio').id
|
||||
S.workouts = [{
|
||||
id: 'synth-cardio', d: '2026-07-25', start: 0, end: 1800000, routineId: 'x', name: 'Synth',
|
||||
bw: 78, vol: 0, prs: [],
|
||||
entries: [
|
||||
{ id: CARDIO_ID, target: { sets: 1, min: 20, speed: 8 }, sets: [{ min: 20, speed: 8, done: true }] }
|
||||
]
|
||||
}]
|
||||
const w = call('get_workout', { date: '2026-07-25' })
|
||||
expect(w.entries[0].mode).toBe('cardio')
|
||||
expect(w.entries[0].sets[0].label).toBe('20 min @ 8 km/h')
|
||||
})
|
||||
})
|
||||
|
||||
/* ---------- get_bodyweight ---------- */
|
||||
|
||||
Reference in new issue
Block a user