Files
wodify-cli/CLAUDE.md
T

16 KiB

wodify — agent notes

Read-only client for the Wodify athlete app (claycrossfit.wodify.com), built so an agent can answer "what's the workout / what did I book / who's coaching / who else is going" without driving a browser at query time.

Replaces browser automation, which was slow and burned a lot of tokens rendering a SPA just to read text back out of the DOM.

Hard rule: read-only

This client must never reserve, cancel, check in, log results, accept terms, change settings, or buy anything. The credential it uses is a full-session login — Wodify issues no read-only token — so nothing at the credential layer enforces this. Enforcement lives in two places, and both must stay:

  1. actions.py::ACTIONS — an explicit allowlist. Nothing not registered can be called.
  2. actions.py::assert_read_only — rejects any path containing a write marker (Create, Save, Reserve, Cancel, SignIn, …), applied even to allowlisted entries.

tests/test_actions.py asserts both, including that known write endpoints are refused. If you add an action, add a test.

How it works

Wodify's athlete app is OutSystems Reactive. Its data actions are plain JSON POSTs:

POST https://<host>/WodifyClient/screenservices/<Module>/<Screen>/<Action>
  X-CSRFToken: <28 chars>
  Cookie: nr1W_Theme_UI=…; nr2W_Theme_UI=…; AuthenticationToken=…
  {"versionInfo": {"moduleVersion": …, "apiVersion": …},
   "viewName": …, "inputParameters": {…}}

Two phases:

Phase Cost Needs a browser?
prime rare — once, then on Wodify redeploys yes, via CDP
query one HTTP POST per question no

prime attaches to a logged-in Chrome over CDP, captures the cookies, the CSRF token, and each action's versionInfo + inputParameters shape, and writes them to a cache. query then does pure stdlib HTTP.

Why prime needs a browser

  • The session bearer nr1W_Theme_UI is HttpOnly (184 chars). document.cookie cannot read it, so it cannot be exported by hand — this is why an earlier cookie-paste approach was impossible, not merely inconvenient.
  • X-CSRFToken is not in localStorage, cookies, or any JS global. It only appears on outbound requests, so it has to be sniffed.
  • apiVersion is per-action, not global (two actions returned w5JqiO_2RpM6VdmR6V470Q and hBUtX6paK6XbMlXso4zBcw). Each endpoint needs its own.

Self-healing

Every response carries versionInfo: {hasModuleVersionChanged, hasApiVersionChanged}. When either flips true — or a call returns 401/403 — the cache is stale and prime must re-run. client.py raises VersionStale / SessionExpired rather than returning wrong data.

Dependencies

The query path is stdlib-only (urllib, json, gzip) — deliberate, so the hot path has no install step. prime needs websockets (declared as the prime extra) because CDP is a WebSocket protocol.

Layout

src/wodify/
  config.py    host, CDP URL, cache path, all env-overridable
  actions.py   read-only allowlist + write guard
  cdp.py       minimal CDP client (prime only)
  prime.py     capture cookies / CSRF / versionInfo -> cache
  client.py    HTTP query path (stdlib)
  store.py     SQLite cache (sqlite3, stdlib)
  service.py   cache-through data access -- all fetches go through here
  render.py    compact text output (token-efficient, not a DOM dump)
  listcmd.py   the `list date` / `list workout` commands
  cli.py       python -m wodify <cmd>

The list interface

wodify list date 2026-07-25        # classes: time, coach, booked/max, title, duration, ID
wodify list workout 190917816      # attendee names + the workout for that class

list date prints IDs; list workout <id> consumes one. Both accept --refresh (bypass cache), --json, and list workout also takes --notes for the coach's brief.

A class ID resolves to nothing on its own — it is per-occurrence, and carries neither date nor program. list date indexes the day's classes into SQLite, and list workout looks the ID up there. Querying an ID for a day never listed returns a message saying exactly that.

SQLite cache

~/.cache/wodify/wodify.db (override with WODIFY_DB), created mode 600 — it holds other members' names.

Table Holds
payloads raw action responses, keyed e.g. schedule:2026-07-25, stamped with the local date
classes one row per class occurrence, so an ID resolves to date + program + limit

Schedules and attendee rosters have a one-hour TTL; workout content remains cached for the local calendar day. All payloads expire at midnight. The class-ID index is not subject to the hourly TTL. bookings queries bypass the payload cache entirely. Use --refresh before attendance decisions: even an hourly cache can predate a recent sign-in. Every command prints whether the answer came from cache or the wire.

Only service.py fetches, so caching cannot be forgotten at a call site.

Environment

Var Default Meaning
WODIFY_HOST claycrossfit.wodify.com tenant host
WODIFY_CDP_URL http://127.0.0.1:9222 Chrome CDP root for prime
WODIFY_CACHE ~/.cache/wodify/session.json cached headers, mode 600

The cache holds live session credentials. Mode 600, never committed (.gitignore), never logged. Anything that prints it is a bug.

