---
name: read-pheidi-plan
description: Fetch and interpret a Pheidi training plan from the public JSON API at GET /api/plans/{publicId}. Use when the user provides a Pheidi plan ID, plan slug, plan URL, or asks to analyze/summarize/answer questions about a Pheidi training plan.
license: MIT
user-invocable: true
argument-hint: "[plan publicId, slug, full plan URL, or path to a saved plan JSON file]"
metadata:
  author: pheidi
  version: "1.1"
---

Read a Pheidi training plan from its public JSON API and answer the user's question about it. The endpoint is read-only, public, rate-limited (30 req/min), and returns the **full plan with every layer applied**.

**Endpoint**: `GET https://app.pheidi.training/api/plans/{publicId}`

**Discovery**: `/.well-known/api-catalog` (RFC 9727 linkset+json) → `/.well-known/openapi.json` (OpenAPI 3.1).

---

## STEP 1: GET THE PLAN

Resolve the input to a `publicId`:

- **Bare ID** (7-char base62 like `aB3xZ9k`, or a slug like `marathon-fall-2026`) → use as-is
- **URL** like `https://app.pheidi.training/plan/{publicId}` or `.../api/plans/{publicId}` → extract the last path segment
- **File path** to a saved JSON → read it directly, skip the fetch

Fetch with `WebFetch` against `https://app.pheidi.training/api/plans/{publicId}`. Ask for the **raw JSON** in the prompt — do not let the model summarize it for you. If the response says 404, the publicId is wrong. If 429, wait a minute and retry.

If the user gave you nothing, ask once: *"What's the plan ID, slug, or URL?"*

---

## STEP 2: UNDERSTAND THE STRUCTURE

The response has six top-level sections. **Read them in this order — the later sections explain anomalies in the earlier ones.**

### Identity
`publicId`, `displayName`, `status` (`Active`/`Completed`/`Archived`/`Paused`), `unit` (`"mi"` or `"km"`), `progressionPattern`, `createdDate`. Use `displayName` when referring to the plan.

### `raceGoal` — what the plan is built for
- `distance` ∈ {`FiveK`, `TenK`, `HalfMarathon`, `FullMarathon`}. Training archetype. A custom race (a 15K, a 10-miler, a 5.5-mile road race) trains as the nearest of these, so `distance` can be `TenK` while the runner is racing something else. Use it to explain structure.
- `distanceLabel`. The race the runner entered, already formatted for display (`5K`, `10K`, `Half Marathon`, `Full Marathon`, or a custom length such as `5.5 mi` or `15 km`). This is the name you show.
- `raceLength`. That same length as a number, in the plan's `unit`. Append `unit` when you print the number.
- `raceDate` (date), `targetTime` (nullable HH:MM:SS), `planWeeks` (int)

### `summary` — pre-computed totals
`totalWeeks`, `totalDistance`, `peakWeeklyDistance`, `longestRun`, `completedWorkouts`, `totalRunWorkouts`, `completionPercentage`. **Use these. Do not re-sum.**

### `vacations` — provenance, not action

Array of `{startDate, endDate, loadPercent}`. `loadPercent` is the volume kept (0 = full rest, 80 = light reduction). The workout layer **already reflects** this — vacations exist so you can explain *why* a stretch of workouts looks reduced.

### `redistributions` — provenance, not action

