# Creating a SwollStep Program

Use this guide alongside the public specification at https://fvgemdcvjuknvzdqkurt.supabase.co/functions/v1/agent-api/openapi.json. The account owner provides the API base URL and an opaque bearer token. Treat the token as a secret: keep it out of prompts intended for sharing, source control, tool output, and logs.

1. Call `GET /v1/catalog` with the token. Reuse existing exercise/workout UUIDs where appropriate. Catalogue fields are native Codable names (`enabledFields`, `distanceUnit`, `paceUnit`); request fields use the OpenAPI names (`fields`, `distance_unit`, `pace_unit`). Do not guess an exercise's attached fields from its name.
2. Build one `CreateProgram` document. Declare any new exercise definitions and new workout prescriptions, referencing them by request-local keys. Use optional labels and optional names. Put meaningful work in targets, and reserve instructions for technique/context.
3. Place direct exercises in block `items` when they need no grouping. For repeated identical bench sets, put one exercise in a group with `fields.rounds: 3`. Keep different ramp-up weights as individual exercise entries. For a timed repeated sequence, attach `duration_seconds`, `repetition: "untilDuration"`, and optional `tracks_rounds`. For intervals, attach duration and interval seconds. No category label is mandatory.
4. Choose inclusive floating start/end dates and weekly rules (Sunday=1, Saturday=7). Match dates, quantities, and training intent to the owner's request. If essential targets are unknown, obtain them from the owner; do not claim these are based on workout history, because this API does not expose it.
5. For progression, give the working prescription an optional step `key` and attach dated `changes` to each intended weekly rule. Use partial target patches (`weight_lb`, `reps`, etc.); they accumulate chronologically. Repeated identical working sets still use one group with rounds. Keep distinct ramp-up targets untouched unless requested. See `example-progression.json`.
6. Submit `POST /v1/programs` with a unique, durable `Idempotency-Key`. Save the exact body and key for retries. A successful 201/status created is immediately saved in normalized tables. A 422 response identifies invalid fields; fix them and use a new key if changing a previously accepted document. A 409 means a key was already used with different content.
7. Save returned workout/Program IDs and the operation receipt ID. Retrieve actual definitions immediately through GET /v1/workouts/{workout-id} or /v1/programs/{program-id}, or the receipt through /v1/operations/{receipt-id}. The owner opens/syncs the app to download these records; no app import/acknowledgement gates creation. For unscheduled Programs omit both start_date/end_date and use week-based changes. Never schedule a draft without the owner's instruction.


Do not try to edit recorded results, change another account, update/delete existing Programs, or start/end a workout. Those actions are outside this token's scope. V1.1 supports weekly schedules with explicit dated target changes; it does not infer progressive overload from actual performance or edit existing Programs via token. Use dated patches for requested progression and preserve the other targets.

The complete example in `example-program.json` illustrates direct warm-up, different ramp-up steps, and three identical working sets. Its dates are illustrative; choose dates for the actual request.


## Relative Programs and recording-only fields

 supply `program.week_count` (1–52) and seven `relative_days` with `day` 1–7, workout references, optional week-based target `changes`, `optional`, `rest_alternative`, and notes. Omit weekday rules and dates. The API expands stable week/day IDs and independent prescription snapshots. A rest-only day omits workout and sets rest_alternative=true; a workout with rest as an alternative must be optional. The app anchors Day 1 to an explicitly chosen start date only when scheduling. RRULE parsing is future work and independent of relative plans. See `return-to-training.json` for a complete unscheduled example.

Steps can use `record_only_fields` for attached reps/duration/distance/pace/effort/stroke measurements without prescribing a target. These are still logged only when performed. Other attached fields keep required-target validation.