Priming from this machine

The logged-in Chrome profile lives on the CDP host, not here. Tunnel first:

ssh -L 9222:127.0.0.1:9222 <cdp-host>

Then python -m wodify prime works locally against the remote profile.

Status

Working, verified live (2026-07-25)

prime and bookings run end-to-end against the real service with no browser at query time:

$ python -m wodify bookings
- 2026-07-20 17:30:00 CrossFit: 5:30 PM [Attended]
- 2026-07-22 17:30:00 CrossFit: 5:30 PM [Attended]
- 2026-07-24 17:30:00 CrossFit: 5:30 PM [Attended]
  • prime over an SSH tunnel to the CDP host's Chrome: 338-char cookie, 28-char CSRF, moduleVersion=4qHsLi2Es1qvgd2NhStmPw
  • Auth accepted: responses carry hasApiVersionChanged: false, so cookie + CSRF + both versions are all valid
  • 60 tests pass, no network needed

The body contract (learned the hard way)

The tamird/wodify-race-repro example uses inputParameters. That is right for ServiceAPI* actions but wrong for screen data actions, which send:

{"versionInfo": {…}, "viewName": "MainScreens.Home",
 "screenData": {"variables": {…entire screen state, incl. ClientVariables…}}}

Sending inputParameters — or adding any key not in the captured body — returns 400 Failed to parse JSON request content. So prime stores the whole body and client patches individual leaves via set_field, which only writes keys that already exist.

Levers that live in screenData.variables.ClientVariables: SelectedDate, GymProgramId, ActiveLocationId, CustomerId, UserId.

SelectedDate must be a bare YYYY-MM-DD. Every datetime form probed (…T00:00:00, …T00:00:00Z, …T07:00:00.000Z) returns 400 — note the browser's localStorage holds 2026-07-24T07:00:00.000Z, which is not the wire format.

WOD content — solved