Records of distance (in the plan's unit) moved from removed workouts (vacation/day-off) onto future easy runs. Fields: `sourceType`, `distanceRedistributed`, `scope` ∈ {`ThisWeek`, `NextNWeeks`, `UntilDate`, `RestOfPlan`}, `scopeWeeks`, `scopeEndDate`, `targetWorkoutTypes`. Again — already applied to workouts; this is just the audit trail.

### `weeks[]` — the plan body
Ordered by `weekNumber`. Each week:
- `phase` ∈ {`Base`, `Build`, `Peak`, `Taper`}
- `totalDistance`, `longRunDistance`, `runDayCount`
- `workouts[]` ordered by `date`

#### Workout fields (the most important part)
| Field | Meaning |
|---|---|
| `date` | ISO date |
| `type` | `Rest`, `Easy`, `Tempo`, `Intervals`, `LongRun`, `MediumLongRun`, `Recovery`, `Fartlek`, `HillRepeats`, `RacePace`, `CrossTraining`, `Strength` |
| `description` | Human-readable summary already accounting for modifier |
| `targetDistance` | **Final value after all layers.** Use this directly. |
| `targetDuration` | Nullable timespan |
| `loadMultiplier` | Distance as fraction of long run (1.0 = long run) |
| `modifier` | Why it looks like this: `None`, `Vacation`, `InjuryReduced`, `DayOff`, `UserEdited`, `UserAdded` |
| `status` | `Pending`, `Completed`, `Skipped` |
| `paceZone` | `{zone, minPace, maxPace, rpeMin, rpeMax, rpeDescription}` — **may itself be `null`** for rest/strength/cross-training workouts. When present, pace fields may be null if user has no VDOT; fall back to `rpeDescription`. |
| `isRunWalk`, `runMinutes`, `walkMinutes` | Galloway intervals (only when enabled in profile) |
| `warmUpDuration`, `coolDownDuration` | Quality workout structure |
| `completion` | **Present only when `status == "Completed"`.** Has `actualDistance`, `actualDuration`, `actualEffort`, `actualAverageHeartRate` (integer, nullable, beats per minute), `actualIntensityZone`, `feedback` ∈ {`None`, `TooEasy`, `JustRight`, `Tough`, `TooHard`}, `completionPercent`, `readinessScore` |
| `override` | **Present only when user manually edited.** Shows the override values. Their effect is already in the top-level fields above. |

---

## STEP 3: LAYER SEMANTICS

The server applies layers in order before serializing:

1. Base generated plan
2. Vacation reductions
3. Injury reductions
4. User overrides
5. Load redistribution

**The workout fields you see are the final output.** The `vacations`, `redistributions`, and per-workout `override` fields are *provenance* — they let you explain divergence from the generated baseline.

Never try to "apply" a vacation or redistribution yourself. That would double-count.

---

## STEP 4: ANSWER THE USER

Common questions and how to answer them:

| Question | How to answer |
|---|---|
| What's my next workout? | First workout where `status == "Pending"` AND `date >= today`. Report `type`, `targetDistance`, `paceZone.zone`, pace range or RPE. |
| How much have I run this week? | Sum `completion.actualDistance` for workouts in current `weekNumber`. Compare to that week's `totalDistance` for planned vs actual. A public plan nulls the whole completion block for health-store runs and for Garmin device data, and a weekly actual-distance sum skips those rows. |
| Why is this week lighter than last? | Check (1) `phase == "Taper"`, (2) any `vacations` overlapping this week, (3) workout `modifier` values in the week. Report the cause. |
| What pace should I run today? | `paceZone.minPace` to `maxPace`. If null, use `paceZone.rpeDescription`. Mention `paceZone.zone` for context. |
| What did I override? | Workouts where `override` is non-null. Show original `type`/`targetDistance` from override vs current top-level values. |
| How am I tracking? | Use `summary.completionPercentage` and `summary.completedWorkouts` / `summary.totalRunWorkouts`. |
| When is my race? | `raceGoal.raceDate`, `raceGoal.distanceLabel`, `raceGoal.targetTime` if set. For the number, `raceGoal.raceLength` with the plan's `unit`. Mention `raceGoal.distance` only to say which standard structure a custom race trains like. |
| Show my full schedule | Walk `weeks[]` in order. For each week list `weekNumber`, `phase`, `totalDistance`, then workouts as `date`, `type`, `distance`, `pace`. |

### Display conventions

- Plans are generated and stored natively in ONE unit: read the plan-level `unit` field (`"mi"` or `"km"`). Every distance (`targetDistance`, `actualDistance`, `totalDistance`, `longRunDistance`, `distanceRedistributed`, `raceLength`) and pace (`minPace`/`maxPace`, minutes per unit) is already in that unit
- NEVER convert values — just append the plan's unit label. A km plan reads `12.0 km`, a miles plan `8.0 mi`
- Pace as `MM:SS /mi` or `MM:SS /km` per the plan's `unit`
- Dates as the user's locale-friendly form (e.g., "Sat, Apr 19")
- Race name: `raceGoal.distanceLabel`. It is already display text. For a number, print `raceGoal.raceLength` with the plan's `unit`.
- Training archetype (`raceGoal.distance`): `FiveK` is 5K structure, `TenK` is 10K, `HalfMarathon` is a half, `FullMarathon` is a marathon. Say this when the raced length and the archetype differ.
- `phase` enum is already title case — use as-is
- Workout `type` enum: split on capitals when displaying (`MediumLongRun` → "Medium Long Run")

### What NOT to do

- The `publicId` is **not a secret**. It's either a random `ShortId` (7-char base62, hard to guess) or a user-chosen `Slug` (potentially guessable). Anyone who knows the publicId can read the plan — there is no auth. Treat slug-based URLs as effectively public; treat ShortId-based URLs as semi-private but not security-grade. Do not encourage runners to "share" guessable slugs as if they were secret.
- Don't compute `summary` fields yourself; the server's values include layer effects you'd miss
- Don't suggest changes to the plan from the API alone — the endpoint is read-only and you don't have user profile data (VDOT, available days, injuries)
- Don't name the runner's race from `raceGoal.distance`. That field is the training archetype. The race they entered is `distanceLabel`.
- Don't fabricate fields. If the user asks about something not in the response (heart-rate zones, splits, GPS), say so. Average heart rate is `completion.actualAverageHeartRate` when present. If it is `null`, report it as unavailable, not as "no heart rate recorded". A public plan nulls the whole completion block for health-store runs and for Garmin device data, and a weekly actual-distance sum skips those rows.

---

## ERROR HANDLING

| Status | Meaning | Action |
|---|---|---|
| 404 | No plan with that publicId | Tell the user the ID is wrong; ask for the correct one |
| 429 | Rate limited (30/min) | Wait one minute, retry once |
| Network failure | App down or no internet | Report cleanly, don't fabricate plan data |

If `weeks` is empty, the plan was created but never generated — tell the user the plan exists but has no workouts yet.