The content action is WOD_Flow/GetAllWorkoutData_WB/DataActionGetAllWorkoutData, viewName: MainScreens.Exercise. Content at Response.ResponseWOD.ResponseWorkout: Name, Notes (coach's brief), and WorkoutComponents.List[].{Name, Comment, IsSection}.

Why it took a while to find, recorded so nobody repeats it:

  • GetWorkoutData_HasWodLeaderboardComponents sounds like the content action but returns a bare {"Response": true}. It is registered as wodflags, never workout.
  • The content action does not fire on a cold load of /WodifyClient/Exercise — that screen shows "No workout posted" and issues no content request at all. Enumerating requests on a direct load therefore "proves" the action does not exist. It only fires when the screen is reached properly: class detail → Go to workout.
  • OutSystems also caches the data action, so revisiting the same date issues no request. Capturing it requires navigating to a date whose WOD is not already cached.
  • ProgramWODList on GetClasses was a red herring — it stays a placeholder record.

Body contract: SelectedDate and GymProgramId appear in two sibling objects (RequestCache and In_Request). client.set_field writes every occurrence, which is why overriding the date works; writing only the first would silently query the wrong day.

prime reproduces the walk via WORKOUT_WALK_JS (Schedule → date → class → Go to workout), which also captures the class-detail actions as a side effect. Pass --workout-date for a day that actually has a posted WOD; a day with nothing published cannot capture it.

Both target workflows work (verified live 2026-07-25)

$ python -m wodify bookings --since 2026-07-18 --until 2026-07-25 --attended
- 2026-07-20 17:30:00 CrossFit: 5:30 PM [Attended] class_id=190917816
- 2026-07-22 17:30:00 CrossFit: 5:30 PM [Attended] class_id=190917818
- 2026-07-24 17:30:00 CrossFit: 5:30 PM [Attended] class_id=190917820

$ python -m wodify workout --date 2026-07-22
# CrossFit - Wed, Jul 22
## WARM-UP
General Warm-Up
1:30 Cardio Choice
...

bookings emits class_id so the two chain together. Range filtering is client-side: the action returns the whole history in one call, so filtering here is cheaper than negotiating a range with the server.

The coach's brief (Notes) is excluded unless --notes is passed — it runs to several thousand characters, and small output is the entire reason this client exists.

Field-name traps (each one produced confident wrong output)

These all failed silently — plausible output, no error. Worth reading before adding a renderer.

Field Trap
PersonName attendee name is not Name. Looking for Name returns an empty list on a full class, reading as "nobody came"
Description the metcon's movements. Reading only Name/Comment yields goals and RPE with no workout
MeasureRepScheme strength set scheme, plain text with real newlines (not HTML)
FromDate the scheduler's date key. It is not SelectedDate (that is the workout screen), so --date was ignored and every query returned today
Id on a class row not ClassId. A class row nests GroupMemberReservationStatus.ClassId == "0", so flattening nested dicts up clobbers the real id and collapses every class into one
Id == "0" OutSystems' empty-record placeholder. Reads exactly like real data; render._real_records filters it

A related lesson worth keeping: when the attendee list came back empty, the code printed an invented explanation ("Wodify hides names for anonymous members"). That was a fabricated cause for a bug in the same function. Empty results now say only what is true — "None returned" — and speculate about nothing.

Known quirks

  • Attendee lists omit the requesting account, so a class you attended shows one fewer person than it has reservations. render.attendee_block flags the gap rather than letting it look like a miscount.
  • schedule only returns programs the account can see: the request carries CustomerHasShowAllClassesEnabled: false and IncludeDropInsAndFreeTrials: false. Programs like Open Gym or Personal Training will not appear even if they ran.
  • ReservationCount is reservations, not attendance. For a past class, the attendee list's HasSignedIn / HasNoShow flags are the real signal.

Deployment

Deployed to the hermes host at ~/repo/wodify, with a wrapper at ~/.local/bin/wodify. The wrapper puts src/ on PYTHONPATH rather than pip-installing: the query path is stdlib-only, and staying out of the hermes venv means hermes update cannot clobber or drop it. It uses the hermes venv's interpreter because prime needs websockets from there.

Chrome runs on that host, so prime works locally with no tunnel. The wodify-viewer hermes skill (v4.0.0) now tells the agent to use the CLI and treat the browser as fallback.

Verified live on the host: list date, list workout (12 attendees + the WOD), and a full prime whose walk log reads {"log":["schedule=true","date=true","classes=4","class=true","hasGoToWorkout=true","goto=true"],"ok":true}.

Self-healing, confirmed in the wild

Wodify redeployed mid-session (moduleVersion went 4qHsLi2Es1qvgd2NhStmPw → Lr5GpsYppagRVIiIPnDo2g). The stale cache did not return wrong data — it raised:

STALE: schedule: Wodify redeployed (module changed=True, api changed=False). Re-prime.

Exit 3, no fallback, no guess. Intended behaviour, fired unprompted.

The 2026-08 redesign: attendees moved, paths re-prefixed

Wodify redeployed around 2026-08-22 and broke attendees in two independent ways. Both are fixed; recorded so the next redesign is faster to diagnose.

  1. Every data action gained a WodifyClient_DataFetch_WB/ prefix (e.g. Schedule_OS/GetClassList_ForClient_WithReservationCounts_WB/... now lives under WodifyClient_DataFetch_WB/Schedule_OS/...). Symptom was subtle: cached apiVersions kept working, so everything except never-captured actions kept answering — and re-prime could not recapture anything new, because _observe matches captured paths exactly against the allowlist.
  2. GetClassAttendees is gone entirely. No request by that name fires anywhere in the app now, on any screen, including scroll. The class screen sources its roster from a different endpoint: WodifyClient_Class/Classes/Class/ActionGetClassAttendees (note: no _WB, no DataAction infix — ServiceAPI style). It only fires when a class is opened from the Scheduler UI, which the existing workout walk already does.

Diagnosis recipe that found both: attach CDP with a request observer, click through Home → Schedule → a class, and dump every /screenservices/ path (probe script pattern in git history, probe4.py). Grepping the dump for the missing action's name fragments (Attendee) reveals its new home.

The response shape also changed: attendees now arrive as Response.ClassDetailAttendee.List[].{PersonName, StatusInClass, ...} — which render.attendee_rows already handled, but the CLI's attendees command had its own older inline renderer that only knew Name/ FirstName+LastName and silently printed "No attendees listed." for every class. Rule reinforced: there must be exactly one attendee-shape parser; render.attendees() now delegates to attendee_rows().

Publishing

Test fixtures use fictional names. Real gym members' names were scrubbed and the git history squashed before first publication — do not reintroduce live attendee names into fixtures or docs, even in examples. The gym host and location id are not secrets and stay.

The Home-variant GetClasses is dead — closed, do not reopen

WodifyClient_Class/Classes/Attendance/DataActionGetClasses returns placeholder records (Id "0", empty ScheduleList, zero WODs) even when the real client calls it. Confirmed by capturing the app's own request/response pair during a live walk to the workout screen: 200, ~10 KB of empty-record scaffolding, real_wods=0. Screen-variable overrides (WBDataFetchIsComplete, IsLoading, ProgramsWithHistory, every date/program combination) were all probed and change nothing. It is not parameter-gated; it is empty by design — the Home screen sources its data from other actions.

The action is removed from the allowlist (a test pins that), and wodify classes is now a CLI alias for schedule, which is the class-list action that actually returns data.

Gotchas found the hard way

  • /WodifyClient/Exercise (the workout screen) renders "No workout posted" even when a workout exists, unless reached via a class. Irrelevant to this client — we call the data action directly — but do not "verify" against that screen and conclude the data is missing.
  • A stale ClassId redirects to Home instead of erroring. ClassId is per-occurrence and changes daily.
  • Capacity is reserved | limit and can exceed the limit when the gym overbooks. Report it verbatim.